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.
This commit is contained in:
Andrew Trick
2022-12-08 10:16:53 -08:00
parent a7726f19aa
commit fe44dce4e7
2 changed files with 17 additions and 0 deletions

View File

@@ -494,6 +494,13 @@ public:
}
SILInstruction *getDefiningInstruction();
/// Return the instruction that defines this value, terminator instruction
/// that produces this result, or null if it is not defined by an instruction.
const SILInstruction *getDefiningInstructionOrTerminator() const {
return const_cast<ValueBase*>(this)->getDefiningInstructionOrTerminator();
}
SILInstruction *getDefiningInstructionOrTerminator();
/// Return the SIL instruction that can be used to describe the first time
/// this value is available.
///

View File

@@ -80,6 +80,16 @@ SILInstruction *ValueBase::getDefiningInstruction() {
return nullptr;
}
SILInstruction *ValueBase::getDefiningInstructionOrTerminator() {
if (auto *inst = dyn_cast<SingleValueInstruction>(this))
return inst;
if (auto *result = dyn_cast<MultipleValueInstructionResult>(this))
return result->getParent();
if (auto *result = SILArgument::isTerminatorResult(this))
return result->getSingleTerminator();
return nullptr;
}
SILInstruction *ValueBase::getDefiningInsertionPoint() {
if (auto *inst = getDefiningInstruction())
return inst;