




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





Instructions
b. Translate it into 3-address code load R1 b load R2 c sub R3 R1 R load R4 a sub R5 R4 R
c. Translate it into Java stack code iload index(a) iload index(b) iload index(c) isub isub
d. Name an advantage of using 3-address code instead of stack code. Greater flexibility in reordering/eliminating instructions.
a. A Ruby-style UPTO loop iterates (exp$_2$-exp$_1$+1) number of times. For example, 5 upto (2+6) do ... end would iterate 4 times. Write syntax-directed actions needed to generate code for a UPTO loop for the following grammar production. Note you can only use the Java instructions provided at the beginning of the exam. stmt exp 1 UPTO exp 2 DO { stmtList } END {: stmt.code = ?? :}
exp := exp 1 NAND exp 2 {: Handle h1 = genInst( NOP ); // end of UPTO loop Handle h2 = genInst( NOP ); // beginning of UPTO loop
exp.code = append( exp 1 .code, genInst( ISTORE( index(1) ) ), exp 2 .code,
a. How are objects and classes implemented in the run-time environment? Class records and object records. b. What compiler-generated code is need to support inheritance? Code to check class type via object tags. c. What is prefixing? Assigning object fields and method references to the same index for subclasses, so dynamic checks of class type will not be needed.
a. Give an example of a machine-independent optimization, and explain why it is machine-independent Eliminating redundancy, since executing fewer instructions usually improves performance b. Give an example of a machine-dependent optimization, and explain why it is machine-dependent Register allocation, since number of registers is machine dependent c. Why would a compiler writer decide not to implement a particular optimization? Insufficent improvement, or rarity of occurence
a. Perform renaming for the code a 0 := b 0 + c 0 b 1 := b 0 + c 0 c 1 := b 1 + c 0
b. Build a DAG for the renamed code
c. How do DAGs support optimizations? By exposing common subexpressions
a. What are the basic blocks? B1 = { S1 } B2 = { S2, S3 } B3 = { S4, S5 } B4 = { S6 } b. What is the control flow graph
c. What is a reverse Postorder numbering of the basic blocks? B1, B2, B3, B4 or B1, B2, B4, B d. Why do compilers use basic blocks? To find regions of code with no control flow where local optimizations may be performed. To reduce the size of the control flow graph. To allow effects of multiple statements to be summarized together.
a. Calculate GEN/KILL for each basic block
B1 a+c, a+b a+b B2 a+c (^)
B3 a+b a+c B4 a+c (^)
b. Solve available expressions, showing IN/OUT for each pass
Init Pass1 Pass2 Pass B1 IN (^) OUT (^) a+c, a+b a+c, a+b a+c, a+b
B2 IN (^) a+b a+b OUT (^) a+c a+c, a+b a+c, a+b B3 IN (^) a+c, a+b a+c, a+b
OUT (^) a+b a+b a+b B4 IN (^) a+b a+b a+b
OUT (^) a+c, a+b a+c, a+b a+c, a+b
Recall that is used in data-flow iterative analysis to combine information where paths merge.
a. Using properties of the operator, prove a b and b a imply a = b. a b implies a b = a, and b a implies b a = b. Since (^) is commutative, a b = b a, so a = a b = b a = b, and a = b.
b. For reaching definitions, pick values for a, b, c for which a > b and b > c. a = { a, b, c }, b = {a, b}, c = {b}
c. For very busy expressions, pick values for a, b for which neither a b or b a are true? a = {a+b}, b = {a+c}
d. How is defined in terms of the operator? a =
e. What is monotonicity and why is it important for iterative data-flow problems? Monotonicity means f(x y) f(x) f(y), and is required for guaranteeing iterative data-flow problems will converge.