[mlir] Remove types from attributes
authorJeff Niu <jeff@modular.com>
Tue, 19 Jul 2022 04:32:38 +0000 (21:32 -0700)
committerJeff Niu <jeff@modular.com>
Mon, 1 Aug 2022 00:01:31 +0000 (20:01 -0400)
commite1795322844ca45ecbcdca8669929a46c666127e
tree38e552a9e3a129f5fd4ed242f0d99ce7a3163769
parentaf1328ef452b9eaa4e9f0bc115aeda8f40c4bbff
[mlir] Remove types from attributes

This patch removes the `type` field from `Attribute` along with the
`Attribute::getType` accessor.

Going forward, this means that attributes in MLIR will no longer have
types as a first-class concept. This patch lays the groundwork to
incrementally remove or refactor code that relies on generic attributes
being typed. The immediate impact will be on attributes that rely on
`Attribute` containing a type, such as `IntegerAttr`,
`DenseElementsAttr`, and `ml_program::ExternAttr`, which will now need
to define a type parameter on their storage classes. This will save
memory as all other attribute kinds will no longer contain a type.

Moreover, it will not be possible to generically query the type of an
attribute directly. This patch provides an attribute interface
`TypedAttr` that implements only one method, `getType`, which can be
used to generically query the types of attributes that implement the
interface. This interface can be used to retain the concept of a "typed
attribute". The ODS-generated accessor for a `type` parameter
automatically implements this method.

Next steps will be to refactor the assembly formats of certain operations
that rely on `parseAttribute(type)` and `printAttributeWithoutType` to
remove special handling of type elision until `type` can be removed from
the dialect parsing hook entirely; and incrementally remove uses of
`TypedAttr`.

Reviewed By: lattner, rriddle, jpienaar

Differential Revision: https://reviews.llvm.org/D130092
57 files changed:
mlir/docs/AttributesAndTypes.md
mlir/include/mlir/Dialect/Arithmetic/IR/ArithmeticOps.td
mlir/include/mlir/Dialect/CommonFolders.h
mlir/include/mlir/Dialect/Complex/IR/ComplexAttributes.td
mlir/include/mlir/Dialect/EmitC/IR/EmitC.td
mlir/include/mlir/Dialect/EmitC/IR/EmitCAttributes.td
mlir/include/mlir/Dialect/MLProgram/IR/MLProgramAttributes.h
mlir/include/mlir/Dialect/MLProgram/IR/MLProgramAttributes.td
mlir/include/mlir/Dialect/SPIRV/IR/SPIRVStructureOps.td
mlir/include/mlir/IR/AttrTypeBase.td
mlir/include/mlir/IR/AttributeSupport.h
mlir/include/mlir/IR/Attributes.h
mlir/include/mlir/IR/BuiltinAttributeInterfaces.h
mlir/include/mlir/IR/BuiltinAttributeInterfaces.td
mlir/include/mlir/IR/BuiltinAttributes.h
mlir/include/mlir/IR/BuiltinAttributes.td
mlir/include/mlir/IR/BuiltinTypeInterfaces.h [new file with mode: 0644]
mlir/include/mlir/IR/BuiltinTypes.h
mlir/lib/AsmParser/DialectSymbolParser.cpp
mlir/lib/CAPI/IR/IR.cpp
mlir/lib/Conversion/ArithmeticToSPIRV/ArithmeticToSPIRV.cpp
mlir/lib/Conversion/VectorToGPU/VectorToGPU.cpp
mlir/lib/Dialect/Arithmetic/IR/ArithmeticOps.cpp
mlir/lib/Dialect/Complex/IR/ComplexOps.cpp
mlir/lib/Dialect/EmitC/IR/EmitC.cpp
mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
mlir/lib/Dialect/Linalg/TransformOps/LinalgTransformOps.cpp
mlir/lib/Dialect/Linalg/Transforms/ElementwiseOpFusion.cpp
mlir/lib/Dialect/Linalg/Transforms/Transforms.cpp
mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
mlir/lib/Dialect/SPIRV/IR/SPIRVCanonicalization.cpp
mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
mlir/lib/Dialect/Vector/IR/VectorOps.cpp
mlir/lib/IR/AsmPrinter.cpp
mlir/lib/IR/AttributeDetail.h
mlir/lib/IR/BuiltinAttributeInterfaces.cpp
mlir/lib/IR/BuiltinAttributes.cpp
mlir/lib/IR/MLIRContext.cpp
mlir/lib/IR/TypeUtilities.cpp
mlir/lib/Rewrite/ByteCode.cpp
mlir/lib/TableGen/AttrOrTypeDef.cpp
mlir/lib/Target/Cpp/TranslateToCpp.cpp
mlir/lib/Target/SPIRV/Serialization/Serializer.cpp
mlir/test/Dialect/LLVMIR/invalid.mlir
mlir/test/Dialect/SPIRV/IR/structure-ops.mlir
mlir/test/IR/file-metadata-resources.mlir
mlir/test/lib/Dialect/Test/TestAttrDefs.td
mlir/test/lib/Dialect/Test/TestAttributes.cpp
mlir/test/lib/Dialect/Test/TestOps.td
mlir/test/mlir-tblgen/attr-or-type-format.td
mlir/test/mlir-tblgen/attrdefs.td
mlir/test/mlir-tblgen/op-result.td
mlir/tools/mlir-tblgen/AttrOrTypeDefGen.cpp
mlir/tools/mlir-tblgen/AttrOrTypeFormatGen.cpp
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
mlir/unittests/IR/AttributeTest.cpp