Skip to content

Commit a50b09b

Browse files
committed
Add SILArgument::isTerminatorResult() and getTransformingTerminator().
1 parent 4e048a8 commit a50b09b

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

include/swift/SIL/SILArgument.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ class SILArgument : public ValueBase {
117117
/// opposed to a cast or projection.
118118
bool isPhiArgument() const;
119119

120+
/// Return true if this block argument is a terminator result.
121+
bool isTerminatorResult() const;
122+
120123
/// If this argument is a phi, return the incoming phi value for the given
121124
/// predecessor BB. If this argument is not a phi, return an invalid SILValue.
122125
SILValue getIncomingPhiValue(SILBasicBlock *predBlock) const;
@@ -208,6 +211,9 @@ class SILPhiArgument : public SILArgument {
208211
/// opposed to a cast or projection.
209212
bool isPhiArgument() const;
210213

214+
/// Return true if this block argument is a terminator result.
215+
bool isTerminatorResult() const { return !isPhiArgument(); }
216+
211217
/// If this argument is a phi, return the incoming phi value for the given
212218
/// predecessor BB. If this argument is not a phi, return an invalid SILValue.
213219
///
@@ -283,6 +289,10 @@ class SILPhiArgument : public SILArgument {
283289
/// terminator has a single operand, return that terminator.
284290
TermInst *getSingleTerminator() const;
285291

292+
/// Return the terminator instruction of which this argument is a result or
293+
/// nullptr.
294+
TermInst *getTransformingTerminator() const;
295+
286296
static bool classof(const SILInstruction *) = delete;
287297
static bool classof(const SILUndef *) = delete;
288298
static bool classof(SILNodePointer node) {
@@ -347,6 +357,16 @@ inline bool SILArgument::isPhiArgument() const {
347357
llvm_unreachable("Covered switch is not covered?!");
348358
}
349359

360+
inline bool SILArgument::isTerminatorResult() const {
361+
switch (getKind()) {
362+
case SILArgumentKind::SILPhiArgument:
363+
return cast<SILPhiArgument>(this)->isTerminatorResult();
364+
case SILArgumentKind::SILFunctionArgument:
365+
return false;
366+
}
367+
llvm_unreachable("Covered switch is not covered?!");
368+
}
369+
350370
inline SILValue
351371
SILArgument::getIncomingPhiValue(SILBasicBlock *predBlock) const {
352372
switch (getKind()) {

lib/SIL/IR/SILArgument.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,14 @@ TermInst *SILPhiArgument::getSingleTerminator() const {
316316
return const_cast<SILBasicBlock *>(predBlock)->getTerminator();
317317
}
318318

319+
TermInst *getTransformingTerminator() const {
320+
if (auto *termInst = getSingleTerminator()) {
321+
if (!isa<BranchInst>(termInst) && !isa<CondBranchInst>(termInst))
322+
return termInst;
323+
}
324+
return nullptr;
325+
}
326+
319327
SILPhiArgument *BranchInst::getArgForOperand(const Operand *oper) {
320328
assert(oper->getUser() == this);
321329
return cast<SILPhiArgument>(

0 commit comments

Comments
 (0)