What Is a Control Flow Graph?
A control flow graph, or CFG, models a function as a directed graph whose nodes are basic blocks and whose edges represent possible transfers of control between them. Branches, loops, and fall-through become edges that capture every route execution might follow. Compilers analyze this graph to drive optimizations and detect properties like unreachable code.
Why it matters
The control flow graph is the structure most dataflow optimizations operate on, from dead code elimination to loop analysis. Seeing code as a graph of paths is what lets a compiler reason about all possible executions.
Related guides
What Is a Basic Block?A basic block is a straight-line sequence of instructions with one entry and one exit, used as the unit of an…
What Is Common Subexpression Elimination?Common subexpression elimination removes redundant computations by reusing a previously computed result inste…
What Is Loop-Invariant Code Motion?Loop-invariant code motion hoists computations whose result does not change across iterations out of a loop s…