@@ -29,121 +29,51 @@ bool swift::isValueAddressOrTrivial(SILValue v) {
29
29
v.getOwnershipKind () == OwnershipKind::None;
30
30
}
31
31
32
- // These operations forward both owned and guaranteed ownership.
33
- static bool isOwnershipForwardingInstructionKind (SILInstructionKind kind) {
34
- switch (kind) {
35
- case SILInstructionKind::TupleInst:
36
- case SILInstructionKind::StructInst:
37
- case SILInstructionKind::EnumInst:
38
- case SILInstructionKind::DifferentiableFunctionInst:
39
- case SILInstructionKind::LinearFunctionInst:
40
- case SILInstructionKind::OpenExistentialRefInst:
41
- case SILInstructionKind::UpcastInst:
42
- case SILInstructionKind::UncheckedValueCastInst:
43
- case SILInstructionKind::UncheckedRefCastInst:
44
- case SILInstructionKind::ConvertFunctionInst:
45
- case SILInstructionKind::RefToBridgeObjectInst:
46
- case SILInstructionKind::BridgeObjectToRefInst:
47
- case SILInstructionKind::UnconditionalCheckedCastInst:
48
- case SILInstructionKind::UncheckedEnumDataInst:
49
- case SILInstructionKind::SelectEnumInst:
50
- case SILInstructionKind::SwitchEnumInst:
51
- case SILInstructionKind::CheckedCastBranchInst:
52
- case SILInstructionKind::DestructureStructInst:
53
- case SILInstructionKind::DestructureTupleInst:
54
- case SILInstructionKind::MarkDependenceInst:
55
- case SILInstructionKind::InitExistentialRefInst:
56
- return true ;
57
- default :
58
- return false ;
59
- }
60
- }
61
-
62
- // These operations forward guaranteed ownership, but don't necessarily forward
63
- // owned values.
64
- static bool isGuaranteedForwardingInstructionKind (SILInstructionKind kind) {
65
- switch (kind) {
66
- case SILInstructionKind::TupleExtractInst:
67
- case SILInstructionKind::StructExtractInst:
68
- case SILInstructionKind::DifferentiableFunctionExtractInst:
69
- case SILInstructionKind::LinearFunctionExtractInst:
70
- case SILInstructionKind::OpenExistentialValueInst:
71
- case SILInstructionKind::OpenExistentialBoxValueInst:
72
- return true ;
73
- default :
74
- return isOwnershipForwardingInstructionKind (kind);
75
- }
76
- }
77
-
78
32
bool swift::canOpcodeForwardGuaranteedValues (SILValue value) {
79
33
// If we have an argument from a transforming terminator, we can forward
80
34
// guaranteed.
81
35
if (auto *arg = dyn_cast<SILArgument>(value))
82
36
if (auto *ti = arg->getSingleTerminator ())
83
- if (ti->isTransformationTerminator ()) {
84
- assert (OwnershipForwardingMixin::isa (ti));
85
- return true ;
86
- }
37
+ if (ti->isTransformationTerminator ())
38
+ return OwnershipForwardingMixin::get (ti)->isDirectlyForwarding ();
87
39
88
- auto *inst = value->getDefiningInstruction ();
89
- if (!inst)
90
- return false ;
40
+ if (auto *inst = value->getDefiningInstruction ())
41
+ if (auto *mixin = OwnershipForwardingMixin::get (inst))
42
+ return mixin->isDirectlyForwarding () &&
43
+ !isa<OwnedFirstArgForwardingSingleValueInst>(inst);
91
44
92
- bool result = isGuaranteedForwardingInstructionKind (inst->getKind ());
93
- if (result) {
94
- assert (!isa<OwnedFirstArgForwardingSingleValueInst>(inst));
95
- assert (OwnershipForwardingMixin::isa (inst));
96
- }
97
- return result;
45
+ return false ;
98
46
}
99
47
100
48
bool swift::canOpcodeForwardGuaranteedValues (Operand *use) {
101
- auto *user = use->getUser ();
102
- bool result = isOwnershipForwardingInstructionKind (user->getKind ());
103
- if (result) {
104
- assert (!isa<GuaranteedFirstArgForwardingSingleValueInst>(user));
105
- assert (OwnershipForwardingMixin::isa (user));
106
- }
107
- return result;
108
- }
109
-
110
- static bool isOwnedForwardingValueKind (SILInstructionKind kind) {
111
- switch (kind) {
112
- case SILInstructionKind::MarkUninitializedInst:
113
- return true ;
114
- default :
115
- return isOwnershipForwardingInstructionKind (kind);
116
- }
49
+ if (auto *mixin = OwnershipForwardingMixin::get (use->getUser ()))
50
+ return mixin->isDirectlyForwarding () &&
51
+ !isa<OwnedFirstArgForwardingSingleValueInst>(use->getUser ());
52
+ return false ;
117
53
}
118
54
119
55
bool swift::canOpcodeForwardOwnedValues (SILValue value) {
120
56
// If we have a SILArgument and we are the successor block of a transforming
121
57
// terminator, we are fine.
122
58
if (auto *arg = dyn_cast<SILPhiArgument>(value))
123
59
if (auto *predTerm = arg->getSingleTerminator ())
124
- if (predTerm->isTransformationTerminator ()) {
125
- assert (OwnershipForwardingMixin::isa (predTerm));
126
- return true ;
127
- }
128
- auto *inst = value->getDefiningInstruction ();
129
- if (!inst)
130
- return false ;
60
+ if (predTerm->isTransformationTerminator ())
61
+ return OwnershipForwardingMixin::get (predTerm)->isDirectlyForwarding ();
131
62
132
- bool result = isOwnedForwardingValueKind (inst-> getKind ());
133
- if (result) {
134
- assert (!isa<GuaranteedFirstArgForwardingSingleValueInst>(inst));
135
- assert ( OwnershipForwardingMixin:: isa (inst) );
136
- }
137
- return result ;
63
+ if ( auto *inst = value-> getDefiningInstruction ())
64
+ if (auto *mixin = OwnershipForwardingMixin::get (inst))
65
+ return mixin-> isDirectlyForwarding () &&
66
+ ! isa<GuaranteedFirstArgForwardingSingleValueInst> (inst);
67
+
68
+ return false ;
138
69
}
139
70
140
71
bool swift::canOpcodeForwardOwnedValues (Operand *use) {
141
72
auto *user = use->getUser ();
142
- bool result = isOwnershipForwardingInstructionKind (user->getKind ());
143
- if (result) {
144
- assert (OwnershipForwardingMixin::isa (user));
145
- }
146
- return result;
73
+ if (auto *mixin = OwnershipForwardingMixin::get (user))
74
+ return mixin->isDirectlyForwarding () &&
75
+ !isa<GuaranteedFirstArgForwardingSingleValueInst>(user);
76
+ return false ;
147
77
}
148
78
149
79
// ===----------------------------------------------------------------------===//
@@ -980,7 +910,8 @@ bool swift::getAllBorrowIntroducingValues(SILValue inputValue,
980
910
// predecessor terminator.
981
911
auto *arg = cast<SILPhiArgument>(value);
982
912
auto *termInst = arg->getSingleTerminator ();
983
- assert (termInst && termInst->isTransformationTerminator ());
913
+ assert (termInst && termInst->isTransformationTerminator () &&
914
+ OwnershipForwardingMixin::get (termInst)->isDirectlyForwarding ());
984
915
assert (termInst->getNumOperands () == 1 &&
985
916
" Transforming terminators should always have a single operand" );
986
917
worklist.push_back (termInst->getAllOperands ()[0 ].get ());
@@ -1031,7 +962,8 @@ BorrowedValue swift::getSingleBorrowIntroducingValue(SILValue inputValue) {
1031
962
// predecessor terminator.
1032
963
auto *arg = cast<SILPhiArgument>(currentValue);
1033
964
auto *termInst = arg->getSingleTerminator ();
1034
- assert (termInst && termInst->isTransformationTerminator ());
965
+ assert (termInst && termInst->isTransformationTerminator () &&
966
+ OwnershipForwardingMixin::get (termInst)->isDirectlyForwarding ());
1035
967
assert (termInst->getNumOperands () == 1 &&
1036
968
" Transformation terminators should only have single operands" );
1037
969
currentValue = termInst->getAllOperands ()[0 ].get ();
@@ -1083,7 +1015,8 @@ bool swift::getAllOwnedValueIntroducers(
1083
1015
// predecessor terminator.
1084
1016
auto *arg = cast<SILPhiArgument>(value);
1085
1017
auto *termInst = arg->getSingleTerminator ();
1086
- assert (termInst && termInst->isTransformationTerminator ());
1018
+ assert (termInst && termInst->isTransformationTerminator () &&
1019
+ OwnershipForwardingMixin::get (termInst)->isDirectlyForwarding ());
1087
1020
assert (termInst->getNumOperands () == 1 &&
1088
1021
" Transforming terminators should always have a single operand" );
1089
1022
worklist.push_back (termInst->getAllOperands ()[0 ].get ());
@@ -1127,10 +1060,11 @@ OwnedValueIntroducer swift::getSingleOwnedValueIntroducer(SILValue inputValue) {
1127
1060
}
1128
1061
1129
1062
// Otherwise, we should have a block argument that is defined by a single
1130
- // predecessor terminator.
1063
+ // predecessor terminator and is directly forwarding .
1131
1064
auto *arg = cast<SILPhiArgument>(currentValue);
1132
1065
auto *termInst = arg->getSingleTerminator ();
1133
- assert (termInst && termInst->isTransformationTerminator ());
1066
+ assert (termInst && termInst->isTransformationTerminator () &&
1067
+ OwnershipForwardingMixin::get (termInst)->isDirectlyForwarding ());
1134
1068
assert (termInst->getNumOperands ()
1135
1069
- termInst->getNumTypeDependentOperands () == 1 &&
1136
1070
" Transformation terminators should only have single operands" );
0 commit comments