@@ -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 ;
@@ -178,6 +181,10 @@ class SILArgument : public ValueBase {
178181 // / terminator has a single operand, return that terminator.
179182 TermInst *getSingleTerminator () const ;
180183
184+ // / Return the terminator instruction for which this argument is a result,
185+ // / otherwise return nullptr.
186+ TermInst *getTerminatorForResultArg () const ;
187+
181188 // / Return the SILArgumentKind of this argument.
182189 SILArgumentKind getKind () const {
183190 return SILArgumentKind (ValueBase::getKind ());
@@ -208,6 +215,9 @@ class SILPhiArgument : public SILArgument {
208215 // / opposed to a cast or projection.
209216 bool isPhiArgument () const ;
210217
218+ // / Return true if this block argument is a terminator result.
219+ bool isTerminatorResult () const { return !isPhiArgument (); }
220+
211221 // / If this argument is a phi, return the incoming phi value for the given
212222 // / predecessor BB. If this argument is not a phi, return an invalid SILValue.
213223 // /
@@ -283,6 +293,10 @@ class SILPhiArgument : public SILArgument {
283293 // / terminator has a single operand, return that terminator.
284294 TermInst *getSingleTerminator () const ;
285295
296+ // / Return the terminator instruction for which this argument is a result,
297+ // / otherwise return nullptr.
298+ TermInst *getTerminatorForResultArg () const ;
299+
286300 static bool classof (const SILInstruction *) = delete;
287301 static bool classof (const SILUndef *) = delete;
288302 static bool classof (SILNodePointer node) {
@@ -347,6 +361,16 @@ inline bool SILArgument::isPhiArgument() const {
347361 llvm_unreachable (" Covered switch is not covered?!" );
348362}
349363
364+ inline bool SILArgument::isTerminatorResult () const {
365+ switch (getKind ()) {
366+ case SILArgumentKind::SILPhiArgument:
367+ return cast<SILPhiArgument>(this )->isTerminatorResult ();
368+ case SILArgumentKind::SILFunctionArgument:
369+ return false ;
370+ }
371+ llvm_unreachable (" Covered switch is not covered?!" );
372+ }
373+
350374inline SILValue
351375SILArgument::getIncomingPhiValue (SILBasicBlock *predBlock) const {
352376 switch (getKind ()) {
@@ -417,6 +441,16 @@ inline TermInst *SILArgument::getSingleTerminator() const {
417441 llvm_unreachable (" Covered switch is not covered?!" );
418442}
419443
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+
420454inline bool SILArgument::getIncomingPhiOperands (
421455 SmallVectorImpl<Operand *> &returnedPhiOperands) const {
422456 switch (getKind ()) {
0 commit comments