Skip to content

Commit f205b20

Browse files
authored
Merge pull request #35554 from eeckstein/single-silnode-in-singlevalueinstruction
SIL: let SingleValueInstruction only inherit from a single SILNode.
2 parents bbe3d4f + ff19917 commit f205b20

39 files changed

+632
-679
lines changed

include/swift/SIL/ApplySite.h

+25-20
Original file line numberDiff line numberDiff line change
@@ -90,28 +90,30 @@ class ApplySite {
9090

9191
SILModule &getModule() const { return Inst->getModule(); }
9292

93-
static ApplySite isa(SILNode *node) {
94-
auto *i = dyn_cast<SILInstruction>(node);
95-
if (!i)
96-
return ApplySite();
97-
98-
auto kind = ApplySiteKind::fromNodeKind(i->getKind());
93+
static ApplySite isa(SILInstruction *inst) {
94+
auto kind = ApplySiteKind::fromNodeKind(inst->getKind());
9995
if (!kind)
10096
return ApplySite();
10197

10298
switch (kind.getValue()) {
10399
case ApplySiteKind::ApplyInst:
104-
return ApplySite(cast<ApplyInst>(node));
100+
return ApplySite(cast<ApplyInst>(inst));
105101
case ApplySiteKind::BeginApplyInst:
106-
return ApplySite(cast<BeginApplyInst>(node));
102+
return ApplySite(cast<BeginApplyInst>(inst));
107103
case ApplySiteKind::TryApplyInst:
108-
return ApplySite(cast<TryApplyInst>(node));
104+
return ApplySite(cast<TryApplyInst>(inst));
109105
case ApplySiteKind::PartialApplyInst:
110-
return ApplySite(cast<PartialApplyInst>(node));
106+
return ApplySite(cast<PartialApplyInst>(inst));
111107
}
112108
llvm_unreachable("covered switch");
113109
}
114110

111+
static ApplySite isa(SILValue value) {
112+
if (auto *inst = value->getDefiningInstruction())
113+
return ApplySite::isa(inst);
114+
return ApplySite();
115+
}
116+
115117
ApplySiteKind getKind() const { return ApplySiteKind(Inst->getKind()); }
116118

117119
explicit operator bool() const { return Inst != nullptr; }
@@ -181,8 +183,8 @@ class ApplySite {
181183
/// Calls to (previous_)dynamic_function_ref have a dynamic target function so
182184
/// we should not optimize them.
183185
bool canOptimize() const {
184-
return !DynamicFunctionRefInst::classof(getCallee()) &&
185-
!PreviousDynamicFunctionRefInst::classof(getCallee());
186+
return !swift::isa<DynamicFunctionRefInst>(getCallee()) &&
187+
!swift::isa<PreviousDynamicFunctionRefInst>(getCallee());
186188
}
187189

188190
/// Return the type.
@@ -493,24 +495,27 @@ class FullApplySite : public ApplySite {
493495
FullApplySite(BeginApplyInst *inst) : ApplySite(inst) {}
494496
FullApplySite(TryApplyInst *inst) : ApplySite(inst) {}
495497

496-
static FullApplySite isa(SILNode *node) {
497-
auto *i = dyn_cast<SILInstruction>(node);
498-
if (!i)
499-
return FullApplySite();
500-
auto kind = FullApplySiteKind::fromNodeKind(i->getKind());
498+
static FullApplySite isa(SILInstruction *inst) {
499+
auto kind = FullApplySiteKind::fromNodeKind(inst->getKind());
501500
if (!kind)
502501
return FullApplySite();
503502
switch (kind.getValue()) {
504503
case FullApplySiteKind::ApplyInst:
505-
return FullApplySite(cast<ApplyInst>(node));
504+
return FullApplySite(cast<ApplyInst>(inst));
506505
case FullApplySiteKind::BeginApplyInst:
507-
return FullApplySite(cast<BeginApplyInst>(node));
506+
return FullApplySite(cast<BeginApplyInst>(inst));
508507
case FullApplySiteKind::TryApplyInst:
509-
return FullApplySite(cast<TryApplyInst>(node));
508+
return FullApplySite(cast<TryApplyInst>(inst));
510509
}
511510
llvm_unreachable("covered switch");
512511
}
513512

513+
static FullApplySite isa(SILValue value) {
514+
if (auto *inst = value->getDefiningInstruction())
515+
return FullApplySite::isa(inst);
516+
return FullApplySite();
517+
}
518+
514519
FullApplySiteKind getKind() const {
515520
return FullApplySiteKind(getInstruction()->getKind());
516521
}

include/swift/SIL/DynamicCasts.h

+3-6
Original file line numberDiff line numberDiff line change
@@ -158,17 +158,14 @@ struct SILDynamicCastInst {
158158
SILDynamicCastInst(ID *i) : inst(i) {}
159159
#include "swift/SIL/SILNodes.def"
160160

161-
static SILDynamicCastInst getAs(SILNode *node) {
162-
auto *i = dyn_cast<SILInstruction>(node);
163-
if (!i)
164-
return SILDynamicCastInst();
165-
auto kind = SILDynamicCastKind::fromNodeKind(i->getKind());
161+
static SILDynamicCastInst getAs(SILInstruction *inst) {
162+
auto kind = SILDynamicCastKind::fromNodeKind(inst->getKind());
166163
if (!kind)
167164
return SILDynamicCastInst();
168165
switch (kind.getValue()) {
169166
#define DYNAMICCAST_INST(ID, PARENT) \
170167
case SILDynamicCastKind::ID: \
171-
return SILDynamicCastInst(cast<ID>(node));
168+
return SILDynamicCastInst(cast<ID>(inst));
172169
#include "swift/SIL/SILNodes.def"
173170
}
174171
}

include/swift/SIL/PrettyStackTrace.h

+2-2
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

+4-4
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)