
Compiler Construction – SMD163
Homework assignment 6
1.
Rewrite the following program to a form which uses a while-loop instead of the for-statement:
int minimum =
a[lo];
for (int
i=lo+1; i<hi; i++)
if (a[i] < minimum) {
int t = a[i];
a[i] = minimum;
minimum = t;
}
a[lo]=
minimum;
2.
Define a generic transformation scheme (similar to our previous
compilation schemes) that
replaces any for-loop with a
corresponding while.
3.
Translate the rewritten program fragment above into a sequence
of three-address instructions using
the intermediate code that has been presented in lectures (see notes). Although formal compilation
schemes have not been defined, you should be able to do this
translation in a rather principled
and mechanical fashion. All variables mentioned can be treated as valid
operands to the three-address
instructions.
4.
Identify the basic blocks in the resulting code, and sketch the
structure of the underlying flowgraph.
5.
Show the the result of applying local common subexpression elimination,
copy propagation, and
dead code elimination to this program fragment.
6.
Show how the program can be further improved by identifying
induction variables and using
strength reduction.
Report via email to
Subject line: SMD163 - 6.
Deadline is Mar 6, 8:00.
Homework assignments are carried out individually.
Oral discussion is good, copying
files is not!