README for lab5: Code generation Ling Li & Xin Yu, Caltech, 03/14/2001 ---------------------------------------------------------------------- We use the solutions for lab5. Our work focused on the optimization. Inline and Common-subexpression elimination (CSE) are implemented. ---------------------------------------------------------------------- Changed files (from lab4): fc_ir/fc_ir_ast.ml IR generation fc_fir/fc_ir_cont.ml CPS conversion fc_fir/fc_ir_esc.ml Escape analysis fc_fir/fc_ir_closure.ml Closure conversion fc_fir/fc_fir_dead.ml Dead code elimination fc_fir/fc_fir_inline.ml Function inlining and constant folding fc_fir/fc_fir_cse.ml Common-subexpression elimination (CSE) ---------------------------------------------------------------------- Main ideas: LetFuns2: Add changes for LetFuns2. Now no LetFuns is used. Inline: 1. Constant expressions: do the computation during compiling. 3 + 4 -> 7; if (1 > 0) e1 else e2 -> e1 2. Short-cut expressions: simplify them. x * 0 -> 0; i + 0 -> i. 3. Mul & Div with 2's power: change to shift. x / 32 -> x >> 5 (ASL) 4. ExtCall/IntCall: cancel ExtCall/IntCall pair. 5. Nested closures: expand them. 6. Small functions: inline it during tail-call. CSE: Compare two expression trees. If they are the same, just keep one copy. For BinOp, we use different comparisons for Plus, Mul (expression has no order) and Minus, Div (expression has order). ---------------------------------------------------------------------- To do: 1. Some old problems in Lab 2, 3, 4. 2. Our code generation and register allocation. 3. More complicated comparisons in CSE. 4. Code hoisting. ---------------------------------------------------------------------- This README file together with the programs can be found at http://www.cs.caltech.edu/~ling/course/cs134b/lab5/