Custom DFS implementation allows us to skip over certain nodes without adding them to the visited map, which is not easily doable with llvm's dfs iterators. What's more, caching predecessors becomes easy.
This patch implements a single DFS function (template) for both forward and reverse DFS, which should be easier to maintain then separate two ones.
Skipping over nodes based on a predicate will be necessary later to implement incremental updates.
There also seems to be a very slight performance improved when bootstrapping clang with this patch on my machine (3:28s -> 3:26s) .