Example #1
0
 /** Move all preCondition block instructions before conditionBlock instructions */
 public void mergePreCondition() {
   if (preCondition != null && conditionBlock != null) {
     preCondition.getInstructions().addAll(conditionBlock.getInstructions());
     conditionBlock.getInstructions().clear();
     conditionBlock.getInstructions().addAll(preCondition.getInstructions());
     preCondition.getInstructions().clear();
   }
 }
Example #2
0
  /** Check if pre-conditions can be inlined into loop condition */
  public boolean checkPreCondition() {
    List<InsnNode> insns = preCondition.getInstructions();
    if (insns.isEmpty()) return true;

    IfNode ifInsn = getIfInsn();
    int size = insns.size();
    for (int i = 0; i < size; i++) {
      InsnNode insn = insns.get(i);
      if (insn.getResult() == null) {
        return false;
      } else {
        RegisterArg res = insn.getResult();
        if (res.getTypedVar().getUseList().size() > 2) return false;

        boolean found = false;
        // search result arg in other insns
        for (int j = i + 1; j < size; j++) {
          if (insns.get(i).containsArg(res)) found = true;
        }
        // or in if insn
        if (!found && ifInsn.containsArg(res)) found = true;

        if (!found) return false;
      }
    }
    return true;
  }
Example #3
0
 public IfNode getIfInsn() {
   return (IfNode)
       conditionBlock.getInstructions().get(conditionBlock.getInstructions().size() - 1);
 }