@@ -541,7 +541,19 @@ class SILInstruction
541
541
SILValue getOperand (unsigned Num) const {
542
542
return getAllOperands ()[Num].get ();
543
543
}
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
+
545
557
void setOperand (unsigned Num, SILValue V) { getAllOperands ()[Num].set (V); }
546
558
void swapOperands (unsigned Num1, unsigned Num2) {
547
559
getAllOperands ()[Num1].swap (getAllOperands ()[Num2]);
@@ -917,32 +929,32 @@ inline SingleValueInstruction *SILNode::castToSingleValueInstruction() {
917
929
// /
918
930
// / NOTE: We assume that the constructor for the instruction subclass that
919
931
// / initializes the kind field on our object is run before our constructor runs.
920
- class OwnershipForwardingInst {
932
+ class OwnershipForwardingMixin {
921
933
ValueOwnershipKind ownershipKind;
922
934
923
935
protected:
924
- OwnershipForwardingInst (SILInstructionKind kind,
925
- ValueOwnershipKind ownershipKind)
936
+ OwnershipForwardingMixin (SILInstructionKind kind,
937
+ ValueOwnershipKind ownershipKind)
926
938
: ownershipKind(ownershipKind) {
927
- assert (classof (kind) && " Invalid subclass?!" );
939
+ assert (isa (kind) && " Invalid subclass?!" );
928
940
}
929
941
930
942
public:
931
943
ValueOwnershipKind getOwnershipKind () const { return ownershipKind; }
932
944
933
945
void setOwnershipKind (ValueOwnershipKind newKind) { ownershipKind = newKind; }
934
946
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);
938
956
return false ;
939
957
}
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);
946
958
};
947
959
948
960
// / A single value inst that forwards a static ownership from one (or all) of
@@ -952,14 +964,14 @@ class OwnershipForwardingInst {
952
964
// / explicitly using setOwnershipKind().
953
965
class FirstArgOwnershipForwardingSingleValueInst
954
966
: public SingleValueInstruction,
955
- public OwnershipForwardingInst {
967
+ public OwnershipForwardingMixin {
956
968
protected:
957
969
FirstArgOwnershipForwardingSingleValueInst (SILInstructionKind kind,
958
970
SILDebugLocation debugLoc,
959
971
SILType ty,
960
972
ValueOwnershipKind ownershipKind)
961
973
: SingleValueInstruction(kind, debugLoc, ty),
962
- OwnershipForwardingInst (kind, ownershipKind) {
974
+ OwnershipForwardingMixin (kind, ownershipKind) {
963
975
assert (classof (kind) && " classof missing new subclass?!" );
964
976
}
965
977
@@ -1084,14 +1096,14 @@ FirstArgOwnershipForwardingSingleValueInst::classof(SILInstructionKind kind) {
1084
1096
1085
1097
class AllArgOwnershipForwardingSingleValueInst
1086
1098
: public SingleValueInstruction,
1087
- public OwnershipForwardingInst {
1099
+ public OwnershipForwardingMixin {
1088
1100
protected:
1089
1101
AllArgOwnershipForwardingSingleValueInst (SILInstructionKind kind,
1090
1102
SILDebugLocation debugLoc,
1091
1103
SILType ty,
1092
1104
ValueOwnershipKind ownershipKind)
1093
1105
: SingleValueInstruction(kind, debugLoc, ty),
1094
- OwnershipForwardingInst (kind, ownershipKind) {
1106
+ OwnershipForwardingMixin (kind, ownershipKind) {
1095
1107
assert (classof (kind) && " classof missing new subclass?!" );
1096
1108
}
1097
1109
@@ -4668,13 +4680,13 @@ class ConversionInst : public SingleValueInstruction {
4668
4680
// / A conversion inst that produces a static OwnershipKind set upon the
4669
4681
// / instruction's construction.
4670
4682
class OwnershipForwardingConversionInst : public ConversionInst ,
4671
- public OwnershipForwardingInst {
4683
+ public OwnershipForwardingMixin {
4672
4684
protected:
4673
4685
OwnershipForwardingConversionInst (SILInstructionKind kind,
4674
4686
SILDebugLocation debugLoc, SILType ty,
4675
4687
ValueOwnershipKind ownershipKind)
4676
4688
: ConversionInst(kind, debugLoc, ty),
4677
- OwnershipForwardingInst (kind, ownershipKind) {
4689
+ OwnershipForwardingMixin (kind, ownershipKind) {
4678
4690
assert (classof (kind) && " classof missing subclass?!" );
4679
4691
}
4680
4692
@@ -5872,15 +5884,15 @@ class SelectEnumInstBase
5872
5884
5873
5885
// / A select enum inst that produces a static OwnershipKind.
5874
5886
class OwnershipForwardingSelectEnumInstBase : public SelectEnumInstBase ,
5875
- public OwnershipForwardingInst {
5887
+ public OwnershipForwardingMixin {
5876
5888
protected:
5877
5889
OwnershipForwardingSelectEnumInstBase (
5878
5890
SILInstructionKind kind, SILDebugLocation debugLoc, SILType type,
5879
5891
bool defaultValue, Optional<ArrayRef<ProfileCounter>> caseCounts,
5880
5892
ProfileCounter defaultCount, ValueOwnershipKind ownershipKind)
5881
5893
: SelectEnumInstBase(kind, debugLoc, type, defaultValue, caseCounts,
5882
5894
defaultCount),
5883
- OwnershipForwardingInst (kind, ownershipKind) {
5895
+ OwnershipForwardingMixin (kind, ownershipKind) {
5884
5896
assert (classof (kind) && " classof missing subclass" );
5885
5897
}
5886
5898
@@ -7612,12 +7624,13 @@ class TermInst : public NonValueInstruction {
7612
7624
};
7613
7625
7614
7626
class OwnershipForwardingTermInst : public TermInst ,
7615
- public OwnershipForwardingInst {
7627
+ public OwnershipForwardingMixin {
7616
7628
protected:
7617
7629
OwnershipForwardingTermInst (SILInstructionKind kind,
7618
7630
SILDebugLocation debugLoc,
7619
7631
ValueOwnershipKind ownershipKind)
7620
- : TermInst(kind, debugLoc), OwnershipForwardingInst(kind, ownershipKind) {
7632
+ : TermInst(kind, debugLoc),
7633
+ OwnershipForwardingMixin (kind, ownershipKind) {
7621
7634
assert (classof (kind));
7622
7635
}
7623
7636
@@ -9081,13 +9094,13 @@ SILFunction *ApplyInstBase<Impl, Base, false>::getCalleeFunction() const {
9081
9094
9082
9095
class OwnershipForwardingMultipleValueInstruction
9083
9096
: public MultipleValueInstruction,
9084
- public OwnershipForwardingInst {
9097
+ public OwnershipForwardingMixin {
9085
9098
public:
9086
9099
OwnershipForwardingMultipleValueInstruction (SILInstructionKind kind,
9087
9100
SILDebugLocation loc,
9088
9101
ValueOwnershipKind ownershipKind)
9089
9102
: MultipleValueInstruction(kind, loc),
9090
- OwnershipForwardingInst (kind, ownershipKind) {
9103
+ OwnershipForwardingMixin (kind, ownershipKind) {
9091
9104
assert (classof (kind) && " Missing subclass from classof?!" );
9092
9105
}
9093
9106
@@ -9276,16 +9289,7 @@ inline bool Operand::isTypeDependent() const {
9276
9289
return getUser ()->isTypeDependentOperand (*this );
9277
9290
}
9278
9291
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) {
9289
9293
return FirstArgOwnershipForwardingSingleValueInst::classof (kind) ||
9290
9294
AllArgOwnershipForwardingSingleValueInst::classof (kind) ||
9291
9295
OwnershipForwardingTermInst::classof (kind) ||
@@ -9294,6 +9298,28 @@ inline bool OwnershipForwardingInst::classof(SILInstructionKind kind) {
9294
9298
OwnershipForwardingMultipleValueInstruction::classof (kind);
9295
9299
}
9296
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
+
9297
9323
} // end swift namespace
9298
9324
9299
9325
// ===----------------------------------------------------------------------===//
0 commit comments