File: | build/source/mlir/lib/TableGen/Interfaces.cpp |
Warning: | line 80, column 27 Called C++ object pointer is null |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | //===- Interfaces.cpp - Interface classes ---------------------------------===// | |||
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 | #include "mlir/TableGen/Interfaces.h" | |||
10 | #include "llvm/ADT/FunctionExtras.h" | |||
11 | #include "llvm/ADT/StringExtras.h" | |||
12 | #include "llvm/Support/FormatVariadic.h" | |||
13 | #include "llvm/TableGen/Error.h" | |||
14 | #include "llvm/TableGen/Record.h" | |||
15 | ||||
16 | using namespace mlir; | |||
17 | using namespace mlir::tblgen; | |||
18 | ||||
19 | //===----------------------------------------------------------------------===// | |||
20 | // InterfaceMethod | |||
21 | //===----------------------------------------------------------------------===// | |||
22 | ||||
23 | InterfaceMethod::InterfaceMethod(const llvm::Record *def) : def(def) { | |||
24 | llvm::DagInit *args = def->getValueAsDag("arguments"); | |||
25 | for (unsigned i = 0, e = args->getNumArgs(); i != e; ++i) { | |||
26 | arguments.push_back( | |||
27 | {llvm::cast<llvm::StringInit>(args->getArg(i))->getValue(), | |||
28 | args->getArgNameStr(i)}); | |||
29 | } | |||
30 | } | |||
31 | ||||
32 | StringRef InterfaceMethod::getReturnType() const { | |||
33 | return def->getValueAsString("returnType"); | |||
34 | } | |||
35 | ||||
36 | // Return the name of this method. | |||
37 | StringRef InterfaceMethod::getName() const { | |||
38 | return def->getValueAsString("name"); | |||
39 | } | |||
40 | ||||
41 | // Return if this method is static. | |||
42 | bool InterfaceMethod::isStatic() const { | |||
43 | return def->isSubClassOf("StaticInterfaceMethod"); | |||
44 | } | |||
45 | ||||
46 | // Return the body for this method if it has one. | |||
47 | std::optional<StringRef> InterfaceMethod::getBody() const { | |||
48 | auto value = def->getValueAsString("body"); | |||
49 | return value.empty() ? std::optional<StringRef>() : value; | |||
50 | } | |||
51 | ||||
52 | // Return the default implementation for this method if it has one. | |||
53 | std::optional<StringRef> InterfaceMethod::getDefaultImplementation() const { | |||
54 | auto value = def->getValueAsString("defaultBody"); | |||
55 | return value.empty() ? std::optional<StringRef>() : value; | |||
56 | } | |||
57 | ||||
58 | // Return the description of this method if it has one. | |||
59 | std::optional<StringRef> InterfaceMethod::getDescription() const { | |||
60 | auto value = def->getValueAsString("description"); | |||
61 | return value.empty() ? std::optional<StringRef>() : value; | |||
62 | } | |||
63 | ||||
64 | ArrayRef<InterfaceMethod::Argument> InterfaceMethod::getArguments() const { | |||
65 | return arguments; | |||
66 | } | |||
67 | ||||
68 | bool InterfaceMethod::arg_empty() const { return arguments.empty(); } | |||
69 | ||||
70 | //===----------------------------------------------------------------------===// | |||
71 | // Interface | |||
72 | //===----------------------------------------------------------------------===// | |||
73 | ||||
74 | Interface::Interface(const llvm::Record *def) : def(def) { | |||
75 | assert(def->isSubClassOf("Interface") &&(static_cast <bool> (def->isSubClassOf("Interface") && "must be subclass of TableGen 'Interface' class") ? void (0) : __assert_fail ("def->isSubClassOf(\"Interface\") && \"must be subclass of TableGen 'Interface' class\"" , "mlir/lib/TableGen/Interfaces.cpp", 76, __extension__ __PRETTY_FUNCTION__ )) | |||
| ||||
76 | "must be subclass of TableGen 'Interface' class")(static_cast <bool> (def->isSubClassOf("Interface") && "must be subclass of TableGen 'Interface' class") ? void (0) : __assert_fail ("def->isSubClassOf(\"Interface\") && \"must be subclass of TableGen 'Interface' class\"" , "mlir/lib/TableGen/Interfaces.cpp", 76, __extension__ __PRETTY_FUNCTION__ )); | |||
77 | ||||
78 | // Initialize the interface methods. | |||
79 | auto *listInit = dyn_cast<llvm::ListInit>(def->getValueInit("methods")); | |||
80 | for (llvm::Init *init : listInit->getValues()) | |||
| ||||
81 | methods.emplace_back(cast<llvm::DefInit>(init)->getDef()); | |||
82 | ||||
83 | // Initialize the interface base classes. | |||
84 | auto *basesInit = | |||
85 | dyn_cast<llvm::ListInit>(def->getValueInit("baseInterfaces")); | |||
86 | llvm::unique_function<void(Interface)> addBaseInterfaceFn = | |||
87 | [&](const Interface &baseInterface) { | |||
88 | // Inherit any base interfaces. | |||
89 | for (const auto &baseBaseInterface : baseInterface.getBaseInterfaces()) | |||
90 | addBaseInterfaceFn(baseBaseInterface); | |||
91 | ||||
92 | // Add the base interface. | |||
93 | baseInterfaces.push_back(std::make_unique<Interface>(baseInterface)); | |||
94 | }; | |||
95 | for (llvm::Init *init : basesInit->getValues()) | |||
96 | addBaseInterfaceFn(Interface(cast<llvm::DefInit>(init)->getDef())); | |||
97 | } | |||
98 | ||||
99 | // Return the name of this interface. | |||
100 | StringRef Interface::getName() const { | |||
101 | return def->getValueAsString("cppInterfaceName"); | |||
102 | } | |||
103 | ||||
104 | // Returns this interface's name prefixed with namespaces. | |||
105 | std::string Interface::getFullyQualifiedName() const { | |||
106 | StringRef cppNamespace = getCppNamespace(); | |||
107 | StringRef name = getName(); | |||
108 | if (cppNamespace.empty()) | |||
109 | return name.str(); | |||
110 | return (cppNamespace + "::" + name).str(); | |||
111 | } | |||
112 | ||||
113 | // Return the C++ namespace of this interface. | |||
114 | StringRef Interface::getCppNamespace() const { | |||
115 | return def->getValueAsString("cppNamespace"); | |||
116 | } | |||
117 | ||||
118 | // Return the methods of this interface. | |||
119 | ArrayRef<InterfaceMethod> Interface::getMethods() const { return methods; } | |||
120 | ||||
121 | // Return the description of this method if it has one. | |||
122 | std::optional<StringRef> Interface::getDescription() const { | |||
123 | auto value = def->getValueAsString("description"); | |||
124 | return value.empty() ? std::optional<StringRef>() : value; | |||
125 | } | |||
126 | ||||
127 | // Return the interfaces extra class declaration code. | |||
128 | std::optional<StringRef> Interface::getExtraClassDeclaration() const { | |||
129 | auto value = def->getValueAsString("extraClassDeclaration"); | |||
130 | return value.empty() ? std::optional<StringRef>() : value; | |||
131 | } | |||
132 | ||||
133 | // Return the traits extra class declaration code. | |||
134 | std::optional<StringRef> Interface::getExtraTraitClassDeclaration() const { | |||
135 | auto value = def->getValueAsString("extraTraitClassDeclaration"); | |||
136 | return value.empty() ? std::optional<StringRef>() : value; | |||
137 | } | |||
138 | ||||
139 | // Return the shared extra class declaration code. | |||
140 | std::optional<StringRef> Interface::getExtraSharedClassDeclaration() const { | |||
141 | auto value = def->getValueAsString("extraSharedClassDeclaration"); | |||
142 | return value.empty() ? std::optional<StringRef>() : value; | |||
143 | } | |||
144 | ||||
145 | std::optional<StringRef> Interface::getExtraClassOf() const { | |||
146 | auto value = def->getValueAsString("extraClassOf"); | |||
147 | return value.empty() ? std::optional<StringRef>() : value; | |||
148 | } | |||
149 | ||||
150 | // Return the body for this method if it has one. | |||
151 | std::optional<StringRef> Interface::getVerify() const { | |||
152 | // Only OpInterface supports the verify method. | |||
153 | if (!isa<OpInterface>(this)) | |||
154 | return std::nullopt; | |||
155 | auto value = def->getValueAsString("verify"); | |||
156 | return value.empty() ? std::optional<StringRef>() : value; | |||
157 | } | |||
158 | ||||
159 | bool Interface::verifyWithRegions() const { | |||
160 | return def->getValueAsBit("verifyWithRegions"); | |||
161 | } | |||
162 | ||||
163 | //===----------------------------------------------------------------------===// | |||
164 | // AttrInterface | |||
165 | //===----------------------------------------------------------------------===// | |||
166 | ||||
167 | bool AttrInterface::classof(const Interface *interface) { | |||
168 | return interface->getDef().isSubClassOf("AttrInterface"); | |||
169 | } | |||
170 | ||||
171 | //===----------------------------------------------------------------------===// | |||
172 | // OpInterface | |||
173 | //===----------------------------------------------------------------------===// | |||
174 | ||||
175 | bool OpInterface::classof(const Interface *interface) { | |||
176 | return interface->getDef().isSubClassOf("OpInterface"); | |||
177 | } | |||
178 | ||||
179 | //===----------------------------------------------------------------------===// | |||
180 | // TypeInterface | |||
181 | //===----------------------------------------------------------------------===// | |||
182 | ||||
183 | bool TypeInterface::classof(const Interface *interface) { | |||
184 | return interface->getDef().isSubClassOf("TypeInterface"); | |||
185 | } |