Skip to content

Commit 4ce4b19

Browse files
committed
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. Fixes: rdar://146357242
1 parent 3860023 commit 4ce4b19

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

cmake/modules/AddSwift.cmake

+3
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,9 @@ function(_add_host_variant_c_compile_flags target)
324324
target_compile_definitions(${target} PRIVATE
325325
$<$<COMPILE_LANGUAGE:C,CXX,OBJC,OBJCXX>:_LARGEFILE_SOURCE _FILE_OFFSET_BITS=64>)
326326
endif()
327+
328+
target_compile_options(${target} PRIVATE
329+
$<$<AND:$<COMPILE_LANGUAGE:C,CXX,OBJC,OBJCXX>,$<BOOL:${SWIFT_ENABLE_SWIFT_IN_SWIFT}>>:SWIFT_ENABLE_SWIFT_IN_SWIFT>)
327330
endfunction()
328331

329332
function(_add_host_variant_link_flags target)

lib/SILOptimizer/LoopTransforms/LoopRotate.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,12 @@ namespace {
485485
class LoopRotation : public SILFunctionTransform {
486486

487487
void run() override {
488+
#ifndef SWIFT_ENABLE_SWIFT_IN_SWIFT
489+
// This pass results in verification failures when Swift sources are not
490+
// enabled.
491+
LLVM_DEBUG(llvm::dbgs() << "Loop Rotate disabled in C++-only Swift compiler\n");
492+
return;
493+
#endif // !SWIFT_ENABLE_SWIFT_IN_SWIFT
488494
SILFunction *f = getFunction();
489495
SILLoopAnalysis *loopAnalysis = PM->getAnalysis<SILLoopAnalysis>();
490496
DominanceAnalysis *domAnalysis = PM->getAnalysis<DominanceAnalysis>();

lib/SILOptimizer/Transforms/SimplifyCFG.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -3317,6 +3317,12 @@ static bool splitBBArguments(SILFunction &Fn) {
33173317
}
33183318

33193319
bool SimplifyCFG::run() {
3320+
#ifndef SWIFT_ENABLE_SWIFT_IN_SWIFT
3321+
// This pass results in verification failures when Swift sources are not
3322+
// enabled.
3323+
LLVM_DEBUG(llvm::dbgs() << "SimplifyCFG disabled in C++-only Swift compiler\n");
3324+
return false;
3325+
#endif //!SWIFT_ENABLE_SWIFT_IN_SWIFT
33203326
LLVM_DEBUG(llvm::dbgs() << "### Run SimplifyCFG on " << Fn.getName() << '\n');
33213327

33223328
// Disable some expensive optimizations if the function is huge.

0 commit comments

Comments
 (0)