1 | //===- Dialect.h - Dialect definition for the Toy IR ----------------------===// |
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 implements the IR Dialect for the Toy language. |
10 | // See docs/Tutorials/Toy/Ch-2.md for more information. |
11 | // |
12 | //===----------------------------------------------------------------------===// |
13 | |
14 | #ifndef MLIR_TUTORIAL_TOY_DIALECT_H_ |
15 | #define MLIR_TUTORIAL_TOY_DIALECT_H_ |
16 | |
17 | #include "mlir/Bytecode/BytecodeOpInterface.h" |
18 | #include "mlir/IR/BuiltinTypes.h" |
19 | #include "mlir/IR/Dialect.h" |
20 | #include "mlir/IR/SymbolTable.h" |
21 | #include "mlir/Interfaces/CallInterfaces.h" |
22 | #include "mlir/Interfaces/CastInterfaces.h" |
23 | #include "mlir/Interfaces/FunctionInterfaces.h" |
24 | #include "mlir/Interfaces/SideEffectInterfaces.h" |
25 | #include "toy/ShapeInferenceInterface.h" |
26 | |
27 | namespace mlir { |
28 | namespace toy { |
29 | namespace detail { |
30 | struct StructTypeStorage; |
31 | } // namespace detail |
32 | } // namespace toy |
33 | } // namespace mlir |
34 | |
35 | /// Include the auto-generated header file containing the declaration of the toy |
36 | /// dialect. |
37 | #include "toy/Dialect.h.inc" |
38 | |
39 | //===----------------------------------------------------------------------===// |
40 | // Toy Operations |
41 | //===----------------------------------------------------------------------===// |
42 | |
43 | /// Include the auto-generated header file containing the declarations of the |
44 | /// toy operations. |
45 | #define GET_OP_CLASSES |
46 | #include "toy/Ops.h.inc" |
47 | |
48 | namespace mlir { |
49 | namespace toy { |
50 | |
51 | //===----------------------------------------------------------------------===// |
52 | // Toy Types |
53 | //===----------------------------------------------------------------------===// |
54 | |
55 | /// This class defines the Toy struct type. It represents a collection of |
56 | /// element types. All derived types in MLIR must inherit from the CRTP class |
57 | /// 'Type::TypeBase'. It takes as template parameters the concrete type |
58 | /// (StructType), the base class to use (Type), and the storage class |
59 | /// (StructTypeStorage). |
60 | class StructType : public mlir::Type::TypeBase<StructType, mlir::Type, |
61 | detail::StructTypeStorage> { |
62 | public: |
63 | /// Inherit some necessary constructors from 'TypeBase'. |
64 | using Base::Base; |
65 | |
66 | /// Create an instance of a `StructType` with the given element types. There |
67 | /// *must* be atleast one element type. |
68 | static StructType get(llvm::ArrayRef<mlir::Type> elementTypes); |
69 | |
70 | /// Returns the element types of this struct type. |
71 | llvm::ArrayRef<mlir::Type> getElementTypes(); |
72 | |
73 | /// Returns the number of element type held by this struct. |
74 | size_t getNumElementTypes() { return getElementTypes().size(); } |
75 | |
76 | /// The name of this struct type. |
77 | static constexpr StringLiteral name = "toy.struct" ; |
78 | }; |
79 | } // namespace toy |
80 | } // namespace mlir |
81 | |
82 | #endif // MLIR_TUTORIAL_TOY_DIALECT_H_ |
83 | |