xref: /llvm-project/mlir/include/mlir/TableGen/Dialect.h (revision e768b076e3b7ed38485a29244a0b989076e4b131)
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.
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 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.
81   bool useDefaultAttributePrinterParser() const;
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   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 
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_
119