Skip to content

Commit 89063c9

Browse files
committed
Add Value.definingInstructionOrTerminator
1 parent e5d7885 commit 89063c9

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

SwiftCompilerSources/Sources/Optimizer/DataStructures/InstructionRange.swift

+1-3
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,8 @@ struct InstructionRange : CustomStringConvertible, NoReflectionChildren {
6464
}
6565

6666
static func beginningInstruction(for value: Value) -> Instruction {
67-
if let def = value.definingInstruction {
67+
if let def = value.definingInstructionOrTerminator {
6868
return def
69-
} else if let result = TerminatorResult(value) {
70-
return result.terminator
7169
}
7270
assert(Phi(value) != nil || value is FunctionArgument)
7371
return value.parentBlock.instructions.first!

SwiftCompilerSources/Sources/SIL/ForwardingInstruction.swift

+1-4
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,9 @@ extension Value {
6666
// If this value is produced by a ForwardingInstruction, return that instruction. This is convenient for following the forwarded value chain.
6767
// Unlike definingInstruction, a value's forwardingInstruction is not necessarily a valid insertion point.
6868
public var forwardingInstruction: ForwardingInstruction? {
69-
if let inst = definingInstruction {
69+
if let inst = definingInstructionOrTerminator {
7070
return inst as? ForwardingInstruction
7171
}
72-
if let termResult = TerminatorResult(self) {
73-
return termResult.terminator as? ForwardingInstruction
74-
}
7572
return nil
7673
}
7774
}

SwiftCompilerSources/Sources/SIL/Value.swift

+9
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,15 @@ extension Value {
138138
}
139139
}
140140

141+
public var definingInstructionOrTerminator: Instruction? {
142+
if let def = definingInstruction {
143+
return def
144+
} else if let result = TerminatorResult(self) {
145+
return result.terminator
146+
}
147+
return nil
148+
}
149+
141150
public var nextInstruction: Instruction {
142151
if self is Argument {
143152
return parentBlock.instructions.first!

0 commit comments

Comments
 (0)