[PATCH] D96033: [clang-repl] Land initial infrastructure for incremental parsing

Vassil Vassilev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 18 13:01:19 PDT 2021


v.g.vassilev added a comment.

In D96033#2766141 <https://reviews.llvm.org/D96033#2766141>, @uweigand wrote:

> In D96033#2765954 <https://reviews.llvm.org/D96033#2765954>, @v.g.vassilev wrote:
>
>> @hubert.reinterpretcast, thanks for the feedback. I have created a patch as discussed -- https://reviews.llvm.org/D102688
>>
>> @uweigand, thanks for reaching out. I believe the patch above should fix your setup. Could you confirm?
>
> Unfortunately, it does not.  Changing the triple doesn't affect the architecture the compiler generates code for.   If you wanted to change the compiler to generate code for the architecture the JIT detects, the easiest way would probably be to use (the equivalent of) "-march=native", which causes the compiler to also auto-detect the current processor in the same way as the JIT does.

Ah, okay. Could you try this patch:

  diff --git a/clang/lib/Interpreter/IncrementalExecutor.cpp b/clang/lib/Interpreter/IncrementalExecutor.cpp
  index f999e5eceaed..9a368d9122bc 100644
  --- a/clang/lib/Interpreter/IncrementalExecutor.cpp
  +++ b/clang/lib/Interpreter/IncrementalExecutor.cpp
  @@ -26,12 +26,14 @@
   namespace clang {
   
   IncrementalExecutor::IncrementalExecutor(llvm::orc::ThreadSafeContext &TSC,
  -                                         llvm::Error &Err)
  +                                         llvm::Error &Err,
  +                                         const llvm::Triple &Triple)
       : TSCtx(TSC) {
     using namespace llvm::orc;
     llvm::ErrorAsOutParameter EAO(&Err);
   
  -  if (auto JitOrErr = LLJITBuilder().create())
  +  auto JTMB = JITTargetMachineBuilder(Triple);
  +  if (auto JitOrErr = LLJITBuilder().setJITTargetMachineBuilder(JTMB).create())
       Jit = std::move(*JitOrErr);
     else {
       Err = JitOrErr.takeError();
  diff --git a/clang/lib/Interpreter/IncrementalExecutor.h b/clang/lib/Interpreter/IncrementalExecutor.h
  index c4e33a390942..b4c6ddec1047 100644
  --- a/clang/lib/Interpreter/IncrementalExecutor.h
  +++ b/clang/lib/Interpreter/IncrementalExecutor.h
  @@ -14,6 +14,7 @@
   #define LLVM_CLANG_LIB_INTERPRETER_INCREMENTALEXECUTOR_H
   
   #include "llvm/ADT/StringRef.h"
  +#include "llvm/ADT/Triple.h"
   #include "llvm/ExecutionEngine/Orc/ExecutionUtils.h"
   
   #include <memory>
  @@ -34,7 +35,8 @@ class IncrementalExecutor {
     llvm::orc::ThreadSafeContext &TSCtx;
   
   public:
  -  IncrementalExecutor(llvm::orc::ThreadSafeContext &TSC, llvm::Error &Err);
  +  IncrementalExecutor(llvm::orc::ThreadSafeContext &TSC, llvm::Error &Err,
  +                      const llvm::Triple &Triple);
     ~IncrementalExecutor();
   
     llvm::Error addModule(std::unique_ptr<llvm::Module> M);
  diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp
  index 79acb5bd6898..025bdb14c54f 100644
  --- a/clang/lib/Interpreter/Interpreter.cpp
  +++ b/clang/lib/Interpreter/Interpreter.cpp
  @@ -16,6 +16,7 @@
   #include "IncrementalExecutor.h"
   #include "IncrementalParser.h"
   
  +#include "clang/AST/ASTContext.h"
   #include "clang/Basic/TargetInfo.h"
   #include "clang/CodeGen/ModuleBuilder.h"
   #include "clang/CodeGen/ObjectFilePCHContainerOperations.h"
  @@ -204,8 +205,11 @@ llvm::Expected<Transaction &> Interpreter::Parse(llvm::StringRef Code) {
   llvm::Error Interpreter::Execute(Transaction &T) {
     assert(T.TheModule);
     if (!IncrExecutor) {
  +    const llvm::Triple &Triple =
  +      getCompilerInstance()->getASTContext().getTargetInfo().getTriple();
       llvm::Error Err = llvm::Error::success();
  -    IncrExecutor = std::make_unique<IncrementalExecutor>(*TSCtx, Err);
  +    IncrExecutor = std::make_unique<IncrementalExecutor>(*TSCtx, Err, Triple);
  +
       if (Err)
         return Err;
     }


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96033/new/

https://reviews.llvm.org/D96033



More information about the cfe-commits mailing list