@@ -929,32 +929,32 @@ inline SingleValueInstruction *SILNode::castToSingleValueInstruction() {
929
929
// /
930
930
// / NOTE: We assume that the constructor for the instruction subclass that
931
931
// / initializes the kind field on our object is run before our constructor runs.
932
- class OwnershipForwardingInst {
932
+ class OwnershipForwardingMixin {
933
933
ValueOwnershipKind ownershipKind;
934
934
935
935
protected:
936
- OwnershipForwardingInst (SILInstructionKind kind,
937
- ValueOwnershipKind ownershipKind)
936
+ OwnershipForwardingMixin (SILInstructionKind kind,
937
+ ValueOwnershipKind ownershipKind)
938
938
: ownershipKind(ownershipKind) {
939
- assert (classof (kind) && " Invalid subclass?!" );
939
+ assert (isa (kind) && " Invalid subclass?!" );
940
940
}
941
941
942
942
public:
943
943
ValueOwnershipKind getOwnershipKind () const { return ownershipKind; }
944
944
945
945
void setOwnershipKind (ValueOwnershipKind newKind) { ownershipKind = newKind; }
946
946
947
- static bool classof (const SILNode *node) {
948
- if (auto *i = dyn_cast<SILInstruction>(node))
949
- 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);
950
956
return false ;
951
957
}
952
-
953
- // Defined inline below due to forward declaration issues.
954
- static bool classof (const SILInstruction *inst);
955
-
956
- // / Define inline below due to forward declaration issues.
957
- static bool classof (SILInstructionKind kind);
958
958
};
959
959
960
960
// / A single value inst that forwards a static ownership from one (or all) of
@@ -964,14 +964,14 @@ class OwnershipForwardingInst {
964
964
// / explicitly using setOwnershipKind().
965
965
class FirstArgOwnershipForwardingSingleValueInst
966
966
: public SingleValueInstruction,
967
- public OwnershipForwardingInst {
967
+ public OwnershipForwardingMixin {
968
968
protected:
969
969
FirstArgOwnershipForwardingSingleValueInst (SILInstructionKind kind,
970
970
SILDebugLocation debugLoc,
971
971
SILType ty,
972
972
ValueOwnershipKind ownershipKind)
973
973
: SingleValueInstruction(kind, debugLoc, ty),
974
- OwnershipForwardingInst (kind, ownershipKind) {
974
+ OwnershipForwardingMixin (kind, ownershipKind) {
975
975
assert (classof (kind) && " classof missing new subclass?!" );
976
976
}
977
977
@@ -1096,14 +1096,14 @@ FirstArgOwnershipForwardingSingleValueInst::classof(SILInstructionKind kind) {
1096
1096
1097
1097
class AllArgOwnershipForwardingSingleValueInst
1098
1098
: public SingleValueInstruction,
1099
- public OwnershipForwardingInst {
1099
+ public OwnershipForwardingMixin {
1100
1100
protected:
1101
1101
AllArgOwnershipForwardingSingleValueInst (SILInstructionKind kind,
1102
1102
SILDebugLocation debugLoc,
1103
1103
SILType ty,
1104
1104
ValueOwnershipKind ownershipKind)
1105
1105
: SingleValueInstruction(kind, debugLoc, ty),
1106
- OwnershipForwardingInst (kind, ownershipKind) {
1106
+ OwnershipForwardingMixin (kind, ownershipKind) {
1107
1107
assert (classof (kind) && " classof missing new subclass?!" );
1108
1108
}
1109
1109
@@ -4680,13 +4680,13 @@ class ConversionInst : public SingleValueInstruction {
4680
4680
// / A conversion inst that produces a static OwnershipKind set upon the
4681
4681
// / instruction's construction.
4682
4682
class OwnershipForwardingConversionInst : public ConversionInst ,
4683
- public OwnershipForwardingInst {
4683
+ public OwnershipForwardingMixin {
4684
4684
protected:
4685
4685
OwnershipForwardingConversionInst (SILInstructionKind kind,
4686
4686
SILDebugLocation debugLoc, SILType ty,
4687
4687
ValueOwnershipKind ownershipKind)
4688
4688
: ConversionInst(kind, debugLoc, ty),
4689
- OwnershipForwardingInst (kind, ownershipKind) {
4689
+ OwnershipForwardingMixin (kind, ownershipKind) {
4690
4690
assert (classof (kind) && " classof missing subclass?!" );
4691
4691
}
4692
4692
@@ -5884,15 +5884,15 @@ class SelectEnumInstBase
5884
5884
5885
5885
// / A select enum inst that produces a static OwnershipKind.
5886
5886
class OwnershipForwardingSelectEnumInstBase : public SelectEnumInstBase ,
5887
- public OwnershipForwardingInst {
5887
+ public OwnershipForwardingMixin {
5888
5888
protected:
5889
5889
OwnershipForwardingSelectEnumInstBase (
5890
5890
SILInstructionKind kind, SILDebugLocation debugLoc, SILType type,
5891
5891
bool defaultValue, Optional<ArrayRef<ProfileCounter>> caseCounts,
5892
5892
ProfileCounter defaultCount, ValueOwnershipKind ownershipKind)
5893
5893
: SelectEnumInstBase(kind, debugLoc, type, defaultValue, caseCounts,
5894
5894
defaultCount),
5895
- OwnershipForwardingInst (kind, ownershipKind) {
5895
+ OwnershipForwardingMixin (kind, ownershipKind) {
5896
5896
assert (classof (kind) && " classof missing subclass" );
5897
5897
}
5898
5898
@@ -7624,12 +7624,13 @@ class TermInst : public NonValueInstruction {
7624
7624
};
7625
7625
7626
7626
class OwnershipForwardingTermInst : public TermInst ,
7627
- public OwnershipForwardingInst {
7627
+ public OwnershipForwardingMixin {
7628
7628
protected:
7629
7629
OwnershipForwardingTermInst (SILInstructionKind kind,
7630
7630
SILDebugLocation debugLoc,
7631
7631
ValueOwnershipKind ownershipKind)
7632
- : TermInst(kind, debugLoc), OwnershipForwardingInst(kind, ownershipKind) {
7632
+ : TermInst(kind, debugLoc),
7633
+ OwnershipForwardingMixin (kind, ownershipKind) {
7633
7634
assert (classof (kind));
7634
7635
}
7635
7636
@@ -9093,13 +9094,13 @@ SILFunction *ApplyInstBase<Impl, Base, false>::getCalleeFunction() const {
9093
9094
9094
9095
class OwnershipForwardingMultipleValueInstruction
9095
9096
: public MultipleValueInstruction,
9096
- public OwnershipForwardingInst {
9097
+ public OwnershipForwardingMixin {
9097
9098
public:
9098
9099
OwnershipForwardingMultipleValueInstruction (SILInstructionKind kind,
9099
9100
SILDebugLocation loc,
9100
9101
ValueOwnershipKind ownershipKind)
9101
9102
: MultipleValueInstruction(kind, loc),
9102
- OwnershipForwardingInst (kind, ownershipKind) {
9103
+ OwnershipForwardingMixin (kind, ownershipKind) {
9103
9104
assert (classof (kind) && " Missing subclass from classof?!" );
9104
9105
}
9105
9106
@@ -9288,16 +9289,7 @@ inline bool Operand::isTypeDependent() const {
9288
9289
return getUser ()->isTypeDependentOperand (*this );
9289
9290
}
9290
9291
9291
- inline bool OwnershipForwardingInst::classof (const SILInstruction *inst) {
9292
- return FirstArgOwnershipForwardingSingleValueInst::classof (inst) ||
9293
- AllArgOwnershipForwardingSingleValueInst::classof (inst) ||
9294
- OwnershipForwardingTermInst::classof (inst) ||
9295
- OwnershipForwardingConversionInst::classof (inst) ||
9296
- OwnershipForwardingSelectEnumInstBase::classof (inst) ||
9297
- OwnershipForwardingMultipleValueInstruction::classof (inst);
9298
- }
9299
-
9300
- inline bool OwnershipForwardingInst::classof (SILInstructionKind kind) {
9292
+ inline bool OwnershipForwardingMixin::isa (SILInstructionKind kind) {
9301
9293
return FirstArgOwnershipForwardingSingleValueInst::classof (kind) ||
9302
9294
AllArgOwnershipForwardingSingleValueInst::classof (kind) ||
9303
9295
OwnershipForwardingTermInst::classof (kind) ||
@@ -9306,6 +9298,28 @@ inline bool OwnershipForwardingInst::classof(SILInstructionKind kind) {
9306
9298
OwnershipForwardingMultipleValueInstruction::classof (kind);
9307
9299
}
9308
9300
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
+
9309
9323
} // end swift namespace
9310
9324
9311
9325
// ===----------------------------------------------------------------------===//
0 commit comments