diff --git a/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td b/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td --- a/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td +++ b/mlir/include/mlir/Dialect/Tosa/IR/TosaOps.td @@ -6,7 +6,8 @@ // //===----------------------------------------------------------------------===// // -// This file defines the operation set for the TOSA dialect. +// This file defines the operation set for the TOSA dialect as defined in +// the TOSA specfication (https://developer.mlplatform.org/w/tosa/). // //===----------------------------------------------------------------------===// @@ -1517,30 +1518,6 @@ ); } -def Tosa_ApplyScaleOp: Tosa_Op<"apply_scale", [NoSideEffect] # ElementwiseMappable.traits> { - let summary = "Rescale scalar operator for Tosa tensor operators"; - - let description = [{ - Applies rescaling for fixed point values. This behavior is replicated in - multiple quantized operations (mul, convolution, rescale, matmul, pooling). - - The commonplace implementation is to use i64 operations to avoid integer - overflow with target specific implementations can use native operations to - avoid wider than necessary types. - }]; - - let arguments = (ins - Tosa_Int32Like:$value, - Tosa_Int32Like:$multiplier, - Tosa_Int8Like:$shift, - BoolAttr:$double_round - ); - - let results = (outs - Tosa_Int32:$output - ); -} - //===----------------------------------------------------------------------===// // TOSA Spec Section 2.13 // Operator Class: Data Node Ops. @@ -1727,23 +1704,6 @@ ); } -//===----------------------------------------------------------------------===// -// Operator: yield -//===----------------------------------------------------------------------===// -def Tosa_YieldOp : Tosa_Op<"yield", [ - Terminator, - NoSideEffect]> { - let summary = "yield operator"; - - let description = [{ - return operation within the conditional and body of - structured control flow. Operation takes variadic operands - but produces no results of its own. - }]; - - let arguments = (ins - Variadic:$inputs - ); -} +include "mlir/Dialect/Tosa/IR/TosaUtilOps.td" #endif // TOSA_OPS diff --git a/mlir/include/mlir/Dialect/Tosa/IR/TosaUtilOps.td b/mlir/include/mlir/Dialect/Tosa/IR/TosaUtilOps.td new file mode 100644 --- /dev/null +++ b/mlir/include/mlir/Dialect/Tosa/IR/TosaUtilOps.td @@ -0,0 +1,70 @@ +//===-- TosaUtilOps.td - TOSA dialect utility operations ---*- 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 file defines codegen utility operators for the TOSA dialect. +// These operators are not part of the formal TOSA specification and +// are intended to aid code generation from TOSA. +// +//===----------------------------------------------------------------------===// + +#ifndef TOSA_UTIL_OPS +#define TOSA_UTIL_OPS + +include "mlir/IR/OpBase.td" + +include "mlir/Interfaces/SideEffectInterfaces.td" +include "mlir/Interfaces/LoopLikeInterface.td" +include "mlir/Dialect/Tosa/IR/TosaInterfaces.td" + +include "mlir/Dialect/Tosa/IR/TosaTypesBase.td" +include "mlir/Dialect/Tosa/IR/TosaOpBase.td" + +def Tosa_ApplyScaleOp: Tosa_Op<"apply_scale", [NoSideEffect] # ElementwiseMappable.traits> { + let summary = "Rescale scalar operator for Tosa tensor operators"; + + let description = [{ + Applies rescaling for fixed point values. This behavior is replicated in + multiple quantized operations (mul, convolution, rescale, matmul, pooling). + + The commonplace implementation is to use i64 operations to avoid integer + overflow with target specific implementations can use native operations to + avoid wider than necessary types. + }]; + + let arguments = (ins + Tosa_Int32Like:$value, + Tosa_Int32Like:$multiplier, + Tosa_Int8Like:$shift, + BoolAttr:$double_round + ); + + let results = (outs + Tosa_Int32:$output + ); +} + +//===----------------------------------------------------------------------===// +// Operator: yield +//===----------------------------------------------------------------------===// +def Tosa_YieldOp : Tosa_Op<"yield", [ + Terminator, + NoSideEffect]> { + let summary = "yield operator"; + + let description = [{ + return operation within the conditional and body of + structured control flow. Operation takes variadic operands + but produces no results of its own. + }]; + + let arguments = (ins + Variadic:$inputs + ); +} + +#endif // TOSA_UTIL_OPS