summaryrefslogtreecommitdiff
path: root/source/slang/slang-ir-sccp.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-07-19 13:50:49 -0700
committerGitHub <noreply@github.com>2023-07-19 13:50:49 -0700
commit1cfb1c85b52e00cde2d21874a88cda2c22d18b62 (patch)
treea38b24534d865ffe33a3d0fc030f5449ba729e28 /source/slang/slang-ir-sccp.cpp
parent1fe5e83f3dcc8ef0efa2dd083ebdfab5d0f101a9 (diff)
Optimize specialization, and remove unnecessary calls to `simplifyIR`. (#2999)
* Remove unneccessary calls to `simplifyIR`. * fix. * Delete obsolete hoistConst pass. * Fix. * Small improvements. * Fix. * Fix enum lowering. * fix * tweaks. * tweaks. --------- Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-ir-sccp.cpp')
-rw-r--r--source/slang/slang-ir-sccp.cpp36
1 files changed, 32 insertions, 4 deletions
diff --git a/source/slang/slang-ir-sccp.cpp b/source/slang/slang-ir-sccp.cpp
index d5e4c6e99..ce635dca8 100644
--- a/source/slang/slang-ir-sccp.cpp
+++ b/source/slang/slang-ir-sccp.cpp
@@ -1248,12 +1248,30 @@ struct SCCPContext
}
}
- // Run the constant folding on global scope only.
+ // Run the constant folding on global scope and specialized types only.
bool applyOnGlobalScope(IRModule* module)
{
- builderStorage = IRBuilder(shared->module);
+ bool changed = applyOnScope(module->getModuleInst());
for (auto child : module->getModuleInst()->getChildren())
{
+ switch (child->getOp())
+ {
+ case kIROp_StructType:
+ case kIROp_ClassType:
+ case kIROp_InterfaceType:
+ case kIROp_WitnessTable:
+ changed |= applyOnScope(child);
+ break;
+ }
+ }
+ return changed;
+ }
+
+ bool applyOnScope(IRInst* scopeInst)
+ {
+ builderStorage = IRBuilder(scopeInst);
+ for (auto child : scopeInst->getChildren())
+ {
// Only consider evaluable opcodes.
if (!isEvaluableOpCode(child->getOp()))
continue;
@@ -1265,7 +1283,7 @@ struct SCCPContext
auto inst = ssaWorkList[0];
ssaWorkList.fastRemoveAt(0);
// Only consider evaluable opcodes and insts at global scope.
- if (!isEvaluableOpCode(inst->getOp()) || inst->getParent() != module->getModuleInst())
+ if (!isEvaluableOpCode(inst->getOp()) || inst->getParent() != scopeInst)
continue;
updateValueForInst(inst);
}
@@ -1273,7 +1291,7 @@ struct SCCPContext
bool changed = false;
// Replace the insts with their values.
List<IRInst*> instsToRemove;
- for (auto child : module->getModuleInst()->getChildren())
+ for (auto child : scopeInst->getChildren())
{
if (!isEvaluableOpCode(child->getOp()))
continue;
@@ -1670,6 +1688,16 @@ static bool applySparseConditionalConstantPropagationRec(
for( auto childInst : inst->getDecorationsAndChildren() )
{
+ switch (childInst->getOp())
+ {
+ case kIROp_Func:
+ case kIROp_Block:
+ case kIROp_Generic:
+ break;
+ default:
+ // Skip other op codes.
+ continue;
+ }
changed |= applySparseConditionalConstantPropagationRec(globalContext, childInst);
}
return changed;