Relax restriction on affine_apply dim and symbol operands
authorNicolas Vasilache <ntv@google.com>
Tue, 26 Nov 2019 15:38:33 +0000 (07:38 -0800)
committerA. Unique TensorFlower <gardener@tensorflow.org>
Tue, 26 Nov 2019 15:39:05 +0000 (07:39 -0800)
The affine_apply operation is currently "doubly" affine and conflates two things:
1. it applies an affine map to a list of values of type `index` that are defined as either dim or symbol
2. it restricts (and propagates constraints on) the provenance of dims and symbols to a small subset of ops for which more restrictive polyhedral constraints apply.

Point 2. is related to the ability to form so-called static control parts and is related to dependence analysis and legality of transformations.

Point 1. however is completely independent, the only local implication of dims and symbol for affine_apply is that dims compose while symbols concatenate as well as the structural constraint that dims may not be multiplied.

The properties of composition and canonicalization in affine_apply are more generally useful. This CL relaxes the verifier on affine_apply so it can be used more generally.

The relevant affine.for/if/load/store op verifiers already implement the dim and symbol checking.

See this thread for the related discussion: https://groups.google.com/a/tensorflow.org/g/mlir/c/HkwCbV8D9N0/m/8srUNrX6CAAJ

PiperOrigin-RevId: 282562517

mlir/lib/Dialect/AffineOps/AffineOps.cpp
mlir/test/AffineOps/invalid.mlir

index ae219c7..2cd357f 100644 (file)
@@ -285,11 +285,6 @@ LogicalResult AffineApplyOp::verify() {
   if (!getResult()->getType().isIndex())
     return emitOpError("result must be of type 'index'");
 
-  // Verify that the operands are valid dimension and symbol identifiers.
-  if (failed(verifyDimAndSymbolIdentifiers(*this, getOperands(),
-                                           map.getNumDims())))
-    return failure();
-
   // Verify that the map only produces one result.
   if (map.getNumResults() != 1)
     return emitOpError("mapping must produce one value");
index 390b2ae..4534d70 100644 (file)
@@ -2,32 +2,6 @@
 
 // -----
 
-#map = (d0)[s0] -> (d0 + s0)
-
-func @affine_apply_invalid_dim(%arg : index) {
-  affine.for %n0 = 0 to 7 {
-    %dim = addi %arg, %arg : index
-
-    // expected-error@+1 {{operand cannot be used as a dimension id}}
-    %x  = affine.apply #map(%dim)[%arg]
-  }
-  return
-}
-
-// -----
-
-#map0 = (d0)[s0] -> (d0 + s0)
-
-func @affine_apply_invalid_sym() {
-  affine.for %i0 = 0 to 7 {
-    // expected-error@+1 {{operand cannot be used as a symbol}}
-    %0 = affine.apply #map0(%i0)[%i0]
-  }
-  return
-}
-
-// -----
-
 func @affine_apply_operand_non_index(%arg0 : i32) {
   // Custom parser automatically assigns all arguments the `index` so we must
   // use the generic syntax here to exercise the verifier.