Uniformize composition of AffineApplyOp by construction
authorNicolas Vasilache <ntv@google.com>
Fri, 11 Jan 2019 05:54:34 +0000 (21:54 -0800)
committerjpienaar <jpienaar@google.com>
Fri, 29 Mar 2019 22:08:40 +0000 (15:08 -0700)
commitcfa583196031b83a9dc40ace0d9796dbaa5147cb
treec588ecbf6e1240de2532ae0f0d42357a5aca1070
parentfdcfa0bb52108055495e69c15338f61c5d2d019f
Uniformize composition of AffineApplyOp by construction

This CL is the 5th on the path to simplifying AffineMap composition.
This removes the distinction between normalized single-result AffineMap and
more general composed multi-result map.

One nice byproduct of making the implementation driven by single-result is
that the multi-result extension is a trivial change: the implementation is
still single-result and we just use:

```
unsigned idx = getIndexOf(...);
map.getResult(idx);
```

This CL also fixes an AffineNormalizer implementation issue related to symbols.
Namely it stops performing substitutions on symbols in AffineNormalizer and
instead concatenates them all to be consistent with the call to
`AffineMap::compose(AffineMap)`. This latter call to `compose` cannot perform
simplifications of symbols coming from different maps based on positions only:
i.e. dims are applied and renumbered but symbols must be concatenated.

The only way to determine whether symbols from different AffineApply are the
same is to look at the concrete values. The canonicalizeMapAndOperands is thus
extended with behavior to support replacing operands that appear multiple
times.

Lastly, this CL demonstrates that the implementation is correct by rewriting
ComposeAffineMaps using only `makeComposedAffineApply`. The implementation
uses a matcher because AffineApplyOp are introduced as composed operations on
the fly instead of iteratively forwardSubstituting. For this purpose, a walker
would revisit freshly introduced AffineApplyOp. Regardless, ComposeAffineMaps
is scheduled to disappear, this CL replaces the implementation based on
iterative `forwardSubstitute` by a composed-by-construction
`makeComposedAffineApply`.
Remaining calls to `forwardSubstitute` will be removed in the next CL.

PiperOrigin-RevId: 228830443
13 files changed:
mlir/include/mlir/Analysis/AffineAnalysis.h
mlir/lib/Analysis/AffineAnalysis.cpp
mlir/lib/IR/BuiltinOps.cpp
mlir/lib/Transforms/ComposeAffineMaps.cpp
mlir/lib/Transforms/MaterializeVectors.cpp
mlir/lib/Transforms/Vectorization/VectorizerTestPass.cpp
mlir/test/Transforms/Vectorize/materialize.mlir
mlir/test/Transforms/Vectorize/materialize_vectors_1d_to_1d.mlir
mlir/test/Transforms/Vectorize/materialize_vectors_2d_to_1d.mlir
mlir/test/Transforms/Vectorize/materialize_vectors_2d_to_2d.mlir
mlir/test/Transforms/Vectorize/normalize_maps.mlir
mlir/test/Transforms/canonicalize.mlir
mlir/test/Transforms/compose-affine-maps.mlir