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"
17#include "mlir/TableGen/Constraint.h"
18#include "mlir/TableGen/Dialect.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:
32 using Constraint::Constraint;
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++ class name for this type (which may just be ::mlir::Type).
60 std::string getCPPClassName() 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.
69 Dialect getDialect() const;
70};
71
72} // namespace tblgen
73} // namespace mlir
74
75#endif // MLIR_TABLEGEN_TYPE_H_
76

source code of mlir/include/mlir/TableGen/Type.h