Chapter 9: Code generation

Basic blocks

. sequence of statements in which flow of control enters at the beginning and leaves at the end

. Algorithm to identify basic blocks

. determine leader

- first statement is a leader

- any target of a goto statement is a leader

- any statement that follows a goto statement is a leader

. for each leader its basic block consists of the leader and all statements up to next leader

A basic block is a sequence of consecutive statements in which flow of control enters at the beginning and leaves at the end without halt or possibility of branching except at the end. The following algorithm can be used to partition a sequence of three-address statements into basic blocks:

1. We first determine the set of leaders, the first statements of basic blocks. The rules we use are the following:

. The first statement is a leader.

. Any statement that is the target of a conditional or unconditional goto is a leader.

. Any statement that immediately follows a goto or conditional goto statement is a leader.

2. For each leader, its basic block consists of the leader and all statements up to but not including the next leader or the end of the program.