Skip to content

Commit ff19917

Browse files
committed
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.
1 parent 40f0980 commit ff19917

33 files changed

+479
-506
lines changed

include/swift/SIL/PrettyStackTrace.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
#define SWIFT_SIL_PRETTYSTACKTRACE_H
2020

2121
#include "swift/SIL/SILLocation.h"
22+
#include "swift/SIL/SILNode.h"
2223
#include "llvm/Support/PrettyStackTrace.h"
2324

2425
namespace swift {
2526
class ASTContext;
2627
class SILFunction;
27-
class SILNode;
2828

2929
void printSILLocationDescription(llvm::raw_ostream &out, SILLocation loc,
3030
ASTContext &ctx);
@@ -74,7 +74,7 @@ class PrettyStackTraceSILNode : public llvm::PrettyStackTraceEntry {
7474
const char *Action;
7575

7676
public:
77-
PrettyStackTraceSILNode(const char *action, const SILNode *node)
77+
PrettyStackTraceSILNode(const char *action, SILNodePointer node)
7878
: Node(node), Action(action) {}
7979

8080
virtual void print(llvm::raw_ostream &OS) const override;

include/swift/SIL/SILArgument.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class SILArgument : public ValueBase {
7878
explicit SILArgument(ValueKind subClassKind, SILType type,
7979
ValueOwnershipKind ownershipKind,
8080
const ValueDecl *inputDecl = nullptr)
81-
: ValueBase(subClassKind, type, IsRepresentative::Yes),
81+
: ValueBase(subClassKind, type),
8282
parentBlock(nullptr), decl(inputDecl) {
8383
Bits.SILArgument.VOKind = static_cast<unsigned>(ownershipKind);
8484
}
@@ -106,7 +106,7 @@ class SILArgument : public ValueBase {
106106

107107
static bool classof(const SILInstruction *) = delete;
108108
static bool classof(const SILUndef *) = delete;
109-
static bool classof(const SILNode *node) {
109+
static bool classof(SILNodePointer node) {
110110
return node->getKind() >= SILNodeKind::First_SILArgument &&
111111
node->getKind() <= SILNodeKind::Last_SILArgument;
112112
}
@@ -279,7 +279,7 @@ class SILPhiArgument : public SILArgument {
279279

280280
static bool classof(const SILInstruction *) = delete;
281281
static bool classof(const SILUndef *) = delete;
282-
static bool classof(const SILNode *node) {
282+
static bool classof(SILNodePointer node) {
283283
return node->getKind() == SILNodeKind::SILPhiArgument;
284284
}
285285
};
@@ -322,7 +322,7 @@ class SILFunctionArgument : public SILArgument {
322322

323323
static bool classof(const SILInstruction *) = delete;
324324
static bool classof(const SILUndef *) = delete;
325-
static bool classof(const SILNode *node) {
325+
static bool classof(SILNodePointer node) {
326326
return node->getKind() == SILNodeKind::SILFunctionArgument;
327327
}
328328
};

0 commit comments

Comments
 (0)