private static OPT_Instruction transform(OPT_Instruction s, OPT_Instruction def) { if (s.operator == INT_ADD || s.operator == INT_SUB) { return transformForInt(s,def); } else { return transformForLong(s,def); } }
  final public static void perform(OPT_IR ir) {        // Create a set of potential computations to fold.    HashSet candidates = new HashSet(20);    for (Enumeration e = ir.forwardInstrEnumerator(); e.hasMoreElements();) {      OPT_Instruction s = (OPT_Instruction)e.nextElement();      // Check if s is a fixed-point add/subtract instruction with       // a constant second operand      OPT_Register r = isCandidateExpression(s);      if (r != null) {        candidates.add(r);      }    }    if (RESTRICT_TO_DEAD_EXPRESSIONS) {      pruneCandidates(candidates);    }    boolean didSomething = true;    while (didSomething) {      didSomething = false;      for (Iterator i = candidates.iterator(); i.hasNext(); ) {        OPT_Register r = (OPT_Register)i.next();        OPT_Instruction s = r.getFirstDef();        OPT_Operand val1 = Binary.getVal1(s);        if (VM.VerifyAssertions) {           if (!val1.isRegister())             VM.sysWrite("Expression folding trouble AAA" + s);          VM.assert(val1.isRegister());        }        if (candidates.contains(val1.asRegister().register)) {          OPT_Instruction def = val1.asRegister().register.getFirstDef();          OPT_Operand def1 = Binary.getVal1(def);          if (VM.VerifyAssertions) {            if (!def1.isRegister())               VM.sysWrite("Expression folding trouble BBB" + def);            VM.assert(def1.isRegister());          }          OPT_Operand def2 = Binary.getVal2(def);          if (VM.VerifyAssertions) {            if (!def2.isConstant())               VM.sysWrite("Expression folding trouble CCC" + def);            VM.assert(def2.isConstant());          }          OPT_Instruction newS = transform(s,def);          s.insertAfter(newS);          OPT_DefUse.updateDUForNewInstruction(newS);          OPT_DefUse.removeInstructionAndUpdateDU(s);          didSomething = true;        }      }    }  }        /**   * Prune the candidate set; restrict candidates to only allow   * transformations that result in dead code to be eliminated   */  private static void pruneCandidates(HashSet candidates) {    for (Iterator i = candidates.iterator(); i.hasNext(); ) {      OPT_Register r = (OPT_Register)i.next();      OPT_Instruction s = r.getFirstDef();      OPT_Operand val1 = Binary.getVal1(s);      OPT_Register v1 = val1.asRegister().register;      if (candidates.contains(v1)) {        for (Enumeration uses = OPT_DefUse.uses(v1); uses.hasMoreElements();) {          OPT_RegisterOperand op = (OPT_RegisterOperand)uses.nextElement();          OPT_Instruction u = op.instruction;          if (isCandidateExpression(u) == null) {            i.remove();            break;          }        }      }    }  }  /**   * Perform the transfomation on the instruction s = A +/- c   * where def is the definition of A.   *   * @return the new instruction to replace s;   */  private static OPT_Instruction transform(OPT_Instruction s,                                            OPT_Instruction def) {    if (s.operator == INT_ADD || s.operator == INT_SUB) {      return transformForInt(s,def);    } else {      return transformForLong(s,def);    }  }