File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed
lib/SILOptimizer/Transforms Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change 18
18
19
19
#include " swift/SILOptimizer/PassManager/Transforms.h"
20
20
#include " swift/SILOptimizer/Analysis/AliasAnalysis.h"
21
+ #include " swift/SILOptimizer/Analysis/BasicCalleeAnalysis.h"
21
22
#include " swift/SIL/NodeBits.h"
22
23
#include " swift/SIL/SILFunction.h"
23
24
#include " swift/SIL/SILBasicBlock.h"
@@ -176,6 +177,13 @@ void TempLValueOptPass::tempLValueOpt(CopyAddrInst *copyInst) {
176
177
// but a block argument.
177
178
SILInstruction *destRootInst = destRootAddr->getDefiningInstruction ();
178
179
180
+ bool needDestroyEarly = false ;
181
+ BasicCalleeAnalysis *bca = nullptr ;
182
+ if (!copyInst->isInitializationOfDest ()) {
183
+ needDestroyEarly = true ;
184
+ bca = PM->getAnalysis <BasicCalleeAnalysis>();
185
+ }
186
+
179
187
// Iterate over the liferange of the temporary and make some validity checks.
180
188
AliasAnalysis *AA = nullptr ;
181
189
SILInstruction *beginOfLiferange = nullptr ;
@@ -220,6 +228,9 @@ void TempLValueOptPass::tempLValueOpt(CopyAddrInst *copyInst) {
220
228
// Needed to treat init_existential_addr as not-writing projection.
221
229
projections.contains (inst) == 0 )
222
230
return ;
231
+
232
+ if (needDestroyEarly && isDeinitBarrier (inst, bca))
233
+ return ;
223
234
}
224
235
}
225
236
assert (endOfLiferangeReached);
Original file line number Diff line number Diff line change 1
1
// RUN: %target-sil-opt -enable-sil-verify-all %s -temp-lvalue-opt | %FileCheck %s
2
2
3
+ // REQUIRES: swift_in_compiler
4
+
3
5
import Swift
4
6
import Builtin
5
7
@@ -300,3 +302,35 @@ bb0(%0 : $*T):
300
302
return %78 : $()
301
303
}
302
304
305
+ sil @createAny : $@convention(thin) () -> @out Any
306
+ sil @createAny_no_barrier : $@convention(thin) () -> @out Any {
307
+ [global:]
308
+ }
309
+
310
+ // CHECK-LABEL: sil [ossa] @test_deinit_barrier :
311
+ // CHECK: copy_addr [take]
312
+ // CHECK-LABEL: } // end sil function 'test_deinit_barrier'
313
+ sil [ossa] @test_deinit_barrier : $@convention(thin) (@guaranteed Any, @inout Any) -> () {
314
+ bb0(%0 : @guaranteed $Any, %1 : $*Any):
315
+ %2 = alloc_stack $Any
316
+ %4 = function_ref @createAny : $@convention(thin) () -> @out Any
317
+ %5 = apply %4(%2) : $@convention(thin) () -> @out Any
318
+ copy_addr [take] %2 to %1 : $*Any
319
+ dealloc_stack %2 : $*Any
320
+ %11 = tuple ()
321
+ return %11 : $()
322
+ }
323
+
324
+ // CHECK-LABEL: sil [ossa] @test_no_deinit_barrier :
325
+ // CHECK-NOT: copy_addr
326
+ // CHECK-LABEL: } // end sil function 'test_no_deinit_barrier'
327
+ sil [ossa] @test_no_deinit_barrier : $@convention(thin) (@guaranteed Any, @inout Any) -> () {
328
+ bb0(%0 : @guaranteed $Any, %1 : $*Any):
329
+ %2 = alloc_stack $Any
330
+ %4 = function_ref @createAny_no_barrier : $@convention(thin) () -> @out Any
331
+ %5 = apply %4(%2) : $@convention(thin) () -> @out Any
332
+ copy_addr [take] %2 to %1 : $*Any
333
+ dealloc_stack %2 : $*Any
334
+ %11 = tuple ()
335
+ return %11 : $()
336
+ }
You can’t perform that action at this time.
0 commit comments