[Mlir-commits] [mlir] [mlir][tosa] Move variable op definitions to `TosaOps.td` (NFC) (PR #165260)
Luke Hutton
llvmlistbot at llvm.org
Mon Oct 27 07:53:59 PDT 2025
https://github.com/lhutton1 created https://github.com/llvm/llvm-project/pull/165260
Variable ops (VARIABLE/VARIABLE_READ/VARIABLE_WRITE) are part of the TOSA specification and should therefore be defined in `TosaOps.td`.
>From 38af4cde2a69541cb3ce1a1c3f0f03b861a354bf Mon Sep 17 00:00:00 2001
From: Luke Hutton <luke.hutton at arm.com>
Date: Mon, 27 Oct 2025 14:50:04 +0000
Subject: [PATCH] [mlir][tosa] Move variable op definitions to `TosaOps.td`
(NFC)
Variable ops (VARIABLE/VARIABLE_READ/VARIABLE_WRITE) are part
of the TOSA specification and should therefore be defined in
`TosaOps.td`.
Change-Id: I4c675da45ece85063e76bf71c74953b3372fb82a
---
mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td | 101 ++++++++++++++++++
.../mlir/Dialect/Tosa/IR/TosaUtilOps.td | 101 ------------------
2 files changed, 101 insertions(+), 101 deletions(-)
diff --git a/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td b/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td
index 6f07247b478c8..ae20051685f8e 100644
--- a/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td
+++ b/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td
@@ -19,6 +19,7 @@ include "mlir/IR/OpBase.td"
include "mlir/Interfaces/SideEffectInterfaces.td"
include "mlir/Interfaces/InferTypeOpInterface.td"
include "mlir/Interfaces/LoopLikeInterface.td"
+include "mlir/IR/SymbolInterfaces.td"
include "mlir/Dialect/Tosa/IR/TosaInterfaces.td"
include "mlir/Dialect/Tosa/IR/TosaTypesBase.td"
@@ -2751,6 +2752,106 @@ def Tosa_WhileOp : Tosa_Op<"while_loop", [
let hasVerifier = 1;
}
+//===----------------------------------------------------------------------===//
+// Operator: variable
+//===----------------------------------------------------------------------===//
+def Tosa_VariableOp : Tosa_Op<"variable", [Symbol]> {
+ let summary = "Defines a variable";
+
+ let description = [{
+ Defines a new TOSA variable. This is a persistent mutable value across multiple
+ TOSA graph invocations. Modifications are expressed using read/write semantics.
+ }];
+
+ let arguments = (ins
+ // Note: "sym_name" is used as opposed to "name" in the specification,
+ // since a Symbol must be named "sym_name" for it to be recognised by
+ // the containing SymbolTable.
+ SymbolNameAttr:$sym_name,
+ IndexElementsAttr:$var_shape,
+ TypeAttr:$type,
+ OptionalAttr<AnyAttr>:$initial_value
+ );
+
+ list<Availability> availability = [
+ Profile<[Tosa_PRO_INT, Tosa_PRO_FP]>,
+ Extension<[Tosa_EXT_VARIABLE]>,
+ ];
+
+ let hasCustomAssemblyFormat = 1;
+
+ let assemblyFormat = [{
+ $sym_name
+ attr-dict
+ custom<VariableOpTypeOrInitialValue>($var_shape, $type, $initial_value)
+ }];
+
+ let builders = [Tosa_VariableOpBuilder];
+
+ let extraClassDeclaration = [{
+ ::llvm::StringRef getName() {
+ return getSymName();
+ }
+ }];
+}
+
+//===----------------------------------------------------------------------===//
+// Operator: variable_write
+//===----------------------------------------------------------------------===//
+def Tosa_VariableWriteOp : Tosa_Op<"variable_write", []> {
+ let summary = "write_buffer operator";
+
+ let description = [{
+ Assigns a value to the pseudo-buffer resource holding a persistent mutable tensor.
+ }];
+
+ let arguments = (ins
+ SymbolNameAttr:$name,
+ Tosa_Tensor:$input1
+ );
+
+ list<Availability> availability = [
+ Profile<[Tosa_PRO_INT, Tosa_PRO_FP]>,
+ Extension<[Tosa_EXT_VARIABLE]>,
+ ];
+
+ let assemblyFormat = [{
+ $name attr-dict `,` $input1 `:` type($input1)
+ }];
+
+ let hasVerifier = 1;
+}
+
+//===----------------------------------------------------------------------===//
+// Operator: variable_read
+//===----------------------------------------------------------------------===//
+def Tosa_VariableReadOp : Tosa_Op<"variable_read", []> {
+ let summary = "read_buffer operator";
+
+ let description = [{
+ Reads the value from a pseudo-buffer resource holding a persistent mutable tensor.
+ }];
+
+ let arguments = (ins
+ SymbolNameAttr:$name
+ );
+
+ let results = (outs
+ Tosa_Tensor:$output1
+ );
+
+ list<Availability> availability = [
+ Profile<[Tosa_PRO_INT, Tosa_PRO_FP]>,
+ Extension<[Tosa_EXT_VARIABLE]>,
+ ];
+
+ let assemblyFormat = [{
+ $name attr-dict `:` type($output1)
+ }];
+
+ let hasVerifier = 1;
+}
+
include "mlir/Dialect/Tosa/IR/TosaUtilOps.td"
include "mlir/Dialect/Tosa/IR/TosaShapeOps.td"
diff --git a/mlir/include/mlir/Dialect/Tosa/IR/TosaUtilOps.td b/mlir/include/mlir/Dialect/Tosa/IR/TosaUtilOps.td
index f1a618e75061b..4c71089c50fba 100644
--- a/mlir/include/mlir/Dialect/Tosa/IR/TosaUtilOps.td
+++ b/mlir/include/mlir/Dialect/Tosa/IR/TosaUtilOps.td
@@ -18,7 +18,6 @@
include "mlir/IR/OpBase.td"
include "mlir/Interfaces/SideEffectInterfaces.td"
-include "mlir/IR/SymbolInterfaces.td"
include "mlir/Interfaces/LoopLikeInterface.td"
include "mlir/Interfaces/VectorInterfaces.td"
include "mlir/Dialect/Tosa/IR/TosaInterfaces.td"
@@ -80,104 +79,4 @@ def Tosa_YieldOp : Tosa_Op<"yield", [
let assemblyFormat = "$inputs attr-dict `:` type($inputs)";
}
-//===----------------------------------------------------------------------===//
-// Operator: variable
-//===----------------------------------------------------------------------===//
-def Tosa_VariableOp : Tosa_Op<"variable", [Symbol]> {
- let summary = "Defines a variable";
-
- let description = [{
- Defines a new TOSA variable. This is a persistent mutable value across multiple
- TOSA graph invocations. Modifications are expressed using read/write semantics.
- }];
-
- let arguments = (ins
- // Note: "sym_name" is used as opposed to "name" in the specification,
- // since a Symbol must be named "sym_name" for it to be recognised by
- // the containing SymbolTable.
- SymbolNameAttr:$sym_name,
- IndexElementsAttr:$var_shape,
- TypeAttr:$type,
- OptionalAttr<AnyAttr>:$initial_value
- );
-
- list<Availability> availability = [
- Profile<[Tosa_PRO_INT, Tosa_PRO_FP]>,
- Extension<[Tosa_EXT_VARIABLE]>,
- ];
-
- let hasCustomAssemblyFormat = 1;
-
- let assemblyFormat = [{
- $sym_name
- attr-dict
- custom<VariableOpTypeOrInitialValue>($var_shape, $type, $initial_value)
- }];
-
- let builders = [Tosa_VariableOpBuilder];
-
- let extraClassDeclaration = [{
- ::llvm::StringRef getName() {
- return getSymName();
- }
- }];
-}
-
-//===----------------------------------------------------------------------===//
-// Operator: variable_write
-//===----------------------------------------------------------------------===//
-def Tosa_VariableWriteOp : Tosa_Op<"variable_write", []> {
- let summary = "write_buffer operator";
-
- let description = [{
- Assigns a value to the pseudo-buffer resource holding a persistent mutable tensor.
- }];
-
- let arguments = (ins
- SymbolNameAttr:$name,
- Tosa_Tensor:$input1
- );
-
- list<Availability> availability = [
- Profile<[Tosa_PRO_INT, Tosa_PRO_FP]>,
- Extension<[Tosa_EXT_VARIABLE]>,
- ];
-
- let assemblyFormat = [{
- $name attr-dict `,` $input1 `:` type($input1)
- }];
-
- let hasVerifier = 1;
-}
-
-//===----------------------------------------------------------------------===//
-// Operator: variable_read
-//===----------------------------------------------------------------------===//
-def Tosa_VariableReadOp : Tosa_Op<"variable_read", []> {
- let summary = "read_buffer operator";
-
- let description = [{
- Reads the value from a pseudo-buffer resource holding a persistent mutable tensor.
- }];
-
- let arguments = (ins
- SymbolNameAttr:$name
- );
-
- let results = (outs
- Tosa_Tensor:$output1
- );
-
- list<Availability> availability = [
- Profile<[Tosa_PRO_INT, Tosa_PRO_FP]>,
- Extension<[Tosa_EXT_VARIABLE]>,
- ];
-
- let assemblyFormat = [{
- $name attr-dict `:` type($output1)
- }];
-
- let hasVerifier = 1;
-}
-
#endif // TOSA_UTIL_OPS
More information about the Mlir-commits
mailing list