1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

[ORC] Add findSymbolIn() wrapper to C bindings, take #2.

Re-appply r333147, reverted in r333152 due to a pre-existing bug. As
D47308 has been merged in r333206, the OSX issue should now be
resolved.

In many cases JIT users will know in which module a symbol
resides. Avoiding to search other modules can be more efficient. It
also allows to handle duplicate symbol names between modules.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D44889

llvm-svn: 333215
This commit is contained in:
Andres Freund 2018-05-24 18:44:34 +00:00
parent 33474b29b1
commit 5a4700cb8f
4 changed files with 59 additions and 6 deletions

View File

@ -140,6 +140,15 @@ LLVMOrcErrorCode LLVMOrcGetSymbolAddress(LLVMOrcJITStackRef JITStack,
LLVMOrcTargetAddress *RetAddr,
const char *SymbolName);
/**
* Get symbol address from JIT instance, searching only the specified
* handle.
*/
LLVMOrcErrorCode LLVMOrcGetSymbolAddressIn(LLVMOrcJITStackRef JITStack,
LLVMOrcTargetAddress *RetAddr,
LLVMOrcModuleHandle H,
const char *SymbolName);
/**
* Dispose of an ORC JIT stack.
*/

View File

@ -112,6 +112,14 @@ LLVMOrcErrorCode LLVMOrcGetSymbolAddress(LLVMOrcJITStackRef JITStack,
return J.findSymbolAddress(*RetAddr, SymbolName, true);
}
LLVMOrcErrorCode LLVMOrcGetSymbolAddressIn(LLVMOrcJITStackRef JITStack,
LLVMOrcTargetAddress *RetAddr,
LLVMOrcModuleHandle H,
const char *SymbolName) {
OrcCBindingsStack &J = *unwrap(JITStack);
return J.findSymbolAddressIn(*RetAddr, H, SymbolName, true);
}
LLVMOrcErrorCode LLVMOrcDisposeInstance(LLVMOrcJITStackRef JITStack) {
auto *J = unwrap(JITStack);
auto Err = J->shutdown();

View File

@ -380,6 +380,7 @@ public:
JITSymbol findSymbolIn(orc::VModuleKey K, const std::string &Name,
bool ExportedSymbolsOnly) {
assert(KeyLayers.count(K) && "looking up symbol in unknown module");
return KeyLayers[K]->findSymbolIn(K, mangle(Name), ExportedSymbolsOnly);
}
@ -403,6 +404,27 @@ public:
return LLVMOrcErrSuccess;
}
LLVMOrcErrorCode findSymbolAddressIn(JITTargetAddress &RetAddr,
orc::VModuleKey K,
const std::string &Name,
bool ExportedSymbolsOnly) {
RetAddr = 0;
if (auto Sym = findSymbolIn(K, Name, ExportedSymbolsOnly)) {
// Successful lookup, non-null symbol:
if (auto AddrOrErr = Sym.getAddress()) {
RetAddr = *AddrOrErr;
return LLVMOrcErrSuccess;
} else
return mapError(AddrOrErr.takeError());
} else if (auto Err = Sym.takeError()) {
// Lookup failure - report error.
return mapError(std::move(Err));
}
// Otherwise we had a successful lookup but got a null result. We already
// set RetAddr to '0' above, so just return success.
return LLVMOrcErrSuccess;
}
const std::string &getErrorMessage() const { return ErrMsg; }
private:

View File

@ -98,12 +98,26 @@ TEST_F(OrcCAPIExecutionTest, TestEagerIRCompilation) {
LLVMOrcModuleHandle H;
LLVMOrcAddEagerlyCompiledIR(JIT, &H, wrap(M.release()), myResolver, nullptr);
LLVMOrcTargetAddress MainAddr;
LLVMOrcGetSymbolAddress(JIT, &MainAddr, "main");
MainFnTy MainFn = (MainFnTy)MainAddr;
int Result = MainFn();
EXPECT_EQ(Result, 42)
<< "Eagerly JIT'd code did not return expected result";
// get symbol address searching the entire stack
{
LLVMOrcTargetAddress MainAddr;
LLVMOrcGetSymbolAddress(JIT, &MainAddr, "main");
MainFnTy MainFn = (MainFnTy)MainAddr;
int Result = MainFn();
EXPECT_EQ(Result, 42)
<< "Eagerly JIT'd code did not return expected result";
}
// and then just searching a single handle
{
LLVMOrcTargetAddress MainAddr;
LLVMOrcGetSymbolAddressIn(JIT, &MainAddr, H, "main");
MainFnTy MainFn = (MainFnTy)MainAddr;
int Result = MainFn();
EXPECT_EQ(Result, 42)
<< "Eagerly JIT'd code did not return expected result";
}
LLVMOrcRemoveModule(JIT, H);