1 // 2 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 3 // See https://llvm.org/LICENSE.txt for license information. 4 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 5 // 6 //===----------------------------------------------------------------------===// 7 // 8 // Dialect wrapper to simplify using TableGen Record defining a MLIR dialect. 9 // 10 //===----------------------------------------------------------------------===// 11 12 #ifndef MLIR_TABLEGEN_DIALECT_H_ 13 #define MLIR_TABLEGEN_DIALECT_H_ 14 15 #include "mlir/Support/LLVM.h" 16 #include <string> 17 #include <vector> 18 19 namespace llvm { 20 class Record; 21 } // end namespace llvm 22 23 namespace mlir { 24 namespace tblgen { 25 // Wrapper class that contains a MLIR dialect's information defined in TableGen 26 // and provides helper methods for accessing them. 27 class Dialect { 28 public: 29 explicit Dialect(const llvm::Record *def); 30 31 // Returns the name of this dialect. 32 StringRef getName() const; 33 34 // Returns the C++ namespaces that ops of this dialect should be placed into. 35 StringRef getCppNamespace() const; 36 37 // Returns this dialect's C++ class name. 38 std::string getCppClassName() const; 39 40 // Returns the summary description of the dialect. Returns empty string if 41 // none. 42 StringRef getSummary() const; 43 44 // Returns the description of the dialect. Returns empty string if none. 45 StringRef getDescription() const; 46 47 // Returns the list of dialect (class names) that this dialect depends on. 48 // These are dialects that will be loaded on construction of this dialect. 49 ArrayRef<StringRef> getDependentDialects() const; 50 51 // Returns the dialects extra class declaration code. 52 llvm::Optional<StringRef> getExtraClassDeclaration() const; 53 54 // Returns true if this dialect has a constant materializer. 55 bool hasConstantMaterializer() const; 56 57 /// Returns true if this dialect has an operation attribute verifier. 58 bool hasOperationAttrVerify() const; 59 60 /// Returns true if this dialect has a region argument attribute verifier. 61 bool hasRegionArgAttrVerify() const; 62 63 /// Returns true if this dialect has a region result attribute verifier. 64 bool hasRegionResultAttrVerify() const; 65 66 // Returns whether two dialects are equal by checking the equality of the 67 // underlying record. 68 bool operator==(const Dialect &other) const; 69 70 bool operator!=(const Dialect &other) const { return !(*this == other); } 71 72 // Compares two dialects by comparing the names of the dialects. 73 bool operator<(const Dialect &other) const; 74 75 // Returns whether the dialect is defined. 76 explicit operator bool() const { return def != nullptr; } 77 78 private: 79 const llvm::Record *def; 80 std::vector<StringRef> dependentDialects; 81 }; 82 } // end namespace tblgen 83 } // end namespace mlir 84 85 #endif // MLIR_TABLEGEN_DIALECT_H_ 86