MLIR  18.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  /// Default to use properties for storing Attributes for operations in this
90  /// dialect.
91  bool usePropertiesForAttributes() const;
92 
93  // Returns whether two dialects are equal by checking the equality of the
94  // underlying record.
95  bool operator==(const Dialect &other) const;
96 
97  bool operator!=(const Dialect &other) const { return !(*this == other); }
98 
99  // Compares two dialects by comparing the names of the dialects.
100  bool operator<(const Dialect &other) const;
101 
102  // Returns whether the dialect is defined.
103  explicit operator bool() const { return def != nullptr; }
104 
105 private:
106  const llvm::Record *def;
107  std::vector<StringRef> dependentDialects;
108 };
109 } // namespace tblgen
110 } // namespace mlir
111 
112 #endif // MLIR_TABLEGEN_DIALECT_H_
StringRef getDescription() const
Definition: Dialect.cpp:52
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
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:113
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:109
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:97
Include the generated interface declarations.
Definition: CallGraph.h:229
Include the generated interface declarations.