Skip to content

Commit 39c202d

Browse files
committed
[sil] Add a new helper method CondBranchInst::isConditionOperand.
I am doing some refactoring on BranchPropagatedUser that is requiring me to work a lot more with arguments and I found a need for this to avoid trafficing in operand indices. As part of this I also needed to write the helper getConditionOperand() to get the underlying operand. I refactored the already preset getCondition() to use this helper instead since it was just semantically that method + get operand's value.
1 parent 860192b commit 39c202d

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

include/swift/SIL/SILInstruction.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7213,7 +7213,10 @@ class CondBranchInst final
72137213
ProfileCounter FalseBBCount, SILFunction &F);
72147214

72157215
public:
7216-
SILValue getCondition() const { return getAllOperands()[ConditionIdx].get(); }
7216+
const Operand *getConditionOperand() const {
7217+
return &getAllOperands()[ConditionIdx];
7218+
}
7219+
SILValue getCondition() const { return getConditionOperand()->get(); }
72177220
void setCondition(SILValue newCondition) {
72187221
getAllOperands()[ConditionIdx].set(newCondition);
72197222
}
@@ -7259,6 +7262,11 @@ class CondBranchInst final
72597262
return getAllOperands().slice(NumFixedOpers + getNumTrueArgs());
72607263
}
72617264

7265+
/// Returns true if \p op is mapped to the condition operand of the cond_br.
7266+
bool isConditionOperand(Operand *op) const {
7267+
return getConditionOperand() == op;
7268+
}
7269+
72627270
bool isConditionOperandIndex(unsigned OpIndex) const {
72637271
assert(OpIndex < getNumOperands() &&
72647272
"OpIndex must be an index for an actual operand");

0 commit comments

Comments
 (0)