File tree Expand file tree Collapse file tree 3 files changed +27
-7
lines changed
lib/SILOptimizer/Transforms Expand file tree Collapse file tree 3 files changed +27
-7
lines changed Original file line number Diff line number Diff line change @@ -377,19 +377,24 @@ bool ObjectOutliner::optimizeObjectAllocation(
377
377
// Replace the alloc_ref by global_value + strong_retain instructions.
378
378
SILBuilder B (ARI);
379
379
GlobalValueInst *GVI = B.createGlobalValue (ARI->getLoc (), Glob);
380
- B. createStrongRetain (ARI-> getLoc (), GVI, B. getDefaultAtomicity ()) ;
380
+ bool hasToRetain = true ;
381
381
llvm::SmallVector<Operand *, 8 > Worklist (ARI->use_begin (), ARI->use_end ());
382
382
while (!Worklist.empty ()) {
383
383
auto *Use = Worklist.pop_back_val ();
384
384
SILInstruction *User = Use->getUser ();
385
385
switch (User->getKind ()) {
386
386
case SILInstructionKind::DeallocRefInst:
387
+ case SILInstructionKind::SetDeallocatingInst:
388
+ hasToRetain = false ;
387
389
ToRemove.push_back (User);
388
390
break ;
389
391
default :
390
392
Use->set (GVI);
391
393
}
392
394
}
395
+ if (hasToRetain) {
396
+ B.createStrongRetain (ARI->getLoc (), GVI, B.getDefaultAtomicity ());
397
+ }
393
398
if (FindStringCall && NumTailElems > 16 ) {
394
399
assert (&*std::next (ARI->getIterator ()) != FindStringCall &&
395
400
" FindStringCall must not be the next instruction after ARI because "
Original file line number Diff line number Diff line change @@ -8,10 +8,9 @@ class E : B { }
8
8
9
9
// CHECK: sil @patatino : $@convention(thin) () -> () {
10
10
// CHECK: bb0:
11
- // CHECK: %0 = global_value @patatinoTv_ : $B // user: %1
12
- // CHECK: strong_retain %0 : $B // id: %1
13
- // CHECK: %2 = tuple () // user: %3
14
- // CHECK: return %2 : $() // id: %3
11
+ // CHECK: %0 = global_value @patatinoTv_ : $B
12
+ // CHECK: %1 = tuple ()
13
+ // CHECK: return %1 : $()
15
14
// CHECK: }
16
15
17
16
sil @patatino : $@convention(thin) () -> () {
Original file line number Diff line number Diff line change 74
74
return %r : $()
75
75
}
76
76
77
+ // CHECK-LABEL: sil @handle_deallocation
78
+ // CHECK: global_value
79
+ // CHECK-NEXT: ref_element_addr
80
+ // CHECK-NEXT: tuple
81
+ // CHECK-NEXT: return
82
+ sil @handle_deallocation : $@convention(thin) () -> () {
83
+ bb0:
84
+ %3 = integer_literal $Builtin.Int64, 3
85
+ %4 = struct $Int64 (%3 : $Builtin.Int64)
86
+ %5 = alloc_ref $Obj
87
+ %6 = ref_element_addr %5 : $Obj, #Obj.value
88
+ store %4 to %6 : $*Int64
89
+ set_deallocating %5 : $Obj
90
+ dealloc_ref %5 : $Obj
91
+ %r = tuple ()
92
+ return %r : $()
93
+ }
94
+
77
95
// CHECK-LABEL: sil @dont_outline_global_double_store
78
96
// CHECK: alloc_ref
79
97
// CHECK: store
203
221
%r = tuple ()
204
222
return %r : $()
205
223
}
206
-
207
-
You can’t perform that action at this time.
0 commit comments