@@ -177,6 +177,45 @@ struct UseDefChainVisitor
177
177
178
178
} // namespace
179
179
180
+ // / Classify an instructions as look through when we are looking through
181
+ // / values. We assert that all instructions that are CONSTANT_TRANSLATION
182
+ // / LookThrough to make sure they stay in sync.
183
+ static bool isStaticallyLookThroughInst (SILInstruction *inst) {
184
+ switch (inst->getKind ()) {
185
+ default :
186
+ return false ;
187
+ case SILInstructionKind::BeginAccessInst:
188
+ case SILInstructionKind::BeginBorrowInst:
189
+ case SILInstructionKind::BeginDeallocRefInst:
190
+ case SILInstructionKind::BridgeObjectToRefInst:
191
+ case SILInstructionKind::CopyValueInst:
192
+ case SILInstructionKind::CopyableToMoveOnlyWrapperAddrInst:
193
+ case SILInstructionKind::CopyableToMoveOnlyWrapperValueInst:
194
+ case SILInstructionKind::DestructureStructInst:
195
+ case SILInstructionKind::DestructureTupleInst:
196
+ case SILInstructionKind::EndCOWMutationInst:
197
+ case SILInstructionKind::EndInitLetRefInst:
198
+ case SILInstructionKind::ExplicitCopyValueInst:
199
+ case SILInstructionKind::InitEnumDataAddrInst:
200
+ case SILInstructionKind::MarkDependenceInst:
201
+ case SILInstructionKind::MarkUninitializedInst:
202
+ case SILInstructionKind::MarkUnresolvedNonCopyableValueInst:
203
+ case SILInstructionKind::MarkUnresolvedReferenceBindingInst:
204
+ case SILInstructionKind::MoveOnlyWrapperToCopyableAddrInst:
205
+ case SILInstructionKind::MoveOnlyWrapperToCopyableBoxInst:
206
+ case SILInstructionKind::MoveOnlyWrapperToCopyableValueInst:
207
+ case SILInstructionKind::MoveValueInst:
208
+ case SILInstructionKind::OpenExistentialAddrInst:
209
+ case SILInstructionKind::ProjectBlockStorageInst:
210
+ case SILInstructionKind::ProjectBoxInst:
211
+ case SILInstructionKind::RefToBridgeObjectInst:
212
+ case SILInstructionKind::UncheckedRefCastInst:
213
+ case SILInstructionKind::UncheckedTakeEnumDataAddrInst:
214
+ case SILInstructionKind::UpcastInst:
215
+ return true ;
216
+ }
217
+ }
218
+
180
219
static SILValue getUnderlyingTrackedObjectValue (SILValue value) {
181
220
auto *fn = value->getFunction ();
182
221
SILValue result = value;
@@ -189,14 +228,16 @@ static SILValue getUnderlyingTrackedObjectValue(SILValue value) {
189
228
temp = lookThroughOwnershipInsts (temp);
190
229
191
230
if (auto *svi = dyn_cast<SingleValueInstruction>(temp)) {
192
- if (isa<ExplicitCopyValueInst, CopyableToMoveOnlyWrapperValueInst,
193
- MoveOnlyWrapperToCopyableValueInst,
194
- MoveOnlyWrapperToCopyableBoxInst, BeginAccessInst,
195
- MarkDependenceInst>(svi) ||
196
- isIdentityPreservingRefCast (svi)) {
231
+ if (isStaticallyLookThroughInst (svi)) {
197
232
temp = svi->getOperand (0 );
198
233
}
199
234
235
+ if (auto cast = SILDynamicCastInst::getAs (svi)) {
236
+ if (cast.isRCIdentityPreserving ()) {
237
+ temp = svi->getOperand (0 );
238
+ }
239
+ }
240
+
200
241
// If we have a cast and our operand and result are non-Sendable, treat it
201
242
// as a look through.
202
243
if (isa<UncheckedTrivialBitCastInst, UncheckedBitwiseCastInst,
@@ -223,13 +264,10 @@ static SILValue getUnderlyingTrackedObjectValue(SILValue value) {
223
264
}
224
265
}
225
266
226
- if (auto *dsi = dyn_cast_or_null<DestructureStructInst>(
227
- temp->getDefiningInstruction ())) {
228
- temp = dsi->getOperand ();
229
- }
230
- if (auto *dti = dyn_cast_or_null<DestructureTupleInst>(
231
- temp->getDefiningInstruction ())) {
232
- temp = dti->getOperand ();
267
+ if (auto *inst = temp->getDefiningInstruction ()) {
268
+ if (isStaticallyLookThroughInst (inst)) {
269
+ temp = inst->getOperand (0 );
270
+ }
233
271
}
234
272
235
273
if (temp != result) {
@@ -1895,6 +1933,12 @@ void PartitionOpBuilder::print(llvm::raw_ostream &os) const {
1895
1933
1896
1934
#define CONSTANT_TRANSLATION (INST, Kind ) \
1897
1935
TranslationSemantics PartitionOpTranslator::visit##INST(INST *inst) { \
1936
+ assert ((TranslationSemantics::Kind != TranslationSemantics::LookThrough || \
1937
+ isStaticallyLookThroughInst (inst)) && \
1938
+ " Out of sync?!" ); \
1939
+ assert ((TranslationSemantics::Kind == TranslationSemantics::LookThrough || \
1940
+ !isStaticallyLookThroughInst (inst)) && \
1941
+ " Out of sync?!" ); \
1898
1942
return TranslationSemantics::Kind; \
1899
1943
}
1900
1944
@@ -2297,7 +2341,7 @@ PartitionOpTranslator::visitRefToRawPointerInst(RefToRawPointerInst *r) {
2297
2341
2298
2342
TranslationSemantics
2299
2343
PartitionOpTranslator::visitMarkDependenceInst (MarkDependenceInst *mdi) {
2300
- translateSILAssign (mdi, mdi->getValue ());
2344
+ translateSILLookThrough (mdi-> getResults () , mdi->getValue ());
2301
2345
translateSILRequire (mdi->getBase ());
2302
2346
return TranslationSemantics::Special;
2303
2347
}
0 commit comments