summaryrefslogtreecommitdiff
path: root/source/slang/slang-ir-deduplicate.cpp
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2024-10-29 14:49:26 +0800
committerGitHub <noreply@github.com>2024-10-29 14:49:26 +0800
commitf65d756bff8d4c5cbc15bd0322a2ae8e6b896a21 (patch)
treeea1d61342cd29368e19135000ec2948813096205 /source/slang/slang-ir-deduplicate.cpp
parenta729c15e9dce9f5116a38afc66329ab2ca4cea54 (diff)
format
* format * Minor test fixes * enable checking cpp format in ci
Diffstat (limited to 'source/slang/slang-ir-deduplicate.cpp')
-rw-r--r--source/slang/slang-ir-deduplicate.cpp110
1 files changed, 55 insertions, 55 deletions
diff --git a/source/slang/slang-ir-deduplicate.cpp b/source/slang/slang-ir-deduplicate.cpp
index 4579ae42b..8a4bc1910 100644
--- a/source/slang/slang-ir-deduplicate.cpp
+++ b/source/slang/slang-ir-deduplicate.cpp
@@ -2,80 +2,80 @@
namespace Slang
{
- void IRDeduplicationContext::init(IRModule* module)
- {
- m_module = module;
- m_session = module->getSession();
+void IRDeduplicationContext::init(IRModule* module)
+{
+ m_module = module;
+ m_session = module->getSession();
- m_globalValueNumberingMap.clear();
- m_constantMap.clear();
- }
+ m_globalValueNumberingMap.clear();
+ m_constantMap.clear();
+}
- void IRDeduplicationContext::removeHoistableInstFromGlobalNumberingMap(IRInst* instToRemove)
+void IRDeduplicationContext::removeHoistableInstFromGlobalNumberingMap(IRInst* instToRemove)
+{
+ InstHashSet userWorkListSet(instToRemove->getModule());
+ InstWorkList userWorkList(instToRemove->getModule());
+ auto addToWorkList = [&](IRInst* i)
{
- InstHashSet userWorkListSet(instToRemove->getModule());
- InstWorkList userWorkList(instToRemove->getModule());
- auto addToWorkList = [&](IRInst* i)
- {
- if (userWorkListSet.add(i))
- userWorkList.add(i);
- };
- addToWorkList(instToRemove);
- for (Index i = 0; i < userWorkList.getCount(); i++)
+ if (userWorkListSet.add(i))
+ userWorkList.add(i);
+ };
+ addToWorkList(instToRemove);
+ for (Index i = 0; i < userWorkList.getCount(); i++)
+ {
+ auto inst = userWorkList[i];
+ if (getIROpInfo(inst->getOp()).isHoistable())
{
- auto inst = userWorkList[i];
- if (getIROpInfo(inst->getOp()).isHoistable())
+ _removeGlobalNumberingEntry(inst);
+ for (auto use = inst->firstUse; use; use = use->nextUse)
{
- _removeGlobalNumberingEntry(inst);
- for (auto use = inst->firstUse; use; use = use->nextUse)
- {
- addToWorkList(use->getUser());
- }
+ addToWorkList(use->getUser());
}
}
}
+}
- void IRDeduplicationContext::tryHoistInst(IRInst* inst)
+void IRDeduplicationContext::tryHoistInst(IRInst* inst)
+{
+ InstWorkList workList(inst->getModule());
+ InstHashSet workListSet(inst->getModule());
+ workList.add(inst);
+ workListSet.add(inst);
+ IRBuilder builder(inst->getModule());
+
+ for (Index i = 0; i < workList.getCount(); i++)
{
- InstWorkList workList(inst->getModule());
- InstHashSet workListSet(inst->getModule());
- workList.add(inst);
- workListSet.add(inst);
- IRBuilder builder(inst->getModule());
+ auto item = workList[i];
- for (Index i = 0; i < workList.getCount(); i++)
+ // Does inst no longer depend on anything defined locally?
+ // If so we should hoist it.
+ bool shouldHoist = false;
+ for (UInt a = 0; a < item->getOperandCount(); a++)
{
- auto item = workList[i];
-
- // Does inst no longer depend on anything defined locally?
- // If so we should hoist it.
- bool shouldHoist = false;
- for (UInt a = 0; a < item->getOperandCount(); a++)
+ auto opParent = item->getOperand(a)->getParent();
+ if (opParent != item->getParent())
{
- auto opParent = item->getOperand(a)->getParent();
- if (opParent != item->getParent())
- {
- shouldHoist = true;
- break;
- }
+ shouldHoist = true;
+ break;
}
+ }
- // Hoisting this inst
- if (shouldHoist)
- {
- item->removeFromParent();
- addHoistableInst(&builder, item);
+ // Hoisting this inst
+ if (shouldHoist)
+ {
+ item->removeFromParent();
+ addHoistableInst(&builder, item);
- // Continue to consider all users for hoisting.
- for (auto use = item->firstUse; use; use = use->nextUse)
+ // Continue to consider all users for hoisting.
+ for (auto use = item->firstUse; use; use = use->nextUse)
+ {
+ if (getIROpInfo(use->getUser()->getOp()).isHoistable())
{
- if (getIROpInfo(use->getUser()->getOp()).isHoistable())
- {
- if (workListSet.add(use->getUser()))
- workList.add(use->getUser());
- }
+ if (workListSet.add(use->getUser()))
+ workList.add(use->getUser());
}
}
}
}
}
+} // namespace Slang