@@ -183,15 +183,12 @@ struct UseDefChainVisitor
183183// / values. We assert that all instructions that are CONSTANT_TRANSLATION
184184// / LookThrough to make sure they stay in sync.
185185static bool isStaticallyLookThroughInst (SILInstruction *inst) {
186- if (auto cast = SILDynamicCastInst::getAs (inst))
187- if (cast.isRCIdentityPreserving ())
188- return true ;
189-
190186 switch (inst->getKind ()) {
191187 default :
192188 return false ;
193189 case SILInstructionKind::BeginAccessInst:
194190 case SILInstructionKind::BeginBorrowInst:
191+ case SILInstructionKind::BeginCOWMutationInst:
195192 case SILInstructionKind::BeginDeallocRefInst:
196193 case SILInstructionKind::BridgeObjectToRefInst:
197194 case SILInstructionKind::CopyValueInst:
@@ -224,6 +221,13 @@ static bool isStaticallyLookThroughInst(SILInstruction *inst) {
224221 case SILInstructionKind::UpcastInst:
225222 case SILInstructionKind::ValueToBridgeObjectInst:
226223 return true ;
224+ case SILInstructionKind::UnconditionalCheckedCastInst: {
225+ auto cast = SILDynamicCastInst::getAs (inst);
226+ assert (cast);
227+ if (cast.isRCIdentityPreserving ())
228+ return true ;
229+ return false ;
230+ }
227231 }
228232}
229233
@@ -2306,6 +2310,7 @@ CONSTANT_TRANSLATION(UnownedToRefInst, LookThrough)
23062310CONSTANT_TRANSLATION(UnownedCopyValueInst, LookThrough)
23072311CONSTANT_TRANSLATION(DropDeinitInst, LookThrough)
23082312CONSTANT_TRANSLATION(ValueToBridgeObjectInst, LookThrough)
2313+ CONSTANT_TRANSLATION(BeginCOWMutationInst, LookThrough)
23092314
23102315// ===---
23112316// Store
@@ -2321,6 +2326,9 @@ CONSTANT_TRANSLATION(StoreInst, Store)
23212326CONSTANT_TRANSLATION(StoreBorrowInst, Store)
23222327CONSTANT_TRANSLATION(StoreWeakInst, Store)
23232328CONSTANT_TRANSLATION(MarkUnresolvedMoveAddrInst, Store)
2329+ CONSTANT_TRANSLATION(UncheckedRefCastAddrInst, Store)
2330+ CONSTANT_TRANSLATION(UnconditionalCheckedCastAddrInst, Store)
2331+ CONSTANT_TRANSLATION(StoreUnownedInst, Store)
23242332
23252333// ===---
23262334// Ignored
@@ -2332,8 +2340,13 @@ CONSTANT_TRANSLATION(MarkUnresolvedMoveAddrInst, Store)
23322340CONSTANT_TRANSLATION(AllocGlobalInst, Ignored)
23332341CONSTANT_TRANSLATION(AutoreleaseValueInst, Ignored)
23342342CONSTANT_TRANSLATION(DeallocBoxInst, Ignored)
2343+ CONSTANT_TRANSLATION(DeallocPartialRefInst, Ignored)
2344+ CONSTANT_TRANSLATION(DeallocRefInst, Ignored)
23352345CONSTANT_TRANSLATION(DeallocStackInst, Ignored)
2346+ CONSTANT_TRANSLATION(DeallocStackRefInst, Ignored)
23362347CONSTANT_TRANSLATION(DebugValueInst, Ignored)
2348+ CONSTANT_TRANSLATION(DeinitExistentialAddrInst, Ignored)
2349+ CONSTANT_TRANSLATION(DeinitExistentialValueInst, Ignored)
23372350CONSTANT_TRANSLATION(DestroyAddrInst, Ignored)
23382351CONSTANT_TRANSLATION(DestroyValueInst, Ignored)
23392352CONSTANT_TRANSLATION(EndAccessInst, Ignored)
@@ -2346,6 +2359,8 @@ CONSTANT_TRANSLATION(MetatypeInst, Ignored)
23462359CONSTANT_TRANSLATION(EndApplyInst, Ignored)
23472360CONSTANT_TRANSLATION(AbortApplyInst, Ignored)
23482361CONSTANT_TRANSLATION(DebugStepInst, Ignored)
2362+ CONSTANT_TRANSLATION(IncrementProfilerCounterInst, Ignored)
2363+ CONSTANT_TRANSLATION(TestSpecificationInst, Ignored)
23492364
23502365// ===---
23512366// Require
@@ -2410,7 +2425,6 @@ CONSTANT_TRANSLATION(VectorInst, Unhandled)
24102425CONSTANT_TRANSLATION(TuplePackElementAddrInst, Unhandled)
24112426CONSTANT_TRANSLATION(TuplePackExtractInst, Unhandled)
24122427CONSTANT_TRANSLATION(PackElementGetInst, Unhandled)
2413- CONSTANT_TRANSLATION(RefTailAddrInst, Unhandled)
24142428CONSTANT_TRANSLATION(InitExistentialValueInst, Unhandled)
24152429CONSTANT_TRANSLATION(InitExistentialMetatypeInst, Unhandled)
24162430CONSTANT_TRANSLATION(OpenExistentialMetatypeInst, Unhandled)
@@ -2433,9 +2447,6 @@ CONSTANT_TRANSLATION(RebindMemoryInst, Unhandled)
24332447CONSTANT_TRANSLATION(ThrowAddrInst, Unhandled)
24342448CONSTANT_TRANSLATION(AwaitAsyncContinuationInst, Unhandled)
24352449CONSTANT_TRANSLATION(DeallocPackInst, Unhandled)
2436- CONSTANT_TRANSLATION(DeallocStackRefInst, Unhandled)
2437- CONSTANT_TRANSLATION(DeallocRefInst, Unhandled)
2438- CONSTANT_TRANSLATION(DeallocPartialRefInst, Unhandled)
24392450CONSTANT_TRANSLATION(UnmanagedRetainValueInst, Unhandled)
24402451CONSTANT_TRANSLATION(UnmanagedReleaseValueInst, Unhandled)
24412452CONSTANT_TRANSLATION(UnmanagedAutoreleaseValueInst, Unhandled)
@@ -2445,15 +2456,7 @@ CONSTANT_TRANSLATION(AssignInst, Unhandled)
24452456CONSTANT_TRANSLATION(AssignByWrapperInst, Unhandled)
24462457CONSTANT_TRANSLATION(AssignOrInitInst, Unhandled)
24472458CONSTANT_TRANSLATION(MarkFunctionEscapeInst, Unhandled)
2448- CONSTANT_TRANSLATION(TestSpecificationInst, Unhandled)
2449- CONSTANT_TRANSLATION(StoreUnownedInst, Unhandled)
2450- CONSTANT_TRANSLATION(DeinitExistentialAddrInst, Unhandled)
2451- CONSTANT_TRANSLATION(DeinitExistentialValueInst, Unhandled)
2452- CONSTANT_TRANSLATION(UnconditionalCheckedCastAddrInst, Unhandled)
2453- CONSTANT_TRANSLATION(UncheckedRefCastAddrInst, Unhandled)
24542459CONSTANT_TRANSLATION(PackElementSetInst, Unhandled)
2455- CONSTANT_TRANSLATION(IncrementProfilerCounterInst, Unhandled)
2456- CONSTANT_TRANSLATION(BeginCOWMutationInst, Unhandled)
24572460
24582461// ===---
24592462// Apply
@@ -2628,12 +2631,42 @@ TranslationSemantics PartitionOpTranslator::visitUnconditionalCheckedCastInst(
26282631// ref_element_addr to be merged into.
26292632TranslationSemantics
26302633PartitionOpTranslator::visitRefElementAddrInst (RefElementAddrInst *reai) {
2631- // If we are accessing a let of a Sendable type, do not treat the
2632- // ref_element_addr as a require use.
2633- if (reai->getField ()->isLet () && !isNonSendableType (reai->getType ())) {
2634- LLVM_DEBUG (llvm::dbgs () << " Found a let! Not tracking!\n " );
2635- return TranslationSemantics::Ignored;
2634+ // If our field is a NonSendableType...
2635+ if (!isNonSendableType (reai->getType ())) {
2636+ // And the field is a let... then ignore it. We know that we cannot race on
2637+ // any writes to the field.
2638+ if (reai->getField ()->isLet ()) {
2639+ LLVM_DEBUG (llvm::dbgs () << " Found a let! Not tracking!\n " );
2640+ return TranslationSemantics::Ignored;
2641+ }
2642+
2643+ // Otherwise, we need to treat the access to the field as a require since we
2644+ // could have a race on assignment to the class.
2645+ return TranslationSemantics::Require;
26362646 }
2647+
2648+ return TranslationSemantics::Assign;
2649+ }
2650+
2651+ TranslationSemantics
2652+ PartitionOpTranslator::visitRefTailAddrInst (RefTailAddrInst *reai) {
2653+ // If our trailing type is Sendable...
2654+ if (!isNonSendableType (reai->getType ())) {
2655+ // And our ref_tail_addr is immutable... we can ignore the access since we
2656+ // cannot race against a write to any of these fields.
2657+ if (reai->isImmutable ()) {
2658+ LLVM_DEBUG (
2659+ llvm::dbgs ()
2660+ << " Found an immutable Sendable ref_tail_addr! Not tracking!\n " );
2661+ return TranslationSemantics::Ignored;
2662+ }
2663+
2664+ // Otherwise, we need a require since the value maybe alive.
2665+ return TranslationSemantics::Require;
2666+ }
2667+
2668+ // If we have a NonSendable type, treat the address as a separate Element from
2669+ // our base value.
26372670 return TranslationSemantics::Assign;
26382671}
26392672
0 commit comments