22
22
23
23
using namespace swift ;
24
24
25
+ SILValue swift::stripOwnershipInsts (SILValue v) {
26
+ while (true ) {
27
+ switch (v->getKind ()) {
28
+ default :
29
+ return v;
30
+ case ValueKind::CopyValueInst:
31
+ case ValueKind::BeginBorrowInst:
32
+ v = cast<SingleValueInstruction>(v)->getOperand (0 );
33
+ }
34
+ }
35
+ }
36
+
25
37
// / Strip off casts/indexing insts/address projections from V until there is
26
38
// / nothing left to strip.
27
39
// / FIXME: Why don't we strip projections after stripping indexes?
28
- SILValue swift::getUnderlyingObject (SILValue V ) {
40
+ SILValue swift::getUnderlyingObject (SILValue v ) {
29
41
while (true ) {
30
- SILValue V2 = stripIndexingInsts (stripAddressProjections (stripCasts (V)));
31
- if (V2 == V)
32
- return V2;
33
- V = V2;
42
+ SILValue v2 = stripCasts (v);
43
+ v2 = stripAddressProjections (v2);
44
+ v2 = stripIndexingInsts (v2);
45
+ v2 = stripOwnershipInsts (v2);
46
+ if (v2 == v)
47
+ return v2;
48
+ v = v2;
34
49
}
35
50
}
36
51
@@ -56,12 +71,15 @@ SILValue swift::getUnderlyingAddressRoot(SILValue V) {
56
71
}
57
72
58
73
59
- SILValue swift::getUnderlyingObjectStopAtMarkDependence (SILValue V ) {
74
+ SILValue swift::getUnderlyingObjectStopAtMarkDependence (SILValue v ) {
60
75
while (true ) {
61
- SILValue V2 = stripIndexingInsts (stripAddressProjections (stripCastsWithoutMarkDependence (V)));
62
- if (V2 == V)
63
- return V2;
64
- V = V2;
76
+ SILValue v2 = stripCastsWithoutMarkDependence (v);
77
+ v2 = stripAddressProjections (v2);
78
+ v2 = stripIndexingInsts (v2);
79
+ v2 = stripOwnershipInsts (v2);
80
+ if (v2 == v)
81
+ return v2;
82
+ v = v2;
65
83
}
66
84
}
67
85
@@ -138,47 +156,68 @@ SILValue swift::stripCastsWithoutMarkDependence(SILValue V) {
138
156
}
139
157
}
140
158
141
- SILValue swift::stripCasts (SILValue V ) {
159
+ SILValue swift::stripCasts (SILValue v ) {
142
160
while (true ) {
143
- V = stripSinglePredecessorArgs (V );
161
+ v = stripSinglePredecessorArgs (v );
144
162
145
- auto K = V ->getKind ();
146
- if (isRCIdentityPreservingCast (K )
147
- || K == ValueKind::UncheckedTrivialBitCastInst
148
- || K == ValueKind::MarkDependenceInst) {
149
- V = cast<SingleValueInstruction>(V )->getOperand (0 );
163
+ auto k = v ->getKind ();
164
+ if (isRCIdentityPreservingCast (k )
165
+ || k == ValueKind::UncheckedTrivialBitCastInst
166
+ || k == ValueKind::MarkDependenceInst) {
167
+ v = cast<SingleValueInstruction>(v )->getOperand (0 );
150
168
continue ;
151
169
}
152
-
153
- return V;
170
+
171
+ SILValue v2 = stripOwnershipInsts (v);
172
+ if (v2 != v) {
173
+ v = v2;
174
+ continue ;
175
+ }
176
+
177
+ return v;
154
178
}
155
179
}
156
180
157
- SILValue swift::stripUpCasts (SILValue V ) {
158
- assert (V ->getType ().isClassOrClassMetatype () &&
181
+ SILValue swift::stripUpCasts (SILValue v ) {
182
+ assert (v ->getType ().isClassOrClassMetatype () &&
159
183
" Expected class or class metatype!" );
160
184
161
- V = stripSinglePredecessorArgs (V);
162
-
163
- while (auto upcast = dyn_cast<UpcastInst>(V))
164
- V = stripSinglePredecessorArgs (upcast->getOperand ());
185
+ v = stripSinglePredecessorArgs (v);
165
186
166
- return V;
187
+ while (true ) {
188
+ if (auto *ui = dyn_cast<UpcastInst>(v)) {
189
+ v = ui->getOperand ();
190
+ continue ;
191
+ }
192
+
193
+ SILValue v2 = stripSinglePredecessorArgs (v);
194
+ v2 = stripOwnershipInsts (v2);
195
+ if (v2 == v) {
196
+ return v2;
197
+ }
198
+ v = v2;
199
+ }
167
200
}
168
201
169
- SILValue swift::stripClassCasts (SILValue V ) {
202
+ SILValue swift::stripClassCasts (SILValue v ) {
170
203
while (true ) {
171
- if (auto *UI = dyn_cast<UpcastInst>(V )) {
172
- V = UI ->getOperand ();
204
+ if (auto *ui = dyn_cast<UpcastInst>(v )) {
205
+ v = ui ->getOperand ();
173
206
continue ;
174
207
}
175
208
176
- if (auto *UCCI = dyn_cast<UnconditionalCheckedCastInst>(V )) {
177
- V = UCCI ->getOperand ();
209
+ if (auto *ucci = dyn_cast<UnconditionalCheckedCastInst>(v )) {
210
+ v = ucci ->getOperand ();
178
211
continue ;
179
212
}
180
-
181
- return V;
213
+
214
+ SILValue v2 = stripOwnershipInsts (v);
215
+ if (v2 != v) {
216
+ v = v2;
217
+ continue ;
218
+ }
219
+
220
+ return v;
182
221
}
183
222
}
184
223
0 commit comments