MLIR  20.0.0git
Context.h
Go to the documentation of this file.
1 //===- Context.h - MLIR PDLL ODS Context ------------------------*- 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_CONTEXT_H_
10 #define MLIR_TOOLS_PDLL_ODS_CONTEXT_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 llvm {
20 class SMLoc;
21 } // namespace llvm
22 
23 namespace mlir {
24 namespace pdll {
25 namespace ods {
26 class AttributeConstraint;
27 class Dialect;
28 class Operation;
29 class TypeConstraint;
30 
31 /// This class contains all of the registered ODS operation classes.
32 class Context {
33 public:
36 
37  /// Insert a new attribute constraint with the context. Returns the inserted
38  /// constraint, or a previously inserted constraint with the same name.
39  const AttributeConstraint &insertAttributeConstraint(StringRef name,
40  StringRef summary,
41  StringRef cppClass);
42 
43  /// Insert a new type constraint with the context. Returns the inserted
44  /// constraint, or a previously inserted constraint with the same name.
45  const TypeConstraint &insertTypeConstraint(StringRef name, StringRef summary,
46  StringRef cppClass);
47 
48  /// Insert a new dialect with the context. Returns the inserted dialect, or a
49  /// previously inserted dialect with the same name.
50  Dialect &insertDialect(StringRef name);
51 
52  /// Lookup a dialect registered with the given name, or null if no dialect
53  /// with that name was inserted.
54  const Dialect *lookupDialect(StringRef name) const;
55 
56  /// Return a range of all of the registered dialects.
57  auto getDialects() const {
58  return llvm::make_pointee_range(llvm::make_second_range(dialects));
59  }
60 
61  /// Insert a new operation with the context. Returns the inserted operation,
62  /// and a boolean indicating if the operation newly inserted (false if the
63  /// operation already existed).
64  std::pair<Operation *, bool>
65  insertOperation(StringRef name, StringRef summary, StringRef desc,
66  StringRef nativeClassName, bool supportsResultTypeInferrence,
67  SMLoc loc);
68 
69  /// Lookup an operation registered with the given name, or null if no
70  /// operation with that name is registered.
71  const Operation *lookupOperation(StringRef name) const;
72 
73  /// Print the contents of this context to the provided stream.
74  void print(raw_ostream &os) const;
75 
76 private:
77  llvm::StringMap<std::unique_ptr<AttributeConstraint>> attributeConstraints;
78  llvm::StringMap<std::unique_ptr<Dialect>> dialects;
79  llvm::StringMap<std::unique_ptr<TypeConstraint>> typeConstraints;
80 };
81 } // namespace ods
82 } // namespace pdll
83 } // namespace mlir
84 
85 #endif // MLIR_PDL_pdll_ODS_CONTEXT_H_
This class represents a generic ODS Attribute constraint.
Definition: Constraint.h:63
This class contains all of the registered ODS operation classes.
Definition: Context.h:32
std::pair< Operation *, bool > insertOperation(StringRef name, StringRef summary, StringRef desc, StringRef nativeClassName, bool supportsResultTypeInferrence, SMLoc loc)
Insert a new operation with the context.
Definition: Context.cpp:64
const TypeConstraint & insertTypeConstraint(StringRef name, StringRef summary, StringRef cppClass)
Insert a new type constraint with the context.
Definition: Context.cpp:42
auto getDialects() const
Return a range of all of the registered dialects.
Definition: Context.h:57
Dialect & insertDialect(StringRef name)
Insert a new dialect with the context.
Definition: Context.cpp:51
const Dialect * lookupDialect(StringRef name) const
Lookup a dialect registered with the given name, or null if no dialect with that name was inserted.
Definition: Context.cpp:58
const AttributeConstraint & insertAttributeConstraint(StringRef name, StringRef summary, StringRef cppClass)
Insert a new attribute constraint with the context.
Definition: Context.cpp:28
const Operation * lookupOperation(StringRef name) const
Lookup an operation registered with the given name, or null if no operation with that name is registe...
Definition: Context.cpp:73
void print(raw_ostream &os) const
Print the contents of this context to the provided stream.
Definition: Context.cpp:91
This class represents an ODS dialect, and contains information on the constructs held within the dial...
Definition: Dialect.h:26
This class provides an ODS representation of a specific operation.
Definition: Operation.h:125
This class represents a generic ODS Type constraint.
Definition: Constraint.h:84
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Definition: CallGraph.h:229
Include the generated interface declarations.