Exemplo n.º 1
0
 /**
  * Does the current state of the algorithm optimistically assume that two nodes are congruent?
  * Note: this can return false even if the value numbers are currently the same.
  *
  * @param v1 first vertex
  * @param v2 second vertex
  */
 private boolean checkCongruence(OPT_ValueGraphVertex v1, OPT_ValueGraphVertex v2) {
   if (v1 == v2) return true;
   // make sure the two nodes have the same label
   if (v1.getLabel() != v2.getLabel()) return false;
   // make sure that the operands match
   int arity = v1.getArity();
   for (int i = 0; i < arity; i++) {
     OPT_ValueGraphVertex target1 = v1.getTarget(i);
     OPT_ValueGraphVertex target2 = v2.getTarget(i);
     // if either target is null, then that particular control
     // flow path is never realized, so assume TOP
     if ((target1 == null) || (target2 == null)) continue;
     if (target1.getValueNumber() != target2.getValueNumber()) return false;
   }
   return true;
 }
Exemplo n.º 2
0
 /**
  * Initialize the congruence classes, assuming that all nodes with the same label are congruent.
  */
 private void initialize() {
   // store a map from label -> congruenceClass
   HashMap labelMap = new HashMap(10);
   for (Enumeration e = valueGraph.enumerateVertices(); e.hasMoreElements(); ) {
     OPT_ValueGraphVertex v = (OPT_ValueGraphVertex) e.nextElement();
     Object label = v.getLabel();
     OPT_GVCongruenceClass c = findOrCreateCongruenceClass(label, labelMap);
     // add this node to the congruence class
     c.addVertex(v);
     // set the value number for the node
     v.setValueNumber(c.getValueNumber());
   }
 }