@@ -581,48 +581,35 @@ std::pair<AffineMap, AffineMap> FlatLinearConstraints::getLowerAndUpperBound(
581581 return {lbMap, ubMap};
582582}
583583
584- // / Computes the lower and upper bounds of the first 'num' dimensional
585- // / variables (starting at 'offset') as affine maps of the remaining
586- // / variables (dimensional and symbolic variables). Local variables are
587- // / themselves explicitly computed as affine functions of other variables in
588- // / this process if needed.
589- void FlatLinearConstraints::getSliceBounds (unsigned offset, unsigned num,
590- MLIRContext *context,
591- SmallVectorImpl<AffineMap> *lbMaps,
592- SmallVectorImpl<AffineMap> *ubMaps,
593- bool closedUB) {
594- assert (offset + num <= getNumDimVars () && " invalid range" );
595-
596- // Basic simplification.
597- normalizeConstraintsByGCD ();
598-
599- LLVM_DEBUG (llvm::dbgs () << " getSliceBounds for variables at positions ["
600- << offset << " , " << offset + num << " )\n " );
601- LLVM_DEBUG (dumpPretty ());
602-
603- // Record computed/detected variables.
604- SmallVector<AffineExpr, 8 > memo (getNumVars ());
584+ // / Compute a representation of `num` identifiers starting at `offset` in `cst`
585+ // / as affine expressions involving other known identifiers. Each identifier's
586+ // / expression (in terms of known identifiers) is populated into `memo`.
587+ static void computeUnknownVars (const FlatLinearConstraints &cst,
588+ MLIRContext *context, unsigned offset,
589+ unsigned num,
590+ SmallVectorImpl<AffineExpr> &memo) {
605591 // Initialize dimensional and symbolic variables.
606- for (unsigned i = 0 , e = getNumDimVars (); i < e; i++) {
592+ for (unsigned i = 0 , e = cst. getNumDimVars (); i < e; i++) {
607593 if (i < offset)
608594 memo[i] = getAffineDimExpr (i, context);
609595 else if (i >= offset + num)
610596 memo[i] = getAffineDimExpr (i - num, context);
611597 }
612- for (unsigned i = getNumDimVars (), e = getNumDimAndSymbolVars (); i < e; i++)
613- memo[i] = getAffineSymbolExpr (i - getNumDimVars (), context);
598+ for (unsigned i = cst.getNumDimVars (), e = cst.getNumDimAndSymbolVars ();
599+ i < e; i++)
600+ memo[i] = getAffineSymbolExpr (i - cst.getNumDimVars (), context);
614601
615602 bool changed;
616603 do {
617604 changed = false ;
618605 // Identify yet unknown variables as constants or mod's / floordiv's of
619606 // other variables if possible.
620- for (unsigned pos = 0 ; pos < getNumVars (); pos++) {
607+ for (unsigned pos = 0 , f = cst. getNumVars (); pos < f ; pos++) {
621608 if (memo[pos])
622609 continue ;
623610
624- auto lbConst = getConstantBound64 (BoundType::LB, pos);
625- auto ubConst = getConstantBound64 (BoundType::UB, pos);
611+ auto lbConst = cst. getConstantBound64 (BoundType::LB, pos);
612+ auto ubConst = cst. getConstantBound64 (BoundType::UB, pos);
626613 if (lbConst.has_value () && ubConst.has_value ()) {
627614 // Detect equality to a constant.
628615 if (*lbConst == *ubConst) {
@@ -633,7 +620,7 @@ void FlatLinearConstraints::getSliceBounds(unsigned offset, unsigned num,
633620
634621 // Detect a variable as modulo of another variable w.r.t a
635622 // constant.
636- if (detectAsMod (* this , pos, offset, num, *lbConst, *ubConst, context,
623+ if (detectAsMod (cst , pos, offset, num, *lbConst, *ubConst, context,
637624 memo)) {
638625 changed = true ;
639626 continue ;
@@ -642,24 +629,24 @@ void FlatLinearConstraints::getSliceBounds(unsigned offset, unsigned num,
642629
643630 // Detect a variable as a floordiv of an affine function of other
644631 // variables (divisor is a positive constant).
645- if (detectAsFloorDiv (* this , pos, context, memo)) {
632+ if (detectAsFloorDiv (cst , pos, context, memo)) {
646633 changed = true ;
647634 continue ;
648635 }
649636
650637 // Detect a variable as an expression of other variables.
651638 unsigned idx;
652- if (!findConstraintWithNonZeroAt (pos, /* isEq=*/ true , &idx)) {
639+ if (!cst. findConstraintWithNonZeroAt (pos, /* isEq=*/ true , &idx)) {
653640 continue ;
654641 }
655642
656643 // Build AffineExpr solving for variable 'pos' in terms of all others.
657644 auto expr = getAffineConstantExpr (0 , context);
658645 unsigned j, e;
659- for (j = 0 , e = getNumVars (); j < e; ++j) {
646+ for (j = 0 , e = cst. getNumVars (); j < e; ++j) {
660647 if (j == pos)
661648 continue ;
662- int64_t c = atEq64 (idx, j);
649+ int64_t c = cst. atEq64 (idx, j);
663650 if (c == 0 )
664651 continue ;
665652 // If any of the involved IDs hasn't been found yet, we can't proceed.
@@ -673,8 +660,8 @@ void FlatLinearConstraints::getSliceBounds(unsigned offset, unsigned num,
673660 continue ;
674661
675662 // Add constant term to AffineExpr.
676- expr = expr + atEq64 (idx, getNumVars ());
677- int64_t vPos = atEq64 (idx, pos);
663+ expr = expr + cst. atEq64 (idx, cst. getNumVars ());
664+ int64_t vPos = cst. atEq64 (idx, pos);
678665 assert (vPos != 0 && " expected non-zero here" );
679666 if (vPos > 0 )
680667 expr = (-expr).floorDiv (vPos);
@@ -689,6 +676,30 @@ void FlatLinearConstraints::getSliceBounds(unsigned offset, unsigned num,
689676 // variable's explicit form is computed (in memo[pos]), it's not updated
690677 // again.
691678 } while (changed);
679+ }
680+
681+ // / Computes the lower and upper bounds of the first 'num' dimensional
682+ // / variables (starting at 'offset') as affine maps of the remaining
683+ // / variables (dimensional and symbolic variables). Local variables are
684+ // / themselves explicitly computed as affine functions of other variables in
685+ // / this process if needed.
686+ void FlatLinearConstraints::getSliceBounds (unsigned offset, unsigned num,
687+ MLIRContext *context,
688+ SmallVectorImpl<AffineMap> *lbMaps,
689+ SmallVectorImpl<AffineMap> *ubMaps,
690+ bool closedUB) {
691+ assert (offset + num <= getNumDimVars () && " invalid range" );
692+
693+ // Basic simplification.
694+ normalizeConstraintsByGCD ();
695+
696+ LLVM_DEBUG (llvm::dbgs () << " getSliceBounds for variables at positions ["
697+ << offset << " , " << offset + num << " )\n " );
698+ LLVM_DEBUG (dumpPretty ());
699+
700+ // Record computed/detected variables.
701+ SmallVector<AffineExpr, 8 > memo (getNumVars ());
702+ computeUnknownVars (*this , context, offset, num, memo);
692703
693704 int64_t ubAdjustment = closedUB ? 0 : 1 ;
694705
0 commit comments