Example #1
0
  /**
   * Add an existing equation to the system
   *
   * @param eq the equation
   */
  void addEquation(DF_Equation eq) {
    equations.addGraphNode(eq);
    newEquations.add(eq);

    DF_LatticeCell lhs = eq.getLHS();
    if (!(lhs.getDefs().hasNext() || lhs.getUses().hasNext())) {
      lhs.addDef(eq);
      equations.addGraphNode(lhs);
    } else {
      lhs.addDef(eq);
    }

    DF_LatticeCell[] operands = eq.getOperands();
    for (int i = 1; i < operands.length; i++) {
      DF_LatticeCell op = operands[i];
      if (!(op.getDefs().hasNext() || op.getUses().hasNext())) {
        op.addUse(eq);
        equations.addGraphNode(op);
      } else {
        op.addUse(eq);
      }
    }

    if (EAGER && eq.evaluate()) changedCell(lhs);
  }
Example #2
0
 /**
  * Add an equation with three operands on the right-hand side.
  *
  * @param lhs the lattice cell set by this equation
  * @param operator the equation operator
  * @param op1 first operand on the rhs
  * @param op2 second operand on the rhs
  * @param op3 third operand on the rhs
  */
 void newEquation(
     DF_LatticeCell lhs,
     DF_Operator operator,
     DF_LatticeCell op1,
     DF_LatticeCell op2,
     DF_LatticeCell op3) {
   // add to the list of equations
   DF_Equation eq = new DF_Equation(lhs, operator, op1, op2, op3);
   equations.addGraphNode(eq);
   equations.addGraphNode(lhs);
   equations.addGraphNode(op1);
   equations.addGraphNode(op2);
   equations.addGraphNode(op3);
   newEquations.add(eq);
   // add lattice cells for the operands to the working solution
   //       cells.put(lhs.getKey(),lhs);
   //       cells.put(op1.getKey(),op1);
   op1.addUse(eq);
   //       cells.put(op2.getKey(),op2);
   op2.addUse(eq);
   //       cells.put(op3.getKey(),op3);
   op3.addUse(eq);
   lhs.addDef(eq);
   if (EAGER && eq.evaluate()) changedCell(lhs);
 }
Example #3
0
 /**
  * Add all equations which contain a given cell to the work list.
  *
  * @param cell the cell in question
  */
 public void addCellAppearancesToWorkList(DF_LatticeCell cell) {
   for (Enumeration<DF_Equation> e = getEquations(); e.hasMoreElements(); ) {
     DF_Equation eq = e.nextElement();
     if (eq.hasCell(cell)) {
       addToWorkList(eq);
     }
   }
 }
Example #4
0
 /**
  * Number the equations in topological order.
  *
  * <p>PRECONDITION: Already called addGraphEdges()
  *
  * <p>Algorithm:
  *
  * <ul>
  *   <li>1. create a DAG of SCCs
  *   <li>2. number this DAG topologically
  *   <li>3. walk through the DAG and number nodes as they are encountered
  * </ul>
  */
 private void numberEquationsTopological() {
   GraphNodeEnumeration topOrder = GraphUtilities.enumerateTopSort(equations);
   Enumeration<GraphNode> rev = new ReverseDFSenumerateByFinish(equations, topOrder);
   int number = 0;
   while (rev.hasMoreElements()) {
     GraphNode elt = rev.nextElement();
     if (elt instanceof DF_Equation) {
       DF_Equation eq = (DF_Equation) elt;
       eq.setTopologicalNumber(number++);
     }
   }
 }
Example #5
0
 /** Add all new equations to the work list. */
 public void addNewEquationsToWorkList() {
   if (DEBUG) {
     System.out.println("new equations:");
   }
   for (DF_Equation eq : newEquations) {
     if (DEBUG) {
       System.out.println(eq.toString());
     }
     addToWorkList(eq);
   }
   newEquations = new HashSet<DF_Equation>();
   if (DEBUG) {
     System.out.println("end of new equations");
   }
 }
Example #6
0
 /**
  * Add an equation to the system with an arbitrary number of operands on the right-hand side.
  *
  * @param lhs lattice cell set by this equation
  * @param operator the equation operator
  * @param rhs the operands on the rhs
  */
 protected void newEquation(DF_LatticeCell lhs, DF_Operator operator, DF_LatticeCell[] rhs) {
   // add to the list of equations
   DF_Equation eq = new DF_Equation(lhs, operator, rhs);
   equations.addGraphNode(eq);
   equations.addGraphNode(lhs);
   newEquations.add(eq);
   // add the operands to the working solution
   //       cells.put(lhs.getKey(),lhs);
   for (DF_LatticeCell rh : rhs) {
     //        cells.put(rhs[i].getKey(),rhs[i]);
     rh.addUse(eq);
     equations.addGraphNode(rh);
   }
   lhs.addDef(eq);
   if (EAGER && eq.evaluate()) changedCell(lhs);
 }
Example #7
0
 /**
  * Solve the set of dataflow equations.
  *
  * <p>PRECONDITION: equations are set up
  */
 public void solve() {
   // addGraphEdges();
   numberEquationsTopological();
   initializeLatticeCells();
   initializeWorkList();
   while (!workList.isEmpty()) {
     DF_Equation eq = workList.first();
     workList.remove(eq);
     boolean change = eq.evaluate();
     if (DEBUG) {
       System.out.println("After evaluation " + eq);
     }
     if (change) {
       updateWorkList(eq);
     }
   }
 }
Example #8
0
 /**
  * Update the worklist, assuming that a particular equation has been re-evaluated
  *
  * @param eq the equation that has been re-evaluated.
  */
 protected void updateWorkList(DF_Equation eq) {
   // find each equation which uses this lattice cell, and
   // add it to the work list
   Iterator<DF_Equation> e = eq.getLHS().getUses();
   while (e.hasNext()) {
     workList.add(e.next());
   }
 }