|
13 | 13 | #ifndef TOSA_TYPES_BASE |
14 | 14 | #define TOSA_TYPES_BASE |
15 | 15 |
|
| 16 | +include "mlir/IR/AttrTypeBase.td" |
16 | 17 | include "mlir/IR/OpBase.td" |
17 | 18 |
|
| 19 | +include "mlir/Dialect/Tosa/IR/TosaOpBase.td" |
| 20 | + |
18 | 21 | //===----------------------------------------------------------------------===// |
19 | 22 | // Tosa Type Definitions. |
20 | 23 | //===----------------------------------------------------------------------===// |
@@ -218,4 +221,66 @@ def Tosa_Buffer : MemRefOf<[Tosa_AnyNumber]>; |
218 | 221 | def Tosa_TupleBuffer : NestedTupleOf<[Tosa_Buffer]>; |
219 | 222 | def Tosa_BufOrTuple : AnyTypeOf<[Tosa_Buffer, Tosa_TupleBuffer]>; |
220 | 223 |
|
| 224 | +//===----------------------------------------------------------------------===// |
| 225 | +// Tosa Type Definitions. |
| 226 | +//===----------------------------------------------------------------------===// |
| 227 | + |
| 228 | +// The base class for Tosa dialect types. |
| 229 | +class Tosa_Type<string name, string typeMnemonic, list<Trait> traits = []> |
| 230 | + : TypeDef<Tosa_Dialect, name, traits> { |
| 231 | + let mnemonic = typeMnemonic; |
| 232 | +} |
| 233 | + |
| 234 | +//===----------------------------------------------------------------------===// |
| 235 | +// ShapeType |
| 236 | +//===----------------------------------------------------------------------===// |
| 237 | +def Tosa_Shape : Tosa_Type<"shape", "shape"> { |
| 238 | + let summary = "Shape with static rank and Index element type"; |
| 239 | + let description = [{ |
| 240 | + Syntax: |
| 241 | + |
| 242 | + ``` shape - type :: = `shape` `<` rank `>` |
| 243 | + ``` Values with shape type represents a shape with a fixed rank and a list |
| 244 | + of dimensions |
| 245 | + .Rank must be zero or a positive integer |
| 246 | + .Each dimension is represented by the builtin |
| 247 | + Index type. |
| 248 | + |
| 249 | + Examples: |
| 250 | + |
| 251 | + ```mlir |
| 252 | + // Shape with rank of four, for example, [1, 1, 8, 16]: |
| 253 | + !tosa |
| 254 | + .shape<4> |
| 255 | + |
| 256 | + // Shape with rank of one, for example, [16]: |
| 257 | + !tosa |
| 258 | + .shape<1> |
| 259 | + |
| 260 | + // Shape with rank zero, for example, [] (i.e., shape of scalar values): |
| 261 | + !tosa.shape<0> |
| 262 | + ``` |
| 263 | + }]; |
| 264 | + let parameters = (ins "int" : $rank); |
| 265 | + let builders = [TypeBuilder<(ins "int" : $rank)>]; |
| 266 | + let assemblyFormat = "`<` $rank `>`"; |
| 267 | + |
| 268 | + let genVerifyDecl = 1; |
| 269 | +} |
| 270 | + |
| 271 | +def IsTosaShapeType : CPred<"mlir::tosa::isa_tosa_shape_type($_self)">; |
| 272 | + |
| 273 | +// Whether a Tosa Shape type has a rank equal to the specified rank. |
| 274 | +class IsTosaShapeOfRankPred<int rank> : And<[ |
| 275 | + IsTosaShapeType, |
| 276 | + CPred<[{::llvm::cast<::mlir::tosa::shapeType>($_self).getRank() == }] # rank> |
| 277 | +]>; |
| 278 | + |
| 279 | +class TosaShapeOfRank<int rank> |
| 280 | + : Type<IsTosaShapeOfRankPred<rank>, "Tosa shape type of rank " #rank>; |
| 281 | + |
| 282 | +def Rank1TosaShape : TosaShapeOfRank<1>; |
| 283 | +def Rank2TosaShape : TosaShapeOfRank<2>; |
| 284 | +def Rank4TosaShape : TosaShapeOfRank<4>; |
| 285 | + |
221 | 286 | #endif // TOSA_TYPES_BASE |
0 commit comments