MLIR  20.0.0git
Type.h
Go to the documentation of this file.
1 //===- Type.h - Type class --------------------------------------*- 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 // Type wrapper to simplify using TableGen Record defining a MLIR Type.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef MLIR_TABLEGEN_TYPE_H_
14 #define MLIR_TABLEGEN_TYPE_H_
15 
16 #include "mlir/Support/LLVM.h"
18 #include "mlir/TableGen/Dialect.h"
19 
20 namespace llvm {
21 class DefInit;
22 class Record;
23 } // namespace llvm
24 
25 namespace mlir {
26 namespace tblgen {
27 
28 // Wrapper class with helper methods for accessing Type constraints defined in
29 // TableGen.
30 class TypeConstraint : public Constraint {
31 public:
33 
34  TypeConstraint(const llvm::DefInit *record);
35 
36  static bool classof(const Constraint *c) { return c->getKind() == CK_Type; }
37 
38  // Returns true if this is an optional type constraint.
39  bool isOptional() const;
40 
41  // Returns true if this is a variadic type constraint.
42  bool isVariadic() const;
43 
44  // Returns true if this is a nested variadic type constraint.
45  bool isVariadicOfVariadic() const;
46 
47  // Return the segment size attribute used if this is a variadic of variadic
48  // constraint. Asserts isVariadicOfVariadic() is true.
49  StringRef getVariadicOfVariadicSegmentSizeAttr() const;
50 
51  // Returns true if this is a variable length type constraint. This is either
52  // variadic or optional.
53  bool isVariableLength() const { return isOptional() || isVariadic(); }
54 
55  // Returns the builder call for this constraint if this is a buildable type,
56  // returns std::nullopt otherwise.
57  std::optional<StringRef> getBuilderCall() const;
58 
59  // Return the C++ type for this type (which may just be ::mlir::Type).
60  StringRef getCppType() const;
61 };
62 
63 // Wrapper class with helper methods for accessing Types defined in TableGen.
64 class Type : public TypeConstraint {
65 public:
66  explicit Type(const llvm::Record *record);
67 
68  // Returns the dialect for the type if defined.
70 };
71 
72 } // namespace tblgen
73 } // namespace mlir
74 
75 #endif // MLIR_TABLEGEN_TYPE_H_
Kind getKind() const
Definition: Constraint.h:76
Constraint(const llvm::Record *record, Kind kind)
Definition: Constraint.h:36
TypeConstraint(const llvm::DefInit *record)
Definition: Type.cpp:23
StringRef getVariadicOfVariadicSegmentSizeAttr() const
Definition: Type.cpp:38
bool isVariadic() const
Definition: Type.cpp:30
StringRef getCppType() const
Definition: Type.cpp:64
bool isOptional() const
Definition: Type.cpp:26
bool isVariableLength() const
Definition: Type.h:53
static bool classof(const Constraint *c)
Definition: Type.h:36
std::optional< StringRef > getBuilderCall() const
Definition: Type.cpp:45
bool isVariadicOfVariadic() const
Definition: Type.cpp:34
Dialect getDialect() const
Type(const llvm::Record *record)
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Definition: CallGraph.h:229
Include the generated interface declarations.