[llvm] r270908 - [Orc] Don't create empty globals modules in the CompileOnDemandLayer.

Lang Hames via llvm-commits llvm-commits at lists.llvm.org
Thu May 26 13:33:37 PDT 2016


Author: lhames
Date: Thu May 26 15:33:37 2016
New Revision: 270908

URL: http://llvm.org/viewvc/llvm-project?rev=270908&view=rev
Log:
[Orc] Don't create empty globals modules in the CompileOnDemandLayer.

Global variables and aliases are emitted eagerly, but there may not be any in
the incoming module. In that case, we can save some memory and compile time by
not building, emitting and tracking an empty globals module.


Modified:
    llvm/trunk/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h

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=270908&r1=270907&r2=270908&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h Thu May 26 15:33:37 2016
@@ -253,14 +253,8 @@ private:
 
     Module &SrcM = LMResources.SourceModule->getResource();
 
-    // Create the GlobalValues module.
+    // Create stub functions.
     const DataLayout &DL = SrcM.getDataLayout();
-    auto GVsM = llvm::make_unique<Module>((SrcM.getName() + ".globals").str(),
-                                          SrcM.getContext());
-    GVsM->setDataLayout(DL);
-
-    // Create function stubs.
-    ValueToValueMapTy VMap;
     {
       typename IndirectStubsMgrT::StubInitsMap StubInits;
       for (auto &F : SrcM) {
@@ -292,6 +286,19 @@ private:
       assert(!EC && "Error generating stubs");
     }
 
+    // If this module doesn't contain any globals or aliases we can bail out
+    // early and avoid the overhead of creating and managing an empty globals
+    // module.
+    if (SrcM.global_empty() && SrcM.alias_empty())
+      return;
+
+    // Create the GlobalValues module.
+    auto GVsM = llvm::make_unique<Module>((SrcM.getName() + ".globals").str(),
+                                          SrcM.getContext());
+    GVsM->setDataLayout(DL);
+
+    ValueToValueMapTy VMap;
+
     // Clone global variable decls.
     for (auto &GV : SrcM.globals())
       if (!GV.isDeclaration() && !VMap.count(&GV))




More information about the llvm-commits mailing list