Skip to content

Commit ae42738

Browse files
authored
Non-Recursive CFG DFS. (shader-slang#2953)
Co-authored-by: Yong He <yhe@nvidia.com>
1 parent c5b0708 commit ae42738

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

source/slang/slang-ir-dominators.cpp

+21-4
Original file line numberDiff line numberDiff line change
@@ -279,16 +279,33 @@ struct DepthFirstSearchContext
279279
template<typename SuccessorFunc>
280280
void walk(IRBlock* block, const SuccessorFunc& getSuccessors)
281281
{
282+
List<IRBlock*> nodeStack;
283+
nodeStack.add(block);
282284
visited.add(block);
283285
preVisit(block);
284-
for(auto succ : getSuccessors(block))
286+
287+
while (nodeStack.getCount())
285288
{
286-
if(!visited.contains(succ))
289+
auto curNode = nodeStack.getLast();
290+
bool pushedChild = false;
291+
for (auto succ : getSuccessors(curNode))
292+
{
293+
if (!visited.contains(succ))
294+
{
295+
pushedChild = true;
296+
nodeStack.add(succ);
297+
visited.add(succ);
298+
299+
preVisit(succ);
300+
break;
301+
}
302+
}
303+
if (!pushedChild)
287304
{
288-
walk(succ, getSuccessors);
305+
postVisit(curNode);
306+
nodeStack.removeLast();
289307
}
290308
}
291-
postVisit(block);
292309
}
293310

294311
/// Overridable action to perform on first entering a CFG node.

0 commit comments

Comments
 (0)