Skip to content

Commit 7aab3c5

Browse files
committed
Factor InstructionRange.beginningInstruction for use elsewhere.
1 parent d6d8323 commit 7aab3c5

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

SwiftCompilerSources/Sources/Optimizer/DataStructures/InstructionRange.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,17 @@ struct InstructionRange : CustomStringConvertible, NoReflectionChildren {
6060
}
6161

6262
init(for value: Value, _ context: some Context) {
63-
var begin: Instruction
63+
self = InstructionRange(begin: InstructionRange.beginningInstruction(for: value), context)
64+
}
65+
66+
static func beginningInstruction(for value: Value) -> Instruction {
6467
if let def = value.definingInstruction {
65-
begin = def
68+
return def
6669
} 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!
70+
return result.terminator
7171
}
72-
self = InstructionRange(begin: begin, context)
72+
assert(Phi(value) != nil || value is FunctionArgument)
73+
return value.parentBlock.instructions.first!
7374
}
7475

7576
/// Insert a potential end instruction.

0 commit comments

Comments
 (0)