πŸŽ“ Computer Science & Engineering Portal

Master Engineering Disciplines with Structured Notes

Comprehensive academic lecture notes, exam-oriented unit summaries, laboratory manuals, and previous year question papers designed strictly for university students.

πŸ“‘

University Syllabi

AKTU & AICTE aligned semester guidelines.

πŸ“

Exam Question Papers

Previous 5 years solved university papers.

πŸ’‘

Lab Manuals & Viva

Practical codes with outputs & interview Qs.

Core Subjects & Units Hub

Click on any specific unit to immediately view its lecture notes below

Viewing All Lectures

Basic Block

Basic Block

Basic block contains a sequence of statement. The flow of control enters at the beginning of the statement and leave at the end without any halt (except may be the last instruction of the block).

The following sequence of three address statements forms a basic block:

  1. t1:= x * x  
  2. t2:= x * y  
  3. t3:= 2 * t2  
  4. t4:= t1 + t3  
  5. t5:= y * y  
  6. t6:= t4 + t5  

Basic block construction:

Algorithm: Partition into basic blocks

Input: It contains the sequence of three address statements

Output: it contains a list of basic blocks with each three address statement in exactly one block

Method: First identify the leader in the code. The rules for finding leaders are as follows:

  • The first statement is a leader.
  • Statement L is a leader if there is an conditional or unconditional goto statement like: if....goto L or goto L
  • Instruction L is a leader if it immediately follows a goto or conditional goto statement like: if goto B or goto B

For each leader, its basic block consists of the leader and all statement up to. It doesn't include the next leader or end of the program.

Consider the following source code for dot product of two vectors a and b of length 10:

  1. begin   
  2.            prod :=0;   
  3. i:=1;   
  4. do begin   
  5. prod :=prod+ a[i] * b[i];   
  6. i :=i+1;   
  7. end   
  8. while i <= 10   
  9. end  

The three address code for the above source program is given below:

B1

  1. (1) prod := 0   
  2. (2) i := 1  

B2

  1. (3) t1 := 4* i   
  2. (4) t2 := a[t1]   
  3. (5) t3 := 4* i   
  4. (6) t4 := b[t3]   
  5. (7) t5 := t2*t4   
  6. (8) t6 := prod+t5   
  7. (9) prod := t6   
  8. (10)    t7 := i+1   
  9. (11)    i := t7   
  10. (12)    if i<=10 goto (3)      

Basic block B1 contains the statement (1) to (2)

Basic block B2 contains the statement (3) to (12)

Labels: ,

Discussion & Queries (<$I18NNumComments$>):

<$CommentPager$>
<$I18NAtCommentTimeWithPermalink$>, <$I18NCommentAuthorSaid$>

<$BlogCommentBody$>

<$BlogCommentDeleteIcon$>
<$CommentPager$>