-
Notifications
You must be signed in to change notification settings - Fork 14.9k
Allow for custom code model in clang::Interpreter #156977
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
This is necessary when using ASan, since the larger code size will lead to errors such as: ``` JIT session error: In graph clojure_core-clojure.core$clojure_core_cpp_cast_24538-24543-jitted-objectbuffer, section .eh_frame: relocation target 0x7bffe374b000 (DW.ref.__gxx_personality_v0) is out of range of Delta32 fixup at address 0x7bffe374b000 (<anonymous block> @ 0x7fffebf48158 + 0x13) ``` Previously, `clang::Interpreter` would hard-code the usage of a small code model. With this change, we default to small, but allow for custom values. This related to llvm#102858 and llvm#135401. There is no change to default behavior here.
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-clang Author: Jeaye Wilkerson (jeaye) ChangesThis is necessary when using ASan, since the larger code size will lead to errors such as:
Previously, There is no change to default behavior here. @lhames for review. Full diff: https://github.com/llvm/llvm-project/pull/156977.diff 2 Files Affected:
diff --git a/clang/include/clang/Interpreter/Interpreter.h b/clang/include/clang/Interpreter/Interpreter.h
index 8c124aadf1005..3890a06917f76 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -115,11 +115,15 @@ class Interpreter {
/// An optional compiler instance for CUDA offloading
std::unique_ptr<CompilerInstance> DeviceCI;
+ /// An optional code model to provide to the JITTargetMachineBuilder
+ std::optional<llvm::CodeModel::Model> CM;
+
protected:
// Derived classes can use an extended interface of the Interpreter.
Interpreter(std::unique_ptr<CompilerInstance> Instance, llvm::Error &Err,
std::unique_ptr<llvm::orc::LLJITBuilder> JITBuilder = nullptr,
- std::unique_ptr<clang::ASTConsumer> Consumer = nullptr);
+ std::unique_ptr<clang::ASTConsumer> Consumer = nullptr,
+ const std::optional<llvm::CodeModel::Model> &CM = std::nullopt);
// Create the internal IncrementalExecutor, or re-create it after calling
// ResetExecutor().
@@ -133,7 +137,8 @@ class Interpreter {
virtual ~Interpreter();
static llvm::Expected<std::unique_ptr<Interpreter>>
create(std::unique_ptr<CompilerInstance> CI,
- std::unique_ptr<llvm::orc::LLJITBuilder> JITBuilder = nullptr);
+ std::unique_ptr<llvm::orc::LLJITBuilder> JITBuilder = nullptr,
+ const std::optional<llvm::CodeModel::Model> &CM = std::nullopt);
static llvm::Expected<std::unique_ptr<Interpreter>>
createWithCUDA(std::unique_ptr<CompilerInstance> CI,
std::unique_ptr<CompilerInstance> DCI);
diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp
index 47995216fac46..a483506932107 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -251,8 +251,9 @@ IncrementalCompilerBuilder::CreateCudaHost() {
Interpreter::Interpreter(std::unique_ptr<CompilerInstance> Instance,
llvm::Error &ErrOut,
std::unique_ptr<llvm::orc::LLJITBuilder> JITBuilder,
- std::unique_ptr<clang::ASTConsumer> Consumer)
- : JITBuilder(std::move(JITBuilder)) {
+ std::unique_ptr<clang::ASTConsumer> Consumer,
+ const std::optional<llvm::CodeModel::Model> &CM)
+ : CM(CM), JITBuilder(std::move(JITBuilder)) {
CI = std::move(Instance);
llvm::ErrorAsOutParameter EAO(&ErrOut);
auto LLVMCtx = std::make_unique<llvm::LLVMContext>();
@@ -349,10 +350,11 @@ const char *const Runtimes = R"(
llvm::Expected<std::unique_ptr<Interpreter>>
Interpreter::create(std::unique_ptr<CompilerInstance> CI,
- std::unique_ptr<llvm::orc::LLJITBuilder> JB) {
+ std::unique_ptr<llvm::orc::LLJITBuilder> JB,
+ const std::optional<llvm::CodeModel::Model> &CM) {
llvm::Error Err = llvm::Error::success();
auto Interp = std::unique_ptr<Interpreter>(
- new Interpreter(std::move(CI), Err, JB ? std::move(JB) : nullptr));
+ new Interpreter(std::move(CI), Err, JB ? std::move(JB) : nullptr, nullptr, CM));
if (Err)
return std::move(Err);
@@ -526,6 +528,8 @@ llvm::Error Interpreter::CreateExecutor() {
auto JTMB = createJITTargetMachineBuilder(TT);
if (!JTMB)
return JTMB.takeError();
+ if (CM)
+ JTMB->setCodeModel(CM);
auto JB = IncrementalExecutor::createDefaultJITBuilder(std::move(*JTMB));
if (!JB)
return JB.takeError();
|
This is necessary when using ASan, since the larger code size will lead to errors such as:
Previously,
clang::Interpreter
would hard-code the usage of a small code model. With this change, we default to small, but allow for custom values. This related to #102858 and #135401.There is no change to default behavior here.
@lhames for review.