[llvm] r344078 - [ORC] Promote and rename private symbols inside the CompileOnDemand layer,

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 9 13:44:33 PDT 2018


Author: lhames
Date: Tue Oct  9 13:44:32 2018
New Revision: 344078

URL: http://llvm.org/viewvc/llvm-project?rev=344078&view=rev
Log:
[ORC] Promote and rename private symbols inside the CompileOnDemand layer,
rather than require them to have been promoted before being passed in.

Dropping this precondition is better for layer composition (CompileOnDemandLayer
was the only one that placed pre-conditions on the modules that could be added).
It also means that the promoted private symbols do not show up in the target
JITDylib's symbol table. Instead, they are confined to the hidden implementation
dylib that contains the actual definitions.

For the 403.gcc testcase this cut down the public symbol table size from ~15,000
symbols to ~4000, substantially reducing symbol dependence tracking costs.

Modified:
    llvm/trunk/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h
    llvm/trunk/include/llvm/ExecutionEngine/Orc/IndirectionUtils.h
    llvm/trunk/include/llvm/ExecutionEngine/Orc/LLJIT.h
    llvm/trunk/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp
    llvm/trunk/lib/ExecutionEngine/Orc/ExecutionUtils.cpp
    llvm/trunk/lib/ExecutionEngine/Orc/IndirectionUtils.cpp
    llvm/trunk/lib/ExecutionEngine/Orc/LLJIT.cpp

Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h?rev=344078&r1=344077&r2=344078&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h Tue Oct  9 13:44:32 2018
@@ -129,6 +129,7 @@ private:
   IndirectStubsManagerBuilder BuildIndirectStubsManager;
   PerDylibResourcesMap DylibResources;
   PartitionFunction Partition = compileRequested;
+  SymbolLinkagePromoter PromoteSymbols;
 };
 
 /// Compile-on-demand layer.

Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/IndirectionUtils.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/IndirectionUtils.h?rev=344078&r1=344077&r2=344078&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/IndirectionUtils.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/IndirectionUtils.h Tue Oct  9 13:44:32 2018
@@ -427,7 +427,9 @@ void makeStub(Function &F, Value &ImplPo
 /// used for all symbols to be added to a single JITDylib.
 class SymbolLinkagePromoter {
 public:
-  void operator()(Module &M);
+  /// Promote symbols in the given module. Returns the set of global values
+  /// that have been renamed/promoted.
+  std::vector<GlobalValue *> operator()(Module &M);
 
 private:
   unsigned NextId = 0;

Modified: llvm/trunk/include/llvm/ExecutionEngine/Orc/LLJIT.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/Orc/LLJIT.h?rev=344078&r1=344077&r2=344078&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/LLJIT.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/LLJIT.h Tue Oct  9 13:44:32 2018
@@ -182,7 +182,6 @@ private:
 
   IRTransformLayer2 TransformLayer;
   CompileOnDemandLayer2 CODLayer;
-  SymbolLinkagePromoter PromoteSymbols;
 };
 
 } // End namespace orc

Modified: llvm/trunk/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp?rev=344078&r1=344077&r2=344078&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/CompileOnDemandLayer.cpp Tue Oct  9 13:44:32 2018
@@ -134,10 +134,7 @@ void CompileOnDemandLayer2::emit(Materia
   SymbolAliasMap NonCallables;
   SymbolAliasMap Callables;
   for (auto &GV : M.global_values()) {
-    assert(GV.hasName() && !GV.hasLocalLinkage() &&
-           "GlobalValues must have been promoted before adding to "
-           "CompileOnDemandLayer");
-    if (GV.isDeclaration() || GV.hasAppendingLinkage())
+    if (GV.isDeclaration() || GV.hasLocalLinkage() || GV.hasAppendingLinkage())
       continue;
 
     auto Name = Mangle(GV.getName());
@@ -259,6 +256,25 @@ void CompileOnDemandLayer2::emitPartitio
     return;
   }
 
+  // Ok -- we actually need to partition the symbols. Promote the symbol
+  // linkages/names.
+  // FIXME: We apply this once per partitioning. It's safe, but overkill.
+  {
+    auto PromotedGlobals = PromoteSymbols(*TSM.getModule());
+    if (!PromotedGlobals.empty()) {
+      MangleAndInterner Mangle(ES, TSM.getModule()->getDataLayout());
+      SymbolFlagsMap SymbolFlags;
+      for (auto &GV : PromotedGlobals)
+        SymbolFlags[Mangle(GV->getName())] =
+            JITSymbolFlags::fromGlobalValue(*GV);
+      if (auto Err = R.defineMaterializing(SymbolFlags)) {
+        ES.reportError(std::move(Err));
+        R.failMaterialization();
+        return;
+      }
+    }
+  }
+
   expandPartition(*GVsToExtract);
 
   // Extract the requested partiton (plus any necessary aliases) and
@@ -268,7 +284,6 @@ void CompileOnDemandLayer2::emitPartitio
   };
 
   auto ExtractedTSM = extractSubModule(TSM, ".submodule", ShouldExtract);
-
   R.replace(llvm::make_unique<PartitioningIRMaterializationUnit>(
       ES, std::move(TSM), *this));
 

Modified: llvm/trunk/lib/ExecutionEngine/Orc/ExecutionUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/ExecutionUtils.cpp?rev=344078&r1=344077&r2=344078&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/ExecutionUtils.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/ExecutionUtils.cpp Tue Oct  9 13:44:32 2018
@@ -99,6 +99,12 @@ void CtorDtorRunner2::add(iterator_range
     assert(CtorDtor.Func && CtorDtor.Func->hasName() &&
            "Ctor/Dtor function must be named to be runnable under the JIT");
 
+    // FIXME: Maybe use a symbol promoter here instead.
+    if (CtorDtor.Func->hasLocalLinkage()) {
+      CtorDtor.Func->setLinkage(GlobalValue::ExternalLinkage);
+      CtorDtor.Func->setVisibility(GlobalValue::HiddenVisibility);
+    }
+
     if (CtorDtor.Data && cast<GlobalValue>(CtorDtor.Data)->isDeclaration()) {
       dbgs() << "  Skipping because why now?\n";
       continue;

Modified: llvm/trunk/lib/ExecutionEngine/Orc/IndirectionUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/IndirectionUtils.cpp?rev=344078&r1=344077&r2=344078&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/IndirectionUtils.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/IndirectionUtils.cpp Tue Oct  9 13:44:32 2018
@@ -248,8 +248,11 @@ void makeStub(Function &F, Value &ImplPo
     Builder.CreateRet(Call);
 }
 
-void SymbolLinkagePromoter::operator()(Module &M) {
+std::vector<GlobalValue *> SymbolLinkagePromoter::operator()(Module &M) {
+  std::vector<GlobalValue *> PromotedGlobals;
+
   for (auto &GV : M.global_values()) {
+    bool Promoted = true;
 
     // Rename if necessary.
     if (!GV.hasName())
@@ -258,13 +261,21 @@ void SymbolLinkagePromoter::operator()(M
       GV.setName("__" + GV.getName().substr(1) + "." + Twine(NextId++));
     else if (GV.hasLocalLinkage())
       GV.setName("__orc_lcl." + GV.getName() + "." + Twine(NextId++));
+    else
+      Promoted = false;
 
     if (GV.hasLocalLinkage()) {
       GV.setLinkage(GlobalValue::ExternalLinkage);
       GV.setVisibility(GlobalValue::HiddenVisibility);
+      Promoted = true;
     }
     GV.setUnnamedAddr(GlobalValue::UnnamedAddr::None);
+
+    if (Promoted)
+      PromotedGlobals.push_back(&GV);
   }
+
+  return PromotedGlobals;
 }
 
 Function* cloneFunctionDecl(Module &Dst, const Function &F,

Modified: llvm/trunk/lib/ExecutionEngine/Orc/LLJIT.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/Orc/LLJIT.cpp?rev=344078&r1=344077&r2=344078&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/Orc/LLJIT.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/Orc/LLJIT.cpp Tue Oct  9 13:44:32 2018
@@ -185,8 +185,6 @@ Error LLLazyJIT::addLazyIRModule(JITDyli
   if (auto Err = applyDataLayout(*TSM.getModule()))
     return Err;
 
-  PromoteSymbols(*TSM.getModule());
-
   recordCtorDtors(*TSM.getModule());
 
   auto K = ES->allocateVModule();




More information about the llvm-commits mailing list