MLIR 22.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"
19
20namespace llvm {
21class DefInit;
22class Record;
23} // namespace llvm
24
25namespace mlir {
26namespace tblgen {
27
28// Wrapper class with helper methods for accessing Type constraints defined in
29// TableGen.
30class TypeConstraint : public Constraint {
31public:
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.
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.
64class Type : public TypeConstraint {
65public:
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_
Constraint(const llvm::Record *record, Kind kind)
Definition Constraint.h:43
TypeConstraint(const llvm::DefInit *record)
Definition Type.cpp:22
StringRef getVariadicOfVariadicSegmentSizeAttr() const
Definition Type.cpp:37
bool isVariadic() const
Definition Type.cpp:29
StringRef getCppType() const
Definition Type.cpp:63
bool isOptional() const
Definition Type.cpp:25
bool isVariableLength() const
Definition Type.h:53
static bool classof(const Constraint *c)
Definition Type.h:36
Constraint(const llvm::Record *record, Kind kind)
Definition Constraint.h:43
std::optional< StringRef > getBuilderCall() const
Definition Type.cpp:44
bool isVariadicOfVariadic() const
Definition Type.cpp:33
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.