Example #1
0
  /**
   * Return the location in the block to split. Use the last spill store point found as the location
   * to split. If no spill store is found, use the last instruction that does not cause a violation.
   * This method will throw an exception if not split location is found.
   */
  private final Instruction findSplitLocation(Hyperblock hb, PredicateBlock block, int chunkSize) {
    int cLSID = 0;
    int cSize = 0;
    Instruction splitLocation = null;
    boolean foundSpillPoint = false;
    BitVect mov3 = new BitVect();
    Stack<Node> wl = new Stack<Node>();
    IntMap<Integer> uses = new IntMap<Integer>(37);
    IntMap<Vector<Integer>> targets = hb.computeTargets(wl, mov3);

    for (Instruction inst = block.getFirstInstruction(); inst != null; inst = inst.getNext()) {
      if (inst.isMarker()) {
        continue;
      }

      if (inst.isLoad() || inst.isStore()) {
        int id =
            (inst.isLoad()
                ? ((LoadInstruction) inst).getLSQid()
                : ((StoreInstruction) inst).getLSQid());
        if (id > cLSID) {
          cLSID = id;
        }
      }

      cSize += block.estimateNumInstructions(inst);
      cSize += block.estimateFanout(inst, targets, uses, mov3);

      if ((cLSID >= Trips2Machine.maxLSQEntries) || (cSize >= chunkSize)) {
        if (splitLocation == null) {
          splitLocation = inst; // Possible when splitting because of spills.
        }
        assert (splitLocation != block.getLastInstruction())
            : "How is the last instruction the split location?";
        return splitLocation;
      }

      if (inst.isSpillStorePoint()) {
        splitLocation = inst;
        foundSpillPoint = true;
      }

      if (!foundSpillPoint) {
        splitLocation = inst;
      }
    }

    throw new scale.common.InternalError("Could not find a location to split the predicate block.");
  }