[mlir][linalg] Verify indexing map required attributes
authorLei Zhang <antiagainst@google.com>
Tue, 9 Feb 2021 13:47:21 +0000 (08:47 -0500)
committerLei Zhang <antiagainst@google.com>
Tue, 9 Feb 2021 13:48:29 +0000 (08:48 -0500)
commit4c640e49c9553363bc0e6fcbdbfe8d678683db97
tree84178ccd139879593030f6495f348902f9cab28b
parente0b8604e5d3c80a727a833663e765c8057ce7825
[mlir][linalg] Verify indexing map required attributes

Indexing maps for named ops can reference attributes so that
we can synthesize the indexing map dynamically. This supports
cases like strides for convolution ops. However, it does cause
an issue: now the indexing_maps() function call is dependent
on those attributes.

Linalg ops inherit LinalgOpInterfaceTraits, which calls
verifyStructuredOpInterface() to verify the interface.
verifyStructuredOpInterface() further calls indexing_maps().
Note that trait verification is done before the op itself,
where ODS generates the verification for those attributes.
So we can have indexing_maps() referencing non-existing or
invalid attribute, before the ODS-generated verification
kick in.

There isn't a dependency handling mechansim for traits.
This commit adds new interface methods to query whether an
op hasDynamicIndexingMaps() and then perform
verifyIndexingMapRequiredAttributes() in
verifyStructuredOpInterface() to handle the dependency issue.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D96297
mlir/include/mlir/Dialect/Linalg/IR/LinalgInterfaces.td
mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp
mlir/test/mlir-linalg-ods-gen/test-linalg-ods-gen.tc
mlir/tools/mlir-linalg-ods-gen/mlir-linalg-ods-gen.cpp