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

What's hot

Optimization of basic blocks
Optimization of basic blocksOptimization of basic blocks
Optimization of basic blocks
ishwarya516
 
Code Optimization
Code OptimizationCode Optimization
Code Optimizationguest9f8315
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generation
RamchandraRegmi
 
Lecture 12 intermediate code generation
Lecture 12 intermediate code generationLecture 12 intermediate code generation
Lecture 12 intermediate code generation
Iffat Anjum
 
Intermediate code generator
Intermediate code generatorIntermediate code generator
Intermediate code generator
sanchi29
 
Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)   Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)
Tasif Tanzim
 
Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler Design
Kuppusamy P
 
Instruction format
Instruction formatInstruction format
Instruction format
Sanjeev Patel
 
Yacc
YaccYacc
LR Parsing
LR ParsingLR Parsing
LR Parsing
Eelco Visser
 
Polish Notation In Data Structure
Polish Notation In Data StructurePolish Notation In Data Structure
Polish Notation In Data Structure
Meghaj Mallick
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
Dattatray Gandhmal
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
Akhil Kaushik
 
Register allocation and assignment
Register allocation and assignmentRegister allocation and assignment
Register allocation and assignment
Karthi Keyan
 
Unit iv(simple code generator)
Unit iv(simple code generator)Unit iv(simple code generator)
Unit iv(simple code generator)
Kalaimathi Vijayakumar
 
Type checking in compiler design
Type checking in compiler designType checking in compiler design
Type checking in compiler design
Sudip Singh
 
Dag representation of basic blocks
Dag representation of basic blocksDag representation of basic blocks
Dag representation of basic blocks
Jothi Lakshmi
 
Peephole Optimization
Peephole OptimizationPeephole Optimization
Peephole Optimization
United International University
 
Compiler Design Unit 5
Compiler Design Unit 5Compiler Design Unit 5
Compiler Design Unit 5
Jena Catherine Bel D
 
instruction cycle ppt
instruction cycle pptinstruction cycle ppt
instruction cycle pptsheetal singh
 

What's hot (20)

Optimization of basic blocks
Optimization of basic blocksOptimization of basic blocks
Optimization of basic blocks
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
Intermediate code generation
Intermediate code generationIntermediate code generation
Intermediate code generation
 
Lecture 12 intermediate code generation
Lecture 12 intermediate code generationLecture 12 intermediate code generation
Lecture 12 intermediate code generation
 
Intermediate code generator
Intermediate code generatorIntermediate code generator
Intermediate code generator
 
Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)   Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)
 
Intermediate code generation in Compiler Design
Intermediate code generation in Compiler DesignIntermediate code generation in Compiler Design
Intermediate code generation in Compiler Design
 
Instruction format
Instruction formatInstruction format
Instruction format
 
Yacc
YaccYacc
Yacc
 
LR Parsing
LR ParsingLR Parsing
LR Parsing
 
Polish Notation In Data Structure
Polish Notation In Data StructurePolish Notation In Data Structure
Polish Notation In Data Structure
 
Input-Buffering
Input-BufferingInput-Buffering
Input-Buffering
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
Register allocation and assignment
Register allocation and assignmentRegister allocation and assignment
Register allocation and assignment
 
Unit iv(simple code generator)
Unit iv(simple code generator)Unit iv(simple code generator)
Unit iv(simple code generator)
 
Type checking in compiler design
Type checking in compiler designType checking in compiler design
Type checking in compiler design
 
Dag representation of basic blocks
Dag representation of basic blocksDag representation of basic blocks
Dag representation of basic blocks
 
Peephole Optimization
Peephole OptimizationPeephole Optimization
Peephole Optimization
 
Compiler Design Unit 5
Compiler Design Unit 5Compiler Design Unit 5
Compiler Design Unit 5
 
instruction cycle ppt
instruction cycle pptinstruction cycle ppt
instruction cycle ppt
 

Similar to Basic blocks - compiler design

Code optimization lecture
Code optimization lectureCode optimization lecture
Code optimization lecture
Prashant Singh
 
Code Optimization.ppt
Code Optimization.pptCode Optimization.ppt
Code Optimization.ppt
JohnSamuel280314
 
CS540-2-lecture11 - Copy.ppt
CS540-2-lecture11 - Copy.pptCS540-2-lecture11 - Copy.ppt
CS540-2-lecture11 - Copy.ppt
ssuser0be977
 
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...
Hsien-Hsin Sean Lee, Ph.D.
 
Code optimisation presnted
Code optimisation presntedCode optimisation presnted
Code optimisation presnted
bhavanatmithun
 
Compiler unit 4
Compiler unit 4Compiler unit 4
Compiler unit 4
BBDITM LUCKNOW
 
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
annaunivedu
 
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
LogsAk
 
Basic Block
Basic BlockBasic Block
Basic Block
Shiv1234567
 
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
Arti Parab Academics
 
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
 
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
SilvanildoManoeldaSi
 
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
 
unit-3.pptx
unit-3.pptxunit-3.pptx
unit-3.pptx
RajaDesingu2
 
A109210503 digitallogicdesign1
A109210503 digitallogicdesign1A109210503 digitallogicdesign1
A109210503 digitallogicdesign1
jntuworld
 
ERTS UNIT 3.ppt
ERTS UNIT 3.pptERTS UNIT 3.ppt
ERTS UNIT 3.ppt
Pavithra525349
 
3rd Semester Computer Science and Engineering (ACU) Question papers
3rd Semester Computer Science and Engineering  (ACU) Question papers3rd Semester Computer Science and Engineering  (ACU) Question papers
3rd Semester Computer Science and Engineering (ACU) Question papers
BGS Institute of Technology, Adichunchanagiri University (ACU)
 
Control Flow Graphs
Control Flow GraphsControl Flow Graphs
Control Flow Graphs
daimk2020
 

Similar to Basic blocks - compiler design (20)

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...
 
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
 
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
 
ERTS UNIT 3.ppt
ERTS UNIT 3.pptERTS UNIT 3.ppt
ERTS UNIT 3.ppt
 
3rd Semester Computer Science and Engineering (ACU) Question papers
3rd Semester Computer Science and Engineering  (ACU) Question papers3rd Semester Computer Science and Engineering  (ACU) Question papers
3rd Semester Computer Science and Engineering (ACU) Question papers
 
Control Flow Graphs
Control Flow GraphsControl Flow Graphs
Control Flow Graphs
 

Recently uploaded

AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
SamSarthak3
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
PrashantGoswami42
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
Massimo Talia
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
MuhammadTufail242431
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
Kamal Acharya
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
Kamal Acharya
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
ViniHema
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfCOLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
Kamal Acharya
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
abh.arya
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
FluxPrime1
 

Recently uploaded (20)

AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdfAKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
AKS UNIVERSITY Satna Final Year Project By OM Hardaha.pdf
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.Quality defects in TMT Bars, Possible causes and Potential Solutions.
Quality defects in TMT Bars, Possible causes and Potential Solutions.
 
Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024Nuclear Power Economics and Structuring 2024
Nuclear Power Economics and Structuring 2024
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 
Halogenation process of chemical process industries
Halogenation process of chemical process industriesHalogenation process of chemical process industries
Halogenation process of chemical process industries
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
 
Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
 
power quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptxpower quality voltage fluctuation UNIT - I.pptx
power quality voltage fluctuation UNIT - I.pptx
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdfCOLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
COLLEGE BUS MANAGEMENT SYSTEM PROJECT REPORT.pdf
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
Democratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek AryaDemocratizing Fuzzing at Scale by Abhishek Arya
Democratizing Fuzzing at Scale by Abhishek Arya
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
DESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docxDESIGN A COTTON SEED SEPARATION MACHINE.docx
DESIGN A COTTON SEED SEPARATION MACHINE.docx
 

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 ?