From 30b4aa5a58f6547590561960637ec0bce6b13c09 Mon Sep 17 00:00:00 2001 From: Evan Wilde Date: Fri, 18 Apr 2025 13:44:56 -0700 Subject: [PATCH] SILOptimizer: Disable invalid passes in C++-only compiler The SimplifyCFG and LoopRotate passes result in verification failures when built in a compiler that is not built with Swift sources enabled. - Scope: Disables optimizers passes in C++-only compiler for bootstrapping purposes. Has no impact on full Swift compiler build. - Risk: Low. This change has no impact in build environments where a Swift compiler is available. - Reviewers: @eeckstein - Testing: PR testing -- Full PR testing fails if passes are accidentally disabled. Fixes: rdar://146357242 (cherry picked from commit bca1378fdbf1c584cc765b04643b8d463231c16b) --- cmake/modules/AddSwift.cmake | 3 +++ lib/SILOptimizer/LoopTransforms/LoopRotate.cpp | 6 ++++++ lib/SILOptimizer/Transforms/SimplifyCFG.cpp | 6 ++++++ 3 files changed, 15 insertions(+) diff --git a/cmake/modules/AddSwift.cmake b/cmake/modules/AddSwift.cmake index f219fde451b50..3e51d48dd17e3 100644 --- a/cmake/modules/AddSwift.cmake +++ b/cmake/modules/AddSwift.cmake @@ -324,6 +324,9 @@ function(_add_host_variant_c_compile_flags target) target_compile_definitions(${target} PRIVATE $<$:_LARGEFILE_SOURCE _FILE_OFFSET_BITS=64>) endif() + + target_compile_definitions(${target} PRIVATE + $<$,$>:SWIFT_ENABLE_SWIFT_IN_SWIFT>) endfunction() function(_add_host_variant_link_flags target) diff --git a/lib/SILOptimizer/LoopTransforms/LoopRotate.cpp b/lib/SILOptimizer/LoopTransforms/LoopRotate.cpp index f89863a9ff0b5..4f7862ebf15fb 100644 --- a/lib/SILOptimizer/LoopTransforms/LoopRotate.cpp +++ b/lib/SILOptimizer/LoopTransforms/LoopRotate.cpp @@ -485,6 +485,12 @@ namespace { class LoopRotation : public SILFunctionTransform { void run() override { +#ifndef SWIFT_ENABLE_SWIFT_IN_SWIFT + // This pass results in verification failures when Swift sources are not + // enabled. + LLVM_DEBUG(llvm::dbgs() << "Loop Rotate disabled in C++-only Swift compiler\n"); + return; +#endif // !SWIFT_ENABLE_SWIFT_IN_SWIFT SILFunction *f = getFunction(); SILLoopAnalysis *loopAnalysis = PM->getAnalysis(); DominanceAnalysis *domAnalysis = PM->getAnalysis(); diff --git a/lib/SILOptimizer/Transforms/SimplifyCFG.cpp b/lib/SILOptimizer/Transforms/SimplifyCFG.cpp index 66d23367fd71d..95a835cb07a14 100644 --- a/lib/SILOptimizer/Transforms/SimplifyCFG.cpp +++ b/lib/SILOptimizer/Transforms/SimplifyCFG.cpp @@ -3317,6 +3317,12 @@ static bool splitBBArguments(SILFunction &Fn) { } bool SimplifyCFG::run() { +#ifndef SWIFT_ENABLE_SWIFT_IN_SWIFT + // This pass results in verification failures when Swift sources are not + // enabled. + LLVM_DEBUG(llvm::dbgs() << "SimplifyCFG disabled in C++-only Swift compiler\n"); + return false; +#endif //!SWIFT_ENABLE_SWIFT_IN_SWIFT LLVM_DEBUG(llvm::dbgs() << "### Run SimplifyCFG on " << Fn.getName() << '\n'); // Disable some expensive optimizations if the function is huge.