Basic Blocks in Compiler Design

Basic Block is a straight line code sequence which has no branches in and out branches except to the entry and at the end respectively. Basic Block is a set of statements which always executes one after other, in a sequence.

The first task is to partition a sequence of three-address code into basic blocks. A new basic block is begun with the first instruction and instructions are added until a jump or a label is met. In the absence of jump control moves further consecutively from one instruction to another. The idea is standardized in the algorithm below:

Partitioning three-address code into basic blocks.

Input: A sequence of three address instructions.

Process: Instructions from intermediate code which are leaders are determined. Following are the rules used for finding leader:

  1. The first three-address instruction of the intermediate code is a leader.
  2. Instructions which are targets of jump or conditional jump are leaders.
  3. Instructions which immediately follows jump are considered as leaders.

For each leader thus determined its basic block contains itself and all instructions up to excluding the next leader.

Intermediate code to set a 10*10 matrix to an identity matrix:

1)  i=1
2)  j=1
3)  t1 = 10 * i
4)  t2 = t1 + j
5)  t3 = 8 * t2
6)  t4 = t3 - 88
7)  a[t4] = 0.0
8)  j = j + 1
9)  if j <= goto (3)
10) i = i + 1
11) if i <= 10 goto (2)
12) i = 1
13) t5 = i - 1
14) t6 = 88 * t5
15) a[t6] = 1.0
16) i = i + 1
17) if i <= 10 goto (13) 

The given algorithm is used to convert a matrix into identity matrix i.e. a matrix with all diagonal elements 0 and all other elements as 1. Steps (3)-(6) are used to make elements 0 and step(14) is used to make an element 1. These steps are used recursively by goto.

GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :

Be the First to upvote.

Please write to us at to report any issue with the above content.