SlideShare a Scribd company logo
1 of 20
Download to read offline
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

What's hot

What's hot (20)

Code generation
Code generationCode generation
Code generation
 
Code Optimization
Code OptimizationCode Optimization
Code Optimization
 
Run time storage
Run time storageRun time storage
Run time storage
 
Paging and segmentation
Paging and segmentationPaging and segmentation
Paging and segmentation
 
Peephole Optimization
Peephole OptimizationPeephole Optimization
Peephole Optimization
 
COMPILER DESIGN Run-Time Environments
COMPILER DESIGN Run-Time EnvironmentsCOMPILER DESIGN Run-Time Environments
COMPILER DESIGN Run-Time Environments
 
Intermediate code generator
Intermediate code generatorIntermediate code generator
Intermediate code generator
 
Partial redundancy elimination
Partial redundancy eliminationPartial redundancy elimination
Partial redundancy elimination
 
Peephole optimization techniques in compiler design
Peephole optimization techniques in compiler designPeephole optimization techniques in compiler design
Peephole optimization techniques in compiler design
 
Lecture 14 run time environment
Lecture 14 run time environmentLecture 14 run time environment
Lecture 14 run time environment
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
 
Code optimization in compiler design
Code optimization in compiler designCode optimization in compiler design
Code optimization in compiler design
 
Loop optimization
Loop optimizationLoop optimization
Loop optimization
 
Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)   Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)
 
Spline representations
Spline representationsSpline representations
Spline representations
 
Error Detection & Recovery
Error Detection & RecoveryError Detection & Recovery
Error Detection & Recovery
 
Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 
Raster scan system
Raster scan systemRaster scan system
Raster scan system
 
Heap Management
Heap ManagementHeap Management
Heap Management
 
Syntax directed translation
Syntax directed translationSyntax directed translation
Syntax directed translation
 

Similar to Compiler Design- Machine Independent Optimizations

Fundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptxFundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptxVigneshkumar Ponnusamy
 
Understand and Harness the Capabilities of Intel® Xeon Phi™ Processors
Understand and Harness the Capabilities of Intel® Xeon Phi™ ProcessorsUnderstand and Harness the Capabilities of Intel® Xeon Phi™ Processors
Understand and Harness the Capabilities of Intel® Xeon Phi™ ProcessorsIntel® Software
 
Cs 568 Spring 10 Lecture 5 Estimation
Cs 568 Spring 10  Lecture 5 EstimationCs 568 Spring 10  Lecture 5 Estimation
Cs 568 Spring 10 Lecture 5 EstimationLawrence Bernstein
 
Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming languageVasavi College of Engg
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving TechniquesAshesh R
 
Book management system
Book management systemBook management system
Book management systemSHARDA SHARAN
 
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
 
Compiler Optimization-Space Exploration
Compiler Optimization-Space ExplorationCompiler Optimization-Space Exploration
Compiler Optimization-Space Explorationtmusabbir
 
object oriented programming part inheritance.pptx
object oriented programming part inheritance.pptxobject oriented programming part inheritance.pptx
object oriented programming part inheritance.pptxurvashipundir04
 

Similar to Compiler Design- Machine Independent Optimizations (20)

Code Optimizatoion
Code OptimizatoionCode Optimizatoion
Code Optimizatoion
 
Code optimization
Code optimizationCode optimization
Code optimization
 
Programming in c by pkv
Programming in c by pkvProgramming in c by pkv
Programming in c by pkv
 
Fundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptxFundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptx
 
Unit 3 part2
Unit 3 part2Unit 3 part2
Unit 3 part2
 
Unit 3 part2
Unit 3 part2Unit 3 part2
Unit 3 part2
 
Unit 3 part2
Unit 3 part2Unit 3 part2
Unit 3 part2
 
Understand and Harness the Capabilities of Intel® Xeon Phi™ Processors
Understand and Harness the Capabilities of Intel® Xeon Phi™ ProcessorsUnderstand and Harness the Capabilities of Intel® Xeon Phi™ Processors
Understand and Harness the Capabilities of Intel® Xeon Phi™ Processors
 
Unit 2
Unit 2Unit 2
Unit 2
 
Cs 568 Spring 10 Lecture 5 Estimation
Cs 568 Spring 10  Lecture 5 EstimationCs 568 Spring 10  Lecture 5 Estimation
Cs 568 Spring 10 Lecture 5 Estimation
 
Unit 1
Unit  1Unit  1
Unit 1
 
Unit 3 principles of programming language
Unit 3 principles of programming languageUnit 3 principles of programming language
Unit 3 principles of programming language
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniques
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
Book management system
Book management systemBook management system
Book management system
 
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
 
Compiler Optimization-Space Exploration
Compiler Optimization-Space ExplorationCompiler Optimization-Space Exploration
Compiler Optimization-Space Exploration
 
Plc part 3
Plc  part 3Plc  part 3
Plc part 3
 
object oriented programming part inheritance.pptx
object oriented programming part inheritance.pptxobject oriented programming part inheritance.pptx
object oriented programming part inheritance.pptx
 

More from Jyothishmathi Institute of Technology and Science Karimnagar

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

JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
JAVA PROGRAMMING- GUI Programming with Swing - The Swing ButtonsJAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
JAVA PROGRAMMING- GUI Programming with Swing - The Swing Buttons
 
JAVA PROGRAMMING - The Collections Framework
JAVA PROGRAMMING - The Collections Framework JAVA PROGRAMMING - The Collections Framework
JAVA PROGRAMMING - The Collections Framework
 
JAVA PROGRAMMING- Exception handling - Multithreading
JAVA PROGRAMMING- Exception handling - MultithreadingJAVA PROGRAMMING- Exception handling - Multithreading
JAVA PROGRAMMING- Exception handling - Multithreading
 
JAVA PROGRAMMING – Packages - Stream based I/O
JAVA PROGRAMMING – Packages - Stream based I/O JAVA PROGRAMMING – Packages - Stream based I/O
JAVA PROGRAMMING – Packages - Stream based I/O
 
Java programming -Object-Oriented Thinking- Inheritance
Java programming -Object-Oriented Thinking- InheritanceJava programming -Object-Oriented Thinking- Inheritance
Java programming -Object-Oriented Thinking- Inheritance
 
WEB TECHNOLOGIES JavaScript
WEB TECHNOLOGIES JavaScriptWEB TECHNOLOGIES JavaScript
WEB TECHNOLOGIES JavaScript
 
WEB TECHNOLOGIES JSP
WEB TECHNOLOGIES  JSPWEB TECHNOLOGIES  JSP
WEB TECHNOLOGIES JSP
 
WEB TECHNOLOGIES Servlet
WEB TECHNOLOGIES ServletWEB TECHNOLOGIES Servlet
WEB TECHNOLOGIES Servlet
 
WEB TECHNOLOGIES XML
WEB TECHNOLOGIES XMLWEB TECHNOLOGIES XML
WEB TECHNOLOGIES XML
 
WEB TECHNOLOGIES- PHP Programming
WEB TECHNOLOGIES-  PHP ProgrammingWEB TECHNOLOGIES-  PHP Programming
WEB TECHNOLOGIES- PHP Programming
 
COMPILER DESIGN- Syntax Directed Translation
COMPILER DESIGN- Syntax Directed TranslationCOMPILER DESIGN- Syntax Directed Translation
COMPILER DESIGN- Syntax Directed Translation
 
COMPILER DESIGN- Syntax Analysis
COMPILER DESIGN- Syntax AnalysisCOMPILER DESIGN- Syntax Analysis
COMPILER DESIGN- Syntax Analysis
 
COMPILER DESIGN- Introduction & Lexical Analysis:
COMPILER DESIGN- Introduction & Lexical Analysis: COMPILER DESIGN- Introduction & Lexical Analysis:
COMPILER DESIGN- Introduction & Lexical Analysis:
 
CRYPTOGRAPHY AND NETWORK SECURITY- E-Mail Security
CRYPTOGRAPHY AND NETWORK SECURITY- E-Mail SecurityCRYPTOGRAPHY AND NETWORK SECURITY- E-Mail Security
CRYPTOGRAPHY AND NETWORK SECURITY- E-Mail Security
 
CRYPTOGRAPHY AND NETWORK SECURITY- Transport-level Security
CRYPTOGRAPHY AND NETWORK SECURITY- Transport-level SecurityCRYPTOGRAPHY AND NETWORK SECURITY- Transport-level Security
CRYPTOGRAPHY AND NETWORK SECURITY- Transport-level Security
 
CRYPTOGRAPHY & NETWORK SECURITY- Cryptographic Hash Functions
CRYPTOGRAPHY & NETWORK SECURITY- Cryptographic Hash FunctionsCRYPTOGRAPHY & NETWORK SECURITY- Cryptographic Hash Functions
CRYPTOGRAPHY & NETWORK SECURITY- Cryptographic Hash Functions
 
CRYPTOGRAPHY & NETWOK SECURITY- Symmetric key Ciphers
CRYPTOGRAPHY & NETWOK SECURITY- Symmetric key CiphersCRYPTOGRAPHY & NETWOK SECURITY- Symmetric key Ciphers
CRYPTOGRAPHY & NETWOK SECURITY- Symmetric key Ciphers
 
CRYPTOGRAPHY & NETWORK SECURITY
CRYPTOGRAPHY & NETWORK SECURITYCRYPTOGRAPHY & NETWORK SECURITY
CRYPTOGRAPHY & NETWORK SECURITY
 
Computer Forensics Working with Windows and DOS Systems
Computer Forensics Working with Windows and DOS SystemsComputer Forensics Working with Windows and DOS Systems
Computer Forensics Working with Windows and DOS Systems
 
Current Forensic Tools
Current Forensic Tools Current Forensic Tools
Current Forensic Tools
 

Recently uploaded

FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 

Recently uploaded (20)

FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

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?