Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions include/swift/SIL/SILArgument.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ class SILArgument : public ValueBase {
/// is the enum itself (the operand of the switch_enum).
SILValue getSingleTerminatorOperand() const;

/// If this SILArgument's parent block has a single predecessor whose
/// terminator has a single operand, return that terminator.
TermInst *getSingleTerminator() const;

/// Return the SILArgumentKind of this argument.
SILArgumentKind getKind() const {
return SILArgumentKind(ValueBase::getKind());
Expand Down Expand Up @@ -264,6 +268,10 @@ class SILPhiArgument : public SILArgument {
/// is the enum itself (the operand of the switch_enum).
SILValue getSingleTerminatorOperand() const;

/// If this SILArgument's parent block has a single predecessor whose
/// terminator has a single operand, return that terminator.
TermInst *getSingleTerminator() const;

static bool classof(const SILInstruction *) = delete;
static bool classof(const SILUndef *) = delete;
static bool classof(const SILNode *node) {
Expand Down Expand Up @@ -403,6 +411,16 @@ inline bool SILArgument::getSingleTerminatorOperands(
llvm_unreachable("Covered switch is not covered?!");
}

inline TermInst *SILArgument::getSingleTerminator() const {
switch (getKind()) {
case SILArgumentKind::SILPhiArgument:
return cast<SILPhiArgument>(this)->getSingleTerminator();
case SILArgumentKind::SILFunctionArgument:
return nullptr;
}
llvm_unreachable("Covered switch is not covered?!");
}

} // end swift namespace

#endif
8 changes: 8 additions & 0 deletions lib/SIL/SILArgument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,14 @@ SILValue SILPhiArgument::getSingleTerminatorOperand() const {
return getSingleTerminatorOperandForPred(parentBlock, predBlock, getIndex());
}

TermInst *SILPhiArgument::getSingleTerminator() const {
auto *parentBlock = getParent();
auto *predBlock = parentBlock->getSinglePredecessorBlock();
if (!predBlock)
return nullptr;
return const_cast<SILBasicBlock *>(predBlock)->getTerminator();
}

const SILPhiArgument *BranchInst::getArgForOperand(const Operand *oper) const {
assert(oper->getUser() == this);
return cast<SILPhiArgument>(
Expand Down