CS 6013 - Advanced Compiler Design

Assignment 3: Conditional Constant Propagation.

This assignment is the third part of a multi part project to write an optimizing compiler for Minijava. We start with TACoJava programs and after doing constant propagation (P3), generate optimized programs in TACoJava2 format.

Use JTB and JavaCC, to write in Java one or more visitors which implement context-insensitive conditional constant propagation. Use CHA to build a call-graph. Your main file should be called P3.java, if P.java contains a program to be optimized in TACoJava form then

java P3 < P.java > Pc.java

should create Pc.java in TACoJava2 form and is semantically equivalent to P.java with some of the variables replaced with constants. Note, your program must take input program from standard input and write to standard output (so that we can use redirection). Your code should (i) do constant propagation, and (ii) elide unused assignments + unreachable code that can be identified after the constant propagation pass.

Some instances of redundant code:

  1. x = expr; -- this definition reaches no use, and expr has no side effects.
  2. a.foo(); -- the function has no side-effects.
Some instances of unreachable code:
  1. if (true) S1 else S2 -- S1
  2. if (false) S1 else S2 -- S2
  3. S1; while (false) {S2} S3 -- S1; S3
  4. A function foo of a class A, that is never called.

Grading policy
Your homework will be graded for a total of 100 marks.
[ under development ]