Introduce MLIR Op Properties
authorMehdi Amini <joker.eph@gmail.com>
Sun, 26 Feb 2023 15:46:01 +0000 (10:46 -0500)
committerMehdi Amini <joker.eph@gmail.com>
Tue, 2 May 2023 06:16:34 +0000 (23:16 -0700)
commit5e118f933b6590cecd7f1afb30845a1594bc4a5d
treedeb16795854810d0f1ee2b8a40dbeeee6a1647c0
parent8f966cedea594d9a91e585e88a80a42c04049e6c
Introduce MLIR Op Properties

This new features enabled to dedicate custom storage inline within operations.
This storage can be used as an alternative to attributes to store data that is
specific to an operation. Attribute can also be stored inside the properties
storage if desired, but any kind of data can be present as well. This offers
a way to store and mutate data without uniquing in the Context like Attribute.
See the OpPropertiesTest.cpp for an example where a struct with a
std::vector<> is attached to an operation and mutated in-place:

struct TestProperties {
  int a = -1;
  float b = -1.;
  std::vector<int64_t> array = {-33};
};

More complex scheme (including reference-counting) are also possible.

The only constraint to enable storing a C++ object as "properties" on an
operation is to implement three functions:

- convert from the candidate object to an Attribute
- convert from the Attribute to the candidate object
- hash the object

Optional the parsing and printing can also be customized with 2 extra
functions.

A new options is introduced to ODS to allow dialects to specify:

  let usePropertiesForAttributes = 1;

When set to true, the inherent attributes for all the ops in this dialect
will be using properties instead of being stored alongside discardable
attributes.
The TestDialect showcases this feature.

Another change is that we introduce new APIs on the Operation class
to access separately the inherent attributes from the discardable ones.
We envision deprecating and removing the `getAttr()`, `getAttrsDictionary()`,
and other similar method which don't make the distinction explicit, leading
to an entirely separate namespace for discardable attributes.

Recommit d572cd1b067f after fixing python bindings build.

Differential Revision: https://reviews.llvm.org/D141742
88 files changed:
mlir/docs/LangRef.md
mlir/include/mlir-c/Interfaces.h
mlir/include/mlir/Conversion/LLVMCommon/Pattern.h
mlir/include/mlir/IR/DialectBase.td
mlir/include/mlir/IR/ExtensibleDialect.h
mlir/include/mlir/IR/ODSSupport.h [new file with mode: 0644]
mlir/include/mlir/IR/OpBase.td
mlir/include/mlir/IR/OpDefinition.h
mlir/include/mlir/IR/OpImplementation.h
mlir/include/mlir/IR/Operation.h
mlir/include/mlir/IR/OperationSupport.h
mlir/include/mlir/Interfaces/InferTypeOpInterface.h
mlir/include/mlir/Interfaces/InferTypeOpInterface.td
mlir/include/mlir/TableGen/Argument.h
mlir/include/mlir/TableGen/Class.h
mlir/include/mlir/TableGen/Dialect.h
mlir/include/mlir/TableGen/Operator.h
mlir/include/mlir/TableGen/Property.h [new file with mode: 0644]
mlir/include/mlir/Transforms/DialectConversion.h
mlir/include/mlir/Transforms/OneToNTypeConversion.h
mlir/lib/AsmParser/Parser.cpp
mlir/lib/Bindings/Python/IRInterfaces.cpp
mlir/lib/CAPI/IR/IR.cpp
mlir/lib/CAPI/Interfaces/Interfaces.cpp
mlir/lib/Dialect/GPU/Transforms/AsyncRegionRewriter.cpp
mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
mlir/lib/Dialect/MemRef/Transforms/ExpandStridedMetadata.cpp
mlir/lib/Dialect/SCF/IR/SCF.cpp
mlir/lib/Dialect/Shape/IR/Shape.cpp
mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
mlir/lib/Dialect/Tosa/Transforms/TosaDecomposeTransposeConv.cpp
mlir/lib/Dialect/Tosa/Transforms/TosaInferShapes.cpp
mlir/lib/Dialect/Vector/IR/VectorOps.cpp
mlir/lib/IR/AsmPrinter.cpp
mlir/lib/IR/CMakeLists.txt
mlir/lib/IR/MLIRContext.cpp
mlir/lib/IR/ODSSupport.cpp [new file with mode: 0644]
mlir/lib/IR/Operation.cpp
mlir/lib/IR/OperationSupport.cpp
mlir/lib/Interfaces/InferTypeOpInterface.cpp
mlir/lib/Rewrite/ByteCode.cpp
mlir/lib/TableGen/CMakeLists.txt
mlir/lib/TableGen/CodeGenHelpers.cpp
mlir/lib/TableGen/Dialect.cpp
mlir/lib/TableGen/Operator.cpp
mlir/lib/TableGen/Property.cpp [new file with mode: 0644]
mlir/test/Bytecode/versioning/versioned_attr.mlir
mlir/test/Bytecode/versioning/versioned_op.mlir
mlir/test/Conversion/OneToNTypeConversion/one-to-n-type-conversion.mlir
mlir/test/Conversion/OneToNTypeConversion/scf-structural-one-to-n-type-conversion.mlir
mlir/test/Dialect/Shape/invalid.mlir
mlir/test/Dialect/Tosa/invalid.mlir
mlir/test/IR/greedy-pattern-rewriter-driver.mlir
mlir/test/IR/invalid.mlir
mlir/test/IR/parser.mlir
mlir/test/IR/properties.mlir [new file with mode: 0644]
mlir/test/IR/test-fold-adaptor.mlir
mlir/test/IR/test-manual-cpp-fold.mlir
mlir/test/IR/traits.mlir
mlir/test/Interfaces/InferIntRangeInterface/infer-int-range-test-ops.mlir
mlir/test/Transforms/decompose-call-graph-types.mlir
mlir/test/Transforms/test-legalizer.mlir
mlir/test/Transforms/test-operation-folder.mlir
mlir/test/lib/Dialect/Test/TestDialect.cpp
mlir/test/lib/Dialect/Test/TestDialect.h
mlir/test/lib/Dialect/Test/TestDialect.td
mlir/test/lib/Dialect/Test/TestOps.td
mlir/test/lib/Dialect/Test/TestPatterns.cpp
mlir/test/mlir-tblgen/constraint-unique.td
mlir/test/mlir-tblgen/interfaces-as-constraints.td
mlir/test/mlir-tblgen/op-attribute.td
mlir/test/mlir-tblgen/op-decl-and-defs.td
mlir/test/mlir-tblgen/op-format.td
mlir/test/mlir-tblgen/op-result.td
mlir/test/mlir-tblgen/pattern.mlir
mlir/test/mlir-tblgen/return-types.mlir
mlir/test/python/python_test_ops.td
mlir/tools/mlir-tblgen/FormatGen.cpp
mlir/tools/mlir-tblgen/FormatGen.h
mlir/tools/mlir-tblgen/OpClass.cpp
mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
mlir/tools/mlir-tblgen/OpFormatGen.cpp
mlir/unittests/Debug/FileLineColLocBreakpointManagerTest.cpp
mlir/unittests/IR/AdaptorTest.cpp
mlir/unittests/IR/CMakeLists.txt
mlir/unittests/IR/OpPropertiesTest.cpp [new file with mode: 0644]
mlir/unittests/IR/OperationSupportTest.cpp
mlir/unittests/Transforms/DialectConversion.cpp