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