written 8.4 years ago by | • modified 8.4 years ago |
Mumbai University > Computer Engineering > Sem6 > System Programming and Compiler Construction
Marks: 5M
Year: May 2015
written 8.4 years ago by | • modified 8.4 years ago |
Mumbai University > Computer Engineering > Sem6 > System Programming and Compiler Construction
Marks: 5M
Year: May 2015
written 8.4 years ago by |
Optimization
Optimization can be categorized broadly into two types:
Machine Independent and Machine Dependent.
Function Preserving $\hspace{2.5 cm}$ Loop Optimization
• Common subexpression Elimination $\hspace{.5 cm}$ 1. Code motion
• Constant Folding $\hspace{3.5 cm}$ 2. Strength Reduction
• Copy Propagation $\hspace{3.5 cm}$ 3. Frequency Reduction
• Dead code Elimination $\hspace{2.5 cm}$ 4. Loop distribution
Loop Optimization
We are going to perform optimization on loops.
Code Motion
It specifies on a condition if we perform some operations to be carried out and then compare for a condition.
Instead of that perform the calculation outside the loop and assign a value in the calculation.
What statements inside the following TAC code can be moved outside the loop body?
L0:
tmp1 = tmp2 + tmp3;
tmp4 = tmp4 + 1 ;
PushPram tmp4 ;
LCall _PrintInt ;
PopParams 4;
tmp6 = 10 ;
tmp5 = tmp4 == tmp6 ;
IfZ tmp5 Goto L0 ;
We have an intuition of what makes a loop in a flow graph, but here is a more formal definition. A loop is a set of basic blocks which satisfies two conditions:
For loop L, moving invariant statement s in block B which defines variable v outside the loop is a safe optimization if:
Loop invariant code can be moved to just above the entry point to the loop.