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