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.
52 ArrayRef<StringRef> getDependentDialects() const;
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.
59 bool useStrictPropertiesInAssemblyFormat() const;
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.
81 bool hasOperationInterfaceFallback() const;
82
83 /// Returns true if this dialect should generate the default dispatch for
84 /// attribute printing/parsing.
85 bool useDefaultAttributePrinterParser() const;
86
87 /// Returns true if this dialect should generate the default dispatch for
88 /// type printing/parsing.
89 bool useDefaultTypePrinterParser() const;
90
91 /// Returns true if this dialect can be extended at runtime with new
92 /// operations or types.
93 bool isExtensible() const;
94
95 const llvm::DagInit *getDiscardableAttributes() const;
96
97 const llvm::Record *getDef() const { return def; }
98
99 // Returns whether two dialects are equal by checking the equality of the
100 // underlying record.
101 bool operator==(const Dialect &other) const;
102
103 bool operator!=(const Dialect &other) const { return !(*this == other); }
104
105 // Compares two dialects by comparing the names of the dialects.
106 bool operator<(const Dialect &other) const;
107
108 // Returns whether the dialect is defined.
109 explicit operator bool() const { return def != nullptr; }
110 bool isDefined() const { return def != nullptr; }
111
112private:
113 const llvm::Record *def;
114 std::vector<StringRef> dependentDialects;
115};
116} // namespace tblgen
117} // namespace mlir
118
119#endif // MLIR_TABLEGEN_DIALECT_H_
120