Skip to content

Conversation

@lhutton1
Copy link
Contributor

Variable ops (VARIABLE/VARIABLE_READ/VARIABLE_WRITE) are part of the TOSA specification and should therefore be defined in TosaOps.td.

Variable ops (VARIABLE/VARIABLE_READ/VARIABLE_WRITE) are part
of the TOSA specification and should therefore be defined in
`TosaOps.td`.

Change-Id: I4c675da45ece85063e76bf71c74953b3372fb82a
@llvmbot
Copy link
Member

llvmbot commented Oct 27, 2025

@llvm/pr-subscribers-mlir-tosa

Author: Luke Hutton (lhutton1)

Changes

Variable ops (VARIABLE/VARIABLE_READ/VARIABLE_WRITE) are part of the TOSA specification and should therefore be defined in TosaOps.td.


Full diff: https://github.com/llvm/llvm-project/pull/165260.diff

2 Files Affected:

  • (modified) mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td (+101)
  • (modified) mlir/include/mlir/Dialect/Tosa/IR/TosaUtilOps.td (-101)
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

@llvmbot
Copy link
Member

llvmbot commented Oct 27, 2025

@llvm/pr-subscribers-mlir

Author: Luke Hutton (lhutton1)

Changes

Variable ops (VARIABLE/VARIABLE_READ/VARIABLE_WRITE) are part of the TOSA specification and should therefore be defined in TosaOps.td.


Full diff: https://github.com/llvm/llvm-project/pull/165260.diff

2 Files Affected:

  • (modified) mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td (+101)
  • (modified) mlir/include/mlir/Dialect/Tosa/IR/TosaUtilOps.td (-101)
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

Copy link
Contributor

@psunn psunn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable to me, seems no functional change.

@lhutton1 lhutton1 merged commit 7b48e24 into llvm:main Oct 28, 2025
13 checks passed
@lhutton1 lhutton1 deleted the move-variable-decs branch October 28, 2025 09:16
Lukacma pushed a commit to Lukacma/llvm-project that referenced this pull request Oct 29, 2025
…#165260)

Variable ops (VARIABLE/VARIABLE_READ/VARIABLE_WRITE) are part of the
TOSA specification and should therefore be defined in `TosaOps.td`.
aokblast pushed a commit to aokblast/llvm-project that referenced this pull request Oct 30, 2025
…#165260)

Variable ops (VARIABLE/VARIABLE_READ/VARIABLE_WRITE) are part of the
TOSA specification and should therefore be defined in `TosaOps.td`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants