From 216dfba0af66210a46ef0df18beb73d975fdf727 Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 19 Dec 2022 11:47:19 -0800 Subject: Separate primal computations from unzipped function into an explicit function. (#2569) Co-authored-by: Yong He --- source/slang/slang-ir-ssa-simplification.cpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'source/slang/slang-ir-ssa-simplification.cpp') diff --git a/source/slang/slang-ir-ssa-simplification.cpp b/source/slang/slang-ir-ssa-simplification.cpp index f723325c4..4b604e03a 100644 --- a/source/slang/slang-ir-ssa-simplification.cpp +++ b/source/slang/slang-ir-ssa-simplification.cpp @@ -10,8 +10,6 @@ namespace Slang { - struct IRModule; - // Run a combination of SSA, SCCP, SimplifyCFG, and DeadCodeElimination pass // until no more changes are possible. void simplifyIR(IRModule* module) @@ -37,4 +35,27 @@ namespace Slang iterationCounter++; } } + + void simplifyFunc(IRGlobalValueWithCode* func) + { + bool changed = true; + const int kMaxIterations = 8; + int iterationCounter = 0; + while (changed && iterationCounter < kMaxIterations) + { + changed = false; + changed |= applySparseConditionalConstantPropagation(func); + changed |= peepholeOptimize(func); + changed |= simplifyCFG(func); + + // Note: we disregard the `changed` state from dead code elimination pass since + // SCCP pass could be generating temporarily evaluated constant values and never actually use them. + // DCE will always remove those nearly generated consts and always returns true here. + eliminateDeadCode(func); + + changed |= constructSSA(func); + + iterationCounter++; + } + } } -- cgit v1.2.3