Skip to content

Commit 67a910b

Browse files
committed
[mlir][python] Remove PythonAttr mapping functionality
This functionality has been replaced by TypeCasters (see D151840) depends on D154468 Reviewed By: ftynse Differential Revision: https://reviews.llvm.org/D154469
1 parent fe22b90 commit 67a910b

31 files changed

+26
-102
lines changed

mlir/cmake/modules/AddMLIRPython.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,11 @@ endfunction()
271271
# SOURCES: Same as declare_mlir_python_sources().
272272
# SOURCES_GLOB: Same as declare_mlir_python_sources().
273273
# DEPENDS: Additional dependency targets.
274+
#
275+
# TODO: Right now `TD_FILE` can't be the actual dialect tablegen file, since we
276+
# use its path to determine where to place the generated python file. If
277+
# we made the output path an additional argument here we could remove the
278+
# need for the separate "wrapper" .td files
274279
function(declare_mlir_dialect_python_bindings)
275280
cmake_parse_arguments(ARG
276281
""

mlir/docs/Bindings/Python.md

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,6 @@ the `Func` (which is assigned the namespace `func` as a special case):
919919
#ifndef PYTHON_BINDINGS_FUNC_OPS
920920
#define PYTHON_BINDINGS_FUNC_OPS
921921
922-
include "mlir/Bindings/Python/Attributes.td"
923922
include "mlir/Dialect/Func/IR/FuncOps.td"
924923
925924
#endif // PYTHON_BINDINGS_FUNC_OPS
@@ -1125,14 +1124,10 @@ Dialect operations are provided in Python by wrapping the generic
11251124
properties. Therefore, there is no need to implement a separate C API for them.
11261125
For operations defined in ODS, `mlir-tblgen -gen-python-op-bindings
11271126
-bind-dialect=<dialect-namespace>` generates the Python API from the declarative
1128-
description. If the build API uses specific attribute types, such as
1129-
`::mlir::IntegerAttr` or `::mlir::DenseIntElementsAttr`, for its arguments, the
1130-
mapping to the corresponding Python types should be provided in ODS definition.
1131-
For built-in attribute types, this mapping is available in
1132-
[`include/mlir/Bindings/Python/Attributes.td`](https://github.com/llvm/llvm-project/blob/main/mlir/include/mlir/Bindings/Python/Attributes.td);
1133-
it is sufficient to create a new `.td` file that includes this file and the
1134-
original ODS definition and use it as source for the `mlir-tblgen` call. Such
1135-
`.td` files reside in
1127+
description.
1128+
It is sufficient to create a new `.td` file that includes the original ODS
1129+
definition and use it as source for the `mlir-tblgen` call.
1130+
Such `.td` files reside in
11361131
[`python/mlir/dialects/`](https://github.com/llvm/llvm-project/tree/main/mlir/python/mlir/dialects).
11371132
The results of `mlir-tblgen` are expected to produce a file named
11381133
`_<dialect-namespace>_ops_gen.py` by convention. The generated operation classes

mlir/examples/standalone/python/mlir_standalone/dialects/StandaloneOps.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef PYTHON_BINDINGS_STANDALONE_OPS
1010
#define PYTHON_BINDINGS_STANDALONE_OPS
1111

12-
include "mlir/Bindings/Python/Attributes.td"
1312
include "Standalone/StandaloneOps.td"
1413

1514
#endif

mlir/include/mlir/Bindings/Python/Attributes.td

Lines changed: 0 additions & 24 deletions
This file was deleted.

mlir/python/mlir/dialects/ArithOps.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef PYTHON_BINDINGS_ARITH_OPS
1010
#define PYTHON_BINDINGS_ARITH_OPS
1111

12-
include "mlir/Bindings/Python/Attributes.td"
1312
include "mlir/Dialect/Arith/IR/ArithOps.td"
1413

1514
#endif

mlir/python/mlir/dialects/AsyncOps.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef PYTHON_BINDINGS_ASYNC_OPS
1010
#define PYTHON_BINDINGS_ASYNC_OPS
1111

12-
include "mlir/Bindings/Python/Attributes.td"
1312
include "mlir/Dialect/Async/IR/AsyncOps.td"
1413

1514
#endif

mlir/python/mlir/dialects/BufferizationOps.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef PYTHON_BINDINGS_BUFFERIZATION_OPS
1010
#define PYTHON_BINDINGS_BUFFERIZATION_OPS
1111

12-
include "mlir/Bindings/Python/Attributes.td"
1312
include "mlir/Dialect/Bufferization/IR/BufferizationOps.td"
1413

1514
#endif

mlir/python/mlir/dialects/BufferizationTransformOps.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#ifndef PYTHON_BINDINGS_BUFFERIZATION_TRANSFORM_OPS
1616
#define PYTHON_BINDINGS_BUFFERIZATION_TRANSFORM_OPS
1717

18-
include "mlir/Bindings/Python/Attributes.td"
1918
include "mlir/Dialect/Bufferization/TransformOps/BufferizationTransformOps.td"
2019

2120
#endif // PYTHON_BINDINGS_BUFFERIZATION_TRANSFORM_OPS

mlir/python/mlir/dialects/BuiltinOps.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef PYTHON_BINDINGS_BUILTIN_OPS
1010
#define PYTHON_BINDINGS_BUILTIN_OPS
1111

12-
include "mlir/Bindings/Python/Attributes.td"
1312
include "mlir/IR/BuiltinOps.td"
1413

1514
#endif

mlir/python/mlir/dialects/ComplexOps.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef PYTHON_BINDINGS_COMPLEX_OPS
1010
#define PYTHON_BINDINGS_COMPLEX_OPS
1111

12-
include "mlir/Bindings/Python/Attributes.td"
1312
include "mlir/Dialect/Complex/IR/ComplexOps.td"
1413

1514
#endif

mlir/python/mlir/dialects/ControlFlowOps.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef PYTHON_BINDINGS_CONTROL_FLOW_OPS
1010
#define PYTHON_BINDINGS_CONTROL_FLOW_OPS
1111

12-
include "mlir/Bindings/Python/Attributes.td"
1312
include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.td"
1413

1514
#endif

mlir/python/mlir/dialects/FuncOps.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#ifndef PYTHON_BINDINGS_FUNC
1515
#define PYTHON_BINDINGS_FUNC
1616

17-
include "mlir/Bindings/Python/Attributes.td"
1817
include "mlir/Dialect/Func/IR/FuncOps.td"
1918

2019
#endif

mlir/python/mlir/dialects/GPUOps.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef PYTHON_BINDINGS_GPU_OPS
1010
#define PYTHON_BINDINGS_GPU_OPS
1111

12-
include "mlir/Bindings/Python/Attributes.td"
1312
include "mlir/Dialect/GPU/IR/GPUOps.td"
1413

1514
#endif

mlir/python/mlir/dialects/LinalgOps.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef PYTHON_BINDINGS_LINALG_OPS
1010
#define PYTHON_BINDINGS_LINALG_OPS
1111

12-
include "mlir/Bindings/Python/Attributes.td"
1312
include "mlir/Dialect/Linalg/IR/LinalgOps.td"
1413
include "mlir/Dialect/Linalg/IR/LinalgStructuredOps.td"
1514

mlir/python/mlir/dialects/LinalgStructuredTransformOps.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#ifndef PYTHON_BINDINGS_LINALG_STRUCTURED_TRANSFORM_OPS
1616
#define PYTHON_BINDINGS_LINALG_STRUCTURED_TRANSFORM_OPS
1717

18-
include "mlir/Bindings/Python/Attributes.td"
1918
include "mlir/Dialect/Linalg/TransformOps/LinalgTransformOps.td"
2019

2120
#endif // PYTHON_BINDINGS_LINALG_STRUCTURED_TRANSFORM_OPS

mlir/python/mlir/dialects/MLProgramOps.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef PYTHON_BINDINGS_MLPROGRAM_OPS
1010
#define PYTHON_BINDINGS_MLPROGRAM_OPS
1111

12-
include "mlir/Bindings/Python/Attributes.td"
1312
include "mlir/Dialect/MLProgram/IR/MLProgramOps.td"
1413

1514
#endif

mlir/python/mlir/dialects/MathOps.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef PYTHON_BINDINGS_MATH_OPS
1010
#define PYTHON_BINDINGS_MATH_OPS
1111

12-
include "mlir/Bindings/Python/Attributes.td"
1312
include "mlir/Dialect/Math/IR/MathOps.td"
1413

1514
#endif

mlir/python/mlir/dialects/MemRefOps.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef PYTHON_BINDINGS_MEMREF_OPS
1010
#define PYTHON_BINDINGS_MEMREF_OPS
1111

12-
include "mlir/Bindings/Python/Attributes.td"
1312
include "mlir/Dialect/MemRef/IR/MemRefOps.td"
1413

1514
#endif

mlir/python/mlir/dialects/PDLOps.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef PYTHON_BINDINGS_PDL_OPS
1010
#define PYTHON_BINDINGS_PDL_OPS
1111

12-
include "mlir/Bindings/Python/Attributes.td"
1312
include "mlir/Dialect/PDL/IR/PDLOps.td"
1413

1514
#endif

mlir/python/mlir/dialects/SCFLoopTransformOps.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#ifndef PYTHON_BINDINGS_SCF_LOOP_TRANSFORM_OPS
1616
#define PYTHON_BINDINGS_SCF_LOOP_TRANSFORM_OPS
1717

18-
include "mlir/Bindings/Python/Attributes.td"
1918
include "mlir/Dialect/SCF/TransformOps/SCFTransformOps.td"
2019

2120
#endif // PYTHON_BINDINGS_SCF_LOOP_TRANSFORM_OPS

mlir/python/mlir/dialects/SCFOps.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef PYTHON_BINDINGS_SCF_OPS
1010
#define PYTHON_BINDINGS_SCF_OPS
1111

12-
include "mlir/Bindings/Python/Attributes.td"
1312
include "mlir/Dialect/SCF/IR/SCFOps.td"
1413

1514
#endif

mlir/python/mlir/dialects/ShapeOps.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef PYTHON_BINDINGS_SHAPE_OPS
1010
#define PYTHON_BINDINGS_SHAPE_OPS
1111

12-
include "mlir/Bindings/Python/Attributes.td"
1312
include "mlir/Dialect/Shape/IR/ShapeOps.td"
1413

1514
#endif

mlir/python/mlir/dialects/SparseTensorOps.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef PYTHON_BINDINGS_SPARSE_TENSOR_OPS
1010
#define PYTHON_BINDINGS_SPARSE_TENSOR_OPS
1111

12-
include "mlir/Bindings/Python/Attributes.td"
1312
include "mlir/Dialect/SparseTensor/IR/SparseTensorOps.td"
1413

1514
#endif

mlir/python/mlir/dialects/TensorOps.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef PYTHON_BINDINGS_TENSOR_OPS
1010
#define PYTHON_BINDINGS_TENSOR_OPS
1111

12-
include "mlir/Bindings/Python/Attributes.td"
1312
include "mlir/Dialect/Tensor/IR/TensorOps.td"
1413

1514
#endif

mlir/python/mlir/dialects/TosaOps.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef PYTHON_BINDINGS_TOSA_OPS
1010
#define PYTHON_BINDINGS_TOSA_OPS
1111

12-
include "mlir/Bindings/Python/Attributes.td"
1312
include "mlir/Dialect/Tosa/IR/TosaOps.td"
1413

1514
#endif

mlir/python/mlir/dialects/TransformOps.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef PYTHON_BINDINGS_TRANSFORM_OPS
1010
#define PYTHON_BINDINGS_TRANSFORM_OPS
1111

12-
include "mlir/Bindings/Python/Attributes.td"
1312
include "mlir/Dialect/Transform/IR/TransformOps.td"
1413

1514
#endif // PYTHON_BINDINGS_TRANSFORM_OPS

mlir/python/mlir/dialects/TransformPDLExtensionOps.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
#ifndef PYTHON_BINDINGS_TRANSFORM_PDL_EXTENSION_OPS
1515
#define PYTHON_BINDINGS_TRANSFORM_PDL_EXTENSION_OPS
1616

17-
include "mlir/Bindings/Python/Attributes.td"
1817
include "mlir/Dialect/Transform/PDLExtension/PDLExtensionOps.td"
1918

2019
#endif // PYTHON_BINDINGS_TRANSFORM_PDL_EXTENSION_OPS

mlir/python/mlir/dialects/VectorOps.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef PYTHON_BINDINGS_VECTOR_OPS
1010
#define PYTHON_BINDINGS_VECTOR_OPS
1111

12-
include "mlir/Bindings/Python/Attributes.td"
1312
include "mlir/Dialect/Vector/IR/VectorOps.td"
1413

1514
#endif

mlir/test/mlir-tblgen/op-python-bindings.td

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
include "mlir/IR/OpBase.td"
44
include "mlir/IR/AttrTypeBase.td"
55
include "mlir/Interfaces/InferTypeOpInterface.td"
6-
include "mlir/Bindings/Python/Attributes.td"
76

87
// CHECK: @_ods_cext.register_dialect
98
// CHECK: class _Dialect(_ods_ir.Dialect):
@@ -13,8 +12,6 @@ def Test_Dialect : Dialect {
1312
let name = "test";
1413
let cppNamespace = "Test";
1514
}
16-
def TestAttr : AttrDef<Test_Dialect, "TestAttr">;
17-
def : PythonAttr<TestAttr.cppType, "<TestAttr hook>">;
1815

1916
class TestOp<string mnemonic, list<Trait> traits = []> :
2017
Op<Test_Dialect, mnemonic, traits>;
@@ -114,7 +111,7 @@ def AttrSizedResultsOp : TestOp<"attr_sized_results",
114111
// CHECK-NOT: _ODS_OPERAND_SEGMENTS
115112
// CHECK-NOT: _ODS_RESULT_SEGMENTS
116113
def AttributedOp : TestOp<"attributed_op"> {
117-
// CHECK: def __init__(self, i32attr, in_, test_attr, *, optionalF32Attr=None, unitAttr=None, loc=None, ip=None):
114+
// CHECK: def __init__(self, i32attr, in_, *, optionalF32Attr=None, unitAttr=None, loc=None, ip=None):
118115
// CHECK: operands = []
119116
// CHECK: results = []
120117
// CHECK: attributes = {}
@@ -134,27 +131,24 @@ def AttributedOp : TestOp<"attributed_op"> {
134131

135132
// CHECK: @builtins.property
136133
// CHECK: def i32attr(self):
137-
// CHECK: return (self.operation.attributes["i32attr"])
134+
// CHECK: return self.operation.attributes["i32attr"]
138135

139136
// CHECK: @builtins.property
140137
// CHECK: def optionalF32Attr(self):
141138
// CHECK: if "optionalF32Attr" not in self.operation.attributes:
142139
// CHECK: return None
143-
// CHECK: return (self.operation.attributes["optionalF32Attr"])
140+
// CHECK: return self.operation.attributes["optionalF32Attr"]
144141

145142
// CHECK: @builtins.property
146143
// CHECK: def unitAttr(self):
147144
// CHECK: return "unitAttr" in self.operation.attributes
148145

149146
// CHECK: @builtins.property
150147
// CHECK: def in_(self):
151-
// CHECK: return (self.operation.attributes["in"])
148+
// CHECK: return self.operation.attributes["in"]
152149

153-
// CHECK: @builtins.property
154-
// CHECK: def test_attr(self):
155-
// CHECK: return <TestAttr hook>(self.operation.attributes["test_attr"])
156150
let arguments = (ins I32Attr:$i32attr, OptionalAttr<F32Attr>:$optionalF32Attr,
157-
UnitAttr:$unitAttr, I32Attr:$in, TestAttr:$test_attr);
151+
UnitAttr:$unitAttr, I32Attr:$in);
158152
}
159153

160154
// CHECK: @_ods_cext.register_operation(_Dialect)
@@ -186,7 +180,7 @@ def AttributedOpWithOperands : TestOp<"attributed_op_with_operands"> {
186180
// CHECK: def is_(self):
187181
// CHECK: if "is" not in self.operation.attributes:
188182
// CHECK: return None
189-
// CHECK: return (self.operation.attributes["is"])
183+
// CHECK: return self.operation.attributes["is"]
190184
let arguments = (ins I32, UnitAttr:$in, F32, OptionalAttr<F32Attr>:$is);
191185
}
192186

mlir/test/python/python_test_ops.td

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#define PYTHON_TEST_OPS
1111

1212
include "mlir/IR/AttrTypeBase.td"
13-
include "mlir/Bindings/Python/Attributes.td"
1413
include "mlir/IR/OpBase.td"
1514
include "mlir/Interfaces/InferTypeOpInterface.td"
1615

0 commit comments

Comments
 (0)