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