summaryrefslogtreecommitdiffstats
path: root/llvm/examples/Kaleidoscope
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/examples/Kaleidoscope')
-rw-r--r--llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h4
-rw-r--r--llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h68
-rw-r--r--llvm/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h71
-rw-r--r--llvm/examples/Kaleidoscope/BuildingAJIT/Chapter5/toy.cpp9
4 files changed, 76 insertions, 76 deletions
diff --git a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h
index 212dc1c42ff..0db97866cef 100644
--- a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h
+++ b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/KaleidoscopeJIT.h
@@ -76,8 +76,8 @@ public:
[this](std::unique_ptr<Module> M) {
return optimizeModule(std::move(M));
}),
- CompileCallbackManager(
- orc::createLocalCompileCallbackManager(TM->getTargetTriple(), 0)),
+ CompileCallbackManager(orc::createLocalCompileCallbackManager(
+ TM->getTargetTriple(), ES, 0)),
CODLayer(ES, OptimizeLayer,
[&](orc::VModuleKey K) { return Resolvers[K]; },
[&](orc::VModuleKey K, std::shared_ptr<SymbolResolver> R) {
diff --git a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h
index dc8e936afd2..ddd469b9ae2 100644
--- a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h
+++ b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/KaleidoscopeJIT.h
@@ -116,8 +116,8 @@ public:
[this](std::unique_ptr<Module> M) {
return optimizeModule(std::move(M));
}),
- CompileCallbackMgr(
- orc::createLocalCompileCallbackManager(TM->getTargetTriple(), 0)) {
+ CompileCallbackMgr(orc::createLocalCompileCallbackManager(
+ TM->getTargetTriple(), ES, 0)) {
auto IndirectStubsMgrBuilder =
orc::createLocalIndirectStubsManagerBuilder(TM->getTargetTriple());
IndirectStubsMgr = IndirectStubsMgrBuilder();
@@ -134,22 +134,6 @@ public:
}
Error addFunctionAST(std::unique_ptr<FunctionAST> FnAST) {
- // Create a CompileCallback - this is the re-entry point into the compiler
- // for functions that haven't been compiled yet.
- auto CCInfo = cantFail(CompileCallbackMgr->getCompileCallback());
-
- // Create an indirect stub. This serves as the functions "canonical
- // definition" - an unchanging (constant address) entry point to the
- // function implementation.
- // Initially we point the stub's function-pointer at the compile callback
- // that we just created. In the compile action for the callback (see below)
- // we will update the stub's function pointer to point at the function
- // implementation that we just implemented.
- if (auto Err = IndirectStubsMgr->createStub(mangle(FnAST->getName()),
- CCInfo.getAddress(),
- JITSymbolFlags::Exported))
- return Err;
-
// Move ownership of FnAST to a shared pointer - C++11 lambdas don't support
// capture-by-move, which is be required for unique_ptr.
auto SharedFnAST = std::shared_ptr<FunctionAST>(std::move(FnAST));
@@ -170,23 +154,37 @@ public:
// The JIT runtime (the resolver block) will use the return address of
// this function as the address to continue at once it has reset the
// CPU state to what it was immediately before the call.
- CCInfo.setCompileAction(
- [this, SharedFnAST]() {
- auto M = irgenAndTakeOwnership(*SharedFnAST, "$impl");
- addModule(std::move(M));
- auto Sym = findSymbol(SharedFnAST->getName() + "$impl");
- assert(Sym && "Couldn't find compiled function?");
- JITTargetAddress SymAddr = cantFail(Sym.getAddress());
- if (auto Err =
- IndirectStubsMgr->updatePointer(mangle(SharedFnAST->getName()),
- SymAddr)) {
- logAllUnhandledErrors(std::move(Err), errs(),
- "Error updating function pointer: ");
- exit(1);
- }
-
- return SymAddr;
- });
+ auto CompileAction = [this, SharedFnAST]() {
+ auto M = irgenAndTakeOwnership(*SharedFnAST, "$impl");
+ addModule(std::move(M));
+ auto Sym = findSymbol(SharedFnAST->getName() + "$impl");
+ assert(Sym && "Couldn't find compiled function?");
+ JITTargetAddress SymAddr = cantFail(Sym.getAddress());
+ if (auto Err = IndirectStubsMgr->updatePointer(
+ mangle(SharedFnAST->getName()), SymAddr)) {
+ logAllUnhandledErrors(std::move(Err), errs(),
+ "Error updating function pointer: ");
+ exit(1);
+ }
+
+ return SymAddr;
+ };
+
+ // Create a CompileCallback using the CompileAction - this is the re-entry
+ // point into the compiler for functions that haven't been compiled yet.
+ auto CCAddr = cantFail(
+ CompileCallbackMgr->getCompileCallback(std::move(CompileAction)));
+
+ // Create an indirect stub. This serves as the functions "canonical
+ // definition" - an unchanging (constant address) entry point to the
+ // function implementation.
+ // Initially we point the stub's function-pointer at the compile callback
+ // that we just created. When the compile action for the callback is run we
+ // will update the stub's function pointer to point at the function
+ // implementation that we just implemented.
+ if (auto Err = IndirectStubsMgr->createStub(
+ mangle(SharedFnAST->getName()), CCAddr, JITSymbolFlags::Exported))
+ return Err;
return Error::success();
}
diff --git a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h
index e86f3c3c633..010f5436377 100644
--- a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h
+++ b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter5/KaleidoscopeJIT.h
@@ -78,7 +78,7 @@ using MyRemote = remote::OrcRemoteTargetClient;
class KaleidoscopeJIT {
private:
- ExecutionSession ES;
+ ExecutionSession &ES;
std::shared_ptr<SymbolResolver> Resolver;
std::unique_ptr<TargetMachine> TM;
const DataLayout DL;
@@ -95,8 +95,9 @@ private:
MyRemote &Remote;
public:
- KaleidoscopeJIT(MyRemote &Remote)
- : Resolver(createLegacyLookupResolver(
+ KaleidoscopeJIT(ExecutionSession &ES, MyRemote &Remote)
+ : ES(ES),
+ Resolver(createLegacyLookupResolver(
ES,
[this](const std::string &Name) -> JITSymbol {
if (auto Sym = IndirectStubsMgr->findStub(Name, false))
@@ -146,22 +147,6 @@ public:
}
Error addFunctionAST(std::unique_ptr<FunctionAST> FnAST) {
- // Create a CompileCallback - this is the re-entry point into the compiler
- // for functions that haven't been compiled yet.
- auto CCInfo = cantFail(CompileCallbackMgr->getCompileCallback());
-
- // Create an indirect stub. This serves as the functions "canonical
- // definition" - an unchanging (constant address) entry point to the
- // function implementation.
- // Initially we point the stub's function-pointer at the compile callback
- // that we just created. In the compile action for the callback (see below)
- // we will update the stub's function pointer to point at the function
- // implementation that we just implemented.
- if (auto Err = IndirectStubsMgr->createStub(mangle(FnAST->getName()),
- CCInfo.getAddress(),
- JITSymbolFlags::Exported))
- return Err;
-
// Move ownership of FnAST to a shared pointer - C++11 lambdas don't support
// capture-by-move, which is be required for unique_ptr.
auto SharedFnAST = std::shared_ptr<FunctionAST>(std::move(FnAST));
@@ -182,23 +167,37 @@ public:
// The JIT runtime (the resolver block) will use the return address of
// this function as the address to continue at once it has reset the
// CPU state to what it was immediately before the call.
- CCInfo.setCompileAction(
- [this, SharedFnAST]() {
- auto M = irgenAndTakeOwnership(*SharedFnAST, "$impl");
- addModule(std::move(M));
- auto Sym = findSymbol(SharedFnAST->getName() + "$impl");
- assert(Sym && "Couldn't find compiled function?");
- JITTargetAddress SymAddr = cantFail(Sym.getAddress());
- if (auto Err =
- IndirectStubsMgr->updatePointer(mangle(SharedFnAST->getName()),
- SymAddr)) {
- logAllUnhandledErrors(std::move(Err), errs(),
- "Error updating function pointer: ");
- exit(1);
- }
-
- return SymAddr;
- });
+ auto CompileAction = [this, SharedFnAST]() {
+ auto M = irgenAndTakeOwnership(*SharedFnAST, "$impl");
+ addModule(std::move(M));
+ auto Sym = findSymbol(SharedFnAST->getName() + "$impl");
+ assert(Sym && "Couldn't find compiled function?");
+ JITTargetAddress SymAddr = cantFail(Sym.getAddress());
+ if (auto Err = IndirectStubsMgr->updatePointer(
+ mangle(SharedFnAST->getName()), SymAddr)) {
+ logAllUnhandledErrors(std::move(Err), errs(),
+ "Error updating function pointer: ");
+ exit(1);
+ }
+
+ return SymAddr;
+ };
+
+ // Create a CompileCallback suing the CompileAction - this is the re-entry
+ // point into the compiler for functions that haven't been compiled yet.
+ auto CCAddr = cantFail(
+ CompileCallbackMgr->getCompileCallback(std::move(CompileAction)));
+
+ // Create an indirect stub. This serves as the functions "canonical
+ // definition" - an unchanging (constant address) entry point to the
+ // function implementation.
+ // Initially we point the stub's function-pointer at the compile callback
+ // that we just created. In the compile action for the callback we will
+ // update the stub's function pointer to point at the function
+ // implementation that we just implemented.
+ if (auto Err = IndirectStubsMgr->createStub(
+ mangle(SharedFnAST->getName()), CCAddr, JITSymbolFlags::Exported))
+ return Err;
return Error::success();
}
diff --git a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter5/toy.cpp b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter5/toy.cpp
index 10b60bd12d1..415cc751277 100644
--- a/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter5/toy.cpp
+++ b/llvm/examples/Kaleidoscope/BuildingAJIT/Chapter5/toy.cpp
@@ -1243,7 +1243,9 @@ std::unique_ptr<FDRPCChannel> connect() {
sockaddr_in servAddr;
memset(&servAddr, 0, sizeof(servAddr));
servAddr.sin_family = PF_INET;
- memcpy(&servAddr.sin_addr.s_addr, server->h_addr, server->h_length);
+ char *src;
+ memcpy(&src, &server->h_addr, sizeof(char *));
+ memcpy(&servAddr.sin_addr.s_addr, src, server->h_length);
servAddr.sin_port = htons(Port);
if (connect(sockfd, reinterpret_cast<sockaddr*>(&servAddr),
sizeof(servAddr)) < 0) {
@@ -1276,9 +1278,10 @@ int main(int argc, char *argv[]) {
BinopPrecedence['-'] = 20;
BinopPrecedence['*'] = 40; // highest.
+ ExecutionSession ES;
auto TCPChannel = connect();
- auto Remote = ExitOnErr(MyRemote::Create(*TCPChannel, ExitOnErr));
- TheJIT = llvm::make_unique<KaleidoscopeJIT>(*Remote);
+ auto Remote = ExitOnErr(MyRemote::Create(*TCPChannel, ES));
+ TheJIT = llvm::make_unique<KaleidoscopeJIT>(ES, *Remote);
// Automatically inject a definition for 'printExprResult'.
FunctionProtos["printExprResult"] =
OpenPOWER on IntegriCloud