]> granicus.if.org Git - llvm/commitdiff
[ThinLTO] Ensure anonymous globals renamed even at -O0
authorTeresa Johnson <tejohnson@google.com>
Sat, 17 Sep 2016 20:40:16 +0000 (20:40 +0000)
committerTeresa Johnson <tejohnson@google.com>
Sat, 17 Sep 2016 20:40:16 +0000 (20:40 +0000)
Summary:
This fixes an issue when files are compiled with -flto=thin
at default -O0. We need to rename anonymous globals before attempting
to write the module summary because all values need names for
the summary. This was happening at -O1 and above, but not before
the early exit when constructing the pipeline for -O0.

Also add an internal -prepare-for-thinlto option to enable this
to be tested via opt.

Fixes PR30419.

Reviewers: mehdi_amini

Subscribers: probinson, llvm-commits, mehdi_amini

Differential Revision: https://reviews.llvm.org/D24701

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

lib/Transforms/IPO/PassManagerBuilder.cpp
test/Transforms/NameAnonGlobals/rename.ll

index 9bd9180eff76f1f5c81b20d4cbd908a6bad9f884..cf8348f2dece12c365b088ccf9c8f5f556b6eea1 100644 (file)
@@ -112,6 +112,10 @@ static cl::opt<bool> EnableLoopLoadElim(
     "enable-loop-load-elim", cl::init(true), cl::Hidden,
     cl::desc("Enable the LoopLoadElimination Pass"));
 
+static cl::opt<bool>
+    EnablePrepareForThinLTO("prepare-for-thinlto", cl::init(false), cl::Hidden,
+                            cl::desc("Enable preparation for ThinLTO."));
+
 static cl::opt<bool> RunPGOInstrGen(
     "profile-generate", cl::init(false), cl::Hidden,
     cl::desc("Enable PGO instrumentation."));
@@ -163,7 +167,7 @@ PassManagerBuilder::PassManagerBuilder() {
     EnablePGOInstrGen = RunPGOInstrGen;
     PGOInstrGen = PGOOutputFile;
     PGOInstrUse = RunPGOInstrUse;
-    PrepareForThinLTO = false;
+    PrepareForThinLTO = EnablePrepareForThinLTO;
     PerformThinLTO = false;
 }
 
@@ -395,6 +399,10 @@ void PassManagerBuilder::populateModulePassManager(
     else if (!GlobalExtensions->empty() || !Extensions.empty())
       MPM.add(createBarrierNoopPass());
 
+    if (PrepareForThinLTO)
+      // Rename anon globals to be able to export them in the summary.
+      MPM.add(createNameAnonGlobalPass());
+
     addExtensionsToPM(EP_EnabledOnOptLevel0, MPM);
     return;
   }
index 996dc51800f4a2030d1ce73b3eca1b30e6c765a5..74fb972e7561be1c012971476ae96f7429598ba1 100644 (file)
@@ -1,4 +1,5 @@
 ; RUN: opt -S -name-anon-globals < %s | FileCheck %s
+; RUN: opt -prepare-for-thinlto -O0 -module-summary -o %t.bc < %s
 
 
 ; foo contribute to the unique hash for the module