mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
SIL: let SingleValueInstruction only inherit from a single SILNode.
This removes the ambiguity when casting from a SingleValueInstruction to SILNode, which makes the code simpler. E.g. the "isRepresentativeSILNode" logic is not needed anymore. Also, it reduces the size of the most used instruction class - SingleValueInstruction - by one pointer. Conceptually, SILInstruction is still a SILNode. But implementation-wise SILNode is not a base class of SILInstruction anymore. Only the two sub-classes of SILInstruction - SingleValueInstruction and NonSingleValueInstruction - inherit from SILNode. SingleValueInstruction's SILNode is embedded into a ValueBase and its relative offset in the class is the same as in NonSingleValueInstruction (see SILNodeOffsetChecker). This makes it possible to cast from a SILInstruction to a SILNode without knowing which SILInstruction sub-class it is. Casting to SILNode cannot be done implicitly, but only with an LLVM `cast` or with SILInstruction::asSILNode(). But this is a rare case anyway.
This commit is contained in:
@@ -121,23 +121,6 @@ SILModule *SILNode::getModule() const {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const SILNode *SILNode::getRepresentativeSILNodeSlowPath() const {
|
||||
assert(getStorageLoc() != SILNodeStorageLocation::Instruction);
|
||||
|
||||
if (isa<SingleValueInstruction>(this)) {
|
||||
assert(hasMultipleSILNodeBases(getKind()));
|
||||
return &static_cast<const SILInstruction &>(
|
||||
static_cast<const SingleValueInstruction &>(
|
||||
static_cast<const ValueBase &>(*this)));
|
||||
}
|
||||
|
||||
if (auto *MVR = dyn_cast<MultipleValueInstructionResult>(this)) {
|
||||
return MVR->getParent();
|
||||
}
|
||||
|
||||
llvm_unreachable("Invalid value for slow path");
|
||||
}
|
||||
|
||||
/// Get a location for this value.
|
||||
SILLocation SILValue::getLoc() const {
|
||||
if (auto *instr = Value->getDefiningInstruction())
|
||||
|
||||
Reference in New Issue
Block a user