]> granicus.if.org Git - clang/commitdiff
[ThinLTO] Leverage new in-place renaming support
authorTeresa Johnson <tejohnson@google.com>
Fri, 8 Jan 2016 17:04:29 +0000 (17:04 +0000)
committerTeresa Johnson <tejohnson@google.com>
Fri, 8 Jan 2016 17:04:29 +0000 (17:04 +0000)
Due to the new in-place renaming support added in r257174, we no
longer need to invoke ThinLTO global renaming from clang. It will be
invoked on the module in the FunctionImport pass (by an immediately
following llvm commit).

As a result, we don't need to load the FunctionInfoIndex as early,
so that is moved down into EmitAssemblyHelper::EmitAssembly.

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

include/clang/CodeGen/BackendUtil.h
lib/CodeGen/BackendUtil.cpp
lib/CodeGen/CodeGenAction.cpp

index ba5dc3939ced211c0cef85c35d6620b7458d544b..d375a7881313f6d503c04006182682e68da06cec 100644 (file)
@@ -33,12 +33,10 @@ namespace clang {
     Backend_EmitObj        ///< Emit native object files
   };
 
-  void
-  EmitBackendOutput(DiagnosticsEngine &Diags, const CodeGenOptions &CGOpts,
-                    const TargetOptions &TOpts, const LangOptions &LOpts,
-                    StringRef TDesc, llvm::Module *M, BackendAction Action,
-                    raw_pwrite_stream *OS,
-                    std::unique_ptr<llvm::FunctionInfoIndex> Index = nullptr);
+  void EmitBackendOutput(DiagnosticsEngine &Diags, const CodeGenOptions &CGOpts,
+                         const TargetOptions &TOpts, const LangOptions &LOpts,
+                         StringRef TDesc, llvm::Module *M, BackendAction Action,
+                         raw_pwrite_stream *OS);
 }
 
 #endif
index 7032d00386f391cb655497fee1d791b34a205dc4..6d746c25eed1c9be44cd12e479281a7bd4b55025 100644 (file)
@@ -28,6 +28,7 @@
 #include "llvm/IR/Module.h"
 #include "llvm/IR/Verifier.h"
 #include "llvm/MC/SubtargetFeature.h"
+#include "llvm/Object/FunctionIndexObjectFile.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/TargetRegistry.h"
@@ -54,7 +55,6 @@ class EmitAssemblyHelper {
   const clang::TargetOptions &TargetOpts;
   const LangOptions &LangOpts;
   Module *TheModule;
-  std::unique_ptr<FunctionInfoIndex> FunctionIndex;
 
   Timer CodeGenerationTime;
 
@@ -97,7 +97,7 @@ private:
     return PerFunctionPasses;
   }
 
-  void CreatePasses();
+  void CreatePasses(FunctionInfoIndex *FunctionIndex);
 
   /// Generates the TargetMachine.
   /// Returns Null if it is unable to create the target machine.
@@ -117,12 +117,11 @@ private:
 public:
   EmitAssemblyHelper(DiagnosticsEngine &_Diags, const CodeGenOptions &CGOpts,
                      const clang::TargetOptions &TOpts,
-                     const LangOptions &LOpts, Module *M,
-                     std::unique_ptr<FunctionInfoIndex> Index)
+                     const LangOptions &LOpts, Module *M)
       : Diags(_Diags), CodeGenOpts(CGOpts), TargetOpts(TOpts), LangOpts(LOpts),
