コード例 #1
0
  public void clustering(List<Instruction> instList) {
    // for all phi instructions "x = phi(y1,y2)"
    for (Instruction inst : instList) {
      if (inst.getOperator() == Instruction.phi) {
        // cluster = {x},
        Cluster phiCluster = this.findCluster(VariableManager.getSSAByVersion(inst.getId()));
        if (phiCluster != null) {

          this.mergeCluster(phiCluster, inst.getOperand1());

          this.mergeCluster(phiCluster, inst.getOperand2());
        }
      }
    }

    this.updateInterferenceGraph();
  }
コード例 #2
0
  private Set<SSA> buildIGFromBlock(BasicBlock curBB, Set<SSA> live) {
    List<Instruction> instList = curBB.getInstructions();
    for (int i = instList.size() - 1; i >= 0; i--) {
      Instruction inst = instList.get(i);
      // ignore phi function
      if (inst.getOperator() == Instruction.phi) {
        return live;
      }
      if (inst.getOperator() == Instruction.subroutine) {
        live = this.buildIGRecursive(inst.getOperand2().block, live);
        continue;
      }
      List<SSA> results = VariableManager.getSSAsByVersion(inst.getId());
      // live = live - {i}
      live.removeAll(results);
      live.remove(null);
      // for all x belong to live do

      for (SSA result : results) {
        Cluster resultCluster = this.getCluster(result);
        for (SSA x : live) {
          Cluster xCluster = this.getCluster(x);
          // add edge i <-> x
          xCluster.connectWith(resultCluster);
        }
      }

      // live = live + {j, k}
      if (inst.getOperand1() != null) {
        SSA j = inst.getOperand1().ssa;
        if (j != null) {
          live.add(j);
        }
      }

      if (inst.getOperand2() != null) {
        SSA k = inst.getOperand2().ssa;
        if (k != null) {
          live.add(k);
        }
      }
    }
    return live;
  }