Lably
Skip to content

Control-flow graph

Graphical representation of a computer program or algorithm

  • 23 min read
  • 11 chapters

Related on Lably

Through Computer science, Directed graph and Function (computer programming)

The CFG is essential to many compiler optimizations and static-analysis tools.

Definition

A control flow graph is the directed graph of the basic blocks of the function (the nodes of the graph) and the control flow between them (the edges of the graph).

The exact details vary between representations. Typically, a basic block consists of a straight-line sequence of instructions or statements. Only the last instruction or statement in each block can perform control flow, and control flow can only be directed to the first instruction or statement in a block.

In most CFG representations, there are two specially designated blocks: the entry block, through which control enters into the function, and the exit block, through which all control exits the function (typically by returning). Some representations permit multiple exit blocks, especially if there are different kinds of exit, or permit the exit block to be omitted if it is not reachable .

If there is a control-flow edge from block A to block B, then A is called a predecessor of B, and B is called a successor of A.

Sign in to keep reading

10 more chapters are free with a Lably account.

More in Computing and communication