예제 #1
0
 /**
  * Partition a congruence class.
  *
  * @param partition the class to partition
  */
 private void partitionClass(OPT_GVCongruenceClass partition) {
   // store a reference to the first node in c, which will serve
   // as a representative for this class
   Iterator i = partition.iterator();
   OPT_ValueGraphVertex first = (OPT_ValueGraphVertex) i.next();
   ArrayList newClasses = new ArrayList();
   // now check each other node in c, to see if it matches the
   // representative
   ArrayList toRemove = new ArrayList();
   for (; i.hasNext(); ) {
     OPT_ValueGraphVertex v = (OPT_ValueGraphVertex) i.next();
     if (!checkCongruence(first, v)) {
       // NOT CONGRUENT!!  split the partition.  first check if
       // v fits in any other newly created congruence classes
       int index = findCongruenceMatch(newClasses, v);
       if (index > -1) {
         // MATCH FOUND!! place v in newClasses[index]
         OPT_GVCongruenceClass match = (OPT_GVCongruenceClass) B.get(index);
         match.addVertex(v);
         v.setValueNumber(match.getValueNumber());
       } else {
         // NO MATCH FOUND!! create a new congruence class
         // find the appropriate label for the new congruence class
         // and create a new congruence class with this label
         OPT_GVCongruenceClass c = createCongruenceClass(v);
         newClasses.add(c);
         c.addVertex(v);
         v.setValueNumber(c.getValueNumber());
       }
       // mark v as to be removed from partition
       // (Can't remove it yet while iterating over the set);
       toRemove.add(v);
     }
   }
   // remove necessary vertices
   for (Iterator it = toRemove.iterator(); it.hasNext(); ) {
     OPT_ValueGraphVertex v = (OPT_ValueGraphVertex) it.next();
     partition.removeVertex(v);
   }
   // if needed place the original partition back on the work list
   if ((newClasses.size() > 0) && (partition.size() > 1)) {
     workList.push(partition);
   }
   // place any new congruence classes with size > 1 on the worklist
   // also place any classes which might indirectly be affected
   for (int j = 0; j < newClasses.size(); j++) {
     OPT_GVCongruenceClass c = (OPT_GVCongruenceClass) newClasses.get(j);
     if (c.size() > 1) workList.push(c);
     addDependentClassesToWorklist(c);
   }
 }
예제 #2
0
 /**
  * Does vertex v belong to any congruence class in a vector? If so, returns the value number of
  * the matching congruence class. If none found, returns -1.
  *
  * @param vector a vector of congruence classes
  * @param v the vertex to search for
  * @return the value number corresponding to the congruence class containing v. -1 iff no such
  *     class is found.
  */
 private int findCongruenceMatch(ArrayList vector, OPT_ValueGraphVertex v) {
   for (int i = 0; i < vector.size(); i++) {
     OPT_GVCongruenceClass klass = (OPT_GVCongruenceClass) vector.get(i);
     if (checkCongruence(v, klass)) {
       return klass.getValueNumber();
     }
   }
   return -1;
 }
예제 #3
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());
   }
 }