Skip to content

Commit 3c582f4

Browse files
authored
Merge pull request swiftlang#29601 from gottesmm/pr-132affdd3523248eb7aada4eb4717867466c15f1
2 parents a336904 + 92864f1 commit 3c582f4

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

include/swift/SIL/SILArgument.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ class SILArgument : public ValueBase {
173173
/// is the enum itself (the operand of the switch_enum).
174174
SILValue getSingleTerminatorOperand() const;
175175

176+
/// If this SILArgument's parent block has a single predecessor whose
177+
/// terminator has a single operand, return that terminator.
178+
TermInst *getSingleTerminator() const;
179+
176180
/// Return the SILArgumentKind of this argument.
177181
SILArgumentKind getKind() const {
178182
return SILArgumentKind(ValueBase::getKind());
@@ -264,6 +268,10 @@ class SILPhiArgument : public SILArgument {
264268
/// is the enum itself (the operand of the switch_enum).
265269
SILValue getSingleTerminatorOperand() const;
266270

271+
/// If this SILArgument's parent block has a single predecessor whose
272+
/// terminator has a single operand, return that terminator.
273+
TermInst *getSingleTerminator() const;
274+
267275
static bool classof(const SILInstruction *) = delete;
268276
static bool classof(const SILUndef *) = delete;
269277
static bool classof(const SILNode *node) {
@@ -403,6 +411,16 @@ inline bool SILArgument::getSingleTerminatorOperands(
403411
llvm_unreachable("Covered switch is not covered?!");
404412
}
405413

414+
inline TermInst *SILArgument::getSingleTerminator() const {
415+
switch (getKind()) {
416+
case SILArgumentKind::SILPhiArgument:
417+
return cast<SILPhiArgument>(this)->getSingleTerminator();
418+
case SILArgumentKind::SILFunctionArgument:
419+
return nullptr;
420+
}
421+
llvm_unreachable("Covered switch is not covered?!");
422+
}
423+
406424
} // end swift namespace
407425

408426
#endif

lib/SIL/SILArgument.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,14 @@ SILValue SILPhiArgument::getSingleTerminatorOperand() const {
235235
return getSingleTerminatorOperandForPred(parentBlock, predBlock, getIndex());
236236
}
237237

238+
TermInst *SILPhiArgument::getSingleTerminator() const {
239+
auto *parentBlock = getParent();
240+
auto *predBlock = parentBlock->getSinglePredecessorBlock();
241+
if (!predBlock)
242+
return nullptr;
243+
return const_cast<SILBasicBlock *>(predBlock)->getTerminator();
244+
}
245+
238246
const SILPhiArgument *BranchInst::getArgForOperand(const Operand *oper) const {
239247
assert(oper->getUser() == this);
240248
return cast<SILPhiArgument>(

0 commit comments

Comments
 (0)