-
Notifications
You must be signed in to change notification settings - Fork 14.9k
[Clang-Repl] Add Lambda Support, PID Retrieval, and Dynamic liborc_rt Path in Clang-Repl #155140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…into redirection
if (::OffloadArch.empty()) { | ||
::OffloadArch = "sm_35"; | ||
} | ||
CB.SetOffloadArch(OffloadArch); | ||
CB.SetOffloadArch(::OffloadArch); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these changes relevant to the current PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. if not done, it gives following error:
error: reference to 'OffloadArch' is ambiguous
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which compiler is this? Why it works upstream?
✅ With the latest revision this PR passed the C/C++ code formatter. |
@@ -33,6 +33,10 @@ | |||
using namespace llvm; | |||
using namespace llvm::orc; | |||
|
|||
#if LLVM_ON_UNIX | |||
static std::vector<pid_t> LaunchedExecutorPID; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That should be a member of the Interpreter class I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This vector is updated in launchExecutor. And launchExecutor is called before creation of interpreter. I can define it as static but I don't think it is related enough to be in interpreter class.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need a home for this. The process is not the right home. Either the Interpreter class or the IncrementalExecutor should be good options.
if ((SystemTriple.isOSBinFormatELF() || SystemTriple.isOSBinFormatMachO())) { | ||
std::string OOPExecutor = getExecutorPath(); | ||
std::string OrcRuntimePath = getOrcRuntimePath(CompilerRTPath); | ||
bool UseSharedMemory = false; | ||
std::string SlabAllocateSizeString = ""; | ||
std::unique_ptr<llvm::orc::ExecutorProcessControl> EPC; | ||
EPC = ExitOnError(launchExecutor(OOPExecutor, UseSharedMemory, | ||
SlabAllocateSizeString, | ||
[=] { // Lambda defined inline | ||
auto redirect = [](int from, int to) { | ||
if (from != to) { | ||
dup2(from, to); | ||
close(from); | ||
} | ||
}; | ||
|
||
redirect(0, STDIN_FILENO); | ||
redirect(1, STDOUT_FILENO); | ||
redirect(2, STDERR_FILENO); | ||
|
||
setvbuf(stdout, nullptr, _IONBF, 0); | ||
setvbuf(stderr, nullptr, _IONBF, 0); | ||
})); | ||
if (EPC) { | ||
CB.SetTargetTriple(EPC->getTargetTriple().getTriple()); | ||
JB = ExitOnError(clang::Interpreter::createLLJITBuilder(std::move(EPC), | ||
OrcRuntimePath)); | ||
} | ||
} | ||
|
||
return cantFail(clang::Interpreter::create(std::move(CI), std::move(JB))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of that should go in Interpreter.cpp logic when IsOutOfProcess
is set. This way we won't have to drag OrcRuntimePath
around.
namespace clang { | ||
|
||
/// \brief Configuration options for out-of-process JIT execution. | ||
struct OutOfProcessJITConfig { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That struct can go as a nested Interpreter class.
bool UseSharedMemory; | ||
|
||
/// String representing the slab allocation size for memory management. | ||
std::string SlabAllocateSizeString; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be an unsigned int
I think. All of these should have good default values.
@@ -55,6 +57,8 @@ | |||
#include "llvm/TargetParser/Host.h" | |||
#include "llvm/Transforms/Utils/Cloning.h" // for CloneModule | |||
|
|||
#include <iostream> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably do not need this include.
std::unique_ptr<llvm::orc::ExecutorProcessControl> EPC; | ||
if (OutOfProcessConfig.OOPExecutor != "") { | ||
// Launch an out-of-process executor locally in a child process. | ||
EPC = ExitOnErr(launchExecutor(OutOfProcessConfig.OOPExecutor, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember this is the library, it must not abort the process. Instead the interface should return llvm::Expected<std::unique_ptr<llvm::orc::LLJITBuilder>>
and propagate the error up.
llvm::SmallString<256> BasePath(llvm::sys::fs::getMainExecutable( | ||
"clang-repl", reinterpret_cast<void *>(&getOrcRuntimePath))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That does not work when we are in a library. Why do we need the BasePath at all? I'd think we can ask the TC
and that is mostly it. Do you try to get somehow to the source directory?
@@ -33,6 +33,10 @@ | |||
using namespace llvm; | |||
using namespace llvm::orc; | |||
|
|||
#if LLVM_ON_UNIX | |||
static std::vector<pid_t> LaunchedExecutorPID; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need a home for this. The process is not the right home. Either the Interpreter class or the IncrementalExecutor should be good options.
#include <optional> | ||
|
||
#include <iostream> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need that.
if (::OffloadArch.empty()) { | ||
::OffloadArch = "sm_35"; | ||
} | ||
CB.SetOffloadArch(OffloadArch); | ||
CB.SetOffloadArch(::OffloadArch); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which compiler is this? Why it works upstream?
} else { | ||
Interp = ExitOnErr( | ||
clang::Interpreter::create(std::move(CI), OutOfProcessConfig)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
This PR builds upon the changes introduced in #152562.
Introduces:
liborc_rt
path.