Skip to content

Commit d5f1908

Browse files
committed
[Test] Verified some non-deinit-barrier applies.
Checked that applies of empty functions, or their callees, or their callees' callees, are not deinit barriers. Checked that applies of unknown functions, or their callees, or their callees' calles, are deinit barriers.
1 parent 4476088 commit d5f1908

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed

lib/SILOptimizer/UtilityPasses/UnitTestRunner.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,11 @@
7272
#include "swift/SIL/SILBridging.h"
7373
#include "swift/SIL/SILFunction.h"
7474
#include "swift/SIL/SILInstruction.h"
75+
#include "swift/SILOptimizer/Analysis/BasicCalleeAnalysis.h"
7576
#include "swift/SILOptimizer/PassManager/Passes.h"
7677
#include "swift/SILOptimizer/PassManager/Transforms.h"
7778
#include "swift/SILOptimizer/Utils/CanonicalizeOSSALifetime.h"
79+
#include "swift/SILOptimizer/Utils/InstOptUtils.h"
7880
#include "swift/SILOptimizer/Utils/InstructionDeleter.h"
7981
#include "swift/SILOptimizer/Utils/ParseTestSpecification.h"
8082
#include "llvm/ADT/StringRef.h"
@@ -255,6 +257,23 @@ struct FunctionGetSelfArgumentIndex : UnitTest {
255257
}
256258
};
257259

260+
// Arguments:
261+
// - instruction
262+
// Dumps:
263+
// - instruction
264+
// - whether it's a deinit barrier
265+
struct IsDeinitBarrierTest : UnitTest {
266+
IsDeinitBarrierTest(UnitTestRunner *pass) : UnitTest(pass) {}
267+
void invoke(Arguments &arguments) override {
268+
auto *instruction = arguments.takeInstruction();
269+
auto *analysis = getAnalysis<BasicCalleeAnalysis>();
270+
auto isBarrier = isDeinitBarrier(instruction, analysis);
271+
instruction->dump();
272+
auto *boolString = isBarrier ? "true" : "false";
273+
llvm::errs() << boolString << "\n";
274+
}
275+
};
276+
258277
/// [new_tests] Add the new UnitTest subclass above this line.
259278

260279
class UnitTestRunner : public SILFunctionTransform {
@@ -295,6 +314,7 @@ class UnitTestRunner : public SILFunctionTransform {
295314
ADD_UNIT_TEST_SUBCLASS(
296315
"pruned-liveness-boundary-with-list-of-last-users-insertion-points",
297316
PrunedLivenessBoundaryWithListOfLastUsersInsertionPointsTest)
317+
ADD_UNIT_TEST_SUBCLASS("is-deinit-barrier", IsDeinitBarrierTest)
298318
/// [new_tests] Add the new mapping from string to subclass above this line.
299319

300320
#undef ADD_UNIT_TEST_SUBCLASS

test/SILOptimizer/deinit_barrier.sil

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// RUN: %target-sil-opt -compute-side-effects -unit-test-runner %s 2>&1 | %FileCheck %s
2+
3+
// REQUIRES: swift_in_compiler
4+
5+
sil [ossa] @unknown : $@convention(thin) () -> ()
6+
7+
sil [ossa] @unknown_caller : $@convention(thin) () -> () {
8+
%unknown = function_ref @unknown : $@convention(thin) () -> ()
9+
apply %unknown() : $@convention(thin) () -> ()
10+
%retval = tuple ()
11+
return %retval : $()
12+
}
13+
14+
sil [ossa] @empty_fn : $@convention(thin) () -> () {
15+
%retval = tuple ()
16+
return %retval : $()
17+
}
18+
19+
sil [ossa] @empty_fn_caller : $@convention(thin) () -> () {
20+
%empty_fn = function_ref @empty_fn : $@convention(thin) () -> ()
21+
apply %empty_fn() : $@convention(thin) () -> ()
22+
%retval = tuple ()
23+
return %retval : $()
24+
}
25+
26+
sil [ossa] @empty_fn_caller_caller : $@convention(thin) () -> () {
27+
%empty_fn_caller = function_ref @empty_fn_caller : $@convention(thin) () -> ()
28+
apply %empty_fn_caller() : $@convention(thin) () -> ()
29+
%retval = tuple ()
30+
return %retval : $()
31+
}
32+
33+
34+
// CHECK-LABEL: begin running test 1 of {{[0-9]+}} on call_functions: dump-function
35+
// CHECK: [[EMPTY_FN:%[^,]+]] = function_ref @empty_fn
36+
// CHECK: [[EMPTY_FN_CALLER:%[^,]+]] = function_ref @empty_fn_caller
37+
// CHECK: [[EMPTY_FN_CALLER_CALLER:%[^,]+]] = function_ref @empty_fn_caller_caller
38+
// CHECK: [[UNKNOWN:%[^,]+]] = function_ref @unknown
39+
// CHECK: [[UNKNOWN_CALLER:%[^,]+]] = function_ref @unknown_caller
40+
// CHECK-LABEL: end running test 1 of {{[0-9]+}} on call_functions: dump-function
41+
// CHECK-LABEL: begin running test 2 of {{[0-9]+}} on call_functions: is-deinit-barrier
42+
// CHECK: apply [[EMPTY_FN]]
43+
// CHECK: false
44+
// CHECK-LABEL: end running test 2 of {{[0-9]+}} on call_functions: is-deinit-barrier
45+
// CHECK-LABEL: begin running test 3 of {{[0-9]+}} on call_functions: is-deinit-barrier
46+
// CHECK: apply [[EMPTY_FN_CALLER]]
47+
// CHECK: false
48+
// CHECK-LABEL: end running test 3 of {{[0-9]+}} on call_functions: is-deinit-barrier
49+
// CHECK-LABEL: begin running test 4 of {{[0-9]+}} on call_functions: is-deinit-barrier
50+
// CHECK: apply [[EMPTY_FN_CALLER_CALLER]]
51+
// CHECK: false
52+
// CHECK-LABEL: end running test 4 of {{[0-9]+}} on call_functions: is-deinit-barrier
53+
// CHECK-LABEL: begin running test 5 of {{[0-9]+}} on call_functions: is-deinit-barrier
54+
// CHECK: apply [[UNKNOWN]]
55+
// CHECK: true
56+
// CHECK-LABEL: end running test 5 of {{[0-9]+}} on call_functions: is-deinit-barrier
57+
// CHECK-LABEL: begin running test 6 of {{[0-9]+}} on call_functions: is-deinit-barrier
58+
// CHECK: apply [[UNKNOWN_CALLER]]
59+
// CHECK: true
60+
// CHECK-LABEL: end running test 6 of {{[0-9]+}} on call_functions: is-deinit-barrier
61+
sil [ossa] @call_functions : $@convention(thin) () -> () {
62+
entry:
63+
test_specification "dump-function"
64+
test_specification "is-deinit-barrier @instruction[1]"
65+
%empty_fn = function_ref @empty_fn : $@convention(thin) () -> ()
66+
apply %empty_fn() : $@convention(thin) () -> ()
67+
68+
test_specification "is-deinit-barrier @instruction[3]"
69+
%empty_fn_caller = function_ref @empty_fn_caller : $@convention(thin) () -> ()
70+
apply %empty_fn_caller() : $@convention(thin) () -> ()
71+
72+
test_specification "is-deinit-barrier @instruction[5]"
73+
%empty_fn_caller_caller = function_ref @empty_fn_caller_caller : $@convention(thin) () -> ()
74+
apply %empty_fn_caller_caller() : $@convention(thin) () -> ()
75+
76+
test_specification "is-deinit-barrier @instruction[7]"
77+
%unknown = function_ref @unknown : $@convention(thin) () -> ()
78+
apply %unknown() : $@convention(thin) () -> ()
79+
80+
test_specification "is-deinit-barrier @instruction[9]"
81+
%unknown_caller = function_ref @unknown_caller : $@convention(thin) () -> ()
82+
apply %unknown_caller() : $@convention(thin) () -> ()
83+
84+
%retval = tuple ()
85+
return %retval : $()
86+
}
87+

0 commit comments

Comments
 (0)