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-peephole.cpp | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) (limited to 'source/slang/slang-ir-peephole.cpp') diff --git a/source/slang/slang-ir-peephole.cpp b/source/slang/slang-ir-peephole.cpp index 376795855..ac026b563 100644 --- a/source/slang/slang-ir-peephole.cpp +++ b/source/slang/slang-ir-peephole.cpp @@ -235,9 +235,6 @@ struct PeepholeContext : InstPassBase return false; } - RefPtr domTree; - IRGlobalValueWithCode* domTreeFunc = nullptr; - void processInst(IRInst* inst) { if (as(inst)) @@ -746,13 +743,8 @@ struct PeepholeContext : InstPassBase auto parentFunc = getParentFunc(inst); if (!parentFunc) break; - if (domTreeFunc != parentFunc) - { - domTree = computeDominatorTree(parentFunc); - domTreeFunc = parentFunc; - } - if (!domTree) - break; + + auto domTree = parentFunc->getModule()->findOrCreateDominatorTree(parentFunc); if (domTree->dominates(argValue, inst)) { @@ -816,6 +808,8 @@ struct PeepholeContext : InstPassBase bool processFunc(IRInst* func) { + func->getModule()->invalidateAllAnalysis(); + bool result = false; for (;;) { @@ -847,6 +841,22 @@ bool peepholeOptimize(IRInst* func) return context.processFunc(func); } +bool peepholeOptimizeGlobalScope(IRModule* module) +{ + PeepholeContext context = PeepholeContext(module); + bool result = false; + for (;;) + { + context.changed = false; + for (auto globalInst : module->getGlobalInsts()) + context.processInst(globalInst); + result |= context.changed; + if (!context.changed) + break; + } + return result; +} + bool tryReplaceInstUsesWithSimplifiedValue(IRModule* module, IRInst* inst) { if (inst != tryConstantFoldInst(module, inst)) -- cgit v1.2.3