Skip to content

Commit d3a0113

Browse files
committed
Update all relevant visitors in SILCombine to skip ownership functions.
Instead of bailing on ownership functions in SILCombine::run, we will bail in individual visitors. This way, as SILCombine is updated we can paritially support ownership across the pass.
1 parent 270f734 commit d3a0113

File tree

5 files changed

+128
-4
lines changed

5 files changed

+128
-4
lines changed

lib/SILOptimizer/SILCombiner/SILCombine.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,6 @@ class SILCombine : public SILFunctionTransform {
250250

251251
/// The entry point to the transformation.
252252
void run() override {
253-
// FIXME: We should be able to handle ownership.
254-
if (getFunction()->hasOwnership())
255-
return;
256-
257253
auto *AA = PM->getAnalysis<AliasAnalysis>();
258254
auto *DA = PM->getAnalysis<DominanceAnalysis>();
259255
auto *PCA = PM->getAnalysis<ProtocolConformanceAnalysis>();

lib/SILOptimizer/SILCombiner/SILCombinerApplyVisitors.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ static bool foldInverseReabstractionThunks(PartialApplyInst *PAI,
7979
}
8080

8181
SILInstruction *SILCombiner::visitPartialApplyInst(PartialApplyInst *PAI) {
82+
if (PAI->getFunction()->hasOwnership())
83+
return nullptr;
84+
8285
// partial_apply without any substitutions or arguments is just a
8386
// thin_to_thick_function.
8487
if (!PAI->hasSubstitutions() && (PAI->getNumArguments() == 0)) {
@@ -1234,6 +1237,9 @@ FullApplySite SILCombiner::rewriteApplyCallee(FullApplySite apply,
12341237
}
12351238

12361239
SILInstruction *SILCombiner::visitApplyInst(ApplyInst *AI) {
1240+
if (AI->getFunction()->hasOwnership())
1241+
return nullptr;
1242+
12371243
Builder.setCurrentDebugScope(AI->getDebugScope());
12381244
// apply{partial_apply(x,y)}(z) -> apply(z,x,y) is triggered
12391245
// from visitPartialApplyInst(), so bail here.
@@ -1313,6 +1319,9 @@ SILInstruction *SILCombiner::visitApplyInst(ApplyInst *AI) {
13131319
}
13141320

13151321
SILInstruction *SILCombiner::visitBeginApplyInst(BeginApplyInst *BAI) {
1322+
if (BAI->getFunction()->hasOwnership())
1323+
return nullptr;
1324+
13161325
if (tryOptimizeInoutKeypath(BAI))
13171326
return nullptr;
13181327
return nullptr;
@@ -1368,6 +1377,9 @@ isTryApplyResultNotUsed(UserListTy &AcceptedUses, TryApplyInst *TAI) {
13681377
}
13691378

13701379
SILInstruction *SILCombiner::visitTryApplyInst(TryApplyInst *AI) {
1380+
if (AI->getFunction()->hasOwnership())
1381+
return nullptr;
1382+
13711383
// apply{partial_apply(x,y)}(z) -> apply(z,x,y) is triggered
13721384
// from visitPartialApplyInst(), so bail here.
13731385
if (isa<PartialApplyInst>(AI->getCallee()))

lib/SILOptimizer/SILCombiner/SILCombinerBuiltinVisitors.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,9 @@ SILInstruction *SILCombiner::optimizeStringObject(BuiltinInst *BI) {
530530
}
531531

532532
SILInstruction *SILCombiner::visitBuiltinInst(BuiltinInst *I) {
533+
if (I->getFunction()->hasOwnership())
534+
return nullptr;
535+
533536
if (I->getBuiltinInfo().ID == BuiltinValueKind::CanBeObjCClass)
534537
return optimizeBuiltinCanBeObjCClass(I);
535538
if (I->getBuiltinInfo().ID == BuiltinValueKind::IsConcrete)

lib/SILOptimizer/SILCombiner/SILCombinerCastVisitors.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ using namespace swift::PatternMatch;
3131

3232
SILInstruction *
3333
SILCombiner::visitRefToRawPointerInst(RefToRawPointerInst *RRPI) {
34+
if (RRPI->getFunction()->hasOwnership())
35+
return nullptr;
36+
3437
// Ref to raw pointer consumption of other ref casts.
3538
if (auto *URCI = dyn_cast<UncheckedRefCastInst>(RRPI->getOperand())) {
3639
// (ref_to_raw_pointer (unchecked_ref_cast x))
@@ -57,6 +60,9 @@ SILCombiner::visitRefToRawPointerInst(RefToRawPointerInst *RRPI) {
5760
}
5861

5962
SILInstruction *SILCombiner::visitUpcastInst(UpcastInst *UCI) {
63+
if (UCI->getFunction()->hasOwnership())
64+
return nullptr;
65+
6066
// Ref to raw pointer consumption of other ref casts.
6167
//
6268
// (upcast (upcast x)) -> (upcast x)
@@ -72,6 +78,8 @@ SILInstruction *
7278
SILCombiner::
7379
visitPointerToAddressInst(PointerToAddressInst *PTAI) {
7480
auto *F = PTAI->getFunction();
81+
if (F->hasOwnership())
82+
return nullptr;
7583

7684
Builder.setCurrentDebugScope(PTAI->getDebugScope());
7785

@@ -200,6 +208,9 @@ visitPointerToAddressInst(PointerToAddressInst *PTAI) {
200208

201209
SILInstruction *
202210
SILCombiner::visitUncheckedAddrCastInst(UncheckedAddrCastInst *UADCI) {
211+
if (UADCI->getFunction()->hasOwnership())
212+
return nullptr;
213+
203214
Builder.setCurrentDebugScope(UADCI->getDebugScope());
204215

205216
// (unchecked-addr-cast (unchecked-addr-cast x X->Y) Y->Z)
@@ -221,6 +232,9 @@ SILCombiner::visitUncheckedAddrCastInst(UncheckedAddrCastInst *UADCI) {
221232

222233
SILInstruction *
223234
SILCombiner::visitUncheckedRefCastInst(UncheckedRefCastInst *URCI) {
235+
if (URCI->getFunction()->hasOwnership())
236+
return nullptr;
237+
224238
// (unchecked-ref-cast (unchecked-ref-cast x X->Y) Y->Z)
225239
// ->
226240
// (unchecked-ref-cast x X->Z)
@@ -253,6 +267,8 @@ SILCombiner::visitUncheckedRefCastInst(UncheckedRefCastInst *URCI) {
253267

254268
SILInstruction *
255269
SILCombiner::visitBridgeObjectToRefInst(BridgeObjectToRefInst *BORI) {
270+
if (BORI->getFunction()->hasOwnership())
271+
return nullptr;
256272
// Fold noop casts through Builtin.BridgeObject.
257273
// (bridge_object_to_ref (unchecked-ref-cast x BridgeObject) y)
258274
// -> (unchecked-ref-cast x y)
@@ -266,6 +282,9 @@ SILCombiner::visitBridgeObjectToRefInst(BridgeObjectToRefInst *BORI) {
266282

267283
SILInstruction *
268284
SILCombiner::visitUncheckedRefCastAddrInst(UncheckedRefCastAddrInst *URCI) {
285+
if (URCI->getFunction()->hasOwnership())
286+
return nullptr;
287+
269288
SILType SrcTy = URCI->getSrc()->getType();
270289
if (!SrcTy.isLoadable(*URCI->getFunction()))
271290
return nullptr;
@@ -301,6 +320,9 @@ SILCombiner::visitUncheckedRefCastAddrInst(UncheckedRefCastAddrInst *URCI) {
301320
SILInstruction *
302321
SILCombiner::
303322
visitUnconditionalCheckedCastAddrInst(UnconditionalCheckedCastAddrInst *UCCAI) {
323+
if (UCCAI->getFunction()->hasOwnership())
324+
return nullptr;
325+
304326
if (CastOpt.optimizeUnconditionalCheckedCastAddrInst(UCCAI))
305327
MadeChange = true;
306328

@@ -310,6 +332,9 @@ visitUnconditionalCheckedCastAddrInst(UnconditionalCheckedCastAddrInst *UCCAI) {
310332
SILInstruction *
311333
SILCombiner::
312334
visitUnconditionalCheckedCastInst(UnconditionalCheckedCastInst *UCCI) {
335+
if (UCCI->getFunction()->hasOwnership())
336+
return nullptr;
337+
313338
if (CastOpt.optimizeUnconditionalCheckedCastInst(UCCI)) {
314339
MadeChange = true;
315340
return nullptr;
@@ -338,6 +363,9 @@ visitUnconditionalCheckedCastInst(UnconditionalCheckedCastInst *UCCI) {
338363
SILInstruction *
339364
SILCombiner::
340365
visitRawPointerToRefInst(RawPointerToRefInst *RawToRef) {
366+
if (RawToRef->getFunction()->hasOwnership())
367+
return nullptr;
368+
341369
// (raw_pointer_to_ref (ref_to_raw_pointer x X->Y) Y->Z)
342370
// ->
343371
// (unchecked_ref_cast X->Z)
@@ -353,6 +381,9 @@ visitRawPointerToRefInst(RawPointerToRefInst *RawToRef) {
353381
SILInstruction *
354382
SILCombiner::
355383
visitUncheckedTrivialBitCastInst(UncheckedTrivialBitCastInst *UTBCI) {
384+
if (UTBCI->getFunction()->hasOwnership())
385+
return nullptr;
386+
356387
// (unchecked_trivial_bit_cast Y->Z
357388
// (unchecked_trivial_bit_cast X->Y x))
358389
// ->
@@ -406,6 +437,9 @@ visitUncheckedBitwiseCastInst(UncheckedBitwiseCastInst *UBCI) {
406437

407438
SILInstruction *
408439
SILCombiner::visitThickToObjCMetatypeInst(ThickToObjCMetatypeInst *TTOCMI) {
440+
if (TTOCMI->getFunction()->hasOwnership())
441+
return nullptr;
442+
409443
// Perform the following transformations:
410444
// (thick_to_objc_metatype (metatype @thick)) ->
411445
// (metatype @objc_metatype)
@@ -423,6 +457,9 @@ SILCombiner::visitThickToObjCMetatypeInst(ThickToObjCMetatypeInst *TTOCMI) {
423457

424458
SILInstruction *
425459
SILCombiner::visitObjCToThickMetatypeInst(ObjCToThickMetatypeInst *OCTTMI) {
460+
if (OCTTMI->getFunction()->hasOwnership())
461+
return nullptr;
462+
426463
// Perform the following transformations:
427464
// (objc_to_thick_metatype (metatype @objc_metatype)) ->
428465
// (metatype @thick)
@@ -440,6 +477,9 @@ SILCombiner::visitObjCToThickMetatypeInst(ObjCToThickMetatypeInst *OCTTMI) {
440477

441478
SILInstruction *
442479
SILCombiner::visitCheckedCastBranchInst(CheckedCastBranchInst *CBI) {
480+
if (CBI->getFunction()->hasOwnership())
481+
return nullptr;
482+
443483
if (CastOpt.optimizeCheckedCastBranchInst(CBI))
444484
MadeChange = true;
445485

@@ -449,6 +489,9 @@ SILCombiner::visitCheckedCastBranchInst(CheckedCastBranchInst *CBI) {
449489
SILInstruction *
450490
SILCombiner::
451491
visitCheckedCastAddrBranchInst(CheckedCastAddrBranchInst *CCABI) {
492+
if (CCABI->getFunction()->hasOwnership())
493+
return nullptr;
494+
452495
if (CastOpt.optimizeCheckedCastAddrBranchInst(CCABI))
453496
MadeChange = true;
454497

@@ -457,6 +500,9 @@ visitCheckedCastAddrBranchInst(CheckedCastAddrBranchInst *CCABI) {
457500

458501
SILInstruction *SILCombiner::visitConvertEscapeToNoEscapeInst(
459502
ConvertEscapeToNoEscapeInst *Cvt) {
503+
if (Cvt->getFunction()->hasOwnership())
504+
return nullptr;
505+
460506
auto *OrigThinToThick =
461507
dyn_cast<ThinToThickFunctionInst>(Cvt->getConverted());
462508
if (!OrigThinToThick)
@@ -470,6 +516,9 @@ SILInstruction *SILCombiner::visitConvertEscapeToNoEscapeInst(
470516
}
471517

472518
SILInstruction *SILCombiner::visitConvertFunctionInst(ConvertFunctionInst *CFI) {
519+
if (CFI->getFunction()->hasOwnership())
520+
return nullptr;
521+
473522
// If this conversion only changes substitutions, then rewrite applications
474523
// of the converted function as applications of the original.
475524
//

0 commit comments

Comments
 (0)