From f1d74b3e28f2993f25d39ce19a9f84322206feb2 Mon Sep 17 00:00:00 2001 From: Lang Hames Date: Thu, 26 May 2016 20:33:37 +0000 Subject: [PATCH] [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. llvm-svn: 270908 --- .../Orc/CompileOnDemandLayer.h | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/llvm/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h b/llvm/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h index 540700ff06e9..87555c9ad014 100644 --- a/llvm/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h +++ b/llvm/include/llvm/ExecutionEngine/Orc/CompileOnDemandLayer.h @@ -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((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((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))