Skip to content

Commit 0d594fd

Browse files
committed
Add SILArgument::getTerminatorForResultArg().
1 parent a50b09b commit 0d594fd

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

include/swift/SIL/SILArgument.h

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ class SILArgument : public ValueBase {
181181
/// terminator has a single operand, return that terminator.
182182
TermInst *getSingleTerminator() const;
183183

184+
/// Return the terminator instruction for which this argument is a result,
185+
/// otherwise return nullptr.
186+
TermInst *getTerminatorForResultArg() const;
187+
184188
/// Return the SILArgumentKind of this argument.
185189
SILArgumentKind getKind() const {
186190
return SILArgumentKind(ValueBase::getKind());
@@ -289,9 +293,9 @@ class SILPhiArgument : public SILArgument {
289293
/// terminator has a single operand, return that terminator.
290294
TermInst *getSingleTerminator() const;
291295

292-
/// Return the terminator instruction of which this argument is a result or
293-
/// nullptr.
294-
TermInst *getTransformingTerminator() const;
296+
/// Return the terminator instruction for which this argument is a result,
297+
/// otherwise return nullptr.
298+
TermInst *getTerminatorForResultArg() const;
295299

296300
static bool classof(const SILInstruction *) = delete;
297301
static bool classof(const SILUndef *) = delete;
@@ -437,6 +441,16 @@ inline TermInst *SILArgument::getSingleTerminator() const {
437441
llvm_unreachable("Covered switch is not covered?!");
438442
}
439443

444+
inline TermInst *SILArgument::getTerminatorForResultArg() const {
445+
switch (getKind()) {
446+
case SILArgumentKind::SILPhiArgument:
447+
return cast<SILPhiArgument>(this)->getTerminatorForResultArg();
448+
case SILArgumentKind::SILFunctionArgument:
449+
return nullptr;
450+
}
451+
llvm_unreachable("Covered switch is not covered?!");
452+
}
453+
440454
inline bool SILArgument::getIncomingPhiOperands(
441455
SmallVectorImpl<Operand *> &returnedPhiOperands) const {
442456
switch (getKind()) {

lib/SIL/IR/SILArgument.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ TermInst *SILPhiArgument::getSingleTerminator() const {
316316
return const_cast<SILBasicBlock *>(predBlock)->getTerminator();
317317
}
318318

319-
TermInst *getTransformingTerminator() const {
319+
TermInst *SILPhiArgument::getTerminatorForResultArg() const {
320320
if (auto *termInst = getSingleTerminator()) {
321321
if (!isa<BranchInst>(termInst) && !isa<CondBranchInst>(termInst))
322322
return termInst;

0 commit comments

Comments
 (0)