@@ -418,90 +418,96 @@ bool SILCombiner::doOneIteration(SILFunction &F, unsigned Iteration) {
418
418
if (!parentTransform->continueWithNextSubpassRun (I))
419
419
return false ;
420
420
421
- // Check to see if we can DCE the instruction.
422
- if (isInstructionTriviallyDead (I)) {
423
- LLVM_DEBUG (llvm::dbgs () << " SC: DCE: " << *I << ' \n ' );
424
- eraseInstFromFunction (*I);
425
- ++NumDeadInst;
426
- MadeChange = true ;
427
- continue ;
428
- }
421
+ processInstruction (I, scCanonicalize, MadeChange);
422
+ }
423
+
424
+ Worklist.resetChecked ();
425
+ return MadeChange;
426
+ }
427
+
428
+ void SILCombiner::processInstruction (SILInstruction *I,
429
+ SILCombineCanonicalize &scCanonicalize,
430
+ bool &MadeChange) {
431
+ // Check to see if we can DCE the instruction.
432
+ if (isInstructionTriviallyDead (I)) {
433
+ LLVM_DEBUG (llvm::dbgs () << " SC: DCE: " << *I << ' \n ' );
434
+ eraseInstFromFunction (*I);
435
+ ++NumDeadInst;
436
+ MadeChange = true ;
437
+ return ;
438
+ }
429
439
#ifndef NDEBUG
430
- std::string OrigIStr;
440
+ std::string OrigIStr;
431
441
#endif
432
- LLVM_DEBUG (llvm::raw_string_ostream SS (OrigIStr); I->print (SS);
433
- OrigIStr = SS.str (););
434
- LLVM_DEBUG (llvm::dbgs () << " SC: Visiting: " << OrigIStr << ' \n ' );
442
+ LLVM_DEBUG (llvm::raw_string_ostream SS (OrigIStr); I->print (SS);
443
+ OrigIStr = SS.str (););
444
+ LLVM_DEBUG (llvm::dbgs () << " SC: Visiting: " << OrigIStr << ' \n ' );
435
445
436
- // Canonicalize the instruction.
437
- if (scCanonicalize.tryCanonicalize (I)) {
438
- MadeChange = true ;
439
- continue ;
440
- }
446
+ // Canonicalize the instruction.
447
+ if (scCanonicalize.tryCanonicalize (I)) {
448
+ MadeChange = true ;
449
+ return ;
450
+ }
441
451
442
- // If we have reached this point, all attempts to do simple simplifications
443
- // have failed. First if we have an owned forwarding value, we try to
444
- // sink. Otherwise, we perform the actual SILCombine operation.
445
- if (EnableSinkingOwnedForwardingInstToUses) {
446
- // If we have an ownership forwarding single value inst that forwards
447
- // through its first argument and it is trivially duplicatable, see if it
448
- // only has consuming uses. If so, we can duplicate the instruction into
449
- // the consuming use blocks and destroy any destroy_value uses of it that
450
- // we see. This makes it easier for SILCombine to fold instructions with
451
- // owned parameters since chains of these values will be in the same
452
- // block.
453
- if (auto *svi = dyn_cast<SingleValueInstruction>(I)) {
454
- if (auto fwdOp = ForwardingOperation (svi)) {
455
- if (fwdOp.getSingleForwardingOperand () &&
456
- SILValue (svi)->getOwnershipKind () == OwnershipKind::Owned) {
457
- // Try to sink the value. If we sank the value and deleted it,
458
- // continue. If we didn't optimize or sank but we are still able to
459
- // optimize further, we fall through to SILCombine below.
460
- if (trySinkOwnedForwardingInst (svi)) {
461
- continue ;
462
- }
452
+ // If we have reached this point, all attempts to do simple simplifications
453
+ // have failed. First if we have an owned forwarding value, we try to
454
+ // sink. Otherwise, we perform the actual SILCombine operation.
455
+ if (EnableSinkingOwnedForwardingInstToUses) {
456
+ // If we have an ownership forwarding single value inst that forwards
457
+ // through its first argument and it is trivially duplicatable, see if it
458
+ // only has consuming uses. If so, we can duplicate the instruction into
459
+ // the consuming use blocks and destroy any destroy_value uses of it that
460
+ // we see. This makes it easier for SILCombine to fold instructions with
461
+ // owned parameters since chains of these values will be in the same
462
+ // block.
463
+ if (auto *svi = dyn_cast<SingleValueInstruction>(I)) {
464
+ if (auto fwdOp = ForwardingOperation (svi)) {
465
+ if (fwdOp.getSingleForwardingOperand () &&
466
+ SILValue (svi)->getOwnershipKind () == OwnershipKind::Owned) {
467
+ // Try to sink the value. If we sank the value and deleted it,
468
+ // return. If we didn't optimize or sank but we are still able to
469
+ // optimize further, we fall through to SILCombine below.
470
+ if (trySinkOwnedForwardingInst (svi)) {
471
+ return ;
463
472
}
464
473
}
465
474
}
466
475
}
476
+ }
467
477
468
- // Then begin... SILCombine.
469
- Builder.setInsertionPoint (I);
478
+ // Then begin... SILCombine.
479
+ Builder.setInsertionPoint (I);
470
480
471
- SILInstruction *currentInst = I;
472
- if (SILInstruction *Result = visit (I)) {
473
- ++NumCombined;
474
- // Should we replace the old instruction with a new one?
475
- Worklist.replaceInstructionWithInstruction (I, Result
481
+ SILInstruction *currentInst = I;
482
+ if (SILInstruction *Result = visit (I)) {
483
+ ++NumCombined;
484
+ // Should we replace the old instruction with a new one?
485
+ Worklist.replaceInstructionWithInstruction (I, Result
476
486
#ifndef NDEBUG
477
- ,
478
- OrigIStr
487
+ ,
488
+ OrigIStr
479
489
#endif
480
- );
481
- currentInst = Result;
482
- MadeChange = true ;
483
- }
490
+ );
491
+ currentInst = Result;
492
+ MadeChange = true ;
493
+ }
484
494
485
- // Eliminate copies created that this SILCombine iteration may have
486
- // introduced during OSSA-RAUW.
487
- canonicalizeOSSALifetimes (currentInst->isDeleted () ? nullptr : currentInst);
488
-
489
- // Builder's tracking list has been accumulating instructions created by the
490
- // during this SILCombine iteration. To finish this iteration, go through
491
- // the tracking list and add its contents to the worklist and then clear
492
- // said list in preparation for the next iteration.
493
- for (SILInstruction *I : *Builder.getTrackingList ()) {
494
- if (!I->isDeleted ()) {
495
- LLVM_DEBUG (llvm::dbgs ()
496
- << " SC: add " << *I << " from tracking list to worklist\n " );
497
- Worklist.add (I);
498
- }
495
+ // Eliminate copies created that this SILCombine iteration may have
496
+ // introduced during OSSA-RAUW.
497
+ canonicalizeOSSALifetimes (currentInst->isDeleted () ? nullptr : currentInst);
498
+
499
+ // Builder's tracking list has been accumulating instructions created by the
500
+ // during this SILCombine iteration. To finish this iteration, go through
501
+ // the tracking list and add its contents to the worklist and then clear
502
+ // said list in preparation for the next iteration.
503
+ for (SILInstruction *I : *Builder.getTrackingList ()) {
504
+ if (!I->isDeleted ()) {
505
+ LLVM_DEBUG (llvm::dbgs ()
506
+ << " SC: add " << *I << " from tracking list to worklist\n " );
507
+ Worklist.add (I);
499
508
}
500
- Builder.getTrackingList ()->clear ();
501
509
}
502
-
503
- Worklist.resetChecked ();
504
- return MadeChange;
510
+ Builder.getTrackingList ()->clear ();
505
511
}
506
512
507
513
namespace swift ::test {
0 commit comments