summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLang Hames <lhames@gmail.com>2015-02-23 04:45:05 +0000
committerLang Hames <lhames@gmail.com>2015-02-23 04:45:05 +0000
commit203540f2d6f54eec322ec7d4aeefa811ecb2335c (patch)
tree20e7e515b3365b69e82c833786b4ec03ae6f622c
parent193504ac586824391034cacf732742beb853dd38 (diff)
downloadbcm5719-llvm-203540f2d6f54eec322ec7d4aeefa811ecb2335c.tar.gz
bcm5719-llvm-203540f2d6f54eec322ec7d4aeefa811ecb2335c.zip
[Orc][Kaleidoscope] Tidy up the lazy_irgen tutorial, touch up a couple of
comments in the fully_lazy tutorial to minimize the diff between the two. llvm-svn: 230202
-rw-r--r--llvm/examples/Kaleidoscope/Orc/fully_lazy/toy.cpp19
-rw-r--r--llvm/examples/Kaleidoscope/Orc/lazy_irgen/toy.cpp58
2 files changed, 46 insertions, 31 deletions
diff --git a/llvm/examples/Kaleidoscope/Orc/fully_lazy/toy.cpp b/llvm/examples/Kaleidoscope/Orc/fully_lazy/toy.cpp
index 56123bb41e3..840bf6c7b9a 100644
--- a/llvm/examples/Kaleidoscope/Orc/fully_lazy/toy.cpp
+++ b/llvm/examples/Kaleidoscope/Orc/fully_lazy/toy.cpp
@@ -1205,17 +1205,15 @@ public:
return LazyEmitLayer.findSymbol(Name, true);
}
- JITSymbol findSymbol(const std::string &Name) {
- return findMangledSymbol(Mangle(Name));
+ JITSymbol findMangledSymbolIn(ModuleHandleT H, const std::string &Name) {
+ return LazyEmitLayer.findSymbolIn(H, Name, true);
}
- JITSymbol findMangledSymbolIn(LazyEmitLayerT::ModuleSetHandleT H,
- const std::string &Name) {
- return LazyEmitLayer.findSymbolIn(H, Name, true);
+ JITSymbol findSymbol(const std::string &Name) {
+ return findMangledSymbol(Mangle(Name));
}
- JITSymbol findSymbolIn(LazyEmitLayerT::ModuleSetHandleT H,
- const std::string &Name) {
+ JITSymbol findSymbolIn(ModuleHandleT H, const std::string &Name) {
return findMangledSymbolIn(H, Mangle(Name));
}
@@ -1236,7 +1234,8 @@ private:
// FIXME: What happens if IRGen fails?
auto H = irGenStub(std::move(DefI->second));
- // Remove the map entry now that we're done with it.
+ // Remove the function definition's AST now that we're
+ // finished with it.
FunctionDefs.erase(DefI);
// Return the address of the stub.
@@ -1300,9 +1299,9 @@ private:
CompileLayerT CompileLayer;
LazyEmitLayerT LazyEmitLayer;
- JITCompileCallbackManager<LazyEmitLayerT, OrcX86_64> CompileCallbacks;
-
std::map<std::string, std::unique_ptr<FunctionAST>> FunctionDefs;
+
+ JITCompileCallbackManager<LazyEmitLayerT, OrcX86_64> CompileCallbacks;
};
static void HandleDefinition(SessionContext &S, KaleidoscopeJIT &J) {
diff --git a/llvm/examples/Kaleidoscope/Orc/lazy_irgen/toy.cpp b/llvm/examples/Kaleidoscope/Orc/lazy_irgen/toy.cpp
index 162b0e58999..3225a0d93b8 100644
--- a/llvm/examples/Kaleidoscope/Orc/lazy_irgen/toy.cpp
+++ b/llvm/examples/Kaleidoscope/Orc/lazy_irgen/toy.cpp
@@ -6,8 +6,8 @@
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/IRBuilder.h"
-#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/LegacyPassManager.h"
+#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Verifier.h"
#include "llvm/Support/TargetSelect.h"
@@ -685,7 +685,6 @@ public:
LLVMContext& getLLVMContext() const { return Context; }
void addPrototypeAST(std::unique_ptr<PrototypeAST> P);
PrototypeAST* getPrototypeAST(const std::string &Name);
- std::map<std::string, std::unique_ptr<FunctionAST>> FunctionDefs;
private:
typedef std::map<std::string, std::unique_ptr<PrototypeAST>> PrototypeMap;
LLVMContext &Context;
@@ -1174,27 +1173,14 @@ public:
// We need a memory manager to allocate memory and resolve symbols for this
// new module. Create one that resolves symbols by looking back into the JIT.
auto MM = createLookasideRTDyldMM<SectionMemoryManager>(
- [&](const std::string &Name) -> uint64_t {
+ [&](const std::string &Name) {
// First try to find 'Name' within the JIT.
if (auto Symbol = findMangledSymbol(Name))
return Symbol.getAddress();
- // If we don't find 'Name' in the JIT, see if we have some AST
- // for it.
- auto DefI = Session.FunctionDefs.find(Name);
- if (DefI == Session.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?
- addModule(IRGen(Session, *DefI->second));
-
- // Remove the function definition's AST now that we've
- // finished with it.
- Session.FunctionDefs.erase(DefI);
-
- return findMangledSymbol(Name).getAddress();
+ // If we don't already have a definition of 'Name' then search
+ // the ASTs.
+ return searchUncompiledASTs(Name);
},
[](const std::string &S) { return 0; } );
@@ -1204,15 +1190,43 @@ public:
void removeModule(ModuleHandleT H) { LazyEmitLayer.removeModuleSet(H); }
JITSymbol findMangledSymbol(const std::string &Name) {
- return LazyEmitLayer.findSymbol(Name, false);
+ return LazyEmitLayer.findSymbol(Name, true);
+ }
+
+ JITSymbol findMangledSymbolIn(ModuleHandleT H, const std::string &Name) {
+ return LazyEmitLayer.findSymbolIn(H, Name, true);
}
JITSymbol findSymbol(const std::string &Name) {
return findMangledSymbol(Mangle(Name));
}
+ void addFunctionDefinition(std::unique_ptr<FunctionAST> FnAST) {
+ FunctionDefs[Mangle(FnAST->Proto->Name)] = std::move(FnAST);
+ }
+
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) {
+ 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.
+ FunctionDefs.erase(DefI);
+
+ // Return the address of the function.
+ return findMangledSymbolIn(H, Name).getAddress();
+ }
+
std::unique_ptr<TargetMachine> TM;
Mangler Mang;
SessionContext &Session;
@@ -1220,12 +1234,14 @@ private:
ObjLayerT ObjectLayer;
CompileLayerT CompileLayer;
LazyEmitLayerT LazyEmitLayer;
+
+ std::map<std::string, std::unique_ptr<FunctionAST>> FunctionDefs;
};
static void HandleDefinition(SessionContext &S, KaleidoscopeJIT &J) {
if (auto F = ParseDefinition()) {
S.addPrototypeAST(llvm::make_unique<PrototypeAST>(*F->Proto));
- S.FunctionDefs[J.Mangle(F->Proto->Name)] = std::move(F);
+ J.addFunctionDefinition(std::move(F));
} else {
// Skip token for error recovery.
getNextToken();
OpenPOWER on IntegriCloud