Skip to content

Commit 067d554

Browse files
committedMar 7, 2025
Remove the sorting logic
1 parent 6a8b99d commit 067d554

File tree

1 file changed

+23
-27
lines changed

1 file changed

+23
-27
lines changed
 

‎source/slang/slang-ir.cpp

+23-27
Original file line numberDiff line numberDiff line change
@@ -1687,35 +1687,29 @@ void addHoistableInst(IRBuilder* builder, IRInst* inst)
16871687
//
16881688
IRInst* insertBeforeInst = parent->getFirstChild();
16891689

1690-
// Hoistable instructions are always "ordinary"
1691-
// instructions, so they need to come after
1692-
// any parameters of the parent.
1693-
//
1694-
while (insertBeforeInst && insertBeforeInst->getOp() == kIROp_Param)
1695-
insertBeforeInst = insertBeforeInst->getNextInst();
1696-
16971690
if (inst->getOp() == kIROp_WitnessTable)
16981691
{
16991692
SLANG_ASSERT(getIROpInfo(kIROp_WitnessTable).isHoistable());
17001693

1701-
// WitnessTable can refer to IRSpecialize from its WitnessTableEntry children. In this case,
1702-
// specialize insts must be cloned before the WitnessTable. Similar an WitnessTables can
1703-
// have depdency to another WitnessTable.
1694+
// Because IRWitnessTable is Hoistable, do not move when
1695+
// it is already a child of the parent.
17041696
//
1705-
for (IRInst* iter = insertBeforeInst; iter;)
1706-
{
1707-
bool mayHaveDependency = false;
1708-
switch (iter->getOp())
1709-
{
1710-
case kIROp_Specialize:
1711-
case kIROp_WitnessTable:
1712-
mayHaveDependency = true;
1713-
break;
1714-
}
1697+
if (parent == inst->parent)
1698+
return;
17151699

1716-
iter = iter->getNextInst();
1717-
if (mayHaveDependency)
1718-
insertBeforeInst = iter;
1700+
// For the rest of the cases, IRWitnessTable goes to the
1701+
// end of the list.
1702+
insertBeforeInst = nullptr;
1703+
}
1704+
else
1705+
{
1706+
// Hoistable instructions are always "ordinary"
1707+
// instructions, so they need to come after
1708+
// any parameters of the parent.
1709+
//
1710+
while (insertBeforeInst && insertBeforeInst->getOp() == kIROp_Param)
1711+
{
1712+
insertBeforeInst = insertBeforeInst->getNextInst();
17191713
}
17201714
}
17211715

@@ -4634,11 +4628,13 @@ void addGlobalValue(IRBuilder* builder, IRInst* value)
46344628
parent = builder->getModule()->getModuleInst();
46354629
}
46364630

4637-
// If the value is already in the parent, keep it as-is. Because WitnessTable is Hoistable, the
4638-
// parent can have only one instance of this WitnessTable. The order among siblings should
4639-
// remain because the later siblings may have dependency to the earlier siblings.
4631+
// If the value is already in the parent, keep it as-is.
4632+
// Because WitnessTable is Hoistable, the parent can have
4633+
// only one instance of this WitnessTable. The order among
4634+
// siblings should remain because the later siblings may
4635+
// have dependency to the earlier siblings.
46404636
//
4641-
if (parent == value->parent)
4637+
if (parent == value->parent && value->getOp() == kIROp_WitnessTable)
46424638
{
46434639
SLANG_ASSERT(getIROpInfo(kIROp_WitnessTable).isHoistable());
46444640
return;

0 commit comments

Comments
 (0)