Skip to content

Commit c89f63f

Browse files
authored
Merge pull request #71233 from gottesmm/transfernonsendable-more-insts
[region-isolation] Add support for more instructions
2 parents 6d8f6fc + 5323a65 commit c89f63f

File tree

4 files changed

+416
-51
lines changed

4 files changed

+416
-51
lines changed

include/swift/SIL/SILInstruction.h

Lines changed: 55 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7983,12 +7983,20 @@ class PackElementGetInst final
79837983
SILType elementType);
79847984

79857985
public:
7986-
SILValue getIndex() const {
7987-
return getAllOperands()[IndexOperand].get();
7986+
SILValue getIndex() const { return getIndexOperand()->get(); }
7987+
7988+
Operand *getIndexOperand() { return &getAllOperands()[IndexOperand]; }
7989+
7990+
const Operand *getIndexOperand() const {
7991+
return &getAllOperands()[IndexOperand];
79887992
}
79897993

7990-
SILValue getPack() const {
7991-
return getAllOperands()[PackOperand].get();
7994+
SILValue getPack() const { return getPackOperand()->get(); }
7995+
7996+
Operand *getPackOperand() { return &getAllOperands()[PackOperand]; }
7997+
7998+
const Operand *getPackOperand() const {
7999+
return &getAllOperands()[PackOperand];
79928000
}
79938001

79948002
CanSILPackType getPackType() const {
@@ -8028,18 +8036,29 @@ class PackElementSetInst
80288036
ArrayRef<Operand> getAllOperands() const { return Operands.asArray(); }
80298037
MutableArrayRef<Operand> getAllOperands() { return Operands.asArray(); }
80308038

8031-
SILValue getValue() const {
8032-
return getAllOperands()[ValueOperand].get();
8039+
SILValue getValue() const { return getValueOperand()->get(); }
8040+
8041+
const Operand *getValueOperand() const {
8042+
return &getAllOperands()[ValueOperand];
80338043
}
80348044

8035-
SILValue getIndex() const {
8036-
return getAllOperands()[IndexOperand].get();
8045+
Operand *getValueOperand() { return &getAllOperands()[ValueOperand]; }
8046+
8047+
SILValue getIndex() const { return getIndexOperand()->get(); }
8048+
8049+
const Operand *getIndexOperand() const {
8050+
return &getAllOperands()[IndexOperand];
80378051
}
8052+
Operand *getIndexOperand() { return &getAllOperands()[IndexOperand]; }
8053+
8054+
SILValue getPack() const { return getPackOperand()->get(); }
80388055

8039-
SILValue getPack() const {
8040-
return getAllOperands()[PackOperand].get();
8056+
const Operand *getPackOperand() const {
8057+
return &getAllOperands()[PackOperand];
80418058
}
80428059

8060+
Operand *getPackOperand() { return &getAllOperands()[PackOperand]; }
8061+
80438062
CanSILPackType getPackType() const {
80448063
return getPack()->getType().castTo<SILPackType>();
80458064
}
@@ -8079,12 +8098,20 @@ class TuplePackElementAddrInst final
80798098
SILType elementType);
80808099

80818100
public:
8082-
SILValue getIndex() const {
8083-
return getAllOperands()[IndexOperand].get();
8101+
SILValue getIndex() const { return getIndexOperand()->get(); }
8102+
8103+
Operand *getIndexOperand() { return &getAllOperands()[IndexOperand]; }
8104+
8105+
const Operand *getIndexOperand() const {
8106+
return &getAllOperands()[IndexOperand];
80848107
}
80858108

8086-
SILValue getTuple() const {
8087-
return getAllOperands()[TupleOperand].get();
8109+
SILValue getTuple() const { return getTupleOperand()->get(); }
8110+
8111+
Operand *getTupleOperand() { return &getAllOperands()[TupleOperand]; }
8112+
8113+
const Operand *getTupleOperand() const {
8114+
return &getAllOperands()[TupleOperand];
80888115
}
80898116

80908117
CanTupleType getTupleType() const {
@@ -8124,9 +8151,21 @@ class TuplePackExtractInst final
81248151
ValueOwnershipKind forwardingOwnershipKind);
81258152

81268153
public:
8127-
SILValue getIndex() const { return getAllOperands()[IndexOperand].get(); }
8154+
SILValue getIndex() const { return getIndexOperand()->get(); }
81288155

8129-
SILValue getTuple() const { return getAllOperands()[TupleOperand].get(); }
8156+
Operand *getIndexOperand() { return &getAllOperands()[IndexOperand]; }
8157+
8158+
const Operand *getIndexOperand() const {
8159+
return &getAllOperands()[IndexOperand];
8160+
}
8161+
8162+
SILValue getTuple() const { return getTupleOperand()->get(); }
8163+
8164+
Operand *getTupleOperand() { return &getAllOperands()[TupleOperand]; }
8165+
8166+
const Operand *getTupleOperand() const {
8167+
return &getAllOperands()[TupleOperand];
8168+
}
81308169

81318170
CanTupleType getTupleType() const {
81328171
return getTuple()->getType().castTo<TupleType>();

lib/SILOptimizer/Analysis/RegionAnalysis.cpp

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
185185
static 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)
23062310
CONSTANT_TRANSLATION(UnownedCopyValueInst, LookThrough)
23072311
CONSTANT_TRANSLATION(DropDeinitInst, LookThrough)
23082312
CONSTANT_TRANSLATION(ValueToBridgeObjectInst, LookThrough)
2313+
CONSTANT_TRANSLATION(BeginCOWMutationInst, LookThrough)
23092314

23102315
//===---
23112316
// Store
@@ -2321,6 +2326,9 @@ CONSTANT_TRANSLATION(StoreInst, Store)
23212326
CONSTANT_TRANSLATION(StoreBorrowInst, Store)
23222327
CONSTANT_TRANSLATION(StoreWeakInst, Store)
23232328
CONSTANT_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)
23322340
CONSTANT_TRANSLATION(AllocGlobalInst, Ignored)
23332341
CONSTANT_TRANSLATION(AutoreleaseValueInst, Ignored)
23342342
CONSTANT_TRANSLATION(DeallocBoxInst, Ignored)
2343+
CONSTANT_TRANSLATION(DeallocPartialRefInst, Ignored)
2344+
CONSTANT_TRANSLATION(DeallocRefInst, Ignored)
23352345
CONSTANT_TRANSLATION(DeallocStackInst, Ignored)
2346+
CONSTANT_TRANSLATION(DeallocStackRefInst, Ignored)
23362347
CONSTANT_TRANSLATION(DebugValueInst, Ignored)
2348+
CONSTANT_TRANSLATION(DeinitExistentialAddrInst, Ignored)
2349+
CONSTANT_TRANSLATION(DeinitExistentialValueInst, Ignored)
23372350
CONSTANT_TRANSLATION(DestroyAddrInst, Ignored)
23382351
CONSTANT_TRANSLATION(DestroyValueInst, Ignored)
23392352
CONSTANT_TRANSLATION(EndAccessInst, Ignored)
@@ -2346,6 +2359,8 @@ CONSTANT_TRANSLATION(MetatypeInst, Ignored)
23462359
CONSTANT_TRANSLATION(EndApplyInst, Ignored)
23472360
CONSTANT_TRANSLATION(AbortApplyInst, Ignored)
23482361
CONSTANT_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)
24102425
CONSTANT_TRANSLATION(TuplePackElementAddrInst, Unhandled)
24112426
CONSTANT_TRANSLATION(TuplePackExtractInst, Unhandled)
24122427
CONSTANT_TRANSLATION(PackElementGetInst, Unhandled)
2413-
CONSTANT_TRANSLATION(RefTailAddrInst, Unhandled)
24142428
CONSTANT_TRANSLATION(InitExistentialValueInst, Unhandled)
24152429
CONSTANT_TRANSLATION(InitExistentialMetatypeInst, Unhandled)
24162430
CONSTANT_TRANSLATION(OpenExistentialMetatypeInst, Unhandled)
@@ -2433,9 +2447,6 @@ CONSTANT_TRANSLATION(RebindMemoryInst, Unhandled)
24332447
CONSTANT_TRANSLATION(ThrowAddrInst, Unhandled)
24342448
CONSTANT_TRANSLATION(AwaitAsyncContinuationInst, Unhandled)
24352449
CONSTANT_TRANSLATION(DeallocPackInst, Unhandled)
2436-
CONSTANT_TRANSLATION(DeallocStackRefInst, Unhandled)
2437-
CONSTANT_TRANSLATION(DeallocRefInst, Unhandled)
2438-
CONSTANT_TRANSLATION(DeallocPartialRefInst, Unhandled)
24392450
CONSTANT_TRANSLATION(UnmanagedRetainValueInst, Unhandled)
24402451
CONSTANT_TRANSLATION(UnmanagedReleaseValueInst, Unhandled)
24412452
CONSTANT_TRANSLATION(UnmanagedAutoreleaseValueInst, Unhandled)
@@ -2445,15 +2456,7 @@ CONSTANT_TRANSLATION(AssignInst, Unhandled)
24452456
CONSTANT_TRANSLATION(AssignByWrapperInst, Unhandled)
24462457
CONSTANT_TRANSLATION(AssignOrInitInst, Unhandled)
24472458
CONSTANT_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)
24542459
CONSTANT_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.
26292632
TranslationSemantics
26302633
PartitionOpTranslator::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

Comments
 (0)