@@ -1605,11 +1605,7 @@ static IRInst* pickLaterInstInSameParent(IRInst* left, IRInst* right)
1605
1605
}
1606
1606
}
1607
1607
1608
- // Given an instruction that represents a constant, a type, etc.
1609
- // Try to "hoist" it as far toward the global scope as possible
1610
- // to insert it at a location where it will be maximally visible.
1611
- //
1612
- void addHoistableInst (IRBuilder* builder, IRInst* inst)
1608
+ static IRInst* getParentOfHoistableInst (IRBuilder* builder, IRInst* inst)
1613
1609
{
1614
1610
// Start with the assumption that we would insert this instruction
1615
1611
// into the global scope (the instruction that represents the module)
@@ -1643,6 +1639,17 @@ void addHoistableInst(IRBuilder* builder, IRInst* inst)
1643
1639
//
1644
1640
SLANG_ASSERT (parent);
1645
1641
1642
+ return parent;
1643
+ }
1644
+
1645
+ // Given an instruction that represents a constant, a type, etc.
1646
+ // Try to "hoist" it as far toward the global scope as possible
1647
+ // to insert it at a location where it will be maximally visible.
1648
+ //
1649
+ void addHoistableInst (IRBuilder* builder, IRInst* inst)
1650
+ {
1651
+ IRInst* parent = getParentOfHoistableInst (builder, inst);
1652
+
1646
1653
// Once we determine the parent instruction that the
1647
1654
// new instruction should be inserted into, we need
1648
1655
// to find an appropriate place to insert it.
@@ -1707,6 +1714,7 @@ void addHoistableInst(IRBuilder* builder, IRInst* inst)
1707
1714
// the operands of `inst` come from the same
1708
1715
// block that we insert after them.
1709
1716
//
1717
+ UInt operandCount = inst->getOperandCount ();
1710
1718
for (UInt ii = 0 ; ii < operandCount; ++ii)
1711
1719
{
1712
1720
auto operand = inst->getOperand (ii);
@@ -1742,29 +1750,15 @@ void addHoistableInst(IRBuilder* builder, IRInst* inst)
1742
1750
}
1743
1751
}
1744
1752
1745
- // Add the given inst to the parent of its operand.
1746
- void addInst (IRInst* inst)
1753
+ // This function finds where a parent should be for the given inst,
1754
+ // and add the inst as a last child.
1755
+ // When the inst is marked as Hoistable but the intention is only to de-duplicate it,
1756
+ // the inst can be added in a simpler manner.
1757
+ void addDeduplicatedInst (IRBuilder * builder, IRInst * inst)
1747
1758
{
1748
1759
SLANG_ASSERT (nullptr == inst->parent );
1749
1760
1750
- IRInst* parent = nullptr ;
1751
-
1752
- UInt operandCount = inst->getOperandCount ();
1753
- for (UInt ii = 0 ; ii < operandCount; ++ii)
1754
- {
1755
- auto operand = inst->getOperand (ii);
1756
- if (!operand)
1757
- continue ;
1758
-
1759
- auto operandParent = operand->getParent ();
1760
-
1761
- parent = mergeCandidateParentsForHoistableInst (parent, operandParent);
1762
- }
1763
-
1764
- if (inst->getFullType ())
1765
- {
1766
- parent = mergeCandidateParentsForHoistableInst (parent, inst->getFullType ()->getParent ());
1767
- }
1761
+ IRInst* parent = getParentOfHoistableInst (builder, inst);
1768
1762
1769
1763
inst->insertAtEnd (parent);
1770
1764
}
@@ -2648,7 +2642,7 @@ IRInst* IRBuilder::_findOrEmitHoistableInst(
2648
2642
// In order to de-duplicate them, Witness-table is marked as Hoistable.
2649
2643
// But it is not exactly a hoistable type and it can be added simpler.
2650
2644
if (inst->getOp () == kIROp_WitnessTable )
2651
- addInst ( inst);
2645
+ addDeduplicatedInst ( this , inst);
2652
2646
else
2653
2647
addHoistableInst (this , inst);
2654
2648
}
0 commit comments