File tree Expand file tree Collapse file tree 2 files changed +43
-0
lines changed
lib/SILOptimizer/Transforms Expand file tree Collapse file tree 2 files changed +43
-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 @@ -300,3 +300,35 @@ bb0(%0 : $*T):
300
300
return %78 : $()
301
301
}
302
302
303
+ sil @createAny : $@convention(thin) () -> @out Any
304
+ sil @createAny_no_barrier : $@convention(thin) () -> @out Any {
305
+ [global:]
306
+ }
307
+
308
+ // CHECK-LABEL: sil [ossa] @test_deinit_barrier :
309
+ // CHECK: copy_addr [take]
310
+ // CHECK-LABEL: } // end sil function 'test_deinit_barrier'
311
+ sil [ossa] @test_deinit_barrier : $@convention(thin) (@guaranteed Any, @inout Any) -> () {
312
+ bb0(%0 : @guaranteed $Any, %1 : $*Any):
313
+ %2 = alloc_stack $Any
314
+ %4 = function_ref @createAny : $@convention(thin) () -> @out Any
315
+ %5 = apply %4(%2) : $@convention(thin) () -> @out Any
316
+ copy_addr [take] %2 to %1 : $*Any
317
+ dealloc_stack %2 : $*Any
318
+ %11 = tuple ()
319
+ return %11 : $()
320
+ }
321
+
322
+ // CHECK-LABEL: sil [ossa] @test_no_deinit_barrier :
323
+ // CHECK-NOT: copy_addr
324
+ // CHECK-LABEL: } // end sil function 'test_no_deinit_barrier'
325
+ sil [ossa] @test_no_deinit_barrier : $@convention(thin) (@guaranteed Any, @inout Any) -> () {
326
+ bb0(%0 : @guaranteed $Any, %1 : $*Any):
327
+ %2 = alloc_stack $Any
328
+ %4 = function_ref @createAny_no_barrier : $@convention(thin) () -> @out Any
329
+ %5 = apply %4(%2) : $@convention(thin) () -> @out Any
330
+ copy_addr [take] %2 to %1 : $*Any
331
+ dealloc_stack %2 : $*Any
332
+ %11 = tuple ()
333
+ return %11 : $()
334
+ }
You can’t perform that action at this time.
0 commit comments