예제 #1
0
  private int[][] getDDVec(Table<Declaration, SubscriptExpr> arrayRefs, int loopDepth) {
    if (arrayRefs == null) return new int[0][0];

    int numEdges = 0;
    Stack<DDEdge> wl = WorkArea.<DDEdge>getStack("g<SubscriptExpr>etDDVec");

    Enumeration<DDEdge> k = graph.getEdges();
    while (k.hasMoreElements()) { // Check out every array variable in the loop nest.
      DDEdge edge = k.nextElement();
      if (edge.isSpatial()) continue;

      if (edge.isLoopIndependentDependency()) continue;

      if (edge.representsAllInput()) continue;

      wl.push(edge);
      numEdges++;
    }

    int[][] DDVector = new int[numEdges][loopDepth];

    int i = 0;
    while (!wl.empty()) {
      DDEdge edge = wl.pop();
      if (trace) System.out.println("   edge " + edge);

      // Find dependence distance.

      for (int level = 1; level <= loopDepth; level++)
        DDVector[i][level - 1] = edge.getDistance(level);

      if (trace) {
        System.out.print(i);
        System.out.print(" ");
        System.out.println(edge);
      }

      i++;
    }

    WorkArea.<DDEdge>returnStack(wl);

    return DDVector;
  }
예제 #2
0
  /**
   * Return true if this is a legal loop. A legal loop contains no function calls and has no scalar
   * variable cycles. A cycle exists when the variable is referenced before it is defed. We go to
   * some trouble to allow loops containing cycles such as
   *
   * <pre>
   *   s = s + a(i,j)
   * </pre>
   *
   * to be permuted.
   */
  private boolean legalLoop(LoopHeaderChord loop) {
    Stack<Chord> wl = WorkArea.<Chord>getStack("legalLoop");
    References refs = scribble.getRefs();

    Chord.nextVisit();
    wl.push(loop);
    loop.setVisited();

    int n = loop.numLoopExits();
    for (int i = 0; i < n; i++) loop.getLoopExit(i).setVisited();

    boolean legal = true;

    outer:
    while (!wl.empty()) {
      Chord c = wl.pop();

      if (c.getCall(true) != null) {
        legal = false;
        break;
      }

      if ((c instanceof DecisionChord) && (c != loop.getLoopTest())) {
        legal = false;
        break;
      }

      if (c.isAssignChord() && !c.isPhiExpr()) {
        ExprChord ec = (ExprChord) c;
        Expr lhs = ec.getLValue();
        Expr rhs = ec.getRValue();

        // The variable is both defed and used in the loop and
        // we don't know how it is used.  For example, it could be
        //   s = s + 1
        //   c(i,j) = s
        // or
        //   c(i,j) = s
        //   s = s + 1
        // We want to allow
        //   s = s + c(i,j)
        // because we know that s is not used to specify the
        // value of an array element.  We want to allow
        //   s = ...
        //     = s
        // since there is no cycle.

        if (lhs instanceof LoadDeclAddressExpr) {
          LoadDeclAddressExpr ldae = (LoadDeclAddressExpr) lhs;
          VariableDecl vd = ldae.getDecl().returnVariableDecl();
          if ((vd != null) && !loop.isLoopIndex(vd)) {
            boolean cycle = false;
            Iterator<Chord> it1 = refs.getUseChords(vd);
            while (it1.hasNext()) {
              Chord s = it1.next();
              cycle |= (s == c);
            }

            Iterator<Chord> it2 = refs.getUseChords(vd);
            while (it2.hasNext()) {
              Chord s = it2.next();
              if (c == s) continue;

              if (s.getLoopHeader() != loop) continue;

              if (cycle) {
                // There was a cycle and another use.
                //   s = s + 1
                //     = s
                legal = false;
                break outer;
              }

              // Check for a use before the def.
              while (true) {
                s = s.getNextChord();
                if (s == null) break;
                if (s == c) {
                  legal = false;
                  break outer;
                }
              }
            }
          }
        }
      }

      c.pushOutCfgEdges(wl);
    }

    WorkArea.<Chord>returnStack(wl);

    return legal;
  }