Skip to content

Commit 7060aef

Browse files
authored
Merge pull request #35600 from apple/revert-35554-single-silnode-in-singlevalueinstruction
Revert "SIL: let SingleValueInstruction only inherit from a single SILNode."
2 parents dba2726 + 8e7f9c9 commit 7060aef

39 files changed

+679
-632
lines changed

include/swift/SIL/ApplySite.h

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -90,30 +90,28 @@ class ApplySite {
9090

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

93-
static ApplySite isa(SILInstruction *inst) {
94-
auto kind = ApplySiteKind::fromNodeKind(inst->getKind());
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());
9599
if (!kind)
96100
return ApplySite();
97101

98102
switch (kind.getValue()) {
99103
case ApplySiteKind::ApplyInst:
100-
return ApplySite(cast<ApplyInst>(inst));
104+
return ApplySite(cast<ApplyInst>(node));
101105
case ApplySiteKind::BeginApplyInst:
102-
return ApplySite(cast<BeginApplyInst>(inst));
106+
return ApplySite(cast<BeginApplyInst>(node));
103107
case ApplySiteKind::TryApplyInst:
104-
return ApplySite(cast<TryApplyInst>(inst));
108+
return ApplySite(cast<TryApplyInst>(node));
105109
case ApplySiteKind::PartialApplyInst:
106-
return ApplySite(cast<PartialApplyInst>(inst));
110+
return ApplySite(cast<PartialApplyInst>(node));
107111
}
108112
llvm_unreachable("covered switch");
109113
}
110114

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

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

190188
/// Return the type.
@@ -495,27 +493,24 @@ class FullApplySite : public ApplySite {
495493
FullApplySite(BeginApplyInst *inst) : ApplySite(inst) {}
496494
FullApplySite(TryApplyInst *inst) : ApplySite(inst) {}
497495

498-
static FullApplySite isa(SILInstruction *inst) {
499-
auto kind = FullApplySiteKind::fromNodeKind(inst->getKind());
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());
500501
if (!kind)
501502
return FullApplySite();
502503
switch (kind.getValue()) {
503504
case FullApplySiteKind::ApplyInst:
504-
return FullApplySite(cast<ApplyInst>(inst));
505+
return FullApplySite(cast<ApplyInst>(node));
505506
case FullApplySiteKind::BeginApplyInst:
506-
return FullApplySite(cast<BeginApplyInst>(inst));
507+
return FullApplySite(cast<BeginApplyInst>(node));
507508
case FullApplySiteKind::TryApplyInst:
508-
return FullApplySite(cast<TryApplyInst>(inst));
509+
return FullApplySite(cast<TryApplyInst>(node));
509510
}
510511
llvm_unreachable("covered switch");
511512
}
512513

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

include/swift/SIL/DynamicCasts.h

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

161-
static SILDynamicCastInst getAs(SILInstruction *inst) {
162-
auto kind = SILDynamicCastKind::fromNodeKind(inst->getKind());
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());
163166
if (!kind)
164167
return SILDynamicCastInst();
165168
switch (kind.getValue()) {
166169
#define DYNAMICCAST_INST(ID, PARENT) \
167170
case SILDynamicCastKind::ID: \
168-
return SILDynamicCastInst(cast<ID>(inst));
171+
return SILDynamicCastInst(cast<ID>(node));
169172
#include "swift/SIL/SILNodes.def"
170173
}
171174
}

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"
2322
#include "llvm/Support/PrettyStackTrace.h"
2423

2524
namespace swift {
2625
class ASTContext;
2726
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, SILNodePointer node)
77+
PrettyStackTraceSILNode(const char *action, const SILNode *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),
81+
: ValueBase(subClassKind, type, IsRepresentative::Yes),
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(SILNodePointer node) {
109+
static bool classof(const SILNode *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(SILNodePointer node) {
282+
static bool classof(const SILNode *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(SILNodePointer node) {
325+
static bool classof(const SILNode *node) {
326326
return node->getKind() == SILNodeKind::SILFunctionArgument;
327327
}
328328
};

0 commit comments

Comments
 (0)