forked from OSchip/llvm-project
[ORC] Return ExecutorAddrs rather than JITEvaluatedSymbols from LLJIT::lookup.
Clients don't care about linkage, and ExecutorAddr is much more ergonomic.
This commit is contained in:
parent
b226894d47
commit
16dcbb53dc
|
@ -68,7 +68,7 @@ IncrementalExecutor::getSymbolAddress(llvm::StringRef Name,
|
|||
|
||||
if (!Sym)
|
||||
return Sym.takeError();
|
||||
return Sym->getAddress();
|
||||
return Sym->getValue();
|
||||
}
|
||||
|
||||
} // end namespace clang
|
||||
|
|
|
@ -91,8 +91,8 @@ int main(int argc, char *argv[]) {
|
|||
ExitOnErr(J->addIRModule(std::move(M)));
|
||||
|
||||
// Look up the JIT'd function, cast it to a function pointer, then call it.
|
||||
auto Add1Sym = ExitOnErr(J->lookup("add1"));
|
||||
int (*Add1)(int) = (int (*)(int))Add1Sym.getAddress();
|
||||
auto Add1Addr = ExitOnErr(J->lookup("add1"));
|
||||
int (*Add1)(int) = Add1Addr.toPtr<int(int)>();
|
||||
|
||||
int Result = Add1(42);
|
||||
outs() << "add1(42) = " << Result << "\n";
|
||||
|
|
|
@ -61,8 +61,8 @@ int main(int argc, char *argv[]) {
|
|||
ExitOnErr(J->addIRModule(std::move(M)));
|
||||
|
||||
// Look up the JIT'd function, cast it to a function pointer, then call it.
|
||||
auto Add1Sym = ExitOnErr(J->lookup("add1"));
|
||||
int (*Add1)(int) = (int (*)(int))Add1Sym.getAddress();
|
||||
auto Add1Addr = ExitOnErr(J->lookup("add1"));
|
||||
int (*Add1)(int) = Add1Addr.toPtr<int(int)>();
|
||||
|
||||
int Result = Add1(42);
|
||||
outs() << "add1(42) = " << Result << "\n";
|
||||
|
|
|
@ -92,7 +92,7 @@ int main(int argc, char *argv[]) {
|
|||
auto PrintSymbol = [&](StringRef Name) {
|
||||
dbgs() << Name << " = ";
|
||||
if (auto Sym = J->lookup(JD, Name))
|
||||
dbgs() << formatv("{0:x}\n", Sym->getAddress());
|
||||
dbgs() << *Sym;
|
||||
else
|
||||
dbgs() << "error: " << toString(Sym.takeError()) << "\n";
|
||||
};
|
||||
|
|
|
@ -56,8 +56,8 @@ int main(int argc, char *argv[]) {
|
|||
ExitOnErr(J->addIRModule(std::move(M)));
|
||||
|
||||
// Look up the JIT'd function, cast it to a function pointer, then call it.
|
||||
auto Add1Sym = ExitOnErr(J->lookup("add1"));
|
||||
int (*Add1)(int) = (int (*)(int))Add1Sym.getAddress();
|
||||
auto Add1Addr = ExitOnErr(J->lookup("add1"));
|
||||
int (*Add1)(int) = Add1Addr.toPtr<int(int)>();
|
||||
|
||||
int Result = Add1(42);
|
||||
outs() << "add1(42) = " << Result << "\n";
|
||||
|
|
|
@ -187,8 +187,8 @@ int main(int argc, char *argv[]) {
|
|||
// arguments passed.
|
||||
|
||||
// Look up the JIT'd function, cast it to a function pointer, then call it.
|
||||
auto EntrySym = ExitOnErr(J->lookup("entry"));
|
||||
auto *Entry = (int (*)(int))EntrySym.getAddress();
|
||||
auto EntryAddr = ExitOnErr(J->lookup("entry"));
|
||||
auto *Entry = EntryAddr.toPtr<int(int)>();
|
||||
|
||||
int Result = Entry(argc);
|
||||
outs() << "---Result---\n"
|
||||
|
|
|
@ -108,9 +108,8 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
// Look up the entry point, cast it to a C main function pointer, then use
|
||||
// runAsMain to call it.
|
||||
auto EntrySym = ExitOnErr(J->lookup(EntryPointName));
|
||||
auto EntryFn =
|
||||
jitTargetAddressToFunction<int (*)(int, char *[])>(EntrySym.getAddress());
|
||||
auto EntryAddr = ExitOnErr(J->lookup(EntryPointName));
|
||||
auto EntryFn = EntryAddr.toPtr<int(int, char *[])>();
|
||||
|
||||
return runAsMain(EntryFn, InputArgv, StringRef(InputFiles.front()));
|
||||
}
|
||||
|
|
|
@ -152,8 +152,8 @@ int main(int argc, char *argv[]) {
|
|||
// arguments passed.
|
||||
|
||||
// Look up the JIT'd function, cast it to a function pointer, then call it.
|
||||
auto EntrySym = ExitOnErr(J->lookup("entry"));
|
||||
auto *Entry = (int (*)(int))EntrySym.getAddress();
|
||||
auto EntryAddr = ExitOnErr(J->lookup("entry"));
|
||||
auto *Entry = EntryAddr.toPtr<int(int)>();
|
||||
|
||||
int Result = Entry(argc);
|
||||
outs() << "---Result---\n"
|
||||
|
|
|
@ -69,8 +69,8 @@ void runJITWithCache(ObjectCache &ObjCache) {
|
|||
ExitOnErr(J->addIRModule(std::move(M)));
|
||||
|
||||
// Look up the JIT'd function, cast it to a function pointer, then call it.
|
||||
auto Add1Sym = ExitOnErr(J->lookup("add1"));
|
||||
int (*Add1)(int) = (int (*)(int))Add1Sym.getAddress();
|
||||
auto Add1Addr = ExitOnErr(J->lookup("add1"));
|
||||
int (*Add1)(int) = Add1Addr.toPtr<int(int)>();
|
||||
|
||||
int Result = Add1(42);
|
||||
outs() << "add1(42) = " << Result << "\n";
|
||||
|
|
|
@ -241,8 +241,8 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
// Look up the JIT'd function, cast it to a function pointer, then call it.
|
||||
auto EntrySym = ExitOnErr(J->lookup(EntryPointName));
|
||||
auto *Entry = (int (*)())EntrySym.getAddress();
|
||||
auto EntryAddr = ExitOnErr(J->lookup(EntryPointName));
|
||||
auto *Entry = EntryAddr.toPtr<int()>();
|
||||
|
||||
int Result = Entry();
|
||||
outs() << "---Result---\n"
|
||||
|
|
|
@ -112,8 +112,8 @@ int main(int argc, char *argv[]) {
|
|||
ExitOnErr(J->addIRModule(ExitOnErr(parseExampleModule(MainMod, "MainMod"))));
|
||||
|
||||
// (4) Look up the JIT'd function and call it.
|
||||
auto EntrySym = ExitOnErr(J->lookup("entry"));
|
||||
auto *Entry = (int (*)())EntrySym.getAddress();
|
||||
auto EntryAddr = ExitOnErr(J->lookup("entry"));
|
||||
auto *Entry = EntryAddr.toPtr<int()>();
|
||||
|
||||
int Result = Entry();
|
||||
outs() << "--- Result ---\n"
|
||||
|
|
|
@ -223,7 +223,7 @@ int main(int argc, char *argv[]) {
|
|||
// The example uses a non-lazy JIT for simplicity. Thus, looking up the main
|
||||
// function will materialize all reachable code. It also triggers debug
|
||||
// registration in the remote target process.
|
||||
JITEvaluatedSymbol MainFn = ExitOnErr(J->lookup("main"));
|
||||
auto MainAddr = ExitOnErr(J->lookup("main"));
|
||||
|
||||
outs() << "Running: main(";
|
||||
int Pos = 0;
|
||||
|
@ -238,10 +238,9 @@ int main(int argc, char *argv[]) {
|
|||
// the debugger attached to the target, it should be possible to inspect the
|
||||
// JITed code as if it was compiled statically.
|
||||
{
|
||||
JITTargetAddress MainFnAddr = MainFn.getAddress();
|
||||
ExecutorProcessControl &EPC =
|
||||
J->getExecutionSession().getExecutorProcessControl();
|
||||
int Result = ExitOnErr(EPC.runAsMain(ExecutorAddr(MainFnAddr), ActualArgv));
|
||||
int Result = ExitOnErr(EPC.runAsMain(MainAddr, ActualArgv));
|
||||
outs() << "Exit code: " << Result << "\n";
|
||||
}
|
||||
|
||||
|
|
|
@ -227,11 +227,10 @@ int main(int Argc, char *Argv[]) {
|
|||
}
|
||||
|
||||
// (5) Look up and run the JIT'd function.
|
||||
auto MainSym = ExitOnErr(J->lookup(MainFunctionName));
|
||||
auto MainAddr = ExitOnErr(J->lookup(MainFunctionName));
|
||||
|
||||
using MainFnPtr = int (*)(int, char *[]);
|
||||
MainFnPtr MainFunction =
|
||||
jitTargetAddressToFunction<MainFnPtr>(MainSym.getAddress());
|
||||
auto *MainFunction = MainAddr.toPtr<MainFnPtr>();
|
||||
|
||||
int Result = runAsMain(MainFunction, {}, MainModulePath);
|
||||
outs() << "'" << MainFunctionName << "' finished with exit code: " << Result
|
||||
|
|
|
@ -110,30 +110,30 @@ public:
|
|||
|
||||
/// Look up a symbol in JITDylib JD by the symbol's linker-mangled name (to
|
||||
/// look up symbols based on their IR name use the lookup function instead).
|
||||
Expected<JITEvaluatedSymbol> lookupLinkerMangled(JITDylib &JD,
|
||||
SymbolStringPtr Name);
|
||||
Expected<ExecutorAddr> lookupLinkerMangled(JITDylib &JD,
|
||||
SymbolStringPtr Name);
|
||||
|
||||
/// Look up a symbol in JITDylib JD by the symbol's linker-mangled name (to
|
||||
/// look up symbols based on their IR name use the lookup function instead).
|
||||
Expected<JITEvaluatedSymbol> lookupLinkerMangled(JITDylib &JD,
|
||||
StringRef Name) {
|
||||
Expected<ExecutorAddr> lookupLinkerMangled(JITDylib &JD,
|
||||
StringRef Name) {
|
||||
return lookupLinkerMangled(JD, ES->intern(Name));
|
||||
}
|
||||
|
||||
/// Look up a symbol in the main JITDylib by the symbol's linker-mangled name
|
||||
/// (to look up symbols based on their IR name use the lookup function
|
||||
/// instead).
|
||||
Expected<JITEvaluatedSymbol> lookupLinkerMangled(StringRef Name) {
|
||||
Expected<ExecutorAddr> lookupLinkerMangled(StringRef Name) {
|
||||
return lookupLinkerMangled(*Main, Name);
|
||||
}
|
||||
|
||||
/// Look up a symbol in JITDylib JD based on its IR symbol name.
|
||||
Expected<JITEvaluatedSymbol> lookup(JITDylib &JD, StringRef UnmangledName) {
|
||||
Expected<ExecutorAddr> lookup(JITDylib &JD, StringRef UnmangledName) {
|
||||
return lookupLinkerMangled(JD, mangle(UnmangledName));
|
||||
}
|
||||
|
||||
/// Look up a symbol in the main JITDylib based on its IR symbol name.
|
||||
Expected<JITEvaluatedSymbol> lookup(StringRef UnmangledName) {
|
||||
Expected<ExecutorAddr> lookup(StringRef UnmangledName) {
|
||||
return lookup(*Main, UnmangledName);
|
||||
}
|
||||
|
||||
|
@ -401,7 +401,7 @@ public:
|
|||
std::function<std::unique_ptr<IndirectStubsManager>()>;
|
||||
|
||||
Triple TT;
|
||||
JITTargetAddress LazyCompileFailureAddr = 0;
|
||||
ExecutorAddr LazyCompileFailureAddr;
|
||||
std::unique_ptr<LazyCallThroughManager> LCTMgr;
|
||||
IndirectStubsManagerBuilderFunction ISMBuilder;
|
||||
|
||||
|
@ -415,7 +415,7 @@ public:
|
|||
/// Set the address in the target address to call if a lazy compile fails.
|
||||
///
|
||||
/// If this method is not called then the value will default to 0.
|
||||
SetterImpl &setLazyCompileFailureAddr(JITTargetAddress Addr) {
|
||||
SetterImpl &setLazyCompileFailureAddr(ExecutorAddr Addr) {
|
||||
this->impl().LazyCompileFailureAddr = Addr;
|
||||
return this->impl();
|
||||
}
|
||||
|
|
|
@ -701,10 +701,14 @@ Error LLJIT::addObjectFile(JITDylib &JD, std::unique_ptr<MemoryBuffer> Obj) {
|
|||
return addObjectFile(JD.getDefaultResourceTracker(), std::move(Obj));
|
||||
}
|
||||
|
||||
Expected<JITEvaluatedSymbol> LLJIT::lookupLinkerMangled(JITDylib &JD,
|
||||
SymbolStringPtr Name) {
|
||||
return ES->lookup(
|
||||
makeJITDylibSearchOrder(&JD, JITDylibLookupFlags::MatchAllSymbols), Name);
|
||||
Expected<ExecutorAddr> LLJIT::lookupLinkerMangled(JITDylib &JD,
|
||||
SymbolStringPtr Name) {
|
||||
if (auto Sym = ES->lookup(
|
||||
makeJITDylibSearchOrder(&JD, JITDylibLookupFlags::MatchAllSymbols),
|
||||
Name))
|
||||
return ExecutorAddr(Sym->getAddress());
|
||||
else
|
||||
return Sym.takeError();
|
||||
}
|
||||
|
||||
Expected<std::unique_ptr<ObjectLayer>>
|
||||
|
@ -897,7 +901,7 @@ LLLazyJIT::LLLazyJIT(LLLazyJITBuilderState &S, Error &Err) : LLJIT(S, Err) {
|
|||
LCTMgr = std::move(S.LCTMgr);
|
||||
else {
|
||||
if (auto LCTMgrOrErr = createLocalLazyCallThroughManager(
|
||||
S.TT, *ES, S.LazyCompileFailureAddr))
|
||||
S.TT, *ES, S.LazyCompileFailureAddr.getValue()))
|
||||
LCTMgr = std::move(*LCTMgrOrErr);
|
||||
else {
|
||||
Err = LCTMgrOrErr.takeError();
|
||||
|
|
|
@ -951,7 +951,7 @@ LLVMErrorRef LLVMOrcLLJITLookup(LLVMOrcLLJITRef J,
|
|||
return wrap(Sym.takeError());
|
||||
}
|
||||
|
||||
*Result = Sym->getAddress();
|
||||
*Result = Sym->getValue();
|
||||
return LLVMErrorSuccess;
|
||||
}
|
||||
|
||||
|
|
|
@ -881,7 +881,7 @@ int runOrcJIT(const char *ProgName) {
|
|||
}
|
||||
|
||||
Builder.setLazyCompileFailureAddr(
|
||||
pointerToJITTargetAddress(exitOnLazyCallThroughFailure));
|
||||
orc::ExecutorAddr::fromPtr(exitOnLazyCallThroughFailure));
|
||||
Builder.setNumCompileThreads(LazyJITCompileThreads);
|
||||
|
||||
// If the object cache is enabled then set a custom compile function
|
||||
|
@ -1049,23 +1049,21 @@ int runOrcJIT(const char *ProgName) {
|
|||
for (auto &ThreadEntryPoint : ThreadEntryPoints) {
|
||||
auto EntryPointSym = ExitOnErr(J->lookup(ThreadEntryPoint));
|
||||
typedef void (*EntryPointPtr)();
|
||||
auto EntryPoint =
|
||||
reinterpret_cast<EntryPointPtr>(static_cast<uintptr_t>(EntryPointSym.getAddress()));
|
||||
auto EntryPoint = EntryPointSym.toPtr<EntryPointPtr>();
|
||||
AltEntryThreads.push_back(std::thread([EntryPoint]() { EntryPoint(); }));
|
||||
}
|
||||
|
||||
// Resolve and run the main function.
|
||||
JITEvaluatedSymbol MainSym = ExitOnErr(J->lookup(EntryFunc));
|
||||
auto MainAddr = ExitOnErr(J->lookup(EntryFunc));
|
||||
int Result;
|
||||
|
||||
if (EPC) {
|
||||
// ExecutorProcessControl-based execution with JITLink.
|
||||
Result = ExitOnErr(
|
||||
EPC->runAsMain(orc::ExecutorAddr(MainSym.getAddress()), InputArgv));
|
||||
Result = ExitOnErr(EPC->runAsMain(MainAddr, InputArgv));
|
||||
} else {
|
||||
// Manual in-process execution with RuntimeDyld.
|
||||
using MainFnTy = int(int, char *[]);
|
||||
auto MainFn = jitTargetAddressToFunction<MainFnTy *>(MainSym.getAddress());
|
||||
auto MainFn = MainAddr.toPtr<MainFnTy *>();
|
||||
Result = orc::runAsMain(MainFn, InputArgv, StringRef(InputFile));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue