Basic Blocks & Flow Graphs | Compiler Design - Computer Science Engineering (CSE) PDF Download

Basic Blocks


The characteristics of basic blocks are-

  • They do not contain any kind of jump statements in them.
  • There is no possibility of branching or getting halt in the middle.
  • All the statements execute in the same order they appear.
  • They do not lose lose the flow control of the program.

Example of Basic Block
Three Address Code for the expression a = b + c + d is-
Basic Blocks & Flow Graphs | Compiler Design - Computer Science Engineering (CSE)

Here,

  • All the statements execute in a sequence one after the other.
  • Thus, they form a basic block.

Example of Not a Basic Block
Three Address Code for the expression If A<B then 1 else 0 is-
Basic Blocks & Flow Graphs | Compiler Design - Computer Science Engineering (CSE)

Here,

  • The statements do not execute in a sequence one after the other.
  • Thus, they do not form a basic block.

Partitioning Intermediate Code Into Basic Blocks

Any given code can be partitioned into basic blocks using the following rules-

Rule 1: Determining Leaders
Following statements of the code are called as Leaders

  • First statement of the code.
  • Statement that is a target of the conditional or unconditional goto statement.
  • Statement that appears immediately after a goto statement.

Rule 2: Determining Basic Blocks

  • All the statements that follow the leader (including the leader) till the next leader appears form one basic block.
  • The first statement of the code is called as the first leader.
  • The block containing the first leader is called as Initial block.

Flow Graphs


A flow graph is a directed graph with flow control information added to the basic blocks.

  • The basic blocks serve as nodes of the flow graph.
  • There is a directed edge from block B1 to block B2 if B2 appears immediately after B1 in the code.

Problems Based on Basic Blocks & Flow Graphs


Problem 1: Compute the basic blocks for the given three address statements-

  1. PROD = 0
  2. I = 1
  3. T2 = addr(A) – 4
  4. T4 = addr(B) – 4
  5. T1 = 4 x I
  6. T3 = T2[T1]
  7. T5 = T4[T1]
  8. T6 = T3 x T5
  9. PROD = PROD + T6
  10. I = I + 1
  11. IF I <=20 GOTO (5)

We have-

  • PROD = 0 is a leader since first statement of the code is a leader.
  • T1 = 4 x I is a leader since target of the conditional goto statement is a leader.

Now, the given code can be partitioned into two basic blocks as-
Basic Blocks & Flow Graphs | Compiler Design - Computer Science Engineering (CSE)


Problem 2: Draw a flow graph for the three address statements given in problem-01.

  • Firstly, we compute the basic blocks (already done above).
  • Secondly, we assign the flow control information.

The required flow graph is
Basic Blocks & Flow Graphs | Compiler Design - Computer Science Engineering (CSE)

The document Basic Blocks & Flow Graphs | Compiler Design - Computer Science Engineering (CSE) is a part of the Computer Science Engineering (CSE) Course Compiler Design.
All you need of Computer Science Engineering (CSE) at this link: Computer Science Engineering (CSE)
26 videos|66 docs|30 tests

Top Courses for Computer Science Engineering (CSE)

26 videos|66 docs|30 tests
Download as PDF
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev
Related Searches

study material

,

Extra Questions

,

Objective type Questions

,

video lectures

,

Summary

,

shortcuts and tricks

,

mock tests for examination

,

MCQs

,

Important questions

,

practice quizzes

,

Basic Blocks & Flow Graphs | Compiler Design - Computer Science Engineering (CSE)

,

Previous Year Questions with Solutions

,

Free

,

pdf

,

Basic Blocks & Flow Graphs | Compiler Design - Computer Science Engineering (CSE)

,

past year papers

,

Exam

,

Viva Questions

,

Basic Blocks & Flow Graphs | Compiler Design - Computer Science Engineering (CSE)

,

Sample Paper

,

ppt

,

Semester Notes

;