Skip to content

Commit 45afec6

Browse files
committed
[SIL] Added SILBasicBlock::hasPhi.
1 parent 827df01 commit 45afec6

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

include/swift/SIL/SILBasicBlock.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,12 @@ public SwiftObjectHeader {
426426
/// the debug scope for newly created instructions.
427427
const SILDebugScope *getScopeOfFirstNonMetaInstruction();
428428

429+
/// Whether the block has any phi arguments.
430+
///
431+
/// Note that a block could have an argument and still return false. The
432+
/// argument must also satisfy SILPhiArgument::isPhiArgument.
433+
bool hasPhi() const;
434+
429435
//===--------------------------------------------------------------------===//
430436
// Debugging
431437
//===--------------------------------------------------------------------===//

lib/SIL/IR/SILBasicBlock.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,15 @@ bool SILBasicBlock::isLegalToHoistInto() const {
395395
return true;
396396
}
397397

398+
bool SILBasicBlock::hasPhi() const {
399+
if (getArguments().size() == 0)
400+
return false;
401+
// It is sufficient to check whether the first argument is a phi. A block
402+
// can't have both phis and terminator results.
403+
auto *argument = getArguments()[0];
404+
return argument->isPhiArgument();
405+
}
406+
398407
const SILDebugScope *SILBasicBlock::getScopeOfFirstNonMetaInstruction() {
399408
for (auto &Inst : *this)
400409
if (Inst.isMetaInstruction())

0 commit comments

Comments
 (0)