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.
This doc is part of
26 videos|67 docs|30 tests
Join course for free

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.
Download the notes
Basic Blocks & Flow Graphs
Download as PDF
Download as PDF

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)
Are you preparing for Computer Science Engineering (CSE) Exam? Then you should check out the best video lectures, notes, free mock test series, crash course and much more provided by EduRev. You also get your detailed analysis and report cards along with 24x7 doubt solving for you to excel in Computer Science Engineering (CSE) exam. So join EduRev now and revolutionise the way you learn!
Sign up for Free Download App for Free
26 videos|67 docs|30 tests

Up next

26 videos|67 docs|30 tests
Download as PDF

Up next

Explore Courses for Computer Science Engineering (CSE) exam
Related Searches

Viva Questions

,

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

,

Objective type Questions

,

Exam

,

shortcuts and tricks

,

Free

,

Semester Notes

,

mock tests for examination

,

pdf

,

ppt

,

video lectures

,

past year papers

,

Summary

,

Sample Paper

,

Extra Questions

,

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

,

Important questions

,

Previous Year Questions with Solutions

,

study material

,

practice quizzes

,

MCQs

,

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

;