Skip to content

Commit d7ba60c

Browse files
authored
Fix type legalization pass. (shader-slang#2768)
1 parent 539f17a commit d7ba60c

File tree

1 file changed

+33
-23
lines changed

1 file changed

+33
-23
lines changed

source/slang/slang-ir-legalize-types.cpp

+33-23
Original file line numberDiff line numberDiff line change
@@ -3541,32 +3541,42 @@ struct IRTypeLegalizationPass
35413541
// In order to process an entire module, we start by adding the
35423542
// root module insturction to our work list, and then we will
35433543
// 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.
35443546
//
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 )
35673552
{
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+
}
35693575
}
3576+
3577+
// Any changes made? Run the process again.
3578+
if (lastReplacedInstCount == context->replacedInstructions.Count())
3579+
break;
35703580
}
35713581

35723582
// After we are done, there might be various instructions that

0 commit comments

Comments
 (0)