File tree 1 file changed +21
-4
lines changed
1 file changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -279,16 +279,33 @@ struct DepthFirstSearchContext
279
279
template <typename SuccessorFunc>
280
280
void walk (IRBlock* block, const SuccessorFunc& getSuccessors)
281
281
{
282
+ List<IRBlock*> nodeStack;
283
+ nodeStack.add (block);
282
284
visited.add (block);
283
285
preVisit (block);
284
- for (auto succ : getSuccessors (block))
286
+
287
+ while (nodeStack.getCount ())
285
288
{
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)
287
304
{
288
- walk (succ, getSuccessors);
305
+ postVisit (curNode);
306
+ nodeStack.removeLast ();
289
307
}
290
308
}
291
- postVisit (block);
292
309
}
293
310
294
311
// / Overridable action to perform on first entering a CFG node.
You can’t perform that action at this time.
0 commit comments