Skip to content

Commit d08359e

Browse files
committed
[region-isolation] Add support for ref_to_raw_pointer, raw_pointer_to_ref, index_raw_pointer.
1 parent c90097f commit d08359e

File tree

2 files changed

+176
-38
lines changed

2 files changed

+176
-38
lines changed

lib/SILOptimizer/Mandatory/TransferNonSendable.cpp

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ struct UseDefChainVisitor
194194
} // namespace
195195

196196
static SILValue getUnderlyingTrackedObjectValue(SILValue value) {
197+
auto *fn = value->getFunction();
197198
SILValue result = value;
198199
while (true) {
199200
SILValue temp = result;
@@ -208,6 +209,21 @@ static SILValue getUnderlyingTrackedObjectValue(SILValue value) {
208209
}
209210
}
210211

212+
if (auto *r = dyn_cast<RefToRawPointerInst>(temp)) {
213+
// If our operand is a non-Sendable type, look through this instruction.
214+
if (isNonSendableType(r->getOperand()->getType(), fn)) {
215+
temp = r->getOperand();
216+
}
217+
}
218+
219+
if (auto *r = dyn_cast<RawPointerToRefInst>(temp)) {
220+
// If our result is a non-Sendable type, look through this
221+
// instruction. Builtin.RawPointer is always non-Sendable.
222+
if (isNonSendableType(r->getType(), fn)) {
223+
temp = r->getOperand();
224+
}
225+
}
226+
211227
if (auto *dsi = dyn_cast_or_null<DestructureStructInst>(
212228
temp->getDefiningInstruction())) {
213229
temp = dsi->getOperand();
@@ -2321,6 +2337,7 @@ CONSTANT_TRANSLATION(UncheckedAddrCastInst, Assign)
23212337
CONSTANT_TRANSLATION(UncheckedEnumDataInst, Assign)
23222338
CONSTANT_TRANSLATION(UncheckedOwnershipConversionInst, Assign)
23232339
CONSTANT_TRANSLATION(UnmanagedToRefInst, Assign)
2340+
CONSTANT_TRANSLATION(IndexRawPointerInst, Assign)
23242341

23252342
// These are used by SIL to aggregate values together in a gep like way. We
23262343
// want to look at uses of structs, not the struct uses itself. So just
@@ -2450,12 +2467,9 @@ CONSTANT_TRANSLATION(DeallocExistentialBoxInst, Ignored)
24502467
// Unhandled Instructions
24512468
//
24522469

2453-
CONSTANT_TRANSLATION(IndexRawPointerInst, Unhandled)
24542470
CONSTANT_TRANSLATION(UncheckedTrivialBitCastInst, Unhandled)
24552471
CONSTANT_TRANSLATION(UncheckedBitwiseCastInst, Unhandled)
24562472
CONSTANT_TRANSLATION(UncheckedValueCastInst, Unhandled)
2457-
CONSTANT_TRANSLATION(RefToRawPointerInst, Unhandled)
2458-
CONSTANT_TRANSLATION(RawPointerToRefInst, Unhandled)
24592473
CONSTANT_TRANSLATION(RefToUnownedInst, Unhandled)
24602474
CONSTANT_TRANSLATION(UnownedToRefInst, Unhandled)
24612475
CONSTANT_TRANSLATION(BridgeObjectToWordInst, Unhandled)
@@ -2605,6 +2619,27 @@ IGNORE_IF_SENDABLE_RESULT_ASSIGN_OTHERWISE(StructExtractInst)
26052619
// Custom Handling
26062620
//
26072621

2622+
TranslationSemantics
2623+
PartitionOpTranslator::visitRawPointerToRefInst(RawPointerToRefInst *r) {
2624+
// If our result is non sendable, perform a look through.
2625+
if (isNonSendableType(r->getType()))
2626+
return TranslationSemantics::LookThrough;
2627+
2628+
// Otherwise to be conservative, we need to treat this as a require.
2629+
return TranslationSemantics::Require;
2630+
}
2631+
2632+
TranslationSemantics
2633+
PartitionOpTranslator::visitRefToRawPointerInst(RefToRawPointerInst *r) {
2634+
// If our source ref is non sendable, perform a look through.
2635+
if (isNonSendableType(r->getOperand()->getType()))
2636+
return TranslationSemantics::LookThrough;
2637+
2638+
// Otherwise to be conservative, we need to treat the raw pointer as a fresh
2639+
// sendable value.
2640+
return TranslationSemantics::AssignFresh;
2641+
}
2642+
26082643
TranslationSemantics
26092644
PartitionOpTranslator::visitMarkDependenceInst(MarkDependenceInst *mdi) {
26102645
translateSILAssign(mdi, mdi->getValue());

0 commit comments

Comments
 (0)