diff --git a/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h b/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h --- a/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h @@ -42,6 +42,12 @@ /// compile threads to complete. ~LLJIT(); + /// Set an IR transform (e.g. pass manager pipeline) to run when it is + /// compiled. + void setCompileTransform(IRTransformLayer::TransformFunction Transform) { + TransformLayer->setTransform(std::move(Transform)); + } + /// Returns the ExecutionSession for this instance. ExecutionSession &getExecutionSession() { return *ES; } @@ -145,6 +151,7 @@ std::unique_ptr ObjLinkingLayer; ObjectTransformLayer ObjTransformLayer; std::unique_ptr CompileLayer; + std::unique_ptr TransformLayer; CtorDtorRunner CtorRunner, DtorRunner; }; @@ -182,7 +189,6 @@ LLLazyJIT(LLLazyJITBuilderState &S, Error &Err); std::unique_ptr LCTMgr; - std::unique_ptr TransformLayer; std::unique_ptr CODLayer; }; diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp --- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp +++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp @@ -67,7 +67,7 @@ TSM.withModuleDo([&](Module &M) { return applyDataLayout(M); })) return Err; - return CompileLayer->add(JD, std::move(TSM), ES->allocateVModule()); + return TransformLayer->add(JD, std::move(TSM), ES->allocateVModule()); } Error LLJIT::addObjectFile(JITDylib &JD, std::unique_ptr Obj) { @@ -149,10 +149,13 @@ } CompileLayer = std::make_unique( *ES, ObjTransformLayer, std::move(*CompileFunction)); + + // Create the transform layer. + TransformLayer = std::make_unique(*ES, *CompileLayer); } if (S.NumCompileThreads > 0) { - CompileLayer->setCloneToNewContextOnEmit(true); + TransformLayer->setCloneToNewContextOnEmit(true); CompileThreads = std::make_unique(S.NumCompileThreads); ES->setDispatchMaterialization( [this](JITDylib &JD, std::unique_ptr MU) { @@ -249,9 +252,6 @@ return; } - // Create the transform layer. - TransformLayer = std::make_unique(*ES, *CompileLayer); - // Create the COD layer. CODLayer = std::make_unique( *ES, *TransformLayer, *LCTMgr, std::move(ISMBuilder));