diff options
author | Paul Kirth <paulkirth@google.com> | 2023-11-30 17:09:34 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-30 17:09:34 -0800 |
commit | cfe1ece833d643921da2735cd80e32b32ef170fb (patch) | |
tree | 3a8e1586ea1ac952284975dce7d5279c156319fb /llvm/lib/Passes/PassBuilderPipelines.cpp | |
parent | 51fc8544c7a267e5621eadfebf758f46b015ebd4 (diff) | |
download | llvm-cfe1ece833d643921da2735cd80e32b32ef170fb.zip llvm-cfe1ece833d643921da2735cd80e32b32ef170fb.tar.gz llvm-cfe1ece833d643921da2735cd80e32b32ef170fb.tar.bz2 |
[clang][llvm][fatlto] Avoid cloning modules in FatLTO (#72180)
https://github.com/llvm/llvm-project/issues/70703 pointed out that
cloning LLVM modules could lead to miscompiles when using FatLTO.
This is due to an existing issue when cloning modules with labels (see
#55991 and #47769). Since this can lead to miscompilation, we can avoid
cloning the LLVM modules, which was desirable anyway.
This patch modifies the EmbedBitcodePass to no longer clone the module
or run an input pipeline over it. Further, it make FatLTO always perform
UnifiedLTO, so we can still defer the Thin/Full LTO decision to
link-time. Lastly, it removes dead/obsolete code related to now defunct
options that do not work with the EmbedBitcodePass implementation any
longer.
Diffstat (limited to 'llvm/lib/Passes/PassBuilderPipelines.cpp')
-rw-r--r-- | llvm/lib/Passes/PassBuilderPipelines.cpp | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp index f3d2803..e7f8868 100644 --- a/llvm/lib/Passes/PassBuilderPipelines.cpp +++ b/llvm/lib/Passes/PassBuilderPipelines.cpp @@ -1530,14 +1530,22 @@ PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level, } ModulePassManager -PassBuilder::buildFatLTODefaultPipeline(OptimizationLevel Level, bool ThinLTO, - bool EmitSummary) { +PassBuilder::buildFatLTODefaultPipeline(OptimizationLevel Level) { ModulePassManager MPM; - MPM.addPass(EmbedBitcodePass(ThinLTO, EmitSummary, - ThinLTO - ? buildThinLTOPreLinkDefaultPipeline(Level) - : buildLTOPreLinkDefaultPipeline(Level))); - MPM.addPass(buildPerModuleDefaultPipeline(Level)); + // FatLTO always uses UnifiedLTO, so use the ThinLTOPreLink pipeline + MPM.addPass(buildThinLTOPreLinkDefaultPipeline(Level)); + MPM.addPass(EmbedBitcodePass()); + + // Use the ThinLTO post-link pipeline with sample profiling, other + if (PGOOpt && PGOOpt->Action == PGOOptions::SampleUse) + MPM.addPass(buildThinLTODefaultPipeline(Level, /*ImportSummary=*/nullptr)); + else { + // otherwise, just use module optimization + MPM.addPass( + buildModuleOptimizationPipeline(Level, ThinOrFullLTOPhase::None)); + // Emit annotation remarks. + addAnnotationRemarksPass(MPM); + } return MPM; } |