Unit 5 12mark CD
Unit 5 12mark CD
Include a
comprehensive explanation of each source, highlighting their respective contributions to
enhancing program performance.
02.Create an illustrative examples to demonstrate the practical implementation and outcomes
of the peephole optimizations, fostering a higher level of understanding of their applicability and
impact on program performance
03.(i)Determine the optimization techniques utilized for basic blocks in
computer programs.
1. t1: = 4 * i
2. t2:= a [t1]
3. t3: = 4 * i
4. t4:= b [t3]
5. t5:=t2*t4
6. t6:=Prod+t5
7. Prod:=t6
8. t7:=i+1
9. i:=t7
Ans
2. **Build the Dominator Tree:** Construct the dominator tree for the basic block, representing
control flow relationships.
3. **Find Natural Loops:** Natural loops are regions of code bounded by a single entry point
(header) and a single exit point (back edge). Identify natural loops by examining the dominator
tree.
4. **Classify Loops:** Classify the loops based on their structure (single, nested, or disjoint) and
type (for, while, do-while).
End Reduction in Strength involves transforming expensive operations near the end of a loop to
less expensive ones, aiming to optimize the loop's overall efficiency. This might include
replacing complex calculations with simpler ones or eliminating unnecessary computations.
05.Create DAG representation and three – address code for the following C program.
i = 1; s = 0;
s = s+ a[i] [i];
i = i + 1;
}
06.
Ans
07.(i)Formulate steps to identify the loops in the basic block.
Ans
2. **Build the Dominator Tree:** Construct the dominator tree for the basic block, representing
control flow relationships.
3. **Find Natural Loops:** Natural loops are regions of code bounded by a single entry point
(header) and a single exit point (back edge). Identify natural loops by examining the dominator
tree.
4. **Classify Loops:** Classify the loops based on their structure (single, nested, or disjoint) and
type (for, while, do-while).
08.For the following program segment construct the flow graph and apply the possible
optimization.
Sum:=0
I:=1;
Do
Sum:=prod+A[I]*B[I];
I=I+1;
While I<=20;