@@ -581,48 +581,35 @@ std::pair<AffineMap, AffineMap> FlatLinearConstraints::getLowerAndUpperBound(
581
581
return {lbMap, ubMap};
582
582
}
583
583
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 `num` identifiers starting at `offset` in `cst` as affine
585
+ // / expressions involving other known identifiers. Each identifier's expression
586
+ // / (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) {
605
591
// 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++) {
607
593
if (i < offset)
608
594
memo[i] = getAffineDimExpr (i, context);
609
595
else if (i >= offset + num)
610
596
memo[i] = getAffineDimExpr (i - num, context);
611
597
}
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);
614
601
615
602
bool changed;
616
603
do {
617
604
changed = false ;
618
605
// Identify yet unknown variables as constants or mod's / floordiv's of
619
606
// other variables if possible.
620
- for (unsigned pos = 0 ; pos < getNumVars (); pos++) {
607
+ for (unsigned pos = 0 , f = cst. getNumVars (); pos < f ; pos++) {
621
608
if (memo[pos])
622
609
continue ;
623
610
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);
626
613
if (lbConst.has_value () && ubConst.has_value ()) {
627
614
// Detect equality to a constant.
628
615
if (*lbConst == *ubConst) {
@@ -633,7 +620,7 @@ void FlatLinearConstraints::getSliceBounds(unsigned offset, unsigned num,
633
620
634
621
// Detect a variable as modulo of another variable w.r.t a
635
622
// constant.
636
- if (detectAsMod (* this , pos, offset, num, *lbConst, *ubConst, context,
623
+ if (detectAsMod (cst , pos, offset, num, *lbConst, *ubConst, context,
637
624
memo)) {
638
625
changed = true ;
639
626
continue ;
@@ -642,24 +629,24 @@ void FlatLinearConstraints::getSliceBounds(unsigned offset, unsigned num,
642
629
643
630
// Detect a variable as a floordiv of an affine function of other
644
631
// variables (divisor is a positive constant).
645
- if (detectAsFloorDiv (* this , pos, context, memo)) {
632
+ if (detectAsFloorDiv (cst , pos, context, memo)) {
646
633
changed = true ;
647
634
continue ;
648
635
}
649
636
650
637
// Detect a variable as an expression of other variables.
651
638
unsigned idx;
652
- if (!findConstraintWithNonZeroAt (pos, /* isEq=*/ true , &idx)) {
639
+ if (!cst. findConstraintWithNonZeroAt (pos, /* isEq=*/ true , &idx)) {
653
640
continue ;
654
641
}
655
642
656
643
// Build AffineExpr solving for variable 'pos' in terms of all others.
657
644
auto expr = getAffineConstantExpr (0 , context);
658
645
unsigned j, e;
659
- for (j = 0 , e = getNumVars (); j < e; ++j) {
646
+ for (j = 0 , e = cst. getNumVars (); j < e; ++j) {
660
647
if (j == pos)
661
648
continue ;
662
- int64_t c = atEq64 (idx, j);
649
+ int64_t c = cst. atEq64 (idx, j);
663
650
if (c == 0 )
664
651
continue ;
665
652
// 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,
673
660
continue ;
674
661
675
662
// 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);
678
665
assert (vPos != 0 && " expected non-zero here" );
679
666
if (vPos > 0 )
680
667
expr = (-expr).floorDiv (vPos);
@@ -689,6 +676,30 @@ void FlatLinearConstraints::getSliceBounds(unsigned offset, unsigned num,
689
676
// variable's explicit form is computed (in memo[pos]), it's not updated
690
677
// again.
691
678
} 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);
692
703
693
704
int64_t ubAdjustment = closedUB ? 0 : 1 ;
694
705
0 commit comments