Esempio n. 1
0
  /** Remove all the predicates which are not defined in the hyperblock. */
  private BitVect removePredicates(PredicateBlock start) {
    BitVect predicates = new BitVect();
    Stack<Node> wl = new Stack<Node>();

    // Determine all the predicates defined outside this hyperblock.

    start.nextVisit();
    start.setVisited();
    wl.add(start);

    while (!wl.isEmpty()) {
      PredicateBlock block = (PredicateBlock) wl.pop();
      block.pushOutEdges(wl);

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

        if (inst.isBranch()) {
          continue;
        }

        if (((TripsInstruction) inst).definesPredicate()) {
          predicates.set(inst.getDestRegister());
        }
      }
    }

    // Remove the predicates.

    start.nextVisit();
    start.setVisited();
    wl.add(start);

    while (!wl.isEmpty()) {
      PredicateBlock block = (PredicateBlock) wl.pop();
      block.pushOutEdges(wl);

      if (!block.isPredicated()) {
        continue;
      }

      int rp = block.getPredicate();
      if (predicates.get(rp)) {
        continue;
      }

      block.removePredicates();

      for (Instruction inst = block.getFirstInstruction(); inst != null; inst = inst.getNext()) {
        inst.removePredicates();
      }
    }

    return predicates;
  }
Esempio n. 2
0
  protected void peepholeBeforeRegisterAllocation(Instruction first) {
    Instruction inst = first;

    while (inst != null) {
      Instruction next = inst.getNext();
      int opcode = inst.getOpcode();

      // Recognize patterns, if any, here.

      inst = next;
    }
  }
Esempio n. 3
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.");
  }
Esempio n. 4
0
  /**
   * Find a split point for a block with spills. <br>
   * We know the hyperblock was legal before the insertion of spill code. Return the "deepest" split
   * point in the predicate flow graph, or if there are no split points, the block with the most
   * instructions.
   */
  private PredicateBlock findSplitPointSpills(Hyperblock hb) {
    Vector<PredicateBlock> wl = new Vector<PredicateBlock>();

    PredicateBlock start = hb.getFirstBlock();
    PredicateBlock last = hb.getLastBlock();
    PredicateBlock biggest = null;
    PredicateBlock splitPoint = null;
    int biggestSize = 0;

    if (start.numOutEdges() == 0) {
      return start;
    }

    start.nextVisit();
    start.setVisited();
    wl.add(start);

    // Find the block with the most "real" instructions.
    // We do not include fanout, nulls, or spill code.

    while (!wl.isEmpty()) {
      int sl = wl.size();
      for (int i = 0; i < sl; i++) {
        PredicateBlock block = wl.get(i);
        int size = 0;

        for (Instruction inst = block.getFirstInstruction(); inst != null; inst = inst.getNext()) {
          size++; // TODO?  Should we use the real size of the instruction?
        }

        if (size >= biggestSize) {
          if (block != last) {
            biggestSize = size;
            biggest = block;
          }
        }

        if (block.isSplitPoint() && (block != start)) {
          splitPoint = block;
        }
      }

      wl = hb.getNextPFGLevel(wl);
    }

    return (splitPoint != null) ? splitPoint : biggest;
  }