@@ -31,6 +31,9 @@ using namespace swift::PatternMatch;
31
31
32
32
SILInstruction *
33
33
SILCombiner::visitRefToRawPointerInst (RefToRawPointerInst *RRPI) {
34
+ if (RRPI->getFunction ()->hasOwnership ())
35
+ return nullptr ;
36
+
34
37
// Ref to raw pointer consumption of other ref casts.
35
38
if (auto *URCI = dyn_cast<UncheckedRefCastInst>(RRPI->getOperand ())) {
36
39
// (ref_to_raw_pointer (unchecked_ref_cast x))
@@ -57,6 +60,9 @@ SILCombiner::visitRefToRawPointerInst(RefToRawPointerInst *RRPI) {
57
60
}
58
61
59
62
SILInstruction *SILCombiner::visitUpcastInst (UpcastInst *UCI) {
63
+ if (UCI->getFunction ()->hasOwnership ())
64
+ return nullptr ;
65
+
60
66
// Ref to raw pointer consumption of other ref casts.
61
67
//
62
68
// (upcast (upcast x)) -> (upcast x)
@@ -72,6 +78,8 @@ SILInstruction *
72
78
SILCombiner::
73
79
visitPointerToAddressInst (PointerToAddressInst *PTAI) {
74
80
auto *F = PTAI->getFunction ();
81
+ if (F->hasOwnership ())
82
+ return nullptr ;
75
83
76
84
Builder.setCurrentDebugScope (PTAI->getDebugScope ());
77
85
@@ -200,6 +208,9 @@ visitPointerToAddressInst(PointerToAddressInst *PTAI) {
200
208
201
209
SILInstruction *
202
210
SILCombiner::visitUncheckedAddrCastInst (UncheckedAddrCastInst *UADCI) {
211
+ if (UADCI->getFunction ()->hasOwnership ())
212
+ return nullptr ;
213
+
203
214
Builder.setCurrentDebugScope (UADCI->getDebugScope ());
204
215
205
216
// (unchecked-addr-cast (unchecked-addr-cast x X->Y) Y->Z)
@@ -221,6 +232,9 @@ SILCombiner::visitUncheckedAddrCastInst(UncheckedAddrCastInst *UADCI) {
221
232
222
233
SILInstruction *
223
234
SILCombiner::visitUncheckedRefCastInst (UncheckedRefCastInst *URCI) {
235
+ if (URCI->getFunction ()->hasOwnership ())
236
+ return nullptr ;
237
+
224
238
// (unchecked-ref-cast (unchecked-ref-cast x X->Y) Y->Z)
225
239
// ->
226
240
// (unchecked-ref-cast x X->Z)
@@ -253,6 +267,8 @@ SILCombiner::visitUncheckedRefCastInst(UncheckedRefCastInst *URCI) {
253
267
254
268
SILInstruction *
255
269
SILCombiner::visitBridgeObjectToRefInst (BridgeObjectToRefInst *BORI) {
270
+ if (BORI->getFunction ()->hasOwnership ())
271
+ return nullptr ;
256
272
// Fold noop casts through Builtin.BridgeObject.
257
273
// (bridge_object_to_ref (unchecked-ref-cast x BridgeObject) y)
258
274
// -> (unchecked-ref-cast x y)
@@ -266,6 +282,9 @@ SILCombiner::visitBridgeObjectToRefInst(BridgeObjectToRefInst *BORI) {
266
282
267
283
SILInstruction *
268
284
SILCombiner::visitUncheckedRefCastAddrInst (UncheckedRefCastAddrInst *URCI) {
285
+ if (URCI->getFunction ()->hasOwnership ())
286
+ return nullptr ;
287
+
269
288
SILType SrcTy = URCI->getSrc ()->getType ();
270
289
if (!SrcTy.isLoadable (*URCI->getFunction ()))
271
290
return nullptr ;
@@ -301,6 +320,9 @@ SILCombiner::visitUncheckedRefCastAddrInst(UncheckedRefCastAddrInst *URCI) {
301
320
SILInstruction *
302
321
SILCombiner::
303
322
visitUnconditionalCheckedCastAddrInst (UnconditionalCheckedCastAddrInst *UCCAI) {
323
+ if (UCCAI->getFunction ()->hasOwnership ())
324
+ return nullptr ;
325
+
304
326
if (CastOpt.optimizeUnconditionalCheckedCastAddrInst (UCCAI))
305
327
MadeChange = true ;
306
328
@@ -310,6 +332,9 @@ visitUnconditionalCheckedCastAddrInst(UnconditionalCheckedCastAddrInst *UCCAI) {
310
332
SILInstruction *
311
333
SILCombiner::
312
334
visitUnconditionalCheckedCastInst (UnconditionalCheckedCastInst *UCCI) {
335
+ if (UCCI->getFunction ()->hasOwnership ())
336
+ return nullptr ;
337
+
313
338
if (CastOpt.optimizeUnconditionalCheckedCastInst (UCCI)) {
314
339
MadeChange = true ;
315
340
return nullptr ;
@@ -338,6 +363,9 @@ visitUnconditionalCheckedCastInst(UnconditionalCheckedCastInst *UCCI) {
338
363
SILInstruction *
339
364
SILCombiner::
340
365
visitRawPointerToRefInst (RawPointerToRefInst *RawToRef) {
366
+ if (RawToRef->getFunction ()->hasOwnership ())
367
+ return nullptr ;
368
+
341
369
// (raw_pointer_to_ref (ref_to_raw_pointer x X->Y) Y->Z)
342
370
// ->
343
371
// (unchecked_ref_cast X->Z)
@@ -353,6 +381,9 @@ visitRawPointerToRefInst(RawPointerToRefInst *RawToRef) {
353
381
SILInstruction *
354
382
SILCombiner::
355
383
visitUncheckedTrivialBitCastInst (UncheckedTrivialBitCastInst *UTBCI) {
384
+ if (UTBCI->getFunction ()->hasOwnership ())
385
+ return nullptr ;
386
+
356
387
// (unchecked_trivial_bit_cast Y->Z
357
388
// (unchecked_trivial_bit_cast X->Y x))
358
389
// ->
@@ -406,6 +437,9 @@ visitUncheckedBitwiseCastInst(UncheckedBitwiseCastInst *UBCI) {
406
437
407
438
SILInstruction *
408
439
SILCombiner::visitThickToObjCMetatypeInst (ThickToObjCMetatypeInst *TTOCMI) {
440
+ if (TTOCMI->getFunction ()->hasOwnership ())
441
+ return nullptr ;
442
+
409
443
// Perform the following transformations:
410
444
// (thick_to_objc_metatype (metatype @thick)) ->
411
445
// (metatype @objc_metatype)
@@ -423,6 +457,9 @@ SILCombiner::visitThickToObjCMetatypeInst(ThickToObjCMetatypeInst *TTOCMI) {
423
457
424
458
SILInstruction *
425
459
SILCombiner::visitObjCToThickMetatypeInst (ObjCToThickMetatypeInst *OCTTMI) {
460
+ if (OCTTMI->getFunction ()->hasOwnership ())
461
+ return nullptr ;
462
+
426
463
// Perform the following transformations:
427
464
// (objc_to_thick_metatype (metatype @objc_metatype)) ->
428
465
// (metatype @thick)
@@ -440,6 +477,9 @@ SILCombiner::visitObjCToThickMetatypeInst(ObjCToThickMetatypeInst *OCTTMI) {
440
477
441
478
SILInstruction *
442
479
SILCombiner::visitCheckedCastBranchInst (CheckedCastBranchInst *CBI) {
480
+ if (CBI->getFunction ()->hasOwnership ())
481
+ return nullptr ;
482
+
443
483
if (CastOpt.optimizeCheckedCastBranchInst (CBI))
444
484
MadeChange = true ;
445
485
@@ -449,6 +489,9 @@ SILCombiner::visitCheckedCastBranchInst(CheckedCastBranchInst *CBI) {
449
489
SILInstruction *
450
490
SILCombiner::
451
491
visitCheckedCastAddrBranchInst (CheckedCastAddrBranchInst *CCABI) {
492
+ if (CCABI->getFunction ()->hasOwnership ())
493
+ return nullptr ;
494
+
452
495
if (CastOpt.optimizeCheckedCastAddrBranchInst (CCABI))
453
496
MadeChange = true ;
454
497
@@ -457,6 +500,9 @@ visitCheckedCastAddrBranchInst(CheckedCastAddrBranchInst *CCABI) {
457
500
458
501
SILInstruction *SILCombiner::visitConvertEscapeToNoEscapeInst (
459
502
ConvertEscapeToNoEscapeInst *Cvt) {
503
+ if (Cvt->getFunction ()->hasOwnership ())
504
+ return nullptr ;
505
+
460
506
auto *OrigThinToThick =
461
507
dyn_cast<ThinToThickFunctionInst>(Cvt->getConverted ());
462
508
if (!OrigThinToThick)
@@ -470,6 +516,9 @@ SILInstruction *SILCombiner::visitConvertEscapeToNoEscapeInst(
470
516
}
471
517
472
518
SILInstruction *SILCombiner::visitConvertFunctionInst (ConvertFunctionInst *CFI) {
519
+ if (CFI->getFunction ()->hasOwnership ())
520
+ return nullptr ;
521
+
473
522
// If this conversion only changes substitutions, then rewrite applications
474
523
// of the converted function as applications of the original.
475
524
//
0 commit comments