@@ -1095,6 +1095,12 @@ class MultipleValueInstructionTrailingObjects<Derived, DerivedResult,
1095
1095
return { ptr, NumResults };
1096
1096
}
1097
1097
1098
+ MutableArrayRef<DerivedResult> getAllResultsBuffer () {
1099
+ auto *ptr = this ->TrailingObjects ::template
1100
+ getTrailingObjects<DerivedResult>();
1101
+ return { ptr, NumResults };
1102
+ }
1103
+
1098
1104
SILInstructionResultArray getAllResults () const {
1099
1105
// Our results start at element 1 since we stash the pointer to our parent
1100
1106
// MultipleValueInstruction in the 0 elt slot. This allows all
@@ -8126,23 +8132,20 @@ class DynamicMethodBranchInst
8126
8132
};
8127
8133
8128
8134
// / The base class for cast instructions which are terminators.
8129
- class CastBranchInstBase : public TermInst {
8135
+ template < typename BaseTy> class CastBranchInstBase : public BaseTy {
8130
8136
std::array<SILSuccessor, 2 > DestBBs;
8131
8137
8132
8138
public:
8133
-
8139
+ template < typename ... ArgTys>
8134
8140
CastBranchInstBase (SILInstructionKind K, SILDebugLocation DebugLoc,
8135
8141
SILBasicBlock *SuccessBB, SILBasicBlock *FailureBB,
8136
- ProfileCounter Target1Count = ProfileCounter(),
8137
- ProfileCounter Target2Count = ProfileCounter()) :
8138
- TermInst (K, DebugLoc),
8139
- DestBBs{{{this , SuccessBB, Target1Count},
8140
- {this , FailureBB, Target2Count}}}
8141
- {}
8142
+ ProfileCounter Target1Count, ProfileCounter Target2Count,
8143
+ ArgTys &&... args)
8144
+ : BaseTy(K, DebugLoc, std::forward<ArgTys>(args)...),
8145
+ DestBBs{{{this , SuccessBB, Target1Count},
8146
+ {this , FailureBB, Target2Count}}} {}
8142
8147
8143
- SuccessorListTy getSuccessors () {
8144
- return DestBBs;
8145
- }
8148
+ TermInst::SuccessorListTy getSuccessors () { return DestBBs; }
8146
8149
8147
8150
SILBasicBlock *getSuccessBB () { return DestBBs[0 ]; }
8148
8151
const SILBasicBlock *getSuccessBB () const { return DestBBs[0 ]; }
@@ -8157,7 +8160,7 @@ class CastBranchInstBase : public TermInst {
8157
8160
8158
8161
// / The base class for cast instructions which are terminators and have a
8159
8162
// / CastConsumptionKind.
8160
- class CastBranchWithConsumptionKindBase : public CastBranchInstBase {
8163
+ class CastBranchWithConsumptionKindBase : public CastBranchInstBase <TermInst> {
8161
8164
CastConsumptionKind ConsumptionKind;
8162
8165
8163
8166
public:
@@ -8250,11 +8253,10 @@ class AddrCastInstBase
8250
8253
// / Perform a checked cast operation and branch on whether the cast succeeds.
8251
8254
// / The success branch destination block receives the cast result as a BB
8252
8255
// / argument.
8253
- class CheckedCastBranchInst final :
8254
- public UnaryInstructionWithTypeDependentOperandsBase<
8255
- SILInstructionKind::CheckedCastBranchInst,
8256
- CheckedCastBranchInst,
8257
- CastBranchInstBase> {
8256
+ class CheckedCastBranchInst final
8257
+ : public UnaryInstructionWithTypeDependentOperandsBase<
8258
+ SILInstructionKind::CheckedCastBranchInst, CheckedCastBranchInst,
8259
+ CastBranchInstBase<OwnershipForwardingTermInst>> {
8258
8260
friend SILBuilder;
8259
8261
8260
8262
SILType DestLoweredTy;
@@ -8266,12 +8268,12 @@ class CheckedCastBranchInst final:
8266
8268
ArrayRef<SILValue> TypeDependentOperands,
8267
8269
SILType DestLoweredTy, CanType DestFormalTy,
8268
8270
SILBasicBlock *SuccessBB, SILBasicBlock *FailureBB,
8269
- ProfileCounter Target1Count, ProfileCounter Target2Count)
8270
- : UnaryInstructionWithTypeDependentOperandsBase(DebugLoc, Operand,
8271
- TypeDependentOperands,
8272
- SuccessBB, FailureBB, Target1Count, Target2Count) ,
8273
- DestLoweredTy (DestLoweredTy ),
8274
- DestFormalTy(DestFormalTy),
8271
+ ProfileCounter Target1Count,
8272
+ ProfileCounter Target2Count)
8273
+ : UnaryInstructionWithTypeDependentOperandsBase(
8274
+ DebugLoc, Operand, TypeDependentOperands, SuccessBB, FailureBB ,
8275
+ Target1Count, Target2Count, Operand.getOwnershipKind() ),
8276
+ DestLoweredTy (DestLoweredTy), DestFormalTy(DestFormalTy),
8275
8277
IsExact(IsExact) {}
8276
8278
8277
8279
static CheckedCastBranchInst *
@@ -8297,23 +8299,23 @@ class CheckedCastBranchInst final:
8297
8299
class CheckedCastValueBranchInst final
8298
8300
: public UnaryInstructionWithTypeDependentOperandsBase<
8299
8301
SILInstructionKind::CheckedCastValueBranchInst,
8300
- CheckedCastValueBranchInst,
8301
- CastBranchInstBase> {
8302
+ CheckedCastValueBranchInst, CastBranchInstBase<TermInst>> {
8302
8303
friend SILBuilder;
8303
8304
8304
8305
CanType SourceFormalTy;
8305
8306
SILType DestLoweredTy;
8306
8307
CanType DestFormalTy;
8307
8308
8308
- CheckedCastValueBranchInst (SILDebugLocation DebugLoc,
8309
- SILValue Operand, CanType SourceFormalTy,
8309
+ CheckedCastValueBranchInst (SILDebugLocation DebugLoc, SILValue Operand,
8310
+ CanType SourceFormalTy,
8310
8311
ArrayRef<SILValue> TypeDependentOperands,
8311
8312
SILType DestLoweredTy, CanType DestFormalTy,
8312
8313
SILBasicBlock *SuccessBB, SILBasicBlock *FailureBB)
8313
- : UnaryInstructionWithTypeDependentOperandsBase(DebugLoc, Operand,
8314
- TypeDependentOperands, SuccessBB, FailureBB),
8315
- SourceFormalTy (SourceFormalTy),
8316
- DestLoweredTy(DestLoweredTy), DestFormalTy(DestFormalTy) {}
8314
+ : UnaryInstructionWithTypeDependentOperandsBase(
8315
+ DebugLoc, Operand, TypeDependentOperands, SuccessBB, FailureBB,
8316
+ ProfileCounter (), ProfileCounter()),
8317
+ SourceFormalTy(SourceFormalTy), DestLoweredTy(DestLoweredTy),
8318
+ DestFormalTy(DestFormalTy) {}
8317
8319
8318
8320
static CheckedCastValueBranchInst *
8319
8321
create (SILDebugLocation DebugLoc,
@@ -8757,6 +8759,23 @@ SILFunction *ApplyInstBase<Impl, Base, false>::getCalleeFunction() const {
8757
8759
}
8758
8760
}
8759
8761
8762
+ class OwnershipForwardingMultipleValueInstruction
8763
+ : public MultipleValueInstruction {
8764
+ ValueOwnershipKind ownershipKind;
8765
+
8766
+ public:
8767
+ OwnershipForwardingMultipleValueInstruction (SILInstructionKind kind,
8768
+ SILDebugLocation loc,
8769
+ ValueOwnershipKind ownershipKind)
8770
+ : MultipleValueInstruction(kind, loc), ownershipKind(ownershipKind) {}
8771
+
8772
+ // / Returns the preferred ownership kind of this multiple value instruction.
8773
+ ValueOwnershipKind getOwnershipKind () const { return ownershipKind; }
8774
+ void setOwnershipKind (ValueOwnershipKind newOwnershipKind) {
8775
+ ownershipKind = newOwnershipKind;
8776
+ }
8777
+ };
8778
+
8760
8779
// / A result for the destructure_struct instruction. See documentation for
8761
8780
// / destructure_struct for more information.
8762
8781
class DestructureStructResult final : public MultipleValueInstructionResult {
@@ -8780,15 +8799,15 @@ class DestructureStructResult final : public MultipleValueInstructionResult {
8780
8799
// / struct's fields.
8781
8800
class DestructureStructInst final
8782
8801
: public UnaryInstructionBase<SILInstructionKind::DestructureStructInst,
8783
- MultipleValueInstruction >,
8784
- public MultipleValueInstructionTrailingObjects<
8785
- DestructureStructInst, DestructureStructResult> {
8802
+ OwnershipForwardingMultipleValueInstruction >,
8803
+ public MultipleValueInstructionTrailingObjects<DestructureStructInst,
8804
+ DestructureStructResult> {
8786
8805
friend TrailingObjects;
8787
8806
8788
8807
DestructureStructInst (SILModule &M, SILDebugLocation Loc, SILValue Operand,
8789
8808
ArrayRef<SILType> Types,
8790
8809
ArrayRef<ValueOwnershipKind> OwnershipKinds)
8791
- : UnaryInstructionBase(Loc, Operand),
8810
+ : UnaryInstructionBase(Loc, Operand, Operand.getOwnershipKind() ),
8792
8811
MultipleValueInstructionTrailingObjects (this , Types, OwnershipKinds) {}
8793
8812
8794
8813
public:
@@ -8829,15 +8848,15 @@ class DestructureTupleResult final : public MultipleValueInstructionResult {
8829
8848
// / tuples's elements.
8830
8849
class DestructureTupleInst final
8831
8850
: public UnaryInstructionBase<SILInstructionKind::DestructureTupleInst,
8832
- MultipleValueInstruction >,
8833
- public MultipleValueInstructionTrailingObjects<
8834
- DestructureTupleInst, DestructureTupleResult> {
8851
+ OwnershipForwardingMultipleValueInstruction >,
8852
+ public MultipleValueInstructionTrailingObjects<DestructureTupleInst,
8853
+ DestructureTupleResult> {
8835
8854
friend TrailingObjects;
8836
8855
8837
8856
DestructureTupleInst (SILModule &M, SILDebugLocation Loc, SILValue Operand,
8838
8857
ArrayRef<SILType> Types,
8839
8858
ArrayRef<ValueOwnershipKind> OwnershipKinds)
8840
- : UnaryInstructionBase(Loc, Operand),
8859
+ : UnaryInstructionBase(Loc, Operand, Operand.getOwnershipKind() ),
8841
8860
MultipleValueInstructionTrailingObjects (this , Types, OwnershipKinds) {}
8842
8861
8843
8862
public:
0 commit comments