summaryrefslogtreecommitdiff
path: root/source/slang/slang-ir-dominators.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-02-13 10:38:14 -0800
committerGitHub <noreply@github.com>2023-02-13 10:38:14 -0800
commit4dbc74a953ae1b34ce64a4eaef3aa7feb73663b9 (patch)
tree82b099c1074a0361b0db6a72e96f71d3b8e3b574 /source/slang/slang-ir-dominators.cpp
parent57af2c1c2fccb221fa54fd92415f424b1d7e5beb (diff)
Add Loop Unrolling Pass. (#2644)
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-ir-dominators.cpp')
-rw-r--r--source/slang/slang-ir-dominators.cpp38
1 files changed, 25 insertions, 13 deletions
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<typename SuccessorFunc>
+ 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<IRBlock*>& 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<IRBlock*> prefix;
@@ -344,6 +337,25 @@ void computePostorder(IRGlobalValueWithCode* code, List<IRBlock*>& outOrder)
outOrder = _Move(prefix);
}
+void computePostorderOnReverseCFG(IRGlobalValueWithCode* code, List<IRBlock*>& 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.