Control flow graph
Control flow graph (CFG) is a directed graph representation of a program in which nodes represent basic blocks — sequences of instructions with no branches except at the end — and edges represent possible transfers of control between blocks. It is the foundational data structure for both dataflow analysis and compiler optimization, providing the skeleton over which fixed-point computations propagate information and optimization passes identify transformation opportunities. The construction of a CFG from source code is one of the first tasks performed by a compiler after parsing, and its quality — whether exceptional edges, unreachable code, and irreducible loops are handled correctly — determines the correctness of every subsequent analysis.
The CFG abstracts away the linear sequence of instructions and exposes the program's branching structure, making explicit the paths that execution can take. This abstraction is what enables global optimization: without the CFG, an optimizer can only see local patterns; with it, the optimizer can reason about entire procedures. The dominance relationships in a CFG — which blocks must execute before others — are the basis for SSA form construction and for many advanced optimizations. The CFG is not merely a representation; it is the geometry of the program, and optimization is navigation on that geometry.