public final class GlobalValueNumberState extends Object
Modifier and Type | Field and Description |
---|---|
private ArrayList<GVCongruenceClass> |
B
ArrayList of GVCongruenceClass, indexed by value number.
|
private static boolean |
DEBUG
Print verbose debugging output?
|
private static boolean |
NO_PARAM_ALIAS
Assume parameters are not aliased?
|
static int |
UNKNOWN
Constant used to flag "unknown" value numbers
|
(package private) ValueGraph |
valueGraph
The value graph.
|
private Stack<GVCongruenceClass> |
workList
Stack used for a work list.
|
Constructor and Description |
---|
GlobalValueNumberState(IR ir)
Construct a structure to hold global value number results for an IR.
|
Modifier and Type | Method and Description |
---|---|
private void |
addDependentClassesToWorklist(GVCongruenceClass c)
Assuming congruence class c has changed: find all other classes
that might be affected, and add them to the worklist
|
private boolean |
checkCongruence(ValueGraphVertex v,
GVCongruenceClass c)
Does the current state of the algorithm optimistically assume
that a vertex v is congruent to the vertices in a congruence
class?
|
private boolean |
checkCongruence(ValueGraphVertex v1,
ValueGraphVertex v2)
Does the current state of the algorithm optimistically assume
that two nodes are congruent?
|
(package private) GVCongruenceClass |
congruenceClass(Object name) |
private GVCongruenceClass |
createCongruenceClass(Object label)
Given a label, return a new congruence class for that label.
|
(package private) boolean |
DD(int v1,
int v2)
Definitely-different relation for two value numbers.
|
(package private) boolean |
DD(Object name1,
Object name2)
Definitely-different relation.
|
(package private) boolean |
DS(Object name1,
Object name2)
Definitely-same relation.
|
private int |
findCongruenceMatch(ArrayList<GVCongruenceClass> vector,
ValueGraphVertex v)
Does vertex v belong to any congruence class in a vector?
|
private GVCongruenceClass |
findOrCreateCongruenceClass(Object label,
HashMap<Object,GVCongruenceClass> labelMap)
Given a label, return the congruence class for that label.
|
(package private) int |
getValueNumber(Object name)
Return the (integer) value number for a given variable
|
private void |
globalValueNumber()
Compute node congruence over the value number graph.
|
private void |
initialize()
Initialize the congruence classes, assuming that all nodes
with the same label are congruent.
|
private void |
initializeWorkList()
Initialize the work list.
|
private static boolean |
isBornAtAllocation(Object label) |
private static boolean |
isConstant(Object label) |
(package private) void |
mergeClasses(ValueGraphVertex v1,
ValueGraphVertex v2) |
private void |
partitionClass(GVCongruenceClass partition)
Partition a congruence class.
|
(package private) void |
printValueNumbers()
Print the value numbers for each node in the value graph.
|
public static final int UNKNOWN
private static final boolean DEBUG
private static final boolean NO_PARAM_ALIAS
private final ArrayList<GVCongruenceClass> B
final ValueGraph valueGraph
private final Stack<GVCongruenceClass> workList
GlobalValueNumberState(IR ir)
ir
- governing IRprivate void globalValueNumber()
Algorithm: Muchnick pp. 348-355
Note: the Muchnick algorithm is buggy. In particular, it does not put all needed congruence classes on the worklist.
Two nodes in the value graph are congruent if one of the following holds:
Optimistic algorithm:
The following method breaks Muchnick's algorithm, which will assign m and n the same value number. Muchnick's problem is that it does not put the congruence class for 'int_mul' back on the worklist when we discover, for example, that i is not congruent to k
public int foo(int a, int b, int c, int d, int e, int f, int g, int h) { int i = a+b; int j = c+d; int k = e+f; int l = g+h; int m = i * j; int n = k * l; int o = m/n; return o; }
void mergeClasses(ValueGraphVertex v1, ValueGraphVertex v2)
boolean DS(Object name1, Object name2)
name1
- first variablename2
- second variableboolean DD(int v1, int v2)
TODO: add more smarts
v1
- first value numberv2
- second value numberboolean DD(Object name1, Object name2)
TODO: add more smarts
name1
- name of first object to comparename2
- name of second object to compareGVCongruenceClass congruenceClass(Object name)
int getValueNumber(Object name)
name
- name of the variable to look upvoid printValueNumbers()
private void initialize()
private GVCongruenceClass findOrCreateCongruenceClass(Object label, HashMap<Object,GVCongruenceClass> labelMap)
label
- the label of a congruence classlabelMap
- a mapping from labels to congruence classprivate GVCongruenceClass createCongruenceClass(Object label)
label
- the label of a congruence classprivate void initializeWorkList()
private void partitionClass(GVCongruenceClass partition)
partition
- the class to partitionprivate void addDependentClassesToWorklist(GVCongruenceClass c)
c
- the congruence class that has changedprivate int findCongruenceMatch(ArrayList<GVCongruenceClass> vector, ValueGraphVertex v)
vector
- a vector of congruence classesv
- the vertex to search forprivate boolean checkCongruence(ValueGraphVertex v, GVCongruenceClass c)
v
- the vertex in questionc
- the congurence class to checkprivate boolean checkCongruence(ValueGraphVertex v1, ValueGraphVertex v2)
v1
- first vertexv2
- second vertexprivate static boolean isConstant(Object label)
label
- a labelprivate static boolean isBornAtAllocation(Object label)
label
- a label