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:
Erik Eckstein
2021-01-20 11:09:50 +01:00
parent 40f0980abf
commit ff1991740a
33 changed files with 479 additions and 506 deletions

View File

@@ -246,10 +246,10 @@ void SILFunction::numberValues(llvm::DenseMap<const SILNode*, unsigned> &
for (auto &I : BB) {
auto results = I.getResults();
if (results.empty()) {
ValueToNumberMap[&I] = idx++;
ValueToNumberMap[I.asSILNode()] = idx++;
} else {
// Assign the instruction node the first result ID.
ValueToNumberMap[&I] = idx;
ValueToNumberMap[I.asSILNode()] = idx;
for (auto result : results) {
ValueToNumberMap[result] = idx++;
}