What algorithm is used by InstVisitor to traverse the basic blocks in CFG?

What algorithm is used by InstVisitor to traverse the basic blocks in CFG? I tried to print out the order of traversing the basic block, and found that it is neither DFS nor BFS, so what is it?

The code is here: LLVM: include/llvm/IR/InstVisitor.h Source File

It’s just iterating from Function::begin() to Function::end(), which I believe means it will visit the basic blocks in the order they were added to the function.

If you want a specific iteration order, there are utilities for that, for example LLVM: include/llvm/ADT/PostOrderIterator.h Source File

2 Likes

Thank you. That’s exactly what I need.