From 9a8acea78355b604dbeb29bc38bd4dbf7bfce95f Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 2 Mar 2021 21:54:03 +0100 Subject: [PATCH] Schedule ThinLTOBuffer passes again after sanitizer passes This works around a design defect in the LLVM 12 pass builder implementation. In LLVM 13, the PreLink ThinLTO pipeline properly respects the OptimizerLastEPCallbacks. --- compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp index 79babd27a304f..2f28162f908ac 100644 --- a/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp +++ b/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp @@ -1015,7 +1015,12 @@ LLVMRustOptimizeWithNewPassManager( case LLVMRustOptStage::PreLinkThinLTO: #if LLVM_VERSION_GE(12, 0) MPM = PB.buildThinLTOPreLinkDefaultPipeline(OptLevel); - NeedThinLTOBufferPasses = false; + // The ThinLTOPreLink pipeline already includes ThinLTOBuffer passes. However, callback + // passes may still run afterwards. This means we need to run the buffer passes again. + // FIXME: In LLVM 13, the ThinLTOPreLink pipeline also runs OptimizerLastEPCallbacks + // before the RequiredLTOPreLinkPasses, in which case we can remove these hacks. + if (OptimizerLastEPCallbacks.empty()) + NeedThinLTOBufferPasses = false; #else MPM = PB.buildThinLTOPreLinkDefaultPipeline(OptLevel, DebugPassManager); #endif