Attributes represent additional data about an operation and are intended to be modifiable during the lifetime of the operation. In the dialect-specific Python bindings, attributes are exposed as properties on the operation class. Allow for assigning values to these properties. Also support creating new and deleting existing attributes through the generic "attributes" property of an operation. Any validity checking must be performed by the op verifier after the mutation, similarly to C++. Operations are not invalidated in the process: no dangling pointers can be created as all attributes are owned by the context and will remain live even if they are not used in any operation. Introduce a Python Test dialect by analogy with the Test dialect and to avoid polluting the latter with Python-specific constructs. Use this dialect to implement a test for the attribute access and mutation API. Reviewed By: stellaraccident, mehdi_amini Differential Revision: https://reviews.llvm.org/D91652
29 lines
922 B
TableGen
29 lines
922 B
TableGen
//===-- python_test_ops.td - Python test Op definitions ----*- 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
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef PYTHON_TEST_OPS
|
|
#define PYTHON_TEST_OPS
|
|
|
|
include "mlir/IR/OpBase.td"
|
|
include "../../../lib/Bindings/Python/Attributes.td"
|
|
|
|
def Python_Test_Dialect : Dialect {
|
|
let name = "python_test";
|
|
let cppNamespace = "PythonTest";
|
|
}
|
|
class TestOp<string mnemonic, list<OpTrait> traits = []>
|
|
: Op<Python_Test_Dialect, mnemonic, traits>;
|
|
|
|
def AttributedOp : TestOp<"attributed_op"> {
|
|
let arguments = (ins I32Attr:$mandatory_i32,
|
|
OptionalAttr<I32Attr>:$optional_i32,
|
|
UnitAttr:$unit);
|
|
}
|
|
|
|
#endif // PYTHON_TEST_OPS
|