|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectopt.Optimizer
public final class Optimizer
The Optimizer class optimizes the program. It first converts the AST into a control flow graph of basic blocks containing three address code. It then performs data-flow analyses on the CFG and uses these analyses to transform the CFG. Finally, it converts the CFG to assembly code. This class is incomplete and will need to be implemented by the student.
Constructor Summary | |
---|---|
Optimizer(util.ClassTreeNode root,
boolean debug)
Optimizer constructor |
Method Summary | |
---|---|
java.util.Map<java.lang.String,java.lang.Object> |
applyVisitor(visitor.Visitor visitor,
java.lang.Object o)
Applies a visitor to all ClassTreeNodes. |
void |
buildCFG()
Build the control flow graph |
protected int |
getClassID(java.lang.String name)
Get class identifier |
static java.lang.String |
getDestination(TACInst inst)
Gets the destination of an instruction or null if none |
static java.util.Set<java.lang.String> |
getFieldsUsedInCFG(BasicBlock entryBB)
Returns all field vars written to or read from in the CFG starting at entryBB. |
protected int |
getMethodIdx(java.lang.String refType,
java.lang.String name)
Get method index |
static java.lang.String |
getNextTmp()
Get a new temporary |
static java.lang.String |
getOperand1(TACInst inst)
Gets the first operand of an instruction or null if none |
static java.lang.String |
getOperand2(TACInst inst)
Gets the second operand of an instruction or null if none |
static java.util.Set<java.lang.String> |
getSources(TACInst inst)
Returns new a set with all variables used by given instruction. |
static java.util.Set<java.lang.String> |
getSources(TACInst inst,
java.util.Set<java.lang.String> in)
Returns a set with all variables used by given instruction; if in is not null, it will be used to store result (not cleared). |
protected java.lang.String |
getStaticName(java.lang.String refType,
java.lang.String name)
Get static method name or null if must use dynamic dispatch |
static boolean |
isCallToBuiltIn(CallInst inst)
Returns true, if given call instruction calls a method in a built-in class. |
static boolean |
isField(java.lang.String str)
Is this string a field name |
static boolean |
isNotConst(java.lang.String v)
Returns true, if this a use which should be considered. |
void |
optimize(Optimization optimization)
Perform specified optimization pass on current CFG. |
void |
print()
Print out program |
protected void |
printDot(java.lang.String prefix)
Outputs a .dot file for each non-builtin method for every class. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Optimizer(util.ClassTreeNode root, boolean debug)
root
- root of the class hierarchy treeoptLevel
- level of optimizationdebug
- boolean indicating whether debugging is enabledMethod Detail |
---|
public void optimize(Optimization optimization)
optimization
- Optimization passprotected void printDot(java.lang.String prefix)
prefix
- Filename prefix, e.g. "ssa_"public void print()
public java.util.Map<java.lang.String,java.lang.Object> applyVisitor(visitor.Visitor visitor, java.lang.Object o)
visitor
- Visitor to applyo
- data to pass to the visitor
public void buildCFG()
public static java.lang.String getNextTmp()
public static java.lang.String getDestination(TACInst inst)
inst
- instruction to check
public static java.util.Set<java.lang.String> getSources(TACInst inst)
inst
- TACInst
public static java.util.Set<java.lang.String> getSources(TACInst inst, java.util.Set<java.lang.String> in)
inst
- TACInstin
- null or set to store result in
public static java.lang.String getOperand1(TACInst inst)
inst
- instruction to check
public static java.lang.String getOperand2(TACInst inst)
inst
- instruction to check
public static boolean isField(java.lang.String str)
str
- string to check
public static final boolean isNotConst(java.lang.String v)
v
- Use
public static java.util.Set<java.lang.String> getFieldsUsedInCFG(BasicBlock entryBB)
entryBB
- Entry block of CFG
public static boolean isCallToBuiltIn(CallInst inst)
inst
- call instruction.
protected int getClassID(java.lang.String name)
name
- name of class
protected int getMethodIdx(java.lang.String refType, java.lang.String name)
refType
- name of reference class typename
- name of method
protected java.lang.String getStaticName(java.lang.String refType, java.lang.String name)
refType
- name of reference class typename
- name of method
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |