Skip to content

Commit 1dab294

Browse files
committed
Optimizer: enable the DeinitDevirtualizer pass
It was disabled so far to not hide bugs in the deinit code generation. Now hopefully deinit code generation is stable enough to enable the pass.
1 parent 32b53f8 commit 1dab294

File tree

5 files changed

+17
-30
lines changed

5 files changed

+17
-30
lines changed

lib/SILOptimizer/PassManager/PassPipeline.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,6 @@ static llvm::cl::opt<bool> SILViewSILGenCFG(
6262
"sil-view-silgen-cfg", llvm::cl::init(false),
6363
llvm::cl::desc("Enable the sil cfg viewer pass before diagnostics"));
6464

65-
static llvm::cl::opt<bool>
66-
EnableDeinitDevirtualizer("enable-deinit-devirtualizer", llvm::cl::init(false),
67-
llvm::cl::desc("Enable the DestroyHoisting pass."));
68-
6965
//===----------------------------------------------------------------------===//
7066
// Diagnostic Pass Pipeline
7167
//===----------------------------------------------------------------------===//
@@ -191,14 +187,6 @@ static void addMandatoryDiagnosticOptPipeline(SILPassPipelinePlan &P) {
191187
P.addLifetimeDependenceDiagnostics();
192188
}
193189

194-
// Devirtualize deinits early if requested.
195-
//
196-
// FIXME: why is DeinitDevirtualizer in the middle of the mandatory pipeline,
197-
// and what passes/compilation modes depend on it? This pass is never executed
198-
// or tested without '-Xllvm enable-deinit-devirtualizer'.
199-
if (EnableDeinitDevirtualizer)
200-
P.addDeinitDevirtualizer();
201-
202190
// As a temporary measure, we also eliminate move only for non-trivial types
203191
// until we can audit the later part of the pipeline. Eventually, this should
204192
// occur before IRGen.
@@ -518,6 +506,8 @@ void addFunctionPasses(SILPassPipelinePlan &P,
518506
}
519507
P.addARCSequenceOpts();
520508

