IRGen: fix -disable-llvm-optzns

If LLVM optimizations are to be disabled, we cannot just not run all LLVM passes, because there are some mandatory LLVM passes, like coro splitting.
Instead, just run the -O0 LLVM pipeline if -disable-llvm-optzns is used.

Fixes compiler crashes if -disable-llvm-optzns is used.

Note: if one wants to see the output of IRGen, -emit-irgen can be used.
This commit is contained in:
Erik Eckstein
2023-09-22 10:37:30 +02:00
parent 842d26e9b3
commit b5de7e4e49
12 changed files with 24 additions and 17 deletions

View File

@@ -369,8 +369,6 @@ void swift::performLLVMOptimizations(const IRGenOptions &Opts,
MPM.addPass(InlineTreePrinterPass());
// Add bitcode/ll output passes to pass manager.
ModulePassManager EmptyPassManager;
auto &PassManagerToRun = Opts.DisableLLVMOptzns ? EmptyPassManager : MPM;
switch (Opts.OutputKind) {
case IRGenOutputKind::LLVMAssemblyBeforeOptimization:
@@ -380,7 +378,7 @@ void swift::performLLVMOptimizations(const IRGenOptions &Opts,
case IRGenOutputKind::Module:
break;
case IRGenOutputKind::LLVMAssemblyAfterOptimization:
PassManagerToRun.addPass(PrintModulePass(*out, "", false));
MPM.addPass(PrintModulePass(*out, "", false));
break;
case IRGenOutputKind::LLVMBitcode: {
// Emit a module summary by default for Regular LTO except ld64-based ones
@@ -389,7 +387,7 @@ void swift::performLLVMOptimizations(const IRGenOptions &Opts,
TargetMachine->getTargetTriple().getVendor() != llvm::Triple::Apple;
if (Opts.LLVMLTOKind == IRGenLLVMLTOKind::Thin) {
PassManagerToRun.addPass(ThinLTOBitcodeWriterPass(*out, nullptr));
MPM.addPass(ThinLTOBitcodeWriterPass(*out, nullptr));
} else {
if (EmitRegularLTOSummary) {
Module->addModuleFlag(llvm::Module::Error, "ThinLTO", uint32_t(0));
@@ -399,14 +397,14 @@ void swift::performLLVMOptimizations(const IRGenOptions &Opts,
Module->addModuleFlag(llvm::Module::Error, "EnableSplitLTOUnit",
uint32_t(1));
}
PassManagerToRun.addPass(BitcodeWriterPass(
MPM.addPass(BitcodeWriterPass(
*out, /*ShouldPreserveUseListOrder*/ false, EmitRegularLTOSummary));
}
break;
}
}
PassManagerToRun.run(*Module, MAM);
MPM.run(*Module, MAM);
if (AlignModuleToPageSize) {
align(Module);