Skip to content

Commit fe44dce

Browse files
committed
Add SILValue::getDefiningInstructionOrTerminator().
This allows code to handle terminator results similar to any other instruction result. Data flow should generally handle terminator results like any other instruction that may forward operand ownership to its results. The fact that it is represented as a block argument is an implementation detail that gets in the way of conceptual simplicity.
1 parent a7726f1 commit fe44dce

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

include/swift/SIL/SILValue.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,13 @@ class ValueBase : public SILNode, public SILAllocated<ValueBase> {
494494
}
495495
SILInstruction *getDefiningInstruction();
496496

497+
/// Return the instruction that defines this value, terminator instruction
498+
/// that produces this result, or null if it is not defined by an instruction.
499+
const SILInstruction *getDefiningInstructionOrTerminator() const {
500+
return const_cast<ValueBase*>(this)->getDefiningInstructionOrTerminator();
501+
}
502+
SILInstruction *getDefiningInstructionOrTerminator();
503+
497504
/// Return the SIL instruction that can be used to describe the first time
498505
/// this value is available.
499506
///

lib/SIL/IR/SILValue.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ SILInstruction *ValueBase::getDefiningInstruction() {
8080
return nullptr;
8181
}
8282

83+
SILInstruction *ValueBase::getDefiningInstructionOrTerminator() {
84+
if (auto *inst = dyn_cast<SingleValueInstruction>(this))
85+
return inst;
86+
if (auto *result = dyn_cast<MultipleValueInstructionResult>(this))
87+
return result->getParent();
88+
if (auto *result = SILArgument::isTerminatorResult(this))
89+
return result->getSingleTerminator();
90+
return nullptr;
91+
}
92+
8393
SILInstruction *ValueBase::getDefiningInsertionPoint() {
8494
if (auto *inst = getDefiningInstruction())
8595
return inst;

0 commit comments

Comments
 (0)