The cost of a subscription for a hospital intern to the New…
Questions
The cоst оf а subscriptiоn for а hospitаl intern to the New England Journal of Medicine is a deductible expense for the hospital.
Prоblem 1: Optimizаtiоn Shоrt Answers (8 points) [5 minutes] The following questions concern the interаctions between different optimizаtions a compiler can do. You should be able to answer them in 1 to 2 sentences each. Answers with more than three sentences will not be graded. (A) Performing common subexpression elimination (CSE) can make dead code elimination (DCE) worse. Why? (4 points) (B) Performing CSE on assembly after register allocation can be less effective than performing CSE on three address code. Why? (4 points) Problem 2: Function Calls and Semantic Actions (15 points) [10 minutes] (A) For the following function, show what the activation record for calling the function would be, including both what the caller sets up and what the callee sets up. Make the following assumptions: the machine has four registers, plus special registers such as FP and SP, and all the registers are 4 bytes; the machine follow 4-byte aligned i.e. the minimum number bytes reserved on the stack has to be in 4-bytes granularity (Hint: for handling char) the program is using caller saves; the compiler had to spill one temporary in foo (holding an integer) to the stack. Show the stack growing down (as in the notes); Assume chars are 1 byte; doubles are 8 bytes; and ints, floats and pointers are 4 bytes. For each entry in the stack, show how many bytes that entry takes up. (8 points) 1. double foo (int x, char∗ y, double∗ z) {2. char a3 int b;4. double c;5. c = x + (a + z * 20.0);6. return z;7. } (B) Does line 5 correctly type check? Justify your answer by drawing the type checking tree for the statement. If the statement type checks, show all the types assigned to the sub-components. If the statement does not type check, show the types assigned to the components that do type check, and indicate where type checking fails. (7 points) Problem 3: Common Subexpression Elimination (26 points) [15 minutes] Consider the following piece of code: B = A + B C = A + B A = B + C D = B + C A = A + B (A) Assume there is no aliasing between variables. For each statement, list which expressions are "available" after the statement executes. (10 points) After Instruction Available Expressions 1 2 3 4 5 (B) What does the code look like after performing CSE? When eliminating a redundant expression, replace it with the variable that holds the previous result of computing the expression. (8 points) (C) How would your response to part (B) change if C and D were aliased? (8 points) Problem 4: Local Register Allocation (27 points) [15 minutes] Consider the following code (assume this is the full program): 1 READ (A) 2 READ (B) 3 C = B + A 4 B = C ∗ 2 5 D = B ∗ A 6 C = D + A 7 E = C − A 8 B = D ∗ C 9 A = E + B 10 WRITE(C) //this counts as a use of C 11 WRITE(D) //this counts as a use of D (A) Answer the following questions: Finish the following table. Show which variables and temporaries are live after each instruction (assume no aliasing and this is the entire program). (11 points) After Instruction Live Variables 1 2 3 4 5 6 7 8 9 10 11 (B) For the following scenarios, show what code needs to be generated using bottom-up register allocation for the given three-address-code instruction and give the state of the registers after code generation (if a value in a register is dirty, mark it with a *). If variables need to be spilled, spill non-dirty registers before dirty registers, and if there is a tie, spill the one farthest used in the future. Before instruction 7, assume the state of the registers is as follows: R1 R2 R3 A* D* C* 1. What code is generated for instruction 7, E = C - A (assume E, C and D are live after this instruction) (4 points) 2. What is the state of the registers after this code (4 points)? R1 R2 R3 3. Based on the register states you computed above, what code is generated for the next instruction (instruction 8), B = D * C (assume B, E, C and D are live after this instruction) (4 points)? 4. What is the state of the registers after this code (4 points)? R1 R2 R3 Congratulations, you are almost done with this exam. DO NOT end the Examity session until you have submitted your work to Gradescope. When you have answered all questions: Use your smartphone to scan your answer sheet and save the scan as a PDF. Make sure your scan is clear and legible. Submit your PDF to Gradescope as follows: Email your PDF to yourself or save it to the cloud (Google Drive, etc.). Click this link to go to Gradescope: Final Exam Submit your exam to the assignment Final Exam. Return to this window and click the button below to agree to the honor statement. Click Submit Quiz to end the exam. End the Examity session.