SlideShare a Scribd company logo
Code Optimization in Compiler
Design
• Last Updated: 04 Sep, 2024
• Enhancing performance and efficiency of
executable code
Introduction to Code Optimization
• Improves execution time
• Minimizes resource usage
• Enhances overall system performance
• Applied during compilation without altering
program functionality
Objectives of Code Optimization
• Must preserve program meaning
• Increase program speed and performance
• Keep compilation time reasonable
• Avoid compile-time delays
When and Why to Optimize?
• Performed at development end-stage
• May reduce readability
• Used to:
• - Reduce space and increase compilation
speed
• - Automate tedious optimization tasks
• - Promote code reusability
Types of Code Optimization
• 1. Machine Independent:
• - Improves intermediate code
• - No CPU/memory-specific details
• 2. Machine Dependent:
• - Optimizes target code
• - Utilizes registers, absolute memory
Ways to Optimize Code
• 1. Compile Time Evaluation
• 2. Variable Propagation
• 3. Constant Propagation
• 4. Constant Folding
• 5. Copy Propagation
• 6. Common Sub Expression Elimination
• 7. Dead Code Elimination
• 8. Unreachable Code Elimination
Examples of Optimization
• Compile Time Eval:
• A = 2*(22.0/7.0)*r (computed at compile
time)
• Constant Folding:
• x = 2 * 5 -> x = 10
• Copy Propagation:
• Replace x with a if x = a
Unreachable Code Example
• Before:
• cout << "GFG!";
• return 0;
• cout << num;
• After:
• cout << "GFG!";
• return 0;
Function Optimization Techniques
• Function Inlining
• Function Cloning (e.g., Overloading)
• Strength Reduction:
• a = a * 16 -> a = a << 4
Loop Optimization Techniques
• 1. Code Motion
• 2. Loop Jamming
• 3. Loop Unrolling
Example: Loop Jamming
• Before:
• for(...) x = ...;
• for(...) y = ...;
• After:
• for(...) { x = ...; y = ...; }
Where to Apply Optimization?
• Source Program: Algorithm, loops
• Intermediate Code: Address transformations
• Target Code: Registers, select/move
instructions
Optimization Levels
• Local: Basic blocks (e.g., Value Numbering)
• Regional: Extended blocks (e.g., Loop
Unrolling)
• Global: Functions and loops (e.g., Live Var
Analysis)
• Interprocedural: Across procedures (e.g.,
Inline Substitution)
Advantages of Code Optimization
• Better performance and speed
• Reduced code size and power usage
• Improved portability
• Easier maintenance
Disadvantages of Code
Optimization
• Increases compilation time
• Adds complexity
• Risk of bugs
• Hard to assess benefits
Conclusion
• Code optimization is vital for efficient compiler
design
• Includes various techniques (loops, dead code,
folding)
• Leads to faster, smaller, and efficient code

More Related Content

PDF
Optimization in Programming languages
PPT
Code Optimization Lec#7.ppt Code Optimizer
PPTX
Compiler optimization techniques
PPTX
Fundamental principles of optimization and loop optimization techniques
PPT
basics of optimizations presentation s
PPTX
Code Optimization
PPTX
sCode optimization
PDF
Embedded C - Optimization techniques
Optimization in Programming languages
Code Optimization Lec#7.ppt Code Optimizer
Compiler optimization techniques
Fundamental principles of optimization and loop optimization techniques
basics of optimizations presentation s
Code Optimization
sCode optimization
Embedded C - Optimization techniques

Similar to PowerDirector Activated Full Tested Download (20)

PPTX
Compiler presention
PPTX
Code Optimization In Code Generator In Compiler Design Subject.pptx
PPTX
Code optmize.pptx which is related to coding
PDF
TSR CLASS CD-UNIT 5.pdf sddfsfdsfqweqdew
PDF
TSR CLASS CD-UNIT 5.pdf sddfsfdsfqweqdew
PDF
SPCC_Sem6_Chapter 6_Code Optimization part
PPT
Compiler optimization
PPTX
Introduction to code optimization by dipankar
PPTX
compiler design-Intermediate code generation.pptx
PPTX
Code optimization
PPTX
Code optimization
PPTX
complier design unit 5 for helping students
PPTX
Principal Sources of Optimization in compiler design
PPTX
Code optimization
PPTX
Code optimization
PPTX
Compiler Optimization Presentation
PDF
Code Optimizatoion
PDF
Compiler Design- Machine Independent Optimizations
PDF
Performance_Programming
PPTX
Principal source of optimization in compiler design
Compiler presention
Code Optimization In Code Generator In Compiler Design Subject.pptx
Code optmize.pptx which is related to coding
TSR CLASS CD-UNIT 5.pdf sddfsfdsfqweqdew
TSR CLASS CD-UNIT 5.pdf sddfsfdsfqweqdew
SPCC_Sem6_Chapter 6_Code Optimization part
Compiler optimization
Introduction to code optimization by dipankar
compiler design-Intermediate code generation.pptx
Code optimization
Code optimization
complier design unit 5 for helping students
Principal Sources of Optimization in compiler design
Code optimization
Code optimization
Compiler Optimization Presentation
Code Optimizatoion
Compiler Design- Machine Independent Optimizations
Performance_Programming
Principal source of optimization in compiler design
Ad

Recently uploaded (20)

PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PPT
Teaching material agriculture food technology
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Empathic Computing: Creating Shared Understanding
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
Mobile App Security Testing_ A Comprehensive Guide.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
Encapsulation_ Review paper, used for researhc scholars
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Advanced methodologies resolving dimensionality complications for autism neur...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
20250228 LYD VKU AI Blended-Learning.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Understanding_Digital_Forensics_Presentation.pptx
Unlocking AI with Model Context Protocol (MCP)
Teaching material agriculture food technology
Per capita expenditure prediction using model stacking based on satellite ima...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Chapter 3 Spatial Domain Image Processing.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Empathic Computing: Creating Shared Understanding
“AI and Expert System Decision Support & Business Intelligence Systems”
Ad

PowerDirector Activated Full Tested Download

  • 1. Code Optimization in Compiler Design • Last Updated: 04 Sep, 2024 • Enhancing performance and efficiency of executable code
  • 2. Introduction to Code Optimization • Improves execution time • Minimizes resource usage • Enhances overall system performance • Applied during compilation without altering program functionality
  • 3. Objectives of Code Optimization • Must preserve program meaning • Increase program speed and performance • Keep compilation time reasonable • Avoid compile-time delays
  • 4. When and Why to Optimize? • Performed at development end-stage • May reduce readability • Used to: • - Reduce space and increase compilation speed • - Automate tedious optimization tasks • - Promote code reusability
  • 5. Types of Code Optimization • 1. Machine Independent: • - Improves intermediate code • - No CPU/memory-specific details • 2. Machine Dependent: • - Optimizes target code • - Utilizes registers, absolute memory
  • 6. Ways to Optimize Code • 1. Compile Time Evaluation • 2. Variable Propagation • 3. Constant Propagation • 4. Constant Folding • 5. Copy Propagation • 6. Common Sub Expression Elimination • 7. Dead Code Elimination • 8. Unreachable Code Elimination
  • 7. Examples of Optimization • Compile Time Eval: • A = 2*(22.0/7.0)*r (computed at compile time) • Constant Folding: • x = 2 * 5 -> x = 10 • Copy Propagation: • Replace x with a if x = a
  • 8. Unreachable Code Example • Before: • cout << "GFG!"; • return 0; • cout << num; • After: • cout << "GFG!"; • return 0;
  • 9. Function Optimization Techniques • Function Inlining • Function Cloning (e.g., Overloading) • Strength Reduction: • a = a * 16 -> a = a << 4
  • 10. Loop Optimization Techniques • 1. Code Motion • 2. Loop Jamming • 3. Loop Unrolling
  • 11. Example: Loop Jamming • Before: • for(...) x = ...; • for(...) y = ...; • After: • for(...) { x = ...; y = ...; }
  • 12. Where to Apply Optimization? • Source Program: Algorithm, loops • Intermediate Code: Address transformations • Target Code: Registers, select/move instructions
  • 13. Optimization Levels • Local: Basic blocks (e.g., Value Numbering) • Regional: Extended blocks (e.g., Loop Unrolling) • Global: Functions and loops (e.g., Live Var Analysis) • Interprocedural: Across procedures (e.g., Inline Substitution)
  • 14. Advantages of Code Optimization • Better performance and speed • Reduced code size and power usage • Improved portability • Easier maintenance
  • 15. Disadvantages of Code Optimization • Increases compilation time • Adds complexity • Risk of bugs • Hard to assess benefits
  • 16. Conclusion • Code optimization is vital for efficient compiler design • Includes various techniques (loops, dead code, folding) • Leads to faster, smaller, and efficient code