Control-Flow Graph Definition

Related to traditional notion of flow charts

Example program 1:

while (i < 10) {
  println(j);
  i = i + 1;
  j = j +2*i + 1;
}

Corresponding control-flow graph:

CFG for Squaring

Example program 2:

int i = n;
while (i > 1) {
  println(i);
  if (i % 2 == 0) {
    i = i / 2;
  } else {
    i = 3*i + 1;
  }
}

Corresponding control-flow graph:

Control-Flow Graph

Definition: Control-Flow Graph (CFG) is graph $(V,E,L)$ where

Side Note:

In the example, what are V,E,L?

atomic expression = variable or a constant

ST statements are simple:

Notion of Basic Blocks: straight sequence of nodes (no jumps to or from the middle)