aboutsummaryrefslogtreecommitdiff
path: root/examples/Kaleidoscope/BuildingAJIT
diff options
context:
space:
mode:
Diffstat (limited to 'examples/Kaleidoscope/BuildingAJIT')
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h8
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp2
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h8
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp2
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h7
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter3/toy.cpp2
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h10
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter4/toy.cpp2
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h25
-rw-r--r--examples/Kaleidoscope/BuildingAJIT/Chapter5/toy.cpp2
10 files changed, 34 insertions, 34 deletions
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h b/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h
index f99722f60e91..5a2148a14a14 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter1/KaleidoscopeJIT.h
@@ -48,6 +48,7 @@ public:
KaleidoscopeJIT()
: TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()),
+ ObjectLayer([]() { return std::make_shared<SectionMemoryManager>(); }),
CompileLayer(ObjectLayer, SimpleCompiler(*TM)) {
llvm::sys::DynamicLibrary::LoadLibraryPermanently(nullptr);
}
@@ -74,9 +75,8 @@ public:
// Add the set to the JIT with the resolver we created above and a newly
// created SectionMemoryManager.
- return CompileLayer.addModule(std::move(M),
- make_unique<SectionMemoryManager>(),
- std::move(Resolver));
+ return cantFail(CompileLayer.addModule(std::move(M),
+ std::move(Resolver)));
}
JITSymbol findSymbol(const std::string Name) {
@@ -87,7 +87,7 @@ public:
}
void removeModule(ModuleHandle H) {
- CompileLayer.removeModule(H);
+ cantFail(CompileLayer.removeModule(H));
}
};
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp b/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp
index 163caa6872d7..2471344c6d65 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp
@@ -1150,7 +1150,7 @@ static void HandleTopLevelExpression() {
// Get the symbol's address and cast it to the right type (takes no
// arguments, returns a double) so we can call it as a native function.
- double (*FP)() = (double (*)())(intptr_t)ExprSymbol.getAddress();
+ double (*FP)() = (double (*)())(intptr_t)cantFail(ExprSymbol.getAddress());
fprintf(stderr, "Evaluated to %f\n", FP());
// Delete the anonymous expression module from the JIT.
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h b/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h
index 2cd4ed79aafa..9a295f1566cb 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter2/KaleidoscopeJIT.h
@@ -57,6 +57,7 @@ public:
KaleidoscopeJIT()
: TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()),
+ ObjectLayer([]() { return std::make_shared<SectionMemoryManager>(); }),
CompileLayer(ObjectLayer, SimpleCompiler(*TM)),
OptimizeLayer(CompileLayer,
[this](std::shared_ptr<Module> M) {
@@ -87,9 +88,8 @@ public:
// 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 cantFail(OptimizeLayer.addModule(std::move(M),
+ std::move(Resolver)));
}
JITSymbol findSymbol(const std::string Name) {
@@ -100,7 +100,7 @@ public:
}
void removeModule(ModuleHandle H) {
- OptimizeLayer.removeModule(H);
+ cantFail(OptimizeLayer.removeModule(H));
}
private:
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp b/examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp
index 163caa6872d7..2471344c6d65 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp
@@ -1150,7 +1150,7 @@ static void HandleTopLevelExpression() {
// Get the symbol's address and cast it to the right type (takes no
// arguments, returns a double) so we can call it as a native function.
- double (*FP)() = (double (*)())(intptr_t)ExprSymbol.getAddress();
+ double (*FP)() = (double (*)())(intptr_t)cantFail(ExprSymbol.getAddress());
fprintf(stderr, "Evaluated to %f\n", FP());
// Delete the anonymous expression module from the JIT.
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h b/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h
index f6fb3071d526..a03f5ce5e238 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h
@@ -63,6 +63,7 @@ public:
KaleidoscopeJIT()
: TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()),
+ ObjectLayer([]() { return std::make_shared<SectionMemoryManager>(); }),
CompileLayer(ObjectLayer, SimpleCompiler(*TM)),
OptimizeLayer(CompileLayer,
[this](std::shared_ptr<Module> M) {
@@ -100,9 +101,7 @@ public:
// Add the set to the JIT with the resolver we created above and a newly
// created SectionMemoryManager.
- return CODLayer.addModule(std::move(M),
- make_unique<SectionMemoryManager>(),
- std::move(Resolver));
+ return cantFail(CODLayer.addModule(std::move(M), std::move(Resolver)));
}
JITSymbol findSymbol(const std::string Name) {
@@ -113,7 +112,7 @@ public:
}
void removeModule(ModuleHandle H) {
- CODLayer.removeModule(H);
+ cantFail(CODLayer.removeModule(H));
}
private:
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter3/toy.cpp b/examples/Kaleidoscope/BuildingAJIT/Chapter3/toy.cpp
index 163caa6872d7..2471344c6d65 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter3/toy.cpp
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter3/toy.cpp
@@ -1150,7 +1150,7 @@ static void HandleTopLevelExpression() {
// Get the symbol's address and cast it to the right type (takes no
// arguments, returns a double) so we can call it as a native function.
- double (*FP)() = (double (*)())(intptr_t)ExprSymbol.getAddress();
+ double (*FP)() = (double (*)())(intptr_t)cantFail(ExprSymbol.getAddress());
fprintf(stderr, "Evaluated to %f\n", FP());
// Delete the anonymous expression module from the JIT.
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h b/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h
index d45874e9a693..d10e4748f1a1 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h
@@ -90,6 +90,7 @@ public:
KaleidoscopeJIT()
: TM(EngineBuilder().selectTarget()),
DL(TM->createDataLayout()),
+ ObjectLayer([]() { return std::make_shared<SectionMemoryManager>(); }),
CompileLayer(ObjectLayer, SimpleCompiler(*TM)),
OptimizeLayer(CompileLayer,
[this](std::shared_ptr<Module> M) {
@@ -127,9 +128,8 @@ public:
// 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 cantFail(OptimizeLayer.addModule(std::move(M),
+ std::move(Resolver)));
}
Error addFunctionAST(std::unique_ptr<FunctionAST> FnAST) {
@@ -175,7 +175,7 @@ public:
addModule(std::move(M));
auto Sym = findSymbol(SharedFnAST->getName() + "$impl");
assert(Sym && "Couldn't find compiled function?");
- JITTargetAddress SymAddr = Sym.getAddress();
+ JITTargetAddress SymAddr = cantFail(Sym.getAddress());
if (auto Err =
IndirectStubsMgr->updatePointer(mangle(SharedFnAST->getName()),
SymAddr)) {
@@ -195,7 +195,7 @@ public:
}
void removeModule(ModuleHandle H) {
- OptimizeLayer.removeModule(H);
+ cantFail(OptimizeLayer.removeModule(H));
}
private:
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter4/toy.cpp b/examples/Kaleidoscope/BuildingAJIT/Chapter4/toy.cpp
index ff4b5220105b..ed8ae31ba0fd 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter4/toy.cpp
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter4/toy.cpp
@@ -1153,7 +1153,7 @@ static void HandleTopLevelExpression() {
// Get the symbol's address and cast it to the right type (takes no
// arguments, returns a double) so we can call it as a native function.
- double (*FP)() = (double (*)())(intptr_t)ExprSymbol.getAddress();
+ double (*FP)() = (double (*)())(intptr_t)cantFail(ExprSymbol.getAddress());
fprintf(stderr, "Evaluated to %f\n", FP());
// Delete the anonymous expression module from the JIT.
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h b/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h
index e889c6d34322..7ea535b3af53 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h
@@ -97,6 +97,15 @@ public:
: TM(EngineBuilder().selectTarget(Triple(Remote.getTargetTriple()), "",
"", SmallVector<std::string, 0>())),
DL(TM->createDataLayout()),
+ ObjectLayer([&Remote]() {
+ std::unique_ptr<MyRemote::RCMemoryManager> MemMgr;
+ if (auto Err = Remote.createRemoteMemoryManager(MemMgr)) {
+ logAllUnhandledErrors(std::move(Err), errs(),
+ "Error creating remote memory manager:");
+ exit(1);
+ }
+ return MemMgr;
+ }),
CompileLayer(ObjectLayer, SimpleCompiler(*TM)),
OptimizeLayer(CompileLayer,
[this](std::shared_ptr<Module> M) {
@@ -146,18 +155,10 @@ public:
return JITSymbol(nullptr);
});
- std::unique_ptr<MyRemote::RCMemoryManager> MemMgr;
- if (auto Err = Remote.createRemoteMemoryManager(MemMgr)) {
- logAllUnhandledErrors(std::move(Err), errs(),
- "Error creating remote memory manager:");
- exit(1);
- }
-
// Add the set to the JIT with the resolver we created above and a newly
// created SectionMemoryManager.
- return OptimizeLayer.addModule(std::move(M),
- std::move(MemMgr),
- std::move(Resolver));
+ return cantFail(OptimizeLayer.addModule(std::move(M),
+ std::move(Resolver)));
}
Error addFunctionAST(std::unique_ptr<FunctionAST> FnAST) {
@@ -203,7 +204,7 @@ public:
addModule(std::move(M));
auto Sym = findSymbol(SharedFnAST->getName() + "$impl");
assert(Sym && "Couldn't find compiled function?");
- JITTargetAddress SymAddr = Sym.getAddress();
+ JITTargetAddress SymAddr = cantFail(Sym.getAddress());
if (auto Err =
IndirectStubsMgr->updatePointer(mangle(SharedFnAST->getName()),
SymAddr)) {
@@ -227,7 +228,7 @@ public:
}
void removeModule(ModuleHandle H) {
- OptimizeLayer.removeModule(H);
+ cantFail(OptimizeLayer.removeModule(H));
}
private:
diff --git a/examples/Kaleidoscope/BuildingAJIT/Chapter5/toy.cpp b/examples/Kaleidoscope/BuildingAJIT/Chapter5/toy.cpp
index edd050959d6b..7bbc06a0958f 100644
--- a/examples/Kaleidoscope/BuildingAJIT/Chapter5/toy.cpp
+++ b/examples/Kaleidoscope/BuildingAJIT/Chapter5/toy.cpp
@@ -1177,7 +1177,7 @@ static void HandleTopLevelExpression() {
// Get the symbol's address and cast it to the right type (takes no
// arguments, returns a double) so we can call it as a native function.
- ExitOnErr(TheJIT->executeRemoteExpr(ExprSymbol.getAddress()));
+ ExitOnErr(TheJIT->executeRemoteExpr(cantFail(ExprSymbol.getAddress())));
// Delete the anonymous expression module from the JIT.
TheJIT->removeModule(H);