diff options
Diffstat (limited to 'examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h')
-rw-r--r-- | examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h b/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h index d45874e9a69..58642237d4f 100644 --- a/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h +++ b/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h @@ -77,7 +77,7 @@ private: IRCompileLayer<decltype(ObjectLayer), SimpleCompiler> CompileLayer; using OptimizeFunction = - std::function<std::shared_ptr<Module>(std::shared_ptr<Module>)>; + std::function<std::unique_ptr<Module>(std::unique_ptr<Module>)>; IRTransformLayer<decltype(CompileLayer), OptimizeFunction> OptimizeLayer; @@ -85,14 +85,14 @@ private: std::unique_ptr<IndirectStubsManager> IndirectStubsMgr; public: - using ModuleHandle = decltype(OptimizeLayer)::ModuleHandleT; + using ModuleHandle = decltype(OptimizeLayer)::ModuleSetHandleT; KaleidoscopeJIT() : TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()), CompileLayer(ObjectLayer, SimpleCompiler(*TM)), OptimizeLayer(CompileLayer, - [this](std::shared_ptr<Module> M) { + [this](std::unique_ptr<Module> M) { return optimizeModule(std::move(M)); }), CompileCallbackMgr( @@ -125,11 +125,15 @@ public: return JITSymbol(nullptr); }); + // Build a singleton module set to hold our module. + std::vector<std::unique_ptr<Module>> Ms; + Ms.push_back(std::move(M)); + // Add the set to the JIT with the resolver we created above and a newly // created SectionMemoryManager. - return OptimizeLayer.addModule(std::move(M), - make_unique<SectionMemoryManager>(), - std::move(Resolver)); + return OptimizeLayer.addModuleSet(std::move(Ms), + make_unique<SectionMemoryManager>(), + std::move(Resolver)); } Error addFunctionAST(std::unique_ptr<FunctionAST> FnAST) { @@ -195,7 +199,7 @@ public: } void removeModule(ModuleHandle H) { - OptimizeLayer.removeModule(H); + OptimizeLayer.removeModuleSet(H); } private: @@ -206,7 +210,7 @@ private: return MangledNameStream.str(); } - std::shared_ptr<Module> optimizeModule(std::shared_ptr<Module> M) { + std::unique_ptr<Module> optimizeModule(std::unique_ptr<Module> M) { // Create a function pass manager. auto FPM = llvm::make_unique<legacy::FunctionPassManager>(M.get()); |