File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed
lib/SILOptimizer/Mandatory Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,18 @@ class UnreachableUserCodeReportingState {
91
91
llvm::DenseMap<const SILBasicBlock*, UnreachableInfo> MetaMap;
92
92
};
93
93
94
+ static void deleteEndBorrows (SILValue v) {
95
+ SmallVector<SILInstruction *, 4 > endBorrowList;
96
+ for (auto *use : v->getUses ()) {
97
+ if (auto *ebi = dyn_cast<EndBorrowInst>(use->getUser ())) {
98
+ endBorrowList.push_back (ebi);
99
+ }
100
+ }
101
+ while (!endBorrowList.empty ()) {
102
+ endBorrowList.pop_back_val ()->eraseFromParent ();
103
+ }
104
+ }
105
+
94
106
// / Propagate/remove basic block input values when all predecessors
95
107
// / supply the same arguments.
96
108
static void propagateBasicBlockArgs (SILBasicBlock &BB) {
@@ -173,6 +185,13 @@ static void propagateBasicBlockArgs(SILBasicBlock &BB) {
173
185
// this to CCP and trigger another round of copy propagation.
174
186
SILArgument *Arg = *AI;
175
187
188
+ // If this argument is guaranteed and Args[Idx] is a SILFunctionArgument,
189
+ // delete the end_borrow.
190
+ if (Arg->getOwnershipKind () == ValueOwnershipKind::Guaranteed &&
191
+ isa<SILFunctionArgument>(Args[Idx])) {
192
+ deleteEndBorrows (Arg);
193
+ }
194
+
176
195
// We were able to fold, so all users should use the new folded value.
177
196
Arg->replaceAllUsesWith (Args[Idx]);
178
197
NumBasicBlockArgsPropagated++;
Original file line number Diff line number Diff line change 3
3
import Builtin
4
4
import Swift
5
5
6
+ sil @guaranteed_nativeobject_user : $@convention(thin) (@guaranteed Builtin.NativeObject) -> ()
7
+
6
8
sil private @test1 : $() -> () {
7
9
bb0:
8
10
%5 = integer_literal $Builtin.Int1, 1
@@ -502,3 +504,21 @@ bb3:
502
504
%9999 = tuple()
503
505
return %9999 : $()
504
506
}
507
+
508
+ // CHECK-LABEL: sil [ossa] @eliminate_end_borrow_when_propagating_bb_args : $@convention(thin) (@guaranteed Builtin.NativeObject) -> () {
509
+ // CHECK-NOT: end_borrow
510
+ // CHECK: [[FUNC_REF:%.*]] = function_ref @guaranteed_nativeobject_user
511
+ // CHECK-NEXT: apply [[FUNC_REF]](%0) :
512
+ // CHECK-NOT: end_borrow
513
+ // CHECK: } // end sil function 'eliminate_end_borrow_when_propagating_bb_args'
514
+ sil [ossa] @eliminate_end_borrow_when_propagating_bb_args : $@convention(thin) (@guaranteed Builtin.NativeObject) -> () {
515
+ bb0(%0 : @guaranteed $Builtin.NativeObject):
516
+ br bb1(%0 : $Builtin.NativeObject)
517
+
518
+ bb1(%1 : @guaranteed $Builtin.NativeObject):
519
+ %2 = function_ref @guaranteed_nativeobject_user : $@convention(thin) (@guaranteed Builtin.NativeObject) -> ()
520
+ apply %2(%1) : $@convention(thin) (@guaranteed Builtin.NativeObject) -> ()
521
+ end_borrow %1 : $Builtin.NativeObject
522
+ %9999 = tuple()
523
+ return %9999 : $()
524
+ }
You can’t perform that action at this time.
0 commit comments