public final class Optimizer
extends java.lang.Object
Constructor and Description |
---|
Optimizer(util.ClassTreeNode root,
boolean debug)
Optimizer constructor
|
Modifier and Type | Method and Description |
---|---|
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.
|
public Optimizer(util.ClassTreeNode root, boolean debug)
root
- root of the class hierarchy treeoptLevel
- level of optimizationdebug
- boolean indicating whether debugging is enabledpublic 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 visitorpublic void buildCFG()
public static java.lang.String getNextTmp()
public static java.lang.String getDestination(TACInst inst)
inst
- instruction to checkpublic static java.util.Set<java.lang.String> getSources(TACInst inst)
inst
- TACInstpublic 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 inpublic static java.lang.String getOperand1(TACInst inst)
inst
- instruction to checkpublic static java.lang.String getOperand2(TACInst inst)
inst
- instruction to checkpublic static boolean isField(java.lang.String str)
str
- string to checkpublic static final boolean isNotConst(java.lang.String v)
v
- Usepublic static java.util.Set<java.lang.String> getFieldsUsedInCFG(BasicBlock entryBB)
entryBB
- Entry block of CFGpublic static boolean isCallToBuiltIn(CallInst inst)
inst
- call instruction.protected int getClassID(java.lang.String name)
name
- name of classprotected int getMethodIdx(java.lang.String refType, java.lang.String name)
refType
- name of reference class typename
- name of methodprotected java.lang.String getStaticName(java.lang.String refType, java.lang.String name)
refType
- name of reference class typename
- name of method