MLIR 24.0.0git
Dialect.h
Go to the documentation of this file.
1//===- Dialect.h - Dialect 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// Dialect wrapper to simplify using TableGen Record defining a MLIR dialect.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef MLIR_TABLEGEN_DIALECT_H_
14#define MLIR_TABLEGEN_DIALECT_H_
15
16#include "mlir/Support/LLVM.h"
17#include "llvm/TableGen/Record.h"
18
19#include <string>
20#include <vector>
21
22namespace llvm {
23class Record;
24} // namespace llvm
25
26namespace mlir {
27namespace tblgen {
28// Wrapper class that contains a MLIR dialect's information defined in TableGen
29// and provides helper methods for accessing them.
30class Dialect {
31public:
32 explicit Dialect(const llvm::Record *def);
33
34 // Returns the name of this dialect.
35 StringRef getName() const;
36
37 // Returns the C++ namespaces that ops of this dialect should be placed into.
38 StringRef getCppNamespace() const;
39
40 // Returns this dialect's C++ class name.
41 std::string getCppClassName() const;
42
43 // Returns the summary description of the dialect. Returns empty string if
44 // none.
45 StringRef getSummary() const;
46
47 // Returns the description of the dialect. Returns empty string if none.
48 StringRef getDescription() const;
49
50 // Returns the list of dialect (class names) that this dialect depends on.
51 // These are dialects that will be loaded on construction of this dialect.
53
54 // Returns the dialects extra class declaration code.
55 std::optional<StringRef> getExtraClassDeclaration() const;
56
57 /// Returns true if this dialect uses strict properties in declarative
58 /// assembly formats.
60
61 /// Returns true if this dialect has a canonicalizer.
62 bool hasCanonicalizer() const;
63
64 /// Returns true if this dialect has a constant materializer.
65 bool hasConstantMaterializer() const;
66
67 /// Returns true if the destructor definition is provided explicitly or
68 /// false if a default should be generated.
69 bool hasNonDefaultDestructor() const;
70
71 /// Returns true if this dialect has an operation attribute verifier.
72 bool hasOperationAttrVerify() const;
73
74 /// Returns true if this dialect has a region argument attribute verifier.
75 bool hasRegionArgAttrVerify() const;
76
77 /// Returns true if this dialect has a region result attribute verifier.
78 bool hasRegionResultAttrVerify() const;
79
80 /// Returns true if this dialect has fallback interfaces for its operations.
82
83 /// Returns true if this dialect has an `initialize` method that the generated
84 /// dialect constructor calls.
85 bool hasInitializer() const;
86
87 /// Returns true if the generated dialect constructor should register the
88 /// attributes of this dialect defined in ODS.
90
91 /// Returns true if the generated dialect constructor should register the
92 /// types of this dialect defined in ODS.
93 bool useDefaultTypeRegistration() const;
94
95 /// Returns true if the generated dialect constructor should register the
96 /// operations of this dialect defined in ODS.
98
99 /// Returns true if this dialect should generate the default dispatch for
100 /// attribute printing/parsing.
102
103 /// Returns true if this dialect should generate the default dispatch for
104 /// type printing/parsing.
105 bool useDefaultTypePrinterParser() const;
106
107 /// Returns true if this dialect can be extended at runtime with new
108 /// operations or types.
109 bool isExtensible() const;
110
111 const llvm::DagInit *getDiscardableAttributes() const;
112
113 const llvm::Record *getDef() const { return def; }
114
115 // Returns whether two dialects are equal by checking the equality of the
116 // underlying record.
117 bool operator==(const Dialect &other) const;
118
119 bool operator!=(const Dialect &other) const { return !(*this == other); }
120
121 // Compares two dialects by comparing the names of the dialects.
122 bool operator<(const Dialect &other) const;
123
124 // Returns whether the dialect is defined.
125 explicit operator bool() const { return def != nullptr; }
126 bool isDefined() const { return def != nullptr; }
127
128private:
129 const llvm::Record *def;
130 std::vector<StringRef> dependentDialects;
131};
132} // namespace tblgen
133} // namespace mlir
134
135#endif // MLIR_TABLEGEN_DIALECT_H_
bool useDefaultOperationRegistration() const
Returns true if the generated dialect constructor should register the operations of this dialect defi...
Definition Dialect.cpp:109
StringRef getDescription() const
Definition Dialect.cpp:52
const llvm::Record * getDef() const
Definition Dialect.h:113
bool useDefaultTypeRegistration() const
Returns true if the generated dialect constructor should register the types of this dialect defined i...
Definition Dialect.cpp:105
Dialect(const llvm::Record *def)
Definition Dialect.cpp:19
StringRef getSummary() const
Definition Dialect.cpp:48
std::optional< StringRef > getExtraClassDeclaration() const
Definition Dialect.cpp:60
ArrayRef< StringRef > getDependentDialects() const
Definition Dialect.cpp:56
bool useDefaultAttributeRegistration() const
Returns true if the generated dialect constructor should register the attributes of this dialect defi...
Definition Dialect.cpp:101
const llvm::DagInit * getDiscardableAttributes() const
Definition Dialect.cpp:125
bool hasRegionArgAttrVerify() const
Returns true if this dialect has a region argument attribute verifier.
Definition Dialect.cpp:85
bool hasNonDefaultDestructor() const
Returns true if the destructor definition is provided explicitly or false if a default should be gene...
Definition Dialect.cpp:77
StringRef getCppNamespace() const
Definition Dialect.cpp:28
bool useDefaultAttributePrinterParser() const
Returns true if this dialect should generate the default dispatch for attribute printing/parsing.
Definition Dialect.cpp:113
bool isExtensible() const
Returns true if this dialect can be extended at runtime with new operations or types.
Definition Dialect.cpp:121
StringRef getName() const
bool hasOperationInterfaceFallback() const
Returns true if this dialect has fallback interfaces for its operations.
Definition Dialect.cpp:93
bool hasInitializer() const
Returns true if this dialect has an initialize method that the generated dialect constructor calls.
Definition Dialect.cpp:97
bool hasCanonicalizer() const
Returns true if this dialect has a canonicalizer.
Definition Dialect.cpp:69
bool operator<(const Dialect &other) const
Definition Dialect.cpp:133
bool hasConstantMaterializer() const
Returns true if this dialect has a constant materializer.
Definition Dialect.cpp:73
std::string getCppClassName() const
Definition Dialect.cpp:32
bool hasRegionResultAttrVerify() const
Returns true if this dialect has a region result attribute verifier.
Definition Dialect.cpp:89
bool useDefaultTypePrinterParser() const
Returns true if this dialect should generate the default dispatch for type printing/parsing.
Definition Dialect.cpp:117
bool hasOperationAttrVerify() const
Returns true if this dialect has an operation attribute verifier.
Definition Dialect.cpp:81
bool isDefined() const
Definition Dialect.h:126
bool operator==(const Dialect &other) const
Definition Dialect.cpp:129
bool operator!=(const Dialect &other) const
Definition Dialect.h:119
bool useStrictPropertiesInAssemblyFormat() const
Returns true if this dialect uses strict properties in declarative assembly formats.
Definition Dialect.cpp:65
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Definition CallGraph.h:229
Include the generated interface declarations.