Skip to content

SIL: let SingleValueInstruction only inherit from a single SILNode. #35554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
45 changes: 25 additions & 20 deletions include/swift/SIL/ApplySite.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,28 +90,30 @@ class ApplySite {

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

static ApplySite isa(SILNode *node) {
auto *i = dyn_cast<SILInstruction>(node);
if (!i)
return ApplySite();

auto kind = ApplySiteKind::fromNodeKind(i->getKind());
static ApplySite isa(SILInstruction *inst) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eeckstein I wish you had also renamed this to cast or get. It is weird that this is isa since it doesn't return a bool.

auto kind = ApplySiteKind::fromNodeKind(inst->getKind());
if (!kind)
return ApplySite();

switch (kind.getValue()) {
case ApplySiteKind::ApplyInst:
return ApplySite(cast<ApplyInst>(node));
return ApplySite(cast<ApplyInst>(inst));
case ApplySiteKind::BeginApplyInst:
return ApplySite(cast<BeginApplyInst>(node));
return ApplySite(cast<BeginApplyInst>(inst));
case ApplySiteKind::TryApplyInst:
return ApplySite(cast<TryApplyInst>(node));
return ApplySite(cast<TryApplyInst>(inst));
case ApplySiteKind::PartialApplyInst:
return ApplySite(cast<PartialApplyInst>(node));
return ApplySite(cast<PartialApplyInst>(inst));
}
llvm_unreachable("covered switch");
}

static ApplySite isa(SILValue value) {
if (auto *inst = value->getDefiningInstruction())
return ApplySite::isa(inst);
return ApplySite();
}

ApplySiteKind getKind() const { return ApplySiteKind(Inst->getKind()); }

explicit operator bool() const { return Inst != nullptr; }
Expand Down Expand Up @@ -181,8 +183,8 @@ class ApplySite {
/// Calls to (previous_)dynamic_function_ref have a dynamic target function so
/// we should not optimize them.
bool canOptimize() const {
return !DynamicFunctionRefInst::classof(getCallee()) &&
!PreviousDynamicFunctionRefInst::classof(getCallee());
return !swift::isa<DynamicFunctionRefInst>(getCallee()) &&
!swift::isa<PreviousDynamicFunctionRefInst>(getCallee());
}

/// Return the type.
Expand Down Expand Up @@ -493,24 +495,27 @@ class FullApplySite : public ApplySite {
FullApplySite(BeginApplyInst *inst) : ApplySite(inst) {}
FullApplySite(TryApplyInst *inst) : ApplySite(inst) {}

static FullApplySite isa(SILNode *node) {
auto *i = dyn_cast<SILInstruction>(node);
if (!i)
return FullApplySite();
auto kind = FullApplySiteKind::fromNodeKind(i->getKind());
static FullApplySite isa(SILInstruction *inst) {
auto kind = FullApplySiteKind::fromNodeKind(inst->getKind());
if (!kind)
return FullApplySite();
switch (kind.getValue()) {
case FullApplySiteKind::ApplyInst:
return FullApplySite(cast<ApplyInst>(node));
return FullApplySite(cast<ApplyInst>(inst));
case FullApplySiteKind::BeginApplyInst:
return FullApplySite(cast<BeginApplyInst>(node));
return FullApplySite(cast<BeginApplyInst>(inst));
case FullApplySiteKind::TryApplyInst:
return FullApplySite(cast<TryApplyInst>(node));
return FullApplySite(cast<TryApplyInst>(inst));
}
llvm_unreachable("covered switch");
}

static FullApplySite isa(SILValue value) {
if (auto *inst = value->getDefiningInstruction())
return FullApplySite::isa(inst);
return FullApplySite();
}

FullApplySiteKind getKind() const {
return FullApplySiteKind(getInstruction()->getKind());
}
Expand Down
9 changes: 3 additions & 6 deletions include/swift/SIL/DynamicCasts.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,14 @@ struct SILDynamicCastInst {
SILDynamicCastInst(ID *i) : inst(i) {}
#include "swift/SIL/SILNodes.def"

static SILDynamicCastInst getAs(SILNode *node) {
auto *i = dyn_cast<SILInstruction>(node);
if (!i)
return SILDynamicCastInst();
auto kind = SILDynamicCastKind::fromNodeKind(i->getKind());
static SILDynamicCastInst getAs(SILInstruction *inst) {
auto kind = SILDynamicCastKind::fromNodeKind(inst->getKind());
if (!kind)
return SILDynamicCastInst();
switch (kind.getValue()) {
#define DYNAMICCAST_INST(ID, PARENT) \
case SILDynamicCastKind::ID: \
return SILDynamicCastInst(cast<ID>(node));
return SILDynamicCastInst(cast<ID>(inst));
#include "swift/SIL/SILNodes.def"
}
}
Expand Down
4 changes: 2 additions & 2 deletions include/swift/SIL/PrettyStackTrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
#define SWIFT_SIL_PRETTYSTACKTRACE_H

#include "swift/SIL/SILLocation.h"
#include "swift/SIL/SILNode.h"
#include "llvm/Support/PrettyStackTrace.h"

namespace swift {
class ASTContext;
class SILFunction;
class SILNode;

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

public:
PrettyStackTraceSILNode(const char *action, const SILNode *node)
PrettyStackTraceSILNode(const char *action, SILNodePointer node)
: Node(node), Action(action) {}

virtual void print(llvm::raw_ostream &OS) const override;
Expand Down
8 changes: 4 additions & 4 deletions include/swift/SIL/SILArgument.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class SILArgument : public ValueBase {
explicit SILArgument(ValueKind subClassKind, SILType type,
ValueOwnershipKind ownershipKind,
const ValueDecl *inputDecl = nullptr)
: ValueBase(subClassKind, type, IsRepresentative::Yes),
: ValueBase(subClassKind, type),
parentBlock(nullptr), decl(inputDecl) {
Bits.SILArgument.VOKind = static_cast<unsigned>(ownershipKind);
}
Expand Down Expand Up @@ -106,7 +106,7 @@ class SILArgument : public ValueBase {

static bool classof(const SILInstruction *) = delete;
static bool classof(const SILUndef *) = delete;
static bool classof(const SILNode *node) {
static bool classof(SILNodePointer node) {
return node->getKind() >= SILNodeKind::First_SILArgument &&
node->getKind() <= SILNodeKind::Last_SILArgument;
}
Expand Down Expand Up @@ -279,7 +279,7 @@ class SILPhiArgument : public SILArgument {

static bool classof(const SILInstruction *) = delete;
static bool classof(const SILUndef *) = delete;
static bool classof(const SILNode *node) {
static bool classof(SILNodePointer node) {
return node->getKind() == SILNodeKind::SILPhiArgument;
}
};
Expand Down Expand Up @@ -322,7 +322,7 @@ class SILFunctionArgument : public SILArgument {

static bool classof(const SILInstruction *) = delete;
static bool classof(const SILUndef *) = delete;
static bool classof(const SILNode *node) {
static bool classof(SILNodePointer node) {
return node->getKind() == SILNodeKind::SILFunctionArgument;
}
};
Expand Down
Loading