SlideShare a Scribd company logo
13
Most read
17
Most read
18
Most read
Compiler Design- Machine
Independent Optimizations
Dr R Jegadeesan Prof-CSE
Jyothishmathi Institute of Technology and Science,
Karimnagar
1
SYLLABUS
U N I T 5
2
Machine-Independent Optimizations: The Principal Sources of
Optimization, Introduction to Data-Flow Analysis, Foundations of
Data-Flow Analysis, Constant Propagation, Partial Redundancy
Elimination, Loops in Flow Graphs.
UNIT 5: MACHINE INDEPENDENT
OPTIMIZATION
The principle source of optimization
3
Optimization of the code is often performed at the end of the development stage
since it reduces readability and adds code that is used to increase the
performance.
Types of Code Optimization –The optimization process can be broadly classified
into two types :
Machine Independent Optimization – This code optimization phase attempts to
improve the intermediate code to get a better target code as the output. The part
of the intermediate code which is transformed here does not involve any CPU
registers or absolute memory locations.
Topic Name : The principle source of optimization
Aim & Objective : This code optimization phase attempts improve the
intermediate code to get a better target code as the output
Principle & Operation/ Detailed Explanation
UNIT 5: MACHINE INDEPENDENT
OPTIMIZATION
The principle source of optimization
4
Machine Dependent Optimization – Machine-dependent optimization is done
after the target code has been generated and when the code is transformed
according to the target machine architecture. It involves CPU registers and may
have absolute memory references rather than relative references. Machine-
dependent optimizers put efforts to take maximum advantage of the memory
hierarchy
Topic Name : The principle source of optimization
Aim & Objective : This code optimization phase attempts improve the
intermediate code to get a better target code as the output
Principle & Operation/ Detailed Explanation
Code Optimization is done in the following different ways :
Compile Time Evaluation
(i) A = 2*(22.0/7.0)*r
Perform 2*(22.0/7.0)*r at compile time.
(ii) x = 12.4
y = x/2.3
Evaluate x/2.3 as 12.4/2.3 at compile time.
Variable Propagation
//Before Optimization
c = a * b
x = a
till
d = x * b + 4 5
UNIT 5: MACHINE INDEPENDENT
OPTIMIZATION
The principle source of optimization
//After Optimization
c = a * b
x = a
till
d = a * b + 4
Hence, after variable propagation, a*b and x*b will be identified as common sub-expression.
Dead code elimination : Variable propagation often leads to making assignment statement into dead
code
brightness_4
c = a * b
x = a
till
d = a * b + 4
//After elimination :
c = a * b
till
d = a * b + 4
6
UNIT 5: MACHINE INDEPENDENT
OPTIMIZATION
The principle source of optimization
Code Motion :
• Reduce the evaluation frequency of expression.
• Bring loop invariant statements out of the loop.
a = 200;
while(a>0)
{
b = x + y;
if (a % b == 0}
printf(“%d”, a);
}
7
UNIT 5: MACHINE INDEPENDENT
OPTIMIZATION
The principle source of optimization
//This code can be further optimized as
a = 200;
b = x + y;
while(a>0)
{
if (a % b == 0}
printf(“%d”, a);
}
Induction Variable and Strength Reduction :
• An induction variable is used in loop for the following kind of assignment i = i + constant.
• Strength reduction means replacing the high strength operator by the low strength.
i = 1;
while (i<10)
{
y = i * 4;
}
8
UNIT 5: MACHINE INDEPENDENT
OPTIMIZATION
The principle source of optimization
After Reduction
i = 1
t = 4
{
while( t<40)
y = t;
t = t + 4;
}
9
UNIT 5: MACHINE INDEPENDENT
OPTIMIZATION
The principle source of optimization
UNIT 5: DATA-FLOW ANALYSIS
Data flow analysis in Compiler
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.
Basic Terminologies –
Definition Point: a point in a program containing some definition.
Reference Point: a point in a program containing a reference to a data item.
Evaluation Point: a point in a program containing evaluation of expression.
10
Topic Name : Data flow analysis in Compiler
Aim & Objective : The data flow property represents information which
can be used for optimization.
Principle & Operation/ Detailed Explanation
Basic Terminologies
11
UNIT 5: DATA-FLOW ANALYSIS
Data Flow Properties –
Available Expression – 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 –
Data Flow Properties
12
UNIT 5: DATA-FLOW ANALYSIS
13
Advantage –
It is used to eliminate common sub expressions
•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.
Example –
Data Flow Properties
UNIT 5: DATA-FLOW ANALYSIS
14
UNIT 5: DATA-FLOW ANALYSIS
Data Flow Properties
Advantage –
It is used in constant and variable propagation.
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. Example –
15
Data Flow Properties
UNIT 5: DATA-FLOW ANALYSIS
Advantage –
It is useful for register allocation.
It is used in dead code elimination.
Busy Expression – An expression is busy along a path iff its evaluation exists along that path and none
of its operand definition exists before its evaluation along the path.
Advantage –
It is used for performing code movement optimization.
16
UNIT 5: DATA-FLOW ANALYSIS
Data Flow Properties
Constant Propagation
If a variable is known to contain a particular constant value at a particular
point in the program, replace references to the variable at that point with that
constant value.
After the assignment of one variable to another, a reference to one variable may be
replaced with the value of the other variable (until one or the other of the
variables is reassigned).
Dead Code Elimination
Expressions or statements whose values or effects are unused may be eliminated.
17
Topic Name : Constant Propagation
Aim & Objective : machine independent optimization.
Principle & Operation/ Detailed Explanation :
Constant Propagation
Universities & Important Questions:
1. Explain constant propagation?
UNIT 1 : HEADING
Partial Redundancy Elimination
18
we consider in detail how to minimize the number of expression evaluations.
That is, we want to consider all possible execution sequences in a flow graph, and look at the
number of times an expression
such as x + y is evaluated. By moving around the places where x + y is evaluated and keeping
the result in a temporary variable when necessary, we often can reduce the number of evaluations
of this expression
along many of the execution paths, while not increasing that number along any path.
Note that the number of different places in the flow graph where x + y is evaluated may increase,
but that is relatively unimportant, as long as the number of evaluations of the expression x + y is
reduced.
Loop Optimization
Loop Optimization
Most programs run as a loop in the system. It becomes necessary to optimize the loops in
order to save CPU cycles and memory. Loops can be optimized by the following
techniques:
Invariant code : A fragment of code that resides in the loop and computes the same
value at each iteration is called a loop-invariant code. This code can be moved out of the
loop by saving it to be computed only once, rather than with each iteration.
Induction analysis : A variable is called an induction variable if its value is altered within
the loop by a loop-invariant value.
Strength reduction : There are expressions that consume more CPU cycles, time, and
memory. These expressions should be replaced with cheaper expressions without
compromising the output of expression. For example, multiplication (x * 2) is expensive
in terms of CPU cycles than (x << 1) and yields the same result.
19
Universities & Important Questions:
1. Explain loop optimization?
Thank you
20

More Related Content

PPTX
Principal source of optimization in compiler design
PPTX
Principle source of optimazation
PPTX
Code optimization
PDF
Intermediate code generation in Compiler Design
PDF
Code optimization in compiler design
PPTX
Peephole optimization techniques in compiler design
PPTX
Symbol table design (Compiler Construction)
PPTX
Unit iv(simple code generator)
Principal source of optimization in compiler design
Principle source of optimazation
Code optimization
Intermediate code generation in Compiler Design
Code optimization in compiler design
Peephole optimization techniques in compiler design
Symbol table design (Compiler Construction)
Unit iv(simple code generator)

What's hot (20)

PDF
PPTX
Lecture 14 run time environment
PPTX
Back patching
PPTX
Code generation
PPTX
Principal Sources of Optimization in compiler design
PPTX
Loops in flow
PDF
Syntax Directed Definition and its applications
PPTX
Evaluating hypothesis
PDF
Run time storage
PPT
Chapter 5 -Syntax Directed Translation - Copy.ppt
PPTX
Compiler design syntax analysis
PPTX
Code Optimization
PDF
A* Search Algorithm
PDF
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
PDF
I.BEST FIRST SEARCH IN AI
PPTX
Syntax Analysis in Compiler Design
PPTX
Loop optimization
PDF
COMPILER DESIGN- Syntax Directed Translation
PPTX
knowledge representation using rules
PPT
Chapter 5 Syntax Directed Translation
Lecture 14 run time environment
Back patching
Code generation
Principal Sources of Optimization in compiler design
Loops in flow
Syntax Directed Definition and its applications
Evaluating hypothesis
Run time storage
Chapter 5 -Syntax Directed Translation - Copy.ppt
Compiler design syntax analysis
Code Optimization
A* Search Algorithm
14-Intermediate code generation - Variants of Syntax trees - Three Address Co...
I.BEST FIRST SEARCH IN AI
Syntax Analysis in Compiler Design
Loop optimization
COMPILER DESIGN- Syntax Directed Translation
knowledge representation using rules
Chapter 5 Syntax Directed Translation
Ad

Similar to Compiler Design- Machine Independent Optimizations (20)

PPTX
complier design unit 5 for helping students
PDF
TSR CLASS CD-UNIT 5.pdf sddfsfdsfqweqdew
PDF
TSR CLASS CD-UNIT 5.pdf sddfsfdsfqweqdew
PPTX
Machine_Learning_JNTUH_R18_UNIT5_CONCEPTS.pptx
PPT
Code Optimization Lec#7.ppt Code Optimizer
PPTX
Code optmize.pptx which is related to coding
PDF
SPCC_Sem6_Chapter 6_Code Optimization part
PPTX
Compiler presention
PPT
basics of optimizations presentation s
PPTX
compiler design-Intermediate code generation.pptx
PPTX
Compiler optimization techniques
PPTX
Download RarmaRadio Pro Crack Latest [2025]
PPTX
Code_Optimization_Compiler_Design software .pptx
PPTX
NCH VideoPad Pro Cracked Version Download
PPTX
Download Artweaver Plus Cracked Version Free
PPTX
PowerDirector Activated Full Tested Download
PPTX
Downlaod Wise Registry Cleaner Pro Crack
PPTX
Autodesk CFD Ultimate Crack Latest Version
PPTX
Latest TreeSize Professional 9 Crack Download
PPTX
Compiler Design theory and various phases of compiler.pptx
complier design unit 5 for helping students
TSR CLASS CD-UNIT 5.pdf sddfsfdsfqweqdew
TSR CLASS CD-UNIT 5.pdf sddfsfdsfqweqdew
Machine_Learning_JNTUH_R18_UNIT5_CONCEPTS.pptx
Code Optimization Lec#7.ppt Code Optimizer
Code optmize.pptx which is related to coding
SPCC_Sem6_Chapter 6_Code Optimization part
Compiler presention
basics of optimizations presentation s
compiler design-Intermediate code generation.pptx
Compiler optimization techniques
Download RarmaRadio Pro Crack Latest [2025]
Code_Optimization_Compiler_Design software .pptx
NCH VideoPad Pro Cracked Version Download
Download Artweaver Plus Cracked Version Free
PowerDirector Activated Full Tested Download
Downlaod Wise Registry Cleaner Pro Crack
Autodesk CFD Ultimate Crack Latest Version
Latest TreeSize Professional 9 Crack Download
Compiler Design theory and various phases of compiler.pptx
Ad

More from Jyothishmathi Institute of Technology and Science Karimnagar (20)

PDF
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
PDF
JAVA PROGRAMMING - The Collections Framework
PDF
JAVA PROGRAMMING- Exception handling - Multithreading
PDF
JAVA PROGRAMMING – Packages - Stream based I/O
PDF
Java programming -Object-Oriented Thinking- Inheritance
PDF
COMPILER DESIGN- Introduction & Lexical Analysis:
PPTX
CRYPTOGRAPHY AND NETWORK SECURITY- E-Mail Security
PDF
CRYPTOGRAPHY AND NETWORK SECURITY- Transport-level Security
PDF
CRYPTOGRAPHY & NETWORK SECURITY- Cryptographic Hash Functions
PDF
CRYPTOGRAPHY & NETWOK SECURITY- Symmetric key Ciphers
PDF
Computer Forensics Working with Windows and DOS Systems
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
JAVA PROGRAMMING - The Collections Framework
JAVA PROGRAMMING- Exception handling - Multithreading
JAVA PROGRAMMING – Packages - Stream based I/O
Java programming -Object-Oriented Thinking- Inheritance
COMPILER DESIGN- Introduction & Lexical Analysis:
CRYPTOGRAPHY AND NETWORK SECURITY- E-Mail Security
CRYPTOGRAPHY AND NETWORK SECURITY- Transport-level Security
CRYPTOGRAPHY & NETWORK SECURITY- Cryptographic Hash Functions
CRYPTOGRAPHY & NETWOK SECURITY- Symmetric key Ciphers
Computer Forensics Working with Windows and DOS Systems

Recently uploaded (20)

PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Machine learning based COVID-19 study performance prediction
PDF
Empathic Computing: Creating Shared Understanding
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Modernizing your data center with Dell and AMD
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Encapsulation theory and applications.pdf
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
Chapter 3 Spatial Domain Image Processing.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Machine learning based COVID-19 study performance prediction
Empathic Computing: Creating Shared Understanding
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
The Rise and Fall of 3GPP – Time for a Sabbatical?
Spectral efficient network and resource selection model in 5G networks
Modernizing your data center with Dell and AMD
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Encapsulation theory and applications.pdf
Dropbox Q2 2025 Financial Results & Investor Presentation
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Advanced methodologies resolving dimensionality complications for autism neur...
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
NewMind AI Weekly Chronicles - August'25 Week I

Compiler Design- Machine Independent Optimizations

  • 1. Compiler Design- Machine Independent Optimizations Dr R Jegadeesan Prof-CSE Jyothishmathi Institute of Technology and Science, Karimnagar 1
  • 2. SYLLABUS U N I T 5 2 Machine-Independent Optimizations: The Principal Sources of Optimization, Introduction to Data-Flow Analysis, Foundations of Data-Flow Analysis, Constant Propagation, Partial Redundancy Elimination, Loops in Flow Graphs.
  • 3. UNIT 5: MACHINE INDEPENDENT OPTIMIZATION The principle source of optimization 3 Optimization of the code is often performed at the end of the development stage since it reduces readability and adds code that is used to increase the performance. Types of Code Optimization –The optimization process can be broadly classified into two types : Machine Independent Optimization – This code optimization phase attempts to improve the intermediate code to get a better target code as the output. The part of the intermediate code which is transformed here does not involve any CPU registers or absolute memory locations. Topic Name : The principle source of optimization Aim & Objective : This code optimization phase attempts improve the intermediate code to get a better target code as the output Principle & Operation/ Detailed Explanation
  • 4. UNIT 5: MACHINE INDEPENDENT OPTIMIZATION The principle source of optimization 4 Machine Dependent Optimization – Machine-dependent optimization is done after the target code has been generated and when the code is transformed according to the target machine architecture. It involves CPU registers and may have absolute memory references rather than relative references. Machine- dependent optimizers put efforts to take maximum advantage of the memory hierarchy Topic Name : The principle source of optimization Aim & Objective : This code optimization phase attempts improve the intermediate code to get a better target code as the output Principle & Operation/ Detailed Explanation
  • 5. Code Optimization is done in the following different ways : Compile Time Evaluation (i) A = 2*(22.0/7.0)*r Perform 2*(22.0/7.0)*r at compile time. (ii) x = 12.4 y = x/2.3 Evaluate x/2.3 as 12.4/2.3 at compile time. Variable Propagation //Before Optimization c = a * b x = a till d = x * b + 4 5 UNIT 5: MACHINE INDEPENDENT OPTIMIZATION The principle source of optimization
  • 6. //After Optimization c = a * b x = a till d = a * b + 4 Hence, after variable propagation, a*b and x*b will be identified as common sub-expression. Dead code elimination : Variable propagation often leads to making assignment statement into dead code brightness_4 c = a * b x = a till d = a * b + 4 //After elimination : c = a * b till d = a * b + 4 6 UNIT 5: MACHINE INDEPENDENT OPTIMIZATION The principle source of optimization
  • 7. Code Motion : • Reduce the evaluation frequency of expression. • Bring loop invariant statements out of the loop. a = 200; while(a>0) { b = x + y; if (a % b == 0} printf(“%d”, a); } 7 UNIT 5: MACHINE INDEPENDENT OPTIMIZATION The principle source of optimization
  • 8. //This code can be further optimized as a = 200; b = x + y; while(a>0) { if (a % b == 0} printf(“%d”, a); } Induction Variable and Strength Reduction : • An induction variable is used in loop for the following kind of assignment i = i + constant. • Strength reduction means replacing the high strength operator by the low strength. i = 1; while (i<10) { y = i * 4; } 8 UNIT 5: MACHINE INDEPENDENT OPTIMIZATION The principle source of optimization
  • 9. After Reduction i = 1 t = 4 { while( t<40) y = t; t = t + 4; } 9 UNIT 5: MACHINE INDEPENDENT OPTIMIZATION The principle source of optimization
  • 10. UNIT 5: DATA-FLOW ANALYSIS Data flow analysis in Compiler 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. Basic Terminologies – Definition Point: a point in a program containing some definition. Reference Point: a point in a program containing a reference to a data item. Evaluation Point: a point in a program containing evaluation of expression. 10 Topic Name : Data flow analysis in Compiler Aim & Objective : The data flow property represents information which can be used for optimization. Principle & Operation/ Detailed Explanation
  • 11. Basic Terminologies 11 UNIT 5: DATA-FLOW ANALYSIS
  • 12. Data Flow Properties – Available Expression – 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 – Data Flow Properties 12 UNIT 5: DATA-FLOW ANALYSIS
  • 13. 13 Advantage – It is used to eliminate common sub expressions •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. Example – Data Flow Properties UNIT 5: DATA-FLOW ANALYSIS
  • 14. 14 UNIT 5: DATA-FLOW ANALYSIS Data Flow Properties
  • 15. Advantage – It is used in constant and variable propagation. 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. Example – 15 Data Flow Properties UNIT 5: DATA-FLOW ANALYSIS
  • 16. Advantage – It is useful for register allocation. It is used in dead code elimination. Busy Expression – An expression is busy along a path iff its evaluation exists along that path and none of its operand definition exists before its evaluation along the path. Advantage – It is used for performing code movement optimization. 16 UNIT 5: DATA-FLOW ANALYSIS Data Flow Properties
  • 17. Constant Propagation If a variable is known to contain a particular constant value at a particular point in the program, replace references to the variable at that point with that constant value. After the assignment of one variable to another, a reference to one variable may be replaced with the value of the other variable (until one or the other of the variables is reassigned). Dead Code Elimination Expressions or statements whose values or effects are unused may be eliminated. 17 Topic Name : Constant Propagation Aim & Objective : machine independent optimization. Principle & Operation/ Detailed Explanation : Constant Propagation Universities & Important Questions: 1. Explain constant propagation?
  • 18. UNIT 1 : HEADING Partial Redundancy Elimination 18 we consider in detail how to minimize the number of expression evaluations. That is, we want to consider all possible execution sequences in a flow graph, and look at the number of times an expression such as x + y is evaluated. By moving around the places where x + y is evaluated and keeping the result in a temporary variable when necessary, we often can reduce the number of evaluations of this expression along many of the execution paths, while not increasing that number along any path. Note that the number of different places in the flow graph where x + y is evaluated may increase, but that is relatively unimportant, as long as the number of evaluations of the expression x + y is reduced.
  • 19. Loop Optimization Loop Optimization Most programs run as a loop in the system. It becomes necessary to optimize the loops in order to save CPU cycles and memory. Loops can be optimized by the following techniques: Invariant code : A fragment of code that resides in the loop and computes the same value at each iteration is called a loop-invariant code. This code can be moved out of the loop by saving it to be computed only once, rather than with each iteration. Induction analysis : A variable is called an induction variable if its value is altered within the loop by a loop-invariant value. Strength reduction : There are expressions that consume more CPU cycles, time, and memory. These expressions should be replaced with cheaper expressions without compromising the output of expression. For example, multiplication (x * 2) is expensive in terms of CPU cycles than (x << 1) and yields the same result. 19 Universities & Important Questions: 1. Explain loop optimization?