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
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
16. Conclusion
• Code optimization is vital for efficient compiler
design
• Includes various techniques (loops, dead code,
folding)
• Leads to faster, smaller, and efficient code