@@ -59,6 +59,19 @@ struct InstructionRange : CustomStringConvertible, NoReflectionChildren {
59
59
self . inExclusiveRange. insert ( beginInst)
60
60
}
61
61
62
+ init ( for value: Value , _ context: some Context ) {
63
+ var begin : Instruction
64
+ if let def = value. definingInstruction {
65
+ begin = def
66
+ } else if let result = TerminatorResult ( value) {
67
+ begin = result. terminator
68
+ } else {
69
+ assert ( Phi ( value) != nil || value is FunctionArgument )
70
+ begin = value. parentBlock. instructions. first!
71
+ }
72
+ self = InstructionRange ( begin: begin, context)
73
+ }
74
+
62
75
/// Insert a potential end instruction.
63
76
mutating func insert( _ inst: Instruction ) {
64
77
insertedInsts. insert ( inst)
@@ -103,12 +116,21 @@ struct InstructionRange : CustomStringConvertible, NoReflectionChildren {
103
116
}
104
117
105
118
/// Returns the end instructions.
119
+ ///
120
+ /// Warning: this returns `begin` if no instructions were inserted.
106
121
var ends : LazyMapSequence < LazyFilterSequence < Stack < BasicBlock > > , Instruction > {
107
122
blockRange. ends. map {
108
123
$0. instructions. reversed ( ) . first ( where: { insertedInsts. contains ( $0) } ) !
109
124
}
110
125
}
111
126
127
+ // Returns the exit blocks.
128
+ var exitBlocks : LazySequence < FlattenSequence <
129
+ LazyMapSequence < LazyFilterSequence < Stack < BasicBlock > > ,
130
+ LazyFilterSequence < SuccessorArray > > > > {
131
+ blockRange. exits
132
+ }
133
+
112
134
/// Returns the exit instructions.
113
135
var exits : LazyMapSequence < LazySequence < FlattenSequence <
114
136
LazyMapSequence < LazyFilterSequence < Stack < BasicBlock > > ,
0 commit comments