0% found this document useful (0 votes)
9 views15 pages

Unit 5 12mark CD

Uploaded by

ruthnaruthna6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views15 pages

Unit 5 12mark CD

Uploaded by

ruthnaruthna6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

01.Elucidate the principal sources of optimization in computer programs.

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.

(ii). Construct the DAG for the following Basic block .

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

10. if i<= 20 goto (1).


04.Write about the following in detail

(i) Semantic preserving transformation

(ii)Global Common subexpression

Ans

(i) Steps to Identify Loops in a Basic Block:

1. **Determine Back Edges:** Identify backward branches (conditional or unconditional jumps)


within the basic block.

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).

(ii) Induction Variable and Loop Strength Reduction:

- **Induction Variable:** In a loop, an induction variable is a variable whose value is incremented


or decremented by a constant amount on each iteration. Commonly denoted as "i," it serves as a
control variable. For example, in the loop `for (int i = 0; i < N; i++)`, "i" is the induction variable.

- **Loop Strength Reduction (LSR):** LSR is an optimization technique that transforms


expensive operations inside a loop into cheaper ones. It involves replacing high-cost operations
with equivalent, lower-cost operations. For instance, replacing multiplication with addition or
converting division to multiplication. This helps in improving the performance of the loop by
reducing the computational load.

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;

while ( i<= 10)

s = s+ a[i] [i];

i = i + 1;

}
06.

Ans
07.(i)Formulate steps to identify the loops in the basic block.

(ii) Describe about induction variable and end reduction in strength

Ans

(i) Steps to Identify Loops in a Basic Block:

1. **Determine Back Edges:** Identify backward branches (conditional or unconditional jumps)


within the basic block.

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).

(ii) Induction Variable and Loop Strength Reduction:

- **Induction Variable:** In a loop, an induction variable is a variable whose value is incremented


or decremented by a constant amount on each iteration. Commonly denoted as "i," it serves as a
control variable. For example, in the loop `for (int i = 0; i < N; i++)`, "i" is the induction variable.

- **Loop Strength Reduction (LSR):** LSR is an optimization technique that transforms


expensive operations inside a loop into cheaper ones. It involves replacing high-cost operations
with equivalent, lower-cost operations. For instance, replacing multiplication with addition or
converting division to multiplication. This helps in improving the performance of the loop by
reducing the computational load.
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.

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;

You might also like