MLIR  17.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 <string>
18 #include <vector>
19 
20 namespace llvm {
21 class Record;
22 } // namespace llvm
23 
24 namespace mlir {
25 namespace tblgen {
26 // Wrapper class that contains a MLIR dialect's information defined in TableGen
27 // and provides helper methods for accessing them.
28 class Dialect {
29 public:
30  explicit Dialect(const llvm::Record *def);
31 
32  // Returns the name of this dialect.
33  StringRef getName() const;
34 
35  // Returns the C++ namespaces that ops of this dialect should be placed into.
36  StringRef getCppNamespace() const;
37 
38  // Returns this dialect's C++ class name.
39  std::string getCppClassName() const;
40 
41  // Returns the summary description of the dialect. Returns empty string if
42  // none.
43  StringRef getSummary() const;
44 
45  // Returns the description of the dialect. Returns empty string if none.
46  StringRef getDescription() const;
47 
48  // Returns the list of dialect (class names) that this dialect depends on.
49  // These are dialects that will be loaded on construction of this dialect.
51 
52  // Returns the dialects extra class declaration code.
53  std::optional<StringRef> getExtraClassDeclaration() const;
54 
55  /// Returns true if this dialect has a canonicalizer.
56  bool hasCanonicalizer() const;
57 
58  /// Returns true if this dialect has a constant materializer.
59  bool hasConstantMaterializer() const;
60 
61  /// Returns true if the destructor definition is provided explicitly or
62  /// false if a default should be generated.
63  bool hasNonDefaultDestructor() const;
64 
65  /// Returns true if this dialect has an operation attribute verifier.
66  bool hasOperationAttrVerify() const;
67 
68  /// Returns true if this dialect has a region argument attribute verifier.
69  bool hasRegionArgAttrVerify() const;
70 
71  /// Returns true if this dialect has a region result attribute verifier.
72  bool hasRegionResultAttrVerify() const;
73 
74  /// Returns true if this dialect has fallback interfaces for its operations.
75  bool hasOperationInterfaceFallback() const;
76 
77  /// Returns true if this dialect should generate the default dispatch for
78  /// attribute printing/parsing.
80 
81  /// Returns true if this dialect should generate the default dispatch for
82  /// type printing/parsing.
83  bool useDefaultTypePrinterParser() const;
84 
85  /// Returns true if this dialect can be extended at runtime with new
86  /// operations or types.
87  bool isExtensible() const;
88 
89  enum class FolderAPI {
90  RawAttributes = 0, /// fold method with ArrayRef<Attribute>.
91  FolderAdaptor = 1, /// fold method with the operation's FoldAdaptor.
92  };
93 
94  /// Returns the folder API that should be emitted for operations in this
95  /// dialect.
96  FolderAPI getFolderAPI() const;
97 
98  // Returns whether two dialects are equal by checking the equality of the
99  // underlying record.
100  bool operator==(const Dialect &other) const;
101 
102  bool operator!=(const Dialect &other) const { return !(*this == other); }
103 
104  // Compares two dialects by comparing the names of the dialects.
105  bool operator<(const Dialect &other) const;
106 
107  // Returns whether the dialect is defined.
108  explicit operator bool() const { return def != nullptr; }
109 
110 private:
111  const llvm::Record *def;
112  std::vector<StringRef> dependentDialects;
113 };
114 } // namespace tblgen
115 } // namespace mlir
116 
117 #endif // MLIR_TABLEGEN_DIALECT_H_
StringRef getDescription() const
Definition: Dialect.cpp:53
FolderAPI getFolderAPI() const
Returns the folder API that should be emitted for operations in this dialect.
Definition: Dialect.cpp:106
Dialect(const llvm::Record *def)
Definition: Dialect.cpp:20
StringRef getSummary() const
Definition: Dialect.cpp:49
std::optional< StringRef > getExtraClassDeclaration() const
Definition: Dialect.cpp:61
ArrayRef< StringRef > getDependentDialects() const
Definition: Dialect.cpp:57
bool hasRegionArgAttrVerify() const
Returns true if this dialect has a region argument attribute verifier.
Definition: Dialect.cpp:82
bool hasNonDefaultDestructor() const
Returns true if the destructor definition is provided explicitly or false if a default should be gene...
Definition: Dialect.cpp:74
StringRef getCppNamespace() const
Definition: Dialect.cpp:29
bool useDefaultAttributePrinterParser() const
Returns true if this dialect should generate the default dispatch for attribute printing/parsing.
Definition: Dialect.cpp:94
bool isExtensible() const
Returns true if this dialect can be extended at runtime with new operations or types.
Definition: Dialect.cpp:102
StringRef getName() const
bool hasOperationInterfaceFallback() const
Returns true if this dialect has fallback interfaces for its operations.
Definition: Dialect.cpp:90
bool hasCanonicalizer() const
Returns true if this dialect has a canonicalizer.
Definition: Dialect.cpp:66
bool operator<(const Dialect &other) const
Definition: Dialect.cpp:125
bool hasConstantMaterializer() const
Returns true if this dialect has a constant materializer.
Definition: Dialect.cpp:70
std::string getCppClassName() const
Definition: Dialect.cpp:33
bool hasRegionResultAttrVerify() const
Returns true if this dialect has a region result attribute verifier.
Definition: Dialect.cpp:86
bool useDefaultTypePrinterParser() const
Returns true if this dialect should generate the default dispatch for type printing/parsing.
Definition: Dialect.cpp:98
bool hasOperationAttrVerify() const
Returns true if this dialect has an operation attribute verifier.
Definition: Dialect.cpp:78
@ FolderAdaptor
fold method with ArrayRef<Attribute>.
bool operator==(const Dialect &other) const
Definition: Dialect.cpp:121
bool operator!=(const Dialect &other) const
Definition: Dialect.h:102
Include the generated interface declarations.
Definition: CallGraph.h:229
Include the generated interface declarations.