[llvm] 5877d6f - [ORC] Make mangling convenience methods part of the public API of LLJIT.
Lang Hames via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 8 20:20:25 PDT 2020
Author: Lang Hames
Date: 2020-04-08T20:20:13-07:00
New Revision: 5877d6f5f46cb2a61b6887504508fdb4c60fb157
URL: https://github.com/llvm/llvm-project/commit/5877d6f5f46cb2a61b6887504508fdb4c60fb157
DIFF: https://github.com/llvm/llvm-project/commit/5877d6f5f46cb2a61b6887504508fdb4c60fb157.diff
LOG: [ORC] Make mangling convenience methods part of the public API of LLJIT.
This saves clients from having to manually construct a MangleAndInterner.
Added:
Modified:
llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h b/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
index abd34cc9461f..7d38d0884162 100644
--- a/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
+++ b/llvm/include/llvm/ExecutionEngine/Orc/LLJIT.h
@@ -107,7 +107,14 @@ class LLJIT {
/// 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);
+ 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) {
+ 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
@@ -166,6 +173,14 @@ class LLJIT {
/// Returns a reference to the IR compile layer.
IRCompileLayer &getIRCompileLayer() { return *CompileLayer; }
+ /// Returns a linker-mangled version of UnmangledName.
+ std::string mangle(StringRef UnmangledName) const;
+
+ /// Returns an interned, linker-mangled version of UnmangledName.
+ SymbolStringPtr mangleAndIntern(StringRef UnmangledName) const {
+ return ES->intern(mangle(UnmangledName));
+ }
+
protected:
static std::unique_ptr<ObjectLayer>
createObjectLinkingLayer(LLJITBuilderState &S, ExecutionSession &ES);
@@ -176,8 +191,6 @@ class LLJIT {
/// Create an LLJIT instance with a single compile thread.
LLJIT(LLJITBuilderState &S, Error &Err);
- std::string mangle(StringRef UnmangledName);
-
Error applyDataLayout(Module &M);
void recordCtorDtors(Module &M);
diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
index 9a868a6fbac3..e3ca3dbd8ddc 100644
--- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
+++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp
@@ -122,23 +122,22 @@ class GlobalCtorDtorScraper {
class GenericLLVMIRPlatformSupport : public LLJIT::PlatformSupport {
public:
// GenericLLVMIRPlatform &P) : P(P) {
- GenericLLVMIRPlatformSupport(LLJIT &J) : J(J) {
-
- MangleAndInterner Mangle(getExecutionSession(), J.getDataLayout());
- InitFunctionPrefix = Mangle("__orc_init_func.");
+ GenericLLVMIRPlatformSupport(LLJIT &J)
+ : J(J), InitFunctionPrefix(J.mangle("__orc_init_func.")) {
getExecutionSession().setPlatform(
std::make_unique<GenericLLVMIRPlatform>(*this));
- setInitTransform(J, GlobalCtorDtorScraper(*this, *InitFunctionPrefix));
+ setInitTransform(J, GlobalCtorDtorScraper(*this, InitFunctionPrefix));
SymbolMap StdInterposes;
- StdInterposes[Mangle("__lljit.platform_support_instance")] =
+ StdInterposes[J.mangleAndIntern("__lljit.platform_support_instance")] =
JITEvaluatedSymbol(pointerToJITTargetAddress(this),
JITSymbolFlags::Exported);
- StdInterposes[Mangle("__lljit.cxa_atexit_helper")] = JITEvaluatedSymbol(
- pointerToJITTargetAddress(registerAtExitHelper), JITSymbolFlags());
+ StdInterposes[J.mangleAndIntern("__lljit.cxa_atexit_helper")] =
+ JITEvaluatedSymbol(pointerToJITTargetAddress(registerAtExitHelper),
+ JITSymbolFlags());
cantFail(
J.getMainJITDylib().define(absoluteSymbols(std::move(StdInterposes))));
@@ -152,10 +151,10 @@ class GenericLLVMIRPlatformSupport : public LLJIT::PlatformSupport {
Error setupJITDylib(JITDylib &JD) {
// Add per-jitdylib standard interposes.
- MangleAndInterner Mangle(getExecutionSession(), J.getDataLayout());
SymbolMap PerJDInterposes;
- PerJDInterposes[Mangle("__lljit.run_atexits_helper")] = JITEvaluatedSymbol(
- pointerToJITTargetAddress(runAtExitsHelper), JITSymbolFlags());
+ PerJDInterposes[J.mangleAndIntern("__lljit.run_atexits_helper")] =
+ JITEvaluatedSymbol(pointerToJITTargetAddress(runAtExitsHelper),
+ JITSymbolFlags());
cantFail(JD.define(absoluteSymbols(std::move(PerJDInterposes))));
auto Ctx = std::make_unique<LLVMContext>();
@@ -197,7 +196,7 @@ class GenericLLVMIRPlatformSupport : public LLJIT::PlatformSupport {
// will trigger a lookup to materialize the module) and the InitFunctions
// map (which holds the names of the symbols to execute).
for (auto &KV : MU.getSymbols())
- if ((*KV.first).startswith(*InitFunctionPrefix)) {
+ if ((*KV.first).startswith(InitFunctionPrefix)) {
InitSymbols[&JD].add(KV.first,
SymbolLookupFlags::WeaklyReferencedSymbol);
InitFunctions[&JD].add(KV.first);
@@ -308,8 +307,7 @@ class GenericLLVMIRPlatformSupport : public LLJIT::PlatformSupport {
Expected<std::vector<JITTargetAddress>> getDeinitializers(JITDylib &JD) {
auto &ES = getExecutionSession();
- MangleAndInterner Mangle(getExecutionSession(), J.getDataLayout());
- auto LLJITRunAtExits = Mangle("__lljit_run_atexits");
+ auto LLJITRunAtExits = J.mangleAndIntern("__lljit_run_atexits");
DenseMap<JITDylib *, SymbolLookupSet> LookupSymbols;
std::vector<JITDylib *> DFSLinkOrder;
@@ -459,7 +457,7 @@ class GenericLLVMIRPlatformSupport : public LLJIT::PlatformSupport {
}
LLJIT &J;
- SymbolStringPtr InitFunctionPrefix;
+ std::string InitFunctionPrefix;
DenseMap<JITDylib *, SymbolLookupSet> InitSymbols;
DenseMap<JITDylib *, SymbolLookupSet> InitFunctions;
DenseMap<JITDylib *, SymbolLookupSet> DeInitFunctions;
@@ -653,26 +651,31 @@ class MachOPlatformSupport : public LLJIT::PlatformSupport {
MachOPlatformSupport(LLJIT &J, JITDylib &PlatformJITDylib, DlFcnValues DlFcn)
: J(J), MP(setupPlatform(J)), DlFcn(std::move(DlFcn)) {
- MangleAndInterner Mangle(J.getExecutionSession(), J.getDataLayout());
SymbolMap HelperSymbols;
// platform and atexit helpers.
- HelperSymbols[Mangle("__lljit.platform_support_instance")] =
+ HelperSymbols[J.mangleAndIntern("__lljit.platform_support_instance")] =
JITEvaluatedSymbol(pointerToJITTargetAddress(this), JITSymbolFlags());
- HelperSymbols[Mangle("__lljit.cxa_atexit_helper")] = JITEvaluatedSymbol(
- pointerToJITTargetAddress(registerAtExitHelper), JITSymbolFlags());
- HelperSymbols[Mangle("__lljit.run_atexits_helper")] = JITEvaluatedSymbol(
- pointerToJITTargetAddress(runAtExitsHelper), JITSymbolFlags());
+ HelperSymbols[J.mangleAndIntern("__lljit.cxa_atexit_helper")] =
+ JITEvaluatedSymbol(pointerToJITTargetAddress(registerAtExitHelper),
+ JITSymbolFlags());
+ HelperSymbols[J.mangleAndIntern("__lljit.run_atexits_helper")] =
+ JITEvaluatedSymbol(pointerToJITTargetAddress(runAtExitsHelper),
+ JITSymbolFlags());
// dlfcn helpers.
- HelperSymbols[Mangle("__lljit.dlopen_helper")] = JITEvaluatedSymbol(
- pointerToJITTargetAddress(dlopenHelper), JITSymbolFlags());
- HelperSymbols[Mangle("__lljit.dlclose_helper")] = JITEvaluatedSymbol(
- pointerToJITTargetAddress(dlcloseHelper), JITSymbolFlags());
- HelperSymbols[Mangle("__lljit.dlsym_helper")] = JITEvaluatedSymbol(
- pointerToJITTargetAddress(dlsymHelper), JITSymbolFlags());
- HelperSymbols[Mangle("__lljit.dlerror_helper")] = JITEvaluatedSymbol(
- pointerToJITTargetAddress(dlerrorHelper), JITSymbolFlags());
+ HelperSymbols[J.mangleAndIntern("__lljit.dlopen_helper")] =
+ JITEvaluatedSymbol(pointerToJITTargetAddress(dlopenHelper),
+ JITSymbolFlags());
+ HelperSymbols[J.mangleAndIntern("__lljit.dlclose_helper")] =
+ JITEvaluatedSymbol(pointerToJITTargetAddress(dlcloseHelper),
+ JITSymbolFlags());
+ HelperSymbols[J.mangleAndIntern("__lljit.dlsym_helper")] =
+ JITEvaluatedSymbol(pointerToJITTargetAddress(dlsymHelper),
+ JITSymbolFlags());
+ HelperSymbols[J.mangleAndIntern("__lljit.dlerror_helper")] =
+ JITEvaluatedSymbol(pointerToJITTargetAddress(dlerrorHelper),
+ JITSymbolFlags());
cantFail(
PlatformJITDylib.define(absoluteSymbols(std::move(HelperSymbols))));
@@ -859,8 +862,7 @@ class MachOPlatformSupport : public LLJIT::PlatformSupport {
}
if (!JITSymSearchOrder.empty()) {
- MangleAndInterner Mangle(J.getExecutionSession(), J.getDataLayout());
- auto MangledName = Mangle(Name);
+ auto MangledName = J.mangleAndIntern(Name);
SymbolLookupSet Syms(MangledName,
SymbolLookupFlags::WeaklyReferencedSymbol);
if (auto Result = J.getExecutionSession().lookup(JITSymSearchOrder, Syms,
@@ -987,10 +989,9 @@ Error LLJIT::addObjectFile(JITDylib &JD, std::unique_ptr<MemoryBuffer> Obj) {
}
Expected<JITEvaluatedSymbol> LLJIT::lookupLinkerMangled(JITDylib &JD,
- StringRef Name) {
+ SymbolStringPtr Name) {
return ES->lookup(
- makeJITDylibSearchOrder(&JD, JITDylibLookupFlags::MatchAllSymbols),
- ES->intern(Name));
+ makeJITDylibSearchOrder(&JD, JITDylibLookupFlags::MatchAllSymbols), Name);
}
std::unique_ptr<ObjectLayer>
@@ -1093,7 +1094,7 @@ LLJIT::LLJIT(LLJITBuilderState &S, Error &Err)
setUpGenericLLVMIRPlatform(*this);
}
-std::string LLJIT::mangle(StringRef UnmangledName) {
+std::string LLJIT::mangle(StringRef UnmangledName) const {
std::string MangledName;
{
raw_string_ostream MangledNameStream(MangledName);
More information about the llvm-commits
mailing list