Skip optimization passes when generating debug info
When we're generating Reactor debug info, set the effective optimization
level to 0. This enables running the pass managers back-to-back.
Bug: b/229629349
Change-Id: I9327d5219dc141d1dec0d91b0ef11932aa792c9a
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/65309
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Tested-by: Nicolas Capens <nicolascapens@google.com>
Reviewed-by: Alexis Hétu <sugoi@google.com>
diff --git a/src/Reactor/LLVMJIT.cpp b/src/Reactor/LLVMJIT.cpp
index 027a8db..024b720 100644
--- a/src/Reactor/LLVMJIT.cpp
+++ b/src/Reactor/LLVMJIT.cpp
@@ -868,9 +868,19 @@
}
#endif
- if(coroutine.id) // Run manadory coroutine transforms.
+ int optimizationLevel = getPragmaState(OptimizationLevel);
+
+#ifdef ENABLE_RR_DEBUG_INFO
+ if(debugInfo != nullptr)
{
+ optimizationLevel = 0; // Don't optimize if we're generating debug info.
+ }
+#endif // ENABLE_RR_DEBUG_INFO
+
#if LLVM_VERSION_MAJOR >= 13 // New pass manager
+ if(coroutine.id)
+ {
+ // Run mandatory coroutine transforms.
llvm::PassBuilder pb;
llvm::LoopAnalysisManager lam;
llvm::FunctionAnalysisManager fam;
@@ -886,27 +896,8 @@
llvm::ModulePassManager mpm =
pb.buildO0DefaultPipeline(llvm::OptimizationLevel::O0);
mpm.run(*module, mam);
-#else // Legacy pass manager
- llvm::legacy::PassManager pm;
-
- pm.add(llvm::createCoroEarlyLegacyPass());
- pm.add(llvm::createCoroSplitLegacyPass());
- pm.add(llvm::createCoroElideLegacyPass());
- pm.add(llvm::createBarrierNoopPass());
- pm.add(llvm::createCoroCleanupLegacyPass());
-
- pm.run(*module);
-#endif
}
-#ifdef ENABLE_RR_DEBUG_INFO
- if(debugInfo != nullptr)
- {
- return; // Don't optimize if we're generating debug info.
- }
-#endif // ENABLE_RR_DEBUG_INFO
-
-#if LLVM_VERSION_MAJOR >= 13 // New pass manager
llvm::LoopAnalysisManager lam;
llvm::FunctionAnalysisManager fam;
llvm::CGSCCAnalysisManager cgam;
@@ -929,7 +920,7 @@
pm.addPass(llvm::createModuleToFunctionPassAdaptor(llvm::MemorySanitizerPass(msanOpts)));
}
- if(getPragmaState(OptimizationLevel) > 0)
+ if(optimizationLevel > 0)
{
fpm.addPass(llvm::SROAPass());
fpm.addPass(llvm::InstCombinePass());
@@ -942,6 +933,20 @@
pm.run(*module, mam);
#else // Legacy pass manager
+ if(coroutine.id)
+ {
+ // Run mandatory coroutine transforms.
+ llvm::legacy::PassManager pm;
+
+ pm.add(llvm::createCoroEarlyLegacyPass());
+ pm.add(llvm::createCoroSplitLegacyPass());
+ pm.add(llvm::createCoroElideLegacyPass());
+ pm.add(llvm::createBarrierNoopPass());
+ pm.add(llvm::createCoroCleanupLegacyPass());
+
+ pm.run(*module);
+ }
+
llvm::legacy::PassManager passManager;
if(__has_feature(memory_sanitizer) && msanInstrumentation)
@@ -949,7 +954,7 @@
passManager.add(llvm::createMemorySanitizerLegacyPassPass());
}
- if(getPragmaState(OptimizationLevel) > 0)
+ if(optimizationLevel > 0)
{
passManager.add(llvm::createSROAPass());
passManager.add(llvm::createInstructionCombiningPass());