When parsing, treat an IntegerSet with no constraints as a degenerate true case. Also update the spec to note that affine constraints are optional.

PiperOrigin-RevId: 232158673
This commit is contained in:
River Riddle 2019-02-02 21:01:11 -08:00 committed by jpienaar
parent d54e3dd358
commit 38f8dc67be
4 changed files with 19 additions and 16 deletions

View File

@ -460,7 +460,7 @@ name.
integer-set-id ::= `#` suffix-id
integer-set-inline
::= dim-and-symbol-id-lists `:` affine-constraint-conjunction
::= dim-and-symbol-id-lists `:` '(' affine-constraint-conjunction? ')'
// Declarations of integer sets are at the top of the file.
integer-set-decl ::= integer-set-id `=` integer-set-inline

View File

@ -3279,10 +3279,9 @@ AffineExpr AffineParser::parseAffineConstraint(bool *isEq) {
/// Parse the constraints that are part of an integer set definition.
/// integer-set-inline
/// ::= dim-and-symbol-id-lists `:`
/// affine-constraint-conjunction
/// affine-constraint-conjunction ::= /*empty*/
/// | affine-constraint (`,`
/// affine-constraint)*
/// '(' affine-constraint-conjunction? ')'
/// affine-constraint-conjunction ::= affine-constraint (`,`
/// affine-constraint)*
///
IntegerSet AffineParser::parseIntegerSetConstraints(unsigned numDims,
unsigned numSymbols) {
@ -3303,17 +3302,15 @@ IntegerSet AffineParser::parseIntegerSetConstraints(unsigned numDims,
return res;
};
// Parse a list of affine constraints (comma-separated) .
// Grammar: affine-constraint-conjunct ::= `(` affine-constraint (`,`
// affine-constraint)* `)
auto constraintListLoc = getToken().getLoc();
// Parse a list of affine constraints (comma-separated).
if (parseCommaSeparatedListUntil(Token::r_paren, parseElt, true))
return IntegerSet();
// Check that at least one constraint was parsed.
// If no constraints were parsed, then treat this as a degenerate 'true' case.
if (constraints.empty()) {
emitError(constraintListLoc, "expected a valid affine constraint");
return IntegerSet();
/* 0 == 0 */
auto zero = getAffineConstantExpr(0, getContext());
return builder.getIntegerSet(numDims, numSymbols, zero, true);
}
// Parsed a valid integer set.

View File

@ -802,10 +802,6 @@ func @invalid_tensor_literal() {
// -----
#set_without_constraints = (i, j) : () // expected-error {{expected a valid affine constraint}}
// -----
func @invalid_affine_structure() {
%c0 = constant 0 : index
%idx = affine_apply (d0, d1) (%c0, %c0) // expected-error {{expected '->' or ':'}}

View File

@ -42,6 +42,8 @@
// CHECK-DAG: #set{{[0-9]+}} = (d0) : (d0 - 1 == 0)
#set2 = (d0) : (d0 - 1 == 0)
// CHECK-DAG: [[SET_TRUE:#set[0-9]+]] = () : (0 == 0)
// CHECK-DAG: #set{{[0-9]+}} = (d0)[s0] : (d0 - 2 >= 0, -d0 + 4 >= 0)
// CHECK: func @foo(i32, i64) -> f32
@ -749,6 +751,14 @@ func @type_alias() -> !i32_type_alias {
return %0 : i32
}
// CHECK-LABEL: func @no_integer_set_constraints(
func @no_integer_set_constraints() {
// CHECK: if [[SET_TRUE]]() {
if () : () () {
}
return
}
// CHECK-LABEL: func @verbose_if(
func @verbose_if(%N: index) {
%c = constant 200 : index