Skip to content

Commit 7a18dd4

Browse files
committed
[SIL] Add Argument.incomingOperand(inPredecessor:)
1 parent 3407ccd commit 7a18dd4

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

SwiftCompilerSources/Sources/SIL/Argument.swift

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -87,26 +87,29 @@ public struct Phi {
8787
return value.parentBlock
8888
}
8989

90-
public var incomingOperands: LazyMapSequence<PredecessorList, Operand> {
90+
public func incomingOperand(inPredecessor predecessor: BasicBlock)
91+
-> Operand {
9192
let blockArgIdx = value.index
92-
return predecessors.lazy.map {
93-
switch $0.terminator {
94-
case let br as BranchInst:
95-
return br.operands[blockArgIdx]
96-
case let condBr as CondBranchInst:
97-
if condBr.trueBlock == successor {
98-
assert(condBr.falseBlock != successor)
99-
return condBr.trueOperands[blockArgIdx]
100-
} else {
101-
assert(condBr.falseBlock == successor)
102-
return condBr.falseOperands[blockArgIdx]
103-
}
104-
default:
105-
fatalError("wrong terminator for phi-argument")
93+
switch predecessor.terminator {
94+
case let br as BranchInst:
95+
return br.operands[blockArgIdx]
96+
case let condBr as CondBranchInst:
97+
if condBr.trueBlock == successor {
98+
assert(condBr.falseBlock != successor)
99+
return condBr.trueOperands[blockArgIdx]
100+
} else {
101+
assert(condBr.falseBlock == successor)
102+
return condBr.falseOperands[blockArgIdx]
106103
}
104+
default:
105+
fatalError("wrong terminator for phi-argument")
107106
}
108107
}
109108

109+
public var incomingOperands: LazyMapSequence<PredecessorList, Operand> {
110+
predecessors.lazy.map { incomingOperand(inPredecessor: $0) }
111+
}
112+
110113
public var incomingValues: LazyMapSequence<LazyMapSequence<PredecessorList, Operand>, Value> {
111114
incomingOperands.lazy.map { $0.value }
112115
}

0 commit comments

Comments
 (0)