[Orc] Enable user supplied partitioning functors in the CompileOnDemand layer.
authorLang Hames <lhames@gmail.com>
Wed, 7 Oct 2015 21:53:41 +0000 (21:53 +0000)
committerLang Hames <lhames@gmail.com>
Wed, 7 Oct 2015 21:53:41 +0000 (21:53 +0000)
Previously the CompileOnDemand layer always created single-function partitions.
In theory this new API allows for more interesting partitions, though this has
not been well tested yet.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@249623 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h
tools/lli/OrcLazyJIT.h

index 714ca2374dc359a3343307dacb8edf2e9994f4e0..ff180c21b242188bae70da4b2caeb834851059e0 100644 (file)
@@ -85,7 +85,6 @@ private:
     typedef std::function<RuntimeDyld::SymbolInfo(const std::string&)>
       SymbolResolverFtor;
     SymbolResolverFtor ExternalSymbolResolver;
     typedef std::function<RuntimeDyld::SymbolInfo(const std::string&)>
       SymbolResolverFtor;
     SymbolResolverFtor ExternalSymbolResolver;
-    PartitioningFtor Partitioner;
   };
 
   typedef LogicalDylib<BaseLayerT, LogicalModuleResources,
   };
 
   typedef LogicalDylib<BaseLayerT, LogicalModuleResources,
@@ -100,8 +99,10 @@ public:
 
   /// @brief Construct a compile-on-demand layer instance.
   CompileOnDemandLayer(BaseLayerT &BaseLayer, CompileCallbackMgrT &CallbackMgr,
 
   /// @brief Construct a compile-on-demand layer instance.
   CompileOnDemandLayer(BaseLayerT &BaseLayer, CompileCallbackMgrT &CallbackMgr,
-                       bool CloneStubsIntoPartitions)
+                       PartitioningFtor Partition,
+                       bool CloneStubsIntoPartitions = true)
       : BaseLayer(BaseLayer), CompileCallbackMgr(CallbackMgr),
       : BaseLayer(BaseLayer), CompileCallbackMgr(CallbackMgr),
+        Partition(Partition),
         CloneStubsIntoPartitions(CloneStubsIntoPartitions) {}
 
   /// @brief Add a module to the compile-on-demand layer.
         CloneStubsIntoPartitions(CloneStubsIntoPartitions) {}
 
   /// @brief Add a module to the compile-on-demand layer.
@@ -122,13 +123,6 @@ public:
         return Resolver->findSymbol(Name);
       };
 
         return Resolver->findSymbol(Name);
       };
 
