MLIR 23.0.0git
TosaOps.h
Go to the documentation of this file.
1//===-- TosaOps.h - TOSA dialect operation definitions ----------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file declares the TOSA Dialect in MLIR.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef MLIR_DIALECT_TOSA_IR_TOSAOPS_H
14#define MLIR_DIALECT_TOSA_IR_TOSAOPS_H
15
18#include "mlir/Dialect/Traits.h"
19#include "mlir/IR/Matchers.h"
27
28//===----------------------------------------------------------------------===//
29// TOSA dialect and structs includes.
30//===----------------------------------------------------------------------===//
31
32#include "mlir/Dialect/Tosa/IR/TosaEnums.h.inc"
33#include "mlir/Dialect/Tosa/IR/TosaOpsDialect.h.inc"
35
36//===----------------------------------------------------------------------===//
37// TOSA operation validation includes.
38//===----------------------------------------------------------------------===//
39
40#include "mlir/Dialect/Tosa/IR/TosaAvailability.h.inc"
41
42namespace mlir {
43class PatternRewriter;
44
45namespace tosa {
46
47ParseResult parseVariableOpTypeOrInitialValue(OpAsmParser &parser,
48 DenseElementsAttr &varShapeAttr,
49 TypeAttr &typeAttr,
50 Attribute &initialValueAttr);
51void printVariableOpTypeOrInitialValue(OpAsmPrinter &p, Operation *op,
52 DenseElementsAttr varShapeAttr,
53 TypeAttr typeAttr,
54 Attribute initialValueAttr);
55
56#include "mlir/Dialect/Tosa/IR/TosaInterfaces.h.inc"
57
58} // namespace tosa
59
60namespace OpTrait {
61namespace tosa {
62
63/// This class indicates that an op is tosa-elementwise (permits broadcasting,
64/// unlike Elementwise trait).
65template <typename ConcreteType>
67 : public TraitBase<ConcreteType, TosaElementwiseOperator> {};
68
70/// This class verifies that tosa shape operands are compile time resolvable
71template <typename ConcreteType>
73 : public TraitBase<ConcreteType, TosaResolvableShapeOperands> {
74public:
75 static LogicalResult verifyTrait(Operation *op) {
77 }
78};
79
80/// This class indicates that op operates on tosa shape types
81template <typename ConcreteType>
82class TosaShapeOperator : public TraitBase<ConcreteType, TosaShapeOperator> {};
83
85/// This class indicates that op operates on tosa shape types
86template <typename ConcreteType>
88 : public TraitBase<ConcreteType, TosaShapeOperatorWithSameRanks> {
89public:
90 static LogicalResult verifyTrait(Operation *op) {
92 }
93};
94
95} // namespace tosa
96} // namespace OpTrait
97
98namespace tosa {
99
101
102/// Represents a dimension in the shape of a tensor that can be inferred
103/// based on the other provided dimensions. For example, in a reshape
104/// operation, -1 can be used to indicate a size that is the remainder
105/// of the other dimensions.
107
108} // namespace tosa
109
110} // namespace mlir
111
112#define GET_ATTRDEF_CLASSES
113#include "mlir/Dialect/Tosa/IR/TosaAttributes.h.inc"
114
115#define GET_TYPEDEF_CLASSES
116#include "mlir/Dialect/Tosa/IR/TosaOpsTypesBase.h.inc"
117
118#define GET_OP_CLASSES
119#include "mlir/Dialect/Tosa/IR/TosaOps.h.inc"
120
121namespace mlir {
122namespace tosa {
123
124// Create a rank-1 const tensor for zero point of the source tensor.
125std::optional<Value> createZeroPointTensor(OpBuilder &builder, Location loc,
126 Type srcElemType, int64_t zp = 0);
127
128// Create a pad-const const tensor with value of `val` of required data-type
129Value createPadConstTensor(OpBuilder &builder, Location loc, Value src,
130 int32_t val = 0);
131
132// returns type of variable op
133RankedTensorType getVariableType(VariableOp variableOp);
134
135// Returns the bitwidth of a TOSA tensor element type
136unsigned getBitWidth(Type type);
137
138} // namespace tosa
139} // namespace mlir
140
141#endif // MLIR_DIALECT_TOSA_IR_TOSAOPS_H
Helper class for implementing traits.
This class indicates that an op is tosa-elementwise (permits broadcasting, unlike Elementwise trait).
Definition TosaOps.h:67
This class verifies that tosa shape operands are compile time resolvable.
Definition TosaOps.h:73
static LogicalResult verifyTrait(Operation *op)
Definition TosaOps.h:75
This class indicates that op operates on tosa shape types.
Definition TosaOps.h:88
static LogicalResult verifyTrait(Operation *op)
Definition TosaOps.h:90
This class indicates that op operates on tosa shape types.
Definition TosaOps.h:82
Operation is the basic unit of execution within MLIR.
Definition Operation.h:87
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
LogicalResult verifyTosaShapeOperatorWithSameRanks(Operation *op)
Definition TosaOps.cpp:5604
LogicalResult verifyTosaResolvableShapeOperands(Operation *op)
Definition TosaOps.cpp:5591
RankedTensorType getVariableType(VariableOp variableOp)
ParseResult parseVariableOpTypeOrInitialValue(OpAsmParser &parser, DenseElementsAttr &varShapeAttr, TypeAttr &typeAttr, Attribute &initialValueAttr)
Definition TosaOps.cpp:228
constexpr int64_t kInferableDimSize
Represents a dimension in the shape of a tensor that can be inferred based on the other provided dime...
Definition TosaOps.h:106
void printVariableOpTypeOrInitialValue(OpAsmPrinter &p, Operation *op, DenseElementsAttr varShapeAttr, TypeAttr typeAttr, Attribute initialValueAttr)
Definition TosaOps.cpp:253
unsigned getBitWidth(Type type)
Definition TosaOps.cpp:630
std::optional< Value > createZeroPointTensor(OpBuilder &builder, Location loc, Type srcElemType, int64_t zp=0)
Definition TosaOps.cpp:5555
bool isa_tosa_shape_type(mlir::Type t)
Definition TosaOps.cpp:5579
Value createPadConstTensor(OpBuilder &builder, Location loc, Value src, int32_t val=0)
Definition TosaOps.cpp:615
Include the generated interface declarations.