File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed
lib/SILOptimizer/SILCombiner Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -183,6 +183,7 @@ class SILCombiner :
183
183
SILInstruction *visitPointerToAddressInst (PointerToAddressInst *PTAI);
184
184
SILInstruction *visitUncheckedAddrCastInst (UncheckedAddrCastInst *UADCI);
185
185
SILInstruction *visitUncheckedRefCastInst (UncheckedRefCastInst *URCI);
186
+ SILInstruction *visitEndCOWMutationInst (EndCOWMutationInst *URCI);
186
187
SILInstruction *visitUncheckedRefCastAddrInst (UncheckedRefCastAddrInst *URCI);
187
188
SILInstruction *visitBridgeObjectToRefInst (BridgeObjectToRefInst *BORI);
188
189
SILInstruction *visitUnconditionalCheckedCastInst (
Original file line number Diff line number Diff line change @@ -264,6 +264,26 @@ SILCombiner::visitUncheckedRefCastInst(UncheckedRefCastInst *URCI) {
264
264
return nullptr ;
265
265
}
266
266
267
+ SILInstruction *SILCombiner::visitEndCOWMutationInst (EndCOWMutationInst *ECM) {
268
+
269
+ // Remove a cast if it's only used by an end_cow_mutation.
270
+ //
271
+ // (end_cow_mutation (upcast X)) -> (end_cow_mutation X)
272
+ // (end_cow_mutation (unchecked_ref_cast X)) -> (end_cow_mutation X)
273
+ SILValue op = ECM->getOperand ();
274
+ if (!isa<UncheckedRefCastInst>(op) && !isa<UpcastInst>(op))
275
+ return nullptr ;
276
+ if (!op->hasOneUse ())
277
+ return nullptr ;
278
+
279
+ SingleValueInstruction *refCast = cast<SingleValueInstruction>(op);
280
+ auto *newECM = Builder.createEndCOWMutation (ECM->getLoc (),
281
+ refCast->getOperand (0 ));
282
+ ECM->replaceAllUsesWith (refCast);
283
+ refCast->setOperand (0 , newECM);
284
+ refCast->moveAfter (newECM);
285
+ return eraseInstFromFunction (*ECM);
286
+ }
267
287
268
288
SILInstruction *
269
289
SILCombiner::visitBridgeObjectToRefInst (BridgeObjectToRefInst *BORI) {
You can’t perform that action at this time.
0 commit comments