-    LDResources.Partitioner =
-      [](Function &F) {
-        std::set<Function*> Partition;
-        Partition.insert(&F);
-        return Partition;
-      };
-
     // Process each of the modules in this module set.
     for (auto &M : Ms)
       addLogicalModule(LogicalDylibs.back(),
     // Process each of the modules in this module set.
     for (auto &M : Ms)
       addLogicalModule(LogicalDylibs.back(),
@@ -265,14 +259,14 @@ private:
     // Grab the name of the function being called here.
     std::string CalledFnName = Mangle(F.getName(), SrcM.getDataLayout());
 
     // Grab the name of the function being called here.
     std::string CalledFnName = Mangle(F.getName(), SrcM.getDataLayout());
 
-    auto Partition = LD.getDylibResources().Partitioner(F);
-    auto PartitionH = emitPartition(LD, LMH, Partition);
+    auto Part = Partition(F);
+    auto PartH = emitPartition(LD, LMH, Part);
 
     TargetAddress CalledAddr = 0;
 
     TargetAddress CalledAddr = 0;
-    for (auto *SubF : Partition) {
+    for (auto *SubF : Part) {
       std::string FName = SubF->getName();
       auto FnBodySym =
       std::string FName = SubF->getName();
       auto FnBodySym =
-        BaseLayer.findSymbolIn(PartitionH, Mangle(FName, SrcM.getDataLayout()),
+        BaseLayer.findSymbolIn(PartH, Mangle(FName, SrcM.getDataLayout()),
                                false);
       auto FnPtrSym =
         BaseLayer.findSymbolIn(*LD.moduleHandlesBegin(LMH),
                                false);
       auto FnPtrSym =
         BaseLayer.findSymbolIn(*LD.moduleHandlesBegin(LMH),
@@ -300,13 +294,13 @@ private:
   template <typename PartitionT>
   BaseLayerModuleSetHandleT emitPartition(CODLogicalDylib &LD,
                                           LogicalModuleHandle LMH,
   template <typename PartitionT>
   BaseLayerModuleSetHandleT emitPartition(CODLogicalDylib &LD,
                                           LogicalModuleHandle LMH,
-                                          const PartitionT &Partition) {
+                                          const PartitionT &Part) {
     auto &LMResources = LD.getLogicalModuleResources(LMH);
     Module &SrcM = *LMResources.SourceModule;
 
     // Create the module.
     std::string NewName = SrcM.getName();
     auto &LMResources = LD.getLogicalModuleResources(LMH);
     Module &SrcM = *LMResources.SourceModule;
 
     // Create the module.
     std::string NewName = SrcM.getName();
-    for (auto *F : Partition) {
+    for (auto *F : Part) {
       NewName += ".";
       NewName += F->getName();
     }
       NewName += ".";
       NewName += F->getName();
     }
@@ -317,11 +311,11 @@ private:
     GlobalDeclMaterializer GDM(*M, &LMResources.StubsToClone);
 
     // Create decls in the new module.
     GlobalDeclMaterializer GDM(*M, &LMResources.StubsToClone);
 
     // Create decls in the new module.
-    for (auto *F : Partition)
+    for (auto *F : Part)
       cloneFunctionDecl(*M, *F, &VMap);
 
     // Move the function bodies.
       cloneFunctionDecl(*M, *F, &VMap);
 
     // Move the function bodies.
-    for (auto *F : Partition)
+    for (auto *F : Part)
       moveFunctionBody(*F, VMap, &GDM);
 
     // Create memory manager and symbol resolver.
       moveFunctionBody(*F, VMap, &GDM);
 
     // Create memory manager and symbol resolver.
@@ -348,6 +342,7 @@ private:
   BaseLayerT &BaseLayer;
   CompileCallbackMgrT &CompileCallbackMgr;
   LogicalDylibList LogicalDylibs;
   BaseLayerT &BaseLayer;
   CompileCallbackMgrT &CompileCallbackMgr;
   LogicalDylibList LogicalDylibs;
+  PartitioningFtor Partition;
   bool CloneStubsIntoPartitions;
 };
 
   bool CloneStubsIntoPartitions;
 };
 
index 5019523c7f0e0d71f600364f885e76d6525a7147..ac1199dbde028e1edc3f03b11f03a62f911d12d0 100644 (file)
@@ -54,7 +54,7 @@ public:
         CompileLayer(ObjectLayer, orc::SimpleCompiler(*this->TM)),
         IRDumpLayer(CompileLayer, createDebugDumper()),
         CCMgr(BuildCallbackMgr(IRDumpLayer, CCMgrMemMgr, Context)),
         CompileLayer(ObjectLayer, orc::SimpleCompiler(*this->TM)),
         IRDumpLayer(CompileLayer, createDebugDumper()),
         CCMgr(BuildCallbackMgr(IRDumpLayer, CCMgrMemMgr, Context)),
-        CODLayer(IRDumpLayer, *CCMgr, false),
+        CODLayer(IRDumpLayer, *CCMgr, extractSingleFunction, false),
         CXXRuntimeOverrides(
             [this](const std::string &S) { return mangle(S); }) {}
 
         CXXRuntimeOverrides(
             [this](const std::string &S) { return mangle(S); }) {}
 
@@ -132,6 +132,7 @@ public:
   }
 
 private:
   }
 
 private:
+
   std::string mangle(const std::string &Name) {
     std::string MangledName;
     {
   std::string mangle(const std::string &Name) {
     std::string MangledName;
     {
@@ -141,6 +142,12 @@ private:
     return MangledName;
   }
 
     return MangledName;
   }
 
+  static std::set<Function*> extractSingleFunction(Function &F) {
+    std::set<Function*> Partition;
+    Partition.insert(&F);
+    return Partition;
+  }
+
   static TransformFtor createDebugDumper();
 
   std::unique_ptr<TargetMachine> TM;
   static TransformFtor createDebugDumper();
 
   std::unique_ptr<TargetMachine> TM;