From: Lang Hames Date: Sun, 30 Sep 2018 23:18:24 +0000 (+0000) Subject: [ORC] Add an 'intern' method to ExecutionEngine for interning symbol names. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=71d781c4344c644622539e65ae1a3693d01c4ebe;p=platform%2Fupstream%2Fllvm.git [ORC] Add an 'intern' method to ExecutionEngine for interning symbol names. This cuts down on boilerplate by reducing 'ES.getSymbolStringPool().intern(...)' to 'ES.intern(...)'. llvm-svn: 343427 --- diff --git a/llvm/include/llvm/ExecutionEngine/Orc/Core.h b/llvm/include/llvm/ExecutionEngine/Orc/Core.h index f0a599e..50c73ab 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/Core.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/Core.h @@ -661,8 +661,11 @@ public: /// SymbolStringPools may be shared between ExecutionSessions. ExecutionSession(std::shared_ptr SSP = nullptr); - /// Returns the SymbolStringPool for this ExecutionSession. - SymbolStringPool &getSymbolStringPool() const { return *SSP; } + /// Add a symbol name to the SymbolStringPool and return a pointer to it. + SymbolStringPtr intern(StringRef SymName) { return SSP->intern(SymName); } + + /// Returns a shared_ptr to the SymbolStringPool for this ExecutionSession. + std::shared_ptr getSymbolStringPool() const { return SSP; } /// Run the given lambda with the session mutex locked. template auto runSessionLocked(Func &&F) -> decltype(F()) { diff --git a/llvm/lib/ExecutionEngine/Orc/Core.cpp b/llvm/lib/ExecutionEngine/Orc/Core.cpp index 193a5d8..34cfe02 100644 --- a/llvm/lib/ExecutionEngine/Orc/Core.cpp +++ b/llvm/lib/ExecutionEngine/Orc/Core.cpp @@ -1873,7 +1873,7 @@ SymbolStringPtr MangleAndInterner::operator()(StringRef Name) { raw_string_ostream MangledNameStream(MangledName); Mangler::getNameWithPrefix(MangledNameStream, Name, DL); } - return ES.getSymbolStringPool().intern(MangledName); + return ES.intern(MangledName); } } // End namespace orc. diff --git a/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp b/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp index d0c7095..962ae33 100644 --- a/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp +++ b/llvm/lib/ExecutionEngine/Orc/IndirectionUtils.cpp @@ -60,8 +60,8 @@ void TrampolinePool::anchor() {} Expected JITCompileCallbackManager::getCompileCallback(CompileFunction Compile) { if (auto TrampolineAddr = TP->getTrampoline()) { - auto CallbackName = ES.getSymbolStringPool().intern( - std::string("cc") + std::to_string(++NextCallbackId)); + auto CallbackName = + ES.intern(std::string("cc") + std::to_string(++NextCallbackId)); std::lock_guard Lock(CCMgrMutex); AddrToSymbol[*TrampolineAddr] = CallbackName; diff --git a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp index 2d53e29..89a302c 100644 --- a/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp +++ b/llvm/lib/ExecutionEngine/Orc/LLJIT.cpp @@ -54,7 +54,7 @@ LLJIT::Create(JITTargetMachineBuilder JTMB, DataLayout DL, } Error LLJIT::defineAbsolute(StringRef Name, JITEvaluatedSymbol Sym) { - auto InternedName = ES->getSymbolStringPool().intern(Name); + auto InternedName = ES->intern(Name); SymbolMap Symbols({{InternedName, Sym}}); return Main.define(absoluteSymbols(std::move(Symbols))); } @@ -78,7 +78,7 @@ Error LLJIT::addObjectFile(JITDylib &JD, std::unique_ptr Obj) { Expected LLJIT::lookupLinkerMangled(JITDylib &JD, StringRef Name) { - return llvm::orc::lookup({&JD}, ES->getSymbolStringPool().intern(Name)); + return llvm::orc::lookup({&JD}, ES->intern(Name)); } LLJIT::LLJIT(std::unique_ptr ES, diff --git a/llvm/lib/ExecutionEngine/Orc/Layer.cpp b/llvm/lib/ExecutionEngine/Orc/Layer.cpp index f74f1c8..323e1d2 100644 --- a/llvm/lib/ExecutionEngine/Orc/Layer.cpp +++ b/llvm/lib/ExecutionEngine/Orc/Layer.cpp @@ -170,7 +170,7 @@ Expected getObjectSymbolFlags(ExecutionSession &ES, auto Name = Sym.getName(); if (!Name) return Name.takeError(); - auto InternedName = ES.getSymbolStringPool().intern(*Name); + auto InternedName = ES.intern(*Name); auto SymFlags = JITSymbolFlags::fromObjectSymbol(Sym); if (!SymFlags) return SymFlags.takeError(); diff --git a/llvm/lib/ExecutionEngine/Orc/Legacy.cpp b/llvm/lib/ExecutionEngine/Orc/Legacy.cpp index f61376a..ddb7254 100644 --- a/llvm/lib/ExecutionEngine/Orc/Legacy.cpp +++ b/llvm/lib/ExecutionEngine/Orc/Legacy.cpp @@ -22,7 +22,7 @@ void JITSymbolResolverAdapter::lookup(const LookupSet &Symbols, OnResolvedFunction OnResolved) { SymbolNameSet InternedSymbols; for (auto &S : Symbols) - InternedSymbols.insert(ES.getSymbolStringPool().intern(S)); + InternedSymbols.insert(ES.intern(S)); auto OnResolvedWithUnwrap = [OnResolved](Expected InternedResult) { if (!InternedResult) { @@ -52,7 +52,7 @@ Expected JITSymbolResolverAdapter::getResponsibilitySet(const LookupSet &Symbols) { SymbolNameSet InternedSymbols; for (auto &S : Symbols) - InternedSymbols.insert(ES.getSymbolStringPool().intern(S)); + InternedSymbols.insert(ES.intern(S)); auto InternedResult = R.getResponsibilitySet(InternedSymbols); LookupSet Result; diff --git a/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp b/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp index 5d814bd..a2c4a2f 100644 --- a/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp +++ b/llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp @@ -24,7 +24,7 @@ public: // Intern the requested symbols: lookup takes interned strings. for (auto &S : Symbols) - InternedSymbols.insert(ES.getSymbolStringPool().intern(S)); + InternedSymbols.insert(ES.intern(S)); // Build an OnResolve callback to unwrap the interned strings and pass them // to the OnResolved callback. @@ -167,8 +167,7 @@ Error RTDyldObjectLinkingLayer2::onObjLoad( if (InternalSymbols.count(KV.first)) continue; - auto InternedName = - getExecutionSession().getSymbolStringPool().intern(KV.first); + auto InternedName = getExecutionSession().intern(KV.first); auto Flags = KV.second.getFlags(); // Override object flags and claim responsibility for symbols if diff --git a/llvm/unittests/ExecutionEngine/Orc/LazyCallThroughAndReexportsTest.cpp b/llvm/unittests/ExecutionEngine/Orc/LazyCallThroughAndReexportsTest.cpp index c3c5703..ebe99d4 100644 --- a/llvm/unittests/ExecutionEngine/Orc/LazyCallThroughAndReexportsTest.cpp +++ b/llvm/unittests/ExecutionEngine/Orc/LazyCallThroughAndReexportsTest.cpp @@ -33,7 +33,7 @@ TEST_F(LazyReexportsTest, BasicLocalCallThroughManagerOperation) { return; } - auto DummyTarget = ES.getSymbolStringPool().intern("DummyTarget"); + auto DummyTarget = ES.intern("DummyTarget"); bool DummyTargetMaterialized = false; diff --git a/llvm/unittests/ExecutionEngine/Orc/OrcTestCommon.h b/llvm/unittests/ExecutionEngine/Orc/OrcTestCommon.h index c9a4305..ae6dce6 100644 --- a/llvm/unittests/ExecutionEngine/Orc/OrcTestCommon.h +++ b/llvm/unittests/ExecutionEngine/Orc/OrcTestCommon.h @@ -50,10 +50,10 @@ protected: std::shared_ptr SSP = std::make_shared(); ExecutionSession ES{SSP}; JITDylib &JD = ES.createJITDylib("JD"); - SymbolStringPtr Foo = ES.getSymbolStringPool().intern("foo"); - SymbolStringPtr Bar = ES.getSymbolStringPool().intern("bar"); - SymbolStringPtr Baz = ES.getSymbolStringPool().intern("baz"); - SymbolStringPtr Qux = ES.getSymbolStringPool().intern("qux"); + SymbolStringPtr Foo = ES.intern("foo"); + SymbolStringPtr Bar = ES.intern("bar"); + SymbolStringPtr Baz = ES.intern("baz"); + SymbolStringPtr Qux = ES.intern("qux"); static const JITTargetAddress FooAddr = 1U; static const JITTargetAddress BarAddr = 2U; static const JITTargetAddress BazAddr = 3U; diff --git a/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayer2Test.cpp b/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayer2Test.cpp index d5d15b5..1dbd48b 100644 --- a/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayer2Test.cpp +++ b/llvm/unittests/ExecutionEngine/Orc/RTDyldObjectLinkingLayer2Test.cpp @@ -52,7 +52,7 @@ static bool testSetProcessAllSections(std::unique_ptr Obj, ExecutionSession ES; auto &JD = ES.createJITDylib("main"); - auto Foo = ES.getSymbolStringPool().intern("foo"); + auto Foo = ES.intern("foo"); RTDyldObjectLinkingLayer2 ObjLayer(ES, [&DebugSectionSeen](VModuleKey) { return llvm::make_unique(DebugSectionSeen); @@ -150,7 +150,7 @@ TEST(RTDyldObjectLinkingLayer2Test, TestOverrideObjectFlags) { // Create a simple stack and set the override flags option. ExecutionSession ES; auto &JD = ES.createJITDylib("main"); - auto Foo = ES.getSymbolStringPool().intern("foo"); + auto Foo = ES.intern("foo"); RTDyldObjectLinkingLayer2 ObjLayer( ES, [](VModuleKey) { return llvm::make_unique(); }); IRCompileLayer2 CompileLayer(ES, ObjLayer, FunkySimpleCompiler(*TM)); @@ -212,7 +212,7 @@ TEST(RTDyldObjectLinkingLayer2Test, TestAutoClaimResponsibilityForSymbols) { // Create a simple stack and set the override flags option. ExecutionSession ES; auto &JD = ES.createJITDylib("main"); - auto Foo = ES.getSymbolStringPool().intern("foo"); + auto Foo = ES.intern("foo"); RTDyldObjectLinkingLayer2 ObjLayer( ES, [](VModuleKey) { return llvm::make_unique(); }); IRCompileLayer2 CompileLayer(ES, ObjLayer, FunkySimpleCompiler(*TM));