1010//
1111//===----------------------------------------------------------------------===//
1212
13- import SIL
14-
1513/// A range of instructions.
1614///
1715/// The `InstructionRange` defines a range from a dominating "begin" instruction to one or more "end" instructions.
@@ -38,29 +36,29 @@ import SIL
3836/// This type should be a move-only type, but unfortunately we don't have move-only
3937/// types yet. Therefore it's needed to call `deinitialize()` explicitly to
4038/// destruct this data structure, e.g. in a `defer {}` block.
41- struct InstructionRange : CustomStringConvertible , NoReflectionChildren {
42-
39+ public struct InstructionRange : CustomStringConvertible , NoReflectionChildren {
40+
4341 /// The underlying block range.
44- private( set) var blockRange : BasicBlockRange
42+ public private( set) var blockRange : BasicBlockRange
4543
4644 private var insertedInsts : InstructionSet
4745
4846 // For efficiency, this set does not include instructions in blocks which are not the begin or any end block.
4947 private var inExclusiveRange : InstructionSet
5048
51- init ( begin beginInst: Instruction , _ context: some Context ) {
49+ public init ( begin beginInst: Instruction , _ context: some Context ) {
5250 self = InstructionRange ( beginBlock: beginInst. parentBlock, context)
5351 self . inExclusiveRange. insert ( beginInst)
5452 }
5553
5654 // Note: 'ends' are simply the instructions to insert in the range. 'self.ends' might not return the same sequence
5755 // as this 'ends' argument because 'self.ends' will not include block exits.
58- init < S: Sequence > ( begin beginInst: Instruction , ends: S , _ context: some Context ) where S. Element: Instruction {
56+ public init < S: Sequence > ( begin beginInst: Instruction , ends: S , _ context: some Context ) where S. Element: Instruction {
5957 self = InstructionRange ( begin: beginInst, context)
6058 insert ( contentsOf: ends)
6159 }
6260
63- init ( for value: Value , _ context: some Context ) {
61+ public init ( for value: Value , _ context: some Context ) {
6462 if let inst = value. definingInstruction {
6563 self = InstructionRange ( begin: inst, context)
6664 } else if let arg = value as? Argument {
@@ -77,7 +75,7 @@ struct InstructionRange : CustomStringConvertible, NoReflectionChildren {
7775 }
7876
7977 /// Insert a potential end instruction.
80- mutating func insert( _ inst: Instruction ) {
78+ public mutating func insert( _ inst: Instruction ) {
8179 insertedInsts. insert ( inst)
8280 insertIntoRange ( instructions: ReverseInstructionList ( first: inst. previous) )
8381 if blockRange. insert ( inst. parentBlock) {
@@ -90,14 +88,14 @@ struct InstructionRange : CustomStringConvertible, NoReflectionChildren {
9088 }
9189
9290 /// Insert a sequence of potential end instructions.
93- mutating func insert< S: Sequence > ( contentsOf other: S ) where S. Element: Instruction {
91+ public mutating func insert< S: Sequence > ( contentsOf other: S ) where S. Element: Instruction {
9492 for inst in other {
9593 insert ( inst)
9694 }
9795 }
9896
9997 /// Returns true if the exclusive range contains `inst`.
100- func contains( _ inst: Instruction ) -> Bool {
98+ public func contains( _ inst: Instruction ) -> Bool {
10199 if inExclusiveRange. contains ( inst) {
102100 return true
103101 }
@@ -106,37 +104,37 @@ struct InstructionRange : CustomStringConvertible, NoReflectionChildren {
106104 }
107105
108106 /// Returns true if the inclusive range contains `inst`.
109- func inclusiveRangeContains ( _ inst: Instruction ) -> Bool {
107+ public func inclusiveRangeContains ( _ inst: Instruction ) -> Bool {
110108 contains ( inst) || insertedInsts. contains ( inst)
111109 }
112110
113111 /// Returns the end instructions.
114112 ///
115113 /// Warning: this returns `begin` if no instructions were inserted.
116- var ends : LazyMapSequence < LazyFilterSequence < Stack < BasicBlock > > , Instruction > {
114+ public var ends : LazyMapSequence < LazyFilterSequence < Stack < BasicBlock > > , Instruction > {
117115 blockRange. ends. map {
118116 $0. instructions. reversed ( ) . first ( where: { insertedInsts. contains ( $0) } ) !
119117 }
120118 }
121119
122120 // Returns the exit blocks.
123- var exitBlocks : LazySequence < FlattenSequence <
124- LazyMapSequence < LazyFilterSequence < Stack < BasicBlock > > ,
121+ public var exitBlocks : LazySequence < FlattenSequence <
122+ LazyMapSequence < LazyFilterSequence < Stack < BasicBlock > > ,
125123 LazyFilterSequence < SuccessorArray > > > > {
126124 blockRange. exits
127125 }
128126
129127 /// Returns the exit instructions.
130- var exits : LazyMapSequence < LazySequence < FlattenSequence <
131- LazyMapSequence < LazyFilterSequence < Stack < BasicBlock > > ,
128+ public var exits : LazyMapSequence < LazySequence < FlattenSequence <
129+ LazyMapSequence < LazyFilterSequence < Stack < BasicBlock > > ,
132130 LazyFilterSequence < SuccessorArray > > > > ,
133131 Instruction > {
134132 blockRange. exits. lazy. map { $0. instructions. first! }
135133 }
136134
137135 /// Returns the interior instructions.
138- var interiors : LazySequence < FlattenSequence <
139- LazyMapSequence < Stack < BasicBlock > ,
136+ public var interiors : LazySequence < FlattenSequence <
137+ LazyMapSequence < Stack < BasicBlock > ,
140138 LazyFilterSequence < ReverseInstructionList > > > > {
141139 blockRange. inserted. lazy. flatMap {
142140 var include = blockRange. contains ( $0)
@@ -151,7 +149,7 @@ struct InstructionRange : CustomStringConvertible, NoReflectionChildren {
151149 }
152150 }
153151
154- var begin : Instruction ? {
152+ public var begin : Instruction ? {
155153 blockRange. begin. instructions. first ( where: inExclusiveRange. contains)
156154 }
157155
@@ -163,7 +161,7 @@ struct InstructionRange : CustomStringConvertible, NoReflectionChildren {
163161 }
164162 }
165163
166- var description : String {
164+ public var description : String {
167165 return ( blockRange. isValid ? " " : " <invalid> \n " ) +
168166 """
169167 begin: \( begin? . description ?? blockRange. begin. name)
@@ -174,15 +172,15 @@ struct InstructionRange : CustomStringConvertible, NoReflectionChildren {
174172 }
175173
176174 /// TODO: once we have move-only types, make this a real deinit.
177- mutating func deinitialize( ) {
175+ public mutating func deinitialize( ) {
178176 inExclusiveRange. deinitialize ( )
179177 insertedInsts. deinitialize ( )
180178 blockRange. deinitialize ( )
181179 }
182180}
183181
184182extension InstructionRange {
185- enum PathOverlap {
183+ public enum PathOverlap {
186184 // range: ---
187185 // | pathBegin
188186 // | |
@@ -226,7 +224,7 @@ extension InstructionRange {
226224 /// Returns .containsBegin, if this range has the same begin and end as the path.
227225 ///
228226 /// Precondition: `begin` dominates `end`.
229- func overlaps( pathBegin: Instruction , pathEnd: Instruction , _ context: some Context ) -> PathOverlap {
227+ public func overlaps( pathBegin: Instruction , pathEnd: Instruction , _ context: some Context ) -> PathOverlap {
230228 assert ( pathBegin != pathEnd, " expect an exclusive path " )
231229 if contains ( pathBegin) {
232230 // Note: pathEnd != self.begin here since self.contains(pathBegin)
@@ -277,25 +275,3 @@ extension InstructionRange {
277275 }
278276}
279277
280- let rangeOverlapsPathTest = FunctionTest ( " range_overlaps_path " ) {
281- function, arguments, context in
282- let rangeValue = arguments. takeValue ( )
283- print ( " Range of: \( rangeValue) " )
284- var range = computeLinearLiveness ( for: rangeValue, context)
285- defer { range. deinitialize ( ) }
286- let pathInst = arguments. takeInstruction ( )
287- print ( " Path begin: \( pathInst) " )
288- if let pathBegin = pathInst as? ScopedInstruction {
289- for end in pathBegin. endInstructions {
290- print ( " Overlap kind: " , range. overlaps ( pathBegin: pathInst, pathEnd: end, context) )
291- }
292- return
293- }
294- if let pathValue = pathInst as? SingleValueInstruction , pathValue. ownership == . owned {
295- for end in pathValue. uses. endingLifetime {
296- print ( " Overlap kind: " , range. overlaps ( pathBegin: pathInst, pathEnd: end. instruction, context) )
297- }
298- return
299- }
300- print ( " Test specification error: not a scoped or owned instruction: \( pathInst) " )
301- }
0 commit comments