Skip to content
Latchkey

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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →