final class ValueGraph extends Object
From Muchnick, "the value graph of a procedure is a labeled directed graph whose nodes are labeled with operators, function symbols, or constants, and whose edges represent generating assignments and point from an operator or function to its operands; the edges are labeled with natural numbers that indicate the operand position that each operand has with respect to the given operator or function."
Modifier and Type | Field and Description |
---|---|
private SpaceEffGraph |
graph
Internal graph structure of the value graph.
|
private HashMap<Object,ValueGraphVertex> |
nameMap
A mapping from name to value graph vertex.
|
Constructor and Description |
---|
ValueGraph(IR ir)
Construct a value graph from an IR.
|
Modifier and Type | Method and Description |
---|---|
private void |
addRegisterNodes(IR ir)
Add a node to the value graph for every symbolic register.
|
private Operand |
bypassMoves(Operand op)
Bypass MOVE instructions that def an operand: return the first def
in the chain that is not the result of a MOVE instruction.
|
private void |
computeClosure()
Due to PI nodes and Moves, the initial label for a register may be
another register.
|
Enumeration<GraphNode> |
enumerateVertices()
Enumerate the vertices in the value graph.
|
private ValueGraphVertex |
findOrCreateVertex(ConditionOperand op)
Find or create an ValueGraphVertex corresponding to a
given method operand
|
private ValueGraphVertex |
findOrCreateVertex(ConstantOperand op)
Find or create an ValueGraphVertex corresponding to a
given constant operand
|
private ValueGraphVertex |
findOrCreateVertex(MethodOperand op)
Find or create an ValueGraphVertex corresponding to a
given method operand
|
private ValueGraphVertex |
findOrCreateVertex(Object var)
Find or create an ValueGraphVertex corresponding to a
given variable.
|
private ValueGraphVertex |
findOrCreateVertex(Register r)
Find or create an ValueGraphVertex corresponding to a
given register
|
private ValueGraphVertex |
findOrCreateVertex(TypeOperand op)
Find or create an ValueGraphVertex corresponding to a
given type operand
|
ValueGraphVertex |
getVertex(Object name)
Return the vertex which has a given name.
|
private void |
link(ValueGraphVertex src,
ValueGraphVertex target,
int pos)
Link two vertices in the value graph
|
private void |
processALoad(Instruction s)
Update the value graph to account for a given ALOAD instruction.
|
private void |
processAStore(Instruction s)
Update the value graph to account for a given ASTORE instruction.
|
private void |
processBinary(Instruction s)
Update the value graph to account for a given Binary instruction.
|
private void |
processCall(Instruction s)
Update the value graph to account for a given Call instruction.
|
private void |
processGuardedBinary(Instruction s)
Update the value graph to account for a given GuardedBinary instruction.
|
private void |
processGuardedUnary(Instruction s)
Update the value graph to account for a given GuardedUnary instruction.
|
private void |
processIfCmp(Instruction s)
Update the value graph to account for a given IfCmp instruction.
|
private void |
processInlineGuard(Instruction s)
Update the value graph to account for a given InlineGuard instruction.
|
private void |
processInstruction(Instruction s)
Update the value graph to account for a given instruction.
|
private void |
processMove(Instruction s)
Update the value graph to account for a given MOVE instruction.
|
private void |
processNew(Instruction s)
Update the value graph to account for a given NEW instruction.
|
private void |
processNewArray(Instruction s)
Update the value graph to account for a given NEWARRAY instruction.
|
private void |
processNullCheck(Instruction s)
Update the value graph to account for a given NullCheck instruction.
|
private void |
processPhi(Instruction s)
Update the value graph to account for a given Phi instruction.
|
private void |
processPi(Instruction s)
Update the value graph to account for a given PI instruction.
|
private void |
processPrologue(Instruction s)
Update the value graph to account for an IR_PROLOGUE instruction
PRECONDITION:
Prologue.conforms(s); |
private void |
processPutField(Instruction s)
Update the value graph to account for a given PUTFIELD instruction.
|
private void |
processPutStatic(Instruction s)
Update the value graph to account for a given PUTSTATIC instruction.
|
private void |
processUnary(Instruction s)
Update the value graph to account for a given Unary instruction.
|
private void |
processZeroCheck(Instruction s)
Update the value graph to account for a given NullCheck instruction.
|
String |
toString()
Return a String representation of the value graph.
|
private final SpaceEffGraph graph
private final HashMap<Object,ValueGraphVertex> nameMap
ValueGraph(IR ir)
PRECONDITION: The IR must be in SSA form.
ir
- the IRprivate void computeClosure()
public Enumeration<GraphNode> enumerateVertices()
public ValueGraphVertex getVertex(Object name)
name
- the name of the vertexprivate void addRegisterNodes(IR ir)
PRECONDITION: register lists are computed and valid
ir
- the governing IRprivate void processInstruction(Instruction s)
s
- the instruction in questionprivate void processMove(Instruction s)
PRECONDITION: Move.conforms(s);
s
- the instruction in questionprivate void processPi(Instruction s)
PRECONDITION: s.operator == PI
s
- the instruction in questionprivate void processNew(Instruction s)
PRECONDITION: New.conforms(s);
For a new instruction, we always create a new vertex.
s
- the instruction in questionprivate void processNewArray(Instruction s)
PRECONDITION: NewArray.conforms(s);
For a newarray instruction, we always create a new vertex.
s
- the instruction in questionprivate void processPutField(Instruction s)
PRECONDITION: PutField.conforms(s);
Make sure we have value graph nodes for a constant value
s
- the instruction in questionprivate void processPutStatic(Instruction s)
PRECONDITION: PutStatic.conforms(s);
Make sure we have value graph nodes for a constant value
s
- the instruction in questionprivate void processAStore(Instruction s)
PRECONDITION: AStore.conforms(s);
Make sure we have value graph nodes for a constant value
s
- the instruction in questionprivate void processALoad(Instruction s)
PRECONDITION: ALoad.conforms(s);
Make sure we have value graph nodes for a constant value
s
- the instruction in questionprivate void processUnary(Instruction s)
PRECONDITION: Unary.conforms(s);
s
- the instruction in questionprivate void processGuardedUnary(Instruction s)
PRECONDITION: GuardedUnary.conforms(s);
Careful: we define two Guarded Unaries to be equivalent regardless of
whether the guards are equivalent!
s
- the instruction in questionprivate void processNullCheck(Instruction s)
PRECONDITION: NullCheck.conforms(s);
s
- the instruction in questionprivate void processZeroCheck(Instruction s)
PRECONDITION: ZeroCheck.conforms(s);
s
- the instruction in questionprivate void processBinary(Instruction s)
PRECONDITION: Binary.conforms(s);
s
- the instruction in questionprivate void processGuardedBinary(Instruction s)
PRECONDITION: GuardedBinary.conforms(s);
Careful: we define two Guarded Binaries to be equivalent regardless of
whether the guards are equivalent!
s
- the instruction in questionprivate void processInlineGuard(Instruction s)
PRECONDITION: InlineGuard.conforms(s);
s
- the instruction in questionprivate void processIfCmp(Instruction s)
PRECONDITION: IfCmp.conforms(s);
s
- the instruction in questionprivate void processPhi(Instruction s)
PRECONDITION: Phi.conforms(s);
s
- the instruction in questionprivate void processPrologue(Instruction s)
PRECONDITION: Prologue.conforms(s);
s
- the instruction in questionprivate void processCall(Instruction s)
PRECONDITION: Call.conforms(s);
s
- the instruction in questionprivate ValueGraphVertex findOrCreateVertex(Object var)
var
- The variableprivate ValueGraphVertex findOrCreateVertex(Register r)
r
- the registerprivate ValueGraphVertex findOrCreateVertex(ConstantOperand op)
op
- the constant operandprivate ValueGraphVertex findOrCreateVertex(TypeOperand op)
op
- the operand in questionprivate ValueGraphVertex findOrCreateVertex(MethodOperand op)
op
- the operand in questionprivate ValueGraphVertex findOrCreateVertex(ConditionOperand op)
op
- the operand in questionprivate void link(ValueGraphVertex src, ValueGraphVertex target, int pos)
src
- the deftarget
- the usepos
- the position of target in the set of usesprivate Operand bypassMoves(Operand op)
Note: treat PI instructions like MOVES
op
- the RegisterOperand