SlideShare a Scribd company logo
2
Most read
3
Most read
5
Most read
PRINCPAL SOURCES OF OPTIMISATION
R. Rajkumar
AP | CSE
SRM IST
UNIT 5
Principle SOURCES OF OPTIMISATION
•A compiler optimization must preserve the semantics of the
original program.
•Except in very special circumstances, once a programmer
chooses and implements a particular algorithm, the compiler
cannot understand enough about the program to replace it
with a substantially different and more efficient algorithm.
•A compiler knows only how to apply relatively low-level
semantic transformations, using general facts.
Function-Preserving Transformations
There are a number of ways in which a compiler can improve a
program without changing the function it computes.
Function preserving transformations examples:
• 1. Common sub expression elimination
• 2. Copy propagation,
• 3. Dead-code elimination
• 4. Constant folding
Common Sub expressions elimination:
An occurrence of an expression E is called a common
sub-expression if E was previously computed, and the
values of variables in E have not changed since the
previous computation.
We can avoid recomputing the expression if we can use
the previously computed value.
For example
t1: = 4*i
t2: = a [t1]
t3: = 4*j
t4: = 4*i
t5: = n
t6: = b [t4] +t5
The common sub-
expression elimination as
t1: = 4*i
t2: = a [t1]
t3: = 4*j
t5: = n
t6: = b [t1] +t5
[ The common sub expression t4:
=4*i is eliminated as its
computation is already in t1 and
the value of i is not been changed
from definition to use.]
Copy Propagation:
Assignments of the form f : = g called copy statements, or copies for short.
The idea behind the copy-propagation transformation is to use g for f,
whenever possible after the copy statement f: = g.
Copy propagation means use of one variable instead of another. This may not
appear to be an improvement, but as we shall see it gives us an opportunity
to eliminate x.
• For example:
x=Pi;
A=x*r*r;
The optimization using copy propagation can be done as follows: A=Pi*r*r;
Here the variable x is eliminated
Dead-Code Eliminations:
A variable is live at a point in a program if its value can be used subsequently;
otherwise, it is dead at that point. A related idea is dead or useless code,
statements that compute values that never get used. While the programmer is
unlikely to introduce any dead code intentionally, it may appear as the result of
previous transformations.
Example:
i=0;
if(i=1)
{
a=b+5;
} Here, ‘if’ statement is dead code because this condition will never get satisfied.
Constant folding:
Deducing at compile time that the value of an expression is a constant
and using the constant instead is known as constant folding. One
advantage of copy propagation is that it often turns the copy statement
into dead code.
For example,
a=3.14157/2 can be replaced by
a=1.570 there by eliminating a division operation.
Loop Optimizations
In loops, especially in the inner loops, programs tend to spend the bulk of
their time. The running time of a program may be improved if the number of
instructions in an inner loop is decreased, even if we increase the amount of
code outside that loop.
Three techniques are important for loop optimization:
• Code motion, which moves code outside a loop;
• Induction-variable elimination, which we apply to replace variables from
inner loop.
• Reduction in strength, which replaces and expensive operation by a
cheaper one, such as a multiplication by an addition.
Principal source of optimization in compiler design
Data flow analysis
• It is the analysis of flow of data in control flow graph, i.e., the analysis
that determines the information regarding the definition and use of
data in program. With the help of this analysis optimization can be
done. In general, its process in which values are computed using data
flow analysis. The data flow property represents information which
can be used for optimization.
Data flow analysis
A expression is said to be available at a program point x iff along paths its reaching to x.
A Expression is available at its evaluation point.
A expression a+b is said to be available if none of the operands gets modified before their use.
Example
AVAILABLE EXPRESSION
Reaching Definition
• A definition D is reaches a point x if there is path from D to x in
which D is not killed, i.e., not redefined.
Live variable
A variable is said to be live at some point p if from p to end the
variable is used before it is redefined else it becomes dead.
Advantages:
It is useful for register allocation.
It is used in dead code elimination.
Summary
• Principle Sources of Optimisation
• Function-Preserving Transformations
• Common Sub expressions elimination:
• Copy Propagation:
• Dead-Code Eliminations:
• Constant folding:
• Loop Optimizations
• Data flow analysis
• Available Expression
• Reaching Definition
• Live variable

More Related Content

PDF
Code optimization in compiler design
PPTX
4.6 halting problem
PPTX
Python basics
PDF
Compiler Design- Machine Independent Optimizations
PPT
Software quality assurance lecture 1
PPT
Artificial Intelligence: Case-based & Model-based Reasoning
PPTX
Functions in c language
PPTX
Nanorobotics ppt
Code optimization in compiler design
4.6 halting problem
Python basics
Compiler Design- Machine Independent Optimizations
Software quality assurance lecture 1
Artificial Intelligence: Case-based & Model-based Reasoning
Functions in c language
Nanorobotics ppt

What's hot (20)

PPTX
Principal Sources of Optimization in compiler design
PPTX
Principle source of optimazation
PPTX
Peephole optimization techniques in compiler design
PPTX
Peephole Optimization
PPTX
Multiplexing in mobile computing
PDF
Token, Pattern and Lexeme
PPTX
Pipelining powerpoint presentation
PPTX
Type checking in compiler design
PPTX
ELEMENTS OF TRANSPORT PROTOCOL
PPT
Pipeline hazards in computer Architecture ppt
PPT
Type Checking(Compiler Design) #ShareThisIfYouLike
PPTX
Problem reduction AND OR GRAPH & AO* algorithm.ppt
PPTX
Finite automata-for-lexical-analysis
PPTX
Page replacement algorithms
PPTX
Analog and Digital Transmission
PDF
Issues in the design of Code Generator
PPTX
INSTRUCTION LEVEL PARALLALISM
PPTX
Video display devices
PDF
7. data link layer error detection and correction codes - parity and checksum
PPTX
Code Optimization
Principal Sources of Optimization in compiler design
Principle source of optimazation
Peephole optimization techniques in compiler design
Peephole Optimization
Multiplexing in mobile computing
Token, Pattern and Lexeme
Pipelining powerpoint presentation
Type checking in compiler design
ELEMENTS OF TRANSPORT PROTOCOL
Pipeline hazards in computer Architecture ppt
Type Checking(Compiler Design) #ShareThisIfYouLike
Problem reduction AND OR GRAPH & AO* algorithm.ppt
Finite automata-for-lexical-analysis
Page replacement algorithms
Analog and Digital Transmission
Issues in the design of Code Generator
INSTRUCTION LEVEL PARALLALISM
Video display devices
7. data link layer error detection and correction codes - parity and checksum
Code Optimization
Ad

Similar to Principal source of optimization in compiler design (20)

PPTX
Code optmize.pptx which is related to coding
PPTX
complier design unit 5 for helping students
PPTX
Presentation 1 on algorithm for lab progress
PDF
SPCC_Sem6_Chapter 6_Code Optimization part
PPTX
Machine_Learning_JNTUH_R18_UNIT5_CONCEPTS.pptx
PDF
Code Optimizatoion
PPTX
Function C programming
PPTX
Function Overloading Call by value and call by reference
PDF
Functions in C++.pdf
PPTX
Compiler: Programming Language= Assignments and statements
PDF
introduction to c programming - Topic 3.pdf
PPTX
Code optimization
PPTX
Chapter One Function.pptx
PDF
Programming in c by pkv
PPTX
Functions in c language
PPTX
session-1_Design_Analysis_Algorithm.pptx
PPTX
JAVA programming language made easy.pptx
PPTX
Compiler Design theory and various phases of compiler.pptx
PPTX
Unit 3 Compiler Design Regulation 2021.pptx
PPTX
04. WORKING WITH FUNCTIONS-2 (1).pptx
Code optmize.pptx which is related to coding
complier design unit 5 for helping students
Presentation 1 on algorithm for lab progress
SPCC_Sem6_Chapter 6_Code Optimization part
Machine_Learning_JNTUH_R18_UNIT5_CONCEPTS.pptx
Code Optimizatoion
Function C programming
Function Overloading Call by value and call by reference
Functions in C++.pdf
Compiler: Programming Language= Assignments and statements
introduction to c programming - Topic 3.pdf
Code optimization
Chapter One Function.pptx
Programming in c by pkv
Functions in c language
session-1_Design_Analysis_Algorithm.pptx
JAVA programming language made easy.pptx
Compiler Design theory and various phases of compiler.pptx
Unit 3 Compiler Design Regulation 2021.pptx
04. WORKING WITH FUNCTIONS-2 (1).pptx
Ad

More from Rajkumar R (13)

PPTX
Dr. R. Rajkumar Environment .pptx
PPTX
Health is wealth - Swetha presentation
PPTX
Cloud computing on medical R. Rajkumar
PPTX
How to from good design to great design
PPTX
Business opportunities in ed tech
PPT
Machine learning in human computer interface
PPTX
FDP on AI and ML by R. Rajkumar
PPTX
Tamil Teaching methods for Higher Education
PPTX
Virtual reality for all
PPTX
AI and covid19 | Mr. R. Rajkumar, Assistant Professor, Department of CSE
PPTX
Webinar on oppurtunities on industry 4.0
PPT
Finger print presentation by R Rajkumar
PPTX
Webinar on AI in IoT applications KCG Connect Alumni Digital Series by Rajkumar
Dr. R. Rajkumar Environment .pptx
Health is wealth - Swetha presentation
Cloud computing on medical R. Rajkumar
How to from good design to great design
Business opportunities in ed tech
Machine learning in human computer interface
FDP on AI and ML by R. Rajkumar
Tamil Teaching methods for Higher Education
Virtual reality for all
AI and covid19 | Mr. R. Rajkumar, Assistant Professor, Department of CSE
Webinar on oppurtunities on industry 4.0
Finger print presentation by R Rajkumar
Webinar on AI in IoT applications KCG Connect Alumni Digital Series by Rajkumar

Recently uploaded (20)

PDF
Well-logging-methods_new................
DOCX
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
PPTX
Lesson 3_Tessellation.pptx finite Mathematics
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PDF
PPT on Performance Review to get promotions
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPT
Project quality management in manufacturing
PDF
Digital Logic Computer Design lecture notes
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Well-logging-methods_new................
ASol_English-Language-Literature-Set-1-27-02-2023-converted.docx
Lesson 3_Tessellation.pptx finite Mathematics
Embodied AI: Ushering in the Next Era of Intelligent Systems
Strings in CPP - Strings in C++ are sequences of characters used to store and...
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPT on Performance Review to get promotions
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
Operating System & Kernel Study Guide-1 - converted.pdf
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
Project quality management in manufacturing
Digital Logic Computer Design lecture notes
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Lecture Notes Electrical Wiring System Components
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Internet of Things (IOT) - A guide to understanding
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk

Principal source of optimization in compiler design

  • 1. PRINCPAL SOURCES OF OPTIMISATION R. Rajkumar AP | CSE SRM IST UNIT 5
  • 2. Principle SOURCES OF OPTIMISATION •A compiler optimization must preserve the semantics of the original program. •Except in very special circumstances, once a programmer chooses and implements a particular algorithm, the compiler cannot understand enough about the program to replace it with a substantially different and more efficient algorithm. •A compiler knows only how to apply relatively low-level semantic transformations, using general facts.
  • 3. Function-Preserving Transformations There are a number of ways in which a compiler can improve a program without changing the function it computes. Function preserving transformations examples: • 1. Common sub expression elimination • 2. Copy propagation, • 3. Dead-code elimination • 4. Constant folding
  • 4. Common Sub expressions elimination: An occurrence of an expression E is called a common sub-expression if E was previously computed, and the values of variables in E have not changed since the previous computation. We can avoid recomputing the expression if we can use the previously computed value.
  • 5. For example t1: = 4*i t2: = a [t1] t3: = 4*j t4: = 4*i t5: = n t6: = b [t4] +t5 The common sub- expression elimination as t1: = 4*i t2: = a [t1] t3: = 4*j t5: = n t6: = b [t1] +t5 [ The common sub expression t4: =4*i is eliminated as its computation is already in t1 and the value of i is not been changed from definition to use.]
  • 6. Copy Propagation: Assignments of the form f : = g called copy statements, or copies for short. The idea behind the copy-propagation transformation is to use g for f, whenever possible after the copy statement f: = g. Copy propagation means use of one variable instead of another. This may not appear to be an improvement, but as we shall see it gives us an opportunity to eliminate x. • For example: x=Pi; A=x*r*r; The optimization using copy propagation can be done as follows: A=Pi*r*r; Here the variable x is eliminated
  • 7. Dead-Code Eliminations: A variable is live at a point in a program if its value can be used subsequently; otherwise, it is dead at that point. A related idea is dead or useless code, statements that compute values that never get used. While the programmer is unlikely to introduce any dead code intentionally, it may appear as the result of previous transformations. Example: i=0; if(i=1) { a=b+5; } Here, ‘if’ statement is dead code because this condition will never get satisfied.
  • 8. Constant folding: Deducing at compile time that the value of an expression is a constant and using the constant instead is known as constant folding. One advantage of copy propagation is that it often turns the copy statement into dead code. For example, a=3.14157/2 can be replaced by a=1.570 there by eliminating a division operation.
  • 9. Loop Optimizations In loops, especially in the inner loops, programs tend to spend the bulk of their time. The running time of a program may be improved if the number of instructions in an inner loop is decreased, even if we increase the amount of code outside that loop. Three techniques are important for loop optimization: • Code motion, which moves code outside a loop; • Induction-variable elimination, which we apply to replace variables from inner loop. • Reduction in strength, which replaces and expensive operation by a cheaper one, such as a multiplication by an addition.
  • 11. Data flow analysis • It is the analysis of flow of data in control flow graph, i.e., the analysis that determines the information regarding the definition and use of data in program. With the help of this analysis optimization can be done. In general, its process in which values are computed using data flow analysis. The data flow property represents information which can be used for optimization.
  • 13. A expression is said to be available at a program point x iff along paths its reaching to x. A Expression is available at its evaluation point. A expression a+b is said to be available if none of the operands gets modified before their use. Example AVAILABLE EXPRESSION
  • 14. Reaching Definition • A definition D is reaches a point x if there is path from D to x in which D is not killed, i.e., not redefined.
  • 15. Live variable A variable is said to be live at some point p if from p to end the variable is used before it is redefined else it becomes dead. Advantages: It is useful for register allocation. It is used in dead code elimination.
  • 16. Summary • Principle Sources of Optimisation • Function-Preserving Transformations • Common Sub expressions elimination: • Copy Propagation: • Dead-Code Eliminations: • Constant folding: • Loop Optimizations • Data flow analysis • Available Expression • Reaching Definition • Live variable