MLIR  20.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 
22 namespace llvm {
23 class Record;
24 } // namespace llvm
25 
26 namespace mlir {
27 namespace tblgen {
28 // Wrapper class that contains a MLIR dialect's information defined in TableGen
29 // and provides helper methods for accessing them.
30 class Dialect {
31 public:
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 has a canonicalizer.
58  bool hasCanonicalizer() const;
59 
60  /// Returns true if this dialect has a constant materializer.
61  bool hasConstantMaterializer() const;
62 
63  /// Returns true if the destructor definition is provided explicitly or
64  /// false if a default should be generated.
65  bool hasNonDefaultDestructor() const;
66 
67  /// Returns true if this dialect has an operation attribute verifier.
68  bool hasOperationAttrVerify() const;
69 
70  /// Returns true if this dialect has a region argument attribute verifier.
71  bool hasRegionArgAttrVerify() const;
72 
73  /// Returns true if this dialect has a region result attribute verifier.
74  bool hasRegionResultAttrVerify() const;
75 
76  /// Returns true if this dialect has fallback interfaces for its operations.
77  bool hasOperationInterfaceFallback() const;
78 
79  /// Returns true if this dialect should generate the default dispatch for
80  /// attribute printing/parsing.
82 
83  /// Returns true if this dialect should generate the default dispatch for
84  /// type printing/parsing.
85  bool useDefaultTypePrinterParser() const;
86 
87  /// Returns true if this dialect can be extended at runtime with new
88  /// operations or types.
89  bool isExtensible() const;
90 
91  /// Default to use properties for storing Attributes for operations in this
92  /// dialect.
93  bool usePropertiesForAttributes() const;
94 
95  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 
111 private:
112  const llvm::Record *def;
113  std::vector<StringRef> dependentDialects;
114 };
115 } // namespace tblgen
116 } // namespace mlir
117 
118 #endif // MLIR_TABLEGEN_DIALECT_H_
StringRef getDescription() const
Definition: Dialect.cpp:52
const llvm::Record * getDef() const
Definition: Dialect.h:97
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 hasRegionArgAttrVerify() const
Returns true if this dialect has a region argument attribute verifier.
Definition: Dialect.cpp:81
llvm::DagInit * getDiscardableAttributes() const
Definition: Dialect.cpp:109
bool hasNonDefaultDestructor() const
Returns true if the destructor definition is provided explicitly or false if a default should be gene...
Definition: Dialect.cpp:73
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:93
bool isExtensible() const
Returns true if this dialect can be extended at runtime with new operations or types.
Definition: Dialect.cpp:101
StringRef getName() const
bool hasOperationInterfaceFallback() const
Returns true if this dialect has fallback interfaces for its operations.
Definition: Dialect.cpp:89
bool hasCanonicalizer() const
Returns true if this dialect has a canonicalizer.
Definition: Dialect.cpp:65
bool operator<(const Dialect &other) const
Definition: Dialect.cpp:117
bool hasConstantMaterializer() const
Returns true if this dialect has a constant materializer.
Definition: Dialect.cpp:69
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:85
bool useDefaultTypePrinterParser() const
Returns true if this dialect should generate the default dispatch for type printing/parsing.
Definition: Dialect.cpp:97
bool hasOperationAttrVerify() const
Returns true if this dialect has an operation attribute verifier.
Definition: Dialect.cpp:77
bool operator==(const Dialect &other) const
Definition: Dialect.cpp:113
bool usePropertiesForAttributes() const
Default to use properties for storing Attributes for operations in this dialect.
Definition: Dialect.cpp:105
bool operator!=(const Dialect &other) const
Definition: Dialect.h:103
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Definition: CallGraph.h:229
Include the generated interface declarations.