[Mlir-commits] [mlir] 67a910b - [mlir][python] Remove PythonAttr mapping functionality
Rahul Kayaith
llvmlistbot at llvm.org
Tue Jul 18 09:21:34 PDT 2023
Author: Rahul Kayaith
Date: 2023-07-18T12:21:28-04:00
New Revision: 67a910bbff772ebf4c47e8b434b59cdc4820bb68
URL: https://github.com/llvm/llvm-project/commit/67a910bbff772ebf4c47e8b434b59cdc4820bb68
DIFF: https://github.com/llvm/llvm-project/commit/67a910bbff772ebf4c47e8b434b59cdc4820bb68.diff
LOG: [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
Added:
Modified:
mlir/cmake/modules/AddMLIRPython.cmake
mlir/docs/Bindings/Python.md
mlir/examples/standalone/python/mlir_standalone/dialects/StandaloneOps.td
mlir/python/mlir/dialects/ArithOps.td
mlir/python/mlir/dialects/AsyncOps.td
mlir/python/mlir/dialects/BufferizationOps.td
mlir/python/mlir/dialects/BufferizationTransformOps.td
mlir/python/mlir/dialects/BuiltinOps.td
mlir/python/mlir/dialects/ComplexOps.td
mlir/python/mlir/dialects/ControlFlowOps.td
mlir/python/mlir/dialects/FuncOps.td
mlir/python/mlir/dialects/GPUOps.td
mlir/python/mlir/dialects/LinalgOps.td
mlir/python/mlir/dialects/LinalgStructuredTransformOps.td
mlir/python/mlir/dialects/MLProgramOps.td
mlir/python/mlir/dialects/MathOps.td
mlir/python/mlir/dialects/MemRefOps.td
mlir/python/mlir/dialects/PDLOps.td
mlir/python/mlir/dialects/SCFLoopTransformOps.td
mlir/python/mlir/dialects/SCFOps.td
mlir/python/mlir/dialects/ShapeOps.td
mlir/python/mlir/dialects/SparseTensorOps.td
mlir/python/mlir/dialects/TensorOps.td
mlir/python/mlir/dialects/TosaOps.td
mlir/python/mlir/dialects/TransformOps.td
mlir/python/mlir/dialects/TransformPDLExtensionOps.td
mlir/python/mlir/dialects/VectorOps.td
mlir/test/mlir-tblgen/op-python-bindings.td
mlir/test/python/python_test_ops.td
mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp
Removed:
mlir/include/mlir/Bindings/Python/Attributes.td
################################################################################
diff --git a/mlir/cmake/modules/AddMLIRPython.cmake b/mlir/cmake/modules/AddMLIRPython.cmake
index 9227c5186d736d..382f7c0624e796 100644
--- a/mlir/cmake/modules/AddMLIRPython.cmake
+++ b/mlir/cmake/modules/AddMLIRPython.cmake
@@ -271,6 +271,11 @@ endfunction()
# SOURCES: Same as declare_mlir_python_sources().
# SOURCES_GLOB: Same as declare_mlir_python_sources().
# DEPENDS: Additional dependency targets.
+#
+# TODO: Right now `TD_FILE` can't be the actual dialect tablegen file, since we
+# use its path to determine where to place the generated python file. If
+# we made the output path an additional argument here we could remove the
+# need for the separate "wrapper" .td files
function(declare_mlir_dialect_python_bindings)
cmake_parse_arguments(ARG
""
diff --git a/mlir/docs/Bindings/Python.md b/mlir/docs/Bindings/Python.md
index a7b2b313ea4233..bf54efee1f14e0 100644
--- a/mlir/docs/Bindings/Python.md
+++ b/mlir/docs/Bindings/Python.md
@@ -919,7 +919,6 @@ the `Func` (which is assigned the namespace `func` as a special case):
#ifndef PYTHON_BINDINGS_FUNC_OPS
#define PYTHON_BINDINGS_FUNC_OPS
-include "mlir/Bindings/Python/Attributes.td"
include "mlir/Dialect/Func/IR/FuncOps.td"
#endif // PYTHON_BINDINGS_FUNC_OPS
@@ -1125,14 +1124,10 @@ Dialect operations are provided in Python by wrapping the generic
properties. Therefore, there is no need to implement a separate C API for them.
For operations defined in ODS, `mlir-tblgen -gen-python-op-bindings
-bind-dialect=<dialect-namespace>` generates the Python API from the declarative
-description. If the build API uses specific attribute types, such as
-`::mlir::IntegerAttr` or `::mlir::DenseIntElementsAttr`, for its arguments, the
-mapping to the corresponding Python types should be provided in ODS definition.
-For built-in attribute types, this mapping is available in
-[`include/mlir/Bindings/Python/Attributes.td`](https://github.com/llvm/llvm-project/blob/main/mlir/include/mlir/Bindings/Python/Attributes.td);
-it is sufficient to create a new `.td` file that includes this file and the
-original ODS definition and use it as source for the `mlir-tblgen` call. Such
-`.td` files reside in
+description.
+It is sufficient to create a new `.td` file that includes the original ODS
+definition and use it as source for the `mlir-tblgen` call.
+Such `.td` files reside in
[`python/mlir/dialects/`](https://github.com/llvm/llvm-project/tree/main/mlir/python/mlir/dialects).
The results of `mlir-tblgen` are expected to produce a file named
`_<dialect-namespace>_ops_gen.py` by convention. The generated operation classes
diff --git a/mlir/examples/standalone/python/mlir_standalone/dialects/StandaloneOps.td b/mlir/examples/standalone/python/mlir_standalone/dialects/StandaloneOps.td
index 6cfa6b7aba3ef4..7246582a1b52cd 100644
--- a/mlir/examples/standalone/python/mlir_standalone/dialects/StandaloneOps.td
+++ b/mlir/examples/standalone/python/mlir_standalone/dialects/StandaloneOps.td
@@ -9,7 +9,6 @@
#ifndef PYTHON_BINDINGS_STANDALONE_OPS
#define PYTHON_BINDINGS_STANDALONE_OPS
-include "mlir/Bindings/Python/Attributes.td"
include "Standalone/StandaloneOps.td"
#endif
diff --git a/mlir/include/mlir/Bindings/Python/Attributes.td b/mlir/include/mlir/Bindings/Python/Attributes.td
deleted file mode 100644
index c5947c62ddf460..00000000000000
--- a/mlir/include/mlir/Bindings/Python/Attributes.td
+++ /dev/null
@@ -1,24 +0,0 @@
-//===-- Attributes.td - Attribute mapping for Python -------*- tablegen -*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This defines the mapping between MLIR ODS attributes and the corresponding
-// Python binding classes.
-//
-//===----------------------------------------------------------------------===//
-
-#ifndef PYTHON_BINDINGS_ATTRIBUTES
-#define PYTHON_BINDINGS_ATTRIBUTES
-
-// A mapping between the attribute storage type and the corresponding Python
-// type. There is not necessarily a 1-1 match for non-builtin attributes.
-class PythonAttr<string c, string p> {
- string cppStorageType = c;
- string pythonType = p;
-}
-
-#endif
diff --git a/mlir/python/mlir/dialects/ArithOps.td b/mlir/python/mlir/dialects/ArithOps.td
index aaa9fad21e4ab0..60dbb08a05758c 100644
--- a/mlir/python/mlir/dialects/ArithOps.td
+++ b/mlir/python/mlir/dialects/ArithOps.td
@@ -9,7 +9,6 @@
#ifndef PYTHON_BINDINGS_ARITH_OPS
#define PYTHON_BINDINGS_ARITH_OPS
-include "mlir/Bindings/Python/Attributes.td"
include "mlir/Dialect/Arith/IR/ArithOps.td"
#endif
diff --git a/mlir/python/mlir/dialects/AsyncOps.td b/mlir/python/mlir/dialects/AsyncOps.td
index b65b9bafdd6138..2b05045cff1a25 100644
--- a/mlir/python/mlir/dialects/AsyncOps.td
+++ b/mlir/python/mlir/dialects/AsyncOps.td
@@ -9,7 +9,6 @@
#ifndef PYTHON_BINDINGS_ASYNC_OPS
#define PYTHON_BINDINGS_ASYNC_OPS
-include "mlir/Bindings/Python/Attributes.td"
include "mlir/Dialect/Async/IR/AsyncOps.td"
#endif
diff --git a/mlir/python/mlir/dialects/BufferizationOps.td b/mlir/python/mlir/dialects/BufferizationOps.td
index c5170cee3534cd..b2ac7e2813600e 100644
--- a/mlir/python/mlir/dialects/BufferizationOps.td
+++ b/mlir/python/mlir/dialects/BufferizationOps.td
@@ -9,7 +9,6 @@
#ifndef PYTHON_BINDINGS_BUFFERIZATION_OPS
#define PYTHON_BINDINGS_BUFFERIZATION_OPS
-include "mlir/Bindings/Python/Attributes.td"
include "mlir/Dialect/Bufferization/IR/BufferizationOps.td"
#endif
diff --git a/mlir/python/mlir/dialects/BufferizationTransformOps.td b/mlir/python/mlir/dialects/BufferizationTransformOps.td
index cf2ed661fe0b00..34213be22f90e1 100644
--- a/mlir/python/mlir/dialects/BufferizationTransformOps.td
+++ b/mlir/python/mlir/dialects/BufferizationTransformOps.td
@@ -15,7 +15,6 @@
#ifndef PYTHON_BINDINGS_BUFFERIZATION_TRANSFORM_OPS
#define PYTHON_BINDINGS_BUFFERIZATION_TRANSFORM_OPS
-include "mlir/Bindings/Python/Attributes.td"
include "mlir/Dialect/Bufferization/TransformOps/BufferizationTransformOps.td"
#endif // PYTHON_BINDINGS_BUFFERIZATION_TRANSFORM_OPS
diff --git a/mlir/python/mlir/dialects/BuiltinOps.td b/mlir/python/mlir/dialects/BuiltinOps.td
index ecbb8227d49006..d1c595283b70a8 100644
--- a/mlir/python/mlir/dialects/BuiltinOps.td
+++ b/mlir/python/mlir/dialects/BuiltinOps.td
@@ -9,7 +9,6 @@
#ifndef PYTHON_BINDINGS_BUILTIN_OPS
#define PYTHON_BINDINGS_BUILTIN_OPS
-include "mlir/Bindings/Python/Attributes.td"
include "mlir/IR/BuiltinOps.td"
#endif
diff --git a/mlir/python/mlir/dialects/ComplexOps.td b/mlir/python/mlir/dialects/ComplexOps.td
index 6fd846ba6d270f..17825b6beab1cc 100644
--- a/mlir/python/mlir/dialects/ComplexOps.td
+++ b/mlir/python/mlir/dialects/ComplexOps.td
@@ -9,7 +9,6 @@
#ifndef PYTHON_BINDINGS_COMPLEX_OPS
#define PYTHON_BINDINGS_COMPLEX_OPS
-include "mlir/Bindings/Python/Attributes.td"
include "mlir/Dialect/Complex/IR/ComplexOps.td"
#endif
diff --git a/mlir/python/mlir/dialects/ControlFlowOps.td b/mlir/python/mlir/dialects/ControlFlowOps.td
index 1bb4d41f2626bf..c9610a3c69b039 100644
--- a/mlir/python/mlir/dialects/ControlFlowOps.td
+++ b/mlir/python/mlir/dialects/ControlFlowOps.td
@@ -9,7 +9,6 @@
#ifndef PYTHON_BINDINGS_CONTROL_FLOW_OPS
#define PYTHON_BINDINGS_CONTROL_FLOW_OPS
-include "mlir/Bindings/Python/Attributes.td"
include "mlir/Dialect/ControlFlow/IR/ControlFlowOps.td"
#endif
diff --git a/mlir/python/mlir/dialects/FuncOps.td b/mlir/python/mlir/dialects/FuncOps.td
index 1728091f444405..0816d6a3f9f20f 100644
--- a/mlir/python/mlir/dialects/FuncOps.td
+++ b/mlir/python/mlir/dialects/FuncOps.td
@@ -14,7 +14,6 @@
#ifndef PYTHON_BINDINGS_FUNC
#define PYTHON_BINDINGS_FUNC
-include "mlir/Bindings/Python/Attributes.td"
include "mlir/Dialect/Func/IR/FuncOps.td"
#endif
diff --git a/mlir/python/mlir/dialects/GPUOps.td b/mlir/python/mlir/dialects/GPUOps.td
index 4e23d322f6c2fd..83b1f6cd4c5cfc 100644
--- a/mlir/python/mlir/dialects/GPUOps.td
+++ b/mlir/python/mlir/dialects/GPUOps.td
@@ -9,7 +9,6 @@
#ifndef PYTHON_BINDINGS_GPU_OPS
#define PYTHON_BINDINGS_GPU_OPS
-include "mlir/Bindings/Python/Attributes.td"
include "mlir/Dialect/GPU/IR/GPUOps.td"
#endif
diff --git a/mlir/python/mlir/dialects/LinalgOps.td b/mlir/python/mlir/dialects/LinalgOps.td
index 7650e954d59eee..b7658c85a9c44d 100644
--- a/mlir/python/mlir/dialects/LinalgOps.td
+++ b/mlir/python/mlir/dialects/LinalgOps.td
@@ -9,7 +9,6 @@
#ifndef PYTHON_BINDINGS_LINALG_OPS
#define PYTHON_BINDINGS_LINALG_OPS
-include "mlir/Bindings/Python/Attributes.td"
include "mlir/Dialect/Linalg/IR/LinalgOps.td"
include "mlir/Dialect/Linalg/IR/LinalgStructuredOps.td"
diff --git a/mlir/python/mlir/dialects/LinalgStructuredTransformOps.td b/mlir/python/mlir/dialects/LinalgStructuredTransformOps.td
index a9a53fe6db288e..e11065bf820709 100644
--- a/mlir/python/mlir/dialects/LinalgStructuredTransformOps.td
+++ b/mlir/python/mlir/dialects/LinalgStructuredTransformOps.td
@@ -15,7 +15,6 @@
#ifndef PYTHON_BINDINGS_LINALG_STRUCTURED_TRANSFORM_OPS
#define PYTHON_BINDINGS_LINALG_STRUCTURED_TRANSFORM_OPS
-include "mlir/Bindings/Python/Attributes.td"
include "mlir/Dialect/Linalg/TransformOps/LinalgTransformOps.td"
#endif // PYTHON_BINDINGS_LINALG_STRUCTURED_TRANSFORM_OPS
diff --git a/mlir/python/mlir/dialects/MLProgramOps.td b/mlir/python/mlir/dialects/MLProgramOps.td
index 5ac45ca1b42b51..35b348d5f49466 100644
--- a/mlir/python/mlir/dialects/MLProgramOps.td
+++ b/mlir/python/mlir/dialects/MLProgramOps.td
@@ -9,7 +9,6 @@
#ifndef PYTHON_BINDINGS_MLPROGRAM_OPS
#define PYTHON_BINDINGS_MLPROGRAM_OPS
-include "mlir/Bindings/Python/Attributes.td"
include "mlir/Dialect/MLProgram/IR/MLProgramOps.td"
#endif
diff --git a/mlir/python/mlir/dialects/MathOps.td b/mlir/python/mlir/dialects/MathOps.td
index 03d1fdef0c2e74..8f68467ea9aa79 100644
--- a/mlir/python/mlir/dialects/MathOps.td
+++ b/mlir/python/mlir/dialects/MathOps.td
@@ -9,7 +9,6 @@
#ifndef PYTHON_BINDINGS_MATH_OPS
#define PYTHON_BINDINGS_MATH_OPS
-include "mlir/Bindings/Python/Attributes.td"
include "mlir/Dialect/Math/IR/MathOps.td"
#endif
diff --git a/mlir/python/mlir/dialects/MemRefOps.td b/mlir/python/mlir/dialects/MemRefOps.td
index 8dd9764791ea70..ed346d5a22a3dc 100644
--- a/mlir/python/mlir/dialects/MemRefOps.td
+++ b/mlir/python/mlir/dialects/MemRefOps.td
@@ -9,7 +9,6 @@
#ifndef PYTHON_BINDINGS_MEMREF_OPS
#define PYTHON_BINDINGS_MEMREF_OPS
-include "mlir/Bindings/Python/Attributes.td"
include "mlir/Dialect/MemRef/IR/MemRefOps.td"
#endif
diff --git a/mlir/python/mlir/dialects/PDLOps.td b/mlir/python/mlir/dialects/PDLOps.td
index e4e6a83cd03f0b..a8c2d6bdb89250 100644
--- a/mlir/python/mlir/dialects/PDLOps.td
+++ b/mlir/python/mlir/dialects/PDLOps.td
@@ -9,7 +9,6 @@
#ifndef PYTHON_BINDINGS_PDL_OPS
#define PYTHON_BINDINGS_PDL_OPS
-include "mlir/Bindings/Python/Attributes.td"
include "mlir/Dialect/PDL/IR/PDLOps.td"
#endif
diff --git a/mlir/python/mlir/dialects/SCFLoopTransformOps.td b/mlir/python/mlir/dialects/SCFLoopTransformOps.td
index 5ef07fc7aa137e..7b09fc14bd0a61 100644
--- a/mlir/python/mlir/dialects/SCFLoopTransformOps.td
+++ b/mlir/python/mlir/dialects/SCFLoopTransformOps.td
@@ -15,7 +15,6 @@
#ifndef PYTHON_BINDINGS_SCF_LOOP_TRANSFORM_OPS
#define PYTHON_BINDINGS_SCF_LOOP_TRANSFORM_OPS
-include "mlir/Bindings/Python/Attributes.td"
include "mlir/Dialect/SCF/TransformOps/SCFTransformOps.td"
#endif // PYTHON_BINDINGS_SCF_LOOP_TRANSFORM_OPS
diff --git a/mlir/python/mlir/dialects/SCFOps.td b/mlir/python/mlir/dialects/SCFOps.td
index 58f337e235bbed..f1fc8a8db1419f 100644
--- a/mlir/python/mlir/dialects/SCFOps.td
+++ b/mlir/python/mlir/dialects/SCFOps.td
@@ -9,7 +9,6 @@
#ifndef PYTHON_BINDINGS_SCF_OPS
#define PYTHON_BINDINGS_SCF_OPS
-include "mlir/Bindings/Python/Attributes.td"
include "mlir/Dialect/SCF/IR/SCFOps.td"
#endif
diff --git a/mlir/python/mlir/dialects/ShapeOps.td b/mlir/python/mlir/dialects/ShapeOps.td
index c469a586bb27e5..e217b2edcf1967 100644
--- a/mlir/python/mlir/dialects/ShapeOps.td
+++ b/mlir/python/mlir/dialects/ShapeOps.td
@@ -9,7 +9,6 @@
#ifndef PYTHON_BINDINGS_SHAPE_OPS
#define PYTHON_BINDINGS_SHAPE_OPS
-include "mlir/Bindings/Python/Attributes.td"
include "mlir/Dialect/Shape/IR/ShapeOps.td"
#endif
diff --git a/mlir/python/mlir/dialects/SparseTensorOps.td b/mlir/python/mlir/dialects/SparseTensorOps.td
index b3b4846dbd333e..3f0d522f371e9a 100644
--- a/mlir/python/mlir/dialects/SparseTensorOps.td
+++ b/mlir/python/mlir/dialects/SparseTensorOps.td
@@ -9,7 +9,6 @@
#ifndef PYTHON_BINDINGS_SPARSE_TENSOR_OPS
#define PYTHON_BINDINGS_SPARSE_TENSOR_OPS
-include "mlir/Bindings/Python/Attributes.td"
include "mlir/Dialect/SparseTensor/IR/SparseTensorOps.td"
#endif
diff --git a/mlir/python/mlir/dialects/TensorOps.td b/mlir/python/mlir/dialects/TensorOps.td
index 40ecea7bfe8a17..d68cd24477257a 100644
--- a/mlir/python/mlir/dialects/TensorOps.td
+++ b/mlir/python/mlir/dialects/TensorOps.td
@@ -9,7 +9,6 @@
#ifndef PYTHON_BINDINGS_TENSOR_OPS
#define PYTHON_BINDINGS_TENSOR_OPS
-include "mlir/Bindings/Python/Attributes.td"
include "mlir/Dialect/Tensor/IR/TensorOps.td"
#endif
diff --git a/mlir/python/mlir/dialects/TosaOps.td b/mlir/python/mlir/dialects/TosaOps.td
index d906bad7ce6204..b429780bca58ce 100644
--- a/mlir/python/mlir/dialects/TosaOps.td
+++ b/mlir/python/mlir/dialects/TosaOps.td
@@ -9,7 +9,6 @@
#ifndef PYTHON_BINDINGS_TOSA_OPS
#define PYTHON_BINDINGS_TOSA_OPS
-include "mlir/Bindings/Python/Attributes.td"
include "mlir/Dialect/Tosa/IR/TosaOps.td"
#endif
diff --git a/mlir/python/mlir/dialects/TransformOps.td b/mlir/python/mlir/dialects/TransformOps.td
index 7f0d80ead4e635..e2f6cf932aa3e6 100644
--- a/mlir/python/mlir/dialects/TransformOps.td
+++ b/mlir/python/mlir/dialects/TransformOps.td
@@ -9,7 +9,6 @@
#ifndef PYTHON_BINDINGS_TRANSFORM_OPS
#define PYTHON_BINDINGS_TRANSFORM_OPS
-include "mlir/Bindings/Python/Attributes.td"
include "mlir/Dialect/Transform/IR/TransformOps.td"
#endif // PYTHON_BINDINGS_TRANSFORM_OPS
diff --git a/mlir/python/mlir/dialects/TransformPDLExtensionOps.td b/mlir/python/mlir/dialects/TransformPDLExtensionOps.td
index e3e5daf18d738f..56fadd0295c729 100644
--- a/mlir/python/mlir/dialects/TransformPDLExtensionOps.td
+++ b/mlir/python/mlir/dialects/TransformPDLExtensionOps.td
@@ -14,7 +14,6 @@
#ifndef PYTHON_BINDINGS_TRANSFORM_PDL_EXTENSION_OPS
#define PYTHON_BINDINGS_TRANSFORM_PDL_EXTENSION_OPS
-include "mlir/Bindings/Python/Attributes.td"
include "mlir/Dialect/Transform/PDLExtension/PDLExtensionOps.td"
#endif // PYTHON_BINDINGS_TRANSFORM_PDL_EXTENSION_OPS
diff --git a/mlir/python/mlir/dialects/VectorOps.td b/mlir/python/mlir/dialects/VectorOps.td
index 267c2b2a0a5a80..69a1028c9be61c 100644
--- a/mlir/python/mlir/dialects/VectorOps.td
+++ b/mlir/python/mlir/dialects/VectorOps.td
@@ -9,7 +9,6 @@
#ifndef PYTHON_BINDINGS_VECTOR_OPS
#define PYTHON_BINDINGS_VECTOR_OPS
-include "mlir/Bindings/Python/Attributes.td"
include "mlir/Dialect/Vector/IR/VectorOps.td"
#endif
diff --git a/mlir/test/mlir-tblgen/op-python-bindings.td b/mlir/test/mlir-tblgen/op-python-bindings.td
index 7513edae418551..036ea5b4a852e2 100644
--- a/mlir/test/mlir-tblgen/op-python-bindings.td
+++ b/mlir/test/mlir-tblgen/op-python-bindings.td
@@ -3,7 +3,6 @@
include "mlir/IR/OpBase.td"
include "mlir/IR/AttrTypeBase.td"
include "mlir/Interfaces/InferTypeOpInterface.td"
-include "mlir/Bindings/Python/Attributes.td"
// CHECK: @_ods_cext.register_dialect
// CHECK: class _Dialect(_ods_ir.Dialect):
@@ -13,8 +12,6 @@ def Test_Dialect : Dialect {
let name = "test";
let cppNamespace = "Test";
}
-def TestAttr : AttrDef<Test_Dialect, "TestAttr">;
-def : PythonAttr<TestAttr.cppType, "<TestAttr hook>">;
class TestOp<string mnemonic, list<Trait> traits = []> :
Op<Test_Dialect, mnemonic, traits>;
@@ -114,7 +111,7 @@ def AttrSizedResultsOp : TestOp<"attr_sized_results",
// CHECK-NOT: _ODS_OPERAND_SEGMENTS
// CHECK-NOT: _ODS_RESULT_SEGMENTS
def AttributedOp : TestOp<"attributed_op"> {
- // CHECK: def __init__(self, i32attr, in_, test_attr, *, optionalF32Attr=None, unitAttr=None, loc=None, ip=None):
+ // CHECK: def __init__(self, i32attr, in_, *, optionalF32Attr=None, unitAttr=None, loc=None, ip=None):
// CHECK: operands = []
// CHECK: results = []
// CHECK: attributes = {}
@@ -134,13 +131,13 @@ def AttributedOp : TestOp<"attributed_op"> {
// CHECK: @builtins.property
// CHECK: def i32attr(self):
- // CHECK: return (self.operation.attributes["i32attr"])
+ // CHECK: return self.operation.attributes["i32attr"]
// CHECK: @builtins.property
// CHECK: def optionalF32Attr(self):
// CHECK: if "optionalF32Attr" not in self.operation.attributes:
// CHECK: return None
- // CHECK: return (self.operation.attributes["optionalF32Attr"])
+ // CHECK: return self.operation.attributes["optionalF32Attr"]
// CHECK: @builtins.property
// CHECK: def unitAttr(self):
@@ -148,13 +145,10 @@ def AttributedOp : TestOp<"attributed_op"> {
// CHECK: @builtins.property
// CHECK: def in_(self):
- // CHECK: return (self.operation.attributes["in"])
+ // CHECK: return self.operation.attributes["in"]
- // CHECK: @builtins.property
- // CHECK: def test_attr(self):
- // CHECK: return <TestAttr hook>(self.operation.attributes["test_attr"])
let arguments = (ins I32Attr:$i32attr, OptionalAttr<F32Attr>:$optionalF32Attr,
- UnitAttr:$unitAttr, I32Attr:$in, TestAttr:$test_attr);
+ UnitAttr:$unitAttr, I32Attr:$in);
}
// CHECK: @_ods_cext.register_operation(_Dialect)
@@ -186,7 +180,7 @@ def AttributedOpWithOperands : TestOp<"attributed_op_with_operands"> {
// CHECK: def is_(self):
// CHECK: if "is" not in self.operation.attributes:
// CHECK: return None
- // CHECK: return (self.operation.attributes["is"])
+ // CHECK: return self.operation.attributes["is"]
let arguments = (ins I32, UnitAttr:$in, F32, OptionalAttr<F32Attr>:$is);
}
diff --git a/mlir/test/python/python_test_ops.td b/mlir/test/python/python_test_ops.td
index 2fc78cbddcd510..2adbdcab71834d 100644
--- a/mlir/test/python/python_test_ops.td
+++ b/mlir/test/python/python_test_ops.td
@@ -10,7 +10,6 @@
#define PYTHON_TEST_OPS
include "mlir/IR/AttrTypeBase.td"
-include "mlir/Bindings/Python/Attributes.td"
include "mlir/IR/OpBase.td"
include "mlir/Interfaces/InferTypeOpInterface.td"
diff --git a/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp b/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp
index d25c4b30e8d0b9..f17e6e9eda4031 100644
--- a/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp
+++ b/mlir/tools/mlir-tblgen/OpPythonBindingGen.cpp
@@ -182,24 +182,22 @@ constexpr const char *opVariadicSegmentOptionalTrailingTemplate =
/// Template for an operation attribute getter:
/// {0} is the name of the attribute sanitized for Python;
-/// {1} is the Python type of the attribute;
-/// {2} os the original name of the attribute.
+/// {1} is the original name of the attribute.
constexpr const char *attributeGetterTemplate = R"Py(
@builtins.property
def {0}(self):
- return {1}(self.operation.attributes["{2}"])
+ return self.operation.attributes["{1}"]
)Py";
/// Template for an optional operation attribute getter:
/// {0} is the name of the attribute sanitized for Python;
-/// {1} is the Python type of the attribute;
-/// {2} is the original name of the attribute.
+/// {1} is the original name of the attribute.
constexpr const char *optionalAttributeGetterTemplate = R"Py(
@builtins.property
def {0}(self):
- if "{2}" not in self.operation.attributes:
+ if "{1}" not in self.operation.attributes:
return None
- return {1}(self.operation.attributes["{2}"])
+ return self.operation.attributes["{1}"]
)Py";
/// Template for a getter of a unit operation attribute, returns True of the
@@ -443,9 +441,7 @@ static void emitResultAccessors(const Operator &op, raw_ostream &os) {
}
/// Emits accessors to Op attributes.
-static void emitAttributeAccessors(const Operator &op,
- const AttributeClasses &attributeClasses,
- raw_ostream &os) {
+static void emitAttributeAccessors(const Operator &op, raw_ostream &os) {
for (const auto &namedAttr : op.getAttributes()) {
// Skip "derived" attributes because they are just C++ functions that we
// don't currently expose.
@@ -468,17 +464,15 @@ static void emitAttributeAccessors(const Operator &op,
continue;
}
- StringRef pythonType =
- attributeClasses.lookup(namedAttr.attr.getStorageType());
if (namedAttr.attr.isOptional()) {
os << llvm::formatv(optionalAttributeGetterTemplate, sanitizedName,
- pythonType, namedAttr.name);
+ namedAttr.name);
os << llvm::formatv(optionalAttributeSetterTemplate, sanitizedName,
namedAttr.name);
os << llvm::formatv(attributeDeleterTemplate, sanitizedName,
namedAttr.name);
} else {
- os << llvm::formatv(attributeGetterTemplate, sanitizedName, pythonType,
+ os << llvm::formatv(attributeGetterTemplate, sanitizedName,
namedAttr.name);
os << llvm::formatv(attributeSetterTemplate, sanitizedName,
namedAttr.name);
@@ -944,15 +938,6 @@ static void emitDefaultOpBuilder(const Operator &op, raw_ostream &os) {
llvm::join(builderLines, "\n "));
}
-static void constructAttributeMapping(const llvm::RecordKeeper &records,
- AttributeClasses &attributeClasses) {
- for (const llvm::Record *rec :
- records.getAllDerivedDefinitions("PythonAttr")) {
- attributeClasses.try_emplace(rec->getValueAsString("cppStorageType").trim(),
- rec->getValueAsString("pythonType").trim());
- }
-}
-
static void emitSegmentSpec(
const Operator &op, const char *kind,
llvm::function_ref<int(const Operator &)> getNumElements,
@@ -999,9 +984,7 @@ static void emitRegionAccessors(const Operator &op, raw_ostream &os) {
}
/// Emits bindings for a specific Op to the given output stream.
-static void emitOpBindings(const Operator &op,
- const AttributeClasses &attributeClasses,
- raw_ostream &os) {
+static void emitOpBindings(const Operator &op, raw_ostream &os) {
os << llvm::formatv(opClassTemplate, op.getCppClassName(),
op.getOperationName());
@@ -1016,7 +999,7 @@ static void emitOpBindings(const Operator &op,
emitRegionAttributes(op, os);
emitDefaultOpBuilder(op, os);
emitOperandAccessors(op, os);
- emitAttributeAccessors(op, attributeClasses, os);
+ emitAttributeAccessors(op, os);
emitResultAccessors(op, os);
emitRegionAccessors(op, os);
}
@@ -1028,9 +1011,6 @@ static bool emitAllOps(const llvm::RecordKeeper &records, raw_ostream &os) {
if (clDialectName.empty())
llvm::PrintFatalError("dialect name not provided");
- AttributeClasses attributeClasses;
- constructAttributeMapping(records, attributeClasses);
-
bool isExtension = !clDialectExtensionName.empty();
os << llvm::formatv(fileHeader, isExtension
? clDialectExtensionName.getValue()
@@ -1043,7 +1023,7 @@ static bool emitAllOps(const llvm::RecordKeeper &records, raw_ostream &os) {
for (const llvm::Record *rec : records.getAllDerivedDefinitions("Op")) {
Operator op(rec);
if (op.getDialectName() == clDialectName.getValue())
- emitOpBindings(op, attributeClasses, os);
+ emitOpBindings(op, os);
}
return false;
}
More information about the Mlir-commits
mailing list