1 //===- Dialect.h - PDLL ODS Dialect -----------------------------*- 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 #ifndef MLIR_TOOLS_PDLL_ODS_DIALECT_H_ 10 #define MLIR_TOOLS_PDLL_ODS_DIALECT_H_ 11 12 #include <string> 13 14 #include "mlir/Support/LLVM.h" 15 #include "llvm/ADT/STLExtras.h" 16 #include "llvm/ADT/SmallVector.h" 17 #include "llvm/ADT/StringMap.h" 18 19 namespace mlir { 20 namespace pdll { 21 namespace ods { 22 class Operation; 23 24 /// This class represents an ODS dialect, and contains information on the 25 /// constructs held within the dialect. 26 class Dialect { 27 public: 28 ~Dialect(); 29 30 /// Return the name of this dialect. getName()31 StringRef getName() const { return name; } 32 33 /// Insert a new operation with the dialect. Returns the inserted operation, 34 /// and a boolean indicating if the operation newly inserted (false if the 35 /// operation already existed). 36 std::pair<Operation *, bool> 37 insertOperation(StringRef name, StringRef summary, StringRef desc, 38 StringRef nativeClassName, bool supportsResultTypeInferrence, 39 SMLoc loc); 40 41 /// Lookup an operation registered with the given name, or null if no 42 /// operation with that name is registered. 43 Operation *lookupOperation(StringRef name) const; 44 45 /// Return a map of all of the operations registered to this dialect. getOperations()46 const llvm::StringMap<std::unique_ptr<Operation>> &getOperations() const { 47 return operations; 48 } 49 50 private: 51 explicit Dialect(StringRef name); 52 53 /// The name of the dialect. 54 std::string name; 55 56 /// The operations defined by the dialect. 57 llvm::StringMap<std::unique_ptr<Operation>> operations; 58 59 /// Allow access to the constructor. 60 friend class Context; 61 }; 62 } // namespace ods 63 } // namespace pdll 64 } // namespace mlir 65 66 #endif // MLIR_TOOLS_PDLL_ODS_DIALECT_H_ 67