@@ -3541,32 +3541,42 @@ struct IRTypeLegalizationPass
3541
3541
// In order to process an entire module, we start by adding the
3542
3542
// root module insturction to our work list, and then we will
3543
3543
// proceed to process instructions until the work list goes dry.
3544
+ // The entire process is repeated until no more changes can be
3545
+ // made to the module.
3544
3546
//
3545
- addToWorkList (module->getModuleInst ());
3546
- while ( workList.getCount () != 0 )
3547
- {
3548
- // The order of items in the work list is signficiant;
3549
- // later entries could depend on earlier ones. As such, we
3550
- // cannot just do something like the `fastRemoveAt(...)`
3551
- // operation that could potentially lead to instructions
3552
- // being processed in a different order than they were added.
3553
- //
3554
- // Instead, we will make a copy of the current work list
3555
- // at each step, and swap in an empty work list to be added
3556
- // to with any new instructions.
3557
- //
3558
- List<IRInst*> workListCopy;
3559
- Swap (workListCopy, workList);
3560
- addedToWorkListSet.Clear ();
3561
-
3562
- // Now we simply process each instruction on the copy of
3563
- // the work list, knowing that `processInst` may add additional
3564
- // instructions to the original work list.
3565
- //
3566
- for ( auto inst : workListCopy )
3547
+ for (;;)
3548
+ {
3549
+ auto lastReplacedInstCount = context->replacedInstructions .Count ();
3550
+ addToWorkList (module->getModuleInst ());
3551
+ while ( workList.getCount () != 0 )
3567
3552
{
3568
- processInst (inst);
3553
+ // The order of items in the work list is signficiant;
3554
+ // later entries could depend on earlier ones. As such, we
3555
+ // cannot just do something like the `fastRemoveAt(...)`
3556
+ // operation that could potentially lead to instructions
3557
+ // being processed in a different order than they were added.
3558
+ //
3559
+ // Instead, we will make a copy of the current work list
3560
+ // at each step, and swap in an empty work list to be added
3561
+ // to with any new instructions.
3562
+ //
3563
+ List<IRInst*> workListCopy;
3564
+ Swap (workListCopy, workList);
3565
+ addedToWorkListSet.Clear ();
3566
+
3567
+ // Now we simply process each instruction on the copy of
3568
+ // the work list, knowing that `processInst` may add additional
3569
+ // instructions to the original work list.
3570
+ //
3571
+ for ( auto inst : workListCopy )
3572
+ {
3573
+ processInst (inst);
3574
+ }
3569
3575
}
3576
+
3577
+ // Any changes made? Run the process again.
3578
+ if (lastReplacedInstCount == context->replacedInstructions .Count ())
3579
+ break ;
3570
3580
}
3571
3581
3572
3582
// After we are done, there might be various instructions that
0 commit comments