Skip to content

Commit 57bc670

Browse files
committed
[SILOpt] Add tester for visit adjacent reborrows.
1 parent eee8573 commit 57bc670

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

lib/SILOptimizer/UtilityPasses/UnitTestRunner.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,23 @@ struct CanonicalizeOSSALifetimeTest : UnitTest {
199199
}
200200
};
201201

202-
/// [new_tests] Add the new UnitTest subclass below this line.
202+
// Arguments:
203+
// - SILValue: phi
204+
// Dumps:
205+
// - function
206+
// - the adjacent phis
207+
struct VisitAdjacentReborrowsOfPhiTest : UnitTest {
208+
VisitAdjacentReborrowsOfPhiTest(UnitTestRunner *pass) : UnitTest(pass) {}
209+
void invoke(Arguments &arguments) override {
210+
getFunction()->dump();
211+
visitAdjacentReborrowsOfPhi(cast<SILPhiArgument>(arguments.takeValue()),
212+
[](auto *argument) -> bool {
213+
argument->dump();
214+
return true;
215+
});
216+
}
217+
};
218+
203219
/// [new_tests] Add the new UnitTest subclass above this line.
204220

205221
class UnitTestRunner : public SILFunctionTransform {
@@ -232,6 +248,8 @@ class UnitTestRunner : public SILFunctionTransform {
232248
ADD_UNIT_TEST_SUBCLASS("test-specification-parsing", TestSpecificationTest)
233249
ADD_UNIT_TEST_SUBCLASS("canonicalize-ossa-lifetime",
234250
CanonicalizeOSSALifetimeTest)
251+
ADD_UNIT_TEST_SUBCLASS("visit-adjacent-reborrows-of-phi",
252+
VisitAdjacentReborrowsOfPhiTest)
235253
/// [new_tests] Add the new mapping from string to subclass above this line.
236254

237255
#undef ADD_UNIT_TEST_SUBCLASS

test/SILOptimizer/unit_test.sil

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,36 @@ entry:
106106
return %retval : $()
107107
}
108108

109+
// CHECK-LABEL: begin running test 1 of 1 on pay_the_phi: visit-adjacent-reborrows-of-phi with: @trace[2]
110+
// CHECK: sil [ossa] @pay_the_phi : {{.*}} {
111+
// CHECK: [[C:%[^,]+]] = apply
112+
// CHECK: [[BORROW1:%[^,]+]] = begin_borrow %1
113+
// CHECK: [[BORROW2:%[^,]+]] = begin_borrow %1
114+
// CHECK: br [[EXIT:bb[0-9]+]]([[C]] : $C, [[BORROW1]] : $C, [[BORROW2]] :
115+
// CHECK: [[EXIT]]({{%[^,]+}} : @owned $C, [[GUARANTEED1:%[^,]+]] : @guaranteed $C, [[GUARANTEED2:%[^,]+]] :
116+
// CHECK: } // end sil function 'pay_the_phi'
117+
118+
// CHECK:[[GUARANTEED1]] = argument of [[EXIT]]
119+
// CHECK:[[GUARANTEED2]] = argument of [[EXIT]]
120+
// CHECK-LABEL: end running test 1 of 1 on pay_the_phi: visit-adjacent-reborrows-of-phi with: @trace[2]
121+
sil [ossa] @pay_the_phi : $@convention(thin) () -> () {
122+
entry:
123+
test_specification "visit-adjacent-reborrows-of-phi @trace[2]"
124+
%getC = function_ref @getC : $@convention(thin) () -> @owned C
125+
%c = apply %getC() : $@convention(thin) () -> @owned C
126+
debug_value [trace] %c : $C
127+
%borrow1 = begin_borrow %c : $C
128+
%borrow2 = begin_borrow %c : $C
129+
debug_value [trace] %borrow2 : $C
130+
%borrow3 = begin_borrow %borrow2 : $C
131+
br exit(%c : $C, %borrow1 : $C, %borrow2 : $C, %borrow3 : $C)
132+
133+
exit(%owned : @owned $C, %guaranteed_1 : @guaranteed $C, %guaranteed_2 : @guaranteed $C, %guaranteed_3 : @guaranteed $C):
134+
debug_value [trace] %owned : $C
135+
end_borrow %guaranteed_3 : $C
136+
end_borrow %guaranteed_2 : $C
137+
end_borrow %guaranteed_1 : $C
138+
destroy_value %owned : $C
139+
%retval = tuple ()
140+
return %retval : $()
141+
}

0 commit comments

Comments
 (0)