Skip to content

Commit 99b3f50

Browse files
committed
Revert "Simplfy addDeduplicatedInst into addInst"
This reverts commit d19ff64.
1 parent d19ff64 commit 99b3f50

File tree

1 file changed

+20
-26
lines changed

1 file changed

+20
-26
lines changed

source/slang/slang-ir.cpp

+20-26
Original file line numberDiff line numberDiff line change
@@ -1605,11 +1605,7 @@ static IRInst* pickLaterInstInSameParent(IRInst* left, IRInst* right)
16051605
}
16061606
}
16071607

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)
16131609
{
16141610
// Start with the assumption that we would insert this instruction
16151611
// into the global scope (the instruction that represents the module)
@@ -1643,6 +1639,17 @@ void addHoistableInst(IRBuilder* builder, IRInst* inst)
16431639
//
16441640
SLANG_ASSERT(parent);
16451641

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+
16461653
// Once we determine the parent instruction that the
16471654
// new instruction should be inserted into, we need
16481655
// to find an appropriate place to insert it.
@@ -1707,6 +1714,7 @@ void addHoistableInst(IRBuilder* builder, IRInst* inst)
17071714
// the operands of `inst` come from the same
17081715
// block that we insert after them.
17091716
//
1717+
UInt operandCount = inst->getOperandCount();
17101718
for (UInt ii = 0; ii < operandCount; ++ii)
17111719
{
17121720
auto operand = inst->getOperand(ii);
@@ -1742,29 +1750,15 @@ void addHoistableInst(IRBuilder* builder, IRInst* inst)
17421750
}
17431751
}
17441752

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)
17471758
{
17481759
SLANG_ASSERT(nullptr == inst->parent);
17491760

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);
17681762

17691763
inst->insertAtEnd(parent);
17701764
}
@@ -2648,7 +2642,7 @@ IRInst* IRBuilder::_findOrEmitHoistableInst(
26482642
// In order to de-duplicate them, Witness-table is marked as Hoistable.
26492643
// But it is not exactly a hoistable type and it can be added simpler.
26502644
if (inst->getOp() == kIROp_WitnessTable)
2651-
addInst(inst);
2645+
addDeduplicatedInst(this, inst);
26522646
else
26532647
addHoistableInst(this, inst);
26542648
}

0 commit comments

Comments
 (0)