mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Make SILInstruction no longer a subclass of ValueBase and
introduce a common superclass, SILNode. This is in preparation for allowing instructions to have multiple results. It is also a somewhat more elegant representation for instructions that have zero results. Instructions that are known to have exactly one result inherit from a class, SingleValueInstruction, that subclasses both ValueBase and SILInstruction. Some care must be taken when working with SILNode pointers and testing for equality; please see the comment on SILNode for more information. A number of SIL passes needed to be updated in order to handle this new distinction between SIL values and SIL instructions. Note that the SIL parser is now stricter about not trying to assign a result value from an instruction (like 'return' or 'strong_retain') that does not produce any.
This commit is contained in:
@@ -57,33 +57,59 @@ void ValueBase::replaceAllUsesWithUndef() {
|
||||
}
|
||||
}
|
||||
|
||||
SILBasicBlock *ValueBase::getParentBlock() const {
|
||||
auto *NonConstThis = const_cast<ValueBase *>(this);
|
||||
SILInstruction *ValueBase::getDefiningInstruction() {
|
||||
if (auto inst = dyn_cast<SingleValueInstruction>(this))
|
||||
return inst;
|
||||
// TODO: MultiValueInstruction
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Optional<ValueBase::DefiningInstructionResult>
|
||||
ValueBase::getDefiningInstructionResult() {
|
||||
if (auto inst = dyn_cast<SingleValueInstruction>(this))
|
||||
return DefiningInstructionResult{ inst, 0 };
|
||||
// TODO: MultiValueInstruction
|
||||
return None;
|
||||
}
|
||||
|
||||
SILBasicBlock *SILNode::getParentBlock() const {
|
||||
auto *NonConstThis = const_cast<SILNode *>(this);
|
||||
if (auto *Inst = dyn_cast<SILInstruction>(NonConstThis))
|
||||
return Inst->getParent();
|
||||
// TODO: MultiValueInstruction
|
||||
if (auto *Arg = dyn_cast<SILArgument>(NonConstThis))
|
||||
return Arg->getParent();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SILFunction *ValueBase::getFunction() const {
|
||||
auto *NonConstThis = const_cast<ValueBase *>(this);
|
||||
SILFunction *SILNode::getFunction() const {
|
||||
auto *NonConstThis = const_cast<SILNode *>(this);
|
||||
if (auto *Inst = dyn_cast<SILInstruction>(NonConstThis))
|
||||
return Inst->getFunction();
|
||||
// TODO: MultiValueInstruction
|
||||
if (auto *Arg = dyn_cast<SILArgument>(NonConstThis))
|
||||
return Arg->getFunction();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SILModule *ValueBase::getModule() const {
|
||||
auto *NonConstThis = const_cast<ValueBase *>(this);
|
||||
SILModule *SILNode::getModule() const {
|
||||
auto *NonConstThis = const_cast<SILNode *>(this);
|
||||
if (auto *Inst = dyn_cast<SILInstruction>(NonConstThis))
|
||||
return &Inst->getModule();
|
||||
// TODO: MultiValueInstruction
|
||||
if (auto *Arg = dyn_cast<SILArgument>(NonConstThis))
|
||||
return &Arg->getModule();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const SILNode *SILNode::getCanonicalSILNodeSlowPath() const {
|
||||
assert(getStorageLoc() != SILNodeStorageLocation::Instruction &&
|
||||
hasMultipleSILNodes(getKind()));
|
||||
return &static_cast<const SILInstruction &>(
|
||||
static_cast<const SingleValueInstruction &>(
|
||||
static_cast<const ValueBase &>(*this)));
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// ValueOwnershipKind
|
||||
//===----------------------------------------------------------------------===//
|
||||
@@ -183,9 +209,10 @@ ValueOwnershipKind SILValue::getOwnershipKind() const {
|
||||
return Classifier.visit(const_cast<ValueBase *>(Value));
|
||||
}
|
||||
|
||||
#if 0
|
||||
/// Map a SILValue mnemonic name to its ValueKind.
|
||||
ValueKind swift::getSILValueKind(StringRef Name) {
|
||||
#define INST(Id, Parent, TextualName, MemoryBehavior, ReleasingBehavior) \
|
||||
#define SINGLE_VALUE_INST(Id, TextualName, Parent, MemoryBehavior, ReleasingBehavior) \
|
||||
if (Name == #TextualName) \
|
||||
return ValueKind::Id;
|
||||
|
||||
@@ -206,16 +233,15 @@ ValueKind swift::getSILValueKind(StringRef Name) {
|
||||
/// Map ValueKind to a corresponding mnemonic name.
|
||||
StringRef swift::getSILValueName(ValueKind Kind) {
|
||||
switch (Kind) {
|
||||
#define INST(Id, Parent, TextualName, MemoryBehavior, ReleasingBehavior) \
|
||||
#define SINGLE_VALUE_INST(Id, TextualName, Parent, MemoryBehavior, ReleasingBehavior) \
|
||||
case ValueKind::Id: \
|
||||
return #TextualName; \
|
||||
break;
|
||||
return #TextualName;
|
||||
|
||||
#define VALUE(Id, Parent) \
|
||||
case ValueKind::Id: \
|
||||
return #Id; \
|
||||
break;
|
||||
return #Id;
|
||||
|
||||
#include "swift/SIL/SILNodes.def"
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user