forked from OSchip/llvm-project
[MLIR][Affine] Allow `<=` in IntegerSet constraints
This patch extends the affine parser to allow affine constraints with `<=`. This is useful in writing unittests for Presburger library and test in general. The internal storage and printing of IntegerSet is still in the original format. Reviewed By: bondhugula Differential Revision: https://reviews.llvm.org/D129046
This commit is contained in:
parent
9892706282
commit
3c043ab007
|
@ -258,6 +258,7 @@ Syntax of affine constraints:
|
|||
|
||||
```
|
||||
affine-constraint ::= affine-expr `>=` `affine-expr`
|
||||
| affine-expr `<=` `affine-expr`
|
||||
| affine-expr `==` `affine-expr`
|
||||
affine-constraint-conjunction ::= affine-constraint (`,` affine-constraint)*
|
||||
```
|
||||
|
|
|
@ -598,6 +598,7 @@ ParseResult AffineParser::parseAffineMapRange(unsigned numDims,
|
|||
|
||||
/// Parse an affine constraint.
|
||||
/// affine-constraint ::= affine-expr `>=` `affine-expr`
|
||||
/// | affine-expr `<=` `affine-expr`
|
||||
/// | affine-expr `==` `affine-expr`
|
||||
///
|
||||
/// The constraint is normalized to
|
||||
|
@ -622,6 +623,15 @@ AffineExpr AffineParser::parseAffineConstraint(bool *isEq) {
|
|||
return lhsExpr - rhsExpr;
|
||||
}
|
||||
|
||||
// affine-constraint ::= `affine-expr` `<=` `affine-expr`
|
||||
if (consumeIf(Token::less) && consumeIf(Token::equal)) {
|
||||
AffineExpr rhsExpr = parseAffineExpr();
|
||||
if (!rhsExpr)
|
||||
return nullptr;
|
||||
*isEq = false;
|
||||
return rhsExpr - lhsExpr;
|
||||
}
|
||||
|
||||
// affine-constraint ::= `affine-expr` `==` `affine-expr`
|
||||
if (consumeIf(Token::equal) && consumeIf(Token::equal)) {
|
||||
AffineExpr rhsExpr = parseAffineExpr();
|
||||
|
|
|
@ -41,6 +41,23 @@
|
|||
// CHECK-DAG: #set{{[0-9]+}} = affine_set<(d0, d1, d2, d3) : ((d0 + d1) mod 2 - (d2 + d3) floordiv 2 == 0, d0 mod 2 + d1 mod 2 - (d2 + d3 + d2) >= 0)>
|
||||
#set12 = affine_set<(d0, d1, r0, r1) : ((d0 + d1) mod 2 == (r0 + r1) floordiv 2, ((d0) mod 2) + ((d1) mod 2) >= (r0 + r1) + r0)>
|
||||
|
||||
// Check if affine constraints with <= can be parsed.
|
||||
|
||||
// CHECK-DAG: #set{{[0-9]+}} = affine_set<(d0) : (-d0 >= 0)>
|
||||
#set13 = affine_set<(i) : (i <= 0)>
|
||||
|
||||
// CHECK-DAG: #set{{[0-9]+}} = affine_set<(d0) : (d0 >= 0, -d0 + 10 >= 0)>
|
||||
#set14 = affine_set<(i) : (i >= 0, i <= 10)>
|
||||
|
||||
// CHECK-DAG: #set{{[0-9]+}} = affine_set<(d0, d1)[s0, s1] : (d0 >= 0, -d0 + s0 >= 0, d1 >= 0, -d1 + s1 >= 0)>
|
||||
#set15 = affine_set<(i, j)[N, M] : (i >= 0, i <= N, j >= 0, j <= M)>
|
||||
|
||||
// CHECK-DAG: #set{{[0-9]+}} = affine_set<(d0)[s0] : (d0 >= 0, -d0 + s0 >= 0, -d0 + s0 floordiv 2 >= 0)>
|
||||
#set16 = affine_set<(i)[N] : (i >= 0, i <= N, i <= N floordiv 2)>
|
||||
|
||||
// CHECK-DAG: #set{{[0-9]+}} = affine_set<(d0, d1, d2, d3, d4) : (-d0 >= 0, -d1 >= 0, -d2 >= 0, -d3 >= 0, -d4 >= 0)>
|
||||
#set17 = affine_set<(i0, i1, i2, i3, i4)[] : (i0 <= 0, i1 <= 0, i2 <= 0, i3 <= 0, i4 <= 0)>
|
||||
|
||||
// CHECK-DAG: "testset0"() {set = #set{{[0-9]+}}} : () -> ()
|
||||
"testset0"() {set = #set0} : () -> ()
|
||||
|
||||
|
@ -79,3 +96,18 @@
|
|||
|
||||
// CHECK-DAG: "testset12"() {set = #set{{[0-9]+}}} : () -> ()
|
||||
"testset12"() {set = #set12} : () -> ()
|
||||
|
||||
// CHECK-DAG: "testset13"() {set = #set{{[0-9]+}}} : () -> ()
|
||||
"testset13"() {set = #set13} : () -> ()
|
||||
|
||||
// CHECK-DAG: "testset14"() {set = #set{{[0-9]+}}} : () -> ()
|
||||
"testset14"() {set = #set14} : () -> ()
|
||||
|
||||
// CHECK-DAG: "testset15"() {set = #set{{[0-9]+}}} : () -> ()
|
||||
"testset15"() {set = #set15} : () -> ()
|
||||
|
||||
// CHECK-DAG: "testset16"() {set = #set{{[0-9]+}}} : () -> ()
|
||||
"testset16"() {set = #set16} : () -> ()
|
||||
|
||||
// CHECK-DAG: "testset17"() {set = #set{{[0-9]+}}} : () -> ()
|
||||
"testset17"() {set = #set17} : () -> ()
|
||||
|
|
|
@ -300,14 +300,6 @@ func.func @invalid_if_conditional3() {
|
|||
|
||||
// -----
|
||||
|
||||
func.func @invalid_if_conditional5() {
|
||||
affine.for %i = 1 to 10 {
|
||||
affine.if affine_set<(i)[N] : (i <= 0)> // expected-error {{expected '== affine-expr' or '>= affine-expr' at end of affine constraint}}
|
||||
}
|
||||
}
|
||||
|
||||
// -----
|
||||
|
||||
func.func @invalid_if_conditional6() {
|
||||
affine.for %i = 1 to 10 {
|
||||
affine.if affine_set<(i) : (i)> // expected-error {{expected '== affine-expr' or '>= affine-expr' at end of affine constraint}}
|
||||
|
|
Loading…
Reference in New Issue