Ejemplo n.º 1
0
  /**
   * Constructs and inserts a new empty GOTO block {@code Z} between this block ({@code A}) and a
   * current successor block ({@code B}). The new block will replace B as A's successor and A as B's
   * predecessor. A and B will no longer be directly connected. If B is listed as a successor
   * multiple times, all references are replaced.
   *
   * @param other current successor (B)
   * @return {@code non-null;} an appropriately-constructed instance
   */
  public SsaBasicBlock insertNewSuccessor(SsaBasicBlock other) {
    SsaBasicBlock newSucc = parent.makeNewGotoBlock();

    if (!successors.get(other.index)) {
      throw new RuntimeException(
          "Block " + other.getRopLabelString() + " not successor of " + getRopLabelString());
    }

    // Update the new block.
    newSucc.predecessors.set(this.index);
    newSucc.successors.set(other.index);
    newSucc.successorList.add(other.index);
    newSucc.primarySuccessor = other.index;

    // Update us.
    for (int i = successorList.size() - 1; i >= 0; i--) {
      if (successorList.get(i) == other.index) {
        successorList.set(i, newSucc.index);
      }
    }

    if (primarySuccessor == other.index) {
      primarySuccessor = newSucc.index;
    }
    successors.clear(other.index);
    successors.set(newSucc.index);

    // Update "other".
    other.predecessors.set(newSucc.index);
    other.predecessors.set(index, successors.get(other.index));

    return newSucc;
  }