Jump to content

Control-flow graph

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Hari (talk | contribs) at 20:58, 10 March 2002. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

A control flow graph (CFG) is used in compilers. It is an abstract representation of a program maintained internally by a compiler. Each node in the graph represents a basic block, i.e. a straight-line piece of code without any jumps or jump targets; jump targets start a block, and jumps end of a block. Directed edges are used to represent jumps in the control flow.

A CFG is a static representation of the program, and represents all alternatives of control flow. So, for example, both arms of an if statement are represented in the CFG. A cycle in a CFG implies that there is a loop in the code. This allows a compiler to detect non-syntactic loops (loops created with the goto statement).

The CFG is essential to several compiler optimizations, especially those using relaxation (def-use chaining, use-def chaining).