Skip to content

Commit a61e134

Browse files
committed
Invoke OptimizerLastEPCallbacks in PreLinkThinLTO
The default ThinLTO pre-link pipeline does not include optimizer last extension points. Thus, when using the new LLVM pass manager & ThinLTO & sanitizers on any opt-level different from zero, the sanitizer function passes would be omitted from the pipeline. Add optimizer last extensions points manually to the pipeline, but guard registration with stage check in the case this behaviour changes in the future.
1 parent 97b3d81 commit a61e134

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/rustllvm/PassWrapper.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -868,15 +868,23 @@ LLVMRustOptimizeWithNewPassManager(
868868
} else {
869869
for (const auto &C : PipelineStartEPCallbacks)
870870
PB.registerPipelineStartEPCallback(C);
871-
for (const auto &C : OptimizerLastEPCallbacks)
872-
PB.registerOptimizerLastEPCallback(C);
871+
if (OptStage != LLVMRustOptStage::PreLinkThinLTO) {
872+
for (const auto &C : OptimizerLastEPCallbacks)
873+
PB.registerOptimizerLastEPCallback(C);
874+
}
873875

874876
switch (OptStage) {
875877
case LLVMRustOptStage::PreLinkNoLTO:
876878
MPM = PB.buildPerModuleDefaultPipeline(OptLevel, DebugPassManager);
877879
break;
878880
case LLVMRustOptStage::PreLinkThinLTO:
879881
MPM = PB.buildThinLTOPreLinkDefaultPipeline(OptLevel, DebugPassManager);
882+
if (!OptimizerLastEPCallbacks.empty()) {
883+
FunctionPassManager FPM(DebugPassManager);
884+
for (const auto &C : OptimizerLastEPCallbacks)
885+
C(FPM, OptLevel);
886+
MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
887+
}
880888
break;
881889
case LLVMRustOptStage::PreLinkFatLTO:
882890
MPM = PB.buildLTOPreLinkDefaultPipeline(OptLevel, DebugPassManager);

0 commit comments

Comments
 (0)