509+
P.addDeinitDevirtualizer();
510+
521511
// We earlier eliminated ownership if we are not compiling the stdlib. Now
522512
// handle the stdlib functions, re-simplifying, eliminating ARC as we do.
523513
if (P.getOptions().CopyPropagation != CopyPropagationOption::Off) {

test/IRGen/moveonly_value_functions.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-swift-emit-irgen -O \
2+
// RUN: -Xllvm -sil-disable-pass=deinit-devirtualizer \
23
// RUN: -disable-type-layout \
34
// RUN: %s \
45
// RUN: | \

test/IRGen/raw_layout_multifile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: %{python} %utils/chex.py < %s > %t/raw_layout_multifile.swift
3-
// RUN: %target-swift-frontend -enable-experimental-feature BuiltinModule -enable-experimental-feature RawLayout -emit-ir -O -disable-availability-checking %s %S/Inputs/raw_layout_multifile_b.swift | %FileCheck %t/raw_layout_multifile.swift --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize
3+
// RUN: %target-swift-frontend -enable-experimental-feature BuiltinModule -enable-experimental-feature RawLayout -emit-ir -O -Xllvm -sil-disable-pass=deinit-devirtualizer -disable-availability-checking %s %S/Inputs/raw_layout_multifile_b.swift | %FileCheck %t/raw_layout_multifile.swift --check-prefix=CHECK --check-prefix=CHECK-%target-ptrsize
44

55
@_rawLayout(like: Int32)
66
public struct Foo<T>: ~Copyable {}

test/SILOptimizer/devirt_deinits.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
// RUN: %target-swift-frontend -target %target-cpu-apple-macos14 -primary-file %s -parse-as-library -sil-verify-all -Xllvm -enable-deinit-devirtualizer -module-name=test -emit-sil | %FileCheck %s
1+
// RUN: %target-swift-frontend -target %target-cpu-apple-macos14 -primary-file %s -parse-as-library -O -sil-verify-all -module-name=test -Xllvm -sil-disable-pass=function-signature-opts -emit-sil | %FileCheck %s
22

33
// Also do an end-to-end test and check if the compiled executable works as expected.
4-
// RUN: %target-run-simple-swift(-target %target-cpu-apple-macos14 -Xllvm -enable-deinit-devirtualizer -parse-as-library) | %FileCheck -check-prefix CHECK-OUTPUT %s
4+
// RUN: %target-run-simple-swift(-target %target-cpu-apple-macos14 -parse-as-library -O -Xllvm -sil-disable-pass=function-signature-opts) | %FileCheck -check-prefix CHECK-OUTPUT %s
55

66
// Check if it works in embedded mode.
77
// RUN: %target-run-simple-swift(-target %target-cpu-apple-macos14 -enable-experimental-feature Embedded -parse-as-library -runtime-compatibility-version none -wmo -Xfrontend -disable-objc-interop) | %FileCheck -check-prefix CHECK-OUTPUT %s
@@ -98,8 +98,8 @@ func testTwoFieldDeinits(_ s: consuming StrWithoutDeinit) {
9898
}
9999

100100
// CHECK-LABEL: sil hidden [noinline] @$s4test0A5Enum1yyAA2E1OnF :
101-
// CHECK: switch_enum_addr
102-
// CHECK: bb1:
101+
// CHECK: switch_enum
102+
// CHECK: bb1({{.*}}):
103103
// CHECK: [[D:%.*]] = function_ref @$s4test2S1VfD :
104104
// CHECK: apply [[D]]
105105
// CHECK: } // end sil function '$s4test0A5Enum1yyAA2E1OnF'
@@ -109,13 +109,13 @@ func testEnum1(_ s: consuming E1) {
109109
}
110110

111111
// CHECK-LABEL: sil hidden [noinline] @$s4test0A5Enum2yyAA2E2OnF :
112-
// CHECK: switch_enum_addr
113-
// CHECK: bb1:
112+
// CHECK: switch_enum
113+
// CHECK: bb1({{.*}}):
114114
// CHECK: [[D:%.*]] = function_ref @$s4test2S2VfD :
115115
// CHECK: apply [[D]]
116-
// CHECK: bb2:
117-
// CHECK: switch_enum_addr
118-
// CHECK: bb3:
116+
// CHECK: bb2({{.*}}):
117+
// CHECK: switch_enum
118+
// CHECK: bb3({{.*}}):
119119
// CHECK: [[D:%.*]] = function_ref @$s4test2S1VfD :
120120
// CHECK: apply [[D]]
121121
// CHECK: } // end sil function '$s4test0A5Enum2yyAA2E2OnF'

test/SILOptimizer/stdlib/Atomics.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ func testInt(_: Int)
1515
// CHECK: [[ATOMIC:%.*]] = alloc_stack [lexical] [var_decl] $Atomic<Int>
1616
// CHECK: [[ATOMIC_PTR:%.*]] = address_to_pointer [[ATOMIC]]
1717
// CHECK: builtin "atomicload_monotonic_Int[[PTR_SIZE]]"([[ATOMIC_PTR]] : $Builtin.RawPointer)
18-
// CHECK: destroy_addr [[ATOMIC]] : $*Atomic<Int>
19-
// CHECK-NEXT: dealloc_stack [[ATOMIC]] : $*Atomic<Int>
18+
// CHECK: dealloc_stack [[ATOMIC]] : $*Atomic<Int>
2019
// CHECK-LABEL: } // end sil function 'localLoad'
2120
@_silgen_name("localLoad")
2221
func localLoad() -> Int {
@@ -28,8 +27,7 @@ func localLoad() -> Int {
2827
// CHECK: [[ATOMIC:%.*]] = alloc_stack [lexical] [var_decl] $Atomic<Int>
2928
// CHECK: [[ATOMIC_PTR:%.*]] = address_to_pointer [[ATOMIC]]
3029
// CHECK: builtin "atomicstore_release_Int[[PTR_SIZE]]"([[ATOMIC_PTR]] : $Builtin.RawPointer
31-
// CHECK: destroy_addr [[ATOMIC]] : $*Atomic<Int>
32-
// CHECK-NEXT: dealloc_stack [[ATOMIC]] : $*Atomic<Int>
30+
// CHECK: dealloc_stack [[ATOMIC]] : $*Atomic<Int>
3331
// CHECK-LABEL: } // end sil function 'localStore'
3432
@_silgen_name("localStore")
3533
func localStore() {
@@ -41,8 +39,7 @@ func localStore() {
4139
// CHECK: [[ATOMIC:%.*]] = alloc_stack [lexical] [var_decl] $Atomic<Int>
4240
// CHECK: [[ATOMIC_PTR:%.*]] = address_to_pointer [[ATOMIC]]
4341
// CHECK: builtin "atomicrmw_xchg_acquire_Int[[PTR_SIZE]]"([[ATOMIC_PTR]] : $Builtin.RawPointer
44-
// CHECK: destroy_addr [[ATOMIC]] : $*Atomic<Int>
45-
// CHECK-NEXT: dealloc_stack [[ATOMIC]] : $*Atomic<Int>
42+
// CHECK: dealloc_stack [[ATOMIC]] : $*Atomic<Int>
4643
// CHECK-LABEL: } // end sil function 'localExchange'
4744
@_silgen_name("localExchange")
4845
func localExchange() -> Int {
@@ -54,8 +51,7 @@ func localExchange() -> Int {
5451
// CHECK: [[ATOMIC:%.*]] = alloc_stack [lexical] [var_decl] $Atomic<Int>
5552
// CHECK: [[ATOMIC_PTR:%.*]] = address_to_pointer [[ATOMIC]]
5653
// CHECK: builtin "cmpxchg_seqcst_seqcst_Int[[PTR_SIZE]]"([[ATOMIC_PTR]] : $Builtin.RawPointer
57-
// CHECK: destroy_addr [[ATOMIC]] : $*Atomic<Int>
58-
// CHECK-NEXT: dealloc_stack [[ATOMIC]] : $*Atomic<Int>
54+
// CHECK: dealloc_stack [[ATOMIC]] : $*Atomic<Int>
5955
// CHECK-LABEL: } // end sil function 'localCompareExchange'
6056
@_silgen_name("localCompareExchange")
6157
func localCompareExchange() -> (exchanged: Bool, original: Int) {

0 commit comments

Comments
 (0)