File tree Expand file tree Collapse file tree 3 files changed +55
-0
lines changed
SwiftCompilerSources/Sources/Optimizer/Utilities
test/SILOptimizer/ownership_utils Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Original file line number Diff line number Diff line change @@ -564,3 +564,22 @@ extension AddressOwnershipLiveRange {
564
564
return . local( allocation, range)
565
565
}
566
566
}
567
+
568
+ let addressOwnershipLiveRangeTest = FunctionTest ( " address_ownership_live_range " ) {
569
+ function, arguments, context in
570
+ let address = arguments. takeValue ( )
571
+ print ( " Address: \( address) " )
572
+ print ( " Base: \( address. accessBase) " )
573
+ let begin = address. definingInstructionOrTerminator ?? {
574
+ assert ( address is FunctionArgument )
575
+ return function. instructions. first!
576
+ } ( )
577
+ let localReachabilityCache = LocalVariableReachabilityCache ( )
578
+ guard var ownershipRange = AddressOwnershipLiveRange . compute ( for: address, at: begin,
579
+ localReachabilityCache, context) else {
580
+ print ( " Error: indeterminate live range " )
581
+ return
582
+ }
583
+ defer { ownershipRange. deinitialize ( ) }
584
+ print ( ownershipRange)
585
+ }
Original file line number Diff line number Diff line change @@ -154,6 +154,7 @@ public func registerOptimizerTests() {
154
154
// Register each test.
155
155
registerFunctionTests (
156
156
getAccessBaseTest,
157
+ addressOwnershipLiveRangeTest,
157
158
argumentConventionsTest,
158
159
borrowIntroducersTest,
159
160
enclosingValuesTest,
Original file line number Diff line number Diff line change
1
+ // RUN: %target-sil-opt -test-runner %s -o /dev/null 2>&1 | %FileCheck %s
2
+
3
+ sil_stage canonical
4
+
5
+ import Builtin
6
+
7
+ class C {}
8
+ class D {
9
+ var object: C
10
+ }
11
+
12
+ // An address live range can be extended by a dependent value.
13
+ //
14
+ // CHECK-LABEL: testMarkDepAddressBase: address_ownership_live_range with: %f0
15
+ // CHECK-NEXT: Address: [[F0:%.*]] = ref_element_addr %0 : $D, #D.object
16
+ // CHECK-NEXT: Base: class - [[F0]] = ref_element_addr %0 : $D, #D.object
17
+ // CHECK-NEXT: borrow: functionArgument(%0 = argument of bb0 : $D
18
+ // CHECK-NEXT: begin: [[F0]] = ref_element_addr %0 : $D, #D.object
19
+ // CHECK-NEXT: ends: end_borrow %{{.*}} : $C
20
+ // CHECK-NEXT: exits:
21
+ // CHECK-NEXT: interiors: %{{.*}} = load_borrow %{{.*}} : $*C
22
+ // CHECK-NEXT: %{{.*}} = mark_dependence %{{.*}} : $*C on [[F0]] : $*C
23
+ // CHECK-NEXT: [[F0]] = ref_element_addr %0 : $D, #D.object
24
+ // CHECK-LABEL: end running test 1 of 1 on testMarkDepAddressBase: address_ownership_live_range with: %f0
25
+ sil [ossa] @testMarkDepAddressBase : $@convention(thin) (@guaranteed D, @guaranteed D) -> () {
26
+ bb0(%0 : @guaranteed $D, %1 : @guaranteed $D):
27
+ %f0 = ref_element_addr %0 : $D, #D.object
28
+ %f1 = ref_element_addr %1 : $D, #D.object
29
+ specify_test "address_ownership_live_range %f0"
30
+ %dependence = mark_dependence %f1 on %f0
31
+ %load = load_borrow %dependence
32
+ end_borrow %load
33
+ %99 = tuple()
34
+ return %99 : $()
35
+ }
You can’t perform that action at this time.
0 commit comments