@@ -19,6 +19,7 @@ include "mlir/IR/OpBase.td"
1919include "mlir/Interfaces/SideEffectInterfaces.td"
2020include "mlir/Interfaces/InferTypeOpInterface.td"
2121include "mlir/Interfaces/LoopLikeInterface.td"
22+ include "mlir/IR/SymbolInterfaces.td"
2223include "mlir/Dialect/Tosa/IR/TosaInterfaces.td"
2324
2425include "mlir/Dialect/Tosa/IR/TosaTypesBase.td"
@@ -2814,6 +2815,106 @@ def Tosa_WhileOp : Tosa_Op<"while_loop", [
28142815 let hasVerifier = 1;
28152816}
28162817
2818+ //===----------------------------------------------------------------------===//
2819+ // Operator: variable
2820+ //===----------------------------------------------------------------------===//
2821+ def Tosa_VariableOp : Tosa_Op<"variable", [Symbol]> {
2822+ let summary = "Defines a variable";
2823+
2824+ let description = [{
2825+ Defines a new TOSA variable. This is a persistent mutable value across multiple
2826+ TOSA graph invocations. Modifications are expressed using read/write semantics.
2827+ }];
2828+
2829+ let arguments = (ins
2830+ // Note: "sym_name" is used as opposed to "name" in the specification,
2831+ // since a Symbol must be named "sym_name" for it to be recognised by
2832+ // the containing SymbolTable.
2833+ SymbolNameAttr:$sym_name,
2834+ IndexElementsAttr:$var_shape,
2835+ TypeAttr:$type,
2836+ OptionalAttr<AnyAttr>:$initial_value
2837+ );
2838+
2839+ list<Availability> availability = [
2840+ Profile<[Tosa_PRO_INT, Tosa_PRO_FP]>,
2841+ Extension<[Tosa_EXT_VARIABLE]>,
2842+ ];
2843+
2844+ let hasCustomAssemblyFormat = 1;
2845+
2846+ let assemblyFormat = [{
2847+ $sym_name
2848+ attr-dict
2849+ custom<VariableOpTypeOrInitialValue>($var_shape, $type, $initial_value)
2850+ }];
2851+
2852+ let builders = [Tosa_VariableOpBuilder];
2853+
2854+ let extraClassDeclaration = [{
2855+ ::llvm::StringRef getName() {
2856+ return getSymName();
2857+ }
2858+ }];
2859+ }
2860+
2861+ //===----------------------------------------------------------------------===//
2862+ // Operator: variable_write
2863+ //===----------------------------------------------------------------------===//
2864+ def Tosa_VariableWriteOp : Tosa_Op<"variable_write", []> {
2865+ let summary = "write_buffer operator";
2866+
2867+ let description = [{
2868+ Assigns a value to the pseudo-buffer resource holding a persistent mutable tensor.
2869+ }];
2870+
2871+ let arguments = (ins
2872+ SymbolNameAttr:$name,
2873+ Tosa_Tensor:$input1
2874+ );
2875+
2876+ list<Availability> availability = [
2877+ Profile<[Tosa_PRO_INT, Tosa_PRO_FP]>,
2878+ Extension<[Tosa_EXT_VARIABLE]>,
2879+ ];
2880+
2881+ let assemblyFormat = [{
2882+ $name attr-dict `,` $input1 `:` type($input1)
2883+ }];
2884+
2885+ let hasVerifier = 1;
2886+ }
2887+
2888+ //===----------------------------------------------------------------------===//
2889+ // Operator: variable_read
2890+ //===----------------------------------------------------------------------===//
2891+ def Tosa_VariableReadOp : Tosa_Op<"variable_read", []> {
2892+ let summary = "read_buffer operator";
2893+
2894+ let description = [{
2895+ Reads the value from a pseudo-buffer resource holding a persistent mutable tensor.
2896+ }];
2897+
2898+ let arguments = (ins
2899+ SymbolNameAttr:$name
2900+ );
2901+
2902+ let results = (outs
2903+ Tosa_Tensor:$output1
2904+ );
2905+
2906+ list<Availability> availability = [
2907+ Profile<[Tosa_PRO_INT, Tosa_PRO_FP]>,
2908+ Extension<[Tosa_EXT_VARIABLE]>,
2909+ ];
2910+
2911+ let assemblyFormat = [{
2912+ $name attr-dict `:` type($output1)
2913+ }];
2914+
2915+ let hasVerifier = 1;
2916+ }
2917+
28172918include "mlir/Dialect/Tosa/IR/TosaUtilOps.td"
28182919
28192920include "mlir/Dialect/Tosa/IR/TosaShapeOps.td"
0 commit comments