diff --git a/lib/LTO/LTOCodeGenerator.cpp b/lib/LTO/LTOCodeGenerator.cpp index 1fdc5cf04dd..80aa48e0fbc 100644 --- a/lib/LTO/LTOCodeGenerator.cpp +++ b/lib/LTO/LTOCodeGenerator.cpp @@ -466,11 +466,9 @@ bool LTOCodeGenerator::generateObjectFile(raw_ostream &out, mergedModule->setDataLayout(TargetMach->getSubtargetImpl()->getDataLayout()); passes.add(new DataLayoutPass(mergedModule)); - // Add appropriate TargetLibraryInfo for this module. - passes.add(new TargetLibraryInfo(Triple(TargetMach->getTargetTriple()))); - TargetMach->addAnalysisPasses(passes); + Triple TargetTriple(TargetMach->getTargetTriple()); // Enabling internalize here would use its AllButMain variant. It // keeps only main if it exists and does nothing for libraries. Instead // we create the pass ourselves with the symbol list provided by the linker. @@ -479,6 +477,7 @@ bool LTOCodeGenerator::generateObjectFile(raw_ostream &out, PMB.DisableGVNLoadPRE = DisableGVNLoadPRE; if (!DisableInline) PMB.Inliner = createFunctionInliningPass(); + PMB.LibraryInfo = new TargetLibraryInfo(TargetTriple); PMB.populateLTOPassManager(passes); } diff --git a/lib/Transforms/IPO/PassManagerBuilder.cpp b/lib/Transforms/IPO/PassManagerBuilder.cpp index 07f46883600..b76f3486e5f 100644 --- a/lib/Transforms/IPO/PassManagerBuilder.cpp +++ b/lib/Transforms/IPO/PassManagerBuilder.cpp @@ -314,6 +314,10 @@ void PassManagerBuilder::populateModulePassManager(PassManagerBase &MPM) { } void PassManagerBuilder::populateLTOPassManager(PassManagerBase &PM) { + // Add LibraryInfo if we have some. + if (LibraryInfo) + PM.add(new TargetLibraryInfo(*LibraryInfo)); + // Provide AliasAnalysis services for optimizations. addInitialAliasAnalysisPasses(PM);