From 4dbc74a953ae1b34ce64a4eaef3aa7feb73663b9 Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 13 Feb 2023 10:38:14 -0800 Subject: Add Loop Unrolling Pass. (#2644) Co-authored-by: Yong He --- source/slang/slang-ir-dominators.cpp | 38 ++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 13 deletions(-) (limited to 'source/slang/slang-ir-dominators.cpp') diff --git a/source/slang/slang-ir-dominators.cpp b/source/slang/slang-ir-dominators.cpp index 1ffa7ba5d..5f606092b 100644 --- a/source/slang/slang-ir-dominators.cpp +++ b/source/slang/slang-ir-dominators.cpp @@ -276,29 +276,21 @@ struct DepthFirstSearchContext /// then recursively visit its (unvisited) successors, and /// then perform any post-actions. /// - void walk(IRBlock* block) + template + void walk(IRBlock* block, const SuccessorFunc& getSuccessors) { visited.Add(block); preVisit(block); - for(auto succ : block->getSuccessors()) + for(auto succ : getSuccessors(block)) { if(!visited.Contains(succ)) { - walk(succ); + walk(succ, getSuccessors); } } postVisit(block); } - /// Walk the blocks in a function (or other code-bearing value). - void walk(IRGlobalValueWithCode* code) - { - auto root = code->getFirstBlock(); - if(!root) - return; - walk(root); - } - /// Overridable action to perform on first entering a CFG node. virtual void preVisit(IRBlock* /*block*/) {} @@ -329,7 +321,8 @@ void computePostorder(IRGlobalValueWithCode* code, List& outOrder) { PostorderComputationContext context; context.order = &outOrder; - context.walk(code); + if (code->getFirstBlock()) + context.walk(code->getFirstBlock(), [](IRBlock* block) {return block->getSuccessors(); }); // Append unvisited blocks (unreachable blocks) to the begining of postOrder. List prefix; @@ -344,6 +337,25 @@ void computePostorder(IRGlobalValueWithCode* code, List& outOrder) outOrder = _Move(prefix); } +void computePostorderOnReverseCFG(IRGlobalValueWithCode* code, List& outOrder) +{ + PostorderComputationContext context; + context.order = &outOrder; + for (auto block = code->getLastBlock(); block; block = block->getPrevBlock()) + { + auto terminator = block->getTerminator(); + switch (terminator->getOp()) + { + case kIROp_Return: + case kIROp_MissingReturn: + case kIROp_Unreachable: + context.walk(block, [](IRBlock* b) {return b->getPredecessors(); }); + break; + } + } + return; +} + // // With the preliminaries out of the way, we are ready to implement // the dominator tree construction algorithm as described by Cooper, Harvey, and Kennedy. -- cgit v1.2.3