MLIR 24.0.0git
Interfaces.h
Go to the documentation of this file.
1//===- Interfaces.h - Interface wrapper classes -----------------*- 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_TABLEGEN_INTERFACES_H_
10#define MLIR_TABLEGEN_INTERFACES_H_
11
12#include "mlir/Support/LLVM.h"
13#include "llvm/ADT/SmallVector.h"
14#include "llvm/ADT/StringMap.h"
15#include "llvm/ADT/StringRef.h"
16#include "llvm/ADT/iterator.h"
17#include <vector>
18
19namespace llvm {
20class Init;
21class Record;
22} // namespace llvm
23
24namespace mlir {
25namespace tblgen {
26
27// Wrapper class with helper methods for accessing InterfaceMethod defined
28// in TableGen.
30public:
31 // This struct represents a single method argument.
32 struct Argument {
33 StringRef type;
34 StringRef name;
35 };
36
37 explicit InterfaceMethod(const llvm::Record *def, std::string uniqueName);
38
39 // Return the return type of this method.
40 StringRef getReturnType() const;
41
42 // Return the name of this method.
43 StringRef getName() const;
44
45 // Return the dedup name of this method.
46 StringRef getUniqueName() const;
47
48 // Return if this method is static.
49 bool isStatic() const;
50
51 // Return if the method is a pure virtual one.
52 bool isPureVirtual() const;
53
54 // Return if the method is only a declaration.
55 bool isDeclaration() const;
56
57 // Return the body for this method if it has one.
58 std::optional<StringRef> getBody() const;
59
60 // Return the default implementation for this method if it has one.
61 std::optional<StringRef> getDefaultImplementation() const;
62
63 // Return the description of this method if it has one.
64 std::optional<StringRef> getDescription() const;
65
66 // Arguments.
68 bool arg_empty() const;
69
70private:
71 // The TableGen definition of this method.
72 const llvm::Record *def;
73
74 // The arguments of this method.
76
77 // The unique name of this method, to distinguish it from other methods with
78 // the same name (overloaded methods)
79 std::string uniqueName;
80};
81
82//===----------------------------------------------------------------------===//
83// Interface
84//===----------------------------------------------------------------------===//
85
86// Wrapper class with helper methods for accessing Interfaces defined in
87// TableGen.
88class Interface {
89public:
90 explicit Interface(const llvm::Record *def);
91 Interface(const Interface &rhs) : def(rhs.def), methods(rhs.methods) {
92 for (auto &base : rhs.baseInterfaces)
93 baseInterfaces.push_back(std::make_unique<Interface>(*base));
94 }
95
96 // Return the name of this interface.
97 StringRef getName() const;
98
99 // Returns this interface's name prefixed with namespaces.
100 std::string getFullyQualifiedName() const;
101
102 // Return the C++ namespace of this interface.
103 StringRef getCppNamespace() const;
104
105 // Return the C++ headers declaring this interface.
106 std::vector<StringRef> getCppIncludes() const;
107
108 // Return the methods of this interface.
110
111 // Return the description of this method if it has one.
112 std::optional<StringRef> getDescription() const;
113
114 // Return the interfaces extra class declaration code.
115 std::optional<StringRef> getExtraClassDeclaration() const;
116
117 // Return the traits extra class declaration code.
118 std::optional<StringRef> getExtraTraitClassDeclaration() const;
119
120 // Return the extra class declaration code shared between the interface and
121 // trait classes.
122 std::optional<StringRef> getExtraSharedClassDeclaration() const;
123
124 // Return the extra classof method code.
125 std::optional<StringRef> getExtraClassOf() const;
126
127 // Return the verify method body if it has one.
128 std::optional<StringRef> getVerify() const;
129
130 // Return the base interfaces of this interface.
131 auto getBaseInterfaces() const {
132 return llvm::make_pointee_range(baseInterfaces);
133 }
134
135 // If there's a verify method, return if it needs to access the ops in the
136 // regions.
137 bool verifyWithRegions() const;
138
139 // Returns the Tablegen definition this interface was constructed from.
140 const llvm::Record &getDef() const { return *def; }
141
142private:
143 // The TableGen definition of this interface.
144 const llvm::Record *def;
145
146 // The methods of this interface.
148
149 // The base interfaces of this interface.
151};
152
153// An interface that is registered to an Attribute.
154struct AttrInterface : public Interface {
156
157 static bool classof(const Interface *interface);
158};
159// An interface that is registered to an Operation.
160struct OpInterface : public Interface {
162
163 static bool classof(const Interface *interface);
164};
165// An interface that is registered to a Type.
166struct TypeInterface : public Interface {
168
169 static bool classof(const Interface *interface);
170};
171// An interface that is registered to a Dialect.
174
175 static bool classof(const Interface *interface);
176};
177
178} // namespace tblgen
179} // namespace mlir
180
181#endif // MLIR_TABLEGEN_INTERFACES_H_
StringRef getReturnType() const
std::optional< StringRef > getDefaultImplementation() const
ArrayRef< Argument > getArguments() const
InterfaceMethod(const llvm::Record *def, std::string uniqueName)
std::optional< StringRef > getBody() const
StringRef getUniqueName() const
std::optional< StringRef > getDescription() const
Interface(const llvm::Record *def)
std::optional< StringRef > getExtraClassOf() const
std::optional< StringRef > getDescription() const
std::optional< StringRef > getExtraClassDeclaration() const
std::vector< StringRef > getCppIncludes() const
std::optional< StringRef > getExtraSharedClassDeclaration() const
Interface(const Interface &rhs)
Definition Interfaces.h:91
ArrayRef< InterfaceMethod > getMethods() const
std::optional< StringRef > getExtraTraitClassDeclaration() const
bool verifyWithRegions() const
std::optional< StringRef > getVerify() const
const llvm::Record & getDef() const
Definition Interfaces.h:140
auto getBaseInterfaces() const
Definition Interfaces.h:131
std::string getFullyQualifiedName() const
StringRef getCppNamespace() const
StringRef getName() const
The OpAsmOpInterface, see OpAsmInterface.td for more details.
Definition CallGraph.h:229
Include the generated interface declarations.
Interface(const llvm::Record *def)
static bool classof(const Interface *interface)
Interface(const llvm::Record *def)
static bool classof(const Interface *interface)
Interface(const llvm::Record *def)
static bool classof(const Interface *interface)
Interface(const llvm::Record *def)
static bool classof(const Interface *interface)