@@ -541,7 +541,19 @@ class SILInstruction
541541 SILValue getOperand (unsigned Num) const {
542542 return getAllOperands ()[Num].get ();
543543 }
544- Operand &getOperandRef (unsigned Num) { return getAllOperands ()[Num]; }
544+
545+ // / Return the ith mutable operand of this instruction.
546+ // /
547+ // / Equivalent to performing getAllOperands()[index];
548+ Operand &getOperandRef (unsigned index) { return getAllOperands ()[index]; }
549+
550+ // / Return the ith operand of this instruction.
551+ // /
552+ // / Equivalent to performing getAllOperands()[index];
553+ const Operand &getOperandRef (unsigned index) const {
554+ return getAllOperands ()[index];
555+ }
556+
545557 void setOperand (unsigned Num, SILValue V) { getAllOperands ()[Num].set (V); }
546558 void swapOperands (unsigned Num1, unsigned Num2) {
547559 getAllOperands ()[Num1].swap (getAllOperands ()[Num2]);
@@ -917,32 +929,32 @@ inline SingleValueInstruction *SILNode::castToSingleValueInstruction() {
917929// /
918930// / NOTE: We assume that the constructor for the instruction subclass that
919931// / initializes the kind field on our object is run before our constructor runs.
920- class OwnershipForwardingInst {
932+ class OwnershipForwardingMixin {
921933 ValueOwnershipKind ownershipKind;
922934
923935protected:
924- OwnershipForwardingInst (SILInstructionKind kind,
925- ValueOwnershipKind ownershipKind)
936+ OwnershipForwardingMixin (SILInstructionKind kind,
937+ ValueOwnershipKind ownershipKind)
926938 : ownershipKind(ownershipKind) {
927- assert (classof (kind) && " Invalid subclass?!" );
939+ assert (isa (kind) && " Invalid subclass?!" );
928940 }
929941
930942public:
931943 ValueOwnershipKind getOwnershipKind () const { return ownershipKind; }
932944
933945 void setOwnershipKind (ValueOwnershipKind newKind) { ownershipKind = newKind; }
934946
935- static bool classof (const SILNode *node) {
936- if (auto *i = dyn_cast<SILInstruction>(node))
937- return classof (i);
947+ // / Defined inline below due to forward declaration issues.
948+ static OwnershipForwardingMixin *get (SILInstruction *inst);
949+ // / Defined inline below due to forward declaration issues.
950+ static bool isa (SILInstructionKind kind);
951+ static bool isa (const SILInstruction *inst) { return isa (inst->getKind ()); }
952+ static bool isa (const SILNode *node) {
953+ node = node->getRepresentativeSILNodeInObject ();
954+ if (auto *i = dyn_cast<const SILInstruction>(node))
955+ return isa (i);
938956 return false ;
939957 }
940-
941- // Defined inline below due to forward declaration issues.
942- static bool classof (const SILInstruction *inst);
943-
944- // / Define inline below due to forward declaration issues.
945- static bool classof (SILInstructionKind kind);
946958};
947959
948960// / A single value inst that forwards a static ownership from one (or all) of
@@ -952,14 +964,14 @@ class OwnershipForwardingInst {
952964// / explicitly using setOwnershipKind().
953965class FirstArgOwnershipForwardingSingleValueInst
954966 : public SingleValueInstruction,
955- public OwnershipForwardingInst {
967+ public OwnershipForwardingMixin {
956968protected:
957969 FirstArgOwnershipForwardingSingleValueInst (SILInstructionKind kind,
958970 SILDebugLocation debugLoc,
959971 SILType ty,
960972 ValueOwnershipKind ownershipKind)
961973 : SingleValueInstruction(kind, debugLoc, ty),
962- OwnershipForwardingInst (kind, ownershipKind) {
974+ OwnershipForwardingMixin (kind, ownershipKind) {
963975 assert (classof (kind) && " classof missing new subclass?!" );
964976 }
965977
@@ -1084,14 +1096,14 @@ FirstArgOwnershipForwardingSingleValueInst::classof(SILInstructionKind kind) {
10841096
10851097class AllArgOwnershipForwardingSingleValueInst
10861098 : public SingleValueInstruction,
1087- public OwnershipForwardingInst {
1099+ public OwnershipForwardingMixin {
10881100protected:
10891101 AllArgOwnershipForwardingSingleValueInst (SILInstructionKind kind,
10901102 SILDebugLocation debugLoc,
10911103 SILType ty,
10921104 ValueOwnershipKind ownershipKind)
10931105 : SingleValueInstruction(kind, debugLoc, ty),
1094- OwnershipForwardingInst (kind, ownershipKind) {
1106+ OwnershipForwardingMixin (kind, ownershipKind) {
10951107 assert (classof (kind) && " classof missing new subclass?!" );
10961108 }
10971109
@@ -4668,13 +4680,13 @@ class ConversionInst : public SingleValueInstruction {
46684680// / A conversion inst that produces a static OwnershipKind set upon the
46694681// / instruction's construction.
46704682class OwnershipForwardingConversionInst : public ConversionInst ,
4671- public OwnershipForwardingInst {
4683+ public OwnershipForwardingMixin {
46724684protected:
46734685 OwnershipForwardingConversionInst (SILInstructionKind kind,
46744686 SILDebugLocation debugLoc, SILType ty,
46754687 ValueOwnershipKind ownershipKind)
46764688 : ConversionInst(kind, debugLoc, ty),
4677- OwnershipForwardingInst (kind, ownershipKind) {
4689+ OwnershipForwardingMixin (kind, ownershipKind) {
46784690 assert (classof (kind) && " classof missing subclass?!" );
46794691 }
46804692
@@ -5872,15 +5884,15 @@ class SelectEnumInstBase
58725884
58735885// / A select enum inst that produces a static OwnershipKind.
58745886class OwnershipForwardingSelectEnumInstBase : public SelectEnumInstBase ,
5875- public OwnershipForwardingInst {
5887+ public OwnershipForwardingMixin {
58765888protected:
58775889 OwnershipForwardingSelectEnumInstBase (
58785890 SILInstructionKind kind, SILDebugLocation debugLoc, SILType type,
58795891 bool defaultValue, Optional<ArrayRef<ProfileCounter>> caseCounts,
58805892 ProfileCounter defaultCount, ValueOwnershipKind ownershipKind)
58815893 : SelectEnumInstBase(kind, debugLoc, type, defaultValue, caseCounts,
58825894 defaultCount),
5883- OwnershipForwardingInst (kind, ownershipKind) {
5895+ OwnershipForwardingMixin (kind, ownershipKind) {
58845896 assert (classof (kind) && " classof missing subclass" );
58855897 }
58865898
@@ -7612,12 +7624,13 @@ class TermInst : public NonValueInstruction {
76127624};
76137625
76147626class OwnershipForwardingTermInst : public TermInst ,
7615- public OwnershipForwardingInst {
7627+ public OwnershipForwardingMixin {
76167628protected:
76177629 OwnershipForwardingTermInst (SILInstructionKind kind,
76187630 SILDebugLocation debugLoc,
76197631 ValueOwnershipKind ownershipKind)
7620- : TermInst(kind, debugLoc), OwnershipForwardingInst(kind, ownershipKind) {
7632+ : TermInst(kind, debugLoc),
7633+ OwnershipForwardingMixin (kind, ownershipKind) {
76217634 assert (classof (kind));
76227635 }
76237636
@@ -9081,13 +9094,13 @@ SILFunction *ApplyInstBase<Impl, Base, false>::getCalleeFunction() const {
90819094
90829095class OwnershipForwardingMultipleValueInstruction
90839096 : public MultipleValueInstruction,
9084- public OwnershipForwardingInst {
9097+ public OwnershipForwardingMixin {
90859098public:
90869099 OwnershipForwardingMultipleValueInstruction (SILInstructionKind kind,
90879100 SILDebugLocation loc,
90889101 ValueOwnershipKind ownershipKind)
90899102 : MultipleValueInstruction(kind, loc),
9090- OwnershipForwardingInst (kind, ownershipKind) {
9103+ OwnershipForwardingMixin (kind, ownershipKind) {
90919104 assert (classof (kind) && " Missing subclass from classof?!" );
90929105 }
90939106
@@ -9276,16 +9289,7 @@ inline bool Operand::isTypeDependent() const {
92769289 return getUser ()->isTypeDependentOperand (*this );
92779290}
92789291
9279- inline bool OwnershipForwardingInst::classof (const SILInstruction *inst) {
9280- return FirstArgOwnershipForwardingSingleValueInst::classof (inst) ||
9281- AllArgOwnershipForwardingSingleValueInst::classof (inst) ||
9282- OwnershipForwardingTermInst::classof (inst) ||
9283- OwnershipForwardingConversionInst::classof (inst) ||
9284- OwnershipForwardingSelectEnumInstBase::classof (inst) ||
9285- OwnershipForwardingMultipleValueInstruction::classof (inst);
9286- }
9287-
9288- inline bool OwnershipForwardingInst::classof (SILInstructionKind kind) {
9292+ inline bool OwnershipForwardingMixin::isa (SILInstructionKind kind) {
92899293 return FirstArgOwnershipForwardingSingleValueInst::classof (kind) ||
92909294 AllArgOwnershipForwardingSingleValueInst::classof (kind) ||
92919295 OwnershipForwardingTermInst::classof (kind) ||
@@ -9294,6 +9298,28 @@ inline bool OwnershipForwardingInst::classof(SILInstructionKind kind) {
92949298 OwnershipForwardingMultipleValueInstruction::classof (kind);
92959299}
92969300
9301+ inline OwnershipForwardingMixin *
9302+ OwnershipForwardingMixin::get (SILInstruction *inst) {
9303+ // I am purposely performing this cast in this manner rather than reinterpret
9304+ // casting to OwnershipForwardingMixin to ensure that we offset to the
9305+ // appropriate offset inside of inst instead of converting inst's current
9306+ // location to an OwnershipForwardingMixin which would be incorrect.
9307+ if (auto *result = dyn_cast<FirstArgOwnershipForwardingSingleValueInst>(inst))
9308+ return result;
9309+ if (auto *result = dyn_cast<AllArgOwnershipForwardingSingleValueInst>(inst))
9310+ return result;
9311+ if (auto *result = dyn_cast<OwnershipForwardingTermInst>(inst))
9312+ return result;
9313+ if (auto *result = dyn_cast<OwnershipForwardingConversionInst>(inst))
9314+ return result;
9315+ if (auto *result = dyn_cast<OwnershipForwardingSelectEnumInstBase>(inst))
9316+ return result;
9317+ if (auto *result =
9318+ dyn_cast<OwnershipForwardingMultipleValueInstruction>(inst))
9319+ return result;
9320+ return nullptr ;
9321+ }
9322+
92979323} // end swift namespace
92989324
92999325// ===----------------------------------------------------------------------===//
0 commit comments