SlideShare ist ein Scribd-Unternehmen logo
1 von 27
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 ?

Weitere ähnliche Inhalte

Was ist angesagt?

Code Optimization
Code OptimizationCode Optimization
Code Optimization
guest9f8315
 

Was ist angesagt? (20)

Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler Design
 
Three Address code
Three Address code Three Address code
Three Address code
 
Types of Parser
Types of ParserTypes of Parser
Types of Parser
 
Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)   Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
1.Role lexical Analyzer
1.Role lexical Analyzer1.Role lexical Analyzer
1.Role lexical Analyzer
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
Regular expressions-Theory of computation
Regular expressions-Theory of computationRegular expressions-Theory of computation
Regular expressions-Theory of computation
 
Bubble sort
Bubble sortBubble sort
Bubble sort
 
LR Parsing
LR ParsingLR Parsing
LR Parsing
 
Parsing
ParsingParsing
Parsing
 
Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler design
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
 
Unit iv(simple code generator)
Unit iv(simple code generator)Unit iv(simple code generator)
Unit iv(simple code generator)
 
Three address code generation
Three address code generationThree address code generation
Three address code generation
 
Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design Syntax Analysis in Compiler Design
Syntax Analysis in Compiler Design
 
Intermediate code generator
Intermediate code generatorIntermediate code generator
Intermediate code generator
 
Top down parsing
Top down parsingTop down parsing
Top down parsing
 
Lecture 12 intermediate code generation
Lecture 12 intermediate code generationLecture 12 intermediate code generation
Lecture 12 intermediate code generation
 
Code generation in Compiler Design
Code generation in Compiler DesignCode generation in Compiler Design
Code generation in Compiler Design
 

Ähnlich wie Basic blocks - compiler design

DLD Lecture No 18 Analysis and Design of Combinational Circuit.pptx
DLD Lecture No 18 Analysis and Design of Combinational Circuit.pptxDLD Lecture No 18 Analysis and Design of Combinational Circuit.pptx
DLD Lecture No 18 Analysis and Design of Combinational Circuit.pptx
SaveraAyub2
 
Mcs 10 104 compiler design dec 2014
Mcs 10 104 compiler design dec 2014Mcs 10 104 compiler design dec 2014
Mcs 10 104 compiler design dec 2014
Sreeju Sree
 

Ähnlich wie Basic blocks - compiler design (20)

Basic blocks and control flow graphs
Basic blocks and control flow graphsBasic blocks and control flow graphs
Basic blocks and control flow graphs
 
Bp150520
Bp150520Bp150520
Bp150520
 
Code optimization lecture
Code optimization lectureCode optimization lecture
Code optimization lecture
 
Code Optimization.ppt
Code Optimization.pptCode Optimization.ppt
Code Optimization.ppt
 
CS540-2-lecture11 - Copy.ppt
CS540-2-lecture11 - Copy.pptCS540-2-lecture11 - Copy.ppt
CS540-2-lecture11 - Copy.ppt
 
Lec6 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Instruction...
Lec6 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Instruction...Lec6 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Instruction...
Lec6 Computer Architecture by Hsien-Hsin Sean Lee Georgia Tech -- Instruction...
 
Compiler Design Unit 5
Compiler Design Unit 5Compiler Design Unit 5
Compiler Design Unit 5
 
Code optimisation presnted
Code optimisation presntedCode optimisation presnted
Code optimisation presnted
 
Compiler unit 4
Compiler unit 4Compiler unit 4
Compiler unit 4
 
Ec2203 digital electronics questions anna university by www.annaunivedu.org
Ec2203 digital electronics questions anna university by www.annaunivedu.orgEc2203 digital electronics questions anna university by www.annaunivedu.org
Ec2203 digital electronics questions anna university by www.annaunivedu.org
 
Code optimization
Code optimizationCode optimization
Code optimization
 
Code optimization
Code optimizationCode optimization
Code optimization
 
Principal Sources of Optimization in compiler design
Principal Sources of Optimization in compiler design Principal Sources of Optimization in compiler design
Principal Sources of Optimization in compiler design
 
Basic Block
Basic BlockBasic Block
Basic Block
 
FYBSC IT Digital Electronics Unit III Chapter I Combinational Logic Circuits
FYBSC IT Digital Electronics Unit III Chapter I Combinational Logic CircuitsFYBSC IT Digital Electronics Unit III Chapter I Combinational Logic Circuits
FYBSC IT Digital Electronics Unit III Chapter I Combinational Logic Circuits
 
DLD Lecture No 18 Analysis and Design of Combinational Circuit.pptx
DLD Lecture No 18 Analysis and Design of Combinational Circuit.pptxDLD Lecture No 18 Analysis and Design of Combinational Circuit.pptx
DLD Lecture No 18 Analysis and Design of Combinational Circuit.pptx
 
guia de referencia para a linguagem do fabricante CCS info_syntax.pdf
guia de referencia para a linguagem do fabricante CCS info_syntax.pdfguia de referencia para a linguagem do fabricante CCS info_syntax.pdf
guia de referencia para a linguagem do fabricante CCS info_syntax.pdf
 
Mcs 10 104 compiler design dec 2014
Mcs 10 104 compiler design dec 2014Mcs 10 104 compiler design dec 2014
Mcs 10 104 compiler design dec 2014
 
unit-3.pptx
unit-3.pptxunit-3.pptx
unit-3.pptx
 
A109210503 digitallogicdesign1
A109210503 digitallogicdesign1A109210503 digitallogicdesign1
A109210503 digitallogicdesign1
 

Kürzlich hochgeladen

notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
MsecMca
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Christo Ananth
 

Kürzlich hochgeladen (20)

The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
The Most Attractive Pune Call Girls Manchar 8250192130 Will You Miss This Cha...
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
notes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.pptnotes on Evolution Of Analytic Scalability.ppt
notes on Evolution Of Analytic Scalability.ppt
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar  ≼🔝 Delhi door step de...
Call Now ≽ 9953056974 ≼🔝 Call Girls In New Ashok Nagar ≼🔝 Delhi door step de...
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...Bhosari ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For ...
Bhosari ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For ...
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 

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 ?