diff options
Diffstat (limited to 'examples/Kaleidoscope')
-rw-r--r-- | examples/Kaleidoscope/Chapter4/toy.cpp | 3 | ||||
-rw-r--r-- | examples/Kaleidoscope/Chapter5/toy.cpp | 4 | ||||
-rw-r--r-- | examples/Kaleidoscope/Chapter6/toy.cpp | 4 | ||||
-rw-r--r-- | examples/Kaleidoscope/Chapter7/toy.cpp | 4 | ||||
-rw-r--r-- | examples/Kaleidoscope/Chapter8/toy.cpp | 4 | ||||
-rw-r--r-- | examples/Kaleidoscope/Orc/fully_lazy/toy.cpp | 25 | ||||
-rw-r--r-- | examples/Kaleidoscope/Orc/initial/toy.cpp | 2 | ||||
-rw-r--r-- | examples/Kaleidoscope/Orc/lazy_codegen/toy.cpp | 2 | ||||
-rw-r--r-- | examples/Kaleidoscope/Orc/lazy_irgen/toy.cpp | 23 |
9 files changed, 33 insertions, 38 deletions
diff --git a/examples/Kaleidoscope/Chapter4/toy.cpp b/examples/Kaleidoscope/Chapter4/toy.cpp index 70fe57f..329c3be 100644 --- a/examples/Kaleidoscope/Chapter4/toy.cpp +++ b/examples/Kaleidoscope/Chapter4/toy.cpp @@ -560,8 +560,7 @@ void *MCJITHelper::getPointerToFunction(Function *F) { // Set up the optimizer pipeline. Start with registering info about how the // target lays out data structures. - OpenModule->setDataLayout(NewEngine->getDataLayout()); - FPM->add(new DataLayoutPass()); + OpenModule->setDataLayout(*NewEngine->getDataLayout()); // Provide basic AliasAnalysis support for GVN. FPM->add(createBasicAliasAnalysisPass()); // Promote allocas to registers. diff --git a/examples/Kaleidoscope/Chapter5/toy.cpp b/examples/Kaleidoscope/Chapter5/toy.cpp index 728a2f5..8ebc2bc 100644 --- a/examples/Kaleidoscope/Chapter5/toy.cpp +++ b/examples/Kaleidoscope/Chapter5/toy.cpp @@ -1,3 +1,4 @@ +#include "llvm/ADT/STLExtras.h" #include "llvm/Analysis/Passes.h" #include "llvm/ExecutionEngine/ExecutionEngine.h" #include "llvm/ExecutionEngine/MCJIT.h" @@ -912,8 +913,7 @@ int main() { // Set up the optimizer pipeline. Start with registering info about how the // target lays out data structures. - TheModule->setDataLayout(TheExecutionEngine->getDataLayout()); - OurFPM.add(new DataLayoutPass()); + TheModule->setDataLayout(*TheExecutionEngine->getDataLayout()); // Provide basic AliasAnalysis support for GVN. OurFPM.add(createBasicAliasAnalysisPass()); // Do simple "peephole" optimizations and bit-twiddling optzns. diff --git a/examples/Kaleidoscope/Chapter6/toy.cpp b/examples/Kaleidoscope/Chapter6/toy.cpp index 8131aa1..eb7e8e1 100644 --- a/examples/Kaleidoscope/Chapter6/toy.cpp +++ b/examples/Kaleidoscope/Chapter6/toy.cpp @@ -1,3 +1,4 @@ +#include "llvm/ADT/STLExtras.h" #include "llvm/Analysis/Passes.h" #include "llvm/ExecutionEngine/ExecutionEngine.h" #include "llvm/ExecutionEngine/MCJIT.h" @@ -1033,8 +1034,7 @@ int main() { // Set up the optimizer pipeline. Start with registering info about how the // target lays out data structures. - TheModule->setDataLayout(TheExecutionEngine->getDataLayout()); - OurFPM.add(new DataLayoutPass()); + TheModule->setDataLayout(*TheExecutionEngine->getDataLayout()); // Provide basic AliasAnalysis support for GVN. OurFPM.add(createBasicAliasAnalysisPass()); // Do simple "peephole" optimizations and bit-twiddling optzns. diff --git a/examples/Kaleidoscope/Chapter7/toy.cpp b/examples/Kaleidoscope/Chapter7/toy.cpp index 82f083a..ce5e1dd 100644 --- a/examples/Kaleidoscope/Chapter7/toy.cpp +++ b/examples/Kaleidoscope/Chapter7/toy.cpp @@ -1,3 +1,4 @@ +#include "llvm/ADT/STLExtras.h" #include "llvm/Analysis/Passes.h" #include "llvm/ExecutionEngine/ExecutionEngine.h" #include "llvm/ExecutionEngine/MCJIT.h" @@ -1207,8 +1208,7 @@ int main() { // Set up the optimizer pipeline. Start with registering info about how the // target lays out data structures. - TheModule->setDataLayout(TheExecutionEngine->getDataLayout()); - OurFPM.add(new DataLayoutPass()); + TheModule->setDataLayout(*TheExecutionEngine->getDataLayout()); // Provide basic AliasAnalysis support for GVN. OurFPM.add(createBasicAliasAnalysisPass()); // Promote allocas to registers. diff --git a/examples/Kaleidoscope/Chapter8/toy.cpp b/examples/Kaleidoscope/Chapter8/toy.cpp index 30d4669..39b6a65 100644 --- a/examples/Kaleidoscope/Chapter8/toy.cpp +++ b/examples/Kaleidoscope/Chapter8/toy.cpp @@ -1,3 +1,4 @@ +#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/Triple.h" #include "llvm/Analysis/Passes.h" #include "llvm/ExecutionEngine/ExecutionEngine.h" @@ -1458,8 +1459,7 @@ int main() { // Set up the optimizer pipeline. Start with registering info about how the // target lays out data structures. - TheModule->setDataLayout(TheExecutionEngine->getDataLayout()); - OurFPM.add(new DataLayoutPass()); + TheModule->setDataLayout(*TheExecutionEngine->getDataLayout()); #if 0 // Provide basic AliasAnalysis support for GVN. OurFPM.add(createBasicAliasAnalysisPass()); diff --git a/examples/Kaleidoscope/Orc/fully_lazy/toy.cpp b/examples/Kaleidoscope/Orc/fully_lazy/toy.cpp index 2e65756..3b5dcd0 100644 --- a/examples/Kaleidoscope/Orc/fully_lazy/toy.cpp +++ b/examples/Kaleidoscope/Orc/fully_lazy/toy.cpp @@ -716,7 +716,7 @@ public: M(new Module(GenerateUniqueName("jit_module_"), Session.getLLVMContext())), Builder(Session.getLLVMContext()) { - M->setDataLayout(Session.getTarget().getDataLayout()); + M->setDataLayout(*Session.getTarget().getDataLayout()); } SessionContext& getSession() { return Session; } @@ -1185,7 +1185,8 @@ public: return MangledName; } - void addFunctionDefinition(std::unique_ptr<FunctionAST> FnAST) { + void addFunctionAST(std::unique_ptr<FunctionAST> FnAST) { + std::cerr << "Adding AST: " << FnAST->Proto->Name << "\n"; FunctionDefs[mangle(FnAST->Proto->Name)] = std::move(FnAST); } @@ -1201,7 +1202,7 @@ public: // If we don't already have a definition of 'Name' then search // the ASTs. - return searchUncompiledASTs(Name); + return searchFunctionASTs(Name); }, [](const std::string &S) { return 0; } ); @@ -1231,20 +1232,18 @@ private: // This method searches the FunctionDefs map for a definition of 'Name'. If it // finds one it generates a stub for it and returns the address of the stub. - TargetAddress searchUncompiledASTs(const std::string &Name) { + TargetAddress searchFunctionASTs(const std::string &Name) { auto DefI = FunctionDefs.find(Name); if (DefI == FunctionDefs.end()) return 0; - // We have AST for 'Name'. IRGen a stub for it and add it to the JIT. - // FIXME: What happens if IRGen fails? - auto H = irGenStub(std::move(DefI->second)); - - // Remove the function definition's AST now that we're - // finished with it. + // Return the address of the stub. + // Take the FunctionAST out of the map. + auto FnAST = std::move(DefI->second); FunctionDefs.erase(DefI); - // Return the address of the stub. + // IRGen the AST, add it to the JIT, and return the address for it. + auto H = irGenStub(std::move(FnAST)); return findSymbolIn(H, Name).getAddress(); } @@ -1291,7 +1290,7 @@ private: return findUnmangledSymbolIn(H, Fn->Proto->Name).getAddress(); }); CallbackInfo.setUpdateAction( - CompileCallbacks.getLocalFPUpdater(H, mangle(BodyPtrName))); + getLocalFPUpdater(LazyEmitLayer, H, mangle(BodyPtrName))); return H; } @@ -1310,7 +1309,7 @@ private: static void HandleDefinition(SessionContext &S, KaleidoscopeJIT &J) { if (auto F = ParseDefinition()) { S.addPrototypeAST(llvm::make_unique<PrototypeAST>(*F->Proto)); - J.addFunctionDefinition(std::move(F)); + J.addFunctionAST(std::move(F)); } else { // Skip token for error recovery. getNextToken(); diff --git a/examples/Kaleidoscope/Orc/initial/toy.cpp b/examples/Kaleidoscope/Orc/initial/toy.cpp index 1b65e8c..cc6fb8e 100644 --- a/examples/Kaleidoscope/Orc/initial/toy.cpp +++ b/examples/Kaleidoscope/Orc/initial/toy.cpp @@ -715,7 +715,7 @@ public: M(new Module(GenerateUniqueName("jit_module_"), Session.getLLVMContext())), Builder(Session.getLLVMContext()) { - M->setDataLayout(Session.getTarget().getDataLayout()); + M->setDataLayout(*Session.getTarget().getDataLayout()); } SessionContext& getSession() { return Session; } diff --git a/examples/Kaleidoscope/Orc/lazy_codegen/toy.cpp b/examples/Kaleidoscope/Orc/lazy_codegen/toy.cpp index 1ed267d..6e2ec27 100644 --- a/examples/Kaleidoscope/Orc/lazy_codegen/toy.cpp +++ b/examples/Kaleidoscope/Orc/lazy_codegen/toy.cpp @@ -715,7 +715,7 @@ public: M(new Module(GenerateUniqueName("jit_module_"), Session.getLLVMContext())), Builder(Session.getLLVMContext()) { - M->setDataLayout(Session.getTarget().getDataLayout()); + M->setDataLayout(*Session.getTarget().getDataLayout()); } SessionContext& getSession() { return Session; } diff --git a/examples/Kaleidoscope/Orc/lazy_irgen/toy.cpp b/examples/Kaleidoscope/Orc/lazy_irgen/toy.cpp index d7744ec..19801e1 100644 --- a/examples/Kaleidoscope/Orc/lazy_irgen/toy.cpp +++ b/examples/Kaleidoscope/Orc/lazy_irgen/toy.cpp @@ -715,7 +715,7 @@ public: M(new Module(GenerateUniqueName("jit_module_"), Session.getLLVMContext())), Builder(Session.getLLVMContext()) { - M->setDataLayout(Session.getTarget().getDataLayout()); + M->setDataLayout(*Session.getTarget().getDataLayout()); } SessionContext& getSession() { return Session; } @@ -1174,7 +1174,8 @@ public: return MangledName; } - void addFunctionDefinition(std::unique_ptr<FunctionAST> FnAST) { + void addFunctionAST(std::unique_ptr<FunctionAST> FnAST) { + std::cerr << "Adding AST: " << FnAST->Proto->Name << "\n"; FunctionDefs[mangle(FnAST->Proto->Name)] = std::move(FnAST); } @@ -1190,7 +1191,7 @@ public: // If we don't already have a definition of 'Name' then search // the ASTs. - return searchUncompiledASTs(Name); + return searchFunctionASTs(Name); }, [](const std::string &S) { return 0; } ); @@ -1216,21 +1217,17 @@ private: // This method searches the FunctionDefs map for a definition of 'Name'. If it // finds one it generates a stub for it and returns the address of the stub. - TargetAddress searchUncompiledASTs(const std::string &Name) { + TargetAddress searchFunctionASTs(const std::string &Name) { auto DefI = FunctionDefs.find(Name); if (DefI == FunctionDefs.end()) return 0; - // We have AST for 'Name'. IRGen it, add it to the JIT, and - // return the address for it. - // FIXME: What happens if IRGen fails? - auto H = addModule(IRGen(Session, *DefI->second)); - - // Remove the function definition's AST now that we're - // finished with it. + // Take the FunctionAST out of the map. + auto FnAST = std::move(DefI->second); FunctionDefs.erase(DefI); - // Return the address of the function. + // IRGen the AST, add it to the JIT, and return the address for it. + auto H = addModule(IRGen(Session, *FnAST)); return findSymbolIn(H, Name).getAddress(); } @@ -1246,7 +1243,7 @@ private: static void HandleDefinition(SessionContext &S, KaleidoscopeJIT &J) { if (auto F = ParseDefinition()) { S.addPrototypeAST(llvm::make_unique<PrototypeAST>(*F->Proto)); - J.addFunctionDefinition(std::move(F)); + J.addFunctionAST(std::move(F)); } else { // Skip token for error recovery. getNextToken(); |