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. 50 ArrayRef<StringRef> getDependentDialects() const; 51 52 // Returns the dialects extra class declaration code. 53 llvm::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. 79 bool useDefaultAttributePrinterParser() const; 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 // Returns whether two dialects are equal by checking the equality of the 90 // underlying record. 91 bool operator==(const Dialect &other) const; 92 93 bool operator!=(const Dialect &other) const { return !(*this == other); } 94 95 // Compares two dialects by comparing the names of the dialects. 96 bool operator<(const Dialect &other) const; 97 98 // Returns whether the dialect is defined. 99 explicit operator bool() const { return def != nullptr; } 100 101 // Returns how the accessors should be prefixed in dialect. 102 enum class EmitPrefix { Raw = 0, Prefixed = 1, Both = 2 }; 103 EmitPrefix getEmitAccessorPrefix() const; 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_ 113