public Cost computeRefCost(LoopHeaderChord loop, SubscriptExpr se) { Cost tripL = loop.getTripCount(); InductionVar ivar = loop.getPrimaryInductionVar(); if (ivar == null) return tripL; // Compute // tripL = (ubL - lbL + stepL) / stepL int nsubs = se.numSubscripts(); // number of subscripts in the subscript LoopHeaderChord tloop = loop.getTopLoop(); VariableDecl iv = ivar.getVar(); for (int i = 0; i < nsubs - 1; i++) { // for c code // If the loop index variable of this loop appears in any of the // subscripts other then the last, then return tripL. Expr sI = se.getSubscript(i); AffineExpr ae = tloop.isAffine(sI); if (ae == null) return null; if (ae.hasTerm(iv)) return tripL; } int fs = nsubs - 1; Expr s0 = se.getSubscript(fs); AffineExpr ae = tloop.isAffine(s0); if (ae == null) return null; int at = ae.getTermIndexOrig(iv); long coeff = 0; if (at >= 0) coeff = ae.getCoefficient(at); if (coeff == 0) // Invariant Reuse. return new Cost(1.0, 0); long stepL = loop.getStepValue(); long stride = stepL * coeff; if (stride < 0) stride = -stride; // Unit Reuse. Type et = se.getCoreType().getPointedTo(); int bs = et.memorySizeAsInt(Machine.currentMachine); int cs = Machine.currentMachine.getCacheSize(bs); if (stride <= cs) { // cache line or block size tripL.multiply(stride); tripL.divide(cs); return tripL; } // No Reuse. return tripL; }
public void perform() { if (trace) System.out.println("** LP " + scribble.getRoutineDecl().getName()); LoopHeaderChord lt = scribble.getLoopTree(); Vector<LoopHeaderChord> innerLoops = lt.getInnerLoops(); for (int li = 0; li < innerLoops.size(); li++) { LoopHeaderChord loop = innerLoops.elementAt(li); InductionVar ivar = loop.getPrimaryInductionVar(); if (trace) System.out.println(" lp " + loop.nestedLevel() + " " + loop); if ((ivar == null) || !loop.isPerfectlyNested()) { innerLoops.addVectors(loop.getInnerLoops()); continue; } if (loop.nestedLevel() < 2) // no need to check permutation for a simple nest continue; tryPermute(loop); } }