@@ -66,6 +66,10 @@ class FlatLinearConstraints : public presburger::IntegerPolyhedron {
66
66
// / Return the kind of this object.
67
67
Kind getKind () const override { return Kind::FlatLinearConstraints; }
68
68
69
+ // / Flag to control if conservative semi-affine bounds should be added in
70
+ // / `addBound()`.
71
+ enum class AddConservativeSemiAffineBounds { No = 0 , Yes };
72
+
69
73
// / Adds a bound for the variable at the specified position with constraints
70
74
// / being drawn from the specified bound map. In case of an EQ bound, the
71
75
// / bound map is expected to have exactly one result. In case of a LB/UB, the
@@ -77,21 +81,39 @@ class FlatLinearConstraints : public presburger::IntegerPolyhedron {
77
81
// / as a closed bound by +1/-1 respectively. In case of an EQ bound, it can
78
82
// / only be added as a closed bound.
79
83
// /
84
+ // / Conservative bounds for semi-affine expressions will be added if
85
+ // / `AddConservativeSemiAffineBounds` is set to `Yes`. This currently only
86
+ // / covers semi-affine `mod` expressions, so `addBound()` will still fail if
87
+ // / it encounters a semi-affine `floordiv`, `ceildiv`, or `mul`. Note: If
88
+ // / enabled it is possible for the resulting constraint set to become empty if
89
+ // / a precondition of a conservative bound is found not to hold.
90
+ // /
80
91
// / Note: The dimensions/symbols of this FlatLinearConstraints must match the
81
92
// / dimensions/symbols of the affine map.
82
- LogicalResult addBound (presburger::BoundType type, unsigned pos,
83
- AffineMap boundMap, bool isClosedBound);
93
+ LogicalResult addBound (
94
+ presburger::BoundType type, unsigned pos, AffineMap boundMap,
95
+ bool isClosedBound,
96
+ AddConservativeSemiAffineBounds = AddConservativeSemiAffineBounds::No);
84
97
85
98
// / Adds a bound for the variable at the specified position with constraints
86
99
// / being drawn from the specified bound map. In case of an EQ bound, the
87
100
// / bound map is expected to have exactly one result. In case of a LB/UB, the
88
101
// / bound map may have more than one result, for each of which an inequality
89
102
// / is added.
103
+ // /
104
+ // / Conservative bounds for semi-affine expressions will be added if
105
+ // / `AddConservativeSemiAffineBounds` is set to `Yes`. This currently only
106
+ // / covers semi-affine `mod` expressions, so `addBound()` will still fail if
107
+ // / it encounters a semi-affine `floordiv`, `ceildiv`, or `mul`. Note: If
108
+ // / enabled it is possible for the resulting constraint set to become empty if
109
+ // / a precondition of a conservative bound is found not to hold.
110
+ // /
90
111
// / Note: The dimensions/symbols of this FlatLinearConstraints must match the
91
112
// / dimensions/symbols of the affine map. By default the lower bound is closed
92
113
// / and the upper bound is open.
93
- LogicalResult addBound (presburger::BoundType type, unsigned pos,
94
- AffineMap boundMap);
114
+ LogicalResult addBound (
115
+ presburger::BoundType type, unsigned pos, AffineMap boundMap,
116
+ AddConservativeSemiAffineBounds = AddConservativeSemiAffineBounds::No);
95
117
96
118
// / The `addBound` overload above hides the inherited overloads by default, so
97
119
// / we explicitly introduce them here.
@@ -193,7 +215,8 @@ class FlatLinearConstraints : public presburger::IntegerPolyhedron {
193
215
// / Note: This is a shared helper function of `addLowerOrUpperBound` and
194
216
// / `composeMatchingMap`.
195
217
LogicalResult flattenAlignedMapAndMergeLocals (
196
- AffineMap map, std::vector<SmallVector<int64_t , 8 >> *flattenedExprs);
218
+ AffineMap map, std::vector<SmallVector<int64_t , 8 >> *flattenedExprs,
219
+ bool addConservativeSemiAffineBounds = false );
197
220
198
221
// / Prints the number of constraints, dimensions, symbols and locals in the
199
222
// / FlatLinearConstraints. Also, prints for each variable whether there is
@@ -468,18 +491,19 @@ class FlatLinearValueConstraints : public FlatLinearConstraints {
468
491
// / Flattens 'expr' into 'flattenedExpr', which contains the coefficients of the
469
492
// / dimensions, symbols, and additional variables that represent floor divisions
470
493
// / of dimensions, symbols, and in turn other floor divisions. Returns failure
471
- // / if 'expr' could not be flattened (i.e., semi-affine is not yet handled ).
494
+ // / if 'expr' could not be flattened (i.e., an unhandled semi-affine was found ).
472
495
// / 'cst' contains constraints that connect newly introduced local variables
473
496
// / to existing dimensional and symbolic variables. See documentation for
474
497
// / AffineExprFlattener on how mod's and div's are flattened.
475
- LogicalResult getFlattenedAffineExpr (AffineExpr expr, unsigned numDims,
476
- unsigned numSymbols,
477
- SmallVectorImpl<int64_t > *flattenedExpr,
478
- FlatLinearConstraints *cst = nullptr );
498
+ LogicalResult
499
+ getFlattenedAffineExpr (AffineExpr expr, unsigned numDims, unsigned numSymbols,
500
+ SmallVectorImpl<int64_t > *flattenedExpr,
501
+ FlatLinearConstraints *cst = nullptr ,
502
+ bool addConservativeSemiAffineBounds = false );
479
503
480
504
// / Flattens the result expressions of the map to their corresponding flattened
481
505
// / forms and set in 'flattenedExprs'. Returns failure if any expression in the
482
- // / map could not be flattened (i.e., semi-affine is not yet handled ). 'cst'
506
+ // / map could not be flattened (i.e., an unhandled semi-affine was found ). 'cst'
483
507
// / contains constraints that connect newly introduced local variables to
484
508
// / existing dimensional and / symbolic variables. See documentation for
485
509
// / AffineExprFlattener on how mod's and div's are flattened. For all affine
@@ -490,7 +514,8 @@ LogicalResult getFlattenedAffineExpr(AffineExpr expr, unsigned numDims,
490
514
LogicalResult
491
515
getFlattenedAffineExprs (AffineMap map,
492
516
std::vector<SmallVector<int64_t , 8 >> *flattenedExprs,
493
- FlatLinearConstraints *cst = nullptr );
517
+ FlatLinearConstraints *cst = nullptr ,
518
+ bool addConservativeSemiAffineBounds = false );
494
519
LogicalResult
495
520
getFlattenedAffineExprs (IntegerSet set,
496
521
std::vector<SmallVector<int64_t , 8 >> *flattenedExprs,
0 commit comments