MLIR  20.0.0git
Dialect.h
Go to the documentation of this file.
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:
29 
30  /// Return the name of this dialect.
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.
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_
This class contains all of the registered ODS operation classes.
Definition: Context.h:32
This class represents an ODS dialect, and contains information on the constructs held within the dial...
Definition: Dialect.h:26
StringRef getName() const
Return the name of this dialect.
Definition: Dialect.h:31
const llvm::StringMap< std::unique_ptr< Operation > > & getOperations() const
Return a map of all of the operations registered to this dialect.
Definition: Dialect.h:46
Operation * lookupOperation(StringRef name) const
Lookup an operation registered with the given name, or null if no operation with that name is registe...
Definition: Dialect.cpp:37
std::pair< Operation *, bool > insertOperation(StringRef name, StringRef summary, StringRef desc, StringRef nativeClassName, bool supportsResultTypeInferrence, SMLoc loc)
Insert a new operation with the dialect.
Definition: Dialect.cpp:25
This class provides an ODS representation of a specific operation.
Definition: Operation.h:125
Include the generated interface declarations.