From 1cfb1c85b52e00cde2d21874a88cda2c22d18b62 Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 19 Jul 2023 13:50:49 -0700 Subject: 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 --- source/slang/slang-ir-sccp.cpp | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) (limited to 'source/slang/slang-ir-sccp.cpp') 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,11 +1248,29 @@ 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())) @@ -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 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; -- cgit v1.2.3