-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[clang-repl] Sink RemoteJITUtils into Interpreter class (NFC) #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
Changes from 21 commits
79849c3
825f005
52b0902
3b4fcad
e174e98
b744a9f
0c6c995
2cf71ed
7c29008
41f8e54
4f1d203
a6a4369
63de886
c24e84e
b114bb8
850b953
956f393
14e5afd
65afbff
7dc6590
095a63b
2b6dc6c
7ad10a6
6a58d5f
f1b9135
dd73052
e90df55
521be31
baaff1e
44cde65
fc1f0da
c49ec55
a6a05ea
f2ca64e
0c99b67
51d6657
a71c546
37a9f3d
2cdb210
129a62b
c856255
3a15ddf
54a0dba
98c59b4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,18 +22,36 @@ | |
| #include "clang/Lex/Preprocessor.h" | ||
| #include "clang/Sema/Sema.h" | ||
|
|
||
| #include "clang/Basic/Diagnostic.h" | ||
| #include "clang/Basic/DiagnosticIDs.h" | ||
| #include "clang/Basic/DiagnosticOptions.h" | ||
| #include "clang/Driver/Compilation.h" | ||
| #include "clang/Driver/Driver.h" | ||
| #include "clang/Driver/ToolChain.h" | ||
| #include "llvm/ADT/IntrusiveRefCntPtr.h" | ||
| #include "llvm/ADT/SmallString.h" | ||
| #include "llvm/ExecutionEngine/Orc/LLJIT.h" | ||
| #include "llvm/LineEditor/LineEditor.h" | ||
| #include "llvm/Support/CommandLine.h" | ||
| #include "llvm/Support/FileSystem.h" | ||
| #include "llvm/Support/ManagedStatic.h" // llvm_shutdown | ||
| #include "llvm/Support/Path.h" | ||
| #include "llvm/Support/Signals.h" | ||
| #include "llvm/Support/TargetSelect.h" | ||
| #include "llvm/Support/VirtualFileSystem.h" | ||
| #include "llvm/Support/raw_ostream.h" | ||
| #include "llvm/TargetParser/Host.h" | ||
| #include "llvm/TargetParser/Triple.h" | ||
| #include <optional> | ||
|
|
||
| #include <iostream> | ||
kr-2003 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| #include "llvm/ExecutionEngine/Orc/Debugging/DebuggerSupport.h" | ||
|
|
||
| using namespace clang; | ||
|
|
||
| // Disable LSan for this test. | ||
| // FIXME: Re-enable once we can assume GCC 13.2 or higher. | ||
| // https://llvm.org/github.com/llvm/llvm-project/issues/67586. | ||
|
|
@@ -81,6 +99,40 @@ static llvm::cl::opt<bool> OptHostSupportsJit("host-supports-jit", | |
| static llvm::cl::list<std::string> OptInputs(llvm::cl::Positional, | ||
| llvm::cl::desc("[code to run]")); | ||
|
|
||
| static std::string getCompilerRTPath() { | ||
| clang::DiagnosticOptions DiagOpts; | ||
| llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> DiagID( | ||
| new clang::DiagnosticIDs()); | ||
|
|
||
| clang::IgnoringDiagConsumer DiagConsumer; | ||
| clang::DiagnosticsEngine Diags(DiagID, DiagOpts, &DiagConsumer, false); | ||
| std::vector<const char *> Args = {"clang", "--version"}; | ||
| clang::driver::Driver D("clang", llvm::sys::getProcessTriple(), Diags); | ||
| D.setCheckInputsExist(false); | ||
|
|
||
| std::unique_ptr<clang::driver::Compilation> C(D.BuildCompilation(Args)); | ||
| if (!C) { | ||
| return ""; | ||
| } | ||
|
|
||
| const clang::driver::ToolChain &TC = C->getDefaultToolChain(); | ||
| std::optional<std::string> CompilerRTPath = TC.getCompilerRTPath(); | ||
|
|
||
| return CompilerRTPath ? *CompilerRTPath : ""; | ||
| } | ||
|
|
||
| static std::string getOrcRuntimePath() { | ||
kr-2003 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (OrcRuntimePath.empty()) { | ||
| llvm::SmallString<256> BasePath(llvm::sys::fs::getMainExecutable( | ||
| "clang-repl", reinterpret_cast<void *>(&getOrcRuntimePath))); | ||
| llvm::sys::path::remove_filename(BasePath); // Remove clang-repl filename. | ||
| llvm::sys::path::remove_filename(BasePath); // Remove ./bin directory. | ||
| llvm::sys::path::append(BasePath, getCompilerRTPath()); | ||
| return BasePath.str().str(); | ||
| } | ||
| return OrcRuntimePath; | ||
| } | ||
|
|
||
| static llvm::Error sanitizeOopArguments(const char *ArgV0) { | ||
| // Only one of -oop-executor and -oop-executor-connect can be used. | ||
| if (!!OOPExecutor.getNumOccurrences() && | ||
|
|
@@ -121,17 +173,21 @@ static llvm::Error sanitizeOopArguments(const char *ArgV0) { | |
| ArgV0, reinterpret_cast<void *>(&sanitizeOopArguments))); | ||
| llvm::sys::path::remove_filename(BasePath); // Remove clang-repl filename. | ||
| llvm::sys::path::remove_filename(BasePath); // Remove ./bin directory. | ||
| llvm::sys::path::append(BasePath, CLANG_INSTALL_LIBDIR_BASENAME, "clang", | ||
| CLANG_VERSION_MAJOR_STRING); | ||
| if (SystemTriple.isOSBinFormatELF()) | ||
| OrcRuntimePath = | ||
| BasePath.str().str() + "/lib/x86_64-unknown-linux-gnu/liborc_rt.a"; | ||
| else if (SystemTriple.isOSBinFormatMachO()) | ||
| OrcRuntimePath = BasePath.str().str() + "/lib/darwin/liborc_rt_osx.a"; | ||
| else | ||
| std::string CompilerRTPath = getCompilerRTPath(); | ||
| if (llvm::sys::fs::exists(CompilerRTPath + "/liborc_rt.a")) { | ||
| llvm::sys::path::append(BasePath, CompilerRTPath); | ||
| OrcRuntimePath = BasePath.str().str() + "/liborc_rt.a"; | ||
| } else if (!llvm::sys::fs::exists(CompilerRTPath + "/liborc_rt_osx.a")) { | ||
| llvm::sys::path::append(BasePath, CompilerRTPath); | ||
| OrcRuntimePath = BasePath.str().str() + "/liborc_rt_osx.a"; | ||
| } else if (!llvm::sys::fs::exists(CompilerRTPath + "/liborc_rt-x86_64.a")) { | ||
| llvm::sys::path::append(BasePath, CompilerRTPath); | ||
| OrcRuntimePath = BasePath.str().str() + "/liborc_rt-x86_64.a"; | ||
| } else { | ||
| return llvm::make_error<llvm::StringError>( | ||
| "Out-of-process execution is not supported on non-unix platforms", | ||
| "ORC runtime not found in " + CompilerRTPath, | ||
| llvm::inconvertibleErrorCode()); | ||
| } | ||
| } | ||
|
|
||
| // If -oop-executor was used but no value was specified then use a sensible | ||
|
|
@@ -186,7 +242,7 @@ struct ReplListCompleter { | |
| clang::Interpreter &MainInterp; | ||
| ReplListCompleter(clang::IncrementalCompilerBuilder &CB, | ||
| clang::Interpreter &Interp) | ||
| : CB(CB), MainInterp(Interp){}; | ||
| : CB(CB), MainInterp(Interp) {}; | ||
|
|
||
| std::vector<llvm::LineEditor::Completion> operator()(llvm::StringRef Buffer, | ||
| size_t Pos) const; | ||
|
|
@@ -275,10 +331,10 @@ int main(int argc, const char **argv) { | |
| if (!CudaPath.empty()) | ||
| CB.SetCudaSDK(CudaPath); | ||
|
|
||
| if (OffloadArch.empty()) { | ||
| OffloadArch = "sm_35"; | ||
| if (::OffloadArch.empty()) { | ||
| ::OffloadArch = "sm_35"; | ||
| } | ||
| CB.SetOffloadArch(OffloadArch); | ||
| CB.SetOffloadArch(::OffloadArch); | ||
|
||
|
|
||
| DeviceCI = ExitOnErr(CB.CreateCudaDevice()); | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.