-        TheModule(M), FunctionIndex(std::move(Index)),
-        CodeGenerationTime("Code Generation Time"), CodeGenPasses(nullptr),
-        PerModulePasses(nullptr), PerFunctionPasses(nullptr) {}
+        TheModule(M), CodeGenerationTime("Code Generation Time"),
+        CodeGenPasses(nullptr), PerModulePasses(nullptr),
+        PerFunctionPasses(nullptr) {}
 
   ~EmitAssemblyHelper() {
     delete CodeGenPasses;
@@ -278,7 +277,7 @@ static void addSymbolRewriterPass(const CodeGenOptions &Opts,
   MPM->add(createRewriteSymbolsPass(DL));
 }
 
-void EmitAssemblyHelper::CreatePasses() {
+void EmitAssemblyHelper::CreatePasses(FunctionInfoIndex *FunctionIndex) {
   if (CodeGenOpts.DisableLLVMPasses)
     return;
 
@@ -332,9 +331,8 @@ void EmitAssemblyHelper::CreatePasses() {
 
   // If we are performing a ThinLTO importing compile, invoke the LTO
   // pipeline and pass down the in-memory function index.
-  if (!CodeGenOpts.ThinLTOIndexFile.empty()) {
-    assert(FunctionIndex && "Expected non-empty function index");
-    PMBuilder.FunctionIndex = FunctionIndex.get();
+  if (FunctionIndex) {
+    PMBuilder.FunctionIndex = FunctionIndex;
     PMBuilder.populateLTOPassManager(*MPM);
     return;
   }
@@ -642,7 +640,28 @@ void EmitAssemblyHelper::EmitAssembly(BackendAction Action,
     return;
   if (TM)
     TheModule->setDataLayout(TM->createDataLayout());
-  CreatePasses();
+
+  // If we are performing a ThinLTO importing compile, load the function
+  // index into memory and pass it into CreatePasses, which will add it
+  // to the PassManagerBuilder and invoke LTO passes.
+  std::unique_ptr<FunctionInfoIndex> FunctionIndex;
+  if (!CodeGenOpts.ThinLTOIndexFile.empty()) {
+    ErrorOr<std::unique_ptr<FunctionInfoIndex>> IndexOrErr =
+        llvm::getFunctionIndexForFile(CodeGenOpts.ThinLTOIndexFile,
+                                      [&](const DiagnosticInfo &DI) {
+                                        TheModule->getContext().diagnose(DI);
+                                      });
+    if (std::error_code EC = IndexOrErr.getError()) {
+      std::string Error = EC.message();
+      errs() << "Error loading index file '" << CodeGenOpts.ThinLTOIndexFile
+             << "': " << Error << "\n";
+      return;
+    }
+    FunctionIndex = std::move(IndexOrErr.get());
+    assert(FunctionIndex && "Expected non-empty function index");
+  }
+
+  CreatePasses(FunctionIndex.get());
 
   switch (Action) {
   case Backend_EmitNothing:
@@ -695,10 +714,8 @@ void clang::EmitBackendOutput(DiagnosticsEngine &Diags,
                               const clang::TargetOptions &TOpts,
                               const LangOptions &LOpts, StringRef TDesc,
                               Module *M, BackendAction Action,
-                              raw_pwrite_stream *OS,
-                              std::unique_ptr<FunctionInfoIndex> Index) {
-  EmitAssemblyHelper AsmHelper(Diags, CGOpts, TOpts, LOpts, M,
-                               std::move(Index));
+                              raw_pwrite_stream *OS) {
+  EmitAssemblyHelper AsmHelper(Diags, CGOpts, TOpts, LOpts, M);
 
   AsmHelper.EmitAssembly(Action, OS);
 
index abef5432518eeeaaaa67fd8cf4b1665c533ac317..0a670ab19aa56aef3462a3527935066283d4b365 100644 (file)
 #include "llvm/IR/DebugInfo.h"
 #include "llvm/IR/DiagnosticInfo.h"
 #include "llvm/IR/DiagnosticPrinter.h"
-#include "llvm/IR/FunctionInfo.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
 #include "llvm/IRReader/IRReader.h"
 #include "llvm/Linker/Linker.h"
-#include "llvm/Object/FunctionIndexObjectFile.h"
 #include "llvm/Pass.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/SourceMgr.h"
@@ -781,43 +779,11 @@ void CodeGenAction::ExecuteAction() {
       TheModule->setTargetTriple(TargetOpts.Triple);
     }
 
-    auto DiagHandler = [&](const DiagnosticInfo &DI) {
-      TheModule->getContext().diagnose(DI);
-    };
-
-    // If we are performing ThinLTO importing compilation (indicated by
-    // a non-empty index file option), then we need promote to global scope
-    // and rename any local values that are potentially exported to other
-    // modules. Do this early so that the rest of the compilation sees the
-    // promoted symbols.
-    std::unique_ptr<FunctionInfoIndex> Index;
-    if (!CI.getCodeGenOpts().ThinLTOIndexFile.empty()) {
-      ErrorOr<std::unique_ptr<FunctionInfoIndex>> IndexOrErr =
-          llvm::getFunctionIndexForFile(CI.getCodeGenOpts().ThinLTOIndexFile,
-                                        DiagHandler);
-      if (std::error_code EC = IndexOrErr.getError()) {
-        std::string Error = EC.message();
-        errs() << "Error loading index file '"
-               << CI.getCodeGenOpts().ThinLTOIndexFile << "': " << Error
-               << "\n";
-        return;
-      }
-      Index = std::move(IndexOrErr.get());
-      assert(Index);
-      // Currently this requires creating a new Module object.
-      std::unique_ptr<llvm::Module> RenamedModule =
-          renameModuleForThinLTO(std::move(TheModule), Index.get());
-      if (!RenamedModule)
-        return;
-
-      TheModule = std::move(RenamedModule);
-    }
-
     LLVMContext &Ctx = TheModule->getContext();
     Ctx.setInlineAsmDiagnosticHandler(BitcodeInlineAsmDiagHandler);
     EmitBackendOutput(CI.getDiagnostics(), CI.getCodeGenOpts(), TargetOpts,
                       CI.getLangOpts(), CI.getTarget().getDataLayoutString(),
-                      TheModule.get(), BA, OS, std::move(Index));
+                      TheModule.get(), BA, OS);
     return;
   }