SlideShare a Scribd company logo
G r e a t
M a t e s
W E L C O M E !
Thank you for coming today!
Fazle Rabbi Khan
161-15-6917
4
BASIC BLOCKS ANDFLOW
GRAPHS
5
What is Basic Blocks?
A basic block is a sequence of consecutive instructions
which are always executed in sequence without halt or
possibility of branching.
6
Type of Basic Blocks
Basic Blocks
Transformations on Basic Blocks
Structure preserving Transformations
Algebraic transformations
Representation of Basic Blocks
7
Steps of Basic Blocks
Introduce a graph representation of three address statement that is helpful
for discussing code generation.
Nodes in flow graph – Computation
Edges in flow graph – Control Flow
Register Assignment to find inner loop flow control is used.
 Partition the intermediate code into basic blocks
 The basic blocks become the nodes of a flow graph, whose edges indicate which blocks can follow
which other blocks.
8
Basic Blocks
B2:
The flow graph for the above three address code is givenbelow:
B1:
PROD = 0
I = 1
T2=addr(A)-4
T4 =addr(B)-4
T1 =4*I
T3= T2[T1]
T5 = T4[T1]
T6 =T3*T5
PROD =PROD + T6
I =I+1
IF I<= 20 GOTO B2
Abdur Rahman
162-15-7749
10
Basic Blocks ConstructionAlgorithm.
Algorithm: Partitioning three-address instructions into basic
blocks.
INPUT: A sequence of three-address instructions.
OUTPUT: A list of the basic blocks for that sequence in which
each instruction is assigned to exactly one basic block.
11
Basic Blocks
Find the leaders
Basic Blocks
13
Follow Diagram
14
H.M Nasim
161-15-7365
15
Transformations on Basic Blocks
■ A code-improving transformation is a code optimization to improve speed or reduce code size.
■ Global transformations are performed across basic blocks.
■ Local transformations are only performed on single basic blocks.
■ Transformations must be safe and preserve the meaning of the code .
■ A local transformation is safe if the transformed basic block is guaranteed to be equivalent to its
original form
16
Transformations on Basic Blocks
LocalTransformation
Some local transformation are:
Common-
Subexpression
Elimination
Dead Code Elimination
Renaming Temporary
Variables
Interchange of
Statements
Algebraic
Transformations
17
Common-Subexpression Elimination
■ Remove redundant computations
■ 2nd and 4th:compute same expression in fig:1(a)
■ Look at 1st and 3rd in fig:1(b) :b is redefine in 2nd therefore different in3rd, not the same
expression
fig:1(a) fig:1(b)
a := b + c b
:= a - d c := b
+ c d := a - d
a := b + c b
:= a - d c := b
+ c d := b
t1 := b * c t2 :=
a - t1 t3 := b * c
t4 := t2 + t3
t1 := b * c t2 :=
a - t1 t4 := t2 +
t1
18
Sukanta Dey
161-15-7259
Dead Code Elimination
■ Remove unused statements
Assuming a is dead (not used)
Remove unreachable code
b := a + 1
a := b + c
…
b := a + 1
…
goto L2
b := x + y
…
Renaming Temporary Variables
■ Temporary variables that are dead at the end of a block can be safely
renamed.
■ The basic block is transforms into an equivalent block in which each statement
that
defines a temporary defines a new temporary.
■ Such a basic block is called normal-form block or simple block.
Normal-form block
■ Note that normal-form blocks permit all statement interchanges
that arepossible.
t1 := b + c
t2 := a - t1
t1 := t1 * d
d := t2 + t1
t1 := b + c
t2 := a - t1
t3 := t1 * d
d := t2 + t3
Interchange of Statements
■ Independent statements can be reordered without effecting the value of block to
make its optimal use.
■ Note that normal-form blocks permit all statement interchanges that are
possible
t1 := b + c
t2 := a - t1
t3 := t1 * d
d := t2 + t3
t1 := b + c
t3 := t1 * d
t2 := a - t1
d := t2 + t3
22
OVI modak
162-15-7795
Algebraic Transformations
■ Change arithmetic operations to transform blocks to algebraic equivalent
forms.
■ Simplify expression or replace expensive expressions by cheaper ones.
■ In statement 3,usually require a function call
■ Transforms to simple and equivalent statement
t1 := a - a
t2 := b + t1
t3 := t2 **2
t1 := 0
t2 := b
t3 := t2 * t2
24
Representation of Basic Blocks
Variety of data structures.
Quadruples are used with pointers.
Jumping from one block to another block with conditional and
unconditional jumps.
Block B finishes the code then B’ is continued
Block B’ reaches last line then control goes back to the beginning of B’.
25
L O O P S o f D i a g r a mN o . 1
N o . 2
N o . 3
Loop contains no other loop is
called inner loop.
The collection of node has unique entry
All node in the collection are strongly connected.
26
• Google.com
• Wikipedia .
• Slide Shares.com
• Online.Visual-paradiagram.com
• Youtube.com
Reference & Tools
T H A N K Y O U !
A N Y Q U E S T I O N S ?

More Related Content

PDF
Intermediate code generation
PPTX
Back patching
PPTX
Register allocation and assignment
PPTX
Top down parsing
PPTX
Optimization of basic blocks
PPTX
Three Address code
PPT
Ll(1) Parser in Compilers
PPTX
Three address code In Compiler Design
Intermediate code generation
Back patching
Register allocation and assignment
Top down parsing
Optimization of basic blocks
Three Address code
Ll(1) Parser in Compilers
Three address code In Compiler Design

What's hot (20)

PDF
Code optimization in compiler design
PPTX
Stressen's matrix multiplication
PPTX
Basic Blocks and Flow Graphs
PDF
Dataflow Analysis
PDF
Query trees
PDF
Syntax Directed Definition and its applications
PPT
Chapter 6 intermediate code generation
PDF
Compiler Design- Machine Independent Optimizations
PPT
Time complexity
PDF
Daa notes 1
PPTX
Lexical Analysis - Compiler Design
PPTX
Principle source of optimazation
PPTX
COMPILER DESIGN
PPTX
Bruteforce algorithm
DOC
Time and space complexity
PPTX
Ambiguous & Unambiguous Grammar
PDF
Intermediate code generation in Compiler Design
PPT
17. Recovery System in DBMS
PPTX
sum of subset problem using Backtracking
Code optimization in compiler design
Stressen's matrix multiplication
Basic Blocks and Flow Graphs
Dataflow Analysis
Query trees
Syntax Directed Definition and its applications
Chapter 6 intermediate code generation
Compiler Design- Machine Independent Optimizations
Time complexity
Daa notes 1
Lexical Analysis - Compiler Design
Principle source of optimazation
COMPILER DESIGN
Bruteforce algorithm
Time and space complexity
Ambiguous & Unambiguous Grammar
Intermediate code generation in Compiler Design
17. Recovery System in DBMS
sum of subset problem using Backtracking
Ad

Similar to Basic blocks - compiler design (20)

PPTX
Basic blocks and control flow graphs
PPTX
PPTX
UNIT V - Compiler Design notes power point presentation
PPT
457418.-Compiler-Design-Code-optimization.ppt
PPTX
Compiler Design_Code generation techniques.pptx
PDF
Code optimization lecture
PPT
unit-5.pptvshvshshhshsjjsjshhshshshhshsj
PPT
Compiler Design Unit 5
PPT
Code Generations - 1 compiler design.ppt
PPTX
Dag representation of basic blocks
PPTX
Principal Sources of Optimization in compiler design
PPTX
Compiler Design theory and various phases of compiler.pptx
PPT
Intermediate code generation
PPTX
Basic Block
PPT
456589.-Compiler-Design-Code-Generation (1).ppt
PDF
Compiler unit 4
PPT
PRESENTATION ON DATA STRUCTURE AND THEIR TYPE
PPT
456589.-Compiler-Design-Code-Generation (1).ppt
PPTX
Code optmize.pptx which is related to coding
Basic blocks and control flow graphs
UNIT V - Compiler Design notes power point presentation
457418.-Compiler-Design-Code-optimization.ppt
Compiler Design_Code generation techniques.pptx
Code optimization lecture
unit-5.pptvshvshshhshsjjsjshhshshshhshsj
Compiler Design Unit 5
Code Generations - 1 compiler design.ppt
Dag representation of basic blocks
Principal Sources of Optimization in compiler design
Compiler Design theory and various phases of compiler.pptx
Intermediate code generation
Basic Block
456589.-Compiler-Design-Code-Generation (1).ppt
Compiler unit 4
PRESENTATION ON DATA STRUCTURE AND THEIR TYPE
456589.-Compiler-Design-Code-Generation (1).ppt
Code optmize.pptx which is related to coding
Ad

Recently uploaded (20)

PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
Digital Logic Computer Design lecture notes
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
composite construction of structures.pdf
PPTX
Sustainable Sites - Green Building Construction
PPTX
additive manufacturing of ss316l using mig welding
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
CH1 Production IntroductoryConcepts.pptx
PDF
Well-logging-methods_new................
PDF
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPT
Project quality management in manufacturing
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
PPTX
web development for engineering and engineering
PDF
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Digital Logic Computer Design lecture notes
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
composite construction of structures.pdf
Sustainable Sites - Green Building Construction
additive manufacturing of ss316l using mig welding
CYBER-CRIMES AND SECURITY A guide to understanding
CH1 Production IntroductoryConcepts.pptx
Well-logging-methods_new................
PRIZ Academy - 9 Windows Thinking Where to Invest Today to Win Tomorrow.pdf
Model Code of Practice - Construction Work - 21102022 .pdf
Project quality management in manufacturing
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
OOP with Java - Java Introduction (Basics)
bas. eng. economics group 4 presentation 1.pptx
IOT PPTs Week 10 Lecture Material.pptx of NPTEL Smart Cities contd
web development for engineering and engineering
July 2025 - Top 10 Read Articles in International Journal of Software Enginee...
Embodied AI: Ushering in the Next Era of Intelligent Systems

Basic blocks - compiler design

  • 1. G r e a t M a t e s
  • 2. W E L C O M E ! Thank you for coming today!
  • 5. 5 What is Basic Blocks? A basic block is a sequence of consecutive instructions which are always executed in sequence without halt or possibility of branching.
  • 6. 6 Type of Basic Blocks Basic Blocks Transformations on Basic Blocks Structure preserving Transformations Algebraic transformations Representation of Basic Blocks
  • 7. 7 Steps of Basic Blocks Introduce a graph representation of three address statement that is helpful for discussing code generation. Nodes in flow graph – Computation Edges in flow graph – Control Flow Register Assignment to find inner loop flow control is used.  Partition the intermediate code into basic blocks  The basic blocks become the nodes of a flow graph, whose edges indicate which blocks can follow which other blocks.
  • 8. 8 Basic Blocks B2: The flow graph for the above three address code is givenbelow: B1: PROD = 0 I = 1 T2=addr(A)-4 T4 =addr(B)-4 T1 =4*I T3= T2[T1] T5 = T4[T1] T6 =T3*T5 PROD =PROD + T6 I =I+1 IF I<= 20 GOTO B2
  • 10. 10 Basic Blocks ConstructionAlgorithm. Algorithm: Partitioning three-address instructions into basic blocks. INPUT: A sequence of three-address instructions. OUTPUT: A list of the basic blocks for that sequence in which each instruction is assigned to exactly one basic block.
  • 15. 15 Transformations on Basic Blocks ■ A code-improving transformation is a code optimization to improve speed or reduce code size. ■ Global transformations are performed across basic blocks. ■ Local transformations are only performed on single basic blocks. ■ Transformations must be safe and preserve the meaning of the code . ■ A local transformation is safe if the transformed basic block is guaranteed to be equivalent to its original form
  • 16. 16 Transformations on Basic Blocks LocalTransformation Some local transformation are: Common- Subexpression Elimination Dead Code Elimination Renaming Temporary Variables Interchange of Statements Algebraic Transformations
  • 17. 17 Common-Subexpression Elimination ■ Remove redundant computations ■ 2nd and 4th:compute same expression in fig:1(a) ■ Look at 1st and 3rd in fig:1(b) :b is redefine in 2nd therefore different in3rd, not the same expression fig:1(a) fig:1(b) a := b + c b := a - d c := b + c d := a - d a := b + c b := a - d c := b + c d := b t1 := b * c t2 := a - t1 t3 := b * c t4 := t2 + t3 t1 := b * c t2 := a - t1 t4 := t2 + t1
  • 19. Dead Code Elimination ■ Remove unused statements Assuming a is dead (not used) Remove unreachable code b := a + 1 a := b + c … b := a + 1 … goto L2 b := x + y …
  • 20. Renaming Temporary Variables ■ Temporary variables that are dead at the end of a block can be safely renamed. ■ The basic block is transforms into an equivalent block in which each statement that defines a temporary defines a new temporary. ■ Such a basic block is called normal-form block or simple block. Normal-form block ■ Note that normal-form blocks permit all statement interchanges that arepossible. t1 := b + c t2 := a - t1 t1 := t1 * d d := t2 + t1 t1 := b + c t2 := a - t1 t3 := t1 * d d := t2 + t3
  • 21. Interchange of Statements ■ Independent statements can be reordered without effecting the value of block to make its optimal use. ■ Note that normal-form blocks permit all statement interchanges that are possible t1 := b + c t2 := a - t1 t3 := t1 * d d := t2 + t3 t1 := b + c t3 := t1 * d t2 := a - t1 d := t2 + t3
  • 23. Algebraic Transformations ■ Change arithmetic operations to transform blocks to algebraic equivalent forms. ■ Simplify expression or replace expensive expressions by cheaper ones. ■ In statement 3,usually require a function call ■ Transforms to simple and equivalent statement t1 := a - a t2 := b + t1 t3 := t2 **2 t1 := 0 t2 := b t3 := t2 * t2
  • 24. 24 Representation of Basic Blocks Variety of data structures. Quadruples are used with pointers. Jumping from one block to another block with conditional and unconditional jumps. Block B finishes the code then B’ is continued Block B’ reaches last line then control goes back to the beginning of B’.
  • 25. 25 L O O P S o f D i a g r a mN o . 1 N o . 2 N o . 3 Loop contains no other loop is called inner loop. The collection of node has unique entry All node in the collection are strongly connected.
  • 26. 26 • Google.com • Wikipedia . • Slide Shares.com • Online.Visual-paradiagram.com • Youtube.com Reference & Tools
  • 27. T H A N K Y O U ! A N Y Q U E S T I O N S ?