Index: lib/Transforms/IPO/PassManagerBuilder.cpp =================================================================== --- lib/Transforms/IPO/PassManagerBuilder.cpp +++ lib/Transforms/IPO/PassManagerBuilder.cpp @@ -112,6 +112,10 @@ "enable-loop-load-elim", cl::init(true), cl::Hidden, cl::desc("Enable the LoopLoadElimination Pass")); +static cl::opt + EnablePrepareForThinLTO("prepare-for-thinlto", cl::init(false), cl::Hidden, + cl::desc("Enable preparation for ThinLTO.")); + static cl::opt RunPGOInstrGen( "profile-generate", cl::init(false), cl::Hidden, cl::desc("Enable PGO instrumentation.")); @@ -163,7 +167,7 @@ EnablePGOInstrGen = RunPGOInstrGen; PGOInstrGen = PGOOutputFile; PGOInstrUse = RunPGOInstrUse; - PrepareForThinLTO = false; + PrepareForThinLTO = EnablePrepareForThinLTO; PerformThinLTO = false; } @@ -395,6 +399,10 @@ 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: test/Transforms/NameAnonGlobals/rename.ll =================================================================== --- test/Transforms/NameAnonGlobals/rename.ll +++ test/Transforms/NameAnonGlobals/rename.ll @@ -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