



































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A comprehensive overview of code optimization techniques and runtime environments in compiler design. It covers the principal sources of optimization, including common subexpression elimination, copy propagation, dead-code elimination, and constant folding. The document also delves into peephole optimization, optimization of basic blocks, and an introduction to global data flow analysis. Additionally, it explores runtime environments, source language issues, storage organization, storage allocation strategies, access to non-local names, and parameter passing. The detailed coverage of these topics makes this document a valuable resource for students and researchers interested in compiler design and optimization.
Typology: Cheat Sheet
1 / 75
This page cannot be seen from the preview
Don't miss anything!




































































FACULTY NAME:
Mr.R.Raja Sekar, AP- CSE
Course Outcome – Unit V
UNIT V Code Optimization and Run Time Environments 9
Introduction– Principal Sources of Optimization – Peephole
Optimization- Optimization of basic Blocks – Introduction to Global Data Flow
Analysis – Runtime Environments – Source Language issues – Storage
Organization – Storage Allocation strategies – Access to non-local names –
Parameter Passing.
Apply for various optimization techniques for
dataflow analysis.
Code Optimization - Introduction
Optimization is a program transformation
technique, which tries to improve the code by
making it consume less resources (i.e. CPU,
Memory) and deliver high speed.
Code Optimization – Introduction (..contd)
A code optimizing process must follow the
three rules given below:
program.
possible, the program should demand less number of resources.
overall compiling process.
Code Optimization – Types
Machine-independent Optimization
Machine-dependent Optimization
Machine-independent Optimization
Code Optimization – Phases
Global Optimization:
Transformations are applied to large program segments that
includes functions, procedures and loops.
Local Optimization:
Transformations are applied to small blocks of statements. The
local optimization is done prior to global optimization.
Principal sources Code Optimization
Common Subexpressions elimination
Copy Propagation
Dead-Code elimination
Constant Folding
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.
x=Pi;
A=xrr;
The optimization using copy propagation can be done as follows: A=Pirr;
Here the variable x is eliminated
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.
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.
An important modification that decreases the amount of code
in a loop is code motion.
This transformation takes an expression that yields the same
result independent of the number of times a loop is executed (a
loop-invariant computation) and places the expression before
the loop.
For example, evaluation of limit-2 is a loop-invariant
computation
in the following while-statement:
while (i <= limit-2) /* statement does not change limit*/
Code motion will result in the equivalent of
t= limit-2;
while (i<=t) /* statement does not change limit or t */
Loops are usually processed inside out. For example consider
the loop around B3.
Note that the values of j and t4 remain in lock-step; every time
the value of j decreases by 1, that of t4 decreases by 4 because
4*j is assigned to t4.
Such identifiers are called induction variables.