/** Merge the congruence classes containing vertices v1 and v2.; */ public void mergeClasses(OPT_ValueGraphVertex v1, OPT_ValueGraphVertex v2) { if (DEBUG) { System.out.println("@@@@ mergeClasses called with v1 = " + v1 + " ; v2 = " + v2); } int val1 = v1.getValueNumber(); int val2 = v2.getValueNumber(); if (val1 == val2) return; OPT_GVCongruenceClass class1 = (OPT_GVCongruenceClass) B.get(val1); while (true) { OPT_GVCongruenceClass class2 = (OPT_GVCongruenceClass) B.get(val2); Iterator i = class2.iterator(); if (!i.hasNext()) break; OPT_ValueGraphVertex v = (OPT_ValueGraphVertex) i.next(); if (DEBUG) System.out.println("@@@@ moving vertex " + v + " from class " + val2 + " to class " + val1); class1.addVertex(v); class2.removeVertex(v); v.setValueNumber(val1); } // Null out entry for val2 B.set(val2, null); }
/** Print the value numbers for each node in the value graph. */ public void printValueNumbers() { for (Enumeration e = valueGraph.enumerateVertices(); e.hasMoreElements(); ) { OPT_ValueGraphVertex v = (OPT_ValueGraphVertex) e.nextElement(); int valueNumber = v.getValueNumber(); OPT_GVCongruenceClass c = (OPT_GVCongruenceClass) B.get(valueNumber); System.out.println(v.name + " " + valueNumber + " " + c.getLabel()); } }
/** * Definitely-different relation for two value numbers. Returns true for the following cases: * * <ul> * <li>v1 and v2 are both constants, but don't match * <li>v1 and v2 both result from NEW statements, but don't match * <li>one of v1 and v2 is a parameter, and the other results from a new statement * </ul> * * <p>TODO: add more smarts * * @param v1 first value number * @param v2 second value number * @return true iff the value numbers for two variables are definitely different */ public boolean DD(int v1, int v2) { if ((v1 == -1) || (v2 == -1)) return false; OPT_GVCongruenceClass class1 = (OPT_GVCongruenceClass) B.get(v1); OPT_GVCongruenceClass class2 = (OPT_GVCongruenceClass) B.get(v2); Object label1 = class1.getLabel(); Object label2 = class2.getLabel(); // if one is a constant, they must both be ... if (isConstant(label1) && !isConstant(label2)) return false; if (!isConstant(label1) && isConstant(label2)) return false; if (isConstant(label1)) return (v1 != v2); // handle DD for allocations if (isBornAtAllocation(label1)) { if (isBornAtAllocation(label2)) { // both are NEW. Are they dd? return (v1 != v2); } else if (class2.containsParameter()) { // one is NEW, other is parameter. They are DD. return true; } } else { if (isBornAtAllocation(label2)) { if (class1.containsParameter()) { // one is NEW, other is parameter. They are DD. return true; } } } // assume parameters are not aliased? if (NO_PARAM_ALIAS) { if (v1 != v2) { if (class1.containsParameter()) { if (class2.containsParameter()) { return true; } } } } // if we haven't figured out they're DD, return false; return false; }
public OPT_GVCongruenceClass congruenceClass(Object name) { OPT_ValueGraphVertex v = valueGraph.getVertex(name); return ((OPT_GVCongruenceClass) B.get(v.getValueNumber())); }