1 | /*===- TableGen'erated file -------------------------------------*- C++ -*-===*\ |
2 | |* *| |
3 | |* Op Definitions *| |
4 | |* *| |
5 | |* Automatically generated file, do not edit! *| |
6 | |* *| |
7 | \*===----------------------------------------------------------------------===*/ |
8 | |
9 | #ifdef GET_OP_LIST |
10 | #undef GET_OP_LIST |
11 | |
12 | ::mlir::tfg::CaseOp, |
13 | ::mlir::tfg::CaseRegionOp, |
14 | ::mlir::tfg::ConditionOp, |
15 | ::mlir::tfg::ForOp, |
16 | ::mlir::tfg::ForRegionOp, |
17 | ::mlir::tfg::GetResultOp, |
18 | ::mlir::tfg::GraphFuncOp, |
19 | ::mlir::tfg::GraphOp, |
20 | ::mlir::tfg::IfOp, |
21 | ::mlir::tfg::IfRegionOp, |
22 | ::mlir::tfg::ReturnOp, |
23 | ::mlir::tfg::StatefulCaseOp, |
24 | ::mlir::tfg::StatefulCaseRegionOp, |
25 | ::mlir::tfg::StatefulIfOp, |
26 | ::mlir::tfg::StatefulIfRegionOp, |
27 | ::mlir::tfg::StatefulWhileOp, |
28 | ::mlir::tfg::StatefulWhileRegionOp, |
29 | ::mlir::tfg::StatelessCaseOp, |
30 | ::mlir::tfg::StatelessCaseRegionOp, |
31 | ::mlir::tfg::StatelessIfOp, |
32 | ::mlir::tfg::StatelessIfRegionOp, |
33 | ::mlir::tfg::StatelessWhileOp, |
34 | ::mlir::tfg::StatelessWhileRegionOp, |
35 | ::mlir::tfg::WhileOp, |
36 | ::mlir::tfg::WhileRegionOp, |
37 | ::mlir::tfg::YieldOp |
38 | #endif // GET_OP_LIST |
39 | |
40 | #ifdef GET_OP_CLASSES |
41 | #undef GET_OP_CLASSES |
42 | |
43 | |
44 | //===----------------------------------------------------------------------===// |
45 | // Local Utility Method Definitions |
46 | //===----------------------------------------------------------------------===// |
47 | |
48 | namespace mlir { |
49 | namespace tfg { |
50 | |
51 | static ::mlir::LogicalResult __mlir_ods_local_type_constraint_ops0( |
52 | ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, |
53 | unsigned valueIndex) { |
54 | if (!((((type.isa<::mlir::TensorType>())) && ([](::mlir::Type elementType) { return (elementType.isSignlessInteger(32)); }(type.cast<::mlir::ShapedType>().getElementType()))) || ((type.isa<::mlir::tf_type::OpaqueTensorType>())))) { |
55 | return op->emitOpError(valueKind) << " #" << valueIndex |
56 | << " must be or opaque tensor type, but got " << type; |
57 | } |
58 | return ::mlir::success(); |
59 | } |
60 | |
61 | static ::mlir::LogicalResult __mlir_ods_local_type_constraint_ops1( |
62 | ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, |
63 | unsigned valueIndex) { |
64 | if (!(((((type.isa<::mlir::TensorType>())) && ([](::mlir::Type elementType) { return (true); }(type.cast<::mlir::ShapedType>().getElementType()))) || ((type.isa<::mlir::tf_type::OpaqueTensorType>()))) || ((type.isa<::mlir::tf_type::ControlType>())))) { |
65 | return op->emitOpError(valueKind) << " #" << valueIndex |
66 | << " must be any tensor or control type, but got " << type; |
67 | } |
68 | return ::mlir::success(); |
69 | } |
70 | |
71 | static ::mlir::LogicalResult __mlir_ods_local_type_constraint_ops2( |
72 | ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, |
73 | unsigned valueIndex) { |
74 | if (!((((type.isa<::mlir::TensorType>())) && ([](::mlir::Type elementType) { return (true); }(type.cast<::mlir::ShapedType>().getElementType()))) || ((type.isa<::mlir::tf_type::OpaqueTensorType>())))) { |
75 | return op->emitOpError(valueKind) << " #" << valueIndex |
76 | << " must be or opaque tensor type, but got " << type; |
77 | } |
78 | return ::mlir::success(); |
79 | } |
80 | |
81 | static ::mlir::LogicalResult __mlir_ods_local_type_constraint_ops3( |
82 | ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, |
83 | unsigned valueIndex) { |
84 | if (!((type.isa<::mlir::tf_type::ControlType>()))) { |
85 | return op->emitOpError(valueKind) << " #" << valueIndex |
86 | << " must be , but got " << type; |
87 | } |
88 | return ::mlir::success(); |
89 | } |
90 | |
91 | static ::mlir::LogicalResult __mlir_ods_local_type_constraint_ops4( |
92 | ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, |
93 | unsigned valueIndex) { |
94 | if (!(((type.isa<::mlir::TensorType>())) && ([](::mlir::Type elementType) { return (elementType.isSignlessInteger(32)); }(type.cast<::mlir::ShapedType>().getElementType())))) { |
95 | return op->emitOpError(valueKind) << " #" << valueIndex |
96 | << " must be tensor of 32-bit signless integer values, but got " << type; |
97 | } |
98 | return ::mlir::success(); |
99 | } |
100 | |
101 | static ::mlir::LogicalResult __mlir_ods_local_type_constraint_ops5( |
102 | ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, |
103 | unsigned valueIndex) { |
104 | if (!(((type.isa<::mlir::TensorType>())) && ([](::mlir::Type elementType) { return (elementType.isSignlessInteger(1)); }(type.cast<::mlir::ShapedType>().getElementType())))) { |
105 | return op->emitOpError(valueKind) << " #" << valueIndex |
106 | << " must be tensor of 1-bit signless integer values, but got " << type; |
107 | } |
108 | return ::mlir::success(); |
109 | } |
110 | |
111 | static ::mlir::LogicalResult __mlir_ods_local_type_constraint_ops6( |
112 | ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, |
113 | unsigned valueIndex) { |
114 | if (!((type.isa<::mlir::tf_type::OpaqueTensorType>()))) { |
115 | return op->emitOpError(valueKind) << " #" << valueIndex |
116 | << " must be , but got " << type; |
117 | } |
118 | return ::mlir::success(); |
119 | } |
120 | |
121 | static ::mlir::LogicalResult __mlir_ods_local_type_constraint_ops7( |
122 | ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, |
123 | unsigned valueIndex) { |
124 | if (!((((type.isa<::mlir::TensorType>())) && ([](::mlir::Type elementType) { return (elementType.isSignlessInteger(1)); }(type.cast<::mlir::ShapedType>().getElementType()))) || ((type.isa<::mlir::tf_type::OpaqueTensorType>())))) { |
125 | return op->emitOpError(valueKind) << " #" << valueIndex |
126 | << " must be or opaque tensor type, but got " << type; |
127 | } |
128 | return ::mlir::success(); |
129 | } |
130 | |
131 | static ::mlir::LogicalResult __mlir_ods_local_type_constraint_ops8( |
132 | ::mlir::Operation *op, ::mlir::Type type, ::llvm::StringRef valueKind, |
133 | unsigned valueIndex) { |
134 | if (!((true))) { |
135 | return op->emitOpError(valueKind) << " #" << valueIndex |
136 | << " must be any type, but got " << type; |
137 | } |
138 | return ::mlir::success(); |
139 | } |
140 | |
141 | static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_ops0( |
142 | ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { |
143 | if (attr && !(((attr.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(attr.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && ((attr.isa<::mlir::tf_type::FuncAttr>())); })))) { |
144 | return op->emitOpError("attribute '" ) << attrName |
145 | << "' failed to satisfy constraint: an array of functions" ; |
146 | } |
147 | return ::mlir::success(); |
148 | } |
149 | |
150 | static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_ops1( |
151 | ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { |
152 | if (attr && !(((attr.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(attr.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && (((attr.isa<::mlir::TypeAttr>())) && ((attr.cast<::mlir::TypeAttr>().getValue().isa<::mlir::Type>()))); })))) { |
153 | return op->emitOpError("attribute '" ) << attrName |
154 | << "' failed to satisfy constraint: type array attribute" ; |
155 | } |
156 | return ::mlir::success(); |
157 | } |
158 | |
159 | static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_ops2( |
160 | ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { |
161 | if (attr && !(((attr.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(attr.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && ((attr.isa<::mlir::tf_type::ShapeAttr>())); })))) { |
162 | return op->emitOpError("attribute '" ) << attrName |
163 | << "' failed to satisfy constraint: An array of shapes." ; |
164 | } |
165 | return ::mlir::success(); |
166 | } |
167 | |
168 | static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_ops3( |
169 | ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { |
170 | if (attr && !(((attr.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(attr.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && ((attr.isa<::mlir::DictionaryAttr>())); })))) { |
171 | return op->emitOpError("attribute '" ) << attrName |
172 | << "' failed to satisfy constraint: an array of dictionaries" ; |
173 | } |
174 | return ::mlir::success(); |
175 | } |
176 | |
177 | static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_ops4( |
178 | ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { |
179 | if (attr && !(((attr.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(attr.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && ((attr.isa<::mlir::tfg::RegionAttr>())); })))) { |
180 | return op->emitOpError("attribute '" ) << attrName |
181 | << "' failed to satisfy constraint: case region preserved attributes" ; |
182 | } |
183 | return ::mlir::success(); |
184 | } |
185 | |
186 | static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_ops5( |
187 | ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { |
188 | if (attr && !((attr.isa<::mlir::tf_type::FuncAttr>()))) { |
189 | return op->emitOpError("attribute '" ) << attrName |
190 | << "' failed to satisfy constraint: Models the `AttrValue.value.func` proto attribute value as a pair of SymbolRef and DictionaryAttr" ; |
191 | } |
192 | return ::mlir::success(); |
193 | } |
194 | |
195 | static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_ops6( |
196 | ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { |
197 | if (attr && !((attr.isa<::mlir::DictionaryAttr>()))) { |
198 | return op->emitOpError("attribute '" ) << attrName |
199 | << "' failed to satisfy constraint: dictionary of named attribute values" ; |
200 | } |
201 | return ::mlir::success(); |
202 | } |
203 | |
204 | static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_ops7( |
205 | ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { |
206 | if (attr && !((attr.isa<::mlir::tfg::RegionAttr>()))) { |
207 | return op->emitOpError("attribute '" ) << attrName |
208 | << "' failed to satisfy constraint: Region attributes, argument and result attributes." ; |
209 | } |
210 | return ::mlir::success(); |
211 | } |
212 | |
213 | static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_ops8( |
214 | ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { |
215 | if (attr && !((attr.isa<::mlir::StringAttr>()))) { |
216 | return op->emitOpError("attribute '" ) << attrName |
217 | << "' failed to satisfy constraint: string attribute" ; |
218 | } |
219 | return ::mlir::success(); |
220 | } |
221 | |
222 | static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_ops9( |
223 | ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { |
224 | if (attr && !(((attr.isa<::mlir::IntegerAttr>())) && ((attr.cast<::mlir::IntegerAttr>().getType().isSignlessInteger(32))))) { |
225 | return op->emitOpError("attribute '" ) << attrName |
226 | << "' failed to satisfy constraint: 32-bit signless integer attribute" ; |
227 | } |
228 | return ::mlir::success(); |
229 | } |
230 | |
231 | static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_ops10( |
232 | ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { |
233 | if (attr && !((attr.isa<::mlir::UnitAttr>()))) { |
234 | return op->emitOpError("attribute '" ) << attrName |
235 | << "' failed to satisfy constraint: unit attribute" ; |
236 | } |
237 | return ::mlir::success(); |
238 | } |
239 | |
240 | static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_ops11( |
241 | ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { |
242 | if (attr && !(((attr.isa<::mlir::TypeAttr>())) && ((attr.cast<::mlir::TypeAttr>().getValue().isa<::mlir::FunctionType>())))) { |
243 | return op->emitOpError("attribute '" ) << attrName |
244 | << "' failed to satisfy constraint: type attribute of function type" ; |
245 | } |
246 | return ::mlir::success(); |
247 | } |
248 | |
249 | static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_ops12( |
250 | ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { |
251 | if (attr && !((attr.isa<::mlir::ArrayAttr>()))) { |
252 | return op->emitOpError("attribute '" ) << attrName |
253 | << "' failed to satisfy constraint: array attribute" ; |
254 | } |
255 | return ::mlir::success(); |
256 | } |
257 | |
258 | static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_ops13( |
259 | ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { |
260 | if (attr && !((attr.isa<::mlir::FlatSymbolRefAttr>()))) { |
261 | return op->emitOpError("attribute '" ) << attrName |
262 | << "' failed to satisfy constraint: flat symbol reference attribute" ; |
263 | } |
264 | return ::mlir::success(); |
265 | } |
266 | |
267 | static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_ops14( |
268 | ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { |
269 | if (attr && !(((attr.isa<::mlir::DenseIntElementsAttr>())) && ((attr.cast<::mlir::DenseIntElementsAttr>().getType().getElementType().isSignlessInteger(32))))) { |
270 | return op->emitOpError("attribute '" ) << attrName |
271 | << "' failed to satisfy constraint: 32-bit signless integer elements attribute" ; |
272 | } |
273 | return ::mlir::success(); |
274 | } |
275 | |
276 | static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_ops15( |
277 | ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { |
278 | if (attr && !(((attr.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(attr.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && ((attr.isa<::mlir::StringAttr>())); })))) { |
279 | return op->emitOpError("attribute '" ) << attrName |
280 | << "' failed to satisfy constraint: string array attribute" ; |
281 | } |
282 | return ::mlir::success(); |
283 | } |
284 | |
285 | static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_ops16( |
286 | ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { |
287 | if (attr && !((attr.isa<::mlir::tf_type::VersionAttr>()))) { |
288 | return op->emitOpError("attribute '" ) << attrName |
289 | << "' failed to satisfy constraint: An Attribute describing the version for a TensorFlow Graph" ; |
290 | } |
291 | return ::mlir::success(); |
292 | } |
293 | |
294 | static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_ops17( |
295 | ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { |
296 | if (attr && !(((attr.isa<::mlir::TypeAttr>())) && ((attr.cast<::mlir::TypeAttr>().getValue().isa<::mlir::Type>())))) { |
297 | return op->emitOpError("attribute '" ) << attrName |
298 | << "' failed to satisfy constraint: any type attribute" ; |
299 | } |
300 | return ::mlir::success(); |
301 | } |
302 | |
303 | static ::mlir::LogicalResult __mlir_ods_local_attr_constraint_ops18( |
304 | ::mlir::Operation *op, ::mlir::Attribute attr, ::llvm::StringRef attrName) { |
305 | if (attr && !(((attr.isa<::mlir::IntegerAttr>())) && ((attr.cast<::mlir::IntegerAttr>().getType().isSignlessInteger(64))))) { |
306 | return op->emitOpError("attribute '" ) << attrName |
307 | << "' failed to satisfy constraint: 64-bit signless integer attribute" ; |
308 | } |
309 | return ::mlir::success(); |
310 | } |
311 | |
312 | static ::mlir::LogicalResult __mlir_ods_local_region_constraint_ops0( |
313 | ::mlir::Operation *op, ::mlir::Region ®ion, ::llvm::StringRef regionName, |
314 | unsigned regionIndex) { |
315 | if (!((::llvm::hasNItems(region, 1)))) { |
316 | return op->emitOpError("region #" ) << regionIndex |
317 | << (regionName.empty() ? " " : " ('" + regionName + "') " ) |
318 | << "failed to verify constraint: region with 1 blocks" ; |
319 | } |
320 | return ::mlir::success(); |
321 | } |
322 | |
323 | static ::mlir::LogicalResult __mlir_ods_local_region_constraint_ops1( |
324 | ::mlir::Operation *op, ::mlir::Region ®ion, ::llvm::StringRef regionName, |
325 | unsigned regionIndex) { |
326 | if (!((true))) { |
327 | return op->emitOpError("region #" ) << regionIndex |
328 | << (regionName.empty() ? " " : " ('" + regionName + "') " ) |
329 | << "failed to verify constraint: any region" ; |
330 | } |
331 | return ::mlir::success(); |
332 | } |
333 | } // namespace tfg |
334 | } // namespace mlir |
335 | namespace mlir { |
336 | namespace tfg { |
337 | |
338 | //===----------------------------------------------------------------------===// |
339 | // ::mlir::tfg::CaseOp definitions |
340 | //===----------------------------------------------------------------------===// |
341 | |
342 | CaseOpAdaptor::CaseOpAdaptor(::mlir::ValueRange values, ::mlir::DictionaryAttr attrs, ::mlir::RegionRange regions) : odsOperands(values), odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) |
343 | odsOpName.emplace("tfg.Case" , odsAttrs.getContext()); |
344 | } |
345 | |
346 | CaseOpAdaptor::CaseOpAdaptor(CaseOp op) : odsOperands(op->getOperands()), odsAttrs(op->getAttrDictionary()), odsRegions(op->getRegions()), odsOpName(op->getName()) {} |
347 | |
348 | ::mlir::ValueRange CaseOpAdaptor::getOperands() { |
349 | return odsOperands; |
350 | } |
351 | |
352 | std::pair<unsigned, unsigned> CaseOpAdaptor::getODSOperandIndexAndLength(unsigned index) { |
353 | bool isVariadic[] = {false, true}; |
354 | int prevVariadicCount = 0; |
355 | for (unsigned i = 0; i < index; ++i) |
356 | if (isVariadic[i]) ++prevVariadicCount; |
357 | |
358 | // Calculate how many dynamic values a static variadic operand corresponds to. |
359 | // This assumes all static variadic operands have the same dynamic value count. |
360 | int variadicSize = (odsOperands.size() - 1) / 1; |
361 | // `index` passed in as the parameter is the static index which counts each |
362 | // operand (variadic or not) as size 1. So here for each previous static variadic |
363 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
364 | // value pack for this static operand starts. |
365 | int start = index + (variadicSize - 1) * prevVariadicCount; |
366 | int size = isVariadic[index] ? variadicSize : 1; |
367 | return {start, size}; |
368 | } |
369 | |
370 | ::mlir::ValueRange CaseOpAdaptor::getODSOperands(unsigned index) { |
371 | auto valueRange = getODSOperandIndexAndLength(index); |
372 | return {std::next(odsOperands.begin(), valueRange.first), |
373 | std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; |
374 | } |
375 | |
376 | ::mlir::Value CaseOpAdaptor::getBranchIndex() { |
377 | return *getODSOperands(0).begin(); |
378 | } |
379 | |
380 | ::mlir::Value CaseOpAdaptor::branch_index() { |
381 | return *getODSOperands(0).begin(); |
382 | } |
383 | |
384 | ::mlir::ValueRange CaseOpAdaptor::getArgs() { |
385 | return getODSOperands(1); |
386 | } |
387 | |
388 | ::mlir::ValueRange CaseOpAdaptor::args() { |
389 | return getODSOperands(1); |
390 | } |
391 | |
392 | ::mlir::DictionaryAttr CaseOpAdaptor::getAttributes() { |
393 | return odsAttrs; |
394 | } |
395 | |
396 | ::mlir::ArrayAttr CaseOpAdaptor::getBranchesAttr() { |
397 | assert(odsAttrs && "no attributes when constructing adapter" ); |
398 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, CaseOp::getBranchesAttrName(*odsOpName)).cast<::mlir::ArrayAttr>(); |
399 | return attr; |
400 | } |
401 | |
402 | ::mlir::ArrayAttr CaseOpAdaptor::getBranches() { |
403 | auto attr = getBranchesAttr(); |
404 | return attr; |
405 | } |
406 | |
407 | ::mlir::ArrayAttr CaseOpAdaptor::branchesAttr() { |
408 | assert(odsAttrs && "no attributes when constructing adapter" ); |
409 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, CaseOp::getBranchesAttrName(*odsOpName)).cast<::mlir::ArrayAttr>(); |
410 | return attr; |
411 | } |
412 | |
413 | ::mlir::ArrayAttr CaseOpAdaptor::branches() { |
414 | auto attr = branchesAttr(); |
415 | return attr; |
416 | } |
417 | |
418 | ::mlir::ArrayAttr CaseOpAdaptor::getTinAttr() { |
419 | assert(odsAttrs && "no attributes when constructing adapter" ); |
420 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 1, CaseOp::getTinAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
421 | return attr; |
422 | } |
423 | |
424 | ::llvm::Optional< ::mlir::ArrayAttr > CaseOpAdaptor::getTin() { |
425 | auto attr = getTinAttr(); |
426 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
427 | } |
428 | |
429 | ::mlir::ArrayAttr CaseOpAdaptor::TinAttr() { |
430 | assert(odsAttrs && "no attributes when constructing adapter" ); |
431 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 1, CaseOp::getTinAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
432 | return attr; |
433 | } |
434 | |
435 | ::llvm::Optional< ::mlir::ArrayAttr > CaseOpAdaptor::Tin() { |
436 | auto attr = TinAttr(); |
437 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
438 | } |
439 | |
440 | ::mlir::ArrayAttr CaseOpAdaptor::getToutAttr() { |
441 | assert(odsAttrs && "no attributes when constructing adapter" ); |
442 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 1, CaseOp::getToutAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
443 | return attr; |
444 | } |
445 | |
446 | ::llvm::Optional< ::mlir::ArrayAttr > CaseOpAdaptor::getTout() { |
447 | auto attr = getToutAttr(); |
448 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
449 | } |
450 | |
451 | ::mlir::ArrayAttr CaseOpAdaptor::ToutAttr() { |
452 | assert(odsAttrs && "no attributes when constructing adapter" ); |
453 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 1, CaseOp::getToutAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
454 | return attr; |
455 | } |
456 | |
457 | ::llvm::Optional< ::mlir::ArrayAttr > CaseOpAdaptor::Tout() { |
458 | auto attr = ToutAttr(); |
459 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
460 | } |
461 | |
462 | ::mlir::ArrayAttr CaseOpAdaptor::getOutputShapesAttr() { |
463 | assert(odsAttrs && "no attributes when constructing adapter" ); |
464 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 0, CaseOp::getOutputShapesAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
465 | return attr; |
466 | } |
467 | |
468 | ::llvm::Optional< ::mlir::ArrayAttr > CaseOpAdaptor::getOutputShapes() { |
469 | auto attr = getOutputShapesAttr(); |
470 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
471 | } |
472 | |
473 | ::mlir::ArrayAttr CaseOpAdaptor::output_shapesAttr() { |
474 | assert(odsAttrs && "no attributes when constructing adapter" ); |
475 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 0, CaseOp::getOutputShapesAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
476 | return attr; |
477 | } |
478 | |
479 | ::llvm::Optional< ::mlir::ArrayAttr > CaseOpAdaptor::output_shapes() { |
480 | auto attr = output_shapesAttr(); |
481 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
482 | } |
483 | |
484 | ::mlir::LogicalResult CaseOpAdaptor::verify(::mlir::Location loc) { |
485 | auto namedAttrRange = odsAttrs; |
486 | auto namedAttrIt = namedAttrRange.begin(); |
487 | ::mlir::Attribute tblgen_branches; |
488 | ::mlir::Attribute tblgen_Tin; |
489 | ::mlir::Attribute tblgen_Tout; |
490 | while (true) { |
491 | if (namedAttrIt == namedAttrRange.end()) |
492 | return emitError(loc, "'tfg.Case' op " "requires attribute 'branches'" ); |
493 | if (namedAttrIt->getName() == CaseOp::getBranchesAttrName(*odsOpName)) { |
494 | tblgen_branches = namedAttrIt->getValue(); |
495 | break; |
496 | } |
497 | else if (namedAttrIt->getName() == CaseOp::getTinAttrName(*odsOpName)) { |
498 | tblgen_Tin = namedAttrIt->getValue(); |
499 | } |
500 | else if (namedAttrIt->getName() == CaseOp::getToutAttrName(*odsOpName)) { |
501 | tblgen_Tout = namedAttrIt->getValue(); |
502 | } |
503 | ++namedAttrIt; |
504 | } |
505 | ::mlir::Attribute tblgen_output_shapes; |
506 | while (true) { |
507 | if (namedAttrIt == namedAttrRange.end()) { |
508 | break; |
509 | } |
510 | else if (namedAttrIt->getName() == CaseOp::getOutputShapesAttrName(*odsOpName)) { |
511 | tblgen_output_shapes = namedAttrIt->getValue(); |
512 | } |
513 | ++namedAttrIt; |
514 | } |
515 | |
516 | if (tblgen_branches && !(((tblgen_branches.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_branches.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && ((attr.isa<::mlir::tf_type::FuncAttr>())); })))) |
517 | return emitError(loc, "'tfg.Case' op " "attribute 'branches' failed to satisfy constraint: an array of functions" ); |
518 | |
519 | if (tblgen_Tin && !(((tblgen_Tin.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_Tin.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && (((attr.isa<::mlir::TypeAttr>())) && ((attr.cast<::mlir::TypeAttr>().getValue().isa<::mlir::Type>()))); })))) |
520 | return emitError(loc, "'tfg.Case' op " "attribute 'Tin' failed to satisfy constraint: type array attribute" ); |
521 | |
522 | if (tblgen_Tout && !(((tblgen_Tout.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_Tout.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && (((attr.isa<::mlir::TypeAttr>())) && ((attr.cast<::mlir::TypeAttr>().getValue().isa<::mlir::Type>()))); })))) |
523 | return emitError(loc, "'tfg.Case' op " "attribute 'Tout' failed to satisfy constraint: type array attribute" ); |
524 | |
525 | if (tblgen_output_shapes && !(((tblgen_output_shapes.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_output_shapes.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && ((attr.isa<::mlir::tf_type::ShapeAttr>())); })))) |
526 | return emitError(loc, "'tfg.Case' op " "attribute 'output_shapes' failed to satisfy constraint: An array of shapes." ); |
527 | return ::mlir::success(); |
528 | } |
529 | |
530 | void CaseOp::getAsmResultNames(::mlir::OpAsmSetValueNameFn setNameFn) { |
531 | auto resultGroup0 = getODSResults(0); |
532 | if (!resultGroup0.empty()) |
533 | setNameFn(*resultGroup0.begin(), "outs" ); |
534 | auto resultGroup1 = getODSResults(1); |
535 | if (!resultGroup1.empty()) |
536 | setNameFn(*resultGroup1.begin(), "ctl" ); |
537 | } |
538 | |
539 | std::pair<unsigned, unsigned> CaseOp::getODSOperandIndexAndLength(unsigned index) { |
540 | bool isVariadic[] = {false, true}; |
541 | int prevVariadicCount = 0; |
542 | for (unsigned i = 0; i < index; ++i) |
543 | if (isVariadic[i]) ++prevVariadicCount; |
544 | |
545 | // Calculate how many dynamic values a static variadic operand corresponds to. |
546 | // This assumes all static variadic operands have the same dynamic value count. |
547 | int variadicSize = (getOperation()->getNumOperands() - 1) / 1; |
548 | // `index` passed in as the parameter is the static index which counts each |
549 | // operand (variadic or not) as size 1. So here for each previous static variadic |
550 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
551 | // value pack for this static operand starts. |
552 | int start = index + (variadicSize - 1) * prevVariadicCount; |
553 | int size = isVariadic[index] ? variadicSize : 1; |
554 | return {start, size}; |
555 | } |
556 | |
557 | ::mlir::Operation::operand_range CaseOp::getODSOperands(unsigned index) { |
558 | auto valueRange = getODSOperandIndexAndLength(index); |
559 | return {std::next(getOperation()->operand_begin(), valueRange.first), |
560 | std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; |
561 | } |
562 | |
563 | ::mlir::Value CaseOp::getBranchIndex() { |
564 | return *getODSOperands(0).begin(); |
565 | } |
566 | |
567 | ::mlir::Value CaseOp::branch_index() { |
568 | return *getODSOperands(0).begin(); |
569 | } |
570 | |
571 | ::mlir::Operation::operand_range CaseOp::getArgs() { |
572 | return getODSOperands(1); |
573 | } |
574 | |
575 | ::mlir::Operation::operand_range CaseOp::args() { |
576 | return getODSOperands(1); |
577 | } |
578 | |
579 | ::mlir::MutableOperandRange CaseOp::getBranchIndexMutable() { |
580 | auto range = getODSOperandIndexAndLength(0); |
581 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
582 | return mutableRange; |
583 | } |
584 | |
585 | ::mlir::MutableOperandRange CaseOp::branch_indexMutable() { |
586 | auto range = getODSOperandIndexAndLength(0); |
587 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
588 | return mutableRange; |
589 | } |
590 | |
591 | ::mlir::MutableOperandRange CaseOp::getArgsMutable() { |
592 | auto range = getODSOperandIndexAndLength(1); |
593 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
594 | return mutableRange; |
595 | } |
596 | |
597 | ::mlir::MutableOperandRange CaseOp::argsMutable() { |
598 | auto range = getODSOperandIndexAndLength(1); |
599 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
600 | return mutableRange; |
601 | } |
602 | |
603 | std::pair<unsigned, unsigned> CaseOp::getODSResultIndexAndLength(unsigned index) { |
604 | bool isVariadic[] = {true, false}; |
605 | int prevVariadicCount = 0; |
606 | for (unsigned i = 0; i < index; ++i) |
607 | if (isVariadic[i]) ++prevVariadicCount; |
608 | |
609 | // Calculate how many dynamic values a static variadic operand corresponds to. |
610 | // This assumes all static variadic operands have the same dynamic value count. |
611 | int variadicSize = (getOperation()->getNumResults() - 1) / 1; |
612 | // `index` passed in as the parameter is the static index which counts each |
613 | // operand (variadic or not) as size 1. So here for each previous static variadic |
614 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
615 | // value pack for this static operand starts. |
616 | int start = index + (variadicSize - 1) * prevVariadicCount; |
617 | int size = isVariadic[index] ? variadicSize : 1; |
618 | return {start, size}; |
619 | } |
620 | |
621 | ::mlir::Operation::result_range CaseOp::getODSResults(unsigned index) { |
622 | auto valueRange = getODSResultIndexAndLength(index); |
623 | return {std::next(getOperation()->result_begin(), valueRange.first), |
624 | std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; |
625 | } |
626 | |
627 | ::mlir::Operation::result_range CaseOp::getOuts() { |
628 | return getODSResults(0); |
629 | } |
630 | |
631 | ::mlir::Operation::result_range CaseOp::outs() { |
632 | return getODSResults(0); |
633 | } |
634 | |
635 | ::mlir::TypedValue<::mlir::tf_type::ControlType> CaseOp::getCtl() { |
636 | return *getODSResults(1).begin(); |
637 | } |
638 | |
639 | ::mlir::TypedValue<::mlir::tf_type::ControlType> CaseOp::ctl() { |
640 | return *getODSResults(1).begin(); |
641 | } |
642 | |
643 | ::mlir::ArrayAttr CaseOp::getBranchesAttr() { |
644 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getBranchesAttrName()).cast<::mlir::ArrayAttr>(); |
645 | } |
646 | |
647 | ::mlir::ArrayAttr CaseOp::getBranches() { |
648 | auto attr = getBranchesAttr(); |
649 | return attr; |
650 | } |
651 | |
652 | ::mlir::ArrayAttr CaseOp::branchesAttr() { |
653 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getBranchesAttrName()).cast<::mlir::ArrayAttr>(); |
654 | } |
655 | |
656 | ::mlir::ArrayAttr CaseOp::branches() { |
657 | auto attr = branchesAttr(); |
658 | return attr; |
659 | } |
660 | |
661 | ::mlir::ArrayAttr CaseOp::getTinAttr() { |
662 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getTinAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
663 | } |
664 | |
665 | ::llvm::Optional< ::mlir::ArrayAttr > CaseOp::getTin() { |
666 | auto attr = getTinAttr(); |
667 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
668 | } |
669 | |
670 | ::mlir::ArrayAttr CaseOp::TinAttr() { |
671 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getTinAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
672 | } |
673 | |
674 | ::llvm::Optional< ::mlir::ArrayAttr > CaseOp::Tin() { |
675 | auto attr = TinAttr(); |
676 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
677 | } |
678 | |
679 | ::mlir::ArrayAttr CaseOp::getToutAttr() { |
680 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getToutAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
681 | } |
682 | |
683 | ::llvm::Optional< ::mlir::ArrayAttr > CaseOp::getTout() { |
684 | auto attr = getToutAttr(); |
685 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
686 | } |
687 | |
688 | ::mlir::ArrayAttr CaseOp::ToutAttr() { |
689 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getToutAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
690 | } |
691 | |
692 | ::llvm::Optional< ::mlir::ArrayAttr > CaseOp::Tout() { |
693 | auto attr = ToutAttr(); |
694 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
695 | } |
696 | |
697 | ::mlir::ArrayAttr CaseOp::getOutputShapesAttr() { |
698 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getOutputShapesAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
699 | } |
700 | |
701 | ::llvm::Optional< ::mlir::ArrayAttr > CaseOp::getOutputShapes() { |
702 | auto attr = getOutputShapesAttr(); |
703 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
704 | } |
705 | |
706 | ::mlir::ArrayAttr CaseOp::output_shapesAttr() { |
707 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getOutputShapesAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
708 | } |
709 | |
710 | ::llvm::Optional< ::mlir::ArrayAttr > CaseOp::output_shapes() { |
711 | auto attr = output_shapesAttr(); |
712 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
713 | } |
714 | |
715 | void CaseOp::setBranchesAttr(::mlir::ArrayAttr attr) { |
716 | (*this)->setAttr(getBranchesAttrName(), attr); |
717 | } |
718 | |
719 | void CaseOp::branchesAttr(::mlir::ArrayAttr attr) { |
720 | (*this)->setAttr(branchesAttrName(), attr); |
721 | } |
722 | |
723 | void CaseOp::setTinAttr(::mlir::ArrayAttr attr) { |
724 | (*this)->setAttr(getTinAttrName(), attr); |
725 | } |
726 | |
727 | void CaseOp::TinAttr(::mlir::ArrayAttr attr) { |
728 | (*this)->setAttr(TinAttrName(), attr); |
729 | } |
730 | |
731 | void CaseOp::setToutAttr(::mlir::ArrayAttr attr) { |
732 | (*this)->setAttr(getToutAttrName(), attr); |
733 | } |
734 | |
735 | void CaseOp::ToutAttr(::mlir::ArrayAttr attr) { |
736 | (*this)->setAttr(ToutAttrName(), attr); |
737 | } |
738 | |
739 | void CaseOp::setOutputShapesAttr(::mlir::ArrayAttr attr) { |
740 | (*this)->setAttr(getOutputShapesAttrName(), attr); |
741 | } |
742 | |
743 | void CaseOp::output_shapesAttr(::mlir::ArrayAttr attr) { |
744 | (*this)->setAttr(output_shapesAttrName(), attr); |
745 | } |
746 | |
747 | ::mlir::Attribute CaseOp::removeTinAttr() { |
748 | return (*this)->removeAttr(getTinAttrName()); |
749 | } |
750 | |
751 | ::mlir::Attribute CaseOp::removeToutAttr() { |
752 | return (*this)->removeAttr(getToutAttrName()); |
753 | } |
754 | |
755 | ::mlir::Attribute CaseOp::removeOutput_shapesAttr() { |
756 | return (*this)->removeAttr(getOutputShapesAttrName()); |
757 | } |
758 | |
759 | void CaseOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, TypeRange results, Value branch_index, ValueRange args, ArrayAttr branches) { |
760 | build(odsBuilder, odsState, results, branch_index, args, branches, |
761 | /*Tin=*/{}, /*Tout=*/{}, /*output_shapes=*/{}); |
762 | |
763 | } |
764 | |
765 | void CaseOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange outs, ::mlir::Type ctl, ::mlir::Value branch_index, ::mlir::ValueRange args, ::mlir::ArrayAttr branches, /*optional*/::mlir::ArrayAttr Tin, /*optional*/::mlir::ArrayAttr Tout, /*optional*/::mlir::ArrayAttr output_shapes) { |
766 | odsState.addOperands(branch_index); |
767 | odsState.addOperands(args); |
768 | odsState.addAttribute(getBranchesAttrName(odsState.name), branches); |
769 | if (Tin) { |
770 | odsState.addAttribute(getTinAttrName(odsState.name), Tin); |
771 | } |
772 | if (Tout) { |
773 | odsState.addAttribute(getToutAttrName(odsState.name), Tout); |
774 | } |
775 | if (output_shapes) { |
776 | odsState.addAttribute(getOutputShapesAttrName(odsState.name), output_shapes); |
777 | } |
778 | odsState.addTypes(outs); |
779 | odsState.addTypes(ctl); |
780 | } |
781 | |
782 | void CaseOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value branch_index, ::mlir::ValueRange args, ::mlir::ArrayAttr branches, /*optional*/::mlir::ArrayAttr Tin, /*optional*/::mlir::ArrayAttr Tout, /*optional*/::mlir::ArrayAttr output_shapes) { |
783 | odsState.addOperands(branch_index); |
784 | odsState.addOperands(args); |
785 | odsState.addAttribute(getBranchesAttrName(odsState.name), branches); |
786 | if (Tin) { |
787 | odsState.addAttribute(getTinAttrName(odsState.name), Tin); |
788 | } |
789 | if (Tout) { |
790 | odsState.addAttribute(getToutAttrName(odsState.name), Tout); |
791 | } |
792 | if (output_shapes) { |
793 | odsState.addAttribute(getOutputShapesAttrName(odsState.name), output_shapes); |
794 | } |
795 | assert(resultTypes.size() >= 1u && "mismatched number of results" ); |
796 | odsState.addTypes(resultTypes); |
797 | } |
798 | |
799 | void CaseOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { |
800 | assert(operands.size() >= 1u && "mismatched number of parameters" ); |
801 | odsState.addOperands(operands); |
802 | odsState.addAttributes(attributes); |
803 | assert(resultTypes.size() >= 1u && "mismatched number of return types" ); |
804 | odsState.addTypes(resultTypes); |
805 | } |
806 | |
807 | ::mlir::LogicalResult CaseOp::verifyInvariantsImpl() { |
808 | auto namedAttrRange = (*this)->getAttrs(); |
809 | auto namedAttrIt = namedAttrRange.begin(); |
810 | ::mlir::Attribute tblgen_branches; |
811 | ::mlir::Attribute tblgen_Tin; |
812 | ::mlir::Attribute tblgen_Tout; |
813 | while (true) { |
814 | if (namedAttrIt == namedAttrRange.end()) |
815 | return emitOpError("requires attribute 'branches'" ); |
816 | if (namedAttrIt->getName() == getBranchesAttrName()) { |
817 | tblgen_branches = namedAttrIt->getValue(); |
818 | break; |
819 | } |
820 | else if (namedAttrIt->getName() == getTinAttrName()) { |
821 | tblgen_Tin = namedAttrIt->getValue(); |
822 | } |
823 | else if (namedAttrIt->getName() == getToutAttrName()) { |
824 | tblgen_Tout = namedAttrIt->getValue(); |
825 | } |
826 | ++namedAttrIt; |
827 | } |
828 | ::mlir::Attribute tblgen_output_shapes; |
829 | while (true) { |
830 | if (namedAttrIt == namedAttrRange.end()) { |
831 | break; |
832 | } |
833 | else if (namedAttrIt->getName() == getOutputShapesAttrName()) { |
834 | tblgen_output_shapes = namedAttrIt->getValue(); |
835 | } |
836 | ++namedAttrIt; |
837 | } |
838 | |
839 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops0(*this, tblgen_branches, "branches" ))) |
840 | return ::mlir::failure(); |
841 | |
842 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops1(*this, tblgen_Tin, "Tin" ))) |
843 | return ::mlir::failure(); |
844 | |
845 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops1(*this, tblgen_Tout, "Tout" ))) |
846 | return ::mlir::failure(); |
847 | |
848 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops2(*this, tblgen_output_shapes, "output_shapes" ))) |
849 | return ::mlir::failure(); |
850 | { |
851 | unsigned index = 0; (void)index; |
852 | auto valueGroup0 = getODSOperands(0); |
853 | |
854 | for (auto v : valueGroup0) { |
855 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops0(*this, v.getType(), "operand" , index++))) |
856 | return ::mlir::failure(); |
857 | } |
858 | auto valueGroup1 = getODSOperands(1); |
859 | |
860 | for (auto v : valueGroup1) { |
861 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops1(*this, v.getType(), "operand" , index++))) |
862 | return ::mlir::failure(); |
863 | } |
864 | } |
865 | { |
866 | unsigned index = 0; (void)index; |
867 | auto valueGroup0 = getODSResults(0); |
868 | |
869 | for (auto v : valueGroup0) { |
870 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops2(*this, v.getType(), "result" , index++))) |
871 | return ::mlir::failure(); |
872 | } |
873 | auto valueGroup1 = getODSResults(1); |
874 | |
875 | for (auto v : valueGroup1) { |
876 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops3(*this, v.getType(), "result" , index++))) |
877 | return ::mlir::failure(); |
878 | } |
879 | } |
880 | return ::mlir::success(); |
881 | } |
882 | |
883 | ::mlir::LogicalResult CaseOp::verifyInvariants() { |
884 | return verifyInvariantsImpl(); |
885 | } |
886 | |
887 | LogicalResult CaseOp::verifySymbolUses( |
888 | SymbolTableCollection &symbol_table) { |
889 | return VerifyCaseLikeOp(*this, symbol_table); |
890 | } |
891 | } // namespace tfg |
892 | } // namespace mlir |
893 | MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::tfg::CaseOp) |
894 | |
895 | namespace mlir { |
896 | namespace tfg { |
897 | |
898 | //===----------------------------------------------------------------------===// |
899 | // ::mlir::tfg::CaseRegionOp definitions |
900 | //===----------------------------------------------------------------------===// |
901 | |
902 | CaseRegionOpAdaptor::CaseRegionOpAdaptor(::mlir::ValueRange values, ::mlir::DictionaryAttr attrs, ::mlir::RegionRange regions) : odsOperands(values), odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) |
903 | odsOpName.emplace("tfg.CaseRegion" , odsAttrs.getContext()); |
904 | } |
905 | |
906 | CaseRegionOpAdaptor::CaseRegionOpAdaptor(CaseRegionOp op) : odsOperands(op->getOperands()), odsAttrs(op->getAttrDictionary()), odsRegions(op->getRegions()), odsOpName(op->getName()) {} |
907 | |
908 | ::mlir::ValueRange CaseRegionOpAdaptor::getOperands() { |
909 | return odsOperands; |
910 | } |
911 | |
912 | std::pair<unsigned, unsigned> CaseRegionOpAdaptor::getODSOperandIndexAndLength(unsigned index) { |
913 | bool isVariadic[] = {false, true}; |
914 | int prevVariadicCount = 0; |
915 | for (unsigned i = 0; i < index; ++i) |
916 | if (isVariadic[i]) ++prevVariadicCount; |
917 | |
918 | // Calculate how many dynamic values a static variadic operand corresponds to. |
919 | // This assumes all static variadic operands have the same dynamic value count. |
920 | int variadicSize = (odsOperands.size() - 1) / 1; |
921 | // `index` passed in as the parameter is the static index which counts each |
922 | // operand (variadic or not) as size 1. So here for each previous static variadic |
923 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
924 | // value pack for this static operand starts. |
925 | int start = index + (variadicSize - 1) * prevVariadicCount; |
926 | int size = isVariadic[index] ? variadicSize : 1; |
927 | return {start, size}; |
928 | } |
929 | |
930 | ::mlir::ValueRange CaseRegionOpAdaptor::getODSOperands(unsigned index) { |
931 | auto valueRange = getODSOperandIndexAndLength(index); |
932 | return {std::next(odsOperands.begin(), valueRange.first), |
933 | std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; |
934 | } |
935 | |
936 | ::mlir::Value CaseRegionOpAdaptor::getBranchIndex() { |
937 | return *getODSOperands(0).begin(); |
938 | } |
939 | |
940 | ::mlir::Value CaseRegionOpAdaptor::branch_index() { |
941 | return *getODSOperands(0).begin(); |
942 | } |
943 | |
944 | ::mlir::ValueRange CaseRegionOpAdaptor::getCtls() { |
945 | return getODSOperands(1); |
946 | } |
947 | |
948 | ::mlir::ValueRange CaseRegionOpAdaptor::ctls() { |
949 | return getODSOperands(1); |
950 | } |
951 | |
952 | ::mlir::DictionaryAttr CaseRegionOpAdaptor::getAttributes() { |
953 | return odsAttrs; |
954 | } |
955 | |
956 | ::mlir::ArrayAttr CaseRegionOpAdaptor::getBranchAttrsAttr() { |
957 | assert(odsAttrs && "no attributes when constructing adapter" ); |
958 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, CaseRegionOp::getBranchAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
959 | return attr; |
960 | } |
961 | |
962 | ::llvm::Optional< ::mlir::ArrayAttr > CaseRegionOpAdaptor::getBranchAttrs() { |
963 | auto attr = getBranchAttrsAttr(); |
964 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
965 | } |
966 | |
967 | ::mlir::ArrayAttr CaseRegionOpAdaptor::branch_attrsAttr() { |
968 | assert(odsAttrs && "no attributes when constructing adapter" ); |
969 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, CaseRegionOp::getBranchAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
970 | return attr; |
971 | } |
972 | |
973 | ::llvm::Optional< ::mlir::ArrayAttr > CaseRegionOpAdaptor::branch_attrs() { |
974 | auto attr = branch_attrsAttr(); |
975 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
976 | } |
977 | |
978 | ::mlir::ArrayAttr CaseRegionOpAdaptor::getRegionAttrsAttr() { |
979 | assert(odsAttrs && "no attributes when constructing adapter" ); |
980 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, CaseRegionOp::getRegionAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
981 | return attr; |
982 | } |
983 | |
984 | ::llvm::Optional< ::mlir::ArrayAttr > CaseRegionOpAdaptor::getRegionAttrs() { |
985 | auto attr = getRegionAttrsAttr(); |
986 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
987 | } |
988 | |
989 | ::mlir::ArrayAttr CaseRegionOpAdaptor::region_attrsAttr() { |
990 | assert(odsAttrs && "no attributes when constructing adapter" ); |
991 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, CaseRegionOp::getRegionAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
992 | return attr; |
993 | } |
994 | |
995 | ::llvm::Optional< ::mlir::ArrayAttr > CaseRegionOpAdaptor::region_attrs() { |
996 | auto attr = region_attrsAttr(); |
997 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
998 | } |
999 | |
1000 | ::mlir::RegionRange CaseRegionOpAdaptor::getRegions() { |
1001 | return odsRegions; |
1002 | } |
1003 | |
1004 | ::mlir::RegionRange CaseRegionOpAdaptor::getBranches() { |
1005 | return odsRegions.drop_front(0); |
1006 | } |
1007 | |
1008 | ::mlir::RegionRange CaseRegionOpAdaptor::branches() { |
1009 | return odsRegions.drop_front(0); |
1010 | } |
1011 | |
1012 | ::mlir::LogicalResult CaseRegionOpAdaptor::verify(::mlir::Location loc) { |
1013 | auto namedAttrRange = odsAttrs; |
1014 | auto namedAttrIt = namedAttrRange.begin(); |
1015 | ::mlir::Attribute tblgen_branch_attrs; |
1016 | ::mlir::Attribute tblgen_region_attrs; |
1017 | while (true) { |
1018 | if (namedAttrIt == namedAttrRange.end()) { |
1019 | break; |
1020 | } |
1021 | else if (namedAttrIt->getName() == CaseRegionOp::getBranchAttrsAttrName(*odsOpName)) { |
1022 | tblgen_branch_attrs = namedAttrIt->getValue(); |
1023 | } |
1024 | else if (namedAttrIt->getName() == CaseRegionOp::getRegionAttrsAttrName(*odsOpName)) { |
1025 | tblgen_region_attrs = namedAttrIt->getValue(); |
1026 | } |
1027 | ++namedAttrIt; |
1028 | } |
1029 | |
1030 | if (tblgen_branch_attrs && !(((tblgen_branch_attrs.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_branch_attrs.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && ((attr.isa<::mlir::DictionaryAttr>())); })))) |
1031 | return emitError(loc, "'tfg.CaseRegion' op " "attribute 'branch_attrs' failed to satisfy constraint: an array of dictionaries" ); |
1032 | |
1033 | if (tblgen_region_attrs && !(((tblgen_region_attrs.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_region_attrs.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && ((attr.isa<::mlir::tfg::RegionAttr>())); })))) |
1034 | return emitError(loc, "'tfg.CaseRegion' op " "attribute 'region_attrs' failed to satisfy constraint: case region preserved attributes" ); |
1035 | return ::mlir::success(); |
1036 | } |
1037 | |
1038 | std::pair<unsigned, unsigned> CaseRegionOp::getODSOperandIndexAndLength(unsigned index) { |
1039 | bool isVariadic[] = {false, true}; |
1040 | int prevVariadicCount = 0; |
1041 | for (unsigned i = 0; i < index; ++i) |
1042 | if (isVariadic[i]) ++prevVariadicCount; |
1043 | |
1044 | // Calculate how many dynamic values a static variadic operand corresponds to. |
1045 | // This assumes all static variadic operands have the same dynamic value count. |
1046 | int variadicSize = (getOperation()->getNumOperands() - 1) / 1; |
1047 | // `index` passed in as the parameter is the static index which counts each |
1048 | // operand (variadic or not) as size 1. So here for each previous static variadic |
1049 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
1050 | // value pack for this static operand starts. |
1051 | int start = index + (variadicSize - 1) * prevVariadicCount; |
1052 | int size = isVariadic[index] ? variadicSize : 1; |
1053 | return {start, size}; |
1054 | } |
1055 | |
1056 | ::mlir::Operation::operand_range CaseRegionOp::getODSOperands(unsigned index) { |
1057 | auto valueRange = getODSOperandIndexAndLength(index); |
1058 | return {std::next(getOperation()->operand_begin(), valueRange.first), |
1059 | std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; |
1060 | } |
1061 | |
1062 | ::mlir::TypedValue<::mlir::TensorType> CaseRegionOp::getBranchIndex() { |
1063 | return *getODSOperands(0).begin(); |
1064 | } |
1065 | |
1066 | ::mlir::TypedValue<::mlir::TensorType> CaseRegionOp::branch_index() { |
1067 | return *getODSOperands(0).begin(); |
1068 | } |
1069 | |
1070 | ::mlir::Operation::operand_range CaseRegionOp::getCtls() { |
1071 | return getODSOperands(1); |
1072 | } |
1073 | |
1074 | ::mlir::Operation::operand_range CaseRegionOp::ctls() { |
1075 | return getODSOperands(1); |
1076 | } |
1077 | |
1078 | ::mlir::MutableOperandRange CaseRegionOp::getBranchIndexMutable() { |
1079 | auto range = getODSOperandIndexAndLength(0); |
1080 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
1081 | return mutableRange; |
1082 | } |
1083 | |
1084 | ::mlir::MutableOperandRange CaseRegionOp::branch_indexMutable() { |
1085 | auto range = getODSOperandIndexAndLength(0); |
1086 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
1087 | return mutableRange; |
1088 | } |
1089 | |
1090 | ::mlir::MutableOperandRange CaseRegionOp::getCtlsMutable() { |
1091 | auto range = getODSOperandIndexAndLength(1); |
1092 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
1093 | return mutableRange; |
1094 | } |
1095 | |
1096 | ::mlir::MutableOperandRange CaseRegionOp::ctlsMutable() { |
1097 | auto range = getODSOperandIndexAndLength(1); |
1098 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
1099 | return mutableRange; |
1100 | } |
1101 | |
1102 | std::pair<unsigned, unsigned> CaseRegionOp::getODSResultIndexAndLength(unsigned index) { |
1103 | bool isVariadic[] = {true, false}; |
1104 | int prevVariadicCount = 0; |
1105 | for (unsigned i = 0; i < index; ++i) |
1106 | if (isVariadic[i]) ++prevVariadicCount; |
1107 | |
1108 | // Calculate how many dynamic values a static variadic operand corresponds to. |
1109 | // This assumes all static variadic operands have the same dynamic value count. |
1110 | int variadicSize = (getOperation()->getNumResults() - 1) / 1; |
1111 | // `index` passed in as the parameter is the static index which counts each |
1112 | // operand (variadic or not) as size 1. So here for each previous static variadic |
1113 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
1114 | // value pack for this static operand starts. |
1115 | int start = index + (variadicSize - 1) * prevVariadicCount; |
1116 | int size = isVariadic[index] ? variadicSize : 1; |
1117 | return {start, size}; |
1118 | } |
1119 | |
1120 | ::mlir::Operation::result_range CaseRegionOp::getODSResults(unsigned index) { |
1121 | auto valueRange = getODSResultIndexAndLength(index); |
1122 | return {std::next(getOperation()->result_begin(), valueRange.first), |
1123 | std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; |
1124 | } |
1125 | |
1126 | ::mlir::Operation::result_range CaseRegionOp::getOuts() { |
1127 | return getODSResults(0); |
1128 | } |
1129 | |
1130 | ::mlir::Operation::result_range CaseRegionOp::outs() { |
1131 | return getODSResults(0); |
1132 | } |
1133 | |
1134 | ::mlir::TypedValue<::mlir::tf_type::ControlType> CaseRegionOp::getCtl() { |
1135 | return *getODSResults(1).begin(); |
1136 | } |
1137 | |
1138 | ::mlir::TypedValue<::mlir::tf_type::ControlType> CaseRegionOp::ctl() { |
1139 | return *getODSResults(1).begin(); |
1140 | } |
1141 | |
1142 | ::mlir::MutableArrayRef<::mlir::Region> CaseRegionOp::getBranches() { |
1143 | return (*this)->getRegions().drop_front(0); |
1144 | } |
1145 | |
1146 | ::mlir::MutableArrayRef<::mlir::Region> CaseRegionOp::branches() { |
1147 | return (*this)->getRegions().drop_front(0); |
1148 | } |
1149 | |
1150 | ::mlir::ArrayAttr CaseRegionOp::getBranchAttrsAttr() { |
1151 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getBranchAttrsAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
1152 | } |
1153 | |
1154 | ::llvm::Optional< ::mlir::ArrayAttr > CaseRegionOp::getBranchAttrs() { |
1155 | auto attr = getBranchAttrsAttr(); |
1156 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
1157 | } |
1158 | |
1159 | ::mlir::ArrayAttr CaseRegionOp::branch_attrsAttr() { |
1160 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getBranchAttrsAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
1161 | } |
1162 | |
1163 | ::llvm::Optional< ::mlir::ArrayAttr > CaseRegionOp::branch_attrs() { |
1164 | auto attr = branch_attrsAttr(); |
1165 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
1166 | } |
1167 | |
1168 | ::mlir::ArrayAttr CaseRegionOp::getRegionAttrsAttr() { |
1169 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getRegionAttrsAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
1170 | } |
1171 | |
1172 | ::llvm::Optional< ::mlir::ArrayAttr > CaseRegionOp::getRegionAttrs() { |
1173 | auto attr = getRegionAttrsAttr(); |
1174 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
1175 | } |
1176 | |
1177 | ::mlir::ArrayAttr CaseRegionOp::region_attrsAttr() { |
1178 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getRegionAttrsAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
1179 | } |
1180 | |
1181 | ::llvm::Optional< ::mlir::ArrayAttr > CaseRegionOp::region_attrs() { |
1182 | auto attr = region_attrsAttr(); |
1183 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
1184 | } |
1185 | |
1186 | void CaseRegionOp::setBranchAttrsAttr(::mlir::ArrayAttr attr) { |
1187 | (*this)->setAttr(getBranchAttrsAttrName(), attr); |
1188 | } |
1189 | |
1190 | void CaseRegionOp::branch_attrsAttr(::mlir::ArrayAttr attr) { |
1191 | (*this)->setAttr(branch_attrsAttrName(), attr); |
1192 | } |
1193 | |
1194 | void CaseRegionOp::setRegionAttrsAttr(::mlir::ArrayAttr attr) { |
1195 | (*this)->setAttr(getRegionAttrsAttrName(), attr); |
1196 | } |
1197 | |
1198 | void CaseRegionOp::region_attrsAttr(::mlir::ArrayAttr attr) { |
1199 | (*this)->setAttr(region_attrsAttrName(), attr); |
1200 | } |
1201 | |
1202 | ::mlir::Attribute CaseRegionOp::removeBranch_attrsAttr() { |
1203 | return (*this)->removeAttr(getBranchAttrsAttrName()); |
1204 | } |
1205 | |
1206 | ::mlir::Attribute CaseRegionOp::removeRegion_attrsAttr() { |
1207 | return (*this)->removeAttr(getRegionAttrsAttrName()); |
1208 | } |
1209 | |
1210 | void CaseRegionOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange outs, ::mlir::Type ctl, ::mlir::Value branch_index, ::mlir::ValueRange ctls, /*optional*/::mlir::ArrayAttr branch_attrs, /*optional*/::mlir::ArrayAttr region_attrs, unsigned branchesCount) { |
1211 | odsState.addOperands(branch_index); |
1212 | odsState.addOperands(ctls); |
1213 | if (branch_attrs) { |
1214 | odsState.addAttribute(getBranchAttrsAttrName(odsState.name), branch_attrs); |
1215 | } |
1216 | if (region_attrs) { |
1217 | odsState.addAttribute(getRegionAttrsAttrName(odsState.name), region_attrs); |
1218 | } |
1219 | for (unsigned i = 0; i < branchesCount; ++i) |
1220 | (void)odsState.addRegion(); |
1221 | odsState.addTypes(outs); |
1222 | odsState.addTypes(ctl); |
1223 | } |
1224 | |
1225 | void CaseRegionOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value branch_index, ::mlir::ValueRange ctls, /*optional*/::mlir::ArrayAttr branch_attrs, /*optional*/::mlir::ArrayAttr region_attrs, unsigned branchesCount) { |
1226 | odsState.addOperands(branch_index); |
1227 | odsState.addOperands(ctls); |
1228 | if (branch_attrs) { |
1229 | odsState.addAttribute(getBranchAttrsAttrName(odsState.name), branch_attrs); |
1230 | } |
1231 | if (region_attrs) { |
1232 | odsState.addAttribute(getRegionAttrsAttrName(odsState.name), region_attrs); |
1233 | } |
1234 | for (unsigned i = 0; i < branchesCount; ++i) |
1235 | (void)odsState.addRegion(); |
1236 | assert(resultTypes.size() >= 1u && "mismatched number of results" ); |
1237 | odsState.addTypes(resultTypes); |
1238 | } |
1239 | |
1240 | void CaseRegionOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes, unsigned numRegions) { |
1241 | assert(operands.size() >= 1u && "mismatched number of parameters" ); |
1242 | odsState.addOperands(operands); |
1243 | odsState.addAttributes(attributes); |
1244 | for (unsigned i = 0; i != numRegions; ++i) |
1245 | (void)odsState.addRegion(); |
1246 | assert(resultTypes.size() >= 1u && "mismatched number of return types" ); |
1247 | odsState.addTypes(resultTypes); |
1248 | } |
1249 | |
1250 | ::mlir::LogicalResult CaseRegionOp::verifyInvariantsImpl() { |
1251 | auto namedAttrRange = (*this)->getAttrs(); |
1252 | auto namedAttrIt = namedAttrRange.begin(); |
1253 | ::mlir::Attribute tblgen_branch_attrs; |
1254 | ::mlir::Attribute tblgen_region_attrs; |
1255 | while (true) { |
1256 | if (namedAttrIt == namedAttrRange.end()) { |
1257 | break; |
1258 | } |
1259 | else if (namedAttrIt->getName() == getBranchAttrsAttrName()) { |
1260 | tblgen_branch_attrs = namedAttrIt->getValue(); |
1261 | } |
1262 | else if (namedAttrIt->getName() == getRegionAttrsAttrName()) { |
1263 | tblgen_region_attrs = namedAttrIt->getValue(); |
1264 | } |
1265 | ++namedAttrIt; |
1266 | } |
1267 | |
1268 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops3(*this, tblgen_branch_attrs, "branch_attrs" ))) |
1269 | return ::mlir::failure(); |
1270 | |
1271 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops4(*this, tblgen_region_attrs, "region_attrs" ))) |
1272 | return ::mlir::failure(); |
1273 | { |
1274 | unsigned index = 0; (void)index; |
1275 | auto valueGroup0 = getODSOperands(0); |
1276 | |
1277 | for (auto v : valueGroup0) { |
1278 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops4(*this, v.getType(), "operand" , index++))) |
1279 | return ::mlir::failure(); |
1280 | } |
1281 | auto valueGroup1 = getODSOperands(1); |
1282 | |
1283 | for (auto v : valueGroup1) { |
1284 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops3(*this, v.getType(), "operand" , index++))) |
1285 | return ::mlir::failure(); |
1286 | } |
1287 | } |
1288 | { |
1289 | unsigned index = 0; (void)index; |
1290 | auto valueGroup0 = getODSResults(0); |
1291 | |
1292 | for (auto v : valueGroup0) { |
1293 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops2(*this, v.getType(), "result" , index++))) |
1294 | return ::mlir::failure(); |
1295 | } |
1296 | auto valueGroup1 = getODSResults(1); |
1297 | |
1298 | for (auto v : valueGroup1) { |
1299 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops3(*this, v.getType(), "result" , index++))) |
1300 | return ::mlir::failure(); |
1301 | } |
1302 | } |
1303 | { |
1304 | unsigned index = 0; (void)index; |
1305 | |
1306 | for (auto ®ion : getBranches()) |
1307 | if (::mlir::failed(__mlir_ods_local_region_constraint_ops0(*this, region, "branches" , index++))) |
1308 | return ::mlir::failure(); |
1309 | } |
1310 | return ::mlir::success(); |
1311 | } |
1312 | |
1313 | ::mlir::LogicalResult CaseRegionOp::verifyInvariants() { |
1314 | if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) |
1315 | return ::mlir::success(); |
1316 | return ::mlir::failure(); |
1317 | } |
1318 | |
1319 | ::mlir::ParseResult CaseRegionOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { |
1320 | ::mlir::OpAsmParser::UnresolvedOperand branch_indexRawOperands[1]; |
1321 | ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> branch_indexOperands(branch_indexRawOperands); ::llvm::SMLoc branch_indexOperandsLoc; |
1322 | (void)branch_indexOperandsLoc; |
1323 | ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> ctlsOperands; |
1324 | ::llvm::SMLoc ctlsOperandsLoc; |
1325 | (void)ctlsOperandsLoc; |
1326 | ::llvm::SmallVector<std::unique_ptr<::mlir::Region>, 2> branchesRegions; |
1327 | ::llvm::ArrayRef<::mlir::Type> branch_indexTypes; |
1328 | ::llvm::ArrayRef<::mlir::Type> outsTypes; |
1329 | |
1330 | branch_indexOperandsLoc = parser.getCurrentLocation(); |
1331 | if (parser.parseOperand(branch_indexRawOperands[0])) |
1332 | return ::mlir::failure(); |
1333 | if (::mlir::succeeded(parser.parseOptionalLSquare())) { |
1334 | |
1335 | ctlsOperandsLoc = parser.getCurrentLocation(); |
1336 | if (parser.parseOperandList(ctlsOperands)) |
1337 | return ::mlir::failure(); |
1338 | if (parser.parseRSquare()) |
1339 | return ::mlir::failure(); |
1340 | } |
1341 | |
1342 | { |
1343 | std::unique_ptr<::mlir::Region> region; |
1344 | auto firstRegionResult = parser.parseOptionalRegion(region); |
1345 | if (firstRegionResult.has_value()) { |
1346 | if (failed(*firstRegionResult)) |
1347 | return ::mlir::failure(); |
1348 | branchesRegions.emplace_back(std::move(region)); |
1349 | |
1350 | // Parse any trailing regions. |
1351 | while (succeeded(parser.parseOptionalComma())) { |
1352 | region = std::make_unique<::mlir::Region>(); |
1353 | if (parser.parseRegion(*region)) |
1354 | return ::mlir::failure(); |
1355 | branchesRegions.emplace_back(std::move(region)); |
1356 | } |
1357 | } |
1358 | } |
1359 | |
1360 | for (auto ®ion : branchesRegions) |
1361 | if (region->empty()) region->emplaceBlock(); |
1362 | if (parser.parseOptionalAttrDict(result.attributes)) |
1363 | return ::mlir::failure(); |
1364 | if (parser.parseColon()) |
1365 | return ::mlir::failure(); |
1366 | |
1367 | ::mlir::FunctionType branch_index__outs_functionType; |
1368 | if (parser.parseType(branch_index__outs_functionType)) |
1369 | return ::mlir::failure(); |
1370 | branch_indexTypes = branch_index__outs_functionType.getInputs(); |
1371 | outsTypes = branch_index__outs_functionType.getResults(); |
1372 | result.addRegions(branchesRegions); |
1373 | ::mlir::Type odsBuildableType0 = parser.getBuilder().getType<::mlir::tf_type::ControlType>(); |
1374 | result.addTypes(outsTypes); |
1375 | result.addTypes(odsBuildableType0); |
1376 | if (parser.resolveOperands(branch_indexOperands, branch_indexTypes, branch_indexOperandsLoc, result.operands)) |
1377 | return ::mlir::failure(); |
1378 | if (parser.resolveOperands(ctlsOperands, odsBuildableType0, ctlsOperandsLoc, result.operands)) |
1379 | return ::mlir::failure(); |
1380 | return ::mlir::success(); |
1381 | } |
1382 | |
1383 | void CaseRegionOp::print(::mlir::OpAsmPrinter &_odsPrinter) { |
1384 | _odsPrinter << ' '; |
1385 | _odsPrinter << getBranchIndex(); |
1386 | if (!getCtls().empty()) { |
1387 | _odsPrinter << ' '; |
1388 | _odsPrinter << "[" ; |
1389 | _odsPrinter << getCtls(); |
1390 | _odsPrinter << "]" ; |
1391 | } |
1392 | _odsPrinter << ' '; |
1393 | llvm::interleaveComma(getBranches(), _odsPrinter, [&](::mlir::Region ®ion) { |
1394 | _odsPrinter.printRegion(region); |
1395 | }); |
1396 | _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), /*elidedAttrs=*/{}); |
1397 | _odsPrinter << ' ' << ":" ; |
1398 | _odsPrinter << ' '; |
1399 | _odsPrinter.printFunctionalType(::llvm::ArrayRef<::mlir::Type>(getBranchIndex().getType()), getOuts().getTypes()); |
1400 | } |
1401 | |
1402 | StringRef CaseRegionOp::getDefaultDialect() { return "tfg" ; } |
1403 | void CaseRegionOp::getAsmResultNames(OpAsmSetValueNameFn setNameFn) { |
1404 | GenericGetAsmResultNames(*this, setNameFn); |
1405 | } |
1406 | |
1407 | YieldOp CaseRegionOp::branch_yield(unsigned idx) { |
1408 | return cast<YieldOp>(branch_block(idx).getTerminator()); |
1409 | } |
1410 | |
1411 | void CaseRegionOp::getSuccessorRegions( |
1412 | Optional<unsigned> index, ArrayRef<Attribute> operands, |
1413 | SmallVectorImpl<RegionSuccessor> ®ions) { |
1414 | GetCaseLikeRegionOpSuccessorRegions(*this, index, operands, regions); |
1415 | } |
1416 | void CaseRegionOp::getRegionInvocationBounds( |
1417 | ArrayRef<Attribute> operands, |
1418 | SmallVectorImpl<InvocationBounds> &invocationBounds) { |
1419 | invocationBounds.append(getNumRegions(), /*Elt=*/{0, 1}); |
1420 | } |
1421 | |
1422 | LogicalResult CaseRegionOp::verify() { return VerifyCaseLikeRegionOp(*this); } |
1423 | |
1424 | BlockArgument CaseRegionOp::getDataValueOf(BlockArgument ctl) { |
1425 | return GetLoopRegionDataOf(ctl); |
1426 | } |
1427 | BlockArgument CaseRegionOp::getControlTokenOf(BlockArgument data) { |
1428 | return GetLoopRegionControlOf(data); |
1429 | } |
1430 | BlockArgument CaseRegionOp::getDataValue(Region ®ion, unsigned idx) { |
1431 | return GetLoopRegionDataArgs(region)[idx]; |
1432 | } |
1433 | BlockArgument CaseRegionOp::getControlToken(Region ®ion, unsigned idx) { |
1434 | return GetLoopRegionControlTokens(region)[idx]; |
1435 | } |
1436 | } // namespace tfg |
1437 | } // namespace mlir |
1438 | MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::tfg::CaseRegionOp) |
1439 | |
1440 | namespace mlir { |
1441 | namespace tfg { |
1442 | |
1443 | //===----------------------------------------------------------------------===// |
1444 | // ::mlir::tfg::ConditionOp definitions |
1445 | //===----------------------------------------------------------------------===// |
1446 | |
1447 | ConditionOpAdaptor::ConditionOpAdaptor(::mlir::ValueRange values, ::mlir::DictionaryAttr attrs, ::mlir::RegionRange regions) : odsOperands(values), odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) |
1448 | odsOpName.emplace("tfg.condition" , odsAttrs.getContext()); |
1449 | } |
1450 | |
1451 | ConditionOpAdaptor::ConditionOpAdaptor(ConditionOp op) : odsOperands(op->getOperands()), odsAttrs(op->getAttrDictionary()), odsRegions(op->getRegions()), odsOpName(op->getName()) {} |
1452 | |
1453 | ::mlir::ValueRange ConditionOpAdaptor::getOperands() { |
1454 | return odsOperands; |
1455 | } |
1456 | |
1457 | std::pair<unsigned, unsigned> ConditionOpAdaptor::getODSOperandIndexAndLength(unsigned index) { |
1458 | assert(odsAttrs && "missing segment size attribute for op" ); |
1459 | auto sizeAttr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, ConditionOp::getOperandSegmentSizesAttrName(*odsOpName)).cast<::mlir::DenseI32ArrayAttr>(); |
1460 | |
1461 | unsigned start = 0; |
1462 | for (unsigned i = 0; i < index; ++i) |
1463 | start += sizeAttr[i]; |
1464 | return {start, sizeAttr[index]}; |
1465 | } |
1466 | |
1467 | ::mlir::ValueRange ConditionOpAdaptor::getODSOperands(unsigned index) { |
1468 | auto valueRange = getODSOperandIndexAndLength(index); |
1469 | return {std::next(odsOperands.begin(), valueRange.first), |
1470 | std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; |
1471 | } |
1472 | |
1473 | ::mlir::Value ConditionOpAdaptor::getCond() { |
1474 | return *getODSOperands(0).begin(); |
1475 | } |
1476 | |
1477 | ::mlir::Value ConditionOpAdaptor::cond() { |
1478 | return *getODSOperands(0).begin(); |
1479 | } |
1480 | |
1481 | ::mlir::ValueRange ConditionOpAdaptor::getArgs() { |
1482 | return getODSOperands(1); |
1483 | } |
1484 | |
1485 | ::mlir::ValueRange ConditionOpAdaptor::args() { |
1486 | return getODSOperands(1); |
1487 | } |
1488 | |
1489 | ::mlir::ValueRange ConditionOpAdaptor::getCtls() { |
1490 | return getODSOperands(2); |
1491 | } |
1492 | |
1493 | ::mlir::ValueRange ConditionOpAdaptor::ctls() { |
1494 | return getODSOperands(2); |
1495 | } |
1496 | |
1497 | ::mlir::DictionaryAttr ConditionOpAdaptor::getAttributes() { |
1498 | return odsAttrs; |
1499 | } |
1500 | |
1501 | ::mlir::LogicalResult ConditionOpAdaptor::verify(::mlir::Location loc) { |
1502 | auto namedAttrRange = odsAttrs; |
1503 | auto namedAttrIt = namedAttrRange.begin(); |
1504 | ::mlir::Attribute tblgen_operand_segment_sizes; |
1505 | while (true) { |
1506 | if (namedAttrIt == namedAttrRange.end()) |
1507 | return emitError(loc, "'tfg.condition' op " "requires attribute 'operand_segment_sizes'" ); |
1508 | if (namedAttrIt->getName() == ConditionOp::getOperandSegmentSizesAttrName(*odsOpName)) { |
1509 | tblgen_operand_segment_sizes = namedAttrIt->getValue(); |
1510 | break; |
1511 | } |
1512 | ++namedAttrIt; |
1513 | } |
1514 | |
1515 | { |
1516 | auto sizeAttr = tblgen_operand_segment_sizes.cast<::mlir::DenseI32ArrayAttr>(); |
1517 | auto numElements = sizeAttr.asArrayRef().size(); |
1518 | if (numElements != 3) |
1519 | return emitError(loc, "'tfg.condition' op " "'operand_segment_sizes' attribute for specifying operand segments must have 3 " |
1520 | "elements, but got " ) << numElements; |
1521 | } |
1522 | return ::mlir::success(); |
1523 | } |
1524 | |
1525 | std::pair<unsigned, unsigned> ConditionOp::getODSOperandIndexAndLength(unsigned index) { |
1526 | auto sizeAttr = ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getOperandSegmentSizesAttrName()).cast<::mlir::DenseI32ArrayAttr>(); |
1527 | |
1528 | unsigned start = 0; |
1529 | for (unsigned i = 0; i < index; ++i) |
1530 | start += sizeAttr[i]; |
1531 | return {start, sizeAttr[index]}; |
1532 | } |
1533 | |
1534 | ::mlir::Operation::operand_range ConditionOp::getODSOperands(unsigned index) { |
1535 | auto valueRange = getODSOperandIndexAndLength(index); |
1536 | return {std::next(getOperation()->operand_begin(), valueRange.first), |
1537 | std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; |
1538 | } |
1539 | |
1540 | ::mlir::TypedValue<::mlir::TensorType> ConditionOp::getCond() { |
1541 | return *getODSOperands(0).begin(); |
1542 | } |
1543 | |
1544 | ::mlir::TypedValue<::mlir::TensorType> ConditionOp::cond() { |
1545 | return *getODSOperands(0).begin(); |
1546 | } |
1547 | |
1548 | ::mlir::Operation::operand_range ConditionOp::getArgs() { |
1549 | return getODSOperands(1); |
1550 | } |
1551 | |
1552 | ::mlir::Operation::operand_range ConditionOp::args() { |
1553 | return getODSOperands(1); |
1554 | } |
1555 | |
1556 | ::mlir::Operation::operand_range ConditionOp::getCtls() { |
1557 | return getODSOperands(2); |
1558 | } |
1559 | |
1560 | ::mlir::Operation::operand_range ConditionOp::ctls() { |
1561 | return getODSOperands(2); |
1562 | } |
1563 | |
1564 | ::mlir::MutableOperandRange ConditionOp::getCondMutable() { |
1565 | auto range = getODSOperandIndexAndLength(0); |
1566 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(0u, *::mlir::impl::getNamedAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getOperandSegmentSizesAttrName()))); |
1567 | return mutableRange; |
1568 | } |
1569 | |
1570 | ::mlir::MutableOperandRange ConditionOp::condMutable() { |
1571 | auto range = getODSOperandIndexAndLength(0); |
1572 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(0u, *::mlir::impl::getNamedAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getOperandSegmentSizesAttrName()))); |
1573 | return mutableRange; |
1574 | } |
1575 | |
1576 | ::mlir::MutableOperandRange ConditionOp::getArgsMutable() { |
1577 | auto range = getODSOperandIndexAndLength(1); |
1578 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(1u, *::mlir::impl::getNamedAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getOperandSegmentSizesAttrName()))); |
1579 | return mutableRange; |
1580 | } |
1581 | |
1582 | ::mlir::MutableOperandRange ConditionOp::argsMutable() { |
1583 | auto range = getODSOperandIndexAndLength(1); |
1584 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(1u, *::mlir::impl::getNamedAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getOperandSegmentSizesAttrName()))); |
1585 | return mutableRange; |
1586 | } |
1587 | |
1588 | ::mlir::MutableOperandRange ConditionOp::getCtlsMutable() { |
1589 | auto range = getODSOperandIndexAndLength(2); |
1590 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(2u, *::mlir::impl::getNamedAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getOperandSegmentSizesAttrName()))); |
1591 | return mutableRange; |
1592 | } |
1593 | |
1594 | ::mlir::MutableOperandRange ConditionOp::ctlsMutable() { |
1595 | auto range = getODSOperandIndexAndLength(2); |
1596 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(2u, *::mlir::impl::getNamedAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getOperandSegmentSizesAttrName()))); |
1597 | return mutableRange; |
1598 | } |
1599 | |
1600 | std::pair<unsigned, unsigned> ConditionOp::getODSResultIndexAndLength(unsigned index) { |
1601 | return {index, 1}; |
1602 | } |
1603 | |
1604 | ::mlir::Operation::result_range ConditionOp::getODSResults(unsigned index) { |
1605 | auto valueRange = getODSResultIndexAndLength(index); |
1606 | return {std::next(getOperation()->result_begin(), valueRange.first), |
1607 | std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; |
1608 | } |
1609 | |
1610 | void ConditionOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Value cond, ::mlir::ValueRange args, ::mlir::ValueRange ctls) { |
1611 | odsState.addOperands(cond); |
1612 | odsState.addOperands(args); |
1613 | odsState.addOperands(ctls); |
1614 | odsState.addAttribute(getOperandSegmentSizesAttrName(odsState.name), odsBuilder.getDenseI32ArrayAttr({1, static_cast<int32_t>(args.size()), static_cast<int32_t>(ctls.size())})); |
1615 | } |
1616 | |
1617 | void ConditionOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value cond, ::mlir::ValueRange args, ::mlir::ValueRange ctls) { |
1618 | odsState.addOperands(cond); |
1619 | odsState.addOperands(args); |
1620 | odsState.addOperands(ctls); |
1621 | odsState.addAttribute(getOperandSegmentSizesAttrName(odsState.name), odsBuilder.getDenseI32ArrayAttr({1, static_cast<int32_t>(args.size()), static_cast<int32_t>(ctls.size())})); |
1622 | assert(resultTypes.size() == 0u && "mismatched number of results" ); |
1623 | odsState.addTypes(resultTypes); |
1624 | } |
1625 | |
1626 | void ConditionOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { |
1627 | assert(operands.size() >= 1u && "mismatched number of parameters" ); |
1628 | odsState.addOperands(operands); |
1629 | odsState.addAttributes(attributes); |
1630 | assert(resultTypes.size() == 0u && "mismatched number of return types" ); |
1631 | odsState.addTypes(resultTypes); |
1632 | } |
1633 | |
1634 | ::mlir::LogicalResult ConditionOp::verifyInvariantsImpl() { |
1635 | auto namedAttrRange = (*this)->getAttrs(); |
1636 | auto namedAttrIt = namedAttrRange.begin(); |
1637 | ::mlir::Attribute tblgen_operand_segment_sizes; |
1638 | while (true) { |
1639 | if (namedAttrIt == namedAttrRange.end()) |
1640 | return emitOpError("requires attribute 'operand_segment_sizes'" ); |
1641 | if (namedAttrIt->getName() == getOperandSegmentSizesAttrName()) { |
1642 | tblgen_operand_segment_sizes = namedAttrIt->getValue(); |
1643 | break; |
1644 | } |
1645 | ++namedAttrIt; |
1646 | } |
1647 | |
1648 | { |
1649 | auto sizeAttr = tblgen_operand_segment_sizes.cast<::mlir::DenseI32ArrayAttr>(); |
1650 | auto numElements = sizeAttr.asArrayRef().size(); |
1651 | if (numElements != 3) |
1652 | return emitOpError("'operand_segment_sizes' attribute for specifying operand segments must have 3 " |
1653 | "elements, but got " ) << numElements; |
1654 | } |
1655 | { |
1656 | unsigned index = 0; (void)index; |
1657 | auto valueGroup0 = getODSOperands(0); |
1658 | |
1659 | for (auto v : valueGroup0) { |
1660 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops5(*this, v.getType(), "operand" , index++))) |
1661 | return ::mlir::failure(); |
1662 | } |
1663 | auto valueGroup1 = getODSOperands(1); |
1664 | |
1665 | for (auto v : valueGroup1) { |
1666 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops2(*this, v.getType(), "operand" , index++))) |
1667 | return ::mlir::failure(); |
1668 | } |
1669 | auto valueGroup2 = getODSOperands(2); |
1670 | |
1671 | for (auto v : valueGroup2) { |
1672 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops3(*this, v.getType(), "operand" , index++))) |
1673 | return ::mlir::failure(); |
1674 | } |
1675 | } |
1676 | return ::mlir::success(); |
1677 | } |
1678 | |
1679 | ::mlir::LogicalResult ConditionOp::verifyInvariants() { |
1680 | return verifyInvariantsImpl(); |
1681 | } |
1682 | |
1683 | ::mlir::ParseResult ConditionOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { |
1684 | ::mlir::OpAsmParser::UnresolvedOperand condRawOperands[1]; |
1685 | ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> condOperands(condRawOperands); ::llvm::SMLoc condOperandsLoc; |
1686 | (void)condOperandsLoc; |
1687 | ::mlir::Type condRawTypes[1]; |
1688 | ::llvm::ArrayRef<::mlir::Type> condTypes(condRawTypes); |
1689 | ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> argsOperands; |
1690 | ::llvm::SMLoc argsOperandsLoc; |
1691 | (void)argsOperandsLoc; |
1692 | ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> ctlsOperands; |
1693 | ::llvm::SMLoc ctlsOperandsLoc; |
1694 | (void)ctlsOperandsLoc; |
1695 | ::llvm::SmallVector<::mlir::Type, 1> argsTypes; |
1696 | |
1697 | condOperandsLoc = parser.getCurrentLocation(); |
1698 | if (parser.parseOperand(condRawOperands[0])) |
1699 | return ::mlir::failure(); |
1700 | if (parser.parseColon()) |
1701 | return ::mlir::failure(); |
1702 | |
1703 | { |
1704 | ::mlir::TensorType type; |
1705 | if (parser.parseCustomTypeWithFallback(type)) |
1706 | return ::mlir::failure(); |
1707 | condRawTypes[0] = type; |
1708 | } |
1709 | if (::mlir::succeeded(parser.parseOptionalLParen())) { |
1710 | |
1711 | argsOperandsLoc = parser.getCurrentLocation(); |
1712 | if (parser.parseOperandList(argsOperands)) |
1713 | return ::mlir::failure(); |
1714 | if (parser.parseRParen()) |
1715 | return ::mlir::failure(); |
1716 | } |
1717 | if (::mlir::succeeded(parser.parseOptionalLSquare())) { |
1718 | |
1719 | ctlsOperandsLoc = parser.getCurrentLocation(); |
1720 | if (parser.parseOperandList(ctlsOperands)) |
1721 | return ::mlir::failure(); |
1722 | if (parser.parseRSquare()) |
1723 | return ::mlir::failure(); |
1724 | } |
1725 | if (parser.parseOptionalAttrDict(result.attributes)) |
1726 | return ::mlir::failure(); |
1727 | if (::mlir::succeeded(parser.parseOptionalColon())) { |
1728 | |
1729 | if (parser.parseTypeList(argsTypes)) |
1730 | return ::mlir::failure(); |
1731 | } |
1732 | result.addAttribute("operand_segment_sizes" , parser.getBuilder().getDenseI32ArrayAttr({1, static_cast<int32_t>(argsOperands.size()), static_cast<int32_t>(ctlsOperands.size())})); |
1733 | ::mlir::Type odsBuildableType0 = parser.getBuilder().getType<::mlir::tf_type::ControlType>(); |
1734 | if (parser.resolveOperands(condOperands, condTypes, condOperandsLoc, result.operands)) |
1735 | return ::mlir::failure(); |
1736 | if (parser.resolveOperands(argsOperands, argsTypes, argsOperandsLoc, result.operands)) |
1737 | return ::mlir::failure(); |
1738 | if (parser.resolveOperands(ctlsOperands, odsBuildableType0, ctlsOperandsLoc, result.operands)) |
1739 | return ::mlir::failure(); |
1740 | return ::mlir::success(); |
1741 | } |
1742 | |
1743 | void ConditionOp::print(::mlir::OpAsmPrinter &_odsPrinter) { |
1744 | _odsPrinter << ' '; |
1745 | _odsPrinter << getCond(); |
1746 | _odsPrinter << ' ' << ":" ; |
1747 | _odsPrinter << ' '; |
1748 | { |
1749 | auto type = getCond().getType(); |
1750 | if (auto validType = type.dyn_cast<::mlir::TensorType>()) |
1751 | _odsPrinter.printStrippedAttrOrType(validType); |
1752 | else |
1753 | _odsPrinter << type; |
1754 | } |
1755 | if (!getArgs().empty()) { |
1756 | _odsPrinter << ' '; |
1757 | _odsPrinter << "(" ; |
1758 | _odsPrinter << getArgs(); |
1759 | _odsPrinter << ")" ; |
1760 | } |
1761 | if (!getCtls().empty()) { |
1762 | _odsPrinter << ' ' << "[" ; |
1763 | _odsPrinter << getCtls(); |
1764 | _odsPrinter << "]" ; |
1765 | } |
1766 | _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), /*elidedAttrs=*/{"operand_segment_sizes" , }); |
1767 | if (!getArgs().empty()) { |
1768 | _odsPrinter << ' ' << ":" ; |
1769 | _odsPrinter << ' '; |
1770 | _odsPrinter << getArgs().getTypes(); |
1771 | } |
1772 | } |
1773 | |
1774 | void ConditionOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { |
1775 | } |
1776 | |
1777 | } // namespace tfg |
1778 | } // namespace mlir |
1779 | MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::tfg::ConditionOp) |
1780 | |
1781 | namespace mlir { |
1782 | namespace tfg { |
1783 | |
1784 | //===----------------------------------------------------------------------===// |
1785 | // ::mlir::tfg::ForOp definitions |
1786 | //===----------------------------------------------------------------------===// |
1787 | |
1788 | ForOpAdaptor::ForOpAdaptor(::mlir::ValueRange values, ::mlir::DictionaryAttr attrs, ::mlir::RegionRange regions) : odsOperands(values), odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) |
1789 | odsOpName.emplace("tfg.For" , odsAttrs.getContext()); |
1790 | } |
1791 | |
1792 | ForOpAdaptor::ForOpAdaptor(ForOp op) : odsOperands(op->getOperands()), odsAttrs(op->getAttrDictionary()), odsRegions(op->getRegions()), odsOpName(op->getName()) {} |
1793 | |
1794 | ::mlir::ValueRange ForOpAdaptor::getOperands() { |
1795 | return odsOperands; |
1796 | } |
1797 | |
1798 | std::pair<unsigned, unsigned> ForOpAdaptor::getODSOperandIndexAndLength(unsigned index) { |
1799 | bool isVariadic[] = {false, false, false, true}; |
1800 | int prevVariadicCount = 0; |
1801 | for (unsigned i = 0; i < index; ++i) |
1802 | if (isVariadic[i]) ++prevVariadicCount; |
1803 | |
1804 | // Calculate how many dynamic values a static variadic operand corresponds to. |
1805 | // This assumes all static variadic operands have the same dynamic value count. |
1806 | int variadicSize = (odsOperands.size() - 3) / 1; |
1807 | // `index` passed in as the parameter is the static index which counts each |
1808 | // operand (variadic or not) as size 1. So here for each previous static variadic |
1809 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
1810 | // value pack for this static operand starts. |
1811 | int start = index + (variadicSize - 1) * prevVariadicCount; |
1812 | int size = isVariadic[index] ? variadicSize : 1; |
1813 | return {start, size}; |
1814 | } |
1815 | |
1816 | ::mlir::ValueRange ForOpAdaptor::getODSOperands(unsigned index) { |
1817 | auto valueRange = getODSOperandIndexAndLength(index); |
1818 | return {std::next(odsOperands.begin(), valueRange.first), |
1819 | std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; |
1820 | } |
1821 | |
1822 | ::mlir::Value ForOpAdaptor::getStart() { |
1823 | return *getODSOperands(0).begin(); |
1824 | } |
1825 | |
1826 | ::mlir::Value ForOpAdaptor::start() { |
1827 | return *getODSOperands(0).begin(); |
1828 | } |
1829 | |
1830 | ::mlir::Value ForOpAdaptor::getLimit() { |
1831 | return *getODSOperands(1).begin(); |
1832 | } |
1833 | |
1834 | ::mlir::Value ForOpAdaptor::limit() { |
1835 | return *getODSOperands(1).begin(); |
1836 | } |
1837 | |
1838 | ::mlir::Value ForOpAdaptor::getDelta() { |
1839 | return *getODSOperands(2).begin(); |
1840 | } |
1841 | |
1842 | ::mlir::Value ForOpAdaptor::delta() { |
1843 | return *getODSOperands(2).begin(); |
1844 | } |
1845 | |
1846 | ::mlir::ValueRange ForOpAdaptor::getArgs() { |
1847 | return getODSOperands(3); |
1848 | } |
1849 | |
1850 | ::mlir::ValueRange ForOpAdaptor::args() { |
1851 | return getODSOperands(3); |
1852 | } |
1853 | |
1854 | ::mlir::DictionaryAttr ForOpAdaptor::getAttributes() { |
1855 | return odsAttrs; |
1856 | } |
1857 | |
1858 | ::mlir::tf_type::FuncAttr ForOpAdaptor::getBodyAttr() { |
1859 | assert(odsAttrs && "no attributes when constructing adapter" ); |
1860 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, ForOp::getBodyAttrName(*odsOpName)).cast<::mlir::tf_type::FuncAttr>(); |
1861 | return attr; |
1862 | } |
1863 | |
1864 | ::mlir::tf_type::FuncAttr ForOpAdaptor::getBody() { |
1865 | auto attr = getBodyAttr(); |
1866 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
1867 | } |
1868 | |
1869 | ::mlir::tf_type::FuncAttr ForOpAdaptor::bodyAttr() { |
1870 | assert(odsAttrs && "no attributes when constructing adapter" ); |
1871 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, ForOp::getBodyAttrName(*odsOpName)).cast<::mlir::tf_type::FuncAttr>(); |
1872 | return attr; |
1873 | } |
1874 | |
1875 | ::mlir::tf_type::FuncAttr ForOpAdaptor::body() { |
1876 | auto attr = bodyAttr(); |
1877 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
1878 | } |
1879 | |
1880 | ::mlir::ArrayAttr ForOpAdaptor::getTAttr() { |
1881 | assert(odsAttrs && "no attributes when constructing adapter" ); |
1882 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 1, ForOp::getTAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
1883 | return attr; |
1884 | } |
1885 | |
1886 | ::llvm::Optional< ::mlir::ArrayAttr > ForOpAdaptor::getT() { |
1887 | auto attr = getTAttr(); |
1888 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
1889 | } |
1890 | |
1891 | ::mlir::ArrayAttr ForOpAdaptor::TAttr() { |
1892 | assert(odsAttrs && "no attributes when constructing adapter" ); |
1893 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 1, ForOp::getTAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
1894 | return attr; |
1895 | } |
1896 | |
1897 | ::llvm::Optional< ::mlir::ArrayAttr > ForOpAdaptor::T() { |
1898 | auto attr = TAttr(); |
1899 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
1900 | } |
1901 | |
1902 | ::mlir::LogicalResult ForOpAdaptor::verify(::mlir::Location loc) { |
1903 | auto namedAttrRange = odsAttrs; |
1904 | auto namedAttrIt = namedAttrRange.begin(); |
1905 | ::mlir::Attribute tblgen_body; |
1906 | ::mlir::Attribute tblgen_T; |
1907 | while (true) { |
1908 | if (namedAttrIt == namedAttrRange.end()) |
1909 | return emitError(loc, "'tfg.For' op " "requires attribute 'body'" ); |
1910 | if (namedAttrIt->getName() == ForOp::getBodyAttrName(*odsOpName)) { |
1911 | tblgen_body = namedAttrIt->getValue(); |
1912 | break; |
1913 | } |
1914 | else if (namedAttrIt->getName() == ForOp::getTAttrName(*odsOpName)) { |
1915 | tblgen_T = namedAttrIt->getValue(); |
1916 | } |
1917 | ++namedAttrIt; |
1918 | } |
1919 | |
1920 | if (tblgen_body && !((tblgen_body.isa<::mlir::tf_type::FuncAttr>()))) |
1921 | return emitError(loc, "'tfg.For' op " "attribute 'body' failed to satisfy constraint: Models the `AttrValue.value.func` proto attribute value as a pair of SymbolRef and DictionaryAttr" ); |
1922 | |
1923 | if (tblgen_T && !(((tblgen_T.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_T.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && (((attr.isa<::mlir::TypeAttr>())) && ((attr.cast<::mlir::TypeAttr>().getValue().isa<::mlir::Type>()))); })))) |
1924 | return emitError(loc, "'tfg.For' op " "attribute 'T' failed to satisfy constraint: type array attribute" ); |
1925 | return ::mlir::success(); |
1926 | } |
1927 | |
1928 | void ForOp::getAsmResultNames(::mlir::OpAsmSetValueNameFn setNameFn) { |
1929 | auto resultGroup0 = getODSResults(0); |
1930 | if (!resultGroup0.empty()) |
1931 | setNameFn(*resultGroup0.begin(), "outs" ); |
1932 | auto resultGroup1 = getODSResults(1); |
1933 | if (!resultGroup1.empty()) |
1934 | setNameFn(*resultGroup1.begin(), "ctl" ); |
1935 | } |
1936 | |
1937 | std::pair<unsigned, unsigned> ForOp::getODSOperandIndexAndLength(unsigned index) { |
1938 | bool isVariadic[] = {false, false, false, true}; |
1939 | int prevVariadicCount = 0; |
1940 | for (unsigned i = 0; i < index; ++i) |
1941 | if (isVariadic[i]) ++prevVariadicCount; |
1942 | |
1943 | // Calculate how many dynamic values a static variadic operand corresponds to. |
1944 | // This assumes all static variadic operands have the same dynamic value count. |
1945 | int variadicSize = (getOperation()->getNumOperands() - 3) / 1; |
1946 | // `index` passed in as the parameter is the static index which counts each |
1947 | // operand (variadic or not) as size 1. So here for each previous static variadic |
1948 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
1949 | // value pack for this static operand starts. |
1950 | int start = index + (variadicSize - 1) * prevVariadicCount; |
1951 | int size = isVariadic[index] ? variadicSize : 1; |
1952 | return {start, size}; |
1953 | } |
1954 | |
1955 | ::mlir::Operation::operand_range ForOp::getODSOperands(unsigned index) { |
1956 | auto valueRange = getODSOperandIndexAndLength(index); |
1957 | return {std::next(getOperation()->operand_begin(), valueRange.first), |
1958 | std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; |
1959 | } |
1960 | |
1961 | ::mlir::Value ForOp::getStart() { |
1962 | return *getODSOperands(0).begin(); |
1963 | } |
1964 | |
1965 | ::mlir::Value ForOp::start() { |
1966 | return *getODSOperands(0).begin(); |
1967 | } |
1968 | |
1969 | ::mlir::Value ForOp::getLimit() { |
1970 | return *getODSOperands(1).begin(); |
1971 | } |
1972 | |
1973 | ::mlir::Value ForOp::limit() { |
1974 | return *getODSOperands(1).begin(); |
1975 | } |
1976 | |
1977 | ::mlir::Value ForOp::getDelta() { |
1978 | return *getODSOperands(2).begin(); |
1979 | } |
1980 | |
1981 | ::mlir::Value ForOp::delta() { |
1982 | return *getODSOperands(2).begin(); |
1983 | } |
1984 | |
1985 | ::mlir::Operation::operand_range ForOp::getArgs() { |
1986 | return getODSOperands(3); |
1987 | } |
1988 | |
1989 | ::mlir::Operation::operand_range ForOp::args() { |
1990 | return getODSOperands(3); |
1991 | } |
1992 | |
1993 | ::mlir::MutableOperandRange ForOp::getStartMutable() { |
1994 | auto range = getODSOperandIndexAndLength(0); |
1995 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
1996 | return mutableRange; |
1997 | } |
1998 | |
1999 | ::mlir::MutableOperandRange ForOp::startMutable() { |
2000 | auto range = getODSOperandIndexAndLength(0); |
2001 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
2002 | return mutableRange; |
2003 | } |
2004 | |
2005 | ::mlir::MutableOperandRange ForOp::getLimitMutable() { |
2006 | auto range = getODSOperandIndexAndLength(1); |
2007 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
2008 | return mutableRange; |
2009 | } |
2010 | |
2011 | ::mlir::MutableOperandRange ForOp::limitMutable() { |
2012 | auto range = getODSOperandIndexAndLength(1); |
2013 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
2014 | return mutableRange; |
2015 | } |
2016 | |
2017 | ::mlir::MutableOperandRange ForOp::getDeltaMutable() { |
2018 | auto range = getODSOperandIndexAndLength(2); |
2019 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
2020 | return mutableRange; |
2021 | } |
2022 | |
2023 | ::mlir::MutableOperandRange ForOp::deltaMutable() { |
2024 | auto range = getODSOperandIndexAndLength(2); |
2025 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
2026 | return mutableRange; |
2027 | } |
2028 | |
2029 | ::mlir::MutableOperandRange ForOp::getArgsMutable() { |
2030 | auto range = getODSOperandIndexAndLength(3); |
2031 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
2032 | return mutableRange; |
2033 | } |
2034 | |
2035 | ::mlir::MutableOperandRange ForOp::argsMutable() { |
2036 | auto range = getODSOperandIndexAndLength(3); |
2037 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
2038 | return mutableRange; |
2039 | } |
2040 | |
2041 | std::pair<unsigned, unsigned> ForOp::getODSResultIndexAndLength(unsigned index) { |
2042 | bool isVariadic[] = {true, false}; |
2043 | int prevVariadicCount = 0; |
2044 | for (unsigned i = 0; i < index; ++i) |
2045 | if (isVariadic[i]) ++prevVariadicCount; |
2046 | |
2047 | // Calculate how many dynamic values a static variadic operand corresponds to. |
2048 | // This assumes all static variadic operands have the same dynamic value count. |
2049 | int variadicSize = (getOperation()->getNumResults() - 1) / 1; |
2050 | // `index` passed in as the parameter is the static index which counts each |
2051 | // operand (variadic or not) as size 1. So here for each previous static variadic |
2052 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
2053 | // value pack for this static operand starts. |
2054 | int start = index + (variadicSize - 1) * prevVariadicCount; |
2055 | int size = isVariadic[index] ? variadicSize : 1; |
2056 | return {start, size}; |
2057 | } |
2058 | |
2059 | ::mlir::Operation::result_range ForOp::getODSResults(unsigned index) { |
2060 | auto valueRange = getODSResultIndexAndLength(index); |
2061 | return {std::next(getOperation()->result_begin(), valueRange.first), |
2062 | std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; |
2063 | } |
2064 | |
2065 | ::mlir::Operation::result_range ForOp::getOuts() { |
2066 | return getODSResults(0); |
2067 | } |
2068 | |
2069 | ::mlir::Operation::result_range ForOp::outs() { |
2070 | return getODSResults(0); |
2071 | } |
2072 | |
2073 | ::mlir::TypedValue<::mlir::tf_type::ControlType> ForOp::getCtl() { |
2074 | return *getODSResults(1).begin(); |
2075 | } |
2076 | |
2077 | ::mlir::TypedValue<::mlir::tf_type::ControlType> ForOp::ctl() { |
2078 | return *getODSResults(1).begin(); |
2079 | } |
2080 | |
2081 | ::mlir::tf_type::FuncAttr ForOp::getBodyAttr() { |
2082 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getBodyAttrName()).cast<::mlir::tf_type::FuncAttr>(); |
2083 | } |
2084 | |
2085 | ::mlir::tf_type::FuncAttr ForOp::getBody() { |
2086 | auto attr = getBodyAttr(); |
2087 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
2088 | } |
2089 | |
2090 | ::mlir::tf_type::FuncAttr ForOp::bodyAttr() { |
2091 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getBodyAttrName()).cast<::mlir::tf_type::FuncAttr>(); |
2092 | } |
2093 | |
2094 | ::mlir::tf_type::FuncAttr ForOp::body() { |
2095 | auto attr = bodyAttr(); |
2096 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
2097 | } |
2098 | |
2099 | ::mlir::ArrayAttr ForOp::getTAttr() { |
2100 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getTAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
2101 | } |
2102 | |
2103 | ::llvm::Optional< ::mlir::ArrayAttr > ForOp::getT() { |
2104 | auto attr = getTAttr(); |
2105 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
2106 | } |
2107 | |
2108 | ::mlir::ArrayAttr ForOp::TAttr() { |
2109 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getTAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
2110 | } |
2111 | |
2112 | ::llvm::Optional< ::mlir::ArrayAttr > ForOp::T() { |
2113 | auto attr = TAttr(); |
2114 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
2115 | } |
2116 | |
2117 | void ForOp::setBodyAttr(::mlir::tf_type::FuncAttr attr) { |
2118 | (*this)->setAttr(getBodyAttrName(), attr); |
2119 | } |
2120 | |
2121 | void ForOp::bodyAttr(::mlir::tf_type::FuncAttr attr) { |
2122 | (*this)->setAttr(bodyAttrName(), attr); |
2123 | } |
2124 | |
2125 | void ForOp::setTAttr(::mlir::ArrayAttr attr) { |
2126 | (*this)->setAttr(getTAttrName(), attr); |
2127 | } |
2128 | |
2129 | void ForOp::TAttr(::mlir::ArrayAttr attr) { |
2130 | (*this)->setAttr(TAttrName(), attr); |
2131 | } |
2132 | |
2133 | ::mlir::Attribute ForOp::removeTAttr() { |
2134 | return (*this)->removeAttr(getTAttrName()); |
2135 | } |
2136 | |
2137 | void ForOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, TypeRange results, Value start, Value limit, Value delta, ValueRange args, FuncAttr body) { |
2138 | build(odsBuilder, odsState, results, start, limit, delta, args, body, |
2139 | /*T=*/{}); |
2140 | |
2141 | } |
2142 | |
2143 | void ForOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange outs, ::mlir::Type ctl, ::mlir::Value start, ::mlir::Value limit, ::mlir::Value delta, ::mlir::ValueRange args, ::mlir::tf_type::FuncAttr body, /*optional*/::mlir::ArrayAttr T) { |
2144 | odsState.addOperands(start); |
2145 | odsState.addOperands(limit); |
2146 | odsState.addOperands(delta); |
2147 | odsState.addOperands(args); |
2148 | odsState.addAttribute(getBodyAttrName(odsState.name), body); |
2149 | if (T) { |
2150 | odsState.addAttribute(getTAttrName(odsState.name), T); |
2151 | } |
2152 | odsState.addTypes(outs); |
2153 | odsState.addTypes(ctl); |
2154 | } |
2155 | |
2156 | void ForOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value start, ::mlir::Value limit, ::mlir::Value delta, ::mlir::ValueRange args, ::mlir::tf_type::FuncAttr body, /*optional*/::mlir::ArrayAttr T) { |
2157 | odsState.addOperands(start); |
2158 | odsState.addOperands(limit); |
2159 | odsState.addOperands(delta); |
2160 | odsState.addOperands(args); |
2161 | odsState.addAttribute(getBodyAttrName(odsState.name), body); |
2162 | if (T) { |
2163 | odsState.addAttribute(getTAttrName(odsState.name), T); |
2164 | } |
2165 | assert(resultTypes.size() >= 1u && "mismatched number of results" ); |
2166 | odsState.addTypes(resultTypes); |
2167 | } |
2168 | |
2169 | void ForOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { |
2170 | assert(operands.size() >= 3u && "mismatched number of parameters" ); |
2171 | odsState.addOperands(operands); |
2172 | odsState.addAttributes(attributes); |
2173 | assert(resultTypes.size() >= 1u && "mismatched number of return types" ); |
2174 | odsState.addTypes(resultTypes); |
2175 | } |
2176 | |
2177 | ::mlir::LogicalResult ForOp::verifyInvariantsImpl() { |
2178 | auto namedAttrRange = (*this)->getAttrs(); |
2179 | auto namedAttrIt = namedAttrRange.begin(); |
2180 | ::mlir::Attribute tblgen_body; |
2181 | ::mlir::Attribute tblgen_T; |
2182 | while (true) { |
2183 | if (namedAttrIt == namedAttrRange.end()) |
2184 | return emitOpError("requires attribute 'body'" ); |
2185 | if (namedAttrIt->getName() == getBodyAttrName()) { |
2186 | tblgen_body = namedAttrIt->getValue(); |
2187 | break; |
2188 | } |
2189 | else if (namedAttrIt->getName() == getTAttrName()) { |
2190 | tblgen_T = namedAttrIt->getValue(); |
2191 | } |
2192 | ++namedAttrIt; |
2193 | } |
2194 | |
2195 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops5(*this, tblgen_body, "body" ))) |
2196 | return ::mlir::failure(); |
2197 | |
2198 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops1(*this, tblgen_T, "T" ))) |
2199 | return ::mlir::failure(); |
2200 | { |
2201 | unsigned index = 0; (void)index; |
2202 | auto valueGroup0 = getODSOperands(0); |
2203 | |
2204 | for (auto v : valueGroup0) { |
2205 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops0(*this, v.getType(), "operand" , index++))) |
2206 | return ::mlir::failure(); |
2207 | } |
2208 | auto valueGroup1 = getODSOperands(1); |
2209 | |
2210 | for (auto v : valueGroup1) { |
2211 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops0(*this, v.getType(), "operand" , index++))) |
2212 | return ::mlir::failure(); |
2213 | } |
2214 | auto valueGroup2 = getODSOperands(2); |
2215 | |
2216 | for (auto v : valueGroup2) { |
2217 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops0(*this, v.getType(), "operand" , index++))) |
2218 | return ::mlir::failure(); |
2219 | } |
2220 | auto valueGroup3 = getODSOperands(3); |
2221 | |
2222 | for (auto v : valueGroup3) { |
2223 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops1(*this, v.getType(), "operand" , index++))) |
2224 | return ::mlir::failure(); |
2225 | } |
2226 | } |
2227 | { |
2228 | unsigned index = 0; (void)index; |
2229 | auto valueGroup0 = getODSResults(0); |
2230 | |
2231 | for (auto v : valueGroup0) { |
2232 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops2(*this, v.getType(), "result" , index++))) |
2233 | return ::mlir::failure(); |
2234 | } |
2235 | auto valueGroup1 = getODSResults(1); |
2236 | |
2237 | for (auto v : valueGroup1) { |
2238 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops3(*this, v.getType(), "result" , index++))) |
2239 | return ::mlir::failure(); |
2240 | } |
2241 | } |
2242 | return ::mlir::success(); |
2243 | } |
2244 | |
2245 | ::mlir::LogicalResult ForOp::verifyInvariants() { |
2246 | return verifyInvariantsImpl(); |
2247 | } |
2248 | |
2249 | } // namespace tfg |
2250 | } // namespace mlir |
2251 | MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::tfg::ForOp) |
2252 | |
2253 | namespace mlir { |
2254 | namespace tfg { |
2255 | |
2256 | //===----------------------------------------------------------------------===// |
2257 | // ::mlir::tfg::ForRegionOp definitions |
2258 | //===----------------------------------------------------------------------===// |
2259 | |
2260 | ForRegionOpAdaptor::ForRegionOpAdaptor(::mlir::ValueRange values, ::mlir::DictionaryAttr attrs, ::mlir::RegionRange regions) : odsOperands(values), odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) |
2261 | odsOpName.emplace("tfg.ForRegion" , odsAttrs.getContext()); |
2262 | } |
2263 | |
2264 | ForRegionOpAdaptor::ForRegionOpAdaptor(ForRegionOp op) : odsOperands(op->getOperands()), odsAttrs(op->getAttrDictionary()), odsRegions(op->getRegions()), odsOpName(op->getName()) {} |
2265 | |
2266 | ::mlir::ValueRange ForRegionOpAdaptor::getOperands() { |
2267 | return odsOperands; |
2268 | } |
2269 | |
2270 | std::pair<unsigned, unsigned> ForRegionOpAdaptor::getODSOperandIndexAndLength(unsigned index) { |
2271 | assert(odsAttrs && "missing segment size attribute for op" ); |
2272 | auto sizeAttr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, ForRegionOp::getOperandSegmentSizesAttrName(*odsOpName)).cast<::mlir::DenseI32ArrayAttr>(); |
2273 | |
2274 | unsigned start = 0; |
2275 | for (unsigned i = 0; i < index; ++i) |
2276 | start += sizeAttr[i]; |
2277 | return {start, sizeAttr[index]}; |
2278 | } |
2279 | |
2280 | ::mlir::ValueRange ForRegionOpAdaptor::getODSOperands(unsigned index) { |
2281 | auto valueRange = getODSOperandIndexAndLength(index); |
2282 | return {std::next(odsOperands.begin(), valueRange.first), |
2283 | std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; |
2284 | } |
2285 | |
2286 | ::mlir::Value ForRegionOpAdaptor::getStart() { |
2287 | return *getODSOperands(0).begin(); |
2288 | } |
2289 | |
2290 | ::mlir::Value ForRegionOpAdaptor::start() { |
2291 | return *getODSOperands(0).begin(); |
2292 | } |
2293 | |
2294 | ::mlir::Value ForRegionOpAdaptor::getLimit() { |
2295 | return *getODSOperands(1).begin(); |
2296 | } |
2297 | |
2298 | ::mlir::Value ForRegionOpAdaptor::limit() { |
2299 | return *getODSOperands(1).begin(); |
2300 | } |
2301 | |
2302 | ::mlir::Value ForRegionOpAdaptor::getDelta() { |
2303 | return *getODSOperands(2).begin(); |
2304 | } |
2305 | |
2306 | ::mlir::Value ForRegionOpAdaptor::delta() { |
2307 | return *getODSOperands(2).begin(); |
2308 | } |
2309 | |
2310 | ::mlir::ValueRange ForRegionOpAdaptor::getInit() { |
2311 | return getODSOperands(3); |
2312 | } |
2313 | |
2314 | ::mlir::ValueRange ForRegionOpAdaptor::init() { |
2315 | return getODSOperands(3); |
2316 | } |
2317 | |
2318 | ::mlir::ValueRange ForRegionOpAdaptor::getCtls() { |
2319 | return getODSOperands(4); |
2320 | } |
2321 | |
2322 | ::mlir::ValueRange ForRegionOpAdaptor::ctls() { |
2323 | return getODSOperands(4); |
2324 | } |
2325 | |
2326 | ::mlir::DictionaryAttr ForRegionOpAdaptor::getAttributes() { |
2327 | return odsAttrs; |
2328 | } |
2329 | |
2330 | ::mlir::DictionaryAttr ForRegionOpAdaptor::getBodyAttrsAttr() { |
2331 | assert(odsAttrs && "no attributes when constructing adapter" ); |
2332 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 1, ForRegionOp::getBodyAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
2333 | return attr; |
2334 | } |
2335 | |
2336 | ::llvm::Optional< ::mlir::DictionaryAttr > ForRegionOpAdaptor::getBodyAttrs() { |
2337 | auto attr = getBodyAttrsAttr(); |
2338 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
2339 | } |
2340 | |
2341 | ::mlir::DictionaryAttr ForRegionOpAdaptor::body_attrsAttr() { |
2342 | assert(odsAttrs && "no attributes when constructing adapter" ); |
2343 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 1, ForRegionOp::getBodyAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
2344 | return attr; |
2345 | } |
2346 | |
2347 | ::llvm::Optional< ::mlir::DictionaryAttr > ForRegionOpAdaptor::body_attrs() { |
2348 | auto attr = body_attrsAttr(); |
2349 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
2350 | } |
2351 | |
2352 | ::mlir::tfg::RegionAttr ForRegionOpAdaptor::getRegionAttrsAttr() { |
2353 | assert(odsAttrs && "no attributes when constructing adapter" ); |
2354 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 0, ForRegionOp::getRegionAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
2355 | return attr; |
2356 | } |
2357 | |
2358 | ::llvm::Optional<::mlir::tfg::RegionAttr> ForRegionOpAdaptor::getRegionAttrs() { |
2359 | auto attr = getRegionAttrsAttr(); |
2360 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
2361 | } |
2362 | |
2363 | ::mlir::tfg::RegionAttr ForRegionOpAdaptor::region_attrsAttr() { |
2364 | assert(odsAttrs && "no attributes when constructing adapter" ); |
2365 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 0, ForRegionOp::getRegionAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
2366 | return attr; |
2367 | } |
2368 | |
2369 | ::llvm::Optional<::mlir::tfg::RegionAttr> ForRegionOpAdaptor::region_attrs() { |
2370 | auto attr = region_attrsAttr(); |
2371 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
2372 | } |
2373 | |
2374 | ::mlir::RegionRange ForRegionOpAdaptor::getRegions() { |
2375 | return odsRegions; |
2376 | } |
2377 | |
2378 | ::mlir::Region &ForRegionOpAdaptor::getBodyRegion() { |
2379 | return *odsRegions[0]; |
2380 | } |
2381 | |
2382 | ::mlir::Region &ForRegionOpAdaptor::body_region() { |
2383 | return *odsRegions[0]; |
2384 | } |
2385 | |
2386 | ::mlir::LogicalResult ForRegionOpAdaptor::verify(::mlir::Location loc) { |
2387 | auto namedAttrRange = odsAttrs; |
2388 | auto namedAttrIt = namedAttrRange.begin(); |
2389 | ::mlir::Attribute tblgen_operand_segment_sizes; |
2390 | ::mlir::Attribute tblgen_body_attrs; |
2391 | while (true) { |
2392 | if (namedAttrIt == namedAttrRange.end()) |
2393 | return emitError(loc, "'tfg.ForRegion' op " "requires attribute 'operand_segment_sizes'" ); |
2394 | if (namedAttrIt->getName() == ForRegionOp::getOperandSegmentSizesAttrName(*odsOpName)) { |
2395 | tblgen_operand_segment_sizes = namedAttrIt->getValue(); |
2396 | break; |
2397 | } |
2398 | else if (namedAttrIt->getName() == ForRegionOp::getBodyAttrsAttrName(*odsOpName)) { |
2399 | tblgen_body_attrs = namedAttrIt->getValue(); |
2400 | } |
2401 | ++namedAttrIt; |
2402 | } |
2403 | ::mlir::Attribute tblgen_region_attrs; |
2404 | while (true) { |
2405 | if (namedAttrIt == namedAttrRange.end()) { |
2406 | break; |
2407 | } |
2408 | else if (namedAttrIt->getName() == ForRegionOp::getRegionAttrsAttrName(*odsOpName)) { |
2409 | tblgen_region_attrs = namedAttrIt->getValue(); |
2410 | } |
2411 | ++namedAttrIt; |
2412 | } |
2413 | |
2414 | { |
2415 | auto sizeAttr = tblgen_operand_segment_sizes.cast<::mlir::DenseI32ArrayAttr>(); |
2416 | auto numElements = sizeAttr.asArrayRef().size(); |
2417 | if (numElements != 5) |
2418 | return emitError(loc, "'tfg.ForRegion' op " "'operand_segment_sizes' attribute for specifying operand segments must have 5 " |
2419 | "elements, but got " ) << numElements; |
2420 | } |
2421 | |
2422 | if (tblgen_body_attrs && !((tblgen_body_attrs.isa<::mlir::DictionaryAttr>()))) |
2423 | return emitError(loc, "'tfg.ForRegion' op " "attribute 'body_attrs' failed to satisfy constraint: dictionary of named attribute values" ); |
2424 | |
2425 | if (tblgen_region_attrs && !((tblgen_region_attrs.isa<::mlir::tfg::RegionAttr>()))) |
2426 | return emitError(loc, "'tfg.ForRegion' op " "attribute 'region_attrs' failed to satisfy constraint: Region attributes, argument and result attributes." ); |
2427 | return ::mlir::success(); |
2428 | } |
2429 | |
2430 | std::pair<unsigned, unsigned> ForRegionOp::getODSOperandIndexAndLength(unsigned index) { |
2431 | auto sizeAttr = ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getOperandSegmentSizesAttrName()).cast<::mlir::DenseI32ArrayAttr>(); |
2432 | |
2433 | unsigned start = 0; |
2434 | for (unsigned i = 0; i < index; ++i) |
2435 | start += sizeAttr[i]; |
2436 | return {start, sizeAttr[index]}; |
2437 | } |
2438 | |
2439 | ::mlir::Operation::operand_range ForRegionOp::getODSOperands(unsigned index) { |
2440 | auto valueRange = getODSOperandIndexAndLength(index); |
2441 | return {std::next(getOperation()->operand_begin(), valueRange.first), |
2442 | std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; |
2443 | } |
2444 | |
2445 | ::mlir::TypedValue<::mlir::TensorType> ForRegionOp::getStart() { |
2446 | return *getODSOperands(0).begin(); |
2447 | } |
2448 | |
2449 | ::mlir::TypedValue<::mlir::TensorType> ForRegionOp::start() { |
2450 | return *getODSOperands(0).begin(); |
2451 | } |
2452 | |
2453 | ::mlir::TypedValue<::mlir::TensorType> ForRegionOp::getLimit() { |
2454 | return *getODSOperands(1).begin(); |
2455 | } |
2456 | |
2457 | ::mlir::TypedValue<::mlir::TensorType> ForRegionOp::limit() { |
2458 | return *getODSOperands(1).begin(); |
2459 | } |
2460 | |
2461 | ::mlir::TypedValue<::mlir::TensorType> ForRegionOp::getDelta() { |
2462 | return *getODSOperands(2).begin(); |
2463 | } |
2464 | |
2465 | ::mlir::TypedValue<::mlir::TensorType> ForRegionOp::delta() { |
2466 | return *getODSOperands(2).begin(); |
2467 | } |
2468 | |
2469 | ::mlir::Operation::operand_range ForRegionOp::getInit() { |
2470 | return getODSOperands(3); |
2471 | } |
2472 | |
2473 | ::mlir::Operation::operand_range ForRegionOp::init() { |
2474 | return getODSOperands(3); |
2475 | } |
2476 | |
2477 | ::mlir::Operation::operand_range ForRegionOp::getCtls() { |
2478 | return getODSOperands(4); |
2479 | } |
2480 | |
2481 | ::mlir::Operation::operand_range ForRegionOp::ctls() { |
2482 | return getODSOperands(4); |
2483 | } |
2484 | |
2485 | ::mlir::MutableOperandRange ForRegionOp::getStartMutable() { |
2486 | auto range = getODSOperandIndexAndLength(0); |
2487 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(0u, *::mlir::impl::getNamedAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getOperandSegmentSizesAttrName()))); |
2488 | return mutableRange; |
2489 | } |
2490 | |
2491 | ::mlir::MutableOperandRange ForRegionOp::startMutable() { |
2492 | auto range = getODSOperandIndexAndLength(0); |
2493 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(0u, *::mlir::impl::getNamedAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getOperandSegmentSizesAttrName()))); |
2494 | return mutableRange; |
2495 | } |
2496 | |
2497 | ::mlir::MutableOperandRange ForRegionOp::getLimitMutable() { |
2498 | auto range = getODSOperandIndexAndLength(1); |
2499 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(1u, *::mlir::impl::getNamedAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getOperandSegmentSizesAttrName()))); |
2500 | return mutableRange; |
2501 | } |
2502 | |
2503 | ::mlir::MutableOperandRange ForRegionOp::limitMutable() { |
2504 | auto range = getODSOperandIndexAndLength(1); |
2505 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(1u, *::mlir::impl::getNamedAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getOperandSegmentSizesAttrName()))); |
2506 | return mutableRange; |
2507 | } |
2508 | |
2509 | ::mlir::MutableOperandRange ForRegionOp::getDeltaMutable() { |
2510 | auto range = getODSOperandIndexAndLength(2); |
2511 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(2u, *::mlir::impl::getNamedAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getOperandSegmentSizesAttrName()))); |
2512 | return mutableRange; |
2513 | } |
2514 | |
2515 | ::mlir::MutableOperandRange ForRegionOp::deltaMutable() { |
2516 | auto range = getODSOperandIndexAndLength(2); |
2517 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(2u, *::mlir::impl::getNamedAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getOperandSegmentSizesAttrName()))); |
2518 | return mutableRange; |
2519 | } |
2520 | |
2521 | ::mlir::MutableOperandRange ForRegionOp::getInitMutable() { |
2522 | auto range = getODSOperandIndexAndLength(3); |
2523 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(3u, *::mlir::impl::getNamedAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getOperandSegmentSizesAttrName()))); |
2524 | return mutableRange; |
2525 | } |
2526 | |
2527 | ::mlir::MutableOperandRange ForRegionOp::initMutable() { |
2528 | auto range = getODSOperandIndexAndLength(3); |
2529 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(3u, *::mlir::impl::getNamedAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getOperandSegmentSizesAttrName()))); |
2530 | return mutableRange; |
2531 | } |
2532 | |
2533 | ::mlir::MutableOperandRange ForRegionOp::getCtlsMutable() { |
2534 | auto range = getODSOperandIndexAndLength(4); |
2535 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(4u, *::mlir::impl::getNamedAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getOperandSegmentSizesAttrName()))); |
2536 | return mutableRange; |
2537 | } |
2538 | |
2539 | ::mlir::MutableOperandRange ForRegionOp::ctlsMutable() { |
2540 | auto range = getODSOperandIndexAndLength(4); |
2541 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(4u, *::mlir::impl::getNamedAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getOperandSegmentSizesAttrName()))); |
2542 | return mutableRange; |
2543 | } |
2544 | |
2545 | std::pair<unsigned, unsigned> ForRegionOp::getODSResultIndexAndLength(unsigned index) { |
2546 | bool isVariadic[] = {true, false}; |
2547 | int prevVariadicCount = 0; |
2548 | for (unsigned i = 0; i < index; ++i) |
2549 | if (isVariadic[i]) ++prevVariadicCount; |
2550 | |
2551 | // Calculate how many dynamic values a static variadic operand corresponds to. |
2552 | // This assumes all static variadic operands have the same dynamic value count. |
2553 | int variadicSize = (getOperation()->getNumResults() - 1) / 1; |
2554 | // `index` passed in as the parameter is the static index which counts each |
2555 | // operand (variadic or not) as size 1. So here for each previous static variadic |
2556 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
2557 | // value pack for this static operand starts. |
2558 | int start = index + (variadicSize - 1) * prevVariadicCount; |
2559 | int size = isVariadic[index] ? variadicSize : 1; |
2560 | return {start, size}; |
2561 | } |
2562 | |
2563 | ::mlir::Operation::result_range ForRegionOp::getODSResults(unsigned index) { |
2564 | auto valueRange = getODSResultIndexAndLength(index); |
2565 | return {std::next(getOperation()->result_begin(), valueRange.first), |
2566 | std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; |
2567 | } |
2568 | |
2569 | ::mlir::Operation::result_range ForRegionOp::getOuts() { |
2570 | return getODSResults(0); |
2571 | } |
2572 | |
2573 | ::mlir::Operation::result_range ForRegionOp::outs() { |
2574 | return getODSResults(0); |
2575 | } |
2576 | |
2577 | ::mlir::TypedValue<::mlir::tf_type::ControlType> ForRegionOp::getCtl() { |
2578 | return *getODSResults(1).begin(); |
2579 | } |
2580 | |
2581 | ::mlir::TypedValue<::mlir::tf_type::ControlType> ForRegionOp::ctl() { |
2582 | return *getODSResults(1).begin(); |
2583 | } |
2584 | |
2585 | ::mlir::Region &ForRegionOp::getBodyRegion() { |
2586 | return (*this)->getRegion(0); |
2587 | } |
2588 | |
2589 | ::mlir::Region &ForRegionOp::body_region() { |
2590 | return (*this)->getRegion(0); |
2591 | } |
2592 | |
2593 | ::mlir::DictionaryAttr ForRegionOp::getBodyAttrsAttr() { |
2594 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getBodyAttrsAttrName()).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
2595 | } |
2596 | |
2597 | ::llvm::Optional< ::mlir::DictionaryAttr > ForRegionOp::getBodyAttrs() { |
2598 | auto attr = getBodyAttrsAttr(); |
2599 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
2600 | } |
2601 | |
2602 | ::mlir::DictionaryAttr ForRegionOp::body_attrsAttr() { |
2603 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getBodyAttrsAttrName()).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
2604 | } |
2605 | |
2606 | ::llvm::Optional< ::mlir::DictionaryAttr > ForRegionOp::body_attrs() { |
2607 | auto attr = body_attrsAttr(); |
2608 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
2609 | } |
2610 | |
2611 | ::mlir::tfg::RegionAttr ForRegionOp::getRegionAttrsAttr() { |
2612 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getRegionAttrsAttrName()).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
2613 | } |
2614 | |
2615 | ::llvm::Optional<::mlir::tfg::RegionAttr> ForRegionOp::getRegionAttrs() { |
2616 | auto attr = getRegionAttrsAttr(); |
2617 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
2618 | } |
2619 | |
2620 | ::mlir::tfg::RegionAttr ForRegionOp::region_attrsAttr() { |
2621 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getRegionAttrsAttrName()).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
2622 | } |
2623 | |
2624 | ::llvm::Optional<::mlir::tfg::RegionAttr> ForRegionOp::region_attrs() { |
2625 | auto attr = region_attrsAttr(); |
2626 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
2627 | } |
2628 | |
2629 | void ForRegionOp::setBodyAttrsAttr(::mlir::DictionaryAttr attr) { |
2630 | (*this)->setAttr(getBodyAttrsAttrName(), attr); |
2631 | } |
2632 | |
2633 | void ForRegionOp::body_attrsAttr(::mlir::DictionaryAttr attr) { |
2634 | (*this)->setAttr(body_attrsAttrName(), attr); |
2635 | } |
2636 | |
2637 | void ForRegionOp::setRegionAttrsAttr(::mlir::tfg::RegionAttr attr) { |
2638 | (*this)->setAttr(getRegionAttrsAttrName(), attr); |
2639 | } |
2640 | |
2641 | void ForRegionOp::region_attrsAttr(::mlir::tfg::RegionAttr attr) { |
2642 | (*this)->setAttr(region_attrsAttrName(), attr); |
2643 | } |
2644 | |
2645 | ::mlir::Attribute ForRegionOp::removeBody_attrsAttr() { |
2646 | return (*this)->removeAttr(getBodyAttrsAttrName()); |
2647 | } |
2648 | |
2649 | ::mlir::Attribute ForRegionOp::removeRegion_attrsAttr() { |
2650 | return (*this)->removeAttr(getRegionAttrsAttrName()); |
2651 | } |
2652 | |
2653 | void ForRegionOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange outs, ::mlir::Type ctl, ::mlir::Value start, ::mlir::Value limit, ::mlir::Value delta, ::mlir::ValueRange init, ::mlir::ValueRange ctls, /*optional*/::mlir::DictionaryAttr body_attrs, /*optional*/::mlir::tfg::RegionAttr region_attrs) { |
2654 | odsState.addOperands(start); |
2655 | odsState.addOperands(limit); |
2656 | odsState.addOperands(delta); |
2657 | odsState.addOperands(init); |
2658 | odsState.addOperands(ctls); |
2659 | odsState.addAttribute(getOperandSegmentSizesAttrName(odsState.name), odsBuilder.getDenseI32ArrayAttr({1, 1, 1, static_cast<int32_t>(init.size()), static_cast<int32_t>(ctls.size())})); |
2660 | if (body_attrs) { |
2661 | odsState.addAttribute(getBodyAttrsAttrName(odsState.name), body_attrs); |
2662 | } |
2663 | if (region_attrs) { |
2664 | odsState.addAttribute(getRegionAttrsAttrName(odsState.name), region_attrs); |
2665 | } |
2666 | (void)odsState.addRegion(); |
2667 | odsState.addTypes(outs); |
2668 | odsState.addTypes(ctl); |
2669 | } |
2670 | |
2671 | void ForRegionOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value start, ::mlir::Value limit, ::mlir::Value delta, ::mlir::ValueRange init, ::mlir::ValueRange ctls, /*optional*/::mlir::DictionaryAttr body_attrs, /*optional*/::mlir::tfg::RegionAttr region_attrs) { |
2672 | odsState.addOperands(start); |
2673 | odsState.addOperands(limit); |
2674 | odsState.addOperands(delta); |
2675 | odsState.addOperands(init); |
2676 | odsState.addOperands(ctls); |
2677 | odsState.addAttribute(getOperandSegmentSizesAttrName(odsState.name), odsBuilder.getDenseI32ArrayAttr({1, 1, 1, static_cast<int32_t>(init.size()), static_cast<int32_t>(ctls.size())})); |
2678 | if (body_attrs) { |
2679 | odsState.addAttribute(getBodyAttrsAttrName(odsState.name), body_attrs); |
2680 | } |
2681 | if (region_attrs) { |
2682 | odsState.addAttribute(getRegionAttrsAttrName(odsState.name), region_attrs); |
2683 | } |
2684 | (void)odsState.addRegion(); |
2685 | assert(resultTypes.size() >= 1u && "mismatched number of results" ); |
2686 | odsState.addTypes(resultTypes); |
2687 | } |
2688 | |
2689 | void ForRegionOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { |
2690 | assert(operands.size() >= 3u && "mismatched number of parameters" ); |
2691 | odsState.addOperands(operands); |
2692 | odsState.addAttributes(attributes); |
2693 | for (unsigned i = 0; i != 1; ++i) |
2694 | (void)odsState.addRegion(); |
2695 | assert(resultTypes.size() >= 1u && "mismatched number of return types" ); |
2696 | odsState.addTypes(resultTypes); |
2697 | } |
2698 | |
2699 | ::mlir::LogicalResult ForRegionOp::verifyInvariantsImpl() { |
2700 | auto namedAttrRange = (*this)->getAttrs(); |
2701 | auto namedAttrIt = namedAttrRange.begin(); |
2702 | ::mlir::Attribute tblgen_operand_segment_sizes; |
2703 | ::mlir::Attribute tblgen_body_attrs; |
2704 | while (true) { |
2705 | if (namedAttrIt == namedAttrRange.end()) |
2706 | return emitOpError("requires attribute 'operand_segment_sizes'" ); |
2707 | if (namedAttrIt->getName() == getOperandSegmentSizesAttrName()) { |
2708 | tblgen_operand_segment_sizes = namedAttrIt->getValue(); |
2709 | break; |
2710 | } |
2711 | else if (namedAttrIt->getName() == getBodyAttrsAttrName()) { |
2712 | tblgen_body_attrs = namedAttrIt->getValue(); |
2713 | } |
2714 | ++namedAttrIt; |
2715 | } |
2716 | ::mlir::Attribute tblgen_region_attrs; |
2717 | while (true) { |
2718 | if (namedAttrIt == namedAttrRange.end()) { |
2719 | break; |
2720 | } |
2721 | else if (namedAttrIt->getName() == getRegionAttrsAttrName()) { |
2722 | tblgen_region_attrs = namedAttrIt->getValue(); |
2723 | } |
2724 | ++namedAttrIt; |
2725 | } |
2726 | |
2727 | { |
2728 | auto sizeAttr = tblgen_operand_segment_sizes.cast<::mlir::DenseI32ArrayAttr>(); |
2729 | auto numElements = sizeAttr.asArrayRef().size(); |
2730 | if (numElements != 5) |
2731 | return emitOpError("'operand_segment_sizes' attribute for specifying operand segments must have 5 " |
2732 | "elements, but got " ) << numElements; |
2733 | } |
2734 | |
2735 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops6(*this, tblgen_body_attrs, "body_attrs" ))) |
2736 | return ::mlir::failure(); |
2737 | |
2738 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops7(*this, tblgen_region_attrs, "region_attrs" ))) |
2739 | return ::mlir::failure(); |
2740 | { |
2741 | unsigned index = 0; (void)index; |
2742 | auto valueGroup0 = getODSOperands(0); |
2743 | |
2744 | for (auto v : valueGroup0) { |
2745 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops4(*this, v.getType(), "operand" , index++))) |
2746 | return ::mlir::failure(); |
2747 | } |
2748 | auto valueGroup1 = getODSOperands(1); |
2749 | |
2750 | for (auto v : valueGroup1) { |
2751 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops4(*this, v.getType(), "operand" , index++))) |
2752 | return ::mlir::failure(); |
2753 | } |
2754 | auto valueGroup2 = getODSOperands(2); |
2755 | |
2756 | for (auto v : valueGroup2) { |
2757 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops4(*this, v.getType(), "operand" , index++))) |
2758 | return ::mlir::failure(); |
2759 | } |
2760 | auto valueGroup3 = getODSOperands(3); |
2761 | |
2762 | for (auto v : valueGroup3) { |
2763 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops2(*this, v.getType(), "operand" , index++))) |
2764 | return ::mlir::failure(); |
2765 | } |
2766 | auto valueGroup4 = getODSOperands(4); |
2767 | |
2768 | for (auto v : valueGroup4) { |
2769 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops3(*this, v.getType(), "operand" , index++))) |
2770 | return ::mlir::failure(); |
2771 | } |
2772 | } |
2773 | { |
2774 | unsigned index = 0; (void)index; |
2775 | auto valueGroup0 = getODSResults(0); |
2776 | |
2777 | for (auto v : valueGroup0) { |
2778 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops2(*this, v.getType(), "result" , index++))) |
2779 | return ::mlir::failure(); |
2780 | } |
2781 | auto valueGroup1 = getODSResults(1); |
2782 | |
2783 | for (auto v : valueGroup1) { |
2784 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops3(*this, v.getType(), "result" , index++))) |
2785 | return ::mlir::failure(); |
2786 | } |
2787 | } |
2788 | { |
2789 | unsigned index = 0; (void)index; |
2790 | |
2791 | for (auto ®ion : ::llvm::makeMutableArrayRef((*this)->getRegion(0))) |
2792 | if (::mlir::failed(__mlir_ods_local_region_constraint_ops0(*this, region, "body_region" , index++))) |
2793 | return ::mlir::failure(); |
2794 | } |
2795 | return ::mlir::success(); |
2796 | } |
2797 | |
2798 | ::mlir::LogicalResult ForRegionOp::verifyInvariants() { |
2799 | if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) |
2800 | return ::mlir::success(); |
2801 | return ::mlir::failure(); |
2802 | } |
2803 | |
2804 | ::mlir::ParseResult ForRegionOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { |
2805 | ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> initOperands; |
2806 | ::llvm::SMLoc initOperandsLoc; |
2807 | (void)initOperandsLoc; |
2808 | ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> ctlsOperands; |
2809 | ::llvm::SMLoc ctlsOperandsLoc; |
2810 | (void)ctlsOperandsLoc; |
2811 | ::mlir::OpAsmParser::UnresolvedOperand startRawOperands[1]; |
2812 | ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> startOperands(startRawOperands); ::llvm::SMLoc startOperandsLoc; |
2813 | (void)startOperandsLoc; |
2814 | ::mlir::OpAsmParser::UnresolvedOperand limitRawOperands[1]; |
2815 | ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> limitOperands(limitRawOperands); ::llvm::SMLoc limitOperandsLoc; |
2816 | (void)limitOperandsLoc; |
2817 | ::mlir::OpAsmParser::UnresolvedOperand deltaRawOperands[1]; |
2818 | ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> deltaOperands(deltaRawOperands); ::llvm::SMLoc deltaOperandsLoc; |
2819 | (void)deltaOperandsLoc; |
2820 | std::unique_ptr<::mlir::Region> body_regionRegion = std::make_unique<::mlir::Region>(); |
2821 | ::mlir::Type startRawTypes[1]; |
2822 | ::llvm::ArrayRef<::mlir::Type> startTypes(startRawTypes); |
2823 | ::mlir::Type limitRawTypes[1]; |
2824 | ::llvm::ArrayRef<::mlir::Type> limitTypes(limitRawTypes); |
2825 | ::mlir::Type deltaRawTypes[1]; |
2826 | ::llvm::ArrayRef<::mlir::Type> deltaTypes(deltaRawTypes); |
2827 | ::llvm::SmallVector<::mlir::Type, 1> initTypes; |
2828 | ::llvm::SmallVector<::mlir::Type, 1> outsTypes; |
2829 | if (::mlir::succeeded(parser.parseOptionalLParen())) { |
2830 | |
2831 | initOperandsLoc = parser.getCurrentLocation(); |
2832 | if (parser.parseOperandList(initOperands)) |
2833 | return ::mlir::failure(); |
2834 | if (parser.parseRParen()) |
2835 | return ::mlir::failure(); |
2836 | } |
2837 | if (::mlir::succeeded(parser.parseOptionalLSquare())) { |
2838 | |
2839 | ctlsOperandsLoc = parser.getCurrentLocation(); |
2840 | if (parser.parseOperandList(ctlsOperands)) |
2841 | return ::mlir::failure(); |
2842 | if (parser.parseRSquare()) |
2843 | return ::mlir::failure(); |
2844 | } |
2845 | if (parser.parseKeyword("from" )) |
2846 | return ::mlir::failure(); |
2847 | |
2848 | startOperandsLoc = parser.getCurrentLocation(); |
2849 | if (parser.parseOperand(startRawOperands[0])) |
2850 | return ::mlir::failure(); |
2851 | if (parser.parseKeyword("to" )) |
2852 | return ::mlir::failure(); |
2853 | |
2854 | limitOperandsLoc = parser.getCurrentLocation(); |
2855 | if (parser.parseOperand(limitRawOperands[0])) |
2856 | return ::mlir::failure(); |
2857 | if (parser.parseKeyword("by" )) |
2858 | return ::mlir::failure(); |
2859 | |
2860 | deltaOperandsLoc = parser.getCurrentLocation(); |
2861 | if (parser.parseOperand(deltaRawOperands[0])) |
2862 | return ::mlir::failure(); |
2863 | |
2864 | if (parser.parseRegion(*body_regionRegion)) |
2865 | return ::mlir::failure(); |
2866 | |
2867 | if (body_regionRegion->empty()) body_regionRegion->emplaceBlock(); |
2868 | if (parser.parseOptionalAttrDict(result.attributes)) |
2869 | return ::mlir::failure(); |
2870 | if (parser.parseColon()) |
2871 | return ::mlir::failure(); |
2872 | if (parser.parseLParen()) |
2873 | return ::mlir::failure(); |
2874 | |
2875 | { |
2876 | ::mlir::TensorType type; |
2877 | if (parser.parseCustomTypeWithFallback(type)) |
2878 | return ::mlir::failure(); |
2879 | startRawTypes[0] = type; |
2880 | } |
2881 | if (parser.parseComma()) |
2882 | return ::mlir::failure(); |
2883 | |
2884 | { |
2885 | ::mlir::TensorType type; |
2886 | if (parser.parseCustomTypeWithFallback(type)) |
2887 | return ::mlir::failure(); |
2888 | limitRawTypes[0] = type; |
2889 | } |
2890 | if (parser.parseComma()) |
2891 | return ::mlir::failure(); |
2892 | |
2893 | { |
2894 | ::mlir::TensorType type; |
2895 | if (parser.parseCustomTypeWithFallback(type)) |
2896 | return ::mlir::failure(); |
2897 | deltaRawTypes[0] = type; |
2898 | } |
2899 | if (::mlir::succeeded(parser.parseOptionalComma())) { |
2900 | |
2901 | if (parser.parseTypeList(initTypes)) |
2902 | return ::mlir::failure(); |
2903 | } |
2904 | if (parser.parseRParen()) |
2905 | return ::mlir::failure(); |
2906 | if (::mlir::succeeded(parser.parseOptionalArrow())) { |
2907 | if (parser.parseLParen()) |
2908 | return ::mlir::failure(); |
2909 | |
2910 | if (parser.parseTypeList(outsTypes)) |
2911 | return ::mlir::failure(); |
2912 | if (parser.parseRParen()) |
2913 | return ::mlir::failure(); |
2914 | } |
2915 | result.addRegion(std::move(body_regionRegion)); |
2916 | result.addAttribute("operand_segment_sizes" , parser.getBuilder().getDenseI32ArrayAttr({1, 1, 1, static_cast<int32_t>(initOperands.size()), static_cast<int32_t>(ctlsOperands.size())})); |
2917 | ::mlir::Type odsBuildableType0 = parser.getBuilder().getType<::mlir::tf_type::ControlType>(); |
2918 | result.addTypes(outsTypes); |
2919 | result.addTypes(odsBuildableType0); |
2920 | if (parser.resolveOperands(startOperands, startTypes, startOperandsLoc, result.operands)) |
2921 | return ::mlir::failure(); |
2922 | if (parser.resolveOperands(limitOperands, limitTypes, limitOperandsLoc, result.operands)) |
2923 | return ::mlir::failure(); |
2924 | if (parser.resolveOperands(deltaOperands, deltaTypes, deltaOperandsLoc, result.operands)) |
2925 | return ::mlir::failure(); |
2926 | if (parser.resolveOperands(initOperands, initTypes, initOperandsLoc, result.operands)) |
2927 | return ::mlir::failure(); |
2928 | if (parser.resolveOperands(ctlsOperands, odsBuildableType0, ctlsOperandsLoc, result.operands)) |
2929 | return ::mlir::failure(); |
2930 | return ::mlir::success(); |
2931 | } |
2932 | |
2933 | void ForRegionOp::print(::mlir::OpAsmPrinter &_odsPrinter) { |
2934 | if (!getInit().empty()) { |
2935 | _odsPrinter << "(" ; |
2936 | _odsPrinter << getInit(); |
2937 | _odsPrinter << ")" ; |
2938 | } |
2939 | if (!getCtls().empty()) { |
2940 | _odsPrinter << ' ' << "[" ; |
2941 | _odsPrinter << getCtls(); |
2942 | _odsPrinter << "]" ; |
2943 | } |
2944 | _odsPrinter << ' ' << "from" ; |
2945 | _odsPrinter << ' '; |
2946 | _odsPrinter << getStart(); |
2947 | _odsPrinter << ' ' << "to" ; |
2948 | _odsPrinter << ' '; |
2949 | _odsPrinter << getLimit(); |
2950 | _odsPrinter << ' ' << "by" ; |
2951 | _odsPrinter << ' '; |
2952 | _odsPrinter << getDelta(); |
2953 | _odsPrinter << ' '; |
2954 | _odsPrinter.printRegion(getBodyRegion()); |
2955 | _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), /*elidedAttrs=*/{"operand_segment_sizes" , }); |
2956 | _odsPrinter << ' ' << ":" ; |
2957 | _odsPrinter << ' ' << "(" ; |
2958 | { |
2959 | auto type = getStart().getType(); |
2960 | if (auto validType = type.dyn_cast<::mlir::TensorType>()) |
2961 | _odsPrinter.printStrippedAttrOrType(validType); |
2962 | else |
2963 | _odsPrinter << type; |
2964 | } |
2965 | _odsPrinter << "," ; |
2966 | _odsPrinter << ' '; |
2967 | { |
2968 | auto type = getLimit().getType(); |
2969 | if (auto validType = type.dyn_cast<::mlir::TensorType>()) |
2970 | _odsPrinter.printStrippedAttrOrType(validType); |
2971 | else |
2972 | _odsPrinter << type; |
2973 | } |
2974 | _odsPrinter << "," ; |
2975 | _odsPrinter << ' '; |
2976 | { |
2977 | auto type = getDelta().getType(); |
2978 | if (auto validType = type.dyn_cast<::mlir::TensorType>()) |
2979 | _odsPrinter.printStrippedAttrOrType(validType); |
2980 | else |
2981 | _odsPrinter << type; |
2982 | } |
2983 | if (!getInit().empty()) { |
2984 | _odsPrinter << "," ; |
2985 | _odsPrinter << ' '; |
2986 | _odsPrinter << getInit().getTypes(); |
2987 | } |
2988 | _odsPrinter << ")" ; |
2989 | if (!getOuts().empty()) { |
2990 | _odsPrinter << ' ' << "->" ; |
2991 | _odsPrinter << ' ' << "(" ; |
2992 | _odsPrinter << getOuts().getTypes(); |
2993 | _odsPrinter << ")" ; |
2994 | } |
2995 | } |
2996 | |
2997 | StringRef ForRegionOp::getDefaultDialect() { return "tfg" ; } |
2998 | void ForRegionOp::getAsmResultNames(OpAsmSetValueNameFn setNameFn) { |
2999 | GenericGetAsmResultNames(*this, setNameFn); |
3000 | } |
3001 | |
3002 | YieldOp ForRegionOp::body_yield() { |
3003 | return cast<YieldOp>(body_block().getTerminator()); |
3004 | } |
3005 | } // namespace tfg |
3006 | } // namespace mlir |
3007 | MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::tfg::ForRegionOp) |
3008 | |
3009 | namespace mlir { |
3010 | namespace tfg { |
3011 | |
3012 | //===----------------------------------------------------------------------===// |
3013 | // ::mlir::tfg::GetResultOp definitions |
3014 | //===----------------------------------------------------------------------===// |
3015 | |
3016 | GetResultOpAdaptor::GetResultOpAdaptor(::mlir::ValueRange values, ::mlir::DictionaryAttr attrs, ::mlir::RegionRange regions) : odsOperands(values), odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) |
3017 | odsOpName.emplace("tfg.get_result" , odsAttrs.getContext()); |
3018 | } |
3019 | |
3020 | GetResultOpAdaptor::GetResultOpAdaptor(GetResultOp op) : odsOperands(op->getOperands()), odsAttrs(op->getAttrDictionary()), odsRegions(op->getRegions()), odsOpName(op->getName()) {} |
3021 | |
3022 | ::mlir::ValueRange GetResultOpAdaptor::getOperands() { |
3023 | return odsOperands; |
3024 | } |
3025 | |
3026 | std::pair<unsigned, unsigned> GetResultOpAdaptor::getODSOperandIndexAndLength(unsigned index) { |
3027 | return {index, 1}; |
3028 | } |
3029 | |
3030 | ::mlir::ValueRange GetResultOpAdaptor::getODSOperands(unsigned index) { |
3031 | auto valueRange = getODSOperandIndexAndLength(index); |
3032 | return {std::next(odsOperands.begin(), valueRange.first), |
3033 | std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; |
3034 | } |
3035 | |
3036 | ::mlir::Value GetResultOpAdaptor::getValue() { |
3037 | return *getODSOperands(0).begin(); |
3038 | } |
3039 | |
3040 | ::mlir::Value GetResultOpAdaptor::value() { |
3041 | return *getODSOperands(0).begin(); |
3042 | } |
3043 | |
3044 | ::mlir::DictionaryAttr GetResultOpAdaptor::getAttributes() { |
3045 | return odsAttrs; |
3046 | } |
3047 | |
3048 | ::mlir::StringAttr GetResultOpAdaptor::getNameAttr() { |
3049 | assert(odsAttrs && "no attributes when constructing adapter" ); |
3050 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 1, GetResultOp::getNameAttrName(*odsOpName)).cast<::mlir::StringAttr>(); |
3051 | return attr; |
3052 | } |
3053 | |
3054 | ::llvm::StringRef GetResultOpAdaptor::getName() { |
3055 | auto attr = getNameAttr(); |
3056 | return attr.getValue(); |
3057 | } |
3058 | |
3059 | ::mlir::StringAttr GetResultOpAdaptor::nameAttr() { |
3060 | assert(odsAttrs && "no attributes when constructing adapter" ); |
3061 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 1, GetResultOp::getNameAttrName(*odsOpName)).cast<::mlir::StringAttr>(); |
3062 | return attr; |
3063 | } |
3064 | |
3065 | ::llvm::StringRef GetResultOpAdaptor::name() { |
3066 | auto attr = nameAttr(); |
3067 | return attr.getValue(); |
3068 | } |
3069 | |
3070 | ::mlir::IntegerAttr GetResultOpAdaptor::getNumberAttr() { |
3071 | assert(odsAttrs && "no attributes when constructing adapter" ); |
3072 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 0, GetResultOp::getNumberAttrName(*odsOpName)).cast<::mlir::IntegerAttr>(); |
3073 | return attr; |
3074 | } |
3075 | |
3076 | uint32_t GetResultOpAdaptor::getNumber() { |
3077 | auto attr = getNumberAttr(); |
3078 | return attr.getValue().getZExtValue(); |
3079 | } |
3080 | |
3081 | ::mlir::IntegerAttr GetResultOpAdaptor::numberAttr() { |
3082 | assert(odsAttrs && "no attributes when constructing adapter" ); |
3083 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 0, GetResultOp::getNumberAttrName(*odsOpName)).cast<::mlir::IntegerAttr>(); |
3084 | return attr; |
3085 | } |
3086 | |
3087 | uint32_t GetResultOpAdaptor::number() { |
3088 | auto attr = numberAttr(); |
3089 | return attr.getValue().getZExtValue(); |
3090 | } |
3091 | |
3092 | ::mlir::LogicalResult GetResultOpAdaptor::verify(::mlir::Location loc) { |
3093 | auto namedAttrRange = odsAttrs; |
3094 | auto namedAttrIt = namedAttrRange.begin(); |
3095 | ::mlir::Attribute tblgen_name; |
3096 | while (true) { |
3097 | if (namedAttrIt == namedAttrRange.end()) |
3098 | return emitError(loc, "'tfg.get_result' op " "requires attribute 'name'" ); |
3099 | if (namedAttrIt->getName() == GetResultOp::getNameAttrName(*odsOpName)) { |
3100 | tblgen_name = namedAttrIt->getValue(); |
3101 | break; |
3102 | } |
3103 | ++namedAttrIt; |
3104 | } |
3105 | ::mlir::Attribute tblgen_number; |
3106 | while (true) { |
3107 | if (namedAttrIt == namedAttrRange.end()) |
3108 | return emitError(loc, "'tfg.get_result' op " "requires attribute 'number'" ); |
3109 | if (namedAttrIt->getName() == GetResultOp::getNumberAttrName(*odsOpName)) { |
3110 | tblgen_number = namedAttrIt->getValue(); |
3111 | break; |
3112 | } |
3113 | ++namedAttrIt; |
3114 | } |
3115 | |
3116 | if (tblgen_name && !((tblgen_name.isa<::mlir::StringAttr>()))) |
3117 | return emitError(loc, "'tfg.get_result' op " "attribute 'name' failed to satisfy constraint: string attribute" ); |
3118 | |
3119 | if (tblgen_number && !(((tblgen_number.isa<::mlir::IntegerAttr>())) && ((tblgen_number.cast<::mlir::IntegerAttr>().getType().isSignlessInteger(32))))) |
3120 | return emitError(loc, "'tfg.get_result' op " "attribute 'number' failed to satisfy constraint: 32-bit signless integer attribute" ); |
3121 | return ::mlir::success(); |
3122 | } |
3123 | |
3124 | std::pair<unsigned, unsigned> GetResultOp::getODSOperandIndexAndLength(unsigned index) { |
3125 | return {index, 1}; |
3126 | } |
3127 | |
3128 | ::mlir::Operation::operand_range GetResultOp::getODSOperands(unsigned index) { |
3129 | auto valueRange = getODSOperandIndexAndLength(index); |
3130 | return {std::next(getOperation()->operand_begin(), valueRange.first), |
3131 | std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; |
3132 | } |
3133 | |
3134 | ::mlir::TypedValue<::mlir::tf_type::OpaqueTensorType> GetResultOp::getValue() { |
3135 | return *getODSOperands(0).begin(); |
3136 | } |
3137 | |
3138 | ::mlir::TypedValue<::mlir::tf_type::OpaqueTensorType> GetResultOp::value() { |
3139 | return *getODSOperands(0).begin(); |
3140 | } |
3141 | |
3142 | ::mlir::MutableOperandRange GetResultOp::getValueMutable() { |
3143 | auto range = getODSOperandIndexAndLength(0); |
3144 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
3145 | return mutableRange; |
3146 | } |
3147 | |
3148 | ::mlir::MutableOperandRange GetResultOp::valueMutable() { |
3149 | auto range = getODSOperandIndexAndLength(0); |
3150 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
3151 | return mutableRange; |
3152 | } |
3153 | |
3154 | std::pair<unsigned, unsigned> GetResultOp::getODSResultIndexAndLength(unsigned index) { |
3155 | return {index, 1}; |
3156 | } |
3157 | |
3158 | ::mlir::Operation::result_range GetResultOp::getODSResults(unsigned index) { |
3159 | auto valueRange = getODSResultIndexAndLength(index); |
3160 | return {std::next(getOperation()->result_begin(), valueRange.first), |
3161 | std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; |
3162 | } |
3163 | |
3164 | ::mlir::TypedValue<::mlir::tf_type::OpaqueTensorType> GetResultOp::getResult() { |
3165 | return *getODSResults(0).begin(); |
3166 | } |
3167 | |
3168 | ::mlir::TypedValue<::mlir::tf_type::OpaqueTensorType> GetResultOp::result() { |
3169 | return *getODSResults(0).begin(); |
3170 | } |
3171 | |
3172 | ::mlir::StringAttr GetResultOp::getNameAttr() { |
3173 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getNameAttrName()).cast<::mlir::StringAttr>(); |
3174 | } |
3175 | |
3176 | ::llvm::StringRef GetResultOp::getName() { |
3177 | auto attr = getNameAttr(); |
3178 | return attr.getValue(); |
3179 | } |
3180 | |
3181 | ::mlir::StringAttr GetResultOp::nameAttr() { |
3182 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getNameAttrName()).cast<::mlir::StringAttr>(); |
3183 | } |
3184 | |
3185 | ::llvm::StringRef GetResultOp::name() { |
3186 | auto attr = nameAttr(); |
3187 | return attr.getValue(); |
3188 | } |
3189 | |
3190 | ::mlir::IntegerAttr GetResultOp::getNumberAttr() { |
3191 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getNumberAttrName()).cast<::mlir::IntegerAttr>(); |
3192 | } |
3193 | |
3194 | uint32_t GetResultOp::getNumber() { |
3195 | auto attr = getNumberAttr(); |
3196 | return attr.getValue().getZExtValue(); |
3197 | } |
3198 | |
3199 | ::mlir::IntegerAttr GetResultOp::numberAttr() { |
3200 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getNumberAttrName()).cast<::mlir::IntegerAttr>(); |
3201 | } |
3202 | |
3203 | uint32_t GetResultOp::number() { |
3204 | auto attr = numberAttr(); |
3205 | return attr.getValue().getZExtValue(); |
3206 | } |
3207 | |
3208 | void GetResultOp::setNameAttr(::mlir::StringAttr attr) { |
3209 | (*this)->setAttr(getNameAttrName(), attr); |
3210 | } |
3211 | |
3212 | void GetResultOp::nameAttr(::mlir::StringAttr attr) { |
3213 | (*this)->setAttr(nameAttrName(), attr); |
3214 | } |
3215 | |
3216 | void GetResultOp::setNumberAttr(::mlir::IntegerAttr attr) { |
3217 | (*this)->setAttr(getNumberAttrName(), attr); |
3218 | } |
3219 | |
3220 | void GetResultOp::numberAttr(::mlir::IntegerAttr attr) { |
3221 | (*this)->setAttr(numberAttrName(), attr); |
3222 | } |
3223 | |
3224 | void GetResultOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type result, ::mlir::Value value, ::mlir::StringAttr name, ::mlir::IntegerAttr number) { |
3225 | odsState.addOperands(value); |
3226 | odsState.addAttribute(getNameAttrName(odsState.name), name); |
3227 | odsState.addAttribute(getNumberAttrName(odsState.name), number); |
3228 | odsState.addTypes(result); |
3229 | } |
3230 | |
3231 | void GetResultOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Value value, ::mlir::StringAttr name, ::mlir::IntegerAttr number) { |
3232 | odsState.addOperands(value); |
3233 | odsState.addAttribute(getNameAttrName(odsState.name), name); |
3234 | odsState.addAttribute(getNumberAttrName(odsState.name), number); |
3235 | |
3236 | ::llvm::SmallVector<::mlir::Type, 2> inferredReturnTypes; |
3237 | if (::mlir::succeeded(GetResultOp::inferReturnTypes(odsBuilder.getContext(), |
3238 | odsState.location, odsState.operands, |
3239 | odsState.attributes.getDictionary(odsState.getContext()), |
3240 | /*regions=*/{}, inferredReturnTypes))) |
3241 | odsState.addTypes(inferredReturnTypes); |
3242 | else |
3243 | ::llvm::report_fatal_error("Failed to infer result type(s)." ); |
3244 | } |
3245 | |
3246 | void GetResultOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value value, ::mlir::StringAttr name, ::mlir::IntegerAttr number) { |
3247 | odsState.addOperands(value); |
3248 | odsState.addAttribute(getNameAttrName(odsState.name), name); |
3249 | odsState.addAttribute(getNumberAttrName(odsState.name), number); |
3250 | assert(resultTypes.size() == 1u && "mismatched number of results" ); |
3251 | odsState.addTypes(resultTypes); |
3252 | } |
3253 | |
3254 | void GetResultOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Type result, ::mlir::Value value, ::llvm::StringRef name, uint32_t number) { |
3255 | odsState.addOperands(value); |
3256 | odsState.addAttribute(getNameAttrName(odsState.name), odsBuilder.getStringAttr(name)); |
3257 | odsState.addAttribute(getNumberAttrName(odsState.name), odsBuilder.getIntegerAttr(odsBuilder.getIntegerType(32), number)); |
3258 | odsState.addTypes(result); |
3259 | } |
3260 | |
3261 | void GetResultOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::Value value, ::llvm::StringRef name, uint32_t number) { |
3262 | odsState.addOperands(value); |
3263 | odsState.addAttribute(getNameAttrName(odsState.name), odsBuilder.getStringAttr(name)); |
3264 | odsState.addAttribute(getNumberAttrName(odsState.name), odsBuilder.getIntegerAttr(odsBuilder.getIntegerType(32), number)); |
3265 | |
3266 | ::llvm::SmallVector<::mlir::Type, 2> inferredReturnTypes; |
3267 | if (::mlir::succeeded(GetResultOp::inferReturnTypes(odsBuilder.getContext(), |
3268 | odsState.location, odsState.operands, |
3269 | odsState.attributes.getDictionary(odsState.getContext()), |
3270 | /*regions=*/{}, inferredReturnTypes))) |
3271 | odsState.addTypes(inferredReturnTypes); |
3272 | else |
3273 | ::llvm::report_fatal_error("Failed to infer result type(s)." ); |
3274 | } |
3275 | |
3276 | void GetResultOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value value, ::llvm::StringRef name, uint32_t number) { |
3277 | odsState.addOperands(value); |
3278 | odsState.addAttribute(getNameAttrName(odsState.name), odsBuilder.getStringAttr(name)); |
3279 | odsState.addAttribute(getNumberAttrName(odsState.name), odsBuilder.getIntegerAttr(odsBuilder.getIntegerType(32), number)); |
3280 | assert(resultTypes.size() == 1u && "mismatched number of results" ); |
3281 | odsState.addTypes(resultTypes); |
3282 | } |
3283 | |
3284 | void GetResultOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { |
3285 | assert(operands.size() == 1u && "mismatched number of parameters" ); |
3286 | odsState.addOperands(operands); |
3287 | odsState.addAttributes(attributes); |
3288 | assert(resultTypes.size() == 1u && "mismatched number of return types" ); |
3289 | odsState.addTypes(resultTypes); |
3290 | } |
3291 | |
3292 | void GetResultOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { |
3293 | assert(operands.size() == 1u && "mismatched number of parameters" ); |
3294 | odsState.addOperands(operands); |
3295 | odsState.addAttributes(attributes); |
3296 | |
3297 | ::llvm::SmallVector<::mlir::Type, 2> inferredReturnTypes; |
3298 | if (::mlir::succeeded(GetResultOp::inferReturnTypes(odsBuilder.getContext(), |
3299 | odsState.location, operands, |
3300 | odsState.attributes.getDictionary(odsState.getContext()), |
3301 | odsState.regions, inferredReturnTypes))) { |
3302 | assert(inferredReturnTypes.size() == 1u && "mismatched number of return types" ); |
3303 | odsState.addTypes(inferredReturnTypes); |
3304 | } else { |
3305 | ::llvm::report_fatal_error("Failed to infer result type(s)." ); |
3306 | } |
3307 | } |
3308 | |
3309 | ::mlir::LogicalResult GetResultOp::verifyInvariantsImpl() { |
3310 | auto namedAttrRange = (*this)->getAttrs(); |
3311 | auto namedAttrIt = namedAttrRange.begin(); |
3312 | ::mlir::Attribute tblgen_name; |
3313 | while (true) { |
3314 | if (namedAttrIt == namedAttrRange.end()) |
3315 | return emitOpError("requires attribute 'name'" ); |
3316 | if (namedAttrIt->getName() == getNameAttrName()) { |
3317 | tblgen_name = namedAttrIt->getValue(); |
3318 | break; |
3319 | } |
3320 | ++namedAttrIt; |
3321 | } |
3322 | ::mlir::Attribute tblgen_number; |
3323 | while (true) { |
3324 | if (namedAttrIt == namedAttrRange.end()) |
3325 | return emitOpError("requires attribute 'number'" ); |
3326 | if (namedAttrIt->getName() == getNumberAttrName()) { |
3327 | tblgen_number = namedAttrIt->getValue(); |
3328 | break; |
3329 | } |
3330 | ++namedAttrIt; |
3331 | } |
3332 | |
3333 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops8(*this, tblgen_name, "name" ))) |
3334 | return ::mlir::failure(); |
3335 | |
3336 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops9(*this, tblgen_number, "number" ))) |
3337 | return ::mlir::failure(); |
3338 | { |
3339 | unsigned index = 0; (void)index; |
3340 | auto valueGroup0 = getODSOperands(0); |
3341 | |
3342 | for (auto v : valueGroup0) { |
3343 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops6(*this, v.getType(), "operand" , index++))) |
3344 | return ::mlir::failure(); |
3345 | } |
3346 | } |
3347 | { |
3348 | unsigned index = 0; (void)index; |
3349 | auto valueGroup0 = getODSResults(0); |
3350 | |
3351 | for (auto v : valueGroup0) { |
3352 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops6(*this, v.getType(), "result" , index++))) |
3353 | return ::mlir::failure(); |
3354 | } |
3355 | } |
3356 | return ::mlir::success(); |
3357 | } |
3358 | |
3359 | ::mlir::LogicalResult GetResultOp::verifyInvariants() { |
3360 | return verifyInvariantsImpl(); |
3361 | } |
3362 | |
3363 | ::mlir::LogicalResult GetResultOp::inferReturnTypes(::mlir::MLIRContext *context, ::llvm::Optional<::mlir::Location> location, ::mlir::ValueRange operands, ::mlir::DictionaryAttr attributes, ::mlir::RegionRange regions, ::llvm::SmallVectorImpl<::mlir::Type>&inferredReturnTypes) { |
3364 | inferredReturnTypes.resize(1); |
3365 | ::mlir::Builder odsBuilder(context); |
3366 | ::mlir::Type odsInferredType0 = odsBuilder.getType<::mlir::tf_type::OpaqueTensorType>(); |
3367 | inferredReturnTypes[0] = odsInferredType0; |
3368 | return ::mlir::success(); |
3369 | } |
3370 | |
3371 | ::mlir::ParseResult GetResultOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { |
3372 | ::mlir::OpAsmParser::UnresolvedOperand valueRawOperands[1]; |
3373 | ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> valueOperands(valueRawOperands); ::llvm::SMLoc valueOperandsLoc; |
3374 | (void)valueOperandsLoc; |
3375 | ::mlir::StringAttr nameAttr; |
3376 | ::mlir::IntegerAttr numberAttr; |
3377 | if (parser.parseLParen()) |
3378 | return ::mlir::failure(); |
3379 | |
3380 | valueOperandsLoc = parser.getCurrentLocation(); |
3381 | if (parser.parseOperand(valueRawOperands[0])) |
3382 | return ::mlir::failure(); |
3383 | if (parser.parseRParen()) |
3384 | return ::mlir::failure(); |
3385 | |
3386 | if (parser.parseCustomAttributeWithFallback(nameAttr, parser.getBuilder().getType<::mlir::NoneType>(), "name" , |
3387 | result.attributes)) { |
3388 | return ::mlir::failure(); |
3389 | } |
3390 | if (parser.parseColon()) |
3391 | return ::mlir::failure(); |
3392 | |
3393 | if (parser.parseCustomAttributeWithFallback(numberAttr, parser.getBuilder().getIntegerType(32), "number" , |
3394 | result.attributes)) { |
3395 | return ::mlir::failure(); |
3396 | } |
3397 | if (parser.parseOptionalAttrDictWithKeyword(result.attributes)) |
3398 | return ::mlir::failure(); |
3399 | ::mlir::Type odsBuildableType0 = parser.getBuilder().getType<::mlir::tf_type::OpaqueTensorType>(); |
3400 | result.addTypes(odsBuildableType0); |
3401 | if (parser.resolveOperands(valueOperands, odsBuildableType0, valueOperandsLoc, result.operands)) |
3402 | return ::mlir::failure(); |
3403 | return ::mlir::success(); |
3404 | } |
3405 | |
3406 | void GetResultOp::print(::mlir::OpAsmPrinter &_odsPrinter) { |
3407 | _odsPrinter << "(" ; |
3408 | _odsPrinter << getValue(); |
3409 | _odsPrinter << ")" ; |
3410 | _odsPrinter << ' '; |
3411 | _odsPrinter.printAttributeWithoutType(getNameAttr()); |
3412 | _odsPrinter << ' ' << ":" ; |
3413 | _odsPrinter << ' '; |
3414 | _odsPrinter.printAttributeWithoutType(getNumberAttr()); |
3415 | _odsPrinter.printOptionalAttrDictWithKeyword((*this)->getAttrs(), /*elidedAttrs=*/{"name" , "number" }); |
3416 | } |
3417 | |
3418 | void GetResultOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { |
3419 | } |
3420 | |
3421 | } // namespace tfg |
3422 | } // namespace mlir |
3423 | MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::tfg::GetResultOp) |
3424 | |
3425 | namespace mlir { |
3426 | namespace tfg { |
3427 | |
3428 | //===----------------------------------------------------------------------===// |
3429 | // ::mlir::tfg::GraphFuncOp definitions |
3430 | //===----------------------------------------------------------------------===// |
3431 | |
3432 | GraphFuncOpAdaptor::GraphFuncOpAdaptor(::mlir::ValueRange values, ::mlir::DictionaryAttr attrs, ::mlir::RegionRange regions) : odsOperands(values), odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) |
3433 | odsOpName.emplace("tfg.func" , odsAttrs.getContext()); |
3434 | } |
3435 | |
3436 | GraphFuncOpAdaptor::GraphFuncOpAdaptor(GraphFuncOp op) : odsOperands(op->getOperands()), odsAttrs(op->getAttrDictionary()), odsRegions(op->getRegions()), odsOpName(op->getName()) {} |
3437 | |
3438 | ::mlir::ValueRange GraphFuncOpAdaptor::getOperands() { |
3439 | return odsOperands; |
3440 | } |
3441 | |
3442 | std::pair<unsigned, unsigned> GraphFuncOpAdaptor::getODSOperandIndexAndLength(unsigned index) { |
3443 | return {index, 1}; |
3444 | } |
3445 | |
3446 | ::mlir::ValueRange GraphFuncOpAdaptor::getODSOperands(unsigned index) { |
3447 | auto valueRange = getODSOperandIndexAndLength(index); |
3448 | return {std::next(odsOperands.begin(), valueRange.first), |
3449 | std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; |
3450 | } |
3451 | |
3452 | ::mlir::DictionaryAttr GraphFuncOpAdaptor::getAttributes() { |
3453 | return odsAttrs; |
3454 | } |
3455 | |
3456 | ::mlir::UnitAttr GraphFuncOpAdaptor::getGenericAttr() { |
3457 | assert(odsAttrs && "no attributes when constructing adapter" ); |
3458 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 1, GraphFuncOp::getGenericAttrName(*odsOpName)).dyn_cast_or_null<::mlir::UnitAttr>(); |
3459 | return attr; |
3460 | } |
3461 | |
3462 | bool GraphFuncOpAdaptor::getGeneric() { |
3463 | auto attr = getGenericAttr(); |
3464 | return attr != nullptr; |
3465 | } |
3466 | |
3467 | ::mlir::UnitAttr GraphFuncOpAdaptor::genericAttr() { |
3468 | assert(odsAttrs && "no attributes when constructing adapter" ); |
3469 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 1, GraphFuncOp::getGenericAttrName(*odsOpName)).dyn_cast_or_null<::mlir::UnitAttr>(); |
3470 | return attr; |
3471 | } |
3472 | |
3473 | bool GraphFuncOpAdaptor::generic() { |
3474 | auto attr = genericAttr(); |
3475 | return attr != nullptr; |
3476 | } |
3477 | |
3478 | ::mlir::StringAttr GraphFuncOpAdaptor::getSymNameAttr() { |
3479 | assert(odsAttrs && "no attributes when constructing adapter" ); |
3480 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 0, GraphFuncOp::getSymNameAttrName(*odsOpName)).cast<::mlir::StringAttr>(); |
3481 | return attr; |
3482 | } |
3483 | |
3484 | ::llvm::StringRef GraphFuncOpAdaptor::getSymName() { |
3485 | auto attr = getSymNameAttr(); |
3486 | return attr.getValue(); |
3487 | } |
3488 | |
3489 | ::mlir::StringAttr GraphFuncOpAdaptor::sym_nameAttr() { |
3490 | assert(odsAttrs && "no attributes when constructing adapter" ); |
3491 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 0, GraphFuncOp::getSymNameAttrName(*odsOpName)).cast<::mlir::StringAttr>(); |
3492 | return attr; |
3493 | } |
3494 | |
3495 | ::llvm::StringRef GraphFuncOpAdaptor::sym_name() { |
3496 | auto attr = sym_nameAttr(); |
3497 | return attr.getValue(); |
3498 | } |
3499 | |
3500 | ::mlir::TypeAttr GraphFuncOpAdaptor::getFunctionTypeAttr() { |
3501 | assert(odsAttrs && "no attributes when constructing adapter" ); |
3502 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 1, GraphFuncOp::getFunctionTypeAttrName(*odsOpName)).cast<::mlir::TypeAttr>(); |
3503 | return attr; |
3504 | } |
3505 | |
3506 | ::mlir::FunctionType GraphFuncOpAdaptor::getFunctionType() { |
3507 | auto attr = getFunctionTypeAttr(); |
3508 | return attr.getValue().cast<::mlir::FunctionType>(); |
3509 | } |
3510 | |
3511 | ::mlir::TypeAttr GraphFuncOpAdaptor::function_typeAttr() { |
3512 | assert(odsAttrs && "no attributes when constructing adapter" ); |
3513 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 1, GraphFuncOp::getFunctionTypeAttrName(*odsOpName)).cast<::mlir::TypeAttr>(); |
3514 | return attr; |
3515 | } |
3516 | |
3517 | ::mlir::FunctionType GraphFuncOpAdaptor::function_type() { |
3518 | auto attr = function_typeAttr(); |
3519 | return attr.getValue().cast<::mlir::FunctionType>(); |
3520 | } |
3521 | |
3522 | ::mlir::ArrayAttr GraphFuncOpAdaptor::getArgAttrsAttr() { |
3523 | assert(odsAttrs && "no attributes when constructing adapter" ); |
3524 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, GraphFuncOp::getArgAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
3525 | return attr; |
3526 | } |
3527 | |
3528 | ::llvm::Optional< ::mlir::ArrayAttr > GraphFuncOpAdaptor::getArgAttrs() { |
3529 | auto attr = getArgAttrsAttr(); |
3530 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
3531 | } |
3532 | |
3533 | ::mlir::ArrayAttr GraphFuncOpAdaptor::arg_attrsAttr() { |
3534 | assert(odsAttrs && "no attributes when constructing adapter" ); |
3535 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, GraphFuncOp::getArgAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
3536 | return attr; |
3537 | } |
3538 | |
3539 | ::llvm::Optional< ::mlir::ArrayAttr > GraphFuncOpAdaptor::arg_attrs() { |
3540 | auto attr = arg_attrsAttr(); |
3541 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
3542 | } |
3543 | |
3544 | ::mlir::ArrayAttr GraphFuncOpAdaptor::getResAttrsAttr() { |
3545 | assert(odsAttrs && "no attributes when constructing adapter" ); |
3546 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 1, GraphFuncOp::getResAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
3547 | return attr; |
3548 | } |
3549 | |
3550 | ::llvm::Optional< ::mlir::ArrayAttr > GraphFuncOpAdaptor::getResAttrs() { |
3551 | auto attr = getResAttrsAttr(); |
3552 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
3553 | } |
3554 | |
3555 | ::mlir::ArrayAttr GraphFuncOpAdaptor::res_attrsAttr() { |
3556 | assert(odsAttrs && "no attributes when constructing adapter" ); |
3557 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 1, GraphFuncOp::getResAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
3558 | return attr; |
3559 | } |
3560 | |
3561 | ::llvm::Optional< ::mlir::ArrayAttr > GraphFuncOpAdaptor::res_attrs() { |
3562 | auto attr = res_attrsAttr(); |
3563 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
3564 | } |
3565 | |
3566 | ::mlir::StringAttr GraphFuncOpAdaptor::getDescriptionAttr() { |
3567 | assert(odsAttrs && "no attributes when constructing adapter" ); |
3568 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, GraphFuncOp::getDescriptionAttrName(*odsOpName)).dyn_cast_or_null<::mlir::StringAttr>(); |
3569 | return attr; |
3570 | } |
3571 | |
3572 | ::llvm::Optional< ::llvm::StringRef > GraphFuncOpAdaptor::getDescription() { |
3573 | auto attr = getDescriptionAttr(); |
3574 | return attr ? ::llvm::Optional< ::llvm::StringRef >(attr.getValue()) : (::llvm::None); |
3575 | } |
3576 | |
3577 | ::mlir::StringAttr GraphFuncOpAdaptor::descriptionAttr() { |
3578 | assert(odsAttrs && "no attributes when constructing adapter" ); |
3579 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, GraphFuncOp::getDescriptionAttrName(*odsOpName)).dyn_cast_or_null<::mlir::StringAttr>(); |
3580 | return attr; |
3581 | } |
3582 | |
3583 | ::llvm::Optional< ::llvm::StringRef > GraphFuncOpAdaptor::description() { |
3584 | auto attr = descriptionAttr(); |
3585 | return attr ? ::llvm::Optional< ::llvm::StringRef >(attr.getValue()) : (::llvm::None); |
3586 | } |
3587 | |
3588 | ::mlir::UnitAttr GraphFuncOpAdaptor::getIsStatefulAttr() { |
3589 | assert(odsAttrs && "no attributes when constructing adapter" ); |
3590 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 1, GraphFuncOp::getIsStatefulAttrName(*odsOpName)).dyn_cast_or_null<::mlir::UnitAttr>(); |
3591 | return attr; |
3592 | } |
3593 | |
3594 | bool GraphFuncOpAdaptor::getIsStateful() { |
3595 | auto attr = getIsStatefulAttr(); |
3596 | return attr != nullptr; |
3597 | } |
3598 | |
3599 | ::mlir::UnitAttr GraphFuncOpAdaptor::is_statefulAttr() { |
3600 | assert(odsAttrs && "no attributes when constructing adapter" ); |
3601 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 1, GraphFuncOp::getIsStatefulAttrName(*odsOpName)).dyn_cast_or_null<::mlir::UnitAttr>(); |
3602 | return attr; |
3603 | } |
3604 | |
3605 | bool GraphFuncOpAdaptor::is_stateful() { |
3606 | auto attr = is_statefulAttr(); |
3607 | return attr != nullptr; |
3608 | } |
3609 | |
3610 | ::mlir::FlatSymbolRefAttr GraphFuncOpAdaptor::getGradientAttr() { |
3611 | assert(odsAttrs && "no attributes when constructing adapter" ); |
3612 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 1, GraphFuncOp::getGradientAttrName(*odsOpName)).dyn_cast_or_null<::mlir::FlatSymbolRefAttr>(); |
3613 | return attr; |
3614 | } |
3615 | |
3616 | ::llvm::Optional< ::llvm::StringRef > GraphFuncOpAdaptor::getGradient() { |
3617 | auto attr = getGradientAttr(); |
3618 | return attr ? ::llvm::Optional< ::llvm::StringRef >(attr.getValue()) : (::llvm::None); |
3619 | } |
3620 | |
3621 | ::mlir::FlatSymbolRefAttr GraphFuncOpAdaptor::gradientAttr() { |
3622 | assert(odsAttrs && "no attributes when constructing adapter" ); |
3623 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 1, GraphFuncOp::getGradientAttrName(*odsOpName)).dyn_cast_or_null<::mlir::FlatSymbolRefAttr>(); |
3624 | return attr; |
3625 | } |
3626 | |
3627 | ::llvm::Optional< ::llvm::StringRef > GraphFuncOpAdaptor::gradient() { |
3628 | auto attr = gradientAttr(); |
3629 | return attr ? ::llvm::Optional< ::llvm::StringRef >(attr.getValue()) : (::llvm::None); |
3630 | } |
3631 | |
3632 | ::mlir::DenseIntElementsAttr GraphFuncOpAdaptor::getResourceArgUniqueIdsKeysAttr() { |
3633 | assert(odsAttrs && "no attributes when constructing adapter" ); |
3634 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 1, GraphFuncOp::getResourceArgUniqueIdsKeysAttrName(*odsOpName)).dyn_cast_or_null<::mlir::DenseIntElementsAttr>(); |
3635 | return attr; |
3636 | } |
3637 | |
3638 | ::llvm::Optional< ::mlir::DenseIntElementsAttr > GraphFuncOpAdaptor::getResourceArgUniqueIdsKeys() { |
3639 | auto attr = getResourceArgUniqueIdsKeysAttr(); |
3640 | return attr ? ::llvm::Optional< ::mlir::DenseIntElementsAttr >(attr) : (::llvm::None); |
3641 | } |
3642 | |
3643 | ::mlir::DenseIntElementsAttr GraphFuncOpAdaptor::resource_arg_unique_ids_keysAttr() { |
3644 | assert(odsAttrs && "no attributes when constructing adapter" ); |
3645 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 1, GraphFuncOp::getResourceArgUniqueIdsKeysAttrName(*odsOpName)).dyn_cast_or_null<::mlir::DenseIntElementsAttr>(); |
3646 | return attr; |
3647 | } |
3648 | |
3649 | ::llvm::Optional< ::mlir::DenseIntElementsAttr > GraphFuncOpAdaptor::resource_arg_unique_ids_keys() { |
3650 | auto attr = resource_arg_unique_ids_keysAttr(); |
3651 | return attr ? ::llvm::Optional< ::mlir::DenseIntElementsAttr >(attr) : (::llvm::None); |
3652 | } |
3653 | |
3654 | ::mlir::DenseIntElementsAttr GraphFuncOpAdaptor::getResourceArgUniqueIdsValuesAttr() { |
3655 | assert(odsAttrs && "no attributes when constructing adapter" ); |
3656 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 1, GraphFuncOp::getResourceArgUniqueIdsValuesAttrName(*odsOpName)).dyn_cast_or_null<::mlir::DenseIntElementsAttr>(); |
3657 | return attr; |
3658 | } |
3659 | |
3660 | ::llvm::Optional< ::mlir::DenseIntElementsAttr > GraphFuncOpAdaptor::getResourceArgUniqueIdsValues() { |
3661 | auto attr = getResourceArgUniqueIdsValuesAttr(); |
3662 | return attr ? ::llvm::Optional< ::mlir::DenseIntElementsAttr >(attr) : (::llvm::None); |
3663 | } |
3664 | |
3665 | ::mlir::DenseIntElementsAttr GraphFuncOpAdaptor::resource_arg_unique_ids_valuesAttr() { |
3666 | assert(odsAttrs && "no attributes when constructing adapter" ); |
3667 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 1, GraphFuncOp::getResourceArgUniqueIdsValuesAttrName(*odsOpName)).dyn_cast_or_null<::mlir::DenseIntElementsAttr>(); |
3668 | return attr; |
3669 | } |
3670 | |
3671 | ::llvm::Optional< ::mlir::DenseIntElementsAttr > GraphFuncOpAdaptor::resource_arg_unique_ids_values() { |
3672 | auto attr = resource_arg_unique_ids_valuesAttr(); |
3673 | return attr ? ::llvm::Optional< ::mlir::DenseIntElementsAttr >(attr) : (::llvm::None); |
3674 | } |
3675 | |
3676 | ::mlir::ArrayAttr GraphFuncOpAdaptor::getControlOutputAttr() { |
3677 | assert(odsAttrs && "no attributes when constructing adapter" ); |
3678 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, GraphFuncOp::getControlOutputAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
3679 | return attr; |
3680 | } |
3681 | |
3682 | ::llvm::Optional< ::mlir::ArrayAttr > GraphFuncOpAdaptor::getControlOutput() { |
3683 | auto attr = getControlOutputAttr(); |
3684 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
3685 | } |
3686 | |
3687 | ::mlir::ArrayAttr GraphFuncOpAdaptor::control_outputAttr() { |
3688 | assert(odsAttrs && "no attributes when constructing adapter" ); |
3689 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, GraphFuncOp::getControlOutputAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
3690 | return attr; |
3691 | } |
3692 | |
3693 | ::llvm::Optional< ::mlir::ArrayAttr > GraphFuncOpAdaptor::control_output() { |
3694 | auto attr = control_outputAttr(); |
3695 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
3696 | } |
3697 | |
3698 | ::mlir::RegionRange GraphFuncOpAdaptor::getRegions() { |
3699 | return odsRegions; |
3700 | } |
3701 | |
3702 | ::mlir::Region &GraphFuncOpAdaptor::getBody() { |
3703 | return *odsRegions[0]; |
3704 | } |
3705 | |
3706 | ::mlir::Region &GraphFuncOpAdaptor::body() { |
3707 | return *odsRegions[0]; |
3708 | } |
3709 | |
3710 | ::mlir::LogicalResult GraphFuncOpAdaptor::verify(::mlir::Location loc) { |
3711 | auto namedAttrRange = odsAttrs; |
3712 | auto namedAttrIt = namedAttrRange.begin(); |
3713 | ::mlir::Attribute tblgen_function_type; |
3714 | ::mlir::Attribute tblgen_arg_attrs; |
3715 | ::mlir::Attribute tblgen_control_output; |
3716 | ::mlir::Attribute tblgen_description; |
3717 | while (true) { |
3718 | if (namedAttrIt == namedAttrRange.end()) |
3719 | return emitError(loc, "'tfg.func' op " "requires attribute 'function_type'" ); |
3720 | if (namedAttrIt->getName() == GraphFuncOp::getFunctionTypeAttrName(*odsOpName)) { |
3721 | tblgen_function_type = namedAttrIt->getValue(); |
3722 | break; |
3723 | } |
3724 | else if (namedAttrIt->getName() == GraphFuncOp::getArgAttrsAttrName(*odsOpName)) { |
3725 | tblgen_arg_attrs = namedAttrIt->getValue(); |
3726 | } |
3727 | else if (namedAttrIt->getName() == GraphFuncOp::getControlOutputAttrName(*odsOpName)) { |
3728 | tblgen_control_output = namedAttrIt->getValue(); |
3729 | } |
3730 | else if (namedAttrIt->getName() == GraphFuncOp::getDescriptionAttrName(*odsOpName)) { |
3731 | tblgen_description = namedAttrIt->getValue(); |
3732 | } |
3733 | ++namedAttrIt; |
3734 | } |
3735 | ::mlir::Attribute tblgen_sym_name; |
3736 | ::mlir::Attribute tblgen_generic; |
3737 | ::mlir::Attribute tblgen_gradient; |
3738 | ::mlir::Attribute tblgen_is_stateful; |
3739 | ::mlir::Attribute tblgen_res_attrs; |
3740 | ::mlir::Attribute tblgen_resource_arg_unique_ids_keys; |
3741 | ::mlir::Attribute tblgen_resource_arg_unique_ids_values; |
3742 | while (true) { |
3743 | if (namedAttrIt == namedAttrRange.end()) |
3744 | return emitError(loc, "'tfg.func' op " "requires attribute 'sym_name'" ); |
3745 | if (namedAttrIt->getName() == GraphFuncOp::getSymNameAttrName(*odsOpName)) { |
3746 | tblgen_sym_name = namedAttrIt->getValue(); |
3747 | break; |
3748 | } |
3749 | else if (namedAttrIt->getName() == GraphFuncOp::getGenericAttrName(*odsOpName)) { |
3750 | tblgen_generic = namedAttrIt->getValue(); |
3751 | } |
3752 | else if (namedAttrIt->getName() == GraphFuncOp::getGradientAttrName(*odsOpName)) { |
3753 | tblgen_gradient = namedAttrIt->getValue(); |
3754 | } |
3755 | else if (namedAttrIt->getName() == GraphFuncOp::getIsStatefulAttrName(*odsOpName)) { |
3756 | tblgen_is_stateful = namedAttrIt->getValue(); |
3757 | } |
3758 | else if (namedAttrIt->getName() == GraphFuncOp::getResAttrsAttrName(*odsOpName)) { |
3759 | tblgen_res_attrs = namedAttrIt->getValue(); |
3760 | } |
3761 | else if (namedAttrIt->getName() == GraphFuncOp::getResourceArgUniqueIdsKeysAttrName(*odsOpName)) { |
3762 | tblgen_resource_arg_unique_ids_keys = namedAttrIt->getValue(); |
3763 | } |
3764 | else if (namedAttrIt->getName() == GraphFuncOp::getResourceArgUniqueIdsValuesAttrName(*odsOpName)) { |
3765 | tblgen_resource_arg_unique_ids_values = namedAttrIt->getValue(); |
3766 | } |
3767 | ++namedAttrIt; |
3768 | } |
3769 | |
3770 | if (tblgen_generic && !((tblgen_generic.isa<::mlir::UnitAttr>()))) |
3771 | return emitError(loc, "'tfg.func' op " "attribute 'generic' failed to satisfy constraint: unit attribute" ); |
3772 | |
3773 | if (tblgen_sym_name && !((tblgen_sym_name.isa<::mlir::StringAttr>()))) |
3774 | return emitError(loc, "'tfg.func' op " "attribute 'sym_name' failed to satisfy constraint: string attribute" ); |
3775 | |
3776 | if (tblgen_function_type && !(((tblgen_function_type.isa<::mlir::TypeAttr>())) && ((tblgen_function_type.cast<::mlir::TypeAttr>().getValue().isa<::mlir::FunctionType>())))) |
3777 | return emitError(loc, "'tfg.func' op " "attribute 'function_type' failed to satisfy constraint: type attribute of function type" ); |
3778 | |
3779 | if (tblgen_arg_attrs && !((tblgen_arg_attrs.isa<::mlir::ArrayAttr>()))) |
3780 | return emitError(loc, "'tfg.func' op " "attribute 'arg_attrs' failed to satisfy constraint: array attribute" ); |
3781 | |
3782 | if (tblgen_res_attrs && !((tblgen_res_attrs.isa<::mlir::ArrayAttr>()))) |
3783 | return emitError(loc, "'tfg.func' op " "attribute 'res_attrs' failed to satisfy constraint: array attribute" ); |
3784 | |
3785 | if (tblgen_description && !((tblgen_description.isa<::mlir::StringAttr>()))) |
3786 | return emitError(loc, "'tfg.func' op " "attribute 'description' failed to satisfy constraint: string attribute" ); |
3787 | |
3788 | if (tblgen_is_stateful && !((tblgen_is_stateful.isa<::mlir::UnitAttr>()))) |
3789 | return emitError(loc, "'tfg.func' op " "attribute 'is_stateful' failed to satisfy constraint: unit attribute" ); |
3790 | |
3791 | if (tblgen_gradient && !((tblgen_gradient.isa<::mlir::FlatSymbolRefAttr>()))) |
3792 | return emitError(loc, "'tfg.func' op " "attribute 'gradient' failed to satisfy constraint: flat symbol reference attribute" ); |
3793 | |
3794 | if (tblgen_resource_arg_unique_ids_keys && !(((tblgen_resource_arg_unique_ids_keys.isa<::mlir::DenseIntElementsAttr>())) && ((tblgen_resource_arg_unique_ids_keys.cast<::mlir::DenseIntElementsAttr>().getType().getElementType().isSignlessInteger(32))))) |
3795 | return emitError(loc, "'tfg.func' op " "attribute 'resource_arg_unique_ids_keys' failed to satisfy constraint: 32-bit signless integer elements attribute" ); |
3796 | |
3797 | if (tblgen_resource_arg_unique_ids_values && !(((tblgen_resource_arg_unique_ids_values.isa<::mlir::DenseIntElementsAttr>())) && ((tblgen_resource_arg_unique_ids_values.cast<::mlir::DenseIntElementsAttr>().getType().getElementType().isSignlessInteger(32))))) |
3798 | return emitError(loc, "'tfg.func' op " "attribute 'resource_arg_unique_ids_values' failed to satisfy constraint: 32-bit signless integer elements attribute" ); |
3799 | |
3800 | if (tblgen_control_output && !(((tblgen_control_output.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_control_output.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && ((attr.isa<::mlir::StringAttr>())); })))) |
3801 | return emitError(loc, "'tfg.func' op " "attribute 'control_output' failed to satisfy constraint: string array attribute" ); |
3802 | return ::mlir::success(); |
3803 | } |
3804 | |
3805 | std::pair<unsigned, unsigned> GraphFuncOp::getODSOperandIndexAndLength(unsigned index) { |
3806 | return {index, 1}; |
3807 | } |
3808 | |
3809 | ::mlir::Operation::operand_range GraphFuncOp::getODSOperands(unsigned index) { |
3810 | auto valueRange = getODSOperandIndexAndLength(index); |
3811 | return {std::next(getOperation()->operand_begin(), valueRange.first), |
3812 | std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; |
3813 | } |
3814 | |
3815 | std::pair<unsigned, unsigned> GraphFuncOp::getODSResultIndexAndLength(unsigned index) { |
3816 | return {index, 1}; |
3817 | } |
3818 | |
3819 | ::mlir::Operation::result_range GraphFuncOp::getODSResults(unsigned index) { |
3820 | auto valueRange = getODSResultIndexAndLength(index); |
3821 | return {std::next(getOperation()->result_begin(), valueRange.first), |
3822 | std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; |
3823 | } |
3824 | |
3825 | ::mlir::Region &GraphFuncOp::getBody() { |
3826 | return (*this)->getRegion(0); |
3827 | } |
3828 | |
3829 | ::mlir::Region &GraphFuncOp::body() { |
3830 | return (*this)->getRegion(0); |
3831 | } |
3832 | |
3833 | ::mlir::UnitAttr GraphFuncOp::getGenericAttr() { |
3834 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 1, getGenericAttrName()).dyn_cast_or_null<::mlir::UnitAttr>(); |
3835 | } |
3836 | |
3837 | bool GraphFuncOp::getGeneric() { |
3838 | auto attr = getGenericAttr(); |
3839 | return attr != nullptr; |
3840 | } |
3841 | |
3842 | ::mlir::UnitAttr GraphFuncOp::genericAttr() { |
3843 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 1, getGenericAttrName()).dyn_cast_or_null<::mlir::UnitAttr>(); |
3844 | } |
3845 | |
3846 | bool GraphFuncOp::generic() { |
3847 | auto attr = genericAttr(); |
3848 | return attr != nullptr; |
3849 | } |
3850 | |
3851 | ::mlir::StringAttr GraphFuncOp::getSymNameAttr() { |
3852 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getSymNameAttrName()).cast<::mlir::StringAttr>(); |
3853 | } |
3854 | |
3855 | ::llvm::StringRef GraphFuncOp::getSymName() { |
3856 | auto attr = getSymNameAttr(); |
3857 | return attr.getValue(); |
3858 | } |
3859 | |
3860 | ::mlir::StringAttr GraphFuncOp::sym_nameAttr() { |
3861 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getSymNameAttrName()).cast<::mlir::StringAttr>(); |
3862 | } |
3863 | |
3864 | ::llvm::StringRef GraphFuncOp::sym_name() { |
3865 | auto attr = sym_nameAttr(); |
3866 | return attr.getValue(); |
3867 | } |
3868 | |
3869 | ::mlir::TypeAttr GraphFuncOp::getFunctionTypeAttr() { |
3870 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getFunctionTypeAttrName()).cast<::mlir::TypeAttr>(); |
3871 | } |
3872 | |
3873 | ::mlir::FunctionType GraphFuncOp::getFunctionType() { |
3874 | auto attr = getFunctionTypeAttr(); |
3875 | return attr.getValue().cast<::mlir::FunctionType>(); |
3876 | } |
3877 | |
3878 | ::mlir::TypeAttr GraphFuncOp::function_typeAttr() { |
3879 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getFunctionTypeAttrName()).cast<::mlir::TypeAttr>(); |
3880 | } |
3881 | |
3882 | ::mlir::FunctionType GraphFuncOp::function_type() { |
3883 | auto attr = function_typeAttr(); |
3884 | return attr.getValue().cast<::mlir::FunctionType>(); |
3885 | } |
3886 | |
3887 | ::mlir::ArrayAttr GraphFuncOp::getArgAttrsAttr() { |
3888 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getArgAttrsAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
3889 | } |
3890 | |
3891 | ::llvm::Optional< ::mlir::ArrayAttr > GraphFuncOp::getArgAttrs() { |
3892 | auto attr = getArgAttrsAttr(); |
3893 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
3894 | } |
3895 | |
3896 | ::mlir::ArrayAttr GraphFuncOp::arg_attrsAttr() { |
3897 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getArgAttrsAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
3898 | } |
3899 | |
3900 | ::llvm::Optional< ::mlir::ArrayAttr > GraphFuncOp::arg_attrs() { |
3901 | auto attr = arg_attrsAttr(); |
3902 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
3903 | } |
3904 | |
3905 | ::mlir::ArrayAttr GraphFuncOp::getResAttrsAttr() { |
3906 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 1, getResAttrsAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
3907 | } |
3908 | |
3909 | ::llvm::Optional< ::mlir::ArrayAttr > GraphFuncOp::getResAttrs() { |
3910 | auto attr = getResAttrsAttr(); |
3911 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
3912 | } |
3913 | |
3914 | ::mlir::ArrayAttr GraphFuncOp::res_attrsAttr() { |
3915 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 1, getResAttrsAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
3916 | } |
3917 | |
3918 | ::llvm::Optional< ::mlir::ArrayAttr > GraphFuncOp::res_attrs() { |
3919 | auto attr = res_attrsAttr(); |
3920 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
3921 | } |
3922 | |
3923 | ::mlir::StringAttr GraphFuncOp::getDescriptionAttr() { |
3924 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getDescriptionAttrName()).dyn_cast_or_null<::mlir::StringAttr>(); |
3925 | } |
3926 | |
3927 | ::llvm::Optional< ::llvm::StringRef > GraphFuncOp::getDescription() { |
3928 | auto attr = getDescriptionAttr(); |
3929 | return attr ? ::llvm::Optional< ::llvm::StringRef >(attr.getValue()) : (::llvm::None); |
3930 | } |
3931 | |
3932 | ::mlir::StringAttr GraphFuncOp::descriptionAttr() { |
3933 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getDescriptionAttrName()).dyn_cast_or_null<::mlir::StringAttr>(); |
3934 | } |
3935 | |
3936 | ::llvm::Optional< ::llvm::StringRef > GraphFuncOp::description() { |
3937 | auto attr = descriptionAttr(); |
3938 | return attr ? ::llvm::Optional< ::llvm::StringRef >(attr.getValue()) : (::llvm::None); |
3939 | } |
3940 | |
3941 | ::mlir::UnitAttr GraphFuncOp::getIsStatefulAttr() { |
3942 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 1, getIsStatefulAttrName()).dyn_cast_or_null<::mlir::UnitAttr>(); |
3943 | } |
3944 | |
3945 | bool GraphFuncOp::getIsStateful() { |
3946 | auto attr = getIsStatefulAttr(); |
3947 | return attr != nullptr; |
3948 | } |
3949 | |
3950 | ::mlir::UnitAttr GraphFuncOp::is_statefulAttr() { |
3951 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 1, getIsStatefulAttrName()).dyn_cast_or_null<::mlir::UnitAttr>(); |
3952 | } |
3953 | |
3954 | bool GraphFuncOp::is_stateful() { |
3955 | auto attr = is_statefulAttr(); |
3956 | return attr != nullptr; |
3957 | } |
3958 | |
3959 | ::mlir::FlatSymbolRefAttr GraphFuncOp::getGradientAttr() { |
3960 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 1, getGradientAttrName()).dyn_cast_or_null<::mlir::FlatSymbolRefAttr>(); |
3961 | } |
3962 | |
3963 | ::llvm::Optional< ::llvm::StringRef > GraphFuncOp::getGradient() { |
3964 | auto attr = getGradientAttr(); |
3965 | return attr ? ::llvm::Optional< ::llvm::StringRef >(attr.getValue()) : (::llvm::None); |
3966 | } |
3967 | |
3968 | ::mlir::FlatSymbolRefAttr GraphFuncOp::gradientAttr() { |
3969 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 1, getGradientAttrName()).dyn_cast_or_null<::mlir::FlatSymbolRefAttr>(); |
3970 | } |
3971 | |
3972 | ::llvm::Optional< ::llvm::StringRef > GraphFuncOp::gradient() { |
3973 | auto attr = gradientAttr(); |
3974 | return attr ? ::llvm::Optional< ::llvm::StringRef >(attr.getValue()) : (::llvm::None); |
3975 | } |
3976 | |
3977 | ::mlir::DenseIntElementsAttr GraphFuncOp::getResourceArgUniqueIdsKeysAttr() { |
3978 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 1, getResourceArgUniqueIdsKeysAttrName()).dyn_cast_or_null<::mlir::DenseIntElementsAttr>(); |
3979 | } |
3980 | |
3981 | ::llvm::Optional< ::mlir::DenseIntElementsAttr > GraphFuncOp::getResourceArgUniqueIdsKeys() { |
3982 | auto attr = getResourceArgUniqueIdsKeysAttr(); |
3983 | return attr ? ::llvm::Optional< ::mlir::DenseIntElementsAttr >(attr) : (::llvm::None); |
3984 | } |
3985 | |
3986 | ::mlir::DenseIntElementsAttr GraphFuncOp::resource_arg_unique_ids_keysAttr() { |
3987 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 1, getResourceArgUniqueIdsKeysAttrName()).dyn_cast_or_null<::mlir::DenseIntElementsAttr>(); |
3988 | } |
3989 | |
3990 | ::llvm::Optional< ::mlir::DenseIntElementsAttr > GraphFuncOp::resource_arg_unique_ids_keys() { |
3991 | auto attr = resource_arg_unique_ids_keysAttr(); |
3992 | return attr ? ::llvm::Optional< ::mlir::DenseIntElementsAttr >(attr) : (::llvm::None); |
3993 | } |
3994 | |
3995 | ::mlir::DenseIntElementsAttr GraphFuncOp::getResourceArgUniqueIdsValuesAttr() { |
3996 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 1, getResourceArgUniqueIdsValuesAttrName()).dyn_cast_or_null<::mlir::DenseIntElementsAttr>(); |
3997 | } |
3998 | |
3999 | ::llvm::Optional< ::mlir::DenseIntElementsAttr > GraphFuncOp::getResourceArgUniqueIdsValues() { |
4000 | auto attr = getResourceArgUniqueIdsValuesAttr(); |
4001 | return attr ? ::llvm::Optional< ::mlir::DenseIntElementsAttr >(attr) : (::llvm::None); |
4002 | } |
4003 | |
4004 | ::mlir::DenseIntElementsAttr GraphFuncOp::resource_arg_unique_ids_valuesAttr() { |
4005 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 1, getResourceArgUniqueIdsValuesAttrName()).dyn_cast_or_null<::mlir::DenseIntElementsAttr>(); |
4006 | } |
4007 | |
4008 | ::llvm::Optional< ::mlir::DenseIntElementsAttr > GraphFuncOp::resource_arg_unique_ids_values() { |
4009 | auto attr = resource_arg_unique_ids_valuesAttr(); |
4010 | return attr ? ::llvm::Optional< ::mlir::DenseIntElementsAttr >(attr) : (::llvm::None); |
4011 | } |
4012 | |
4013 | ::mlir::ArrayAttr GraphFuncOp::getControlOutputAttr() { |
4014 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getControlOutputAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
4015 | } |
4016 | |
4017 | ::llvm::Optional< ::mlir::ArrayAttr > GraphFuncOp::getControlOutput() { |
4018 | auto attr = getControlOutputAttr(); |
4019 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
4020 | } |
4021 | |
4022 | ::mlir::ArrayAttr GraphFuncOp::control_outputAttr() { |
4023 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getControlOutputAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
4024 | } |
4025 | |
4026 | ::llvm::Optional< ::mlir::ArrayAttr > GraphFuncOp::control_output() { |
4027 | auto attr = control_outputAttr(); |
4028 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
4029 | } |
4030 | |
4031 | void GraphFuncOp::setGenericAttr(::mlir::UnitAttr attr) { |
4032 | (*this)->setAttr(getGenericAttrName(), attr); |
4033 | } |
4034 | |
4035 | void GraphFuncOp::genericAttr(::mlir::UnitAttr attr) { |
4036 | (*this)->setAttr(genericAttrName(), attr); |
4037 | } |
4038 | |
4039 | void GraphFuncOp::setSymNameAttr(::mlir::StringAttr attr) { |
4040 | (*this)->setAttr(getSymNameAttrName(), attr); |
4041 | } |
4042 | |
4043 | void GraphFuncOp::sym_nameAttr(::mlir::StringAttr attr) { |
4044 | (*this)->setAttr(sym_nameAttrName(), attr); |
4045 | } |
4046 | |
4047 | void GraphFuncOp::setFunctionTypeAttr(::mlir::TypeAttr attr) { |
4048 | (*this)->setAttr(getFunctionTypeAttrName(), attr); |
4049 | } |
4050 | |
4051 | void GraphFuncOp::function_typeAttr(::mlir::TypeAttr attr) { |
4052 | (*this)->setAttr(function_typeAttrName(), attr); |
4053 | } |
4054 | |
4055 | void GraphFuncOp::setArgAttrsAttr(::mlir::ArrayAttr attr) { |
4056 | (*this)->setAttr(getArgAttrsAttrName(), attr); |
4057 | } |
4058 | |
4059 | void GraphFuncOp::arg_attrsAttr(::mlir::ArrayAttr attr) { |
4060 | (*this)->setAttr(arg_attrsAttrName(), attr); |
4061 | } |
4062 | |
4063 | void GraphFuncOp::setResAttrsAttr(::mlir::ArrayAttr attr) { |
4064 | (*this)->setAttr(getResAttrsAttrName(), attr); |
4065 | } |
4066 | |
4067 | void GraphFuncOp::res_attrsAttr(::mlir::ArrayAttr attr) { |
4068 | (*this)->setAttr(res_attrsAttrName(), attr); |
4069 | } |
4070 | |
4071 | void GraphFuncOp::setDescriptionAttr(::mlir::StringAttr attr) { |
4072 | (*this)->setAttr(getDescriptionAttrName(), attr); |
4073 | } |
4074 | |
4075 | void GraphFuncOp::descriptionAttr(::mlir::StringAttr attr) { |
4076 | (*this)->setAttr(descriptionAttrName(), attr); |
4077 | } |
4078 | |
4079 | void GraphFuncOp::setIsStatefulAttr(::mlir::UnitAttr attr) { |
4080 | (*this)->setAttr(getIsStatefulAttrName(), attr); |
4081 | } |
4082 | |
4083 | void GraphFuncOp::is_statefulAttr(::mlir::UnitAttr attr) { |
4084 | (*this)->setAttr(is_statefulAttrName(), attr); |
4085 | } |
4086 | |
4087 | void GraphFuncOp::setGradientAttr(::mlir::FlatSymbolRefAttr attr) { |
4088 | (*this)->setAttr(getGradientAttrName(), attr); |
4089 | } |
4090 | |
4091 | void GraphFuncOp::gradientAttr(::mlir::FlatSymbolRefAttr attr) { |
4092 | (*this)->setAttr(gradientAttrName(), attr); |
4093 | } |
4094 | |
4095 | void GraphFuncOp::setResourceArgUniqueIdsKeysAttr(::mlir::DenseIntElementsAttr attr) { |
4096 | (*this)->setAttr(getResourceArgUniqueIdsKeysAttrName(), attr); |
4097 | } |
4098 | |
4099 | void GraphFuncOp::resource_arg_unique_ids_keysAttr(::mlir::DenseIntElementsAttr attr) { |
4100 | (*this)->setAttr(resource_arg_unique_ids_keysAttrName(), attr); |
4101 | } |
4102 | |
4103 | void GraphFuncOp::setResourceArgUniqueIdsValuesAttr(::mlir::DenseIntElementsAttr attr) { |
4104 | (*this)->setAttr(getResourceArgUniqueIdsValuesAttrName(), attr); |
4105 | } |
4106 | |
4107 | void GraphFuncOp::resource_arg_unique_ids_valuesAttr(::mlir::DenseIntElementsAttr attr) { |
4108 | (*this)->setAttr(resource_arg_unique_ids_valuesAttrName(), attr); |
4109 | } |
4110 | |
4111 | void GraphFuncOp::setControlOutputAttr(::mlir::ArrayAttr attr) { |
4112 | (*this)->setAttr(getControlOutputAttrName(), attr); |
4113 | } |
4114 | |
4115 | void GraphFuncOp::control_outputAttr(::mlir::ArrayAttr attr) { |
4116 | (*this)->setAttr(control_outputAttrName(), attr); |
4117 | } |
4118 | |
4119 | ::mlir::Attribute GraphFuncOp::removeGenericAttr() { |
4120 | return (*this)->removeAttr(getGenericAttrName()); |
4121 | } |
4122 | |
4123 | ::mlir::Attribute GraphFuncOp::removeArg_attrsAttr() { |
4124 | return (*this)->removeAttr(getArgAttrsAttrName()); |
4125 | } |
4126 | |
4127 | ::mlir::Attribute GraphFuncOp::removeRes_attrsAttr() { |
4128 | return (*this)->removeAttr(getResAttrsAttrName()); |
4129 | } |
4130 | |
4131 | ::mlir::Attribute GraphFuncOp::removeDescriptionAttr() { |
4132 | return (*this)->removeAttr(getDescriptionAttrName()); |
4133 | } |
4134 | |
4135 | ::mlir::Attribute GraphFuncOp::removeIs_statefulAttr() { |
4136 | return (*this)->removeAttr(getIsStatefulAttrName()); |
4137 | } |
4138 | |
4139 | ::mlir::Attribute GraphFuncOp::removeGradientAttr() { |
4140 | return (*this)->removeAttr(getGradientAttrName()); |
4141 | } |
4142 | |
4143 | ::mlir::Attribute GraphFuncOp::removeResource_arg_unique_ids_keysAttr() { |
4144 | return (*this)->removeAttr(getResourceArgUniqueIdsKeysAttrName()); |
4145 | } |
4146 | |
4147 | ::mlir::Attribute GraphFuncOp::removeResource_arg_unique_ids_valuesAttr() { |
4148 | return (*this)->removeAttr(getResourceArgUniqueIdsValuesAttrName()); |
4149 | } |
4150 | |
4151 | ::mlir::Attribute GraphFuncOp::removeControl_outputAttr() { |
4152 | return (*this)->removeAttr(getControlOutputAttrName()); |
4153 | } |
4154 | |
4155 | void GraphFuncOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState) { |
4156 | (void)odsState.addRegion(); |
4157 | } |
4158 | |
4159 | void GraphFuncOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, const Twine &sym_name, FunctionType type, bool generic) { |
4160 | build(odsBuilder, odsState); |
4161 | odsState.addAttribute(GraphFuncOp::sym_nameAttrName(odsState.name), |
4162 | odsBuilder.getStringAttr(sym_name)); |
4163 | odsState.addAttribute(GraphFuncOp::function_typeAttrName(odsState.name), |
4164 | TypeAttr::get(type)); |
4165 | if (generic) { |
4166 | odsState.addAttribute(GraphFuncOp::genericAttrName(odsState.name), |
4167 | odsBuilder.getUnitAttr()); |
4168 | } |
4169 | |
4170 | } |
4171 | |
4172 | void GraphFuncOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, /*optional*/::mlir::UnitAttr generic, ::mlir::StringAttr sym_name, ::mlir::TypeAttr function_type, /*optional*/::mlir::ArrayAttr arg_attrs, /*optional*/::mlir::ArrayAttr res_attrs, /*optional*/::mlir::StringAttr description, /*optional*/::mlir::UnitAttr is_stateful, /*optional*/::mlir::FlatSymbolRefAttr gradient, /*optional*/::mlir::DenseIntElementsAttr resource_arg_unique_ids_keys, /*optional*/::mlir::DenseIntElementsAttr resource_arg_unique_ids_values, /*optional*/::mlir::ArrayAttr control_output) { |
4173 | if (generic) { |
4174 | odsState.addAttribute(getGenericAttrName(odsState.name), generic); |
4175 | } |
4176 | odsState.addAttribute(getSymNameAttrName(odsState.name), sym_name); |
4177 | odsState.addAttribute(getFunctionTypeAttrName(odsState.name), function_type); |
4178 | if (arg_attrs) { |
4179 | odsState.addAttribute(getArgAttrsAttrName(odsState.name), arg_attrs); |
4180 | } |
4181 | if (res_attrs) { |
4182 | odsState.addAttribute(getResAttrsAttrName(odsState.name), res_attrs); |
4183 | } |
4184 | if (description) { |
4185 | odsState.addAttribute(getDescriptionAttrName(odsState.name), description); |
4186 | } |
4187 | if (is_stateful) { |
4188 | odsState.addAttribute(getIsStatefulAttrName(odsState.name), is_stateful); |
4189 | } |
4190 | if (gradient) { |
4191 | odsState.addAttribute(getGradientAttrName(odsState.name), gradient); |
4192 | } |
4193 | if (resource_arg_unique_ids_keys) { |
4194 | odsState.addAttribute(getResourceArgUniqueIdsKeysAttrName(odsState.name), resource_arg_unique_ids_keys); |
4195 | } |
4196 | if (resource_arg_unique_ids_values) { |
4197 | odsState.addAttribute(getResourceArgUniqueIdsValuesAttrName(odsState.name), resource_arg_unique_ids_values); |
4198 | } |
4199 | if (control_output) { |
4200 | odsState.addAttribute(getControlOutputAttrName(odsState.name), control_output); |
4201 | } |
4202 | (void)odsState.addRegion(); |
4203 | } |
4204 | |
4205 | void GraphFuncOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, /*optional*/::mlir::UnitAttr generic, ::mlir::StringAttr sym_name, ::mlir::TypeAttr function_type, /*optional*/::mlir::ArrayAttr arg_attrs, /*optional*/::mlir::ArrayAttr res_attrs, /*optional*/::mlir::StringAttr description, /*optional*/::mlir::UnitAttr is_stateful, /*optional*/::mlir::FlatSymbolRefAttr gradient, /*optional*/::mlir::DenseIntElementsAttr resource_arg_unique_ids_keys, /*optional*/::mlir::DenseIntElementsAttr resource_arg_unique_ids_values, /*optional*/::mlir::ArrayAttr control_output) { |
4206 | if (generic) { |
4207 | odsState.addAttribute(getGenericAttrName(odsState.name), generic); |
4208 | } |
4209 | odsState.addAttribute(getSymNameAttrName(odsState.name), sym_name); |
4210 | odsState.addAttribute(getFunctionTypeAttrName(odsState.name), function_type); |
4211 | if (arg_attrs) { |
4212 | odsState.addAttribute(getArgAttrsAttrName(odsState.name), arg_attrs); |
4213 | } |
4214 | if (res_attrs) { |
4215 | odsState.addAttribute(getResAttrsAttrName(odsState.name), res_attrs); |
4216 | } |
4217 | if (description) { |
4218 | odsState.addAttribute(getDescriptionAttrName(odsState.name), description); |
4219 | } |
4220 | if (is_stateful) { |
4221 | odsState.addAttribute(getIsStatefulAttrName(odsState.name), is_stateful); |
4222 | } |
4223 | if (gradient) { |
4224 | odsState.addAttribute(getGradientAttrName(odsState.name), gradient); |
4225 | } |
4226 | if (resource_arg_unique_ids_keys) { |
4227 | odsState.addAttribute(getResourceArgUniqueIdsKeysAttrName(odsState.name), resource_arg_unique_ids_keys); |
4228 | } |
4229 | if (resource_arg_unique_ids_values) { |
4230 | odsState.addAttribute(getResourceArgUniqueIdsValuesAttrName(odsState.name), resource_arg_unique_ids_values); |
4231 | } |
4232 | if (control_output) { |
4233 | odsState.addAttribute(getControlOutputAttrName(odsState.name), control_output); |
4234 | } |
4235 | (void)odsState.addRegion(); |
4236 | assert(resultTypes.size() == 0u && "mismatched number of results" ); |
4237 | odsState.addTypes(resultTypes); |
4238 | } |
4239 | |
4240 | void GraphFuncOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, /*optional*/bool generic, ::llvm::StringRef sym_name, ::mlir::FunctionType function_type, /*optional*/::mlir::ArrayAttr arg_attrs, /*optional*/::mlir::ArrayAttr res_attrs, /*optional*/::mlir::StringAttr description, /*optional*/bool is_stateful, /*optional*/::mlir::FlatSymbolRefAttr gradient, /*optional*/::mlir::DenseIntElementsAttr resource_arg_unique_ids_keys, /*optional*/::mlir::DenseIntElementsAttr resource_arg_unique_ids_values, /*optional*/::mlir::ArrayAttr control_output) { |
4241 | if (generic) { |
4242 | odsState.addAttribute(getGenericAttrName(odsState.name), odsBuilder.getUnitAttr()); |
4243 | } |
4244 | odsState.addAttribute(getSymNameAttrName(odsState.name), odsBuilder.getStringAttr(sym_name)); |
4245 | odsState.addAttribute(getFunctionTypeAttrName(odsState.name), ::mlir::TypeAttr::get(function_type)); |
4246 | if (arg_attrs) { |
4247 | odsState.addAttribute(getArgAttrsAttrName(odsState.name), arg_attrs); |
4248 | } |
4249 | if (res_attrs) { |
4250 | odsState.addAttribute(getResAttrsAttrName(odsState.name), res_attrs); |
4251 | } |
4252 | if (description) { |
4253 | odsState.addAttribute(getDescriptionAttrName(odsState.name), description); |
4254 | } |
4255 | if (is_stateful) { |
4256 | odsState.addAttribute(getIsStatefulAttrName(odsState.name), odsBuilder.getUnitAttr()); |
4257 | } |
4258 | if (gradient) { |
4259 | odsState.addAttribute(getGradientAttrName(odsState.name), gradient); |
4260 | } |
4261 | if (resource_arg_unique_ids_keys) { |
4262 | odsState.addAttribute(getResourceArgUniqueIdsKeysAttrName(odsState.name), resource_arg_unique_ids_keys); |
4263 | } |
4264 | if (resource_arg_unique_ids_values) { |
4265 | odsState.addAttribute(getResourceArgUniqueIdsValuesAttrName(odsState.name), resource_arg_unique_ids_values); |
4266 | } |
4267 | if (control_output) { |
4268 | odsState.addAttribute(getControlOutputAttrName(odsState.name), control_output); |
4269 | } |
4270 | (void)odsState.addRegion(); |
4271 | } |
4272 | |
4273 | void GraphFuncOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, /*optional*/bool generic, ::llvm::StringRef sym_name, ::mlir::FunctionType function_type, /*optional*/::mlir::ArrayAttr arg_attrs, /*optional*/::mlir::ArrayAttr res_attrs, /*optional*/::mlir::StringAttr description, /*optional*/bool is_stateful, /*optional*/::mlir::FlatSymbolRefAttr gradient, /*optional*/::mlir::DenseIntElementsAttr resource_arg_unique_ids_keys, /*optional*/::mlir::DenseIntElementsAttr resource_arg_unique_ids_values, /*optional*/::mlir::ArrayAttr control_output) { |
4274 | if (generic) { |
4275 | odsState.addAttribute(getGenericAttrName(odsState.name), odsBuilder.getUnitAttr()); |
4276 | } |
4277 | odsState.addAttribute(getSymNameAttrName(odsState.name), odsBuilder.getStringAttr(sym_name)); |
4278 | odsState.addAttribute(getFunctionTypeAttrName(odsState.name), ::mlir::TypeAttr::get(function_type)); |
4279 | if (arg_attrs) { |
4280 | odsState.addAttribute(getArgAttrsAttrName(odsState.name), arg_attrs); |
4281 | } |
4282 | if (res_attrs) { |
4283 | odsState.addAttribute(getResAttrsAttrName(odsState.name), res_attrs); |
4284 | } |
4285 | if (description) { |
4286 | odsState.addAttribute(getDescriptionAttrName(odsState.name), description); |
4287 | } |
4288 | if (is_stateful) { |
4289 | odsState.addAttribute(getIsStatefulAttrName(odsState.name), odsBuilder.getUnitAttr()); |
4290 | } |
4291 | if (gradient) { |
4292 | odsState.addAttribute(getGradientAttrName(odsState.name), gradient); |
4293 | } |
4294 | if (resource_arg_unique_ids_keys) { |
4295 | odsState.addAttribute(getResourceArgUniqueIdsKeysAttrName(odsState.name), resource_arg_unique_ids_keys); |
4296 | } |
4297 | if (resource_arg_unique_ids_values) { |
4298 | odsState.addAttribute(getResourceArgUniqueIdsValuesAttrName(odsState.name), resource_arg_unique_ids_values); |
4299 | } |
4300 | if (control_output) { |
4301 | odsState.addAttribute(getControlOutputAttrName(odsState.name), control_output); |
4302 | } |
4303 | (void)odsState.addRegion(); |
4304 | assert(resultTypes.size() == 0u && "mismatched number of results" ); |
4305 | odsState.addTypes(resultTypes); |
4306 | } |
4307 | |
4308 | void GraphFuncOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { |
4309 | assert(operands.size() == 0u && "mismatched number of parameters" ); |
4310 | odsState.addOperands(operands); |
4311 | odsState.addAttributes(attributes); |
4312 | for (unsigned i = 0; i != 1; ++i) |
4313 | (void)odsState.addRegion(); |
4314 | assert(resultTypes.size() == 0u && "mismatched number of return types" ); |
4315 | odsState.addTypes(resultTypes); |
4316 | } |
4317 | |
4318 | ::mlir::LogicalResult GraphFuncOp::verifyInvariantsImpl() { |
4319 | auto namedAttrRange = (*this)->getAttrs(); |
4320 | auto namedAttrIt = namedAttrRange.begin(); |
4321 | ::mlir::Attribute tblgen_function_type; |
4322 | ::mlir::Attribute tblgen_arg_attrs; |
4323 | ::mlir::Attribute tblgen_control_output; |
4324 | ::mlir::Attribute tblgen_description; |
4325 | while (true) { |
4326 | if (namedAttrIt == namedAttrRange.end()) |
4327 | return emitOpError("requires attribute 'function_type'" ); |
4328 | if (namedAttrIt->getName() == getFunctionTypeAttrName()) { |
4329 | tblgen_function_type = namedAttrIt->getValue(); |
4330 | break; |
4331 | } |
4332 | else if (namedAttrIt->getName() == getArgAttrsAttrName()) { |
4333 | tblgen_arg_attrs = namedAttrIt->getValue(); |
4334 | } |
4335 | else if (namedAttrIt->getName() == getControlOutputAttrName()) { |
4336 | tblgen_control_output = namedAttrIt->getValue(); |
4337 | } |
4338 | else if (namedAttrIt->getName() == getDescriptionAttrName()) { |
4339 | tblgen_description = namedAttrIt->getValue(); |
4340 | } |
4341 | ++namedAttrIt; |
4342 | } |
4343 | ::mlir::Attribute tblgen_sym_name; |
4344 | ::mlir::Attribute tblgen_generic; |
4345 | ::mlir::Attribute tblgen_gradient; |
4346 | ::mlir::Attribute tblgen_is_stateful; |
4347 | ::mlir::Attribute tblgen_res_attrs; |
4348 | ::mlir::Attribute tblgen_resource_arg_unique_ids_keys; |
4349 | ::mlir::Attribute tblgen_resource_arg_unique_ids_values; |
4350 | while (true) { |
4351 | if (namedAttrIt == namedAttrRange.end()) |
4352 | return emitOpError("requires attribute 'sym_name'" ); |
4353 | if (namedAttrIt->getName() == getSymNameAttrName()) { |
4354 | tblgen_sym_name = namedAttrIt->getValue(); |
4355 | break; |
4356 | } |
4357 | else if (namedAttrIt->getName() == getGenericAttrName()) { |
4358 | tblgen_generic = namedAttrIt->getValue(); |
4359 | } |
4360 | else if (namedAttrIt->getName() == getGradientAttrName()) { |
4361 | tblgen_gradient = namedAttrIt->getValue(); |
4362 | } |
4363 | else if (namedAttrIt->getName() == getIsStatefulAttrName()) { |
4364 | tblgen_is_stateful = namedAttrIt->getValue(); |
4365 | } |
4366 | else if (namedAttrIt->getName() == getResAttrsAttrName()) { |
4367 | tblgen_res_attrs = namedAttrIt->getValue(); |
4368 | } |
4369 | else if (namedAttrIt->getName() == getResourceArgUniqueIdsKeysAttrName()) { |
4370 | tblgen_resource_arg_unique_ids_keys = namedAttrIt->getValue(); |
4371 | } |
4372 | else if (namedAttrIt->getName() == getResourceArgUniqueIdsValuesAttrName()) { |
4373 | tblgen_resource_arg_unique_ids_values = namedAttrIt->getValue(); |
4374 | } |
4375 | ++namedAttrIt; |
4376 | } |
4377 | |
4378 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops10(*this, tblgen_generic, "generic" ))) |
4379 | return ::mlir::failure(); |
4380 | |
4381 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops8(*this, tblgen_sym_name, "sym_name" ))) |
4382 | return ::mlir::failure(); |
4383 | |
4384 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops11(*this, tblgen_function_type, "function_type" ))) |
4385 | return ::mlir::failure(); |
4386 | |
4387 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops12(*this, tblgen_arg_attrs, "arg_attrs" ))) |
4388 | return ::mlir::failure(); |
4389 | |
4390 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops12(*this, tblgen_res_attrs, "res_attrs" ))) |
4391 | return ::mlir::failure(); |
4392 | |
4393 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops8(*this, tblgen_description, "description" ))) |
4394 | return ::mlir::failure(); |
4395 | |
4396 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops10(*this, tblgen_is_stateful, "is_stateful" ))) |
4397 | return ::mlir::failure(); |
4398 | |
4399 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops13(*this, tblgen_gradient, "gradient" ))) |
4400 | return ::mlir::failure(); |
4401 | |
4402 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops14(*this, tblgen_resource_arg_unique_ids_keys, "resource_arg_unique_ids_keys" ))) |
4403 | return ::mlir::failure(); |
4404 | |
4405 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops14(*this, tblgen_resource_arg_unique_ids_values, "resource_arg_unique_ids_values" ))) |
4406 | return ::mlir::failure(); |
4407 | |
4408 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops15(*this, tblgen_control_output, "control_output" ))) |
4409 | return ::mlir::failure(); |
4410 | { |
4411 | unsigned index = 0; (void)index; |
4412 | |
4413 | for (auto ®ion : ::llvm::makeMutableArrayRef((*this)->getRegion(0))) |
4414 | if (::mlir::failed(__mlir_ods_local_region_constraint_ops1(*this, region, "body" , index++))) |
4415 | return ::mlir::failure(); |
4416 | } |
4417 | return ::mlir::success(); |
4418 | } |
4419 | |
4420 | ::mlir::LogicalResult GraphFuncOp::verifyInvariants() { |
4421 | if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) |
4422 | return ::mlir::success(); |
4423 | return ::mlir::failure(); |
4424 | } |
4425 | |
4426 | void GraphFuncOp::getCanonicalizationPatterns(::mlir::RewritePatternSet &results, ::mlir::MLIRContext *context) { |
4427 | results.add(canonicalize); |
4428 | } |
4429 | |
4430 | } // namespace tfg |
4431 | } // namespace mlir |
4432 | MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::tfg::GraphFuncOp) |
4433 | |
4434 | namespace mlir { |
4435 | namespace tfg { |
4436 | |
4437 | //===----------------------------------------------------------------------===// |
4438 | // ::mlir::tfg::GraphOp definitions |
4439 | //===----------------------------------------------------------------------===// |
4440 | |
4441 | GraphOpAdaptor::GraphOpAdaptor(::mlir::ValueRange values, ::mlir::DictionaryAttr attrs, ::mlir::RegionRange regions) : odsOperands(values), odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) |
4442 | odsOpName.emplace("tfg.graph" , odsAttrs.getContext()); |
4443 | } |
4444 | |
4445 | GraphOpAdaptor::GraphOpAdaptor(GraphOp op) : odsOperands(op->getOperands()), odsAttrs(op->getAttrDictionary()), odsRegions(op->getRegions()), odsOpName(op->getName()) {} |
4446 | |
4447 | ::mlir::ValueRange GraphOpAdaptor::getOperands() { |
4448 | return odsOperands; |
4449 | } |
4450 | |
4451 | std::pair<unsigned, unsigned> GraphOpAdaptor::getODSOperandIndexAndLength(unsigned index) { |
4452 | return {index, 1}; |
4453 | } |
4454 | |
4455 | ::mlir::ValueRange GraphOpAdaptor::getODSOperands(unsigned index) { |
4456 | auto valueRange = getODSOperandIndexAndLength(index); |
4457 | return {std::next(odsOperands.begin(), valueRange.first), |
4458 | std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; |
4459 | } |
4460 | |
4461 | ::mlir::DictionaryAttr GraphOpAdaptor::getAttributes() { |
4462 | return odsAttrs; |
4463 | } |
4464 | |
4465 | ::mlir::tf_type::VersionAttr GraphOpAdaptor::getVersionAttr() { |
4466 | assert(odsAttrs && "no attributes when constructing adapter" ); |
4467 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, GraphOp::getVersionAttrName(*odsOpName)).cast<::mlir::tf_type::VersionAttr>(); |
4468 | return attr; |
4469 | } |
4470 | |
4471 | ::mlir::tf_type::VersionAttr GraphOpAdaptor::getVersion() { |
4472 | auto attr = getVersionAttr(); |
4473 | return attr.cast<::mlir::tf_type::VersionAttr>(); |
4474 | } |
4475 | |
4476 | ::mlir::tf_type::VersionAttr GraphOpAdaptor::versionAttr() { |
4477 | assert(odsAttrs && "no attributes when constructing adapter" ); |
4478 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, GraphOp::getVersionAttrName(*odsOpName)).cast<::mlir::tf_type::VersionAttr>(); |
4479 | return attr; |
4480 | } |
4481 | |
4482 | ::mlir::tf_type::VersionAttr GraphOpAdaptor::version() { |
4483 | auto attr = versionAttr(); |
4484 | return attr.cast<::mlir::tf_type::VersionAttr>(); |
4485 | } |
4486 | |
4487 | ::mlir::RegionRange GraphOpAdaptor::getRegions() { |
4488 | return odsRegions; |
4489 | } |
4490 | |
4491 | ::mlir::Region &GraphOpAdaptor::getNodes() { |
4492 | return *odsRegions[0]; |
4493 | } |
4494 | |
4495 | ::mlir::Region &GraphOpAdaptor::nodes() { |
4496 | return *odsRegions[0]; |
4497 | } |
4498 | |
4499 | ::mlir::LogicalResult GraphOpAdaptor::verify(::mlir::Location loc) { |
4500 | auto namedAttrRange = odsAttrs; |
4501 | auto namedAttrIt = namedAttrRange.begin(); |
4502 | ::mlir::Attribute tblgen_version; |
4503 | while (true) { |
4504 | if (namedAttrIt == namedAttrRange.end()) |
4505 | return emitError(loc, "'tfg.graph' op " "requires attribute 'version'" ); |
4506 | if (namedAttrIt->getName() == GraphOp::getVersionAttrName(*odsOpName)) { |
4507 | tblgen_version = namedAttrIt->getValue(); |
4508 | break; |
4509 | } |
4510 | ++namedAttrIt; |
4511 | } |
4512 | |
4513 | if (tblgen_version && !((tblgen_version.isa<::mlir::tf_type::VersionAttr>()))) |
4514 | return emitError(loc, "'tfg.graph' op " "attribute 'version' failed to satisfy constraint: An Attribute describing the version for a TensorFlow Graph" ); |
4515 | return ::mlir::success(); |
4516 | } |
4517 | |
4518 | std::pair<unsigned, unsigned> GraphOp::getODSOperandIndexAndLength(unsigned index) { |
4519 | return {index, 1}; |
4520 | } |
4521 | |
4522 | ::mlir::Operation::operand_range GraphOp::getODSOperands(unsigned index) { |
4523 | auto valueRange = getODSOperandIndexAndLength(index); |
4524 | return {std::next(getOperation()->operand_begin(), valueRange.first), |
4525 | std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; |
4526 | } |
4527 | |
4528 | std::pair<unsigned, unsigned> GraphOp::getODSResultIndexAndLength(unsigned index) { |
4529 | return {index, 1}; |
4530 | } |
4531 | |
4532 | ::mlir::Operation::result_range GraphOp::getODSResults(unsigned index) { |
4533 | auto valueRange = getODSResultIndexAndLength(index); |
4534 | return {std::next(getOperation()->result_begin(), valueRange.first), |
4535 | std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; |
4536 | } |
4537 | |
4538 | ::mlir::Region &GraphOp::getNodes() { |
4539 | return (*this)->getRegion(0); |
4540 | } |
4541 | |
4542 | ::mlir::Region &GraphOp::nodes() { |
4543 | return (*this)->getRegion(0); |
4544 | } |
4545 | |
4546 | ::mlir::tf_type::VersionAttr GraphOp::getVersionAttr() { |
4547 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getVersionAttrName()).cast<::mlir::tf_type::VersionAttr>(); |
4548 | } |
4549 | |
4550 | ::mlir::tf_type::VersionAttr GraphOp::getVersion() { |
4551 | auto attr = getVersionAttr(); |
4552 | return attr.cast<::mlir::tf_type::VersionAttr>(); |
4553 | } |
4554 | |
4555 | ::mlir::tf_type::VersionAttr GraphOp::versionAttr() { |
4556 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getVersionAttrName()).cast<::mlir::tf_type::VersionAttr>(); |
4557 | } |
4558 | |
4559 | ::mlir::tf_type::VersionAttr GraphOp::version() { |
4560 | auto attr = versionAttr(); |
4561 | return attr.cast<::mlir::tf_type::VersionAttr>(); |
4562 | } |
4563 | |
4564 | void GraphOp::setVersionAttr(::mlir::tf_type::VersionAttr attr) { |
4565 | (*this)->setAttr(getVersionAttrName(), attr); |
4566 | } |
4567 | |
4568 | void GraphOp::versionAttr(::mlir::tf_type::VersionAttr attr) { |
4569 | (*this)->setAttr(versionAttrName(), attr); |
4570 | } |
4571 | |
4572 | void GraphOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::tf_type::VersionAttr version) { |
4573 | odsState.addAttribute(getVersionAttrName(odsState.name), version); |
4574 | (void)odsState.addRegion(); |
4575 | } |
4576 | |
4577 | void GraphOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::tf_type::VersionAttr version) { |
4578 | odsState.addAttribute(getVersionAttrName(odsState.name), version); |
4579 | (void)odsState.addRegion(); |
4580 | assert(resultTypes.size() == 0u && "mismatched number of results" ); |
4581 | odsState.addTypes(resultTypes); |
4582 | } |
4583 | |
4584 | void GraphOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { |
4585 | assert(operands.size() == 0u && "mismatched number of parameters" ); |
4586 | odsState.addOperands(operands); |
4587 | odsState.addAttributes(attributes); |
4588 | for (unsigned i = 0; i != 1; ++i) |
4589 | (void)odsState.addRegion(); |
4590 | assert(resultTypes.size() == 0u && "mismatched number of return types" ); |
4591 | odsState.addTypes(resultTypes); |
4592 | } |
4593 | |
4594 | ::mlir::LogicalResult GraphOp::verifyInvariantsImpl() { |
4595 | auto namedAttrRange = (*this)->getAttrs(); |
4596 | auto namedAttrIt = namedAttrRange.begin(); |
4597 | ::mlir::Attribute tblgen_version; |
4598 | while (true) { |
4599 | if (namedAttrIt == namedAttrRange.end()) |
4600 | return emitOpError("requires attribute 'version'" ); |
4601 | if (namedAttrIt->getName() == getVersionAttrName()) { |
4602 | tblgen_version = namedAttrIt->getValue(); |
4603 | break; |
4604 | } |
4605 | ++namedAttrIt; |
4606 | } |
4607 | |
4608 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops16(*this, tblgen_version, "version" ))) |
4609 | return ::mlir::failure(); |
4610 | { |
4611 | unsigned index = 0; (void)index; |
4612 | |
4613 | for (auto ®ion : ::llvm::makeMutableArrayRef((*this)->getRegion(0))) |
4614 | if (::mlir::failed(__mlir_ods_local_region_constraint_ops0(*this, region, "nodes" , index++))) |
4615 | return ::mlir::failure(); |
4616 | } |
4617 | return ::mlir::success(); |
4618 | } |
4619 | |
4620 | ::mlir::LogicalResult GraphOp::verifyInvariants() { |
4621 | if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) |
4622 | return ::mlir::success(); |
4623 | return ::mlir::failure(); |
4624 | } |
4625 | |
4626 | ::mlir::ParseResult GraphOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { |
4627 | ::mlir::tf_type::VersionAttr versionAttr; |
4628 | std::unique_ptr<::mlir::Region> nodesRegion = std::make_unique<::mlir::Region>(); |
4629 | |
4630 | if (parser.parseAttribute(versionAttr, ::mlir::Type{}, "version" , result.attributes)) |
4631 | return ::mlir::failure(); |
4632 | if (parser.parseOptionalAttrDictWithKeyword(result.attributes)) |
4633 | return ::mlir::failure(); |
4634 | |
4635 | if (parser.parseRegion(*nodesRegion)) |
4636 | return ::mlir::failure(); |
4637 | |
4638 | if (nodesRegion->empty()) nodesRegion->emplaceBlock(); |
4639 | result.addRegion(std::move(nodesRegion)); |
4640 | return ::mlir::success(); |
4641 | } |
4642 | |
4643 | void GraphOp::print(::mlir::OpAsmPrinter &_odsPrinter) { |
4644 | _odsPrinter << ' '; |
4645 | _odsPrinter.printAttribute(getVersionAttr()); |
4646 | _odsPrinter.printOptionalAttrDictWithKeyword((*this)->getAttrs(), /*elidedAttrs=*/{"version" }); |
4647 | _odsPrinter << ' '; |
4648 | _odsPrinter.printRegion(getNodes()); |
4649 | } |
4650 | |
4651 | } // namespace tfg |
4652 | } // namespace mlir |
4653 | MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::tfg::GraphOp) |
4654 | |
4655 | namespace mlir { |
4656 | namespace tfg { |
4657 | |
4658 | //===----------------------------------------------------------------------===// |
4659 | // ::mlir::tfg::IfOp definitions |
4660 | //===----------------------------------------------------------------------===// |
4661 | |
4662 | IfOpAdaptor::IfOpAdaptor(::mlir::ValueRange values, ::mlir::DictionaryAttr attrs, ::mlir::RegionRange regions) : odsOperands(values), odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) |
4663 | odsOpName.emplace("tfg.If" , odsAttrs.getContext()); |
4664 | } |
4665 | |
4666 | IfOpAdaptor::IfOpAdaptor(IfOp op) : odsOperands(op->getOperands()), odsAttrs(op->getAttrDictionary()), odsRegions(op->getRegions()), odsOpName(op->getName()) {} |
4667 | |
4668 | ::mlir::ValueRange IfOpAdaptor::getOperands() { |
4669 | return odsOperands; |
4670 | } |
4671 | |
4672 | std::pair<unsigned, unsigned> IfOpAdaptor::getODSOperandIndexAndLength(unsigned index) { |
4673 | bool isVariadic[] = {false, true}; |
4674 | int prevVariadicCount = 0; |
4675 | for (unsigned i = 0; i < index; ++i) |
4676 | if (isVariadic[i]) ++prevVariadicCount; |
4677 | |
4678 | // Calculate how many dynamic values a static variadic operand corresponds to. |
4679 | // This assumes all static variadic operands have the same dynamic value count. |
4680 | int variadicSize = (odsOperands.size() - 1) / 1; |
4681 | // `index` passed in as the parameter is the static index which counts each |
4682 | // operand (variadic or not) as size 1. So here for each previous static variadic |
4683 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
4684 | // value pack for this static operand starts. |
4685 | int start = index + (variadicSize - 1) * prevVariadicCount; |
4686 | int size = isVariadic[index] ? variadicSize : 1; |
4687 | return {start, size}; |
4688 | } |
4689 | |
4690 | ::mlir::ValueRange IfOpAdaptor::getODSOperands(unsigned index) { |
4691 | auto valueRange = getODSOperandIndexAndLength(index); |
4692 | return {std::next(odsOperands.begin(), valueRange.first), |
4693 | std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; |
4694 | } |
4695 | |
4696 | ::mlir::Value IfOpAdaptor::getCond() { |
4697 | return *getODSOperands(0).begin(); |
4698 | } |
4699 | |
4700 | ::mlir::Value IfOpAdaptor::cond() { |
4701 | return *getODSOperands(0).begin(); |
4702 | } |
4703 | |
4704 | ::mlir::ValueRange IfOpAdaptor::getArgs() { |
4705 | return getODSOperands(1); |
4706 | } |
4707 | |
4708 | ::mlir::ValueRange IfOpAdaptor::args() { |
4709 | return getODSOperands(1); |
4710 | } |
4711 | |
4712 | ::mlir::DictionaryAttr IfOpAdaptor::getAttributes() { |
4713 | return odsAttrs; |
4714 | } |
4715 | |
4716 | ::mlir::tf_type::FuncAttr IfOpAdaptor::getThenBranchAttr() { |
4717 | assert(odsAttrs && "no attributes when constructing adapter" ); |
4718 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 0, IfOp::getThenBranchAttrName(*odsOpName)).cast<::mlir::tf_type::FuncAttr>(); |
4719 | return attr; |
4720 | } |
4721 | |
4722 | ::mlir::tf_type::FuncAttr IfOpAdaptor::getThenBranch() { |
4723 | auto attr = getThenBranchAttr(); |
4724 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
4725 | } |
4726 | |
4727 | ::mlir::tf_type::FuncAttr IfOpAdaptor::then_branchAttr() { |
4728 | assert(odsAttrs && "no attributes when constructing adapter" ); |
4729 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 0, IfOp::getThenBranchAttrName(*odsOpName)).cast<::mlir::tf_type::FuncAttr>(); |
4730 | return attr; |
4731 | } |
4732 | |
4733 | ::mlir::tf_type::FuncAttr IfOpAdaptor::then_branch() { |
4734 | auto attr = then_branchAttr(); |
4735 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
4736 | } |
4737 | |
4738 | ::mlir::tf_type::FuncAttr IfOpAdaptor::getElseBranchAttr() { |
4739 | assert(odsAttrs && "no attributes when constructing adapter" ); |
4740 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 1, IfOp::getElseBranchAttrName(*odsOpName)).cast<::mlir::tf_type::FuncAttr>(); |
4741 | return attr; |
4742 | } |
4743 | |
4744 | ::mlir::tf_type::FuncAttr IfOpAdaptor::getElseBranch() { |
4745 | auto attr = getElseBranchAttr(); |
4746 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
4747 | } |
4748 | |
4749 | ::mlir::tf_type::FuncAttr IfOpAdaptor::else_branchAttr() { |
4750 | assert(odsAttrs && "no attributes when constructing adapter" ); |
4751 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 1, IfOp::getElseBranchAttrName(*odsOpName)).cast<::mlir::tf_type::FuncAttr>(); |
4752 | return attr; |
4753 | } |
4754 | |
4755 | ::mlir::tf_type::FuncAttr IfOpAdaptor::else_branch() { |
4756 | auto attr = else_branchAttr(); |
4757 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
4758 | } |
4759 | |
4760 | ::mlir::TypeAttr IfOpAdaptor::getTcondAttr() { |
4761 | assert(odsAttrs && "no attributes when constructing adapter" ); |
4762 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, IfOp::getTcondAttrName(*odsOpName)).dyn_cast_or_null<::mlir::TypeAttr>(); |
4763 | return attr; |
4764 | } |
4765 | |
4766 | ::llvm::Optional<::mlir::Type> IfOpAdaptor::getTcond() { |
4767 | auto attr = getTcondAttr(); |
4768 | return attr ? ::llvm::Optional<::mlir::Type>(attr.getValue().cast<::mlir::Type>()) : (::llvm::None); |
4769 | } |
4770 | |
4771 | ::mlir::TypeAttr IfOpAdaptor::TcondAttr() { |
4772 | assert(odsAttrs && "no attributes when constructing adapter" ); |
4773 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, IfOp::getTcondAttrName(*odsOpName)).dyn_cast_or_null<::mlir::TypeAttr>(); |
4774 | return attr; |
4775 | } |
4776 | |
4777 | ::llvm::Optional<::mlir::Type> IfOpAdaptor::Tcond() { |
4778 | auto attr = TcondAttr(); |
4779 | return attr ? ::llvm::Optional<::mlir::Type>(attr.getValue().cast<::mlir::Type>()) : (::llvm::None); |
4780 | } |
4781 | |
4782 | ::mlir::ArrayAttr IfOpAdaptor::getTinAttr() { |
4783 | assert(odsAttrs && "no attributes when constructing adapter" ); |
4784 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, IfOp::getTinAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
4785 | return attr; |
4786 | } |
4787 | |
4788 | ::llvm::Optional< ::mlir::ArrayAttr > IfOpAdaptor::getTin() { |
4789 | auto attr = getTinAttr(); |
4790 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
4791 | } |
4792 | |
4793 | ::mlir::ArrayAttr IfOpAdaptor::TinAttr() { |
4794 | assert(odsAttrs && "no attributes when constructing adapter" ); |
4795 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, IfOp::getTinAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
4796 | return attr; |
4797 | } |
4798 | |
4799 | ::llvm::Optional< ::mlir::ArrayAttr > IfOpAdaptor::Tin() { |
4800 | auto attr = TinAttr(); |
4801 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
4802 | } |
4803 | |
4804 | ::mlir::ArrayAttr IfOpAdaptor::getToutAttr() { |
4805 | assert(odsAttrs && "no attributes when constructing adapter" ); |
4806 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, IfOp::getToutAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
4807 | return attr; |
4808 | } |
4809 | |
4810 | ::llvm::Optional< ::mlir::ArrayAttr > IfOpAdaptor::getTout() { |
4811 | auto attr = getToutAttr(); |
4812 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
4813 | } |
4814 | |
4815 | ::mlir::ArrayAttr IfOpAdaptor::ToutAttr() { |
4816 | assert(odsAttrs && "no attributes when constructing adapter" ); |
4817 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, IfOp::getToutAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
4818 | return attr; |
4819 | } |
4820 | |
4821 | ::llvm::Optional< ::mlir::ArrayAttr > IfOpAdaptor::Tout() { |
4822 | auto attr = ToutAttr(); |
4823 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
4824 | } |
4825 | |
4826 | ::mlir::ArrayAttr IfOpAdaptor::getOutputShapesAttr() { |
4827 | assert(odsAttrs && "no attributes when constructing adapter" ); |
4828 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 1, IfOp::getOutputShapesAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
4829 | return attr; |
4830 | } |
4831 | |
4832 | ::llvm::Optional< ::mlir::ArrayAttr > IfOpAdaptor::getOutputShapes() { |
4833 | auto attr = getOutputShapesAttr(); |
4834 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
4835 | } |
4836 | |
4837 | ::mlir::ArrayAttr IfOpAdaptor::output_shapesAttr() { |
4838 | assert(odsAttrs && "no attributes when constructing adapter" ); |
4839 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 1, IfOp::getOutputShapesAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
4840 | return attr; |
4841 | } |
4842 | |
4843 | ::llvm::Optional< ::mlir::ArrayAttr > IfOpAdaptor::output_shapes() { |
4844 | auto attr = output_shapesAttr(); |
4845 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
4846 | } |
4847 | |
4848 | ::mlir::LogicalResult IfOpAdaptor::verify(::mlir::Location loc) { |
4849 | auto namedAttrRange = odsAttrs; |
4850 | auto namedAttrIt = namedAttrRange.begin(); |
4851 | ::mlir::Attribute tblgen_else_branch; |
4852 | ::mlir::Attribute tblgen_Tcond; |
4853 | ::mlir::Attribute tblgen_Tin; |
4854 | ::mlir::Attribute tblgen_Tout; |
4855 | while (true) { |
4856 | if (namedAttrIt == namedAttrRange.end()) |
4857 | return emitError(loc, "'tfg.If' op " "requires attribute 'else_branch'" ); |
4858 | if (namedAttrIt->getName() == IfOp::getElseBranchAttrName(*odsOpName)) { |
4859 | tblgen_else_branch = namedAttrIt->getValue(); |
4860 | break; |
4861 | } |
4862 | else if (namedAttrIt->getName() == IfOp::getTcondAttrName(*odsOpName)) { |
4863 | tblgen_Tcond = namedAttrIt->getValue(); |
4864 | } |
4865 | else if (namedAttrIt->getName() == IfOp::getTinAttrName(*odsOpName)) { |
4866 | tblgen_Tin = namedAttrIt->getValue(); |
4867 | } |
4868 | else if (namedAttrIt->getName() == IfOp::getToutAttrName(*odsOpName)) { |
4869 | tblgen_Tout = namedAttrIt->getValue(); |
4870 | } |
4871 | ++namedAttrIt; |
4872 | } |
4873 | ::mlir::Attribute tblgen_then_branch; |
4874 | ::mlir::Attribute tblgen_output_shapes; |
4875 | while (true) { |
4876 | if (namedAttrIt == namedAttrRange.end()) |
4877 | return emitError(loc, "'tfg.If' op " "requires attribute 'then_branch'" ); |
4878 | if (namedAttrIt->getName() == IfOp::getThenBranchAttrName(*odsOpName)) { |
4879 | tblgen_then_branch = namedAttrIt->getValue(); |
4880 | break; |
4881 | } |
4882 | else if (namedAttrIt->getName() == IfOp::getOutputShapesAttrName(*odsOpName)) { |
4883 | tblgen_output_shapes = namedAttrIt->getValue(); |
4884 | } |
4885 | ++namedAttrIt; |
4886 | } |
4887 | |
4888 | if (tblgen_then_branch && !((tblgen_then_branch.isa<::mlir::tf_type::FuncAttr>()))) |
4889 | return emitError(loc, "'tfg.If' op " "attribute 'then_branch' failed to satisfy constraint: Models the `AttrValue.value.func` proto attribute value as a pair of SymbolRef and DictionaryAttr" ); |
4890 | |
4891 | if (tblgen_else_branch && !((tblgen_else_branch.isa<::mlir::tf_type::FuncAttr>()))) |
4892 | return emitError(loc, "'tfg.If' op " "attribute 'else_branch' failed to satisfy constraint: Models the `AttrValue.value.func` proto attribute value as a pair of SymbolRef and DictionaryAttr" ); |
4893 | |
4894 | if (tblgen_Tcond && !(((tblgen_Tcond.isa<::mlir::TypeAttr>())) && ((tblgen_Tcond.cast<::mlir::TypeAttr>().getValue().isa<::mlir::Type>())))) |
4895 | return emitError(loc, "'tfg.If' op " "attribute 'Tcond' failed to satisfy constraint: any type attribute" ); |
4896 | |
4897 | if (tblgen_Tin && !(((tblgen_Tin.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_Tin.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && (((attr.isa<::mlir::TypeAttr>())) && ((attr.cast<::mlir::TypeAttr>().getValue().isa<::mlir::Type>()))); })))) |
4898 | return emitError(loc, "'tfg.If' op " "attribute 'Tin' failed to satisfy constraint: type array attribute" ); |
4899 | |
4900 | if (tblgen_Tout && !(((tblgen_Tout.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_Tout.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && (((attr.isa<::mlir::TypeAttr>())) && ((attr.cast<::mlir::TypeAttr>().getValue().isa<::mlir::Type>()))); })))) |
4901 | return emitError(loc, "'tfg.If' op " "attribute 'Tout' failed to satisfy constraint: type array attribute" ); |
4902 | |
4903 | if (tblgen_output_shapes && !(((tblgen_output_shapes.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_output_shapes.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && ((attr.isa<::mlir::tf_type::ShapeAttr>())); })))) |
4904 | return emitError(loc, "'tfg.If' op " "attribute 'output_shapes' failed to satisfy constraint: An array of shapes." ); |
4905 | return ::mlir::success(); |
4906 | } |
4907 | |
4908 | void IfOp::getAsmResultNames(::mlir::OpAsmSetValueNameFn setNameFn) { |
4909 | auto resultGroup0 = getODSResults(0); |
4910 | if (!resultGroup0.empty()) |
4911 | setNameFn(*resultGroup0.begin(), "outs" ); |
4912 | auto resultGroup1 = getODSResults(1); |
4913 | if (!resultGroup1.empty()) |
4914 | setNameFn(*resultGroup1.begin(), "ctl" ); |
4915 | } |
4916 | |
4917 | std::pair<unsigned, unsigned> IfOp::getODSOperandIndexAndLength(unsigned index) { |
4918 | bool isVariadic[] = {false, true}; |
4919 | int prevVariadicCount = 0; |
4920 | for (unsigned i = 0; i < index; ++i) |
4921 | if (isVariadic[i]) ++prevVariadicCount; |
4922 | |
4923 | // Calculate how many dynamic values a static variadic operand corresponds to. |
4924 | // This assumes all static variadic operands have the same dynamic value count. |
4925 | int variadicSize = (getOperation()->getNumOperands() - 1) / 1; |
4926 | // `index` passed in as the parameter is the static index which counts each |
4927 | // operand (variadic or not) as size 1. So here for each previous static variadic |
4928 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
4929 | // value pack for this static operand starts. |
4930 | int start = index + (variadicSize - 1) * prevVariadicCount; |
4931 | int size = isVariadic[index] ? variadicSize : 1; |
4932 | return {start, size}; |
4933 | } |
4934 | |
4935 | ::mlir::Operation::operand_range IfOp::getODSOperands(unsigned index) { |
4936 | auto valueRange = getODSOperandIndexAndLength(index); |
4937 | return {std::next(getOperation()->operand_begin(), valueRange.first), |
4938 | std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; |
4939 | } |
4940 | |
4941 | ::mlir::Value IfOp::getCond() { |
4942 | return *getODSOperands(0).begin(); |
4943 | } |
4944 | |
4945 | ::mlir::Value IfOp::cond() { |
4946 | return *getODSOperands(0).begin(); |
4947 | } |
4948 | |
4949 | ::mlir::Operation::operand_range IfOp::getArgs() { |
4950 | return getODSOperands(1); |
4951 | } |
4952 | |
4953 | ::mlir::Operation::operand_range IfOp::args() { |
4954 | return getODSOperands(1); |
4955 | } |
4956 | |
4957 | ::mlir::MutableOperandRange IfOp::getCondMutable() { |
4958 | auto range = getODSOperandIndexAndLength(0); |
4959 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
4960 | return mutableRange; |
4961 | } |
4962 | |
4963 | ::mlir::MutableOperandRange IfOp::condMutable() { |
4964 | auto range = getODSOperandIndexAndLength(0); |
4965 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
4966 | return mutableRange; |
4967 | } |
4968 | |
4969 | ::mlir::MutableOperandRange IfOp::getArgsMutable() { |
4970 | auto range = getODSOperandIndexAndLength(1); |
4971 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
4972 | return mutableRange; |
4973 | } |
4974 | |
4975 | ::mlir::MutableOperandRange IfOp::argsMutable() { |
4976 | auto range = getODSOperandIndexAndLength(1); |
4977 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
4978 | return mutableRange; |
4979 | } |
4980 | |
4981 | std::pair<unsigned, unsigned> IfOp::getODSResultIndexAndLength(unsigned index) { |
4982 | bool isVariadic[] = {true, false}; |
4983 | int prevVariadicCount = 0; |
4984 | for (unsigned i = 0; i < index; ++i) |
4985 | if (isVariadic[i]) ++prevVariadicCount; |
4986 | |
4987 | // Calculate how many dynamic values a static variadic operand corresponds to. |
4988 | // This assumes all static variadic operands have the same dynamic value count. |
4989 | int variadicSize = (getOperation()->getNumResults() - 1) / 1; |
4990 | // `index` passed in as the parameter is the static index which counts each |
4991 | // operand (variadic or not) as size 1. So here for each previous static variadic |
4992 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
4993 | // value pack for this static operand starts. |
4994 | int start = index + (variadicSize - 1) * prevVariadicCount; |
4995 | int size = isVariadic[index] ? variadicSize : 1; |
4996 | return {start, size}; |
4997 | } |
4998 | |
4999 | ::mlir::Operation::result_range IfOp::getODSResults(unsigned index) { |
5000 | auto valueRange = getODSResultIndexAndLength(index); |
5001 | return {std::next(getOperation()->result_begin(), valueRange.first), |
5002 | std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; |
5003 | } |
5004 | |
5005 | ::mlir::Operation::result_range IfOp::getOuts() { |
5006 | return getODSResults(0); |
5007 | } |
5008 | |
5009 | ::mlir::Operation::result_range IfOp::outs() { |
5010 | return getODSResults(0); |
5011 | } |
5012 | |
5013 | ::mlir::TypedValue<::mlir::tf_type::ControlType> IfOp::getCtl() { |
5014 | return *getODSResults(1).begin(); |
5015 | } |
5016 | |
5017 | ::mlir::TypedValue<::mlir::tf_type::ControlType> IfOp::ctl() { |
5018 | return *getODSResults(1).begin(); |
5019 | } |
5020 | |
5021 | ::mlir::tf_type::FuncAttr IfOp::getThenBranchAttr() { |
5022 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getThenBranchAttrName()).cast<::mlir::tf_type::FuncAttr>(); |
5023 | } |
5024 | |
5025 | ::mlir::tf_type::FuncAttr IfOp::getThenBranch() { |
5026 | auto attr = getThenBranchAttr(); |
5027 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
5028 | } |
5029 | |
5030 | ::mlir::tf_type::FuncAttr IfOp::then_branchAttr() { |
5031 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getThenBranchAttrName()).cast<::mlir::tf_type::FuncAttr>(); |
5032 | } |
5033 | |
5034 | ::mlir::tf_type::FuncAttr IfOp::then_branch() { |
5035 | auto attr = then_branchAttr(); |
5036 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
5037 | } |
5038 | |
5039 | ::mlir::tf_type::FuncAttr IfOp::getElseBranchAttr() { |
5040 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getElseBranchAttrName()).cast<::mlir::tf_type::FuncAttr>(); |
5041 | } |
5042 | |
5043 | ::mlir::tf_type::FuncAttr IfOp::getElseBranch() { |
5044 | auto attr = getElseBranchAttr(); |
5045 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
5046 | } |
5047 | |
5048 | ::mlir::tf_type::FuncAttr IfOp::else_branchAttr() { |
5049 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getElseBranchAttrName()).cast<::mlir::tf_type::FuncAttr>(); |
5050 | } |
5051 | |
5052 | ::mlir::tf_type::FuncAttr IfOp::else_branch() { |
5053 | auto attr = else_branchAttr(); |
5054 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
5055 | } |
5056 | |
5057 | ::mlir::TypeAttr IfOp::getTcondAttr() { |
5058 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getTcondAttrName()).dyn_cast_or_null<::mlir::TypeAttr>(); |
5059 | } |
5060 | |
5061 | ::llvm::Optional<::mlir::Type> IfOp::getTcond() { |
5062 | auto attr = getTcondAttr(); |
5063 | return attr ? ::llvm::Optional<::mlir::Type>(attr.getValue().cast<::mlir::Type>()) : (::llvm::None); |
5064 | } |
5065 | |
5066 | ::mlir::TypeAttr IfOp::TcondAttr() { |
5067 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getTcondAttrName()).dyn_cast_or_null<::mlir::TypeAttr>(); |
5068 | } |
5069 | |
5070 | ::llvm::Optional<::mlir::Type> IfOp::Tcond() { |
5071 | auto attr = TcondAttr(); |
5072 | return attr ? ::llvm::Optional<::mlir::Type>(attr.getValue().cast<::mlir::Type>()) : (::llvm::None); |
5073 | } |
5074 | |
5075 | ::mlir::ArrayAttr IfOp::getTinAttr() { |
5076 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getTinAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
5077 | } |
5078 | |
5079 | ::llvm::Optional< ::mlir::ArrayAttr > IfOp::getTin() { |
5080 | auto attr = getTinAttr(); |
5081 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
5082 | } |
5083 | |
5084 | ::mlir::ArrayAttr IfOp::TinAttr() { |
5085 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getTinAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
5086 | } |
5087 | |
5088 | ::llvm::Optional< ::mlir::ArrayAttr > IfOp::Tin() { |
5089 | auto attr = TinAttr(); |
5090 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
5091 | } |
5092 | |
5093 | ::mlir::ArrayAttr IfOp::getToutAttr() { |
5094 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getToutAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
5095 | } |
5096 | |
5097 | ::llvm::Optional< ::mlir::ArrayAttr > IfOp::getTout() { |
5098 | auto attr = getToutAttr(); |
5099 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
5100 | } |
5101 | |
5102 | ::mlir::ArrayAttr IfOp::ToutAttr() { |
5103 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getToutAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
5104 | } |
5105 | |
5106 | ::llvm::Optional< ::mlir::ArrayAttr > IfOp::Tout() { |
5107 | auto attr = ToutAttr(); |
5108 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
5109 | } |
5110 | |
5111 | ::mlir::ArrayAttr IfOp::getOutputShapesAttr() { |
5112 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 1, getOutputShapesAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
5113 | } |
5114 | |
5115 | ::llvm::Optional< ::mlir::ArrayAttr > IfOp::getOutputShapes() { |
5116 | auto attr = getOutputShapesAttr(); |
5117 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
5118 | } |
5119 | |
5120 | ::mlir::ArrayAttr IfOp::output_shapesAttr() { |
5121 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 1, getOutputShapesAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
5122 | } |
5123 | |
5124 | ::llvm::Optional< ::mlir::ArrayAttr > IfOp::output_shapes() { |
5125 | auto attr = output_shapesAttr(); |
5126 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
5127 | } |
5128 | |
5129 | void IfOp::setThenBranchAttr(::mlir::tf_type::FuncAttr attr) { |
5130 | (*this)->setAttr(getThenBranchAttrName(), attr); |
5131 | } |
5132 | |
5133 | void IfOp::then_branchAttr(::mlir::tf_type::FuncAttr attr) { |
5134 | (*this)->setAttr(then_branchAttrName(), attr); |
5135 | } |
5136 | |
5137 | void IfOp::setElseBranchAttr(::mlir::tf_type::FuncAttr attr) { |
5138 | (*this)->setAttr(getElseBranchAttrName(), attr); |
5139 | } |
5140 | |
5141 | void IfOp::else_branchAttr(::mlir::tf_type::FuncAttr attr) { |
5142 | (*this)->setAttr(else_branchAttrName(), attr); |
5143 | } |
5144 | |
5145 | void IfOp::setTcondAttr(::mlir::TypeAttr attr) { |
5146 | (*this)->setAttr(getTcondAttrName(), attr); |
5147 | } |
5148 | |
5149 | void IfOp::TcondAttr(::mlir::TypeAttr attr) { |
5150 | (*this)->setAttr(TcondAttrName(), attr); |
5151 | } |
5152 | |
5153 | void IfOp::setTinAttr(::mlir::ArrayAttr attr) { |
5154 | (*this)->setAttr(getTinAttrName(), attr); |
5155 | } |
5156 | |
5157 | void IfOp::TinAttr(::mlir::ArrayAttr attr) { |
5158 | (*this)->setAttr(TinAttrName(), attr); |
5159 | } |
5160 | |
5161 | void IfOp::setToutAttr(::mlir::ArrayAttr attr) { |
5162 | (*this)->setAttr(getToutAttrName(), attr); |
5163 | } |
5164 | |
5165 | void IfOp::ToutAttr(::mlir::ArrayAttr attr) { |
5166 | (*this)->setAttr(ToutAttrName(), attr); |
5167 | } |
5168 | |
5169 | void IfOp::setOutputShapesAttr(::mlir::ArrayAttr attr) { |
5170 | (*this)->setAttr(getOutputShapesAttrName(), attr); |
5171 | } |
5172 | |
5173 | void IfOp::output_shapesAttr(::mlir::ArrayAttr attr) { |
5174 | (*this)->setAttr(output_shapesAttrName(), attr); |
5175 | } |
5176 | |
5177 | ::mlir::Attribute IfOp::removeTcondAttr() { |
5178 | return (*this)->removeAttr(getTcondAttrName()); |
5179 | } |
5180 | |
5181 | ::mlir::Attribute IfOp::removeTinAttr() { |
5182 | return (*this)->removeAttr(getTinAttrName()); |
5183 | } |
5184 | |
5185 | ::mlir::Attribute IfOp::removeToutAttr() { |
5186 | return (*this)->removeAttr(getToutAttrName()); |
5187 | } |
5188 | |
5189 | ::mlir::Attribute IfOp::removeOutput_shapesAttr() { |
5190 | return (*this)->removeAttr(getOutputShapesAttrName()); |
5191 | } |
5192 | |
5193 | void IfOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, TypeRange results, Value cond, ValueRange args, FuncAttr then_branch, FuncAttr else_branch) { |
5194 | build(odsBuilder, odsState, results, cond, args, then_branch, else_branch, |
5195 | /*Tcond=*/{}, /*Tin=*/{}, /*Tout=*/{}, /*output_shapes=*/{}); |
5196 | |
5197 | } |
5198 | |
5199 | void IfOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange outs, ::mlir::Type ctl, ::mlir::Value cond, ::mlir::ValueRange args, ::mlir::tf_type::FuncAttr then_branch, ::mlir::tf_type::FuncAttr else_branch, /*optional*/::mlir::TypeAttr Tcond, /*optional*/::mlir::ArrayAttr Tin, /*optional*/::mlir::ArrayAttr Tout, /*optional*/::mlir::ArrayAttr output_shapes) { |
5200 | odsState.addOperands(cond); |
5201 | odsState.addOperands(args); |
5202 | odsState.addAttribute(getThenBranchAttrName(odsState.name), then_branch); |
5203 | odsState.addAttribute(getElseBranchAttrName(odsState.name), else_branch); |
5204 | if (Tcond) { |
5205 | odsState.addAttribute(getTcondAttrName(odsState.name), Tcond); |
5206 | } |
5207 | if (Tin) { |
5208 | odsState.addAttribute(getTinAttrName(odsState.name), Tin); |
5209 | } |
5210 | if (Tout) { |
5211 | odsState.addAttribute(getToutAttrName(odsState.name), Tout); |
5212 | } |
5213 | if (output_shapes) { |
5214 | odsState.addAttribute(getOutputShapesAttrName(odsState.name), output_shapes); |
5215 | } |
5216 | odsState.addTypes(outs); |
5217 | odsState.addTypes(ctl); |
5218 | } |
5219 | |
5220 | void IfOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value cond, ::mlir::ValueRange args, ::mlir::tf_type::FuncAttr then_branch, ::mlir::tf_type::FuncAttr else_branch, /*optional*/::mlir::TypeAttr Tcond, /*optional*/::mlir::ArrayAttr Tin, /*optional*/::mlir::ArrayAttr Tout, /*optional*/::mlir::ArrayAttr output_shapes) { |
5221 | odsState.addOperands(cond); |
5222 | odsState.addOperands(args); |
5223 | odsState.addAttribute(getThenBranchAttrName(odsState.name), then_branch); |
5224 | odsState.addAttribute(getElseBranchAttrName(odsState.name), else_branch); |
5225 | if (Tcond) { |
5226 | odsState.addAttribute(getTcondAttrName(odsState.name), Tcond); |
5227 | } |
5228 | if (Tin) { |
5229 | odsState.addAttribute(getTinAttrName(odsState.name), Tin); |
5230 | } |
5231 | if (Tout) { |
5232 | odsState.addAttribute(getToutAttrName(odsState.name), Tout); |
5233 | } |
5234 | if (output_shapes) { |
5235 | odsState.addAttribute(getOutputShapesAttrName(odsState.name), output_shapes); |
5236 | } |
5237 | assert(resultTypes.size() >= 1u && "mismatched number of results" ); |
5238 | odsState.addTypes(resultTypes); |
5239 | } |
5240 | |
5241 | void IfOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { |
5242 | assert(operands.size() >= 1u && "mismatched number of parameters" ); |
5243 | odsState.addOperands(operands); |
5244 | odsState.addAttributes(attributes); |
5245 | assert(resultTypes.size() >= 1u && "mismatched number of return types" ); |
5246 | odsState.addTypes(resultTypes); |
5247 | } |
5248 | |
5249 | ::mlir::LogicalResult IfOp::verifyInvariantsImpl() { |
5250 | auto namedAttrRange = (*this)->getAttrs(); |
5251 | auto namedAttrIt = namedAttrRange.begin(); |
5252 | ::mlir::Attribute tblgen_else_branch; |
5253 | ::mlir::Attribute tblgen_Tcond; |
5254 | ::mlir::Attribute tblgen_Tin; |
5255 | ::mlir::Attribute tblgen_Tout; |
5256 | while (true) { |
5257 | if (namedAttrIt == namedAttrRange.end()) |
5258 | return emitOpError("requires attribute 'else_branch'" ); |
5259 | if (namedAttrIt->getName() == getElseBranchAttrName()) { |
5260 | tblgen_else_branch = namedAttrIt->getValue(); |
5261 | break; |
5262 | } |
5263 | else if (namedAttrIt->getName() == getTcondAttrName()) { |
5264 | tblgen_Tcond = namedAttrIt->getValue(); |
5265 | } |
5266 | else if (namedAttrIt->getName() == getTinAttrName()) { |
5267 | tblgen_Tin = namedAttrIt->getValue(); |
5268 | } |
5269 | else if (namedAttrIt->getName() == getToutAttrName()) { |
5270 | tblgen_Tout = namedAttrIt->getValue(); |
5271 | } |
5272 | ++namedAttrIt; |
5273 | } |
5274 | ::mlir::Attribute tblgen_then_branch; |
5275 | ::mlir::Attribute tblgen_output_shapes; |
5276 | while (true) { |
5277 | if (namedAttrIt == namedAttrRange.end()) |
5278 | return emitOpError("requires attribute 'then_branch'" ); |
5279 | if (namedAttrIt->getName() == getThenBranchAttrName()) { |
5280 | tblgen_then_branch = namedAttrIt->getValue(); |
5281 | break; |
5282 | } |
5283 | else if (namedAttrIt->getName() == getOutputShapesAttrName()) { |
5284 | tblgen_output_shapes = namedAttrIt->getValue(); |
5285 | } |
5286 | ++namedAttrIt; |
5287 | } |
5288 | |
5289 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops5(*this, tblgen_then_branch, "then_branch" ))) |
5290 | return ::mlir::failure(); |
5291 | |
5292 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops5(*this, tblgen_else_branch, "else_branch" ))) |
5293 | return ::mlir::failure(); |
5294 | |
5295 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops17(*this, tblgen_Tcond, "Tcond" ))) |
5296 | return ::mlir::failure(); |
5297 | |
5298 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops1(*this, tblgen_Tin, "Tin" ))) |
5299 | return ::mlir::failure(); |
5300 | |
5301 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops1(*this, tblgen_Tout, "Tout" ))) |
5302 | return ::mlir::failure(); |
5303 | |
5304 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops2(*this, tblgen_output_shapes, "output_shapes" ))) |
5305 | return ::mlir::failure(); |
5306 | { |
5307 | unsigned index = 0; (void)index; |
5308 | auto valueGroup0 = getODSOperands(0); |
5309 | |
5310 | for (auto v : valueGroup0) { |
5311 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops7(*this, v.getType(), "operand" , index++))) |
5312 | return ::mlir::failure(); |
5313 | } |
5314 | auto valueGroup1 = getODSOperands(1); |
5315 | |
5316 | for (auto v : valueGroup1) { |
5317 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops1(*this, v.getType(), "operand" , index++))) |
5318 | return ::mlir::failure(); |
5319 | } |
5320 | } |
5321 | { |
5322 | unsigned index = 0; (void)index; |
5323 | auto valueGroup0 = getODSResults(0); |
5324 | |
5325 | for (auto v : valueGroup0) { |
5326 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops2(*this, v.getType(), "result" , index++))) |
5327 | return ::mlir::failure(); |
5328 | } |
5329 | auto valueGroup1 = getODSResults(1); |
5330 | |
5331 | for (auto v : valueGroup1) { |
5332 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops3(*this, v.getType(), "result" , index++))) |
5333 | return ::mlir::failure(); |
5334 | } |
5335 | } |
5336 | return ::mlir::success(); |
5337 | } |
5338 | |
5339 | ::mlir::LogicalResult IfOp::verifyInvariants() { |
5340 | return verifyInvariantsImpl(); |
5341 | } |
5342 | |
5343 | LogicalResult IfOp::verifySymbolUses( |
5344 | SymbolTableCollection &symbol_table) { |
5345 | return VerifyIfLikeOp(*this, symbol_table); |
5346 | } |
5347 | } // namespace tfg |
5348 | } // namespace mlir |
5349 | MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::tfg::IfOp) |
5350 | |
5351 | namespace mlir { |
5352 | namespace tfg { |
5353 | |
5354 | //===----------------------------------------------------------------------===// |
5355 | // ::mlir::tfg::IfRegionOp definitions |
5356 | //===----------------------------------------------------------------------===// |
5357 | |
5358 | IfRegionOpAdaptor::IfRegionOpAdaptor(::mlir::ValueRange values, ::mlir::DictionaryAttr attrs, ::mlir::RegionRange regions) : odsOperands(values), odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) |
5359 | odsOpName.emplace("tfg.IfRegion" , odsAttrs.getContext()); |
5360 | } |
5361 | |
5362 | IfRegionOpAdaptor::IfRegionOpAdaptor(IfRegionOp op) : odsOperands(op->getOperands()), odsAttrs(op->getAttrDictionary()), odsRegions(op->getRegions()), odsOpName(op->getName()) {} |
5363 | |
5364 | ::mlir::ValueRange IfRegionOpAdaptor::getOperands() { |
5365 | return odsOperands; |
5366 | } |
5367 | |
5368 | std::pair<unsigned, unsigned> IfRegionOpAdaptor::getODSOperandIndexAndLength(unsigned index) { |
5369 | bool isVariadic[] = {false, true}; |
5370 | int prevVariadicCount = 0; |
5371 | for (unsigned i = 0; i < index; ++i) |
5372 | if (isVariadic[i]) ++prevVariadicCount; |
5373 | |
5374 | // Calculate how many dynamic values a static variadic operand corresponds to. |
5375 | // This assumes all static variadic operands have the same dynamic value count. |
5376 | int variadicSize = (odsOperands.size() - 1) / 1; |
5377 | // `index` passed in as the parameter is the static index which counts each |
5378 | // operand (variadic or not) as size 1. So here for each previous static variadic |
5379 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
5380 | // value pack for this static operand starts. |
5381 | int start = index + (variadicSize - 1) * prevVariadicCount; |
5382 | int size = isVariadic[index] ? variadicSize : 1; |
5383 | return {start, size}; |
5384 | } |
5385 | |
5386 | ::mlir::ValueRange IfRegionOpAdaptor::getODSOperands(unsigned index) { |
5387 | auto valueRange = getODSOperandIndexAndLength(index); |
5388 | return {std::next(odsOperands.begin(), valueRange.first), |
5389 | std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; |
5390 | } |
5391 | |
5392 | ::mlir::Value IfRegionOpAdaptor::getCond() { |
5393 | return *getODSOperands(0).begin(); |
5394 | } |
5395 | |
5396 | ::mlir::Value IfRegionOpAdaptor::cond() { |
5397 | return *getODSOperands(0).begin(); |
5398 | } |
5399 | |
5400 | ::mlir::ValueRange IfRegionOpAdaptor::getCtls() { |
5401 | return getODSOperands(1); |
5402 | } |
5403 | |
5404 | ::mlir::ValueRange IfRegionOpAdaptor::ctls() { |
5405 | return getODSOperands(1); |
5406 | } |
5407 | |
5408 | ::mlir::DictionaryAttr IfRegionOpAdaptor::getAttributes() { |
5409 | return odsAttrs; |
5410 | } |
5411 | |
5412 | ::mlir::DictionaryAttr IfRegionOpAdaptor::getThenAttrsAttr() { |
5413 | assert(odsAttrs && "no attributes when constructing adapter" ); |
5414 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, IfRegionOp::getThenAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
5415 | return attr; |
5416 | } |
5417 | |
5418 | ::llvm::Optional< ::mlir::DictionaryAttr > IfRegionOpAdaptor::getThenAttrs() { |
5419 | auto attr = getThenAttrsAttr(); |
5420 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
5421 | } |
5422 | |
5423 | ::mlir::DictionaryAttr IfRegionOpAdaptor::then_attrsAttr() { |
5424 | assert(odsAttrs && "no attributes when constructing adapter" ); |
5425 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, IfRegionOp::getThenAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
5426 | return attr; |
5427 | } |
5428 | |
5429 | ::llvm::Optional< ::mlir::DictionaryAttr > IfRegionOpAdaptor::then_attrs() { |
5430 | auto attr = then_attrsAttr(); |
5431 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
5432 | } |
5433 | |
5434 | ::mlir::DictionaryAttr IfRegionOpAdaptor::getElseAttrsAttr() { |
5435 | assert(odsAttrs && "no attributes when constructing adapter" ); |
5436 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, IfRegionOp::getElseAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
5437 | return attr; |
5438 | } |
5439 | |
5440 | ::llvm::Optional< ::mlir::DictionaryAttr > IfRegionOpAdaptor::getElseAttrs() { |
5441 | auto attr = getElseAttrsAttr(); |
5442 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
5443 | } |
5444 | |
5445 | ::mlir::DictionaryAttr IfRegionOpAdaptor::else_attrsAttr() { |
5446 | assert(odsAttrs && "no attributes when constructing adapter" ); |
5447 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, IfRegionOp::getElseAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
5448 | return attr; |
5449 | } |
5450 | |
5451 | ::llvm::Optional< ::mlir::DictionaryAttr > IfRegionOpAdaptor::else_attrs() { |
5452 | auto attr = else_attrsAttr(); |
5453 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
5454 | } |
5455 | |
5456 | ::mlir::tfg::RegionAttr IfRegionOpAdaptor::getThenRegionAttrsAttr() { |
5457 | assert(odsAttrs && "no attributes when constructing adapter" ); |
5458 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, IfRegionOp::getThenRegionAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
5459 | return attr; |
5460 | } |
5461 | |
5462 | ::llvm::Optional<::mlir::tfg::RegionAttr> IfRegionOpAdaptor::getThenRegionAttrs() { |
5463 | auto attr = getThenRegionAttrsAttr(); |
5464 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
5465 | } |
5466 | |
5467 | ::mlir::tfg::RegionAttr IfRegionOpAdaptor::then_region_attrsAttr() { |
5468 | assert(odsAttrs && "no attributes when constructing adapter" ); |
5469 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, IfRegionOp::getThenRegionAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
5470 | return attr; |
5471 | } |
5472 | |
5473 | ::llvm::Optional<::mlir::tfg::RegionAttr> IfRegionOpAdaptor::then_region_attrs() { |
5474 | auto attr = then_region_attrsAttr(); |
5475 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
5476 | } |
5477 | |
5478 | ::mlir::tfg::RegionAttr IfRegionOpAdaptor::getElseRegionAttrsAttr() { |
5479 | assert(odsAttrs && "no attributes when constructing adapter" ); |
5480 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, IfRegionOp::getElseRegionAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
5481 | return attr; |
5482 | } |
5483 | |
5484 | ::llvm::Optional<::mlir::tfg::RegionAttr> IfRegionOpAdaptor::getElseRegionAttrs() { |
5485 | auto attr = getElseRegionAttrsAttr(); |
5486 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
5487 | } |
5488 | |
5489 | ::mlir::tfg::RegionAttr IfRegionOpAdaptor::else_region_attrsAttr() { |
5490 | assert(odsAttrs && "no attributes when constructing adapter" ); |
5491 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, IfRegionOp::getElseRegionAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
5492 | return attr; |
5493 | } |
5494 | |
5495 | ::llvm::Optional<::mlir::tfg::RegionAttr> IfRegionOpAdaptor::else_region_attrs() { |
5496 | auto attr = else_region_attrsAttr(); |
5497 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
5498 | } |
5499 | |
5500 | ::mlir::RegionRange IfRegionOpAdaptor::getRegions() { |
5501 | return odsRegions; |
5502 | } |
5503 | |
5504 | ::mlir::Region &IfRegionOpAdaptor::getThenRegion() { |
5505 | return *odsRegions[0]; |
5506 | } |
5507 | |
5508 | ::mlir::Region &IfRegionOpAdaptor::then_region() { |
5509 | return *odsRegions[0]; |
5510 | } |
5511 | |
5512 | ::mlir::Region &IfRegionOpAdaptor::getElseRegion() { |
5513 | return *odsRegions[1]; |
5514 | } |
5515 | |
5516 | ::mlir::Region &IfRegionOpAdaptor::else_region() { |
5517 | return *odsRegions[1]; |
5518 | } |
5519 | |
5520 | ::mlir::LogicalResult IfRegionOpAdaptor::verify(::mlir::Location loc) { |
5521 | auto namedAttrRange = odsAttrs; |
5522 | auto namedAttrIt = namedAttrRange.begin(); |
5523 | ::mlir::Attribute tblgen_else_attrs; |
5524 | ::mlir::Attribute tblgen_else_region_attrs; |
5525 | ::mlir::Attribute tblgen_then_attrs; |
5526 | ::mlir::Attribute tblgen_then_region_attrs; |
5527 | while (true) { |
5528 | if (namedAttrIt == namedAttrRange.end()) { |
5529 | break; |
5530 | } |
5531 | else if (namedAttrIt->getName() == IfRegionOp::getElseAttrsAttrName(*odsOpName)) { |
5532 | tblgen_else_attrs = namedAttrIt->getValue(); |
5533 | } |
5534 | else if (namedAttrIt->getName() == IfRegionOp::getElseRegionAttrsAttrName(*odsOpName)) { |
5535 | tblgen_else_region_attrs = namedAttrIt->getValue(); |
5536 | } |
5537 | else if (namedAttrIt->getName() == IfRegionOp::getThenAttrsAttrName(*odsOpName)) { |
5538 | tblgen_then_attrs = namedAttrIt->getValue(); |
5539 | } |
5540 | else if (namedAttrIt->getName() == IfRegionOp::getThenRegionAttrsAttrName(*odsOpName)) { |
5541 | tblgen_then_region_attrs = namedAttrIt->getValue(); |
5542 | } |
5543 | ++namedAttrIt; |
5544 | } |
5545 | |
5546 | if (tblgen_then_attrs && !((tblgen_then_attrs.isa<::mlir::DictionaryAttr>()))) |
5547 | return emitError(loc, "'tfg.IfRegion' op " "attribute 'then_attrs' failed to satisfy constraint: dictionary of named attribute values" ); |
5548 | |
5549 | if (tblgen_else_attrs && !((tblgen_else_attrs.isa<::mlir::DictionaryAttr>()))) |
5550 | return emitError(loc, "'tfg.IfRegion' op " "attribute 'else_attrs' failed to satisfy constraint: dictionary of named attribute values" ); |
5551 | |
5552 | if (tblgen_then_region_attrs && !((tblgen_then_region_attrs.isa<::mlir::tfg::RegionAttr>()))) |
5553 | return emitError(loc, "'tfg.IfRegion' op " "attribute 'then_region_attrs' failed to satisfy constraint: Region attributes, argument and result attributes." ); |
5554 | |
5555 | if (tblgen_else_region_attrs && !((tblgen_else_region_attrs.isa<::mlir::tfg::RegionAttr>()))) |
5556 | return emitError(loc, "'tfg.IfRegion' op " "attribute 'else_region_attrs' failed to satisfy constraint: Region attributes, argument and result attributes." ); |
5557 | return ::mlir::success(); |
5558 | } |
5559 | |
5560 | std::pair<unsigned, unsigned> IfRegionOp::getODSOperandIndexAndLength(unsigned index) { |
5561 | bool isVariadic[] = {false, true}; |
5562 | int prevVariadicCount = 0; |
5563 | for (unsigned i = 0; i < index; ++i) |
5564 | if (isVariadic[i]) ++prevVariadicCount; |
5565 | |
5566 | // Calculate how many dynamic values a static variadic operand corresponds to. |
5567 | // This assumes all static variadic operands have the same dynamic value count. |
5568 | int variadicSize = (getOperation()->getNumOperands() - 1) / 1; |
5569 | // `index` passed in as the parameter is the static index which counts each |
5570 | // operand (variadic or not) as size 1. So here for each previous static variadic |
5571 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
5572 | // value pack for this static operand starts. |
5573 | int start = index + (variadicSize - 1) * prevVariadicCount; |
5574 | int size = isVariadic[index] ? variadicSize : 1; |
5575 | return {start, size}; |
5576 | } |
5577 | |
5578 | ::mlir::Operation::operand_range IfRegionOp::getODSOperands(unsigned index) { |
5579 | auto valueRange = getODSOperandIndexAndLength(index); |
5580 | return {std::next(getOperation()->operand_begin(), valueRange.first), |
5581 | std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; |
5582 | } |
5583 | |
5584 | ::mlir::TypedValue<::mlir::TensorType> IfRegionOp::getCond() { |
5585 | return *getODSOperands(0).begin(); |
5586 | } |
5587 | |
5588 | ::mlir::TypedValue<::mlir::TensorType> IfRegionOp::cond() { |
5589 | return *getODSOperands(0).begin(); |
5590 | } |
5591 | |
5592 | ::mlir::Operation::operand_range IfRegionOp::getCtls() { |
5593 | return getODSOperands(1); |
5594 | } |
5595 | |
5596 | ::mlir::Operation::operand_range IfRegionOp::ctls() { |
5597 | return getODSOperands(1); |
5598 | } |
5599 | |
5600 | ::mlir::MutableOperandRange IfRegionOp::getCondMutable() { |
5601 | auto range = getODSOperandIndexAndLength(0); |
5602 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
5603 | return mutableRange; |
5604 | } |
5605 | |
5606 | ::mlir::MutableOperandRange IfRegionOp::condMutable() { |
5607 | auto range = getODSOperandIndexAndLength(0); |
5608 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
5609 | return mutableRange; |
5610 | } |
5611 | |
5612 | ::mlir::MutableOperandRange IfRegionOp::getCtlsMutable() { |
5613 | auto range = getODSOperandIndexAndLength(1); |
5614 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
5615 | return mutableRange; |
5616 | } |
5617 | |
5618 | ::mlir::MutableOperandRange IfRegionOp::ctlsMutable() { |
5619 | auto range = getODSOperandIndexAndLength(1); |
5620 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
5621 | return mutableRange; |
5622 | } |
5623 | |
5624 | std::pair<unsigned, unsigned> IfRegionOp::getODSResultIndexAndLength(unsigned index) { |
5625 | bool isVariadic[] = {true, false}; |
5626 | int prevVariadicCount = 0; |
5627 | for (unsigned i = 0; i < index; ++i) |
5628 | if (isVariadic[i]) ++prevVariadicCount; |
5629 | |
5630 | // Calculate how many dynamic values a static variadic operand corresponds to. |
5631 | // This assumes all static variadic operands have the same dynamic value count. |
5632 | int variadicSize = (getOperation()->getNumResults() - 1) / 1; |
5633 | // `index` passed in as the parameter is the static index which counts each |
5634 | // operand (variadic or not) as size 1. So here for each previous static variadic |
5635 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
5636 | // value pack for this static operand starts. |
5637 | int start = index + (variadicSize - 1) * prevVariadicCount; |
5638 | int size = isVariadic[index] ? variadicSize : 1; |
5639 | return {start, size}; |
5640 | } |
5641 | |
5642 | ::mlir::Operation::result_range IfRegionOp::getODSResults(unsigned index) { |
5643 | auto valueRange = getODSResultIndexAndLength(index); |
5644 | return {std::next(getOperation()->result_begin(), valueRange.first), |
5645 | std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; |
5646 | } |
5647 | |
5648 | ::mlir::Operation::result_range IfRegionOp::getOuts() { |
5649 | return getODSResults(0); |
5650 | } |
5651 | |
5652 | ::mlir::Operation::result_range IfRegionOp::outs() { |
5653 | return getODSResults(0); |
5654 | } |
5655 | |
5656 | ::mlir::TypedValue<::mlir::tf_type::ControlType> IfRegionOp::getCtl() { |
5657 | return *getODSResults(1).begin(); |
5658 | } |
5659 | |
5660 | ::mlir::TypedValue<::mlir::tf_type::ControlType> IfRegionOp::ctl() { |
5661 | return *getODSResults(1).begin(); |
5662 | } |
5663 | |
5664 | ::mlir::Region &IfRegionOp::getThenRegion() { |
5665 | return (*this)->getRegion(0); |
5666 | } |
5667 | |
5668 | ::mlir::Region &IfRegionOp::then_region() { |
5669 | return (*this)->getRegion(0); |
5670 | } |
5671 | |
5672 | ::mlir::Region &IfRegionOp::getElseRegion() { |
5673 | return (*this)->getRegion(1); |
5674 | } |
5675 | |
5676 | ::mlir::Region &IfRegionOp::else_region() { |
5677 | return (*this)->getRegion(1); |
5678 | } |
5679 | |
5680 | ::mlir::DictionaryAttr IfRegionOp::getThenAttrsAttr() { |
5681 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getThenAttrsAttrName()).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
5682 | } |
5683 | |
5684 | ::llvm::Optional< ::mlir::DictionaryAttr > IfRegionOp::getThenAttrs() { |
5685 | auto attr = getThenAttrsAttr(); |
5686 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
5687 | } |
5688 | |
5689 | ::mlir::DictionaryAttr IfRegionOp::then_attrsAttr() { |
5690 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getThenAttrsAttrName()).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
5691 | } |
5692 | |
5693 | ::llvm::Optional< ::mlir::DictionaryAttr > IfRegionOp::then_attrs() { |
5694 | auto attr = then_attrsAttr(); |
5695 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
5696 | } |
5697 | |
5698 | ::mlir::DictionaryAttr IfRegionOp::getElseAttrsAttr() { |
5699 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getElseAttrsAttrName()).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
5700 | } |
5701 | |
5702 | ::llvm::Optional< ::mlir::DictionaryAttr > IfRegionOp::getElseAttrs() { |
5703 | auto attr = getElseAttrsAttr(); |
5704 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
5705 | } |
5706 | |
5707 | ::mlir::DictionaryAttr IfRegionOp::else_attrsAttr() { |
5708 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getElseAttrsAttrName()).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
5709 | } |
5710 | |
5711 | ::llvm::Optional< ::mlir::DictionaryAttr > IfRegionOp::else_attrs() { |
5712 | auto attr = else_attrsAttr(); |
5713 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
5714 | } |
5715 | |
5716 | ::mlir::tfg::RegionAttr IfRegionOp::getThenRegionAttrsAttr() { |
5717 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getThenRegionAttrsAttrName()).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
5718 | } |
5719 | |
5720 | ::llvm::Optional<::mlir::tfg::RegionAttr> IfRegionOp::getThenRegionAttrs() { |
5721 | auto attr = getThenRegionAttrsAttr(); |
5722 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
5723 | } |
5724 | |
5725 | ::mlir::tfg::RegionAttr IfRegionOp::then_region_attrsAttr() { |
5726 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getThenRegionAttrsAttrName()).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
5727 | } |
5728 | |
5729 | ::llvm::Optional<::mlir::tfg::RegionAttr> IfRegionOp::then_region_attrs() { |
5730 | auto attr = then_region_attrsAttr(); |
5731 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
5732 | } |
5733 | |
5734 | ::mlir::tfg::RegionAttr IfRegionOp::getElseRegionAttrsAttr() { |
5735 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getElseRegionAttrsAttrName()).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
5736 | } |
5737 | |
5738 | ::llvm::Optional<::mlir::tfg::RegionAttr> IfRegionOp::getElseRegionAttrs() { |
5739 | auto attr = getElseRegionAttrsAttr(); |
5740 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
5741 | } |
5742 | |
5743 | ::mlir::tfg::RegionAttr IfRegionOp::else_region_attrsAttr() { |
5744 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getElseRegionAttrsAttrName()).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
5745 | } |
5746 | |
5747 | ::llvm::Optional<::mlir::tfg::RegionAttr> IfRegionOp::else_region_attrs() { |
5748 | auto attr = else_region_attrsAttr(); |
5749 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
5750 | } |
5751 | |
5752 | void IfRegionOp::setThenAttrsAttr(::mlir::DictionaryAttr attr) { |
5753 | (*this)->setAttr(getThenAttrsAttrName(), attr); |
5754 | } |
5755 | |
5756 | void IfRegionOp::then_attrsAttr(::mlir::DictionaryAttr attr) { |
5757 | (*this)->setAttr(then_attrsAttrName(), attr); |
5758 | } |
5759 | |
5760 | void IfRegionOp::setElseAttrsAttr(::mlir::DictionaryAttr attr) { |
5761 | (*this)->setAttr(getElseAttrsAttrName(), attr); |
5762 | } |
5763 | |
5764 | void IfRegionOp::else_attrsAttr(::mlir::DictionaryAttr attr) { |
5765 | (*this)->setAttr(else_attrsAttrName(), attr); |
5766 | } |
5767 | |
5768 | void IfRegionOp::setThenRegionAttrsAttr(::mlir::tfg::RegionAttr attr) { |
5769 | (*this)->setAttr(getThenRegionAttrsAttrName(), attr); |
5770 | } |
5771 | |
5772 | void IfRegionOp::then_region_attrsAttr(::mlir::tfg::RegionAttr attr) { |
5773 | (*this)->setAttr(then_region_attrsAttrName(), attr); |
5774 | } |
5775 | |
5776 | void IfRegionOp::setElseRegionAttrsAttr(::mlir::tfg::RegionAttr attr) { |
5777 | (*this)->setAttr(getElseRegionAttrsAttrName(), attr); |
5778 | } |
5779 | |
5780 | void IfRegionOp::else_region_attrsAttr(::mlir::tfg::RegionAttr attr) { |
5781 | (*this)->setAttr(else_region_attrsAttrName(), attr); |
5782 | } |
5783 | |
5784 | ::mlir::Attribute IfRegionOp::removeThen_attrsAttr() { |
5785 | return (*this)->removeAttr(getThenAttrsAttrName()); |
5786 | } |
5787 | |
5788 | ::mlir::Attribute IfRegionOp::removeElse_attrsAttr() { |
5789 | return (*this)->removeAttr(getElseAttrsAttrName()); |
5790 | } |
5791 | |
5792 | ::mlir::Attribute IfRegionOp::removeThen_region_attrsAttr() { |
5793 | return (*this)->removeAttr(getThenRegionAttrsAttrName()); |
5794 | } |
5795 | |
5796 | ::mlir::Attribute IfRegionOp::removeElse_region_attrsAttr() { |
5797 | return (*this)->removeAttr(getElseRegionAttrsAttrName()); |
5798 | } |
5799 | |
5800 | void IfRegionOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange outs, ::mlir::Type ctl, ::mlir::Value cond, ::mlir::ValueRange ctls, /*optional*/::mlir::DictionaryAttr then_attrs, /*optional*/::mlir::DictionaryAttr else_attrs, /*optional*/::mlir::tfg::RegionAttr then_region_attrs, /*optional*/::mlir::tfg::RegionAttr else_region_attrs) { |
5801 | odsState.addOperands(cond); |
5802 | odsState.addOperands(ctls); |
5803 | if (then_attrs) { |
5804 | odsState.addAttribute(getThenAttrsAttrName(odsState.name), then_attrs); |
5805 | } |
5806 | if (else_attrs) { |
5807 | odsState.addAttribute(getElseAttrsAttrName(odsState.name), else_attrs); |
5808 | } |
5809 | if (then_region_attrs) { |
5810 | odsState.addAttribute(getThenRegionAttrsAttrName(odsState.name), then_region_attrs); |
5811 | } |
5812 | if (else_region_attrs) { |
5813 | odsState.addAttribute(getElseRegionAttrsAttrName(odsState.name), else_region_attrs); |
5814 | } |
5815 | (void)odsState.addRegion(); |
5816 | (void)odsState.addRegion(); |
5817 | odsState.addTypes(outs); |
5818 | odsState.addTypes(ctl); |
5819 | } |
5820 | |
5821 | void IfRegionOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value cond, ::mlir::ValueRange ctls, /*optional*/::mlir::DictionaryAttr then_attrs, /*optional*/::mlir::DictionaryAttr else_attrs, /*optional*/::mlir::tfg::RegionAttr then_region_attrs, /*optional*/::mlir::tfg::RegionAttr else_region_attrs) { |
5822 | odsState.addOperands(cond); |
5823 | odsState.addOperands(ctls); |
5824 | if (then_attrs) { |
5825 | odsState.addAttribute(getThenAttrsAttrName(odsState.name), then_attrs); |
5826 | } |
5827 | if (else_attrs) { |
5828 | odsState.addAttribute(getElseAttrsAttrName(odsState.name), else_attrs); |
5829 | } |
5830 | if (then_region_attrs) { |
5831 | odsState.addAttribute(getThenRegionAttrsAttrName(odsState.name), then_region_attrs); |
5832 | } |
5833 | if (else_region_attrs) { |
5834 | odsState.addAttribute(getElseRegionAttrsAttrName(odsState.name), else_region_attrs); |
5835 | } |
5836 | (void)odsState.addRegion(); |
5837 | (void)odsState.addRegion(); |
5838 | assert(resultTypes.size() >= 1u && "mismatched number of results" ); |
5839 | odsState.addTypes(resultTypes); |
5840 | } |
5841 | |
5842 | void IfRegionOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { |
5843 | assert(operands.size() >= 1u && "mismatched number of parameters" ); |
5844 | odsState.addOperands(operands); |
5845 | odsState.addAttributes(attributes); |
5846 | for (unsigned i = 0; i != 2; ++i) |
5847 | (void)odsState.addRegion(); |
5848 | assert(resultTypes.size() >= 1u && "mismatched number of return types" ); |
5849 | odsState.addTypes(resultTypes); |
5850 | } |
5851 | |
5852 | ::mlir::LogicalResult IfRegionOp::verifyInvariantsImpl() { |
5853 | auto namedAttrRange = (*this)->getAttrs(); |
5854 | auto namedAttrIt = namedAttrRange.begin(); |
5855 | ::mlir::Attribute tblgen_else_attrs; |
5856 | ::mlir::Attribute tblgen_else_region_attrs; |
5857 | ::mlir::Attribute tblgen_then_attrs; |
5858 | ::mlir::Attribute tblgen_then_region_attrs; |
5859 | while (true) { |
5860 | if (namedAttrIt == namedAttrRange.end()) { |
5861 | break; |
5862 | } |
5863 | else if (namedAttrIt->getName() == getElseAttrsAttrName()) { |
5864 | tblgen_else_attrs = namedAttrIt->getValue(); |
5865 | } |
5866 | else if (namedAttrIt->getName() == getElseRegionAttrsAttrName()) { |
5867 | tblgen_else_region_attrs = namedAttrIt->getValue(); |
5868 | } |
5869 | else if (namedAttrIt->getName() == getThenAttrsAttrName()) { |
5870 | tblgen_then_attrs = namedAttrIt->getValue(); |
5871 | } |
5872 | else if (namedAttrIt->getName() == getThenRegionAttrsAttrName()) { |
5873 | tblgen_then_region_attrs = namedAttrIt->getValue(); |
5874 | } |
5875 | ++namedAttrIt; |
5876 | } |
5877 | |
5878 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops6(*this, tblgen_then_attrs, "then_attrs" ))) |
5879 | return ::mlir::failure(); |
5880 | |
5881 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops6(*this, tblgen_else_attrs, "else_attrs" ))) |
5882 | return ::mlir::failure(); |
5883 | |
5884 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops7(*this, tblgen_then_region_attrs, "then_region_attrs" ))) |
5885 | return ::mlir::failure(); |
5886 | |
5887 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops7(*this, tblgen_else_region_attrs, "else_region_attrs" ))) |
5888 | return ::mlir::failure(); |
5889 | { |
5890 | unsigned index = 0; (void)index; |
5891 | auto valueGroup0 = getODSOperands(0); |
5892 | |
5893 | for (auto v : valueGroup0) { |
5894 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops5(*this, v.getType(), "operand" , index++))) |
5895 | return ::mlir::failure(); |
5896 | } |
5897 | auto valueGroup1 = getODSOperands(1); |
5898 | |
5899 | for (auto v : valueGroup1) { |
5900 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops3(*this, v.getType(), "operand" , index++))) |
5901 | return ::mlir::failure(); |
5902 | } |
5903 | } |
5904 | { |
5905 | unsigned index = 0; (void)index; |
5906 | auto valueGroup0 = getODSResults(0); |
5907 | |
5908 | for (auto v : valueGroup0) { |
5909 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops2(*this, v.getType(), "result" , index++))) |
5910 | return ::mlir::failure(); |
5911 | } |
5912 | auto valueGroup1 = getODSResults(1); |
5913 | |
5914 | for (auto v : valueGroup1) { |
5915 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops3(*this, v.getType(), "result" , index++))) |
5916 | return ::mlir::failure(); |
5917 | } |
5918 | } |
5919 | { |
5920 | unsigned index = 0; (void)index; |
5921 | |
5922 | for (auto ®ion : ::llvm::makeMutableArrayRef((*this)->getRegion(0))) |
5923 | if (::mlir::failed(__mlir_ods_local_region_constraint_ops0(*this, region, "then_region" , index++))) |
5924 | return ::mlir::failure(); |
5925 | |
5926 | for (auto ®ion : ::llvm::makeMutableArrayRef((*this)->getRegion(1))) |
5927 | if (::mlir::failed(__mlir_ods_local_region_constraint_ops0(*this, region, "else_region" , index++))) |
5928 | return ::mlir::failure(); |
5929 | } |
5930 | return ::mlir::success(); |
5931 | } |
5932 | |
5933 | ::mlir::LogicalResult IfRegionOp::verifyInvariants() { |
5934 | if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) |
5935 | return ::mlir::success(); |
5936 | return ::mlir::failure(); |
5937 | } |
5938 | |
5939 | ::mlir::ParseResult IfRegionOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { |
5940 | ::mlir::OpAsmParser::UnresolvedOperand condRawOperands[1]; |
5941 | ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> condOperands(condRawOperands); ::llvm::SMLoc condOperandsLoc; |
5942 | (void)condOperandsLoc; |
5943 | ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> ctlsOperands; |
5944 | ::llvm::SMLoc ctlsOperandsLoc; |
5945 | (void)ctlsOperandsLoc; |
5946 | std::unique_ptr<::mlir::Region> then_regionRegion = std::make_unique<::mlir::Region>(); |
5947 | std::unique_ptr<::mlir::Region> else_regionRegion = std::make_unique<::mlir::Region>(); |
5948 | ::llvm::ArrayRef<::mlir::Type> condTypes; |
5949 | ::llvm::ArrayRef<::mlir::Type> outsTypes; |
5950 | |
5951 | condOperandsLoc = parser.getCurrentLocation(); |
5952 | if (parser.parseOperand(condRawOperands[0])) |
5953 | return ::mlir::failure(); |
5954 | if (::mlir::succeeded(parser.parseOptionalLSquare())) { |
5955 | |
5956 | ctlsOperandsLoc = parser.getCurrentLocation(); |
5957 | if (parser.parseOperandList(ctlsOperands)) |
5958 | return ::mlir::failure(); |
5959 | if (parser.parseRSquare()) |
5960 | return ::mlir::failure(); |
5961 | } |
5962 | if (parser.parseKeyword("then" )) |
5963 | return ::mlir::failure(); |
5964 | |
5965 | if (parser.parseRegion(*then_regionRegion)) |
5966 | return ::mlir::failure(); |
5967 | |
5968 | if (then_regionRegion->empty()) then_regionRegion->emplaceBlock(); |
5969 | if (parser.parseKeyword("else" )) |
5970 | return ::mlir::failure(); |
5971 | |
5972 | if (parser.parseRegion(*else_regionRegion)) |
5973 | return ::mlir::failure(); |
5974 | |
5975 | if (else_regionRegion->empty()) else_regionRegion->emplaceBlock(); |
5976 | if (parser.parseOptionalAttrDict(result.attributes)) |
5977 | return ::mlir::failure(); |
5978 | if (parser.parseColon()) |
5979 | return ::mlir::failure(); |
5980 | |
5981 | ::mlir::FunctionType cond__outs_functionType; |
5982 | if (parser.parseType(cond__outs_functionType)) |
5983 | return ::mlir::failure(); |
5984 | condTypes = cond__outs_functionType.getInputs(); |
5985 | outsTypes = cond__outs_functionType.getResults(); |
5986 | result.addRegion(std::move(then_regionRegion)); |
5987 | result.addRegion(std::move(else_regionRegion)); |
5988 | ::mlir::Type odsBuildableType0 = parser.getBuilder().getType<::mlir::tf_type::ControlType>(); |
5989 | result.addTypes(outsTypes); |
5990 | result.addTypes(odsBuildableType0); |
5991 | if (parser.resolveOperands(condOperands, condTypes, condOperandsLoc, result.operands)) |
5992 | return ::mlir::failure(); |
5993 | if (parser.resolveOperands(ctlsOperands, odsBuildableType0, ctlsOperandsLoc, result.operands)) |
5994 | return ::mlir::failure(); |
5995 | return ::mlir::success(); |
5996 | } |
5997 | |
5998 | void IfRegionOp::print(::mlir::OpAsmPrinter &_odsPrinter) { |
5999 | _odsPrinter << ' '; |
6000 | _odsPrinter << getCond(); |
6001 | if (!getCtls().empty()) { |
6002 | _odsPrinter << ' '; |
6003 | _odsPrinter << "[" ; |
6004 | _odsPrinter << getCtls(); |
6005 | _odsPrinter << "]" ; |
6006 | } |
6007 | _odsPrinter << ' ' << "then" ; |
6008 | _odsPrinter << ' '; |
6009 | _odsPrinter.printRegion(getThenRegion()); |
6010 | _odsPrinter << ' ' << "else" ; |
6011 | _odsPrinter << ' '; |
6012 | _odsPrinter.printRegion(getElseRegion()); |
6013 | _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), /*elidedAttrs=*/{}); |
6014 | _odsPrinter << ' ' << ":" ; |
6015 | _odsPrinter << ' '; |
6016 | _odsPrinter.printFunctionalType(::llvm::ArrayRef<::mlir::Type>(getCond().getType()), getOuts().getTypes()); |
6017 | } |
6018 | |
6019 | StringRef IfRegionOp::getDefaultDialect() { return "tfg" ; } |
6020 | void IfRegionOp::getAsmResultNames(OpAsmSetValueNameFn setNameFn) { |
6021 | GenericGetAsmResultNames(*this, setNameFn); |
6022 | } |
6023 | |
6024 | YieldOp IfRegionOp::then_yield() { |
6025 | return cast<YieldOp>(then_block().getTerminator()); |
6026 | } |
6027 | YieldOp IfRegionOp::else_yield() { |
6028 | return cast<YieldOp>(else_block().getTerminator()); |
6029 | } |
6030 | |
6031 | void IfRegionOp::getSuccessorRegions( |
6032 | Optional<unsigned> index, ArrayRef<Attribute> operands, |
6033 | SmallVectorImpl<RegionSuccessor> ®ions) { |
6034 | GetIfLikeRegionOpSuccessorRegions(*this, index, operands, regions); |
6035 | } |
6036 | void IfRegionOp::getRegionInvocationBounds( |
6037 | ArrayRef<Attribute> operands, |
6038 | SmallVectorImpl<InvocationBounds> &invocationBounds) { |
6039 | invocationBounds.append(/*NumInputs=*/2, /*Elt=*/{0, 1}); |
6040 | } |
6041 | |
6042 | LogicalResult IfRegionOp::verify() { return VerifyIfLikeRegionOp(*this); } |
6043 | |
6044 | BlockArgument IfRegionOp::getDataValueOf(BlockArgument ctl) { |
6045 | return GetLoopRegionDataOf(ctl); |
6046 | } |
6047 | BlockArgument IfRegionOp::getControlTokenOf(BlockArgument data) { |
6048 | return GetLoopRegionControlOf(data); |
6049 | } |
6050 | BlockArgument IfRegionOp::getDataValue(Region ®ion, unsigned idx) { |
6051 | return GetLoopRegionDataArgs(region)[idx]; |
6052 | } |
6053 | BlockArgument IfRegionOp::getControlToken(Region ®ion, unsigned idx) { |
6054 | return GetLoopRegionControlTokens(region)[idx]; |
6055 | } |
6056 | } // namespace tfg |
6057 | } // namespace mlir |
6058 | MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::tfg::IfRegionOp) |
6059 | |
6060 | namespace mlir { |
6061 | namespace tfg { |
6062 | |
6063 | //===----------------------------------------------------------------------===// |
6064 | // ::mlir::tfg::ReturnOp definitions |
6065 | //===----------------------------------------------------------------------===// |
6066 | |
6067 | ReturnOpAdaptor::ReturnOpAdaptor(::mlir::ValueRange values, ::mlir::DictionaryAttr attrs, ::mlir::RegionRange regions) : odsOperands(values), odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) |
6068 | odsOpName.emplace("tfg.return" , odsAttrs.getContext()); |
6069 | } |
6070 | |
6071 | ReturnOpAdaptor::ReturnOpAdaptor(ReturnOp op) : odsOperands(op->getOperands()), odsAttrs(op->getAttrDictionary()), odsRegions(op->getRegions()), odsOpName(op->getName()) {} |
6072 | |
6073 | ::mlir::ValueRange ReturnOpAdaptor::getOperands() { |
6074 | return odsOperands; |
6075 | } |
6076 | |
6077 | std::pair<unsigned, unsigned> ReturnOpAdaptor::getODSOperandIndexAndLength(unsigned index) { |
6078 | bool isVariadic[] = {true}; |
6079 | int prevVariadicCount = 0; |
6080 | for (unsigned i = 0; i < index; ++i) |
6081 | if (isVariadic[i]) ++prevVariadicCount; |
6082 | |
6083 | // Calculate how many dynamic values a static variadic operand corresponds to. |
6084 | // This assumes all static variadic operands have the same dynamic value count. |
6085 | int variadicSize = (odsOperands.size() - 0) / 1; |
6086 | // `index` passed in as the parameter is the static index which counts each |
6087 | // operand (variadic or not) as size 1. So here for each previous static variadic |
6088 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
6089 | // value pack for this static operand starts. |
6090 | int start = index + (variadicSize - 1) * prevVariadicCount; |
6091 | int size = isVariadic[index] ? variadicSize : 1; |
6092 | return {start, size}; |
6093 | } |
6094 | |
6095 | ::mlir::ValueRange ReturnOpAdaptor::getODSOperands(unsigned index) { |
6096 | auto valueRange = getODSOperandIndexAndLength(index); |
6097 | return {std::next(odsOperands.begin(), valueRange.first), |
6098 | std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; |
6099 | } |
6100 | |
6101 | ::mlir::ValueRange ReturnOpAdaptor::operands() { |
6102 | return getODSOperands(0); |
6103 | } |
6104 | |
6105 | ::mlir::DictionaryAttr ReturnOpAdaptor::getAttributes() { |
6106 | return odsAttrs; |
6107 | } |
6108 | |
6109 | ::mlir::ArrayAttr ReturnOpAdaptor::getControlRetAttrsAttr() { |
6110 | assert(odsAttrs && "no attributes when constructing adapter" ); |
6111 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, ReturnOp::getControlRetAttrsAttrName(*odsOpName)).cast<::mlir::ArrayAttr>(); |
6112 | return attr; |
6113 | } |
6114 | |
6115 | ::mlir::ArrayAttr ReturnOpAdaptor::getControlRetAttrs() { |
6116 | auto attr = getControlRetAttrsAttr(); |
6117 | return attr; |
6118 | } |
6119 | |
6120 | ::mlir::ArrayAttr ReturnOpAdaptor::control_ret_attrsAttr() { |
6121 | assert(odsAttrs && "no attributes when constructing adapter" ); |
6122 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, ReturnOp::getControlRetAttrsAttrName(*odsOpName)).cast<::mlir::ArrayAttr>(); |
6123 | return attr; |
6124 | } |
6125 | |
6126 | ::mlir::ArrayAttr ReturnOpAdaptor::control_ret_attrs() { |
6127 | auto attr = control_ret_attrsAttr(); |
6128 | return attr; |
6129 | } |
6130 | |
6131 | ::mlir::LogicalResult ReturnOpAdaptor::verify(::mlir::Location loc) { |
6132 | auto namedAttrRange = odsAttrs; |
6133 | auto namedAttrIt = namedAttrRange.begin(); |
6134 | ::mlir::Attribute tblgen_control_ret_attrs; |
6135 | while (true) { |
6136 | if (namedAttrIt == namedAttrRange.end()) |
6137 | return emitError(loc, "'tfg.return' op " "requires attribute 'control_ret_attrs'" ); |
6138 | if (namedAttrIt->getName() == ReturnOp::getControlRetAttrsAttrName(*odsOpName)) { |
6139 | tblgen_control_ret_attrs = namedAttrIt->getValue(); |
6140 | break; |
6141 | } |
6142 | ++namedAttrIt; |
6143 | } |
6144 | |
6145 | if (tblgen_control_ret_attrs && !(((tblgen_control_ret_attrs.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_control_ret_attrs.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && ((attr.isa<::mlir::DictionaryAttr>())); })))) |
6146 | return emitError(loc, "'tfg.return' op " "attribute 'control_ret_attrs' failed to satisfy constraint: an array of dictionaries" ); |
6147 | return ::mlir::success(); |
6148 | } |
6149 | |
6150 | std::pair<unsigned, unsigned> ReturnOp::getODSOperandIndexAndLength(unsigned index) { |
6151 | bool isVariadic[] = {true}; |
6152 | int prevVariadicCount = 0; |
6153 | for (unsigned i = 0; i < index; ++i) |
6154 | if (isVariadic[i]) ++prevVariadicCount; |
6155 | |
6156 | // Calculate how many dynamic values a static variadic operand corresponds to. |
6157 | // This assumes all static variadic operands have the same dynamic value count. |
6158 | int variadicSize = (getOperation()->getNumOperands() - 0) / 1; |
6159 | // `index` passed in as the parameter is the static index which counts each |
6160 | // operand (variadic or not) as size 1. So here for each previous static variadic |
6161 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
6162 | // value pack for this static operand starts. |
6163 | int start = index + (variadicSize - 1) * prevVariadicCount; |
6164 | int size = isVariadic[index] ? variadicSize : 1; |
6165 | return {start, size}; |
6166 | } |
6167 | |
6168 | ::mlir::Operation::operand_range ReturnOp::getODSOperands(unsigned index) { |
6169 | auto valueRange = getODSOperandIndexAndLength(index); |
6170 | return {std::next(getOperation()->operand_begin(), valueRange.first), |
6171 | std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; |
6172 | } |
6173 | |
6174 | ::mlir::Operation::operand_range ReturnOp::operands() { |
6175 | return getODSOperands(0); |
6176 | } |
6177 | |
6178 | ::mlir::MutableOperandRange ReturnOp::operandsMutable() { |
6179 | auto range = getODSOperandIndexAndLength(0); |
6180 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
6181 | return mutableRange; |
6182 | } |
6183 | |
6184 | std::pair<unsigned, unsigned> ReturnOp::getODSResultIndexAndLength(unsigned index) { |
6185 | return {index, 1}; |
6186 | } |
6187 | |
6188 | ::mlir::Operation::result_range ReturnOp::getODSResults(unsigned index) { |
6189 | auto valueRange = getODSResultIndexAndLength(index); |
6190 | return {std::next(getOperation()->result_begin(), valueRange.first), |
6191 | std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; |
6192 | } |
6193 | |
6194 | ::mlir::ArrayAttr ReturnOp::getControlRetAttrsAttr() { |
6195 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getControlRetAttrsAttrName()).cast<::mlir::ArrayAttr>(); |
6196 | } |
6197 | |
6198 | ::mlir::ArrayAttr ReturnOp::getControlRetAttrs() { |
6199 | auto attr = getControlRetAttrsAttr(); |
6200 | return attr; |
6201 | } |
6202 | |
6203 | ::mlir::ArrayAttr ReturnOp::control_ret_attrsAttr() { |
6204 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getControlRetAttrsAttrName()).cast<::mlir::ArrayAttr>(); |
6205 | } |
6206 | |
6207 | ::mlir::ArrayAttr ReturnOp::control_ret_attrs() { |
6208 | auto attr = control_ret_attrsAttr(); |
6209 | return attr; |
6210 | } |
6211 | |
6212 | void ReturnOp::setControlRetAttrsAttr(::mlir::ArrayAttr attr) { |
6213 | (*this)->setAttr(getControlRetAttrsAttrName(), attr); |
6214 | } |
6215 | |
6216 | void ReturnOp::control_ret_attrsAttr(::mlir::ArrayAttr attr) { |
6217 | (*this)->setAttr(control_ret_attrsAttrName(), attr); |
6218 | } |
6219 | |
6220 | void ReturnOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange operands, ::mlir::ArrayAttr control_ret_attrs) { |
6221 | odsState.addOperands(operands); |
6222 | odsState.addAttribute(getControlRetAttrsAttrName(odsState.name), control_ret_attrs); |
6223 | } |
6224 | |
6225 | void ReturnOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::mlir::ArrayAttr control_ret_attrs) { |
6226 | odsState.addOperands(operands); |
6227 | odsState.addAttribute(getControlRetAttrsAttrName(odsState.name), control_ret_attrs); |
6228 | assert(resultTypes.size() == 0u && "mismatched number of results" ); |
6229 | odsState.addTypes(resultTypes); |
6230 | } |
6231 | |
6232 | void ReturnOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { |
6233 | odsState.addOperands(operands); |
6234 | odsState.addAttributes(attributes); |
6235 | assert(resultTypes.size() == 0u && "mismatched number of return types" ); |
6236 | odsState.addTypes(resultTypes); |
6237 | } |
6238 | |
6239 | ::mlir::LogicalResult ReturnOp::verifyInvariantsImpl() { |
6240 | auto namedAttrRange = (*this)->getAttrs(); |
6241 | auto namedAttrIt = namedAttrRange.begin(); |
6242 | ::mlir::Attribute tblgen_control_ret_attrs; |
6243 | while (true) { |
6244 | if (namedAttrIt == namedAttrRange.end()) |
6245 | return emitOpError("requires attribute 'control_ret_attrs'" ); |
6246 | if (namedAttrIt->getName() == getControlRetAttrsAttrName()) { |
6247 | tblgen_control_ret_attrs = namedAttrIt->getValue(); |
6248 | break; |
6249 | } |
6250 | ++namedAttrIt; |
6251 | } |
6252 | |
6253 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops3(*this, tblgen_control_ret_attrs, "control_ret_attrs" ))) |
6254 | return ::mlir::failure(); |
6255 | { |
6256 | unsigned index = 0; (void)index; |
6257 | auto valueGroup0 = getODSOperands(0); |
6258 | |
6259 | for (auto v : valueGroup0) { |
6260 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops8(*this, v.getType(), "operand" , index++))) |
6261 | return ::mlir::failure(); |
6262 | } |
6263 | } |
6264 | return ::mlir::success(); |
6265 | } |
6266 | |
6267 | ::mlir::LogicalResult ReturnOp::verifyInvariants() { |
6268 | if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) |
6269 | return ::mlir::success(); |
6270 | return ::mlir::failure(); |
6271 | } |
6272 | |
6273 | void ReturnOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { |
6274 | } |
6275 | |
6276 | } // namespace tfg |
6277 | } // namespace mlir |
6278 | MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::tfg::ReturnOp) |
6279 | |
6280 | namespace mlir { |
6281 | namespace tfg { |
6282 | |
6283 | //===----------------------------------------------------------------------===// |
6284 | // ::mlir::tfg::StatefulCaseOp definitions |
6285 | //===----------------------------------------------------------------------===// |
6286 | |
6287 | StatefulCaseOpAdaptor::StatefulCaseOpAdaptor(::mlir::ValueRange values, ::mlir::DictionaryAttr attrs, ::mlir::RegionRange regions) : odsOperands(values), odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) |
6288 | odsOpName.emplace("tfg.StatefulCase" , odsAttrs.getContext()); |
6289 | } |
6290 | |
6291 | StatefulCaseOpAdaptor::StatefulCaseOpAdaptor(StatefulCaseOp op) : odsOperands(op->getOperands()), odsAttrs(op->getAttrDictionary()), odsRegions(op->getRegions()), odsOpName(op->getName()) {} |
6292 | |
6293 | ::mlir::ValueRange StatefulCaseOpAdaptor::getOperands() { |
6294 | return odsOperands; |
6295 | } |
6296 | |
6297 | std::pair<unsigned, unsigned> StatefulCaseOpAdaptor::getODSOperandIndexAndLength(unsigned index) { |
6298 | bool isVariadic[] = {false, true}; |
6299 | int prevVariadicCount = 0; |
6300 | for (unsigned i = 0; i < index; ++i) |
6301 | if (isVariadic[i]) ++prevVariadicCount; |
6302 | |
6303 | // Calculate how many dynamic values a static variadic operand corresponds to. |
6304 | // This assumes all static variadic operands have the same dynamic value count. |
6305 | int variadicSize = (odsOperands.size() - 1) / 1; |
6306 | // `index` passed in as the parameter is the static index which counts each |
6307 | // operand (variadic or not) as size 1. So here for each previous static variadic |
6308 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
6309 | // value pack for this static operand starts. |
6310 | int start = index + (variadicSize - 1) * prevVariadicCount; |
6311 | int size = isVariadic[index] ? variadicSize : 1; |
6312 | return {start, size}; |
6313 | } |
6314 | |
6315 | ::mlir::ValueRange StatefulCaseOpAdaptor::getODSOperands(unsigned index) { |
6316 | auto valueRange = getODSOperandIndexAndLength(index); |
6317 | return {std::next(odsOperands.begin(), valueRange.first), |
6318 | std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; |
6319 | } |
6320 | |
6321 | ::mlir::Value StatefulCaseOpAdaptor::getBranchIndex() { |
6322 | return *getODSOperands(0).begin(); |
6323 | } |
6324 | |
6325 | ::mlir::Value StatefulCaseOpAdaptor::branch_index() { |
6326 | return *getODSOperands(0).begin(); |
6327 | } |
6328 | |
6329 | ::mlir::ValueRange StatefulCaseOpAdaptor::getArgs() { |
6330 | return getODSOperands(1); |
6331 | } |
6332 | |
6333 | ::mlir::ValueRange StatefulCaseOpAdaptor::args() { |
6334 | return getODSOperands(1); |
6335 | } |
6336 | |
6337 | ::mlir::DictionaryAttr StatefulCaseOpAdaptor::getAttributes() { |
6338 | return odsAttrs; |
6339 | } |
6340 | |
6341 | ::mlir::ArrayAttr StatefulCaseOpAdaptor::getBranchesAttr() { |
6342 | assert(odsAttrs && "no attributes when constructing adapter" ); |
6343 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, StatefulCaseOp::getBranchesAttrName(*odsOpName)).cast<::mlir::ArrayAttr>(); |
6344 | return attr; |
6345 | } |
6346 | |
6347 | ::mlir::ArrayAttr StatefulCaseOpAdaptor::getBranches() { |
6348 | auto attr = getBranchesAttr(); |
6349 | return attr; |
6350 | } |
6351 | |
6352 | ::mlir::ArrayAttr StatefulCaseOpAdaptor::branchesAttr() { |
6353 | assert(odsAttrs && "no attributes when constructing adapter" ); |
6354 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, StatefulCaseOp::getBranchesAttrName(*odsOpName)).cast<::mlir::ArrayAttr>(); |
6355 | return attr; |
6356 | } |
6357 | |
6358 | ::mlir::ArrayAttr StatefulCaseOpAdaptor::branches() { |
6359 | auto attr = branchesAttr(); |
6360 | return attr; |
6361 | } |
6362 | |
6363 | ::mlir::ArrayAttr StatefulCaseOpAdaptor::getTinAttr() { |
6364 | assert(odsAttrs && "no attributes when constructing adapter" ); |
6365 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 1, StatefulCaseOp::getTinAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
6366 | return attr; |
6367 | } |
6368 | |
6369 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulCaseOpAdaptor::getTin() { |
6370 | auto attr = getTinAttr(); |
6371 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
6372 | } |
6373 | |
6374 | ::mlir::ArrayAttr StatefulCaseOpAdaptor::TinAttr() { |
6375 | assert(odsAttrs && "no attributes when constructing adapter" ); |
6376 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 1, StatefulCaseOp::getTinAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
6377 | return attr; |
6378 | } |
6379 | |
6380 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulCaseOpAdaptor::Tin() { |
6381 | auto attr = TinAttr(); |
6382 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
6383 | } |
6384 | |
6385 | ::mlir::ArrayAttr StatefulCaseOpAdaptor::getToutAttr() { |
6386 | assert(odsAttrs && "no attributes when constructing adapter" ); |
6387 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 1, StatefulCaseOp::getToutAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
6388 | return attr; |
6389 | } |
6390 | |
6391 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulCaseOpAdaptor::getTout() { |
6392 | auto attr = getToutAttr(); |
6393 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
6394 | } |
6395 | |
6396 | ::mlir::ArrayAttr StatefulCaseOpAdaptor::ToutAttr() { |
6397 | assert(odsAttrs && "no attributes when constructing adapter" ); |
6398 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 1, StatefulCaseOp::getToutAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
6399 | return attr; |
6400 | } |
6401 | |
6402 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulCaseOpAdaptor::Tout() { |
6403 | auto attr = ToutAttr(); |
6404 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
6405 | } |
6406 | |
6407 | ::mlir::ArrayAttr StatefulCaseOpAdaptor::getOutputShapesAttr() { |
6408 | assert(odsAttrs && "no attributes when constructing adapter" ); |
6409 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 0, StatefulCaseOp::getOutputShapesAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
6410 | return attr; |
6411 | } |
6412 | |
6413 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulCaseOpAdaptor::getOutputShapes() { |
6414 | auto attr = getOutputShapesAttr(); |
6415 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
6416 | } |
6417 | |
6418 | ::mlir::ArrayAttr StatefulCaseOpAdaptor::output_shapesAttr() { |
6419 | assert(odsAttrs && "no attributes when constructing adapter" ); |
6420 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 0, StatefulCaseOp::getOutputShapesAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
6421 | return attr; |
6422 | } |
6423 | |
6424 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulCaseOpAdaptor::output_shapes() { |
6425 | auto attr = output_shapesAttr(); |
6426 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
6427 | } |
6428 | |
6429 | ::mlir::LogicalResult StatefulCaseOpAdaptor::verify(::mlir::Location loc) { |
6430 | auto namedAttrRange = odsAttrs; |
6431 | auto namedAttrIt = namedAttrRange.begin(); |
6432 | ::mlir::Attribute tblgen_branches; |
6433 | ::mlir::Attribute tblgen_Tin; |
6434 | ::mlir::Attribute tblgen_Tout; |
6435 | while (true) { |
6436 | if (namedAttrIt == namedAttrRange.end()) |
6437 | return emitError(loc, "'tfg.StatefulCase' op " "requires attribute 'branches'" ); |
6438 | if (namedAttrIt->getName() == StatefulCaseOp::getBranchesAttrName(*odsOpName)) { |
6439 | tblgen_branches = namedAttrIt->getValue(); |
6440 | break; |
6441 | } |
6442 | else if (namedAttrIt->getName() == StatefulCaseOp::getTinAttrName(*odsOpName)) { |
6443 | tblgen_Tin = namedAttrIt->getValue(); |
6444 | } |
6445 | else if (namedAttrIt->getName() == StatefulCaseOp::getToutAttrName(*odsOpName)) { |
6446 | tblgen_Tout = namedAttrIt->getValue(); |
6447 | } |
6448 | ++namedAttrIt; |
6449 | } |
6450 | ::mlir::Attribute tblgen_output_shapes; |
6451 | while (true) { |
6452 | if (namedAttrIt == namedAttrRange.end()) { |
6453 | break; |
6454 | } |
6455 | else if (namedAttrIt->getName() == StatefulCaseOp::getOutputShapesAttrName(*odsOpName)) { |
6456 | tblgen_output_shapes = namedAttrIt->getValue(); |
6457 | } |
6458 | ++namedAttrIt; |
6459 | } |
6460 | |
6461 | if (tblgen_branches && !(((tblgen_branches.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_branches.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && ((attr.isa<::mlir::tf_type::FuncAttr>())); })))) |
6462 | return emitError(loc, "'tfg.StatefulCase' op " "attribute 'branches' failed to satisfy constraint: an array of functions" ); |
6463 | |
6464 | if (tblgen_Tin && !(((tblgen_Tin.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_Tin.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && (((attr.isa<::mlir::TypeAttr>())) && ((attr.cast<::mlir::TypeAttr>().getValue().isa<::mlir::Type>()))); })))) |
6465 | return emitError(loc, "'tfg.StatefulCase' op " "attribute 'Tin' failed to satisfy constraint: type array attribute" ); |
6466 | |
6467 | if (tblgen_Tout && !(((tblgen_Tout.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_Tout.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && (((attr.isa<::mlir::TypeAttr>())) && ((attr.cast<::mlir::TypeAttr>().getValue().isa<::mlir::Type>()))); })))) |
6468 | return emitError(loc, "'tfg.StatefulCase' op " "attribute 'Tout' failed to satisfy constraint: type array attribute" ); |
6469 | |
6470 | if (tblgen_output_shapes && !(((tblgen_output_shapes.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_output_shapes.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && ((attr.isa<::mlir::tf_type::ShapeAttr>())); })))) |
6471 | return emitError(loc, "'tfg.StatefulCase' op " "attribute 'output_shapes' failed to satisfy constraint: An array of shapes." ); |
6472 | return ::mlir::success(); |
6473 | } |
6474 | |
6475 | void StatefulCaseOp::getAsmResultNames(::mlir::OpAsmSetValueNameFn setNameFn) { |
6476 | auto resultGroup0 = getODSResults(0); |
6477 | if (!resultGroup0.empty()) |
6478 | setNameFn(*resultGroup0.begin(), "outs" ); |
6479 | auto resultGroup1 = getODSResults(1); |
6480 | if (!resultGroup1.empty()) |
6481 | setNameFn(*resultGroup1.begin(), "ctl" ); |
6482 | } |
6483 | |
6484 | std::pair<unsigned, unsigned> StatefulCaseOp::getODSOperandIndexAndLength(unsigned index) { |
6485 | bool isVariadic[] = {false, true}; |
6486 | int prevVariadicCount = 0; |
6487 | for (unsigned i = 0; i < index; ++i) |
6488 | if (isVariadic[i]) ++prevVariadicCount; |
6489 | |
6490 | // Calculate how many dynamic values a static variadic operand corresponds to. |
6491 | // This assumes all static variadic operands have the same dynamic value count. |
6492 | int variadicSize = (getOperation()->getNumOperands() - 1) / 1; |
6493 | // `index` passed in as the parameter is the static index which counts each |
6494 | // operand (variadic or not) as size 1. So here for each previous static variadic |
6495 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
6496 | // value pack for this static operand starts. |
6497 | int start = index + (variadicSize - 1) * prevVariadicCount; |
6498 | int size = isVariadic[index] ? variadicSize : 1; |
6499 | return {start, size}; |
6500 | } |
6501 | |
6502 | ::mlir::Operation::operand_range StatefulCaseOp::getODSOperands(unsigned index) { |
6503 | auto valueRange = getODSOperandIndexAndLength(index); |
6504 | return {std::next(getOperation()->operand_begin(), valueRange.first), |
6505 | std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; |
6506 | } |
6507 | |
6508 | ::mlir::Value StatefulCaseOp::getBranchIndex() { |
6509 | return *getODSOperands(0).begin(); |
6510 | } |
6511 | |
6512 | ::mlir::Value StatefulCaseOp::branch_index() { |
6513 | return *getODSOperands(0).begin(); |
6514 | } |
6515 | |
6516 | ::mlir::Operation::operand_range StatefulCaseOp::getArgs() { |
6517 | return getODSOperands(1); |
6518 | } |
6519 | |
6520 | ::mlir::Operation::operand_range StatefulCaseOp::args() { |
6521 | return getODSOperands(1); |
6522 | } |
6523 | |
6524 | ::mlir::MutableOperandRange StatefulCaseOp::getBranchIndexMutable() { |
6525 | auto range = getODSOperandIndexAndLength(0); |
6526 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
6527 | return mutableRange; |
6528 | } |
6529 | |
6530 | ::mlir::MutableOperandRange StatefulCaseOp::branch_indexMutable() { |
6531 | auto range = getODSOperandIndexAndLength(0); |
6532 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
6533 | return mutableRange; |
6534 | } |
6535 | |
6536 | ::mlir::MutableOperandRange StatefulCaseOp::getArgsMutable() { |
6537 | auto range = getODSOperandIndexAndLength(1); |
6538 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
6539 | return mutableRange; |
6540 | } |
6541 | |
6542 | ::mlir::MutableOperandRange StatefulCaseOp::argsMutable() { |
6543 | auto range = getODSOperandIndexAndLength(1); |
6544 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
6545 | return mutableRange; |
6546 | } |
6547 | |
6548 | std::pair<unsigned, unsigned> StatefulCaseOp::getODSResultIndexAndLength(unsigned index) { |
6549 | bool isVariadic[] = {true, false}; |
6550 | int prevVariadicCount = 0; |
6551 | for (unsigned i = 0; i < index; ++i) |
6552 | if (isVariadic[i]) ++prevVariadicCount; |
6553 | |
6554 | // Calculate how many dynamic values a static variadic operand corresponds to. |
6555 | // This assumes all static variadic operands have the same dynamic value count. |
6556 | int variadicSize = (getOperation()->getNumResults() - 1) / 1; |
6557 | // `index` passed in as the parameter is the static index which counts each |
6558 | // operand (variadic or not) as size 1. So here for each previous static variadic |
6559 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
6560 | // value pack for this static operand starts. |
6561 | int start = index + (variadicSize - 1) * prevVariadicCount; |
6562 | int size = isVariadic[index] ? variadicSize : 1; |
6563 | return {start, size}; |
6564 | } |
6565 | |
6566 | ::mlir::Operation::result_range StatefulCaseOp::getODSResults(unsigned index) { |
6567 | auto valueRange = getODSResultIndexAndLength(index); |
6568 | return {std::next(getOperation()->result_begin(), valueRange.first), |
6569 | std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; |
6570 | } |
6571 | |
6572 | ::mlir::Operation::result_range StatefulCaseOp::getOuts() { |
6573 | return getODSResults(0); |
6574 | } |
6575 | |
6576 | ::mlir::Operation::result_range StatefulCaseOp::outs() { |
6577 | return getODSResults(0); |
6578 | } |
6579 | |
6580 | ::mlir::TypedValue<::mlir::tf_type::ControlType> StatefulCaseOp::getCtl() { |
6581 | return *getODSResults(1).begin(); |
6582 | } |
6583 | |
6584 | ::mlir::TypedValue<::mlir::tf_type::ControlType> StatefulCaseOp::ctl() { |
6585 | return *getODSResults(1).begin(); |
6586 | } |
6587 | |
6588 | ::mlir::ArrayAttr StatefulCaseOp::getBranchesAttr() { |
6589 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getBranchesAttrName()).cast<::mlir::ArrayAttr>(); |
6590 | } |
6591 | |
6592 | ::mlir::ArrayAttr StatefulCaseOp::getBranches() { |
6593 | auto attr = getBranchesAttr(); |
6594 | return attr; |
6595 | } |
6596 | |
6597 | ::mlir::ArrayAttr StatefulCaseOp::branchesAttr() { |
6598 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getBranchesAttrName()).cast<::mlir::ArrayAttr>(); |
6599 | } |
6600 | |
6601 | ::mlir::ArrayAttr StatefulCaseOp::branches() { |
6602 | auto attr = branchesAttr(); |
6603 | return attr; |
6604 | } |
6605 | |
6606 | ::mlir::ArrayAttr StatefulCaseOp::getTinAttr() { |
6607 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getTinAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
6608 | } |
6609 | |
6610 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulCaseOp::getTin() { |
6611 | auto attr = getTinAttr(); |
6612 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
6613 | } |
6614 | |
6615 | ::mlir::ArrayAttr StatefulCaseOp::TinAttr() { |
6616 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getTinAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
6617 | } |
6618 | |
6619 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulCaseOp::Tin() { |
6620 | auto attr = TinAttr(); |
6621 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
6622 | } |
6623 | |
6624 | ::mlir::ArrayAttr StatefulCaseOp::getToutAttr() { |
6625 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getToutAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
6626 | } |
6627 | |
6628 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulCaseOp::getTout() { |
6629 | auto attr = getToutAttr(); |
6630 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
6631 | } |
6632 | |
6633 | ::mlir::ArrayAttr StatefulCaseOp::ToutAttr() { |
6634 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getToutAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
6635 | } |
6636 | |
6637 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulCaseOp::Tout() { |
6638 | auto attr = ToutAttr(); |
6639 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
6640 | } |
6641 | |
6642 | ::mlir::ArrayAttr StatefulCaseOp::getOutputShapesAttr() { |
6643 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getOutputShapesAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
6644 | } |
6645 | |
6646 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulCaseOp::getOutputShapes() { |
6647 | auto attr = getOutputShapesAttr(); |
6648 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
6649 | } |
6650 | |
6651 | ::mlir::ArrayAttr StatefulCaseOp::output_shapesAttr() { |
6652 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getOutputShapesAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
6653 | } |
6654 | |
6655 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulCaseOp::output_shapes() { |
6656 | auto attr = output_shapesAttr(); |
6657 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
6658 | } |
6659 | |
6660 | void StatefulCaseOp::setBranchesAttr(::mlir::ArrayAttr attr) { |
6661 | (*this)->setAttr(getBranchesAttrName(), attr); |
6662 | } |
6663 | |
6664 | void StatefulCaseOp::branchesAttr(::mlir::ArrayAttr attr) { |
6665 | (*this)->setAttr(branchesAttrName(), attr); |
6666 | } |
6667 | |
6668 | void StatefulCaseOp::setTinAttr(::mlir::ArrayAttr attr) { |
6669 | (*this)->setAttr(getTinAttrName(), attr); |
6670 | } |
6671 | |
6672 | void StatefulCaseOp::TinAttr(::mlir::ArrayAttr attr) { |
6673 | (*this)->setAttr(TinAttrName(), attr); |
6674 | } |
6675 | |
6676 | void StatefulCaseOp::setToutAttr(::mlir::ArrayAttr attr) { |
6677 | (*this)->setAttr(getToutAttrName(), attr); |
6678 | } |
6679 | |
6680 | void StatefulCaseOp::ToutAttr(::mlir::ArrayAttr attr) { |
6681 | (*this)->setAttr(ToutAttrName(), attr); |
6682 | } |
6683 | |
6684 | void StatefulCaseOp::setOutputShapesAttr(::mlir::ArrayAttr attr) { |
6685 | (*this)->setAttr(getOutputShapesAttrName(), attr); |
6686 | } |
6687 | |
6688 | void StatefulCaseOp::output_shapesAttr(::mlir::ArrayAttr attr) { |
6689 | (*this)->setAttr(output_shapesAttrName(), attr); |
6690 | } |
6691 | |
6692 | ::mlir::Attribute StatefulCaseOp::removeTinAttr() { |
6693 | return (*this)->removeAttr(getTinAttrName()); |
6694 | } |
6695 | |
6696 | ::mlir::Attribute StatefulCaseOp::removeToutAttr() { |
6697 | return (*this)->removeAttr(getToutAttrName()); |
6698 | } |
6699 | |
6700 | ::mlir::Attribute StatefulCaseOp::removeOutput_shapesAttr() { |
6701 | return (*this)->removeAttr(getOutputShapesAttrName()); |
6702 | } |
6703 | |
6704 | void StatefulCaseOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, TypeRange results, Value branch_index, ValueRange args, ArrayAttr branches) { |
6705 | build(odsBuilder, odsState, results, branch_index, args, branches, |
6706 | /*Tin=*/{}, /*Tout=*/{}, /*output_shapes=*/{}); |
6707 | |
6708 | } |
6709 | |
6710 | void StatefulCaseOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange outs, ::mlir::Type ctl, ::mlir::Value branch_index, ::mlir::ValueRange args, ::mlir::ArrayAttr branches, /*optional*/::mlir::ArrayAttr Tin, /*optional*/::mlir::ArrayAttr Tout, /*optional*/::mlir::ArrayAttr output_shapes) { |
6711 | odsState.addOperands(branch_index); |
6712 | odsState.addOperands(args); |
6713 | odsState.addAttribute(getBranchesAttrName(odsState.name), branches); |
6714 | if (Tin) { |
6715 | odsState.addAttribute(getTinAttrName(odsState.name), Tin); |
6716 | } |
6717 | if (Tout) { |
6718 | odsState.addAttribute(getToutAttrName(odsState.name), Tout); |
6719 | } |
6720 | if (output_shapes) { |
6721 | odsState.addAttribute(getOutputShapesAttrName(odsState.name), output_shapes); |
6722 | } |
6723 | odsState.addTypes(outs); |
6724 | odsState.addTypes(ctl); |
6725 | } |
6726 | |
6727 | void StatefulCaseOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value branch_index, ::mlir::ValueRange args, ::mlir::ArrayAttr branches, /*optional*/::mlir::ArrayAttr Tin, /*optional*/::mlir::ArrayAttr Tout, /*optional*/::mlir::ArrayAttr output_shapes) { |
6728 | odsState.addOperands(branch_index); |
6729 | odsState.addOperands(args); |
6730 | odsState.addAttribute(getBranchesAttrName(odsState.name), branches); |
6731 | if (Tin) { |
6732 | odsState.addAttribute(getTinAttrName(odsState.name), Tin); |
6733 | } |
6734 | if (Tout) { |
6735 | odsState.addAttribute(getToutAttrName(odsState.name), Tout); |
6736 | } |
6737 | if (output_shapes) { |
6738 | odsState.addAttribute(getOutputShapesAttrName(odsState.name), output_shapes); |
6739 | } |
6740 | assert(resultTypes.size() >= 1u && "mismatched number of results" ); |
6741 | odsState.addTypes(resultTypes); |
6742 | } |
6743 | |
6744 | void StatefulCaseOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { |
6745 | assert(operands.size() >= 1u && "mismatched number of parameters" ); |
6746 | odsState.addOperands(operands); |
6747 | odsState.addAttributes(attributes); |
6748 | assert(resultTypes.size() >= 1u && "mismatched number of return types" ); |
6749 | odsState.addTypes(resultTypes); |
6750 | } |
6751 | |
6752 | ::mlir::LogicalResult StatefulCaseOp::verifyInvariantsImpl() { |
6753 | auto namedAttrRange = (*this)->getAttrs(); |
6754 | auto namedAttrIt = namedAttrRange.begin(); |
6755 | ::mlir::Attribute tblgen_branches; |
6756 | ::mlir::Attribute tblgen_Tin; |
6757 | ::mlir::Attribute tblgen_Tout; |
6758 | while (true) { |
6759 | if (namedAttrIt == namedAttrRange.end()) |
6760 | return emitOpError("requires attribute 'branches'" ); |
6761 | if (namedAttrIt->getName() == getBranchesAttrName()) { |
6762 | tblgen_branches = namedAttrIt->getValue(); |
6763 | break; |
6764 | } |
6765 | else if (namedAttrIt->getName() == getTinAttrName()) { |
6766 | tblgen_Tin = namedAttrIt->getValue(); |
6767 | } |
6768 | else if (namedAttrIt->getName() == getToutAttrName()) { |
6769 | tblgen_Tout = namedAttrIt->getValue(); |
6770 | } |
6771 | ++namedAttrIt; |
6772 | } |
6773 | ::mlir::Attribute tblgen_output_shapes; |
6774 | while (true) { |
6775 | if (namedAttrIt == namedAttrRange.end()) { |
6776 | break; |
6777 | } |
6778 | else if (namedAttrIt->getName() == getOutputShapesAttrName()) { |
6779 | tblgen_output_shapes = namedAttrIt->getValue(); |
6780 | } |
6781 | ++namedAttrIt; |
6782 | } |
6783 | |
6784 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops0(*this, tblgen_branches, "branches" ))) |
6785 | return ::mlir::failure(); |
6786 | |
6787 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops1(*this, tblgen_Tin, "Tin" ))) |
6788 | return ::mlir::failure(); |
6789 | |
6790 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops1(*this, tblgen_Tout, "Tout" ))) |
6791 | return ::mlir::failure(); |
6792 | |
6793 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops2(*this, tblgen_output_shapes, "output_shapes" ))) |
6794 | return ::mlir::failure(); |
6795 | { |
6796 | unsigned index = 0; (void)index; |
6797 | auto valueGroup0 = getODSOperands(0); |
6798 | |
6799 | for (auto v : valueGroup0) { |
6800 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops0(*this, v.getType(), "operand" , index++))) |
6801 | return ::mlir::failure(); |
6802 | } |
6803 | auto valueGroup1 = getODSOperands(1); |
6804 | |
6805 | for (auto v : valueGroup1) { |
6806 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops1(*this, v.getType(), "operand" , index++))) |
6807 | return ::mlir::failure(); |
6808 | } |
6809 | } |
6810 | { |
6811 | unsigned index = 0; (void)index; |
6812 | auto valueGroup0 = getODSResults(0); |
6813 | |
6814 | for (auto v : valueGroup0) { |
6815 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops2(*this, v.getType(), "result" , index++))) |
6816 | return ::mlir::failure(); |
6817 | } |
6818 | auto valueGroup1 = getODSResults(1); |
6819 | |
6820 | for (auto v : valueGroup1) { |
6821 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops3(*this, v.getType(), "result" , index++))) |
6822 | return ::mlir::failure(); |
6823 | } |
6824 | } |
6825 | return ::mlir::success(); |
6826 | } |
6827 | |
6828 | ::mlir::LogicalResult StatefulCaseOp::verifyInvariants() { |
6829 | return verifyInvariantsImpl(); |
6830 | } |
6831 | |
6832 | LogicalResult StatefulCaseOp::verifySymbolUses( |
6833 | SymbolTableCollection &symbol_table) { |
6834 | return VerifyCaseLikeOp(*this, symbol_table); |
6835 | } |
6836 | } // namespace tfg |
6837 | } // namespace mlir |
6838 | MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::tfg::StatefulCaseOp) |
6839 | |
6840 | namespace mlir { |
6841 | namespace tfg { |
6842 | |
6843 | //===----------------------------------------------------------------------===// |
6844 | // ::mlir::tfg::StatefulCaseRegionOp definitions |
6845 | //===----------------------------------------------------------------------===// |
6846 | |
6847 | StatefulCaseRegionOpAdaptor::StatefulCaseRegionOpAdaptor(::mlir::ValueRange values, ::mlir::DictionaryAttr attrs, ::mlir::RegionRange regions) : odsOperands(values), odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) |
6848 | odsOpName.emplace("tfg.StatefulCaseRegion" , odsAttrs.getContext()); |
6849 | } |
6850 | |
6851 | StatefulCaseRegionOpAdaptor::StatefulCaseRegionOpAdaptor(StatefulCaseRegionOp op) : odsOperands(op->getOperands()), odsAttrs(op->getAttrDictionary()), odsRegions(op->getRegions()), odsOpName(op->getName()) {} |
6852 | |
6853 | ::mlir::ValueRange StatefulCaseRegionOpAdaptor::getOperands() { |
6854 | return odsOperands; |
6855 | } |
6856 | |
6857 | std::pair<unsigned, unsigned> StatefulCaseRegionOpAdaptor::getODSOperandIndexAndLength(unsigned index) { |
6858 | bool isVariadic[] = {false, true}; |
6859 | int prevVariadicCount = 0; |
6860 | for (unsigned i = 0; i < index; ++i) |
6861 | if (isVariadic[i]) ++prevVariadicCount; |
6862 | |
6863 | // Calculate how many dynamic values a static variadic operand corresponds to. |
6864 | // This assumes all static variadic operands have the same dynamic value count. |
6865 | int variadicSize = (odsOperands.size() - 1) / 1; |
6866 | // `index` passed in as the parameter is the static index which counts each |
6867 | // operand (variadic or not) as size 1. So here for each previous static variadic |
6868 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
6869 | // value pack for this static operand starts. |
6870 | int start = index + (variadicSize - 1) * prevVariadicCount; |
6871 | int size = isVariadic[index] ? variadicSize : 1; |
6872 | return {start, size}; |
6873 | } |
6874 | |
6875 | ::mlir::ValueRange StatefulCaseRegionOpAdaptor::getODSOperands(unsigned index) { |
6876 | auto valueRange = getODSOperandIndexAndLength(index); |
6877 | return {std::next(odsOperands.begin(), valueRange.first), |
6878 | std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; |
6879 | } |
6880 | |
6881 | ::mlir::Value StatefulCaseRegionOpAdaptor::getBranchIndex() { |
6882 | return *getODSOperands(0).begin(); |
6883 | } |
6884 | |
6885 | ::mlir::Value StatefulCaseRegionOpAdaptor::branch_index() { |
6886 | return *getODSOperands(0).begin(); |
6887 | } |
6888 | |
6889 | ::mlir::ValueRange StatefulCaseRegionOpAdaptor::getCtls() { |
6890 | return getODSOperands(1); |
6891 | } |
6892 | |
6893 | ::mlir::ValueRange StatefulCaseRegionOpAdaptor::ctls() { |
6894 | return getODSOperands(1); |
6895 | } |
6896 | |
6897 | ::mlir::DictionaryAttr StatefulCaseRegionOpAdaptor::getAttributes() { |
6898 | return odsAttrs; |
6899 | } |
6900 | |
6901 | ::mlir::ArrayAttr StatefulCaseRegionOpAdaptor::getBranchAttrsAttr() { |
6902 | assert(odsAttrs && "no attributes when constructing adapter" ); |
6903 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, StatefulCaseRegionOp::getBranchAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
6904 | return attr; |
6905 | } |
6906 | |
6907 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulCaseRegionOpAdaptor::getBranchAttrs() { |
6908 | auto attr = getBranchAttrsAttr(); |
6909 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
6910 | } |
6911 | |
6912 | ::mlir::ArrayAttr StatefulCaseRegionOpAdaptor::branch_attrsAttr() { |
6913 | assert(odsAttrs && "no attributes when constructing adapter" ); |
6914 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, StatefulCaseRegionOp::getBranchAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
6915 | return attr; |
6916 | } |
6917 | |
6918 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulCaseRegionOpAdaptor::branch_attrs() { |
6919 | auto attr = branch_attrsAttr(); |
6920 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
6921 | } |
6922 | |
6923 | ::mlir::ArrayAttr StatefulCaseRegionOpAdaptor::getRegionAttrsAttr() { |
6924 | assert(odsAttrs && "no attributes when constructing adapter" ); |
6925 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, StatefulCaseRegionOp::getRegionAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
6926 | return attr; |
6927 | } |
6928 | |
6929 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulCaseRegionOpAdaptor::getRegionAttrs() { |
6930 | auto attr = getRegionAttrsAttr(); |
6931 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
6932 | } |
6933 | |
6934 | ::mlir::ArrayAttr StatefulCaseRegionOpAdaptor::region_attrsAttr() { |
6935 | assert(odsAttrs && "no attributes when constructing adapter" ); |
6936 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, StatefulCaseRegionOp::getRegionAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
6937 | return attr; |
6938 | } |
6939 | |
6940 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulCaseRegionOpAdaptor::region_attrs() { |
6941 | auto attr = region_attrsAttr(); |
6942 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
6943 | } |
6944 | |
6945 | ::mlir::RegionRange StatefulCaseRegionOpAdaptor::getRegions() { |
6946 | return odsRegions; |
6947 | } |
6948 | |
6949 | ::mlir::RegionRange StatefulCaseRegionOpAdaptor::getBranches() { |
6950 | return odsRegions.drop_front(0); |
6951 | } |
6952 | |
6953 | ::mlir::RegionRange StatefulCaseRegionOpAdaptor::branches() { |
6954 | return odsRegions.drop_front(0); |
6955 | } |
6956 | |
6957 | ::mlir::LogicalResult StatefulCaseRegionOpAdaptor::verify(::mlir::Location loc) { |
6958 | auto namedAttrRange = odsAttrs; |
6959 | auto namedAttrIt = namedAttrRange.begin(); |
6960 | ::mlir::Attribute tblgen_branch_attrs; |
6961 | ::mlir::Attribute tblgen_region_attrs; |
6962 | while (true) { |
6963 | if (namedAttrIt == namedAttrRange.end()) { |
6964 | break; |
6965 | } |
6966 | else if (namedAttrIt->getName() == StatefulCaseRegionOp::getBranchAttrsAttrName(*odsOpName)) { |
6967 | tblgen_branch_attrs = namedAttrIt->getValue(); |
6968 | } |
6969 | else if (namedAttrIt->getName() == StatefulCaseRegionOp::getRegionAttrsAttrName(*odsOpName)) { |
6970 | tblgen_region_attrs = namedAttrIt->getValue(); |
6971 | } |
6972 | ++namedAttrIt; |
6973 | } |
6974 | |
6975 | if (tblgen_branch_attrs && !(((tblgen_branch_attrs.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_branch_attrs.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && ((attr.isa<::mlir::DictionaryAttr>())); })))) |
6976 | return emitError(loc, "'tfg.StatefulCaseRegion' op " "attribute 'branch_attrs' failed to satisfy constraint: an array of dictionaries" ); |
6977 | |
6978 | if (tblgen_region_attrs && !(((tblgen_region_attrs.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_region_attrs.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && ((attr.isa<::mlir::tfg::RegionAttr>())); })))) |
6979 | return emitError(loc, "'tfg.StatefulCaseRegion' op " "attribute 'region_attrs' failed to satisfy constraint: case region preserved attributes" ); |
6980 | return ::mlir::success(); |
6981 | } |
6982 | |
6983 | std::pair<unsigned, unsigned> StatefulCaseRegionOp::getODSOperandIndexAndLength(unsigned index) { |
6984 | bool isVariadic[] = {false, true}; |
6985 | int prevVariadicCount = 0; |
6986 | for (unsigned i = 0; i < index; ++i) |
6987 | if (isVariadic[i]) ++prevVariadicCount; |
6988 | |
6989 | // Calculate how many dynamic values a static variadic operand corresponds to. |
6990 | // This assumes all static variadic operands have the same dynamic value count. |
6991 | int variadicSize = (getOperation()->getNumOperands() - 1) / 1; |
6992 | // `index` passed in as the parameter is the static index which counts each |
6993 | // operand (variadic or not) as size 1. So here for each previous static variadic |
6994 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
6995 | // value pack for this static operand starts. |
6996 | int start = index + (variadicSize - 1) * prevVariadicCount; |
6997 | int size = isVariadic[index] ? variadicSize : 1; |
6998 | return {start, size}; |
6999 | } |
7000 | |
7001 | ::mlir::Operation::operand_range StatefulCaseRegionOp::getODSOperands(unsigned index) { |
7002 | auto valueRange = getODSOperandIndexAndLength(index); |
7003 | return {std::next(getOperation()->operand_begin(), valueRange.first), |
7004 | std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; |
7005 | } |
7006 | |
7007 | ::mlir::TypedValue<::mlir::TensorType> StatefulCaseRegionOp::getBranchIndex() { |
7008 | return *getODSOperands(0).begin(); |
7009 | } |
7010 | |
7011 | ::mlir::TypedValue<::mlir::TensorType> StatefulCaseRegionOp::branch_index() { |
7012 | return *getODSOperands(0).begin(); |
7013 | } |
7014 | |
7015 | ::mlir::Operation::operand_range StatefulCaseRegionOp::getCtls() { |
7016 | return getODSOperands(1); |
7017 | } |
7018 | |
7019 | ::mlir::Operation::operand_range StatefulCaseRegionOp::ctls() { |
7020 | return getODSOperands(1); |
7021 | } |
7022 | |
7023 | ::mlir::MutableOperandRange StatefulCaseRegionOp::getBranchIndexMutable() { |
7024 | auto range = getODSOperandIndexAndLength(0); |
7025 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
7026 | return mutableRange; |
7027 | } |
7028 | |
7029 | ::mlir::MutableOperandRange StatefulCaseRegionOp::branch_indexMutable() { |
7030 | auto range = getODSOperandIndexAndLength(0); |
7031 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
7032 | return mutableRange; |
7033 | } |
7034 | |
7035 | ::mlir::MutableOperandRange StatefulCaseRegionOp::getCtlsMutable() { |
7036 | auto range = getODSOperandIndexAndLength(1); |
7037 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
7038 | return mutableRange; |
7039 | } |
7040 | |
7041 | ::mlir::MutableOperandRange StatefulCaseRegionOp::ctlsMutable() { |
7042 | auto range = getODSOperandIndexAndLength(1); |
7043 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
7044 | return mutableRange; |
7045 | } |
7046 | |
7047 | std::pair<unsigned, unsigned> StatefulCaseRegionOp::getODSResultIndexAndLength(unsigned index) { |
7048 | bool isVariadic[] = {true, false}; |
7049 | int prevVariadicCount = 0; |
7050 | for (unsigned i = 0; i < index; ++i) |
7051 | if (isVariadic[i]) ++prevVariadicCount; |
7052 | |
7053 | // Calculate how many dynamic values a static variadic operand corresponds to. |
7054 | // This assumes all static variadic operands have the same dynamic value count. |
7055 | int variadicSize = (getOperation()->getNumResults() - 1) / 1; |
7056 | // `index` passed in as the parameter is the static index which counts each |
7057 | // operand (variadic or not) as size 1. So here for each previous static variadic |
7058 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
7059 | // value pack for this static operand starts. |
7060 | int start = index + (variadicSize - 1) * prevVariadicCount; |
7061 | int size = isVariadic[index] ? variadicSize : 1; |
7062 | return {start, size}; |
7063 | } |
7064 | |
7065 | ::mlir::Operation::result_range StatefulCaseRegionOp::getODSResults(unsigned index) { |
7066 | auto valueRange = getODSResultIndexAndLength(index); |
7067 | return {std::next(getOperation()->result_begin(), valueRange.first), |
7068 | std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; |
7069 | } |
7070 | |
7071 | ::mlir::Operation::result_range StatefulCaseRegionOp::getOuts() { |
7072 | return getODSResults(0); |
7073 | } |
7074 | |
7075 | ::mlir::Operation::result_range StatefulCaseRegionOp::outs() { |
7076 | return getODSResults(0); |
7077 | } |
7078 | |
7079 | ::mlir::TypedValue<::mlir::tf_type::ControlType> StatefulCaseRegionOp::getCtl() { |
7080 | return *getODSResults(1).begin(); |
7081 | } |
7082 | |
7083 | ::mlir::TypedValue<::mlir::tf_type::ControlType> StatefulCaseRegionOp::ctl() { |
7084 | return *getODSResults(1).begin(); |
7085 | } |
7086 | |
7087 | ::mlir::MutableArrayRef<::mlir::Region> StatefulCaseRegionOp::getBranches() { |
7088 | return (*this)->getRegions().drop_front(0); |
7089 | } |
7090 | |
7091 | ::mlir::MutableArrayRef<::mlir::Region> StatefulCaseRegionOp::branches() { |
7092 | return (*this)->getRegions().drop_front(0); |
7093 | } |
7094 | |
7095 | ::mlir::ArrayAttr StatefulCaseRegionOp::getBranchAttrsAttr() { |
7096 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getBranchAttrsAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
7097 | } |
7098 | |
7099 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulCaseRegionOp::getBranchAttrs() { |
7100 | auto attr = getBranchAttrsAttr(); |
7101 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
7102 | } |
7103 | |
7104 | ::mlir::ArrayAttr StatefulCaseRegionOp::branch_attrsAttr() { |
7105 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getBranchAttrsAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
7106 | } |
7107 | |
7108 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulCaseRegionOp::branch_attrs() { |
7109 | auto attr = branch_attrsAttr(); |
7110 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
7111 | } |
7112 | |
7113 | ::mlir::ArrayAttr StatefulCaseRegionOp::getRegionAttrsAttr() { |
7114 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getRegionAttrsAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
7115 | } |
7116 | |
7117 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulCaseRegionOp::getRegionAttrs() { |
7118 | auto attr = getRegionAttrsAttr(); |
7119 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
7120 | } |
7121 | |
7122 | ::mlir::ArrayAttr StatefulCaseRegionOp::region_attrsAttr() { |
7123 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getRegionAttrsAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
7124 | } |
7125 | |
7126 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulCaseRegionOp::region_attrs() { |
7127 | auto attr = region_attrsAttr(); |
7128 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
7129 | } |
7130 | |
7131 | void StatefulCaseRegionOp::setBranchAttrsAttr(::mlir::ArrayAttr attr) { |
7132 | (*this)->setAttr(getBranchAttrsAttrName(), attr); |
7133 | } |
7134 | |
7135 | void StatefulCaseRegionOp::branch_attrsAttr(::mlir::ArrayAttr attr) { |
7136 | (*this)->setAttr(branch_attrsAttrName(), attr); |
7137 | } |
7138 | |
7139 | void StatefulCaseRegionOp::setRegionAttrsAttr(::mlir::ArrayAttr attr) { |
7140 | (*this)->setAttr(getRegionAttrsAttrName(), attr); |
7141 | } |
7142 | |
7143 | void StatefulCaseRegionOp::region_attrsAttr(::mlir::ArrayAttr attr) { |
7144 | (*this)->setAttr(region_attrsAttrName(), attr); |
7145 | } |
7146 | |
7147 | ::mlir::Attribute StatefulCaseRegionOp::removeBranch_attrsAttr() { |
7148 | return (*this)->removeAttr(getBranchAttrsAttrName()); |
7149 | } |
7150 | |
7151 | ::mlir::Attribute StatefulCaseRegionOp::removeRegion_attrsAttr() { |
7152 | return (*this)->removeAttr(getRegionAttrsAttrName()); |
7153 | } |
7154 | |
7155 | void StatefulCaseRegionOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange outs, ::mlir::Type ctl, ::mlir::Value branch_index, ::mlir::ValueRange ctls, /*optional*/::mlir::ArrayAttr branch_attrs, /*optional*/::mlir::ArrayAttr region_attrs, unsigned branchesCount) { |
7156 | odsState.addOperands(branch_index); |
7157 | odsState.addOperands(ctls); |
7158 | if (branch_attrs) { |
7159 | odsState.addAttribute(getBranchAttrsAttrName(odsState.name), branch_attrs); |
7160 | } |
7161 | if (region_attrs) { |
7162 | odsState.addAttribute(getRegionAttrsAttrName(odsState.name), region_attrs); |
7163 | } |
7164 | for (unsigned i = 0; i < branchesCount; ++i) |
7165 | (void)odsState.addRegion(); |
7166 | odsState.addTypes(outs); |
7167 | odsState.addTypes(ctl); |
7168 | } |
7169 | |
7170 | void StatefulCaseRegionOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value branch_index, ::mlir::ValueRange ctls, /*optional*/::mlir::ArrayAttr branch_attrs, /*optional*/::mlir::ArrayAttr region_attrs, unsigned branchesCount) { |
7171 | odsState.addOperands(branch_index); |
7172 | odsState.addOperands(ctls); |
7173 | if (branch_attrs) { |
7174 | odsState.addAttribute(getBranchAttrsAttrName(odsState.name), branch_attrs); |
7175 | } |
7176 | if (region_attrs) { |
7177 | odsState.addAttribute(getRegionAttrsAttrName(odsState.name), region_attrs); |
7178 | } |
7179 | for (unsigned i = 0; i < branchesCount; ++i) |
7180 | (void)odsState.addRegion(); |
7181 | assert(resultTypes.size() >= 1u && "mismatched number of results" ); |
7182 | odsState.addTypes(resultTypes); |
7183 | } |
7184 | |
7185 | void StatefulCaseRegionOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes, unsigned numRegions) { |
7186 | assert(operands.size() >= 1u && "mismatched number of parameters" ); |
7187 | odsState.addOperands(operands); |
7188 | odsState.addAttributes(attributes); |
7189 | for (unsigned i = 0; i != numRegions; ++i) |
7190 | (void)odsState.addRegion(); |
7191 | assert(resultTypes.size() >= 1u && "mismatched number of return types" ); |
7192 | odsState.addTypes(resultTypes); |
7193 | } |
7194 | |
7195 | ::mlir::LogicalResult StatefulCaseRegionOp::verifyInvariantsImpl() { |
7196 | auto namedAttrRange = (*this)->getAttrs(); |
7197 | auto namedAttrIt = namedAttrRange.begin(); |
7198 | ::mlir::Attribute tblgen_branch_attrs; |
7199 | ::mlir::Attribute tblgen_region_attrs; |
7200 | while (true) { |
7201 | if (namedAttrIt == namedAttrRange.end()) { |
7202 | break; |
7203 | } |
7204 | else if (namedAttrIt->getName() == getBranchAttrsAttrName()) { |
7205 | tblgen_branch_attrs = namedAttrIt->getValue(); |
7206 | } |
7207 | else if (namedAttrIt->getName() == getRegionAttrsAttrName()) { |
7208 | tblgen_region_attrs = namedAttrIt->getValue(); |
7209 | } |
7210 | ++namedAttrIt; |
7211 | } |
7212 | |
7213 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops3(*this, tblgen_branch_attrs, "branch_attrs" ))) |
7214 | return ::mlir::failure(); |
7215 | |
7216 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops4(*this, tblgen_region_attrs, "region_attrs" ))) |
7217 | return ::mlir::failure(); |
7218 | { |
7219 | unsigned index = 0; (void)index; |
7220 | auto valueGroup0 = getODSOperands(0); |
7221 | |
7222 | for (auto v : valueGroup0) { |
7223 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops4(*this, v.getType(), "operand" , index++))) |
7224 | return ::mlir::failure(); |
7225 | } |
7226 | auto valueGroup1 = getODSOperands(1); |
7227 | |
7228 | for (auto v : valueGroup1) { |
7229 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops3(*this, v.getType(), "operand" , index++))) |
7230 | return ::mlir::failure(); |
7231 | } |
7232 | } |
7233 | { |
7234 | unsigned index = 0; (void)index; |
7235 | auto valueGroup0 = getODSResults(0); |
7236 | |
7237 | for (auto v : valueGroup0) { |
7238 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops2(*this, v.getType(), "result" , index++))) |
7239 | return ::mlir::failure(); |
7240 | } |
7241 | auto valueGroup1 = getODSResults(1); |
7242 | |
7243 | for (auto v : valueGroup1) { |
7244 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops3(*this, v.getType(), "result" , index++))) |
7245 | return ::mlir::failure(); |
7246 | } |
7247 | } |
7248 | { |
7249 | unsigned index = 0; (void)index; |
7250 | |
7251 | for (auto ®ion : getBranches()) |
7252 | if (::mlir::failed(__mlir_ods_local_region_constraint_ops0(*this, region, "branches" , index++))) |
7253 | return ::mlir::failure(); |
7254 | } |
7255 | return ::mlir::success(); |
7256 | } |
7257 | |
7258 | ::mlir::LogicalResult StatefulCaseRegionOp::verifyInvariants() { |
7259 | if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) |
7260 | return ::mlir::success(); |
7261 | return ::mlir::failure(); |
7262 | } |
7263 | |
7264 | ::mlir::ParseResult StatefulCaseRegionOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { |
7265 | ::mlir::OpAsmParser::UnresolvedOperand branch_indexRawOperands[1]; |
7266 | ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> branch_indexOperands(branch_indexRawOperands); ::llvm::SMLoc branch_indexOperandsLoc; |
7267 | (void)branch_indexOperandsLoc; |
7268 | ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> ctlsOperands; |
7269 | ::llvm::SMLoc ctlsOperandsLoc; |
7270 | (void)ctlsOperandsLoc; |
7271 | ::llvm::SmallVector<std::unique_ptr<::mlir::Region>, 2> branchesRegions; |
7272 | ::llvm::ArrayRef<::mlir::Type> branch_indexTypes; |
7273 | ::llvm::ArrayRef<::mlir::Type> outsTypes; |
7274 | |
7275 | branch_indexOperandsLoc = parser.getCurrentLocation(); |
7276 | if (parser.parseOperand(branch_indexRawOperands[0])) |
7277 | return ::mlir::failure(); |
7278 | if (::mlir::succeeded(parser.parseOptionalLSquare())) { |
7279 | |
7280 | ctlsOperandsLoc = parser.getCurrentLocation(); |
7281 | if (parser.parseOperandList(ctlsOperands)) |
7282 | return ::mlir::failure(); |
7283 | if (parser.parseRSquare()) |
7284 | return ::mlir::failure(); |
7285 | } |
7286 | |
7287 | { |
7288 | std::unique_ptr<::mlir::Region> region; |
7289 | auto firstRegionResult = parser.parseOptionalRegion(region); |
7290 | if (firstRegionResult.has_value()) { |
7291 | if (failed(*firstRegionResult)) |
7292 | return ::mlir::failure(); |
7293 | branchesRegions.emplace_back(std::move(region)); |
7294 | |
7295 | // Parse any trailing regions. |
7296 | while (succeeded(parser.parseOptionalComma())) { |
7297 | region = std::make_unique<::mlir::Region>(); |
7298 | if (parser.parseRegion(*region)) |
7299 | return ::mlir::failure(); |
7300 | branchesRegions.emplace_back(std::move(region)); |
7301 | } |
7302 | } |
7303 | } |
7304 | |
7305 | for (auto ®ion : branchesRegions) |
7306 | if (region->empty()) region->emplaceBlock(); |
7307 | if (parser.parseOptionalAttrDict(result.attributes)) |
7308 | return ::mlir::failure(); |
7309 | if (parser.parseColon()) |
7310 | return ::mlir::failure(); |
7311 | |
7312 | ::mlir::FunctionType branch_index__outs_functionType; |
7313 | if (parser.parseType(branch_index__outs_functionType)) |
7314 | return ::mlir::failure(); |
7315 | branch_indexTypes = branch_index__outs_functionType.getInputs(); |
7316 | outsTypes = branch_index__outs_functionType.getResults(); |
7317 | result.addRegions(branchesRegions); |
7318 | ::mlir::Type odsBuildableType0 = parser.getBuilder().getType<::mlir::tf_type::ControlType>(); |
7319 | result.addTypes(outsTypes); |
7320 | result.addTypes(odsBuildableType0); |
7321 | if (parser.resolveOperands(branch_indexOperands, branch_indexTypes, branch_indexOperandsLoc, result.operands)) |
7322 | return ::mlir::failure(); |
7323 | if (parser.resolveOperands(ctlsOperands, odsBuildableType0, ctlsOperandsLoc, result.operands)) |
7324 | return ::mlir::failure(); |
7325 | return ::mlir::success(); |
7326 | } |
7327 | |
7328 | void StatefulCaseRegionOp::print(::mlir::OpAsmPrinter &_odsPrinter) { |
7329 | _odsPrinter << ' '; |
7330 | _odsPrinter << getBranchIndex(); |
7331 | if (!getCtls().empty()) { |
7332 | _odsPrinter << ' '; |
7333 | _odsPrinter << "[" ; |
7334 | _odsPrinter << getCtls(); |
7335 | _odsPrinter << "]" ; |
7336 | } |
7337 | _odsPrinter << ' '; |
7338 | llvm::interleaveComma(getBranches(), _odsPrinter, [&](::mlir::Region ®ion) { |
7339 | _odsPrinter.printRegion(region); |
7340 | }); |
7341 | _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), /*elidedAttrs=*/{}); |
7342 | _odsPrinter << ' ' << ":" ; |
7343 | _odsPrinter << ' '; |
7344 | _odsPrinter.printFunctionalType(::llvm::ArrayRef<::mlir::Type>(getBranchIndex().getType()), getOuts().getTypes()); |
7345 | } |
7346 | |
7347 | StringRef StatefulCaseRegionOp::getDefaultDialect() { return "tfg" ; } |
7348 | void StatefulCaseRegionOp::getAsmResultNames(OpAsmSetValueNameFn setNameFn) { |
7349 | GenericGetAsmResultNames(*this, setNameFn); |
7350 | } |
7351 | |
7352 | YieldOp StatefulCaseRegionOp::branch_yield(unsigned idx) { |
7353 | return cast<YieldOp>(branch_block(idx).getTerminator()); |
7354 | } |
7355 | |
7356 | void StatefulCaseRegionOp::getSuccessorRegions( |
7357 | Optional<unsigned> index, ArrayRef<Attribute> operands, |
7358 | SmallVectorImpl<RegionSuccessor> ®ions) { |
7359 | GetCaseLikeRegionOpSuccessorRegions(*this, index, operands, regions); |
7360 | } |
7361 | void StatefulCaseRegionOp::getRegionInvocationBounds( |
7362 | ArrayRef<Attribute> operands, |
7363 | SmallVectorImpl<InvocationBounds> &invocationBounds) { |
7364 | invocationBounds.append(getNumRegions(), /*Elt=*/{0, 1}); |
7365 | } |
7366 | |
7367 | LogicalResult StatefulCaseRegionOp::verify() { return VerifyCaseLikeRegionOp(*this); } |
7368 | |
7369 | BlockArgument StatefulCaseRegionOp::getDataValueOf(BlockArgument ctl) { |
7370 | return GetLoopRegionDataOf(ctl); |
7371 | } |
7372 | BlockArgument StatefulCaseRegionOp::getControlTokenOf(BlockArgument data) { |
7373 | return GetLoopRegionControlOf(data); |
7374 | } |
7375 | BlockArgument StatefulCaseRegionOp::getDataValue(Region ®ion, unsigned idx) { |
7376 | return GetLoopRegionDataArgs(region)[idx]; |
7377 | } |
7378 | BlockArgument StatefulCaseRegionOp::getControlToken(Region ®ion, unsigned idx) { |
7379 | return GetLoopRegionControlTokens(region)[idx]; |
7380 | } |
7381 | } // namespace tfg |
7382 | } // namespace mlir |
7383 | MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::tfg::StatefulCaseRegionOp) |
7384 | |
7385 | namespace mlir { |
7386 | namespace tfg { |
7387 | |
7388 | //===----------------------------------------------------------------------===// |
7389 | // ::mlir::tfg::StatefulIfOp definitions |
7390 | //===----------------------------------------------------------------------===// |
7391 | |
7392 | StatefulIfOpAdaptor::StatefulIfOpAdaptor(::mlir::ValueRange values, ::mlir::DictionaryAttr attrs, ::mlir::RegionRange regions) : odsOperands(values), odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) |
7393 | odsOpName.emplace("tfg.StatefulIf" , odsAttrs.getContext()); |
7394 | } |
7395 | |
7396 | StatefulIfOpAdaptor::StatefulIfOpAdaptor(StatefulIfOp op) : odsOperands(op->getOperands()), odsAttrs(op->getAttrDictionary()), odsRegions(op->getRegions()), odsOpName(op->getName()) {} |
7397 | |
7398 | ::mlir::ValueRange StatefulIfOpAdaptor::getOperands() { |
7399 | return odsOperands; |
7400 | } |
7401 | |
7402 | std::pair<unsigned, unsigned> StatefulIfOpAdaptor::getODSOperandIndexAndLength(unsigned index) { |
7403 | bool isVariadic[] = {false, true}; |
7404 | int prevVariadicCount = 0; |
7405 | for (unsigned i = 0; i < index; ++i) |
7406 | if (isVariadic[i]) ++prevVariadicCount; |
7407 | |
7408 | // Calculate how many dynamic values a static variadic operand corresponds to. |
7409 | // This assumes all static variadic operands have the same dynamic value count. |
7410 | int variadicSize = (odsOperands.size() - 1) / 1; |
7411 | // `index` passed in as the parameter is the static index which counts each |
7412 | // operand (variadic or not) as size 1. So here for each previous static variadic |
7413 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
7414 | // value pack for this static operand starts. |
7415 | int start = index + (variadicSize - 1) * prevVariadicCount; |
7416 | int size = isVariadic[index] ? variadicSize : 1; |
7417 | return {start, size}; |
7418 | } |
7419 | |
7420 | ::mlir::ValueRange StatefulIfOpAdaptor::getODSOperands(unsigned index) { |
7421 | auto valueRange = getODSOperandIndexAndLength(index); |
7422 | return {std::next(odsOperands.begin(), valueRange.first), |
7423 | std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; |
7424 | } |
7425 | |
7426 | ::mlir::Value StatefulIfOpAdaptor::getCond() { |
7427 | return *getODSOperands(0).begin(); |
7428 | } |
7429 | |
7430 | ::mlir::Value StatefulIfOpAdaptor::cond() { |
7431 | return *getODSOperands(0).begin(); |
7432 | } |
7433 | |
7434 | ::mlir::ValueRange StatefulIfOpAdaptor::getArgs() { |
7435 | return getODSOperands(1); |
7436 | } |
7437 | |
7438 | ::mlir::ValueRange StatefulIfOpAdaptor::args() { |
7439 | return getODSOperands(1); |
7440 | } |
7441 | |
7442 | ::mlir::DictionaryAttr StatefulIfOpAdaptor::getAttributes() { |
7443 | return odsAttrs; |
7444 | } |
7445 | |
7446 | ::mlir::tf_type::FuncAttr StatefulIfOpAdaptor::getThenBranchAttr() { |
7447 | assert(odsAttrs && "no attributes when constructing adapter" ); |
7448 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 0, StatefulIfOp::getThenBranchAttrName(*odsOpName)).cast<::mlir::tf_type::FuncAttr>(); |
7449 | return attr; |
7450 | } |
7451 | |
7452 | ::mlir::tf_type::FuncAttr StatefulIfOpAdaptor::getThenBranch() { |
7453 | auto attr = getThenBranchAttr(); |
7454 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
7455 | } |
7456 | |
7457 | ::mlir::tf_type::FuncAttr StatefulIfOpAdaptor::then_branchAttr() { |
7458 | assert(odsAttrs && "no attributes when constructing adapter" ); |
7459 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 0, StatefulIfOp::getThenBranchAttrName(*odsOpName)).cast<::mlir::tf_type::FuncAttr>(); |
7460 | return attr; |
7461 | } |
7462 | |
7463 | ::mlir::tf_type::FuncAttr StatefulIfOpAdaptor::then_branch() { |
7464 | auto attr = then_branchAttr(); |
7465 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
7466 | } |
7467 | |
7468 | ::mlir::tf_type::FuncAttr StatefulIfOpAdaptor::getElseBranchAttr() { |
7469 | assert(odsAttrs && "no attributes when constructing adapter" ); |
7470 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 1, StatefulIfOp::getElseBranchAttrName(*odsOpName)).cast<::mlir::tf_type::FuncAttr>(); |
7471 | return attr; |
7472 | } |
7473 | |
7474 | ::mlir::tf_type::FuncAttr StatefulIfOpAdaptor::getElseBranch() { |
7475 | auto attr = getElseBranchAttr(); |
7476 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
7477 | } |
7478 | |
7479 | ::mlir::tf_type::FuncAttr StatefulIfOpAdaptor::else_branchAttr() { |
7480 | assert(odsAttrs && "no attributes when constructing adapter" ); |
7481 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 1, StatefulIfOp::getElseBranchAttrName(*odsOpName)).cast<::mlir::tf_type::FuncAttr>(); |
7482 | return attr; |
7483 | } |
7484 | |
7485 | ::mlir::tf_type::FuncAttr StatefulIfOpAdaptor::else_branch() { |
7486 | auto attr = else_branchAttr(); |
7487 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
7488 | } |
7489 | |
7490 | ::mlir::TypeAttr StatefulIfOpAdaptor::getTcondAttr() { |
7491 | assert(odsAttrs && "no attributes when constructing adapter" ); |
7492 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, StatefulIfOp::getTcondAttrName(*odsOpName)).dyn_cast_or_null<::mlir::TypeAttr>(); |
7493 | return attr; |
7494 | } |
7495 | |
7496 | ::llvm::Optional<::mlir::Type> StatefulIfOpAdaptor::getTcond() { |
7497 | auto attr = getTcondAttr(); |
7498 | return attr ? ::llvm::Optional<::mlir::Type>(attr.getValue().cast<::mlir::Type>()) : (::llvm::None); |
7499 | } |
7500 | |
7501 | ::mlir::TypeAttr StatefulIfOpAdaptor::TcondAttr() { |
7502 | assert(odsAttrs && "no attributes when constructing adapter" ); |
7503 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, StatefulIfOp::getTcondAttrName(*odsOpName)).dyn_cast_or_null<::mlir::TypeAttr>(); |
7504 | return attr; |
7505 | } |
7506 | |
7507 | ::llvm::Optional<::mlir::Type> StatefulIfOpAdaptor::Tcond() { |
7508 | auto attr = TcondAttr(); |
7509 | return attr ? ::llvm::Optional<::mlir::Type>(attr.getValue().cast<::mlir::Type>()) : (::llvm::None); |
7510 | } |
7511 | |
7512 | ::mlir::ArrayAttr StatefulIfOpAdaptor::getTinAttr() { |
7513 | assert(odsAttrs && "no attributes when constructing adapter" ); |
7514 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, StatefulIfOp::getTinAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
7515 | return attr; |
7516 | } |
7517 | |
7518 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulIfOpAdaptor::getTin() { |
7519 | auto attr = getTinAttr(); |
7520 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
7521 | } |
7522 | |
7523 | ::mlir::ArrayAttr StatefulIfOpAdaptor::TinAttr() { |
7524 | assert(odsAttrs && "no attributes when constructing adapter" ); |
7525 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, StatefulIfOp::getTinAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
7526 | return attr; |
7527 | } |
7528 | |
7529 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulIfOpAdaptor::Tin() { |
7530 | auto attr = TinAttr(); |
7531 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
7532 | } |
7533 | |
7534 | ::mlir::ArrayAttr StatefulIfOpAdaptor::getToutAttr() { |
7535 | assert(odsAttrs && "no attributes when constructing adapter" ); |
7536 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, StatefulIfOp::getToutAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
7537 | return attr; |
7538 | } |
7539 | |
7540 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulIfOpAdaptor::getTout() { |
7541 | auto attr = getToutAttr(); |
7542 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
7543 | } |
7544 | |
7545 | ::mlir::ArrayAttr StatefulIfOpAdaptor::ToutAttr() { |
7546 | assert(odsAttrs && "no attributes when constructing adapter" ); |
7547 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, StatefulIfOp::getToutAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
7548 | return attr; |
7549 | } |
7550 | |
7551 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulIfOpAdaptor::Tout() { |
7552 | auto attr = ToutAttr(); |
7553 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
7554 | } |
7555 | |
7556 | ::mlir::ArrayAttr StatefulIfOpAdaptor::getOutputShapesAttr() { |
7557 | assert(odsAttrs && "no attributes when constructing adapter" ); |
7558 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 1, StatefulIfOp::getOutputShapesAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
7559 | return attr; |
7560 | } |
7561 | |
7562 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulIfOpAdaptor::getOutputShapes() { |
7563 | auto attr = getOutputShapesAttr(); |
7564 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
7565 | } |
7566 | |
7567 | ::mlir::ArrayAttr StatefulIfOpAdaptor::output_shapesAttr() { |
7568 | assert(odsAttrs && "no attributes when constructing adapter" ); |
7569 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 1, StatefulIfOp::getOutputShapesAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
7570 | return attr; |
7571 | } |
7572 | |
7573 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulIfOpAdaptor::output_shapes() { |
7574 | auto attr = output_shapesAttr(); |
7575 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
7576 | } |
7577 | |
7578 | ::mlir::LogicalResult StatefulIfOpAdaptor::verify(::mlir::Location loc) { |
7579 | auto namedAttrRange = odsAttrs; |
7580 | auto namedAttrIt = namedAttrRange.begin(); |
7581 | ::mlir::Attribute tblgen_else_branch; |
7582 | ::mlir::Attribute tblgen_Tcond; |
7583 | ::mlir::Attribute tblgen_Tin; |
7584 | ::mlir::Attribute tblgen_Tout; |
7585 | while (true) { |
7586 | if (namedAttrIt == namedAttrRange.end()) |
7587 | return emitError(loc, "'tfg.StatefulIf' op " "requires attribute 'else_branch'" ); |
7588 | if (namedAttrIt->getName() == StatefulIfOp::getElseBranchAttrName(*odsOpName)) { |
7589 | tblgen_else_branch = namedAttrIt->getValue(); |
7590 | break; |
7591 | } |
7592 | else if (namedAttrIt->getName() == StatefulIfOp::getTcondAttrName(*odsOpName)) { |
7593 | tblgen_Tcond = namedAttrIt->getValue(); |
7594 | } |
7595 | else if (namedAttrIt->getName() == StatefulIfOp::getTinAttrName(*odsOpName)) { |
7596 | tblgen_Tin = namedAttrIt->getValue(); |
7597 | } |
7598 | else if (namedAttrIt->getName() == StatefulIfOp::getToutAttrName(*odsOpName)) { |
7599 | tblgen_Tout = namedAttrIt->getValue(); |
7600 | } |
7601 | ++namedAttrIt; |
7602 | } |
7603 | ::mlir::Attribute tblgen_then_branch; |
7604 | ::mlir::Attribute tblgen_output_shapes; |
7605 | while (true) { |
7606 | if (namedAttrIt == namedAttrRange.end()) |
7607 | return emitError(loc, "'tfg.StatefulIf' op " "requires attribute 'then_branch'" ); |
7608 | if (namedAttrIt->getName() == StatefulIfOp::getThenBranchAttrName(*odsOpName)) { |
7609 | tblgen_then_branch = namedAttrIt->getValue(); |
7610 | break; |
7611 | } |
7612 | else if (namedAttrIt->getName() == StatefulIfOp::getOutputShapesAttrName(*odsOpName)) { |
7613 | tblgen_output_shapes = namedAttrIt->getValue(); |
7614 | } |
7615 | ++namedAttrIt; |
7616 | } |
7617 | |
7618 | if (tblgen_then_branch && !((tblgen_then_branch.isa<::mlir::tf_type::FuncAttr>()))) |
7619 | return emitError(loc, "'tfg.StatefulIf' op " "attribute 'then_branch' failed to satisfy constraint: Models the `AttrValue.value.func` proto attribute value as a pair of SymbolRef and DictionaryAttr" ); |
7620 | |
7621 | if (tblgen_else_branch && !((tblgen_else_branch.isa<::mlir::tf_type::FuncAttr>()))) |
7622 | return emitError(loc, "'tfg.StatefulIf' op " "attribute 'else_branch' failed to satisfy constraint: Models the `AttrValue.value.func` proto attribute value as a pair of SymbolRef and DictionaryAttr" ); |
7623 | |
7624 | if (tblgen_Tcond && !(((tblgen_Tcond.isa<::mlir::TypeAttr>())) && ((tblgen_Tcond.cast<::mlir::TypeAttr>().getValue().isa<::mlir::Type>())))) |
7625 | return emitError(loc, "'tfg.StatefulIf' op " "attribute 'Tcond' failed to satisfy constraint: any type attribute" ); |
7626 | |
7627 | if (tblgen_Tin && !(((tblgen_Tin.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_Tin.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && (((attr.isa<::mlir::TypeAttr>())) && ((attr.cast<::mlir::TypeAttr>().getValue().isa<::mlir::Type>()))); })))) |
7628 | return emitError(loc, "'tfg.StatefulIf' op " "attribute 'Tin' failed to satisfy constraint: type array attribute" ); |
7629 | |
7630 | if (tblgen_Tout && !(((tblgen_Tout.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_Tout.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && (((attr.isa<::mlir::TypeAttr>())) && ((attr.cast<::mlir::TypeAttr>().getValue().isa<::mlir::Type>()))); })))) |
7631 | return emitError(loc, "'tfg.StatefulIf' op " "attribute 'Tout' failed to satisfy constraint: type array attribute" ); |
7632 | |
7633 | if (tblgen_output_shapes && !(((tblgen_output_shapes.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_output_shapes.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && ((attr.isa<::mlir::tf_type::ShapeAttr>())); })))) |
7634 | return emitError(loc, "'tfg.StatefulIf' op " "attribute 'output_shapes' failed to satisfy constraint: An array of shapes." ); |
7635 | return ::mlir::success(); |
7636 | } |
7637 | |
7638 | void StatefulIfOp::getAsmResultNames(::mlir::OpAsmSetValueNameFn setNameFn) { |
7639 | auto resultGroup0 = getODSResults(0); |
7640 | if (!resultGroup0.empty()) |
7641 | setNameFn(*resultGroup0.begin(), "outs" ); |
7642 | auto resultGroup1 = getODSResults(1); |
7643 | if (!resultGroup1.empty()) |
7644 | setNameFn(*resultGroup1.begin(), "ctl" ); |
7645 | } |
7646 | |
7647 | std::pair<unsigned, unsigned> StatefulIfOp::getODSOperandIndexAndLength(unsigned index) { |
7648 | bool isVariadic[] = {false, true}; |
7649 | int prevVariadicCount = 0; |
7650 | for (unsigned i = 0; i < index; ++i) |
7651 | if (isVariadic[i]) ++prevVariadicCount; |
7652 | |
7653 | // Calculate how many dynamic values a static variadic operand corresponds to. |
7654 | // This assumes all static variadic operands have the same dynamic value count. |
7655 | int variadicSize = (getOperation()->getNumOperands() - 1) / 1; |
7656 | // `index` passed in as the parameter is the static index which counts each |
7657 | // operand (variadic or not) as size 1. So here for each previous static variadic |
7658 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
7659 | // value pack for this static operand starts. |
7660 | int start = index + (variadicSize - 1) * prevVariadicCount; |
7661 | int size = isVariadic[index] ? variadicSize : 1; |
7662 | return {start, size}; |
7663 | } |
7664 | |
7665 | ::mlir::Operation::operand_range StatefulIfOp::getODSOperands(unsigned index) { |
7666 | auto valueRange = getODSOperandIndexAndLength(index); |
7667 | return {std::next(getOperation()->operand_begin(), valueRange.first), |
7668 | std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; |
7669 | } |
7670 | |
7671 | ::mlir::Value StatefulIfOp::getCond() { |
7672 | return *getODSOperands(0).begin(); |
7673 | } |
7674 | |
7675 | ::mlir::Value StatefulIfOp::cond() { |
7676 | return *getODSOperands(0).begin(); |
7677 | } |
7678 | |
7679 | ::mlir::Operation::operand_range StatefulIfOp::getArgs() { |
7680 | return getODSOperands(1); |
7681 | } |
7682 | |
7683 | ::mlir::Operation::operand_range StatefulIfOp::args() { |
7684 | return getODSOperands(1); |
7685 | } |
7686 | |
7687 | ::mlir::MutableOperandRange StatefulIfOp::getCondMutable() { |
7688 | auto range = getODSOperandIndexAndLength(0); |
7689 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
7690 | return mutableRange; |
7691 | } |
7692 | |
7693 | ::mlir::MutableOperandRange StatefulIfOp::condMutable() { |
7694 | auto range = getODSOperandIndexAndLength(0); |
7695 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
7696 | return mutableRange; |
7697 | } |
7698 | |
7699 | ::mlir::MutableOperandRange StatefulIfOp::getArgsMutable() { |
7700 | auto range = getODSOperandIndexAndLength(1); |
7701 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
7702 | return mutableRange; |
7703 | } |
7704 | |
7705 | ::mlir::MutableOperandRange StatefulIfOp::argsMutable() { |
7706 | auto range = getODSOperandIndexAndLength(1); |
7707 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
7708 | return mutableRange; |
7709 | } |
7710 | |
7711 | std::pair<unsigned, unsigned> StatefulIfOp::getODSResultIndexAndLength(unsigned index) { |
7712 | bool isVariadic[] = {true, false}; |
7713 | int prevVariadicCount = 0; |
7714 | for (unsigned i = 0; i < index; ++i) |
7715 | if (isVariadic[i]) ++prevVariadicCount; |
7716 | |
7717 | // Calculate how many dynamic values a static variadic operand corresponds to. |
7718 | // This assumes all static variadic operands have the same dynamic value count. |
7719 | int variadicSize = (getOperation()->getNumResults() - 1) / 1; |
7720 | // `index` passed in as the parameter is the static index which counts each |
7721 | // operand (variadic or not) as size 1. So here for each previous static variadic |
7722 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
7723 | // value pack for this static operand starts. |
7724 | int start = index + (variadicSize - 1) * prevVariadicCount; |
7725 | int size = isVariadic[index] ? variadicSize : 1; |
7726 | return {start, size}; |
7727 | } |
7728 | |
7729 | ::mlir::Operation::result_range StatefulIfOp::getODSResults(unsigned index) { |
7730 | auto valueRange = getODSResultIndexAndLength(index); |
7731 | return {std::next(getOperation()->result_begin(), valueRange.first), |
7732 | std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; |
7733 | } |
7734 | |
7735 | ::mlir::Operation::result_range StatefulIfOp::getOuts() { |
7736 | return getODSResults(0); |
7737 | } |
7738 | |
7739 | ::mlir::Operation::result_range StatefulIfOp::outs() { |
7740 | return getODSResults(0); |
7741 | } |
7742 | |
7743 | ::mlir::TypedValue<::mlir::tf_type::ControlType> StatefulIfOp::getCtl() { |
7744 | return *getODSResults(1).begin(); |
7745 | } |
7746 | |
7747 | ::mlir::TypedValue<::mlir::tf_type::ControlType> StatefulIfOp::ctl() { |
7748 | return *getODSResults(1).begin(); |
7749 | } |
7750 | |
7751 | ::mlir::tf_type::FuncAttr StatefulIfOp::getThenBranchAttr() { |
7752 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getThenBranchAttrName()).cast<::mlir::tf_type::FuncAttr>(); |
7753 | } |
7754 | |
7755 | ::mlir::tf_type::FuncAttr StatefulIfOp::getThenBranch() { |
7756 | auto attr = getThenBranchAttr(); |
7757 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
7758 | } |
7759 | |
7760 | ::mlir::tf_type::FuncAttr StatefulIfOp::then_branchAttr() { |
7761 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getThenBranchAttrName()).cast<::mlir::tf_type::FuncAttr>(); |
7762 | } |
7763 | |
7764 | ::mlir::tf_type::FuncAttr StatefulIfOp::then_branch() { |
7765 | auto attr = then_branchAttr(); |
7766 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
7767 | } |
7768 | |
7769 | ::mlir::tf_type::FuncAttr StatefulIfOp::getElseBranchAttr() { |
7770 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getElseBranchAttrName()).cast<::mlir::tf_type::FuncAttr>(); |
7771 | } |
7772 | |
7773 | ::mlir::tf_type::FuncAttr StatefulIfOp::getElseBranch() { |
7774 | auto attr = getElseBranchAttr(); |
7775 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
7776 | } |
7777 | |
7778 | ::mlir::tf_type::FuncAttr StatefulIfOp::else_branchAttr() { |
7779 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getElseBranchAttrName()).cast<::mlir::tf_type::FuncAttr>(); |
7780 | } |
7781 | |
7782 | ::mlir::tf_type::FuncAttr StatefulIfOp::else_branch() { |
7783 | auto attr = else_branchAttr(); |
7784 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
7785 | } |
7786 | |
7787 | ::mlir::TypeAttr StatefulIfOp::getTcondAttr() { |
7788 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getTcondAttrName()).dyn_cast_or_null<::mlir::TypeAttr>(); |
7789 | } |
7790 | |
7791 | ::llvm::Optional<::mlir::Type> StatefulIfOp::getTcond() { |
7792 | auto attr = getTcondAttr(); |
7793 | return attr ? ::llvm::Optional<::mlir::Type>(attr.getValue().cast<::mlir::Type>()) : (::llvm::None); |
7794 | } |
7795 | |
7796 | ::mlir::TypeAttr StatefulIfOp::TcondAttr() { |
7797 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getTcondAttrName()).dyn_cast_or_null<::mlir::TypeAttr>(); |
7798 | } |
7799 | |
7800 | ::llvm::Optional<::mlir::Type> StatefulIfOp::Tcond() { |
7801 | auto attr = TcondAttr(); |
7802 | return attr ? ::llvm::Optional<::mlir::Type>(attr.getValue().cast<::mlir::Type>()) : (::llvm::None); |
7803 | } |
7804 | |
7805 | ::mlir::ArrayAttr StatefulIfOp::getTinAttr() { |
7806 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getTinAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
7807 | } |
7808 | |
7809 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulIfOp::getTin() { |
7810 | auto attr = getTinAttr(); |
7811 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
7812 | } |
7813 | |
7814 | ::mlir::ArrayAttr StatefulIfOp::TinAttr() { |
7815 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getTinAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
7816 | } |
7817 | |
7818 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulIfOp::Tin() { |
7819 | auto attr = TinAttr(); |
7820 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
7821 | } |
7822 | |
7823 | ::mlir::ArrayAttr StatefulIfOp::getToutAttr() { |
7824 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getToutAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
7825 | } |
7826 | |
7827 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulIfOp::getTout() { |
7828 | auto attr = getToutAttr(); |
7829 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
7830 | } |
7831 | |
7832 | ::mlir::ArrayAttr StatefulIfOp::ToutAttr() { |
7833 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getToutAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
7834 | } |
7835 | |
7836 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulIfOp::Tout() { |
7837 | auto attr = ToutAttr(); |
7838 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
7839 | } |
7840 | |
7841 | ::mlir::ArrayAttr StatefulIfOp::getOutputShapesAttr() { |
7842 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 1, getOutputShapesAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
7843 | } |
7844 | |
7845 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulIfOp::getOutputShapes() { |
7846 | auto attr = getOutputShapesAttr(); |
7847 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
7848 | } |
7849 | |
7850 | ::mlir::ArrayAttr StatefulIfOp::output_shapesAttr() { |
7851 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 1, getOutputShapesAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
7852 | } |
7853 | |
7854 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulIfOp::output_shapes() { |
7855 | auto attr = output_shapesAttr(); |
7856 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
7857 | } |
7858 | |
7859 | void StatefulIfOp::setThenBranchAttr(::mlir::tf_type::FuncAttr attr) { |
7860 | (*this)->setAttr(getThenBranchAttrName(), attr); |
7861 | } |
7862 | |
7863 | void StatefulIfOp::then_branchAttr(::mlir::tf_type::FuncAttr attr) { |
7864 | (*this)->setAttr(then_branchAttrName(), attr); |
7865 | } |
7866 | |
7867 | void StatefulIfOp::setElseBranchAttr(::mlir::tf_type::FuncAttr attr) { |
7868 | (*this)->setAttr(getElseBranchAttrName(), attr); |
7869 | } |
7870 | |
7871 | void StatefulIfOp::else_branchAttr(::mlir::tf_type::FuncAttr attr) { |
7872 | (*this)->setAttr(else_branchAttrName(), attr); |
7873 | } |
7874 | |
7875 | void StatefulIfOp::setTcondAttr(::mlir::TypeAttr attr) { |
7876 | (*this)->setAttr(getTcondAttrName(), attr); |
7877 | } |
7878 | |
7879 | void StatefulIfOp::TcondAttr(::mlir::TypeAttr attr) { |
7880 | (*this)->setAttr(TcondAttrName(), attr); |
7881 | } |
7882 | |
7883 | void StatefulIfOp::setTinAttr(::mlir::ArrayAttr attr) { |
7884 | (*this)->setAttr(getTinAttrName(), attr); |
7885 | } |
7886 | |
7887 | void StatefulIfOp::TinAttr(::mlir::ArrayAttr attr) { |
7888 | (*this)->setAttr(TinAttrName(), attr); |
7889 | } |
7890 | |
7891 | void StatefulIfOp::setToutAttr(::mlir::ArrayAttr attr) { |
7892 | (*this)->setAttr(getToutAttrName(), attr); |
7893 | } |
7894 | |
7895 | void StatefulIfOp::ToutAttr(::mlir::ArrayAttr attr) { |
7896 | (*this)->setAttr(ToutAttrName(), attr); |
7897 | } |
7898 | |
7899 | void StatefulIfOp::setOutputShapesAttr(::mlir::ArrayAttr attr) { |
7900 | (*this)->setAttr(getOutputShapesAttrName(), attr); |
7901 | } |
7902 | |
7903 | void StatefulIfOp::output_shapesAttr(::mlir::ArrayAttr attr) { |
7904 | (*this)->setAttr(output_shapesAttrName(), attr); |
7905 | } |
7906 | |
7907 | ::mlir::Attribute StatefulIfOp::removeTcondAttr() { |
7908 | return (*this)->removeAttr(getTcondAttrName()); |
7909 | } |
7910 | |
7911 | ::mlir::Attribute StatefulIfOp::removeTinAttr() { |
7912 | return (*this)->removeAttr(getTinAttrName()); |
7913 | } |
7914 | |
7915 | ::mlir::Attribute StatefulIfOp::removeToutAttr() { |
7916 | return (*this)->removeAttr(getToutAttrName()); |
7917 | } |
7918 | |
7919 | ::mlir::Attribute StatefulIfOp::removeOutput_shapesAttr() { |
7920 | return (*this)->removeAttr(getOutputShapesAttrName()); |
7921 | } |
7922 | |
7923 | void StatefulIfOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, TypeRange results, Value cond, ValueRange args, FuncAttr then_branch, FuncAttr else_branch) { |
7924 | build(odsBuilder, odsState, results, cond, args, then_branch, else_branch, |
7925 | /*Tcond=*/{}, /*Tin=*/{}, /*Tout=*/{}, /*output_shapes=*/{}); |
7926 | |
7927 | } |
7928 | |
7929 | void StatefulIfOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange outs, ::mlir::Type ctl, ::mlir::Value cond, ::mlir::ValueRange args, ::mlir::tf_type::FuncAttr then_branch, ::mlir::tf_type::FuncAttr else_branch, /*optional*/::mlir::TypeAttr Tcond, /*optional*/::mlir::ArrayAttr Tin, /*optional*/::mlir::ArrayAttr Tout, /*optional*/::mlir::ArrayAttr output_shapes) { |
7930 | odsState.addOperands(cond); |
7931 | odsState.addOperands(args); |
7932 | odsState.addAttribute(getThenBranchAttrName(odsState.name), then_branch); |
7933 | odsState.addAttribute(getElseBranchAttrName(odsState.name), else_branch); |
7934 | if (Tcond) { |
7935 | odsState.addAttribute(getTcondAttrName(odsState.name), Tcond); |
7936 | } |
7937 | if (Tin) { |
7938 | odsState.addAttribute(getTinAttrName(odsState.name), Tin); |
7939 | } |
7940 | if (Tout) { |
7941 | odsState.addAttribute(getToutAttrName(odsState.name), Tout); |
7942 | } |
7943 | if (output_shapes) { |
7944 | odsState.addAttribute(getOutputShapesAttrName(odsState.name), output_shapes); |
7945 | } |
7946 | odsState.addTypes(outs); |
7947 | odsState.addTypes(ctl); |
7948 | } |
7949 | |
7950 | void StatefulIfOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value cond, ::mlir::ValueRange args, ::mlir::tf_type::FuncAttr then_branch, ::mlir::tf_type::FuncAttr else_branch, /*optional*/::mlir::TypeAttr Tcond, /*optional*/::mlir::ArrayAttr Tin, /*optional*/::mlir::ArrayAttr Tout, /*optional*/::mlir::ArrayAttr output_shapes) { |
7951 | odsState.addOperands(cond); |
7952 | odsState.addOperands(args); |
7953 | odsState.addAttribute(getThenBranchAttrName(odsState.name), then_branch); |
7954 | odsState.addAttribute(getElseBranchAttrName(odsState.name), else_branch); |
7955 | if (Tcond) { |
7956 | odsState.addAttribute(getTcondAttrName(odsState.name), Tcond); |
7957 | } |
7958 | if (Tin) { |
7959 | odsState.addAttribute(getTinAttrName(odsState.name), Tin); |
7960 | } |
7961 | if (Tout) { |
7962 | odsState.addAttribute(getToutAttrName(odsState.name), Tout); |
7963 | } |
7964 | if (output_shapes) { |
7965 | odsState.addAttribute(getOutputShapesAttrName(odsState.name), output_shapes); |
7966 | } |
7967 | assert(resultTypes.size() >= 1u && "mismatched number of results" ); |
7968 | odsState.addTypes(resultTypes); |
7969 | } |
7970 | |
7971 | void StatefulIfOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { |
7972 | assert(operands.size() >= 1u && "mismatched number of parameters" ); |
7973 | odsState.addOperands(operands); |
7974 | odsState.addAttributes(attributes); |
7975 | assert(resultTypes.size() >= 1u && "mismatched number of return types" ); |
7976 | odsState.addTypes(resultTypes); |
7977 | } |
7978 | |
7979 | ::mlir::LogicalResult StatefulIfOp::verifyInvariantsImpl() { |
7980 | auto namedAttrRange = (*this)->getAttrs(); |
7981 | auto namedAttrIt = namedAttrRange.begin(); |
7982 | ::mlir::Attribute tblgen_else_branch; |
7983 | ::mlir::Attribute tblgen_Tcond; |
7984 | ::mlir::Attribute tblgen_Tin; |
7985 | ::mlir::Attribute tblgen_Tout; |
7986 | while (true) { |
7987 | if (namedAttrIt == namedAttrRange.end()) |
7988 | return emitOpError("requires attribute 'else_branch'" ); |
7989 | if (namedAttrIt->getName() == getElseBranchAttrName()) { |
7990 | tblgen_else_branch = namedAttrIt->getValue(); |
7991 | break; |
7992 | } |
7993 | else if (namedAttrIt->getName() == getTcondAttrName()) { |
7994 | tblgen_Tcond = namedAttrIt->getValue(); |
7995 | } |
7996 | else if (namedAttrIt->getName() == getTinAttrName()) { |
7997 | tblgen_Tin = namedAttrIt->getValue(); |
7998 | } |
7999 | else if (namedAttrIt->getName() == getToutAttrName()) { |
8000 | tblgen_Tout = namedAttrIt->getValue(); |
8001 | } |
8002 | ++namedAttrIt; |
8003 | } |
8004 | ::mlir::Attribute tblgen_then_branch; |
8005 | ::mlir::Attribute tblgen_output_shapes; |
8006 | while (true) { |
8007 | if (namedAttrIt == namedAttrRange.end()) |
8008 | return emitOpError("requires attribute 'then_branch'" ); |
8009 | if (namedAttrIt->getName() == getThenBranchAttrName()) { |
8010 | tblgen_then_branch = namedAttrIt->getValue(); |
8011 | break; |
8012 | } |
8013 | else if (namedAttrIt->getName() == getOutputShapesAttrName()) { |
8014 | tblgen_output_shapes = namedAttrIt->getValue(); |
8015 | } |
8016 | ++namedAttrIt; |
8017 | } |
8018 | |
8019 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops5(*this, tblgen_then_branch, "then_branch" ))) |
8020 | return ::mlir::failure(); |
8021 | |
8022 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops5(*this, tblgen_else_branch, "else_branch" ))) |
8023 | return ::mlir::failure(); |
8024 | |
8025 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops17(*this, tblgen_Tcond, "Tcond" ))) |
8026 | return ::mlir::failure(); |
8027 | |
8028 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops1(*this, tblgen_Tin, "Tin" ))) |
8029 | return ::mlir::failure(); |
8030 | |
8031 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops1(*this, tblgen_Tout, "Tout" ))) |
8032 | return ::mlir::failure(); |
8033 | |
8034 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops2(*this, tblgen_output_shapes, "output_shapes" ))) |
8035 | return ::mlir::failure(); |
8036 | { |
8037 | unsigned index = 0; (void)index; |
8038 | auto valueGroup0 = getODSOperands(0); |
8039 | |
8040 | for (auto v : valueGroup0) { |
8041 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops7(*this, v.getType(), "operand" , index++))) |
8042 | return ::mlir::failure(); |
8043 | } |
8044 | auto valueGroup1 = getODSOperands(1); |
8045 | |
8046 | for (auto v : valueGroup1) { |
8047 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops1(*this, v.getType(), "operand" , index++))) |
8048 | return ::mlir::failure(); |
8049 | } |
8050 | } |
8051 | { |
8052 | unsigned index = 0; (void)index; |
8053 | auto valueGroup0 = getODSResults(0); |
8054 | |
8055 | for (auto v : valueGroup0) { |
8056 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops2(*this, v.getType(), "result" , index++))) |
8057 | return ::mlir::failure(); |
8058 | } |
8059 | auto valueGroup1 = getODSResults(1); |
8060 | |
8061 | for (auto v : valueGroup1) { |
8062 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops3(*this, v.getType(), "result" , index++))) |
8063 | return ::mlir::failure(); |
8064 | } |
8065 | } |
8066 | return ::mlir::success(); |
8067 | } |
8068 | |
8069 | ::mlir::LogicalResult StatefulIfOp::verifyInvariants() { |
8070 | return verifyInvariantsImpl(); |
8071 | } |
8072 | |
8073 | LogicalResult StatefulIfOp::verifySymbolUses( |
8074 | SymbolTableCollection &symbol_table) { |
8075 | return VerifyIfLikeOp(*this, symbol_table); |
8076 | } |
8077 | } // namespace tfg |
8078 | } // namespace mlir |
8079 | MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::tfg::StatefulIfOp) |
8080 | |
8081 | namespace mlir { |
8082 | namespace tfg { |
8083 | |
8084 | //===----------------------------------------------------------------------===// |
8085 | // ::mlir::tfg::StatefulIfRegionOp definitions |
8086 | //===----------------------------------------------------------------------===// |
8087 | |
8088 | StatefulIfRegionOpAdaptor::StatefulIfRegionOpAdaptor(::mlir::ValueRange values, ::mlir::DictionaryAttr attrs, ::mlir::RegionRange regions) : odsOperands(values), odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) |
8089 | odsOpName.emplace("tfg.StatefulIfRegion" , odsAttrs.getContext()); |
8090 | } |
8091 | |
8092 | StatefulIfRegionOpAdaptor::StatefulIfRegionOpAdaptor(StatefulIfRegionOp op) : odsOperands(op->getOperands()), odsAttrs(op->getAttrDictionary()), odsRegions(op->getRegions()), odsOpName(op->getName()) {} |
8093 | |
8094 | ::mlir::ValueRange StatefulIfRegionOpAdaptor::getOperands() { |
8095 | return odsOperands; |
8096 | } |
8097 | |
8098 | std::pair<unsigned, unsigned> StatefulIfRegionOpAdaptor::getODSOperandIndexAndLength(unsigned index) { |
8099 | bool isVariadic[] = {false, true}; |
8100 | int prevVariadicCount = 0; |
8101 | for (unsigned i = 0; i < index; ++i) |
8102 | if (isVariadic[i]) ++prevVariadicCount; |
8103 | |
8104 | // Calculate how many dynamic values a static variadic operand corresponds to. |
8105 | // This assumes all static variadic operands have the same dynamic value count. |
8106 | int variadicSize = (odsOperands.size() - 1) / 1; |
8107 | // `index` passed in as the parameter is the static index which counts each |
8108 | // operand (variadic or not) as size 1. So here for each previous static variadic |
8109 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
8110 | // value pack for this static operand starts. |
8111 | int start = index + (variadicSize - 1) * prevVariadicCount; |
8112 | int size = isVariadic[index] ? variadicSize : 1; |
8113 | return {start, size}; |
8114 | } |
8115 | |
8116 | ::mlir::ValueRange StatefulIfRegionOpAdaptor::getODSOperands(unsigned index) { |
8117 | auto valueRange = getODSOperandIndexAndLength(index); |
8118 | return {std::next(odsOperands.begin(), valueRange.first), |
8119 | std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; |
8120 | } |
8121 | |
8122 | ::mlir::Value StatefulIfRegionOpAdaptor::getCond() { |
8123 | return *getODSOperands(0).begin(); |
8124 | } |
8125 | |
8126 | ::mlir::Value StatefulIfRegionOpAdaptor::cond() { |
8127 | return *getODSOperands(0).begin(); |
8128 | } |
8129 | |
8130 | ::mlir::ValueRange StatefulIfRegionOpAdaptor::getCtls() { |
8131 | return getODSOperands(1); |
8132 | } |
8133 | |
8134 | ::mlir::ValueRange StatefulIfRegionOpAdaptor::ctls() { |
8135 | return getODSOperands(1); |
8136 | } |
8137 | |
8138 | ::mlir::DictionaryAttr StatefulIfRegionOpAdaptor::getAttributes() { |
8139 | return odsAttrs; |
8140 | } |
8141 | |
8142 | ::mlir::DictionaryAttr StatefulIfRegionOpAdaptor::getThenAttrsAttr() { |
8143 | assert(odsAttrs && "no attributes when constructing adapter" ); |
8144 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, StatefulIfRegionOp::getThenAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
8145 | return attr; |
8146 | } |
8147 | |
8148 | ::llvm::Optional< ::mlir::DictionaryAttr > StatefulIfRegionOpAdaptor::getThenAttrs() { |
8149 | auto attr = getThenAttrsAttr(); |
8150 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
8151 | } |
8152 | |
8153 | ::mlir::DictionaryAttr StatefulIfRegionOpAdaptor::then_attrsAttr() { |
8154 | assert(odsAttrs && "no attributes when constructing adapter" ); |
8155 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, StatefulIfRegionOp::getThenAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
8156 | return attr; |
8157 | } |
8158 | |
8159 | ::llvm::Optional< ::mlir::DictionaryAttr > StatefulIfRegionOpAdaptor::then_attrs() { |
8160 | auto attr = then_attrsAttr(); |
8161 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
8162 | } |
8163 | |
8164 | ::mlir::DictionaryAttr StatefulIfRegionOpAdaptor::getElseAttrsAttr() { |
8165 | assert(odsAttrs && "no attributes when constructing adapter" ); |
8166 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, StatefulIfRegionOp::getElseAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
8167 | return attr; |
8168 | } |
8169 | |
8170 | ::llvm::Optional< ::mlir::DictionaryAttr > StatefulIfRegionOpAdaptor::getElseAttrs() { |
8171 | auto attr = getElseAttrsAttr(); |
8172 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
8173 | } |
8174 | |
8175 | ::mlir::DictionaryAttr StatefulIfRegionOpAdaptor::else_attrsAttr() { |
8176 | assert(odsAttrs && "no attributes when constructing adapter" ); |
8177 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, StatefulIfRegionOp::getElseAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
8178 | return attr; |
8179 | } |
8180 | |
8181 | ::llvm::Optional< ::mlir::DictionaryAttr > StatefulIfRegionOpAdaptor::else_attrs() { |
8182 | auto attr = else_attrsAttr(); |
8183 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
8184 | } |
8185 | |
8186 | ::mlir::tfg::RegionAttr StatefulIfRegionOpAdaptor::getThenRegionAttrsAttr() { |
8187 | assert(odsAttrs && "no attributes when constructing adapter" ); |
8188 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, StatefulIfRegionOp::getThenRegionAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
8189 | return attr; |
8190 | } |
8191 | |
8192 | ::llvm::Optional<::mlir::tfg::RegionAttr> StatefulIfRegionOpAdaptor::getThenRegionAttrs() { |
8193 | auto attr = getThenRegionAttrsAttr(); |
8194 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
8195 | } |
8196 | |
8197 | ::mlir::tfg::RegionAttr StatefulIfRegionOpAdaptor::then_region_attrsAttr() { |
8198 | assert(odsAttrs && "no attributes when constructing adapter" ); |
8199 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, StatefulIfRegionOp::getThenRegionAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
8200 | return attr; |
8201 | } |
8202 | |
8203 | ::llvm::Optional<::mlir::tfg::RegionAttr> StatefulIfRegionOpAdaptor::then_region_attrs() { |
8204 | auto attr = then_region_attrsAttr(); |
8205 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
8206 | } |
8207 | |
8208 | ::mlir::tfg::RegionAttr StatefulIfRegionOpAdaptor::getElseRegionAttrsAttr() { |
8209 | assert(odsAttrs && "no attributes when constructing adapter" ); |
8210 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, StatefulIfRegionOp::getElseRegionAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
8211 | return attr; |
8212 | } |
8213 | |
8214 | ::llvm::Optional<::mlir::tfg::RegionAttr> StatefulIfRegionOpAdaptor::getElseRegionAttrs() { |
8215 | auto attr = getElseRegionAttrsAttr(); |
8216 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
8217 | } |
8218 | |
8219 | ::mlir::tfg::RegionAttr StatefulIfRegionOpAdaptor::else_region_attrsAttr() { |
8220 | assert(odsAttrs && "no attributes when constructing adapter" ); |
8221 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, StatefulIfRegionOp::getElseRegionAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
8222 | return attr; |
8223 | } |
8224 | |
8225 | ::llvm::Optional<::mlir::tfg::RegionAttr> StatefulIfRegionOpAdaptor::else_region_attrs() { |
8226 | auto attr = else_region_attrsAttr(); |
8227 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
8228 | } |
8229 | |
8230 | ::mlir::RegionRange StatefulIfRegionOpAdaptor::getRegions() { |
8231 | return odsRegions; |
8232 | } |
8233 | |
8234 | ::mlir::Region &StatefulIfRegionOpAdaptor::getThenRegion() { |
8235 | return *odsRegions[0]; |
8236 | } |
8237 | |
8238 | ::mlir::Region &StatefulIfRegionOpAdaptor::then_region() { |
8239 | return *odsRegions[0]; |
8240 | } |
8241 | |
8242 | ::mlir::Region &StatefulIfRegionOpAdaptor::getElseRegion() { |
8243 | return *odsRegions[1]; |
8244 | } |
8245 | |
8246 | ::mlir::Region &StatefulIfRegionOpAdaptor::else_region() { |
8247 | return *odsRegions[1]; |
8248 | } |
8249 | |
8250 | ::mlir::LogicalResult StatefulIfRegionOpAdaptor::verify(::mlir::Location loc) { |
8251 | auto namedAttrRange = odsAttrs; |
8252 | auto namedAttrIt = namedAttrRange.begin(); |
8253 | ::mlir::Attribute tblgen_else_attrs; |
8254 | ::mlir::Attribute tblgen_else_region_attrs; |
8255 | ::mlir::Attribute tblgen_then_attrs; |
8256 | ::mlir::Attribute tblgen_then_region_attrs; |
8257 | while (true) { |
8258 | if (namedAttrIt == namedAttrRange.end()) { |
8259 | break; |
8260 | } |
8261 | else if (namedAttrIt->getName() == StatefulIfRegionOp::getElseAttrsAttrName(*odsOpName)) { |
8262 | tblgen_else_attrs = namedAttrIt->getValue(); |
8263 | } |
8264 | else if (namedAttrIt->getName() == StatefulIfRegionOp::getElseRegionAttrsAttrName(*odsOpName)) { |
8265 | tblgen_else_region_attrs = namedAttrIt->getValue(); |
8266 | } |
8267 | else if (namedAttrIt->getName() == StatefulIfRegionOp::getThenAttrsAttrName(*odsOpName)) { |
8268 | tblgen_then_attrs = namedAttrIt->getValue(); |
8269 | } |
8270 | else if (namedAttrIt->getName() == StatefulIfRegionOp::getThenRegionAttrsAttrName(*odsOpName)) { |
8271 | tblgen_then_region_attrs = namedAttrIt->getValue(); |
8272 | } |
8273 | ++namedAttrIt; |
8274 | } |
8275 | |
8276 | if (tblgen_then_attrs && !((tblgen_then_attrs.isa<::mlir::DictionaryAttr>()))) |
8277 | return emitError(loc, "'tfg.StatefulIfRegion' op " "attribute 'then_attrs' failed to satisfy constraint: dictionary of named attribute values" ); |
8278 | |
8279 | if (tblgen_else_attrs && !((tblgen_else_attrs.isa<::mlir::DictionaryAttr>()))) |
8280 | return emitError(loc, "'tfg.StatefulIfRegion' op " "attribute 'else_attrs' failed to satisfy constraint: dictionary of named attribute values" ); |
8281 | |
8282 | if (tblgen_then_region_attrs && !((tblgen_then_region_attrs.isa<::mlir::tfg::RegionAttr>()))) |
8283 | return emitError(loc, "'tfg.StatefulIfRegion' op " "attribute 'then_region_attrs' failed to satisfy constraint: Region attributes, argument and result attributes." ); |
8284 | |
8285 | if (tblgen_else_region_attrs && !((tblgen_else_region_attrs.isa<::mlir::tfg::RegionAttr>()))) |
8286 | return emitError(loc, "'tfg.StatefulIfRegion' op " "attribute 'else_region_attrs' failed to satisfy constraint: Region attributes, argument and result attributes." ); |
8287 | return ::mlir::success(); |
8288 | } |
8289 | |
8290 | std::pair<unsigned, unsigned> StatefulIfRegionOp::getODSOperandIndexAndLength(unsigned index) { |
8291 | bool isVariadic[] = {false, true}; |
8292 | int prevVariadicCount = 0; |
8293 | for (unsigned i = 0; i < index; ++i) |
8294 | if (isVariadic[i]) ++prevVariadicCount; |
8295 | |
8296 | // Calculate how many dynamic values a static variadic operand corresponds to. |
8297 | // This assumes all static variadic operands have the same dynamic value count. |
8298 | int variadicSize = (getOperation()->getNumOperands() - 1) / 1; |
8299 | // `index` passed in as the parameter is the static index which counts each |
8300 | // operand (variadic or not) as size 1. So here for each previous static variadic |
8301 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
8302 | // value pack for this static operand starts. |
8303 | int start = index + (variadicSize - 1) * prevVariadicCount; |
8304 | int size = isVariadic[index] ? variadicSize : 1; |
8305 | return {start, size}; |
8306 | } |
8307 | |
8308 | ::mlir::Operation::operand_range StatefulIfRegionOp::getODSOperands(unsigned index) { |
8309 | auto valueRange = getODSOperandIndexAndLength(index); |
8310 | return {std::next(getOperation()->operand_begin(), valueRange.first), |
8311 | std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; |
8312 | } |
8313 | |
8314 | ::mlir::TypedValue<::mlir::TensorType> StatefulIfRegionOp::getCond() { |
8315 | return *getODSOperands(0).begin(); |
8316 | } |
8317 | |
8318 | ::mlir::TypedValue<::mlir::TensorType> StatefulIfRegionOp::cond() { |
8319 | return *getODSOperands(0).begin(); |
8320 | } |
8321 | |
8322 | ::mlir::Operation::operand_range StatefulIfRegionOp::getCtls() { |
8323 | return getODSOperands(1); |
8324 | } |
8325 | |
8326 | ::mlir::Operation::operand_range StatefulIfRegionOp::ctls() { |
8327 | return getODSOperands(1); |
8328 | } |
8329 | |
8330 | ::mlir::MutableOperandRange StatefulIfRegionOp::getCondMutable() { |
8331 | auto range = getODSOperandIndexAndLength(0); |
8332 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
8333 | return mutableRange; |
8334 | } |
8335 | |
8336 | ::mlir::MutableOperandRange StatefulIfRegionOp::condMutable() { |
8337 | auto range = getODSOperandIndexAndLength(0); |
8338 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
8339 | return mutableRange; |
8340 | } |
8341 | |
8342 | ::mlir::MutableOperandRange StatefulIfRegionOp::getCtlsMutable() { |
8343 | auto range = getODSOperandIndexAndLength(1); |
8344 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
8345 | return mutableRange; |
8346 | } |
8347 | |
8348 | ::mlir::MutableOperandRange StatefulIfRegionOp::ctlsMutable() { |
8349 | auto range = getODSOperandIndexAndLength(1); |
8350 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
8351 | return mutableRange; |
8352 | } |
8353 | |
8354 | std::pair<unsigned, unsigned> StatefulIfRegionOp::getODSResultIndexAndLength(unsigned index) { |
8355 | bool isVariadic[] = {true, false}; |
8356 | int prevVariadicCount = 0; |
8357 | for (unsigned i = 0; i < index; ++i) |
8358 | if (isVariadic[i]) ++prevVariadicCount; |
8359 | |
8360 | // Calculate how many dynamic values a static variadic operand corresponds to. |
8361 | // This assumes all static variadic operands have the same dynamic value count. |
8362 | int variadicSize = (getOperation()->getNumResults() - 1) / 1; |
8363 | // `index` passed in as the parameter is the static index which counts each |
8364 | // operand (variadic or not) as size 1. So here for each previous static variadic |
8365 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
8366 | // value pack for this static operand starts. |
8367 | int start = index + (variadicSize - 1) * prevVariadicCount; |
8368 | int size = isVariadic[index] ? variadicSize : 1; |
8369 | return {start, size}; |
8370 | } |
8371 | |
8372 | ::mlir::Operation::result_range StatefulIfRegionOp::getODSResults(unsigned index) { |
8373 | auto valueRange = getODSResultIndexAndLength(index); |
8374 | return {std::next(getOperation()->result_begin(), valueRange.first), |
8375 | std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; |
8376 | } |
8377 | |
8378 | ::mlir::Operation::result_range StatefulIfRegionOp::getOuts() { |
8379 | return getODSResults(0); |
8380 | } |
8381 | |
8382 | ::mlir::Operation::result_range StatefulIfRegionOp::outs() { |
8383 | return getODSResults(0); |
8384 | } |
8385 | |
8386 | ::mlir::TypedValue<::mlir::tf_type::ControlType> StatefulIfRegionOp::getCtl() { |
8387 | return *getODSResults(1).begin(); |
8388 | } |
8389 | |
8390 | ::mlir::TypedValue<::mlir::tf_type::ControlType> StatefulIfRegionOp::ctl() { |
8391 | return *getODSResults(1).begin(); |
8392 | } |
8393 | |
8394 | ::mlir::Region &StatefulIfRegionOp::getThenRegion() { |
8395 | return (*this)->getRegion(0); |
8396 | } |
8397 | |
8398 | ::mlir::Region &StatefulIfRegionOp::then_region() { |
8399 | return (*this)->getRegion(0); |
8400 | } |
8401 | |
8402 | ::mlir::Region &StatefulIfRegionOp::getElseRegion() { |
8403 | return (*this)->getRegion(1); |
8404 | } |
8405 | |
8406 | ::mlir::Region &StatefulIfRegionOp::else_region() { |
8407 | return (*this)->getRegion(1); |
8408 | } |
8409 | |
8410 | ::mlir::DictionaryAttr StatefulIfRegionOp::getThenAttrsAttr() { |
8411 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getThenAttrsAttrName()).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
8412 | } |
8413 | |
8414 | ::llvm::Optional< ::mlir::DictionaryAttr > StatefulIfRegionOp::getThenAttrs() { |
8415 | auto attr = getThenAttrsAttr(); |
8416 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
8417 | } |
8418 | |
8419 | ::mlir::DictionaryAttr StatefulIfRegionOp::then_attrsAttr() { |
8420 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getThenAttrsAttrName()).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
8421 | } |
8422 | |
8423 | ::llvm::Optional< ::mlir::DictionaryAttr > StatefulIfRegionOp::then_attrs() { |
8424 | auto attr = then_attrsAttr(); |
8425 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
8426 | } |
8427 | |
8428 | ::mlir::DictionaryAttr StatefulIfRegionOp::getElseAttrsAttr() { |
8429 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getElseAttrsAttrName()).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
8430 | } |
8431 | |
8432 | ::llvm::Optional< ::mlir::DictionaryAttr > StatefulIfRegionOp::getElseAttrs() { |
8433 | auto attr = getElseAttrsAttr(); |
8434 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
8435 | } |
8436 | |
8437 | ::mlir::DictionaryAttr StatefulIfRegionOp::else_attrsAttr() { |
8438 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getElseAttrsAttrName()).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
8439 | } |
8440 | |
8441 | ::llvm::Optional< ::mlir::DictionaryAttr > StatefulIfRegionOp::else_attrs() { |
8442 | auto attr = else_attrsAttr(); |
8443 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
8444 | } |
8445 | |
8446 | ::mlir::tfg::RegionAttr StatefulIfRegionOp::getThenRegionAttrsAttr() { |
8447 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getThenRegionAttrsAttrName()).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
8448 | } |
8449 | |
8450 | ::llvm::Optional<::mlir::tfg::RegionAttr> StatefulIfRegionOp::getThenRegionAttrs() { |
8451 | auto attr = getThenRegionAttrsAttr(); |
8452 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
8453 | } |
8454 | |
8455 | ::mlir::tfg::RegionAttr StatefulIfRegionOp::then_region_attrsAttr() { |
8456 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getThenRegionAttrsAttrName()).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
8457 | } |
8458 | |
8459 | ::llvm::Optional<::mlir::tfg::RegionAttr> StatefulIfRegionOp::then_region_attrs() { |
8460 | auto attr = then_region_attrsAttr(); |
8461 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
8462 | } |
8463 | |
8464 | ::mlir::tfg::RegionAttr StatefulIfRegionOp::getElseRegionAttrsAttr() { |
8465 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getElseRegionAttrsAttrName()).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
8466 | } |
8467 | |
8468 | ::llvm::Optional<::mlir::tfg::RegionAttr> StatefulIfRegionOp::getElseRegionAttrs() { |
8469 | auto attr = getElseRegionAttrsAttr(); |
8470 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
8471 | } |
8472 | |
8473 | ::mlir::tfg::RegionAttr StatefulIfRegionOp::else_region_attrsAttr() { |
8474 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getElseRegionAttrsAttrName()).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
8475 | } |
8476 | |
8477 | ::llvm::Optional<::mlir::tfg::RegionAttr> StatefulIfRegionOp::else_region_attrs() { |
8478 | auto attr = else_region_attrsAttr(); |
8479 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
8480 | } |
8481 | |
8482 | void StatefulIfRegionOp::setThenAttrsAttr(::mlir::DictionaryAttr attr) { |
8483 | (*this)->setAttr(getThenAttrsAttrName(), attr); |
8484 | } |
8485 | |
8486 | void StatefulIfRegionOp::then_attrsAttr(::mlir::DictionaryAttr attr) { |
8487 | (*this)->setAttr(then_attrsAttrName(), attr); |
8488 | } |
8489 | |
8490 | void StatefulIfRegionOp::setElseAttrsAttr(::mlir::DictionaryAttr attr) { |
8491 | (*this)->setAttr(getElseAttrsAttrName(), attr); |
8492 | } |
8493 | |
8494 | void StatefulIfRegionOp::else_attrsAttr(::mlir::DictionaryAttr attr) { |
8495 | (*this)->setAttr(else_attrsAttrName(), attr); |
8496 | } |
8497 | |
8498 | void StatefulIfRegionOp::setThenRegionAttrsAttr(::mlir::tfg::RegionAttr attr) { |
8499 | (*this)->setAttr(getThenRegionAttrsAttrName(), attr); |
8500 | } |
8501 | |
8502 | void StatefulIfRegionOp::then_region_attrsAttr(::mlir::tfg::RegionAttr attr) { |
8503 | (*this)->setAttr(then_region_attrsAttrName(), attr); |
8504 | } |
8505 | |
8506 | void StatefulIfRegionOp::setElseRegionAttrsAttr(::mlir::tfg::RegionAttr attr) { |
8507 | (*this)->setAttr(getElseRegionAttrsAttrName(), attr); |
8508 | } |
8509 | |
8510 | void StatefulIfRegionOp::else_region_attrsAttr(::mlir::tfg::RegionAttr attr) { |
8511 | (*this)->setAttr(else_region_attrsAttrName(), attr); |
8512 | } |
8513 | |
8514 | ::mlir::Attribute StatefulIfRegionOp::removeThen_attrsAttr() { |
8515 | return (*this)->removeAttr(getThenAttrsAttrName()); |
8516 | } |
8517 | |
8518 | ::mlir::Attribute StatefulIfRegionOp::removeElse_attrsAttr() { |
8519 | return (*this)->removeAttr(getElseAttrsAttrName()); |
8520 | } |
8521 | |
8522 | ::mlir::Attribute StatefulIfRegionOp::removeThen_region_attrsAttr() { |
8523 | return (*this)->removeAttr(getThenRegionAttrsAttrName()); |
8524 | } |
8525 | |
8526 | ::mlir::Attribute StatefulIfRegionOp::removeElse_region_attrsAttr() { |
8527 | return (*this)->removeAttr(getElseRegionAttrsAttrName()); |
8528 | } |
8529 | |
8530 | void StatefulIfRegionOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange outs, ::mlir::Type ctl, ::mlir::Value cond, ::mlir::ValueRange ctls, /*optional*/::mlir::DictionaryAttr then_attrs, /*optional*/::mlir::DictionaryAttr else_attrs, /*optional*/::mlir::tfg::RegionAttr then_region_attrs, /*optional*/::mlir::tfg::RegionAttr else_region_attrs) { |
8531 | odsState.addOperands(cond); |
8532 | odsState.addOperands(ctls); |
8533 | if (then_attrs) { |
8534 | odsState.addAttribute(getThenAttrsAttrName(odsState.name), then_attrs); |
8535 | } |
8536 | if (else_attrs) { |
8537 | odsState.addAttribute(getElseAttrsAttrName(odsState.name), else_attrs); |
8538 | } |
8539 | if (then_region_attrs) { |
8540 | odsState.addAttribute(getThenRegionAttrsAttrName(odsState.name), then_region_attrs); |
8541 | } |
8542 | if (else_region_attrs) { |
8543 | odsState.addAttribute(getElseRegionAttrsAttrName(odsState.name), else_region_attrs); |
8544 | } |
8545 | (void)odsState.addRegion(); |
8546 | (void)odsState.addRegion(); |
8547 | odsState.addTypes(outs); |
8548 | odsState.addTypes(ctl); |
8549 | } |
8550 | |
8551 | void StatefulIfRegionOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value cond, ::mlir::ValueRange ctls, /*optional*/::mlir::DictionaryAttr then_attrs, /*optional*/::mlir::DictionaryAttr else_attrs, /*optional*/::mlir::tfg::RegionAttr then_region_attrs, /*optional*/::mlir::tfg::RegionAttr else_region_attrs) { |
8552 | odsState.addOperands(cond); |
8553 | odsState.addOperands(ctls); |
8554 | if (then_attrs) { |
8555 | odsState.addAttribute(getThenAttrsAttrName(odsState.name), then_attrs); |
8556 | } |
8557 | if (else_attrs) { |
8558 | odsState.addAttribute(getElseAttrsAttrName(odsState.name), else_attrs); |
8559 | } |
8560 | if (then_region_attrs) { |
8561 | odsState.addAttribute(getThenRegionAttrsAttrName(odsState.name), then_region_attrs); |
8562 | } |
8563 | if (else_region_attrs) { |
8564 | odsState.addAttribute(getElseRegionAttrsAttrName(odsState.name), else_region_attrs); |
8565 | } |
8566 | (void)odsState.addRegion(); |
8567 | (void)odsState.addRegion(); |
8568 | assert(resultTypes.size() >= 1u && "mismatched number of results" ); |
8569 | odsState.addTypes(resultTypes); |
8570 | } |
8571 | |
8572 | void StatefulIfRegionOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { |
8573 | assert(operands.size() >= 1u && "mismatched number of parameters" ); |
8574 | odsState.addOperands(operands); |
8575 | odsState.addAttributes(attributes); |
8576 | for (unsigned i = 0; i != 2; ++i) |
8577 | (void)odsState.addRegion(); |
8578 | assert(resultTypes.size() >= 1u && "mismatched number of return types" ); |
8579 | odsState.addTypes(resultTypes); |
8580 | } |
8581 | |
8582 | ::mlir::LogicalResult StatefulIfRegionOp::verifyInvariantsImpl() { |
8583 | auto namedAttrRange = (*this)->getAttrs(); |
8584 | auto namedAttrIt = namedAttrRange.begin(); |
8585 | ::mlir::Attribute tblgen_else_attrs; |
8586 | ::mlir::Attribute tblgen_else_region_attrs; |
8587 | ::mlir::Attribute tblgen_then_attrs; |
8588 | ::mlir::Attribute tblgen_then_region_attrs; |
8589 | while (true) { |
8590 | if (namedAttrIt == namedAttrRange.end()) { |
8591 | break; |
8592 | } |
8593 | else if (namedAttrIt->getName() == getElseAttrsAttrName()) { |
8594 | tblgen_else_attrs = namedAttrIt->getValue(); |
8595 | } |
8596 | else if (namedAttrIt->getName() == getElseRegionAttrsAttrName()) { |
8597 | tblgen_else_region_attrs = namedAttrIt->getValue(); |
8598 | } |
8599 | else if (namedAttrIt->getName() == getThenAttrsAttrName()) { |
8600 | tblgen_then_attrs = namedAttrIt->getValue(); |
8601 | } |
8602 | else if (namedAttrIt->getName() == getThenRegionAttrsAttrName()) { |
8603 | tblgen_then_region_attrs = namedAttrIt->getValue(); |
8604 | } |
8605 | ++namedAttrIt; |
8606 | } |
8607 | |
8608 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops6(*this, tblgen_then_attrs, "then_attrs" ))) |
8609 | return ::mlir::failure(); |
8610 | |
8611 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops6(*this, tblgen_else_attrs, "else_attrs" ))) |
8612 | return ::mlir::failure(); |
8613 | |
8614 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops7(*this, tblgen_then_region_attrs, "then_region_attrs" ))) |
8615 | return ::mlir::failure(); |
8616 | |
8617 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops7(*this, tblgen_else_region_attrs, "else_region_attrs" ))) |
8618 | return ::mlir::failure(); |
8619 | { |
8620 | unsigned index = 0; (void)index; |
8621 | auto valueGroup0 = getODSOperands(0); |
8622 | |
8623 | for (auto v : valueGroup0) { |
8624 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops5(*this, v.getType(), "operand" , index++))) |
8625 | return ::mlir::failure(); |
8626 | } |
8627 | auto valueGroup1 = getODSOperands(1); |
8628 | |
8629 | for (auto v : valueGroup1) { |
8630 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops3(*this, v.getType(), "operand" , index++))) |
8631 | return ::mlir::failure(); |
8632 | } |
8633 | } |
8634 | { |
8635 | unsigned index = 0; (void)index; |
8636 | auto valueGroup0 = getODSResults(0); |
8637 | |
8638 | for (auto v : valueGroup0) { |
8639 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops2(*this, v.getType(), "result" , index++))) |
8640 | return ::mlir::failure(); |
8641 | } |
8642 | auto valueGroup1 = getODSResults(1); |
8643 | |
8644 | for (auto v : valueGroup1) { |
8645 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops3(*this, v.getType(), "result" , index++))) |
8646 | return ::mlir::failure(); |
8647 | } |
8648 | } |
8649 | { |
8650 | unsigned index = 0; (void)index; |
8651 | |
8652 | for (auto ®ion : ::llvm::makeMutableArrayRef((*this)->getRegion(0))) |
8653 | if (::mlir::failed(__mlir_ods_local_region_constraint_ops0(*this, region, "then_region" , index++))) |
8654 | return ::mlir::failure(); |
8655 | |
8656 | for (auto ®ion : ::llvm::makeMutableArrayRef((*this)->getRegion(1))) |
8657 | if (::mlir::failed(__mlir_ods_local_region_constraint_ops0(*this, region, "else_region" , index++))) |
8658 | return ::mlir::failure(); |
8659 | } |
8660 | return ::mlir::success(); |
8661 | } |
8662 | |
8663 | ::mlir::LogicalResult StatefulIfRegionOp::verifyInvariants() { |
8664 | if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) |
8665 | return ::mlir::success(); |
8666 | return ::mlir::failure(); |
8667 | } |
8668 | |
8669 | ::mlir::ParseResult StatefulIfRegionOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { |
8670 | ::mlir::OpAsmParser::UnresolvedOperand condRawOperands[1]; |
8671 | ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> condOperands(condRawOperands); ::llvm::SMLoc condOperandsLoc; |
8672 | (void)condOperandsLoc; |
8673 | ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> ctlsOperands; |
8674 | ::llvm::SMLoc ctlsOperandsLoc; |
8675 | (void)ctlsOperandsLoc; |
8676 | std::unique_ptr<::mlir::Region> then_regionRegion = std::make_unique<::mlir::Region>(); |
8677 | std::unique_ptr<::mlir::Region> else_regionRegion = std::make_unique<::mlir::Region>(); |
8678 | ::llvm::ArrayRef<::mlir::Type> condTypes; |
8679 | ::llvm::ArrayRef<::mlir::Type> outsTypes; |
8680 | |
8681 | condOperandsLoc = parser.getCurrentLocation(); |
8682 | if (parser.parseOperand(condRawOperands[0])) |
8683 | return ::mlir::failure(); |
8684 | if (::mlir::succeeded(parser.parseOptionalLSquare())) { |
8685 | |
8686 | ctlsOperandsLoc = parser.getCurrentLocation(); |
8687 | if (parser.parseOperandList(ctlsOperands)) |
8688 | return ::mlir::failure(); |
8689 | if (parser.parseRSquare()) |
8690 | return ::mlir::failure(); |
8691 | } |
8692 | if (parser.parseKeyword("then" )) |
8693 | return ::mlir::failure(); |
8694 | |
8695 | if (parser.parseRegion(*then_regionRegion)) |
8696 | return ::mlir::failure(); |
8697 | |
8698 | if (then_regionRegion->empty()) then_regionRegion->emplaceBlock(); |
8699 | if (parser.parseKeyword("else" )) |
8700 | return ::mlir::failure(); |
8701 | |
8702 | if (parser.parseRegion(*else_regionRegion)) |
8703 | return ::mlir::failure(); |
8704 | |
8705 | if (else_regionRegion->empty()) else_regionRegion->emplaceBlock(); |
8706 | if (parser.parseOptionalAttrDict(result.attributes)) |
8707 | return ::mlir::failure(); |
8708 | if (parser.parseColon()) |
8709 | return ::mlir::failure(); |
8710 | |
8711 | ::mlir::FunctionType cond__outs_functionType; |
8712 | if (parser.parseType(cond__outs_functionType)) |
8713 | return ::mlir::failure(); |
8714 | condTypes = cond__outs_functionType.getInputs(); |
8715 | outsTypes = cond__outs_functionType.getResults(); |
8716 | result.addRegion(std::move(then_regionRegion)); |
8717 | result.addRegion(std::move(else_regionRegion)); |
8718 | ::mlir::Type odsBuildableType0 = parser.getBuilder().getType<::mlir::tf_type::ControlType>(); |
8719 | result.addTypes(outsTypes); |
8720 | result.addTypes(odsBuildableType0); |
8721 | if (parser.resolveOperands(condOperands, condTypes, condOperandsLoc, result.operands)) |
8722 | return ::mlir::failure(); |
8723 | if (parser.resolveOperands(ctlsOperands, odsBuildableType0, ctlsOperandsLoc, result.operands)) |
8724 | return ::mlir::failure(); |
8725 | return ::mlir::success(); |
8726 | } |
8727 | |
8728 | void StatefulIfRegionOp::print(::mlir::OpAsmPrinter &_odsPrinter) { |
8729 | _odsPrinter << ' '; |
8730 | _odsPrinter << getCond(); |
8731 | if (!getCtls().empty()) { |
8732 | _odsPrinter << ' '; |
8733 | _odsPrinter << "[" ; |
8734 | _odsPrinter << getCtls(); |
8735 | _odsPrinter << "]" ; |
8736 | } |
8737 | _odsPrinter << ' ' << "then" ; |
8738 | _odsPrinter << ' '; |
8739 | _odsPrinter.printRegion(getThenRegion()); |
8740 | _odsPrinter << ' ' << "else" ; |
8741 | _odsPrinter << ' '; |
8742 | _odsPrinter.printRegion(getElseRegion()); |
8743 | _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), /*elidedAttrs=*/{}); |
8744 | _odsPrinter << ' ' << ":" ; |
8745 | _odsPrinter << ' '; |
8746 | _odsPrinter.printFunctionalType(::llvm::ArrayRef<::mlir::Type>(getCond().getType()), getOuts().getTypes()); |
8747 | } |
8748 | |
8749 | StringRef StatefulIfRegionOp::getDefaultDialect() { return "tfg" ; } |
8750 | void StatefulIfRegionOp::getAsmResultNames(OpAsmSetValueNameFn setNameFn) { |
8751 | GenericGetAsmResultNames(*this, setNameFn); |
8752 | } |
8753 | |
8754 | YieldOp StatefulIfRegionOp::then_yield() { |
8755 | return cast<YieldOp>(then_block().getTerminator()); |
8756 | } |
8757 | YieldOp StatefulIfRegionOp::else_yield() { |
8758 | return cast<YieldOp>(else_block().getTerminator()); |
8759 | } |
8760 | |
8761 | void StatefulIfRegionOp::getSuccessorRegions( |
8762 | Optional<unsigned> index, ArrayRef<Attribute> operands, |
8763 | SmallVectorImpl<RegionSuccessor> ®ions) { |
8764 | GetIfLikeRegionOpSuccessorRegions(*this, index, operands, regions); |
8765 | } |
8766 | void StatefulIfRegionOp::getRegionInvocationBounds( |
8767 | ArrayRef<Attribute> operands, |
8768 | SmallVectorImpl<InvocationBounds> &invocationBounds) { |
8769 | invocationBounds.append(/*NumInputs=*/2, /*Elt=*/{0, 1}); |
8770 | } |
8771 | |
8772 | LogicalResult StatefulIfRegionOp::verify() { return VerifyIfLikeRegionOp(*this); } |
8773 | |
8774 | BlockArgument StatefulIfRegionOp::getDataValueOf(BlockArgument ctl) { |
8775 | return GetLoopRegionDataOf(ctl); |
8776 | } |
8777 | BlockArgument StatefulIfRegionOp::getControlTokenOf(BlockArgument data) { |
8778 | return GetLoopRegionControlOf(data); |
8779 | } |
8780 | BlockArgument StatefulIfRegionOp::getDataValue(Region ®ion, unsigned idx) { |
8781 | return GetLoopRegionDataArgs(region)[idx]; |
8782 | } |
8783 | BlockArgument StatefulIfRegionOp::getControlToken(Region ®ion, unsigned idx) { |
8784 | return GetLoopRegionControlTokens(region)[idx]; |
8785 | } |
8786 | } // namespace tfg |
8787 | } // namespace mlir |
8788 | MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::tfg::StatefulIfRegionOp) |
8789 | |
8790 | namespace mlir { |
8791 | namespace tfg { |
8792 | |
8793 | //===----------------------------------------------------------------------===// |
8794 | // ::mlir::tfg::StatefulWhileOp definitions |
8795 | //===----------------------------------------------------------------------===// |
8796 | |
8797 | StatefulWhileOpAdaptor::StatefulWhileOpAdaptor(::mlir::ValueRange values, ::mlir::DictionaryAttr attrs, ::mlir::RegionRange regions) : odsOperands(values), odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) |
8798 | odsOpName.emplace("tfg.StatefulWhile" , odsAttrs.getContext()); |
8799 | } |
8800 | |
8801 | StatefulWhileOpAdaptor::StatefulWhileOpAdaptor(StatefulWhileOp op) : odsOperands(op->getOperands()), odsAttrs(op->getAttrDictionary()), odsRegions(op->getRegions()), odsOpName(op->getName()) {} |
8802 | |
8803 | ::mlir::ValueRange StatefulWhileOpAdaptor::getOperands() { |
8804 | return odsOperands; |
8805 | } |
8806 | |
8807 | std::pair<unsigned, unsigned> StatefulWhileOpAdaptor::getODSOperandIndexAndLength(unsigned index) { |
8808 | bool isVariadic[] = {true}; |
8809 | int prevVariadicCount = 0; |
8810 | for (unsigned i = 0; i < index; ++i) |
8811 | if (isVariadic[i]) ++prevVariadicCount; |
8812 | |
8813 | // Calculate how many dynamic values a static variadic operand corresponds to. |
8814 | // This assumes all static variadic operands have the same dynamic value count. |
8815 | int variadicSize = (odsOperands.size() - 0) / 1; |
8816 | // `index` passed in as the parameter is the static index which counts each |
8817 | // operand (variadic or not) as size 1. So here for each previous static variadic |
8818 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
8819 | // value pack for this static operand starts. |
8820 | int start = index + (variadicSize - 1) * prevVariadicCount; |
8821 | int size = isVariadic[index] ? variadicSize : 1; |
8822 | return {start, size}; |
8823 | } |
8824 | |
8825 | ::mlir::ValueRange StatefulWhileOpAdaptor::getODSOperands(unsigned index) { |
8826 | auto valueRange = getODSOperandIndexAndLength(index); |
8827 | return {std::next(odsOperands.begin(), valueRange.first), |
8828 | std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; |
8829 | } |
8830 | |
8831 | ::mlir::ValueRange StatefulWhileOpAdaptor::getArgs() { |
8832 | return getODSOperands(0); |
8833 | } |
8834 | |
8835 | ::mlir::ValueRange StatefulWhileOpAdaptor::args() { |
8836 | return getODSOperands(0); |
8837 | } |
8838 | |
8839 | ::mlir::DictionaryAttr StatefulWhileOpAdaptor::getAttributes() { |
8840 | return odsAttrs; |
8841 | } |
8842 | |
8843 | ::mlir::tf_type::FuncAttr StatefulWhileOpAdaptor::getCondAttr() { |
8844 | assert(odsAttrs && "no attributes when constructing adapter" ); |
8845 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 1, StatefulWhileOp::getCondAttrName(*odsOpName)).cast<::mlir::tf_type::FuncAttr>(); |
8846 | return attr; |
8847 | } |
8848 | |
8849 | ::mlir::tf_type::FuncAttr StatefulWhileOpAdaptor::getCond() { |
8850 | auto attr = getCondAttr(); |
8851 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
8852 | } |
8853 | |
8854 | ::mlir::tf_type::FuncAttr StatefulWhileOpAdaptor::condAttr() { |
8855 | assert(odsAttrs && "no attributes when constructing adapter" ); |
8856 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 1, StatefulWhileOp::getCondAttrName(*odsOpName)).cast<::mlir::tf_type::FuncAttr>(); |
8857 | return attr; |
8858 | } |
8859 | |
8860 | ::mlir::tf_type::FuncAttr StatefulWhileOpAdaptor::cond() { |
8861 | auto attr = condAttr(); |
8862 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
8863 | } |
8864 | |
8865 | ::mlir::tf_type::FuncAttr StatefulWhileOpAdaptor::getBodyAttr() { |
8866 | assert(odsAttrs && "no attributes when constructing adapter" ); |
8867 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, StatefulWhileOp::getBodyAttrName(*odsOpName)).cast<::mlir::tf_type::FuncAttr>(); |
8868 | return attr; |
8869 | } |
8870 | |
8871 | ::mlir::tf_type::FuncAttr StatefulWhileOpAdaptor::getBody() { |
8872 | auto attr = getBodyAttr(); |
8873 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
8874 | } |
8875 | |
8876 | ::mlir::tf_type::FuncAttr StatefulWhileOpAdaptor::bodyAttr() { |
8877 | assert(odsAttrs && "no attributes when constructing adapter" ); |
8878 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, StatefulWhileOp::getBodyAttrName(*odsOpName)).cast<::mlir::tf_type::FuncAttr>(); |
8879 | return attr; |
8880 | } |
8881 | |
8882 | ::mlir::tf_type::FuncAttr StatefulWhileOpAdaptor::body() { |
8883 | auto attr = bodyAttr(); |
8884 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
8885 | } |
8886 | |
8887 | ::mlir::IntegerAttr StatefulWhileOpAdaptor::getParallelIterationsAttr() { |
8888 | assert(odsAttrs && "no attributes when constructing adapter" ); |
8889 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 2, odsAttrs.end() - 0, StatefulWhileOp::getParallelIterationsAttrName(*odsOpName)).cast<::mlir::IntegerAttr>(); |
8890 | return attr; |
8891 | } |
8892 | |
8893 | uint64_t StatefulWhileOpAdaptor::getParallelIterations() { |
8894 | auto attr = getParallelIterationsAttr(); |
8895 | return attr.getValue().getZExtValue(); |
8896 | } |
8897 | |
8898 | ::mlir::IntegerAttr StatefulWhileOpAdaptor::parallel_iterationsAttr() { |
8899 | assert(odsAttrs && "no attributes when constructing adapter" ); |
8900 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 2, odsAttrs.end() - 0, StatefulWhileOp::getParallelIterationsAttrName(*odsOpName)).cast<::mlir::IntegerAttr>(); |
8901 | return attr; |
8902 | } |
8903 | |
8904 | uint64_t StatefulWhileOpAdaptor::parallel_iterations() { |
8905 | auto attr = parallel_iterationsAttr(); |
8906 | return attr.getValue().getZExtValue(); |
8907 | } |
8908 | |
8909 | ::mlir::ArrayAttr StatefulWhileOpAdaptor::getTAttr() { |
8910 | assert(odsAttrs && "no attributes when constructing adapter" ); |
8911 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 3, StatefulWhileOp::getTAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
8912 | return attr; |
8913 | } |
8914 | |
8915 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulWhileOpAdaptor::getT() { |
8916 | auto attr = getTAttr(); |
8917 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
8918 | } |
8919 | |
8920 | ::mlir::ArrayAttr StatefulWhileOpAdaptor::TAttr() { |
8921 | assert(odsAttrs && "no attributes when constructing adapter" ); |
8922 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 3, StatefulWhileOp::getTAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
8923 | return attr; |
8924 | } |
8925 | |
8926 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulWhileOpAdaptor::T() { |
8927 | auto attr = TAttr(); |
8928 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
8929 | } |
8930 | |
8931 | ::mlir::ArrayAttr StatefulWhileOpAdaptor::getOutputShapesAttr() { |
8932 | assert(odsAttrs && "no attributes when constructing adapter" ); |
8933 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 2, odsAttrs.end() - 1, StatefulWhileOp::getOutputShapesAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
8934 | return attr; |
8935 | } |
8936 | |
8937 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulWhileOpAdaptor::getOutputShapes() { |
8938 | auto attr = getOutputShapesAttr(); |
8939 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
8940 | } |
8941 | |
8942 | ::mlir::ArrayAttr StatefulWhileOpAdaptor::output_shapesAttr() { |
8943 | assert(odsAttrs && "no attributes when constructing adapter" ); |
8944 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 2, odsAttrs.end() - 1, StatefulWhileOp::getOutputShapesAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
8945 | return attr; |
8946 | } |
8947 | |
8948 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulWhileOpAdaptor::output_shapes() { |
8949 | auto attr = output_shapesAttr(); |
8950 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
8951 | } |
8952 | |
8953 | ::mlir::LogicalResult StatefulWhileOpAdaptor::verify(::mlir::Location loc) { |
8954 | auto namedAttrRange = odsAttrs; |
8955 | auto namedAttrIt = namedAttrRange.begin(); |
8956 | ::mlir::Attribute tblgen_body; |
8957 | ::mlir::Attribute tblgen_T; |
8958 | while (true) { |
8959 | if (namedAttrIt == namedAttrRange.end()) |
8960 | return emitError(loc, "'tfg.StatefulWhile' op " "requires attribute 'body'" ); |
8961 | if (namedAttrIt->getName() == StatefulWhileOp::getBodyAttrName(*odsOpName)) { |
8962 | tblgen_body = namedAttrIt->getValue(); |
8963 | break; |
8964 | } |
8965 | else if (namedAttrIt->getName() == StatefulWhileOp::getTAttrName(*odsOpName)) { |
8966 | tblgen_T = namedAttrIt->getValue(); |
8967 | } |
8968 | ++namedAttrIt; |
8969 | } |
8970 | ::mlir::Attribute tblgen_cond; |
8971 | while (true) { |
8972 | if (namedAttrIt == namedAttrRange.end()) |
8973 | return emitError(loc, "'tfg.StatefulWhile' op " "requires attribute 'cond'" ); |
8974 | if (namedAttrIt->getName() == StatefulWhileOp::getCondAttrName(*odsOpName)) { |
8975 | tblgen_cond = namedAttrIt->getValue(); |
8976 | break; |
8977 | } |
8978 | ++namedAttrIt; |
8979 | } |
8980 | ::mlir::Attribute tblgen_parallel_iterations; |
8981 | ::mlir::Attribute tblgen_output_shapes; |
8982 | while (true) { |
8983 | if (namedAttrIt == namedAttrRange.end()) |
8984 | return emitError(loc, "'tfg.StatefulWhile' op " "requires attribute 'parallel_iterations'" ); |
8985 | if (namedAttrIt->getName() == StatefulWhileOp::getParallelIterationsAttrName(*odsOpName)) { |
8986 | tblgen_parallel_iterations = namedAttrIt->getValue(); |
8987 | break; |
8988 | } |
8989 | else if (namedAttrIt->getName() == StatefulWhileOp::getOutputShapesAttrName(*odsOpName)) { |
8990 | tblgen_output_shapes = namedAttrIt->getValue(); |
8991 | } |
8992 | ++namedAttrIt; |
8993 | } |
8994 | |
8995 | if (tblgen_cond && !((tblgen_cond.isa<::mlir::tf_type::FuncAttr>()))) |
8996 | return emitError(loc, "'tfg.StatefulWhile' op " "attribute 'cond' failed to satisfy constraint: Models the `AttrValue.value.func` proto attribute value as a pair of SymbolRef and DictionaryAttr" ); |
8997 | |
8998 | if (tblgen_body && !((tblgen_body.isa<::mlir::tf_type::FuncAttr>()))) |
8999 | return emitError(loc, "'tfg.StatefulWhile' op " "attribute 'body' failed to satisfy constraint: Models the `AttrValue.value.func` proto attribute value as a pair of SymbolRef and DictionaryAttr" ); |
9000 | |
9001 | if (tblgen_parallel_iterations && !(((tblgen_parallel_iterations.isa<::mlir::IntegerAttr>())) && ((tblgen_parallel_iterations.cast<::mlir::IntegerAttr>().getType().isSignlessInteger(64))))) |
9002 | return emitError(loc, "'tfg.StatefulWhile' op " "attribute 'parallel_iterations' failed to satisfy constraint: 64-bit signless integer attribute" ); |
9003 | |
9004 | if (tblgen_T && !(((tblgen_T.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_T.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && (((attr.isa<::mlir::TypeAttr>())) && ((attr.cast<::mlir::TypeAttr>().getValue().isa<::mlir::Type>()))); })))) |
9005 | return emitError(loc, "'tfg.StatefulWhile' op " "attribute 'T' failed to satisfy constraint: type array attribute" ); |
9006 | |
9007 | if (tblgen_output_shapes && !(((tblgen_output_shapes.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_output_shapes.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && ((attr.isa<::mlir::tf_type::ShapeAttr>())); })))) |
9008 | return emitError(loc, "'tfg.StatefulWhile' op " "attribute 'output_shapes' failed to satisfy constraint: An array of shapes." ); |
9009 | return ::mlir::success(); |
9010 | } |
9011 | |
9012 | void StatefulWhileOp::getAsmResultNames(::mlir::OpAsmSetValueNameFn setNameFn) { |
9013 | auto resultGroup0 = getODSResults(0); |
9014 | if (!resultGroup0.empty()) |
9015 | setNameFn(*resultGroup0.begin(), "outs" ); |
9016 | auto resultGroup1 = getODSResults(1); |
9017 | if (!resultGroup1.empty()) |
9018 | setNameFn(*resultGroup1.begin(), "ctl" ); |
9019 | } |
9020 | |
9021 | std::pair<unsigned, unsigned> StatefulWhileOp::getODSOperandIndexAndLength(unsigned index) { |
9022 | bool isVariadic[] = {true}; |
9023 | int prevVariadicCount = 0; |
9024 | for (unsigned i = 0; i < index; ++i) |
9025 | if (isVariadic[i]) ++prevVariadicCount; |
9026 | |
9027 | // Calculate how many dynamic values a static variadic operand corresponds to. |
9028 | // This assumes all static variadic operands have the same dynamic value count. |
9029 | int variadicSize = (getOperation()->getNumOperands() - 0) / 1; |
9030 | // `index` passed in as the parameter is the static index which counts each |
9031 | // operand (variadic or not) as size 1. So here for each previous static variadic |
9032 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
9033 | // value pack for this static operand starts. |
9034 | int start = index + (variadicSize - 1) * prevVariadicCount; |
9035 | int size = isVariadic[index] ? variadicSize : 1; |
9036 | return {start, size}; |
9037 | } |
9038 | |
9039 | ::mlir::Operation::operand_range StatefulWhileOp::getODSOperands(unsigned index) { |
9040 | auto valueRange = getODSOperandIndexAndLength(index); |
9041 | return {std::next(getOperation()->operand_begin(), valueRange.first), |
9042 | std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; |
9043 | } |
9044 | |
9045 | ::mlir::Operation::operand_range StatefulWhileOp::getArgs() { |
9046 | return getODSOperands(0); |
9047 | } |
9048 | |
9049 | ::mlir::Operation::operand_range StatefulWhileOp::args() { |
9050 | return getODSOperands(0); |
9051 | } |
9052 | |
9053 | ::mlir::MutableOperandRange StatefulWhileOp::getArgsMutable() { |
9054 | auto range = getODSOperandIndexAndLength(0); |
9055 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
9056 | return mutableRange; |
9057 | } |
9058 | |
9059 | ::mlir::MutableOperandRange StatefulWhileOp::argsMutable() { |
9060 | auto range = getODSOperandIndexAndLength(0); |
9061 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
9062 | return mutableRange; |
9063 | } |
9064 | |
9065 | std::pair<unsigned, unsigned> StatefulWhileOp::getODSResultIndexAndLength(unsigned index) { |
9066 | bool isVariadic[] = {true, false}; |
9067 | int prevVariadicCount = 0; |
9068 | for (unsigned i = 0; i < index; ++i) |
9069 | if (isVariadic[i]) ++prevVariadicCount; |
9070 | |
9071 | // Calculate how many dynamic values a static variadic operand corresponds to. |
9072 | // This assumes all static variadic operands have the same dynamic value count. |
9073 | int variadicSize = (getOperation()->getNumResults() - 1) / 1; |
9074 | // `index` passed in as the parameter is the static index which counts each |
9075 | // operand (variadic or not) as size 1. So here for each previous static variadic |
9076 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
9077 | // value pack for this static operand starts. |
9078 | int start = index + (variadicSize - 1) * prevVariadicCount; |
9079 | int size = isVariadic[index] ? variadicSize : 1; |
9080 | return {start, size}; |
9081 | } |
9082 | |
9083 | ::mlir::Operation::result_range StatefulWhileOp::getODSResults(unsigned index) { |
9084 | auto valueRange = getODSResultIndexAndLength(index); |
9085 | return {std::next(getOperation()->result_begin(), valueRange.first), |
9086 | std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; |
9087 | } |
9088 | |
9089 | ::mlir::Operation::result_range StatefulWhileOp::getOuts() { |
9090 | return getODSResults(0); |
9091 | } |
9092 | |
9093 | ::mlir::Operation::result_range StatefulWhileOp::outs() { |
9094 | return getODSResults(0); |
9095 | } |
9096 | |
9097 | ::mlir::TypedValue<::mlir::tf_type::ControlType> StatefulWhileOp::getCtl() { |
9098 | return *getODSResults(1).begin(); |
9099 | } |
9100 | |
9101 | ::mlir::TypedValue<::mlir::tf_type::ControlType> StatefulWhileOp::ctl() { |
9102 | return *getODSResults(1).begin(); |
9103 | } |
9104 | |
9105 | ::mlir::tf_type::FuncAttr StatefulWhileOp::getCondAttr() { |
9106 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 1, getCondAttrName()).cast<::mlir::tf_type::FuncAttr>(); |
9107 | } |
9108 | |
9109 | ::mlir::tf_type::FuncAttr StatefulWhileOp::getCond() { |
9110 | auto attr = getCondAttr(); |
9111 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
9112 | } |
9113 | |
9114 | ::mlir::tf_type::FuncAttr StatefulWhileOp::condAttr() { |
9115 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 1, getCondAttrName()).cast<::mlir::tf_type::FuncAttr>(); |
9116 | } |
9117 | |
9118 | ::mlir::tf_type::FuncAttr StatefulWhileOp::cond() { |
9119 | auto attr = condAttr(); |
9120 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
9121 | } |
9122 | |
9123 | ::mlir::tf_type::FuncAttr StatefulWhileOp::getBodyAttr() { |
9124 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getBodyAttrName()).cast<::mlir::tf_type::FuncAttr>(); |
9125 | } |
9126 | |
9127 | ::mlir::tf_type::FuncAttr StatefulWhileOp::getBody() { |
9128 | auto attr = getBodyAttr(); |
9129 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
9130 | } |
9131 | |
9132 | ::mlir::tf_type::FuncAttr StatefulWhileOp::bodyAttr() { |
9133 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getBodyAttrName()).cast<::mlir::tf_type::FuncAttr>(); |
9134 | } |
9135 | |
9136 | ::mlir::tf_type::FuncAttr StatefulWhileOp::body() { |
9137 | auto attr = bodyAttr(); |
9138 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
9139 | } |
9140 | |
9141 | ::mlir::IntegerAttr StatefulWhileOp::getParallelIterationsAttr() { |
9142 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 2, (*this)->getAttrs().end() - 0, getParallelIterationsAttrName()).cast<::mlir::IntegerAttr>(); |
9143 | } |
9144 | |
9145 | uint64_t StatefulWhileOp::getParallelIterations() { |
9146 | auto attr = getParallelIterationsAttr(); |
9147 | return attr.getValue().getZExtValue(); |
9148 | } |
9149 | |
9150 | ::mlir::IntegerAttr StatefulWhileOp::parallel_iterationsAttr() { |
9151 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 2, (*this)->getAttrs().end() - 0, getParallelIterationsAttrName()).cast<::mlir::IntegerAttr>(); |
9152 | } |
9153 | |
9154 | uint64_t StatefulWhileOp::parallel_iterations() { |
9155 | auto attr = parallel_iterationsAttr(); |
9156 | return attr.getValue().getZExtValue(); |
9157 | } |
9158 | |
9159 | ::mlir::ArrayAttr StatefulWhileOp::getTAttr() { |
9160 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 3, getTAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
9161 | } |
9162 | |
9163 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulWhileOp::getT() { |
9164 | auto attr = getTAttr(); |
9165 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
9166 | } |
9167 | |
9168 | ::mlir::ArrayAttr StatefulWhileOp::TAttr() { |
9169 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 3, getTAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
9170 | } |
9171 | |
9172 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulWhileOp::T() { |
9173 | auto attr = TAttr(); |
9174 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
9175 | } |
9176 | |
9177 | ::mlir::ArrayAttr StatefulWhileOp::getOutputShapesAttr() { |
9178 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 2, (*this)->getAttrs().end() - 1, getOutputShapesAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
9179 | } |
9180 | |
9181 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulWhileOp::getOutputShapes() { |
9182 | auto attr = getOutputShapesAttr(); |
9183 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
9184 | } |
9185 | |
9186 | ::mlir::ArrayAttr StatefulWhileOp::output_shapesAttr() { |
9187 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 2, (*this)->getAttrs().end() - 1, getOutputShapesAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
9188 | } |
9189 | |
9190 | ::llvm::Optional< ::mlir::ArrayAttr > StatefulWhileOp::output_shapes() { |
9191 | auto attr = output_shapesAttr(); |
9192 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
9193 | } |
9194 | |
9195 | void StatefulWhileOp::setCondAttr(::mlir::tf_type::FuncAttr attr) { |
9196 | (*this)->setAttr(getCondAttrName(), attr); |
9197 | } |
9198 | |
9199 | void StatefulWhileOp::condAttr(::mlir::tf_type::FuncAttr attr) { |
9200 | (*this)->setAttr(condAttrName(), attr); |
9201 | } |
9202 | |
9203 | void StatefulWhileOp::setBodyAttr(::mlir::tf_type::FuncAttr attr) { |
9204 | (*this)->setAttr(getBodyAttrName(), attr); |
9205 | } |
9206 | |
9207 | void StatefulWhileOp::bodyAttr(::mlir::tf_type::FuncAttr attr) { |
9208 | (*this)->setAttr(bodyAttrName(), attr); |
9209 | } |
9210 | |
9211 | void StatefulWhileOp::setParallelIterationsAttr(::mlir::IntegerAttr attr) { |
9212 | (*this)->setAttr(getParallelIterationsAttrName(), attr); |
9213 | } |
9214 | |
9215 | void StatefulWhileOp::parallel_iterationsAttr(::mlir::IntegerAttr attr) { |
9216 | (*this)->setAttr(parallel_iterationsAttrName(), attr); |
9217 | } |
9218 | |
9219 | void StatefulWhileOp::setTAttr(::mlir::ArrayAttr attr) { |
9220 | (*this)->setAttr(getTAttrName(), attr); |
9221 | } |
9222 | |
9223 | void StatefulWhileOp::TAttr(::mlir::ArrayAttr attr) { |
9224 | (*this)->setAttr(TAttrName(), attr); |
9225 | } |
9226 | |
9227 | void StatefulWhileOp::setOutputShapesAttr(::mlir::ArrayAttr attr) { |
9228 | (*this)->setAttr(getOutputShapesAttrName(), attr); |
9229 | } |
9230 | |
9231 | void StatefulWhileOp::output_shapesAttr(::mlir::ArrayAttr attr) { |
9232 | (*this)->setAttr(output_shapesAttrName(), attr); |
9233 | } |
9234 | |
9235 | ::mlir::Attribute StatefulWhileOp::removeTAttr() { |
9236 | return (*this)->removeAttr(getTAttrName()); |
9237 | } |
9238 | |
9239 | ::mlir::Attribute StatefulWhileOp::removeOutput_shapesAttr() { |
9240 | return (*this)->removeAttr(getOutputShapesAttrName()); |
9241 | } |
9242 | |
9243 | void StatefulWhileOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, TypeRange results, ValueRange args, FuncAttr cond, FuncAttr body, IntegerAttr parallel_iterations) { |
9244 | build(odsBuilder, odsState, results, args, cond, body, parallel_iterations, |
9245 | /*T=*/{}, /*output_shapes=*/{}); |
9246 | |
9247 | } |
9248 | |
9249 | void StatefulWhileOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange outs, ::mlir::Type ctl, ::mlir::ValueRange args, ::mlir::tf_type::FuncAttr cond, ::mlir::tf_type::FuncAttr body, ::mlir::IntegerAttr parallel_iterations, /*optional*/::mlir::ArrayAttr T, /*optional*/::mlir::ArrayAttr output_shapes) { |
9250 | odsState.addOperands(args); |
9251 | odsState.addAttribute(getCondAttrName(odsState.name), cond); |
9252 | odsState.addAttribute(getBodyAttrName(odsState.name), body); |
9253 | odsState.addAttribute(getParallelIterationsAttrName(odsState.name), parallel_iterations); |
9254 | if (T) { |
9255 | odsState.addAttribute(getTAttrName(odsState.name), T); |
9256 | } |
9257 | if (output_shapes) { |
9258 | odsState.addAttribute(getOutputShapesAttrName(odsState.name), output_shapes); |
9259 | } |
9260 | odsState.addTypes(outs); |
9261 | odsState.addTypes(ctl); |
9262 | } |
9263 | |
9264 | void StatefulWhileOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange args, ::mlir::tf_type::FuncAttr cond, ::mlir::tf_type::FuncAttr body, ::mlir::IntegerAttr parallel_iterations, /*optional*/::mlir::ArrayAttr T, /*optional*/::mlir::ArrayAttr output_shapes) { |
9265 | odsState.addOperands(args); |
9266 | odsState.addAttribute(getCondAttrName(odsState.name), cond); |
9267 | odsState.addAttribute(getBodyAttrName(odsState.name), body); |
9268 | odsState.addAttribute(getParallelIterationsAttrName(odsState.name), parallel_iterations); |
9269 | if (T) { |
9270 | odsState.addAttribute(getTAttrName(odsState.name), T); |
9271 | } |
9272 | if (output_shapes) { |
9273 | odsState.addAttribute(getOutputShapesAttrName(odsState.name), output_shapes); |
9274 | } |
9275 | assert(resultTypes.size() >= 1u && "mismatched number of results" ); |
9276 | odsState.addTypes(resultTypes); |
9277 | } |
9278 | |
9279 | void StatefulWhileOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange outs, ::mlir::Type ctl, ::mlir::ValueRange args, ::mlir::tf_type::FuncAttr cond, ::mlir::tf_type::FuncAttr body, uint64_t parallel_iterations, /*optional*/::mlir::ArrayAttr T, /*optional*/::mlir::ArrayAttr output_shapes) { |
9280 | odsState.addOperands(args); |
9281 | odsState.addAttribute(getCondAttrName(odsState.name), cond); |
9282 | odsState.addAttribute(getBodyAttrName(odsState.name), body); |
9283 | odsState.addAttribute(getParallelIterationsAttrName(odsState.name), odsBuilder.getIntegerAttr(odsBuilder.getIntegerType(64), parallel_iterations)); |
9284 | if (T) { |
9285 | odsState.addAttribute(getTAttrName(odsState.name), T); |
9286 | } |
9287 | if (output_shapes) { |
9288 | odsState.addAttribute(getOutputShapesAttrName(odsState.name), output_shapes); |
9289 | } |
9290 | odsState.addTypes(outs); |
9291 | odsState.addTypes(ctl); |
9292 | } |
9293 | |
9294 | void StatefulWhileOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange args, ::mlir::tf_type::FuncAttr cond, ::mlir::tf_type::FuncAttr body, uint64_t parallel_iterations, /*optional*/::mlir::ArrayAttr T, /*optional*/::mlir::ArrayAttr output_shapes) { |
9295 | odsState.addOperands(args); |
9296 | odsState.addAttribute(getCondAttrName(odsState.name), cond); |
9297 | odsState.addAttribute(getBodyAttrName(odsState.name), body); |
9298 | odsState.addAttribute(getParallelIterationsAttrName(odsState.name), odsBuilder.getIntegerAttr(odsBuilder.getIntegerType(64), parallel_iterations)); |
9299 | if (T) { |
9300 | odsState.addAttribute(getTAttrName(odsState.name), T); |
9301 | } |
9302 | if (output_shapes) { |
9303 | odsState.addAttribute(getOutputShapesAttrName(odsState.name), output_shapes); |
9304 | } |
9305 | assert(resultTypes.size() >= 1u && "mismatched number of results" ); |
9306 | odsState.addTypes(resultTypes); |
9307 | } |
9308 | |
9309 | void StatefulWhileOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { |
9310 | odsState.addOperands(operands); |
9311 | odsState.addAttributes(attributes); |
9312 | assert(resultTypes.size() >= 1u && "mismatched number of return types" ); |
9313 | odsState.addTypes(resultTypes); |
9314 | } |
9315 | |
9316 | ::mlir::LogicalResult StatefulWhileOp::verifyInvariantsImpl() { |
9317 | auto namedAttrRange = (*this)->getAttrs(); |
9318 | auto namedAttrIt = namedAttrRange.begin(); |
9319 | ::mlir::Attribute tblgen_body; |
9320 | ::mlir::Attribute tblgen_T; |
9321 | while (true) { |
9322 | if (namedAttrIt == namedAttrRange.end()) |
9323 | return emitOpError("requires attribute 'body'" ); |
9324 | if (namedAttrIt->getName() == getBodyAttrName()) { |
9325 | tblgen_body = namedAttrIt->getValue(); |
9326 | break; |
9327 | } |
9328 | else if (namedAttrIt->getName() == getTAttrName()) { |
9329 | tblgen_T = namedAttrIt->getValue(); |
9330 | } |
9331 | ++namedAttrIt; |
9332 | } |
9333 | ::mlir::Attribute tblgen_cond; |
9334 | while (true) { |
9335 | if (namedAttrIt == namedAttrRange.end()) |
9336 | return emitOpError("requires attribute 'cond'" ); |
9337 | if (namedAttrIt->getName() == getCondAttrName()) { |
9338 | tblgen_cond = namedAttrIt->getValue(); |
9339 | break; |
9340 | } |
9341 | ++namedAttrIt; |
9342 | } |
9343 | ::mlir::Attribute tblgen_parallel_iterations; |
9344 | ::mlir::Attribute tblgen_output_shapes; |
9345 | while (true) { |
9346 | if (namedAttrIt == namedAttrRange.end()) |
9347 | return emitOpError("requires attribute 'parallel_iterations'" ); |
9348 | if (namedAttrIt->getName() == getParallelIterationsAttrName()) { |
9349 | tblgen_parallel_iterations = namedAttrIt->getValue(); |
9350 | break; |
9351 | } |
9352 | else if (namedAttrIt->getName() == getOutputShapesAttrName()) { |
9353 | tblgen_output_shapes = namedAttrIt->getValue(); |
9354 | } |
9355 | ++namedAttrIt; |
9356 | } |
9357 | |
9358 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops5(*this, tblgen_cond, "cond" ))) |
9359 | return ::mlir::failure(); |
9360 | |
9361 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops5(*this, tblgen_body, "body" ))) |
9362 | return ::mlir::failure(); |
9363 | |
9364 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops18(*this, tblgen_parallel_iterations, "parallel_iterations" ))) |
9365 | return ::mlir::failure(); |
9366 | |
9367 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops1(*this, tblgen_T, "T" ))) |
9368 | return ::mlir::failure(); |
9369 | |
9370 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops2(*this, tblgen_output_shapes, "output_shapes" ))) |
9371 | return ::mlir::failure(); |
9372 | { |
9373 | unsigned index = 0; (void)index; |
9374 | auto valueGroup0 = getODSOperands(0); |
9375 | |
9376 | for (auto v : valueGroup0) { |
9377 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops1(*this, v.getType(), "operand" , index++))) |
9378 | return ::mlir::failure(); |
9379 | } |
9380 | } |
9381 | { |
9382 | unsigned index = 0; (void)index; |
9383 | auto valueGroup0 = getODSResults(0); |
9384 | |
9385 | for (auto v : valueGroup0) { |
9386 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops2(*this, v.getType(), "result" , index++))) |
9387 | return ::mlir::failure(); |
9388 | } |
9389 | auto valueGroup1 = getODSResults(1); |
9390 | |
9391 | for (auto v : valueGroup1) { |
9392 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops3(*this, v.getType(), "result" , index++))) |
9393 | return ::mlir::failure(); |
9394 | } |
9395 | } |
9396 | return ::mlir::success(); |
9397 | } |
9398 | |
9399 | ::mlir::LogicalResult StatefulWhileOp::verifyInvariants() { |
9400 | return verifyInvariantsImpl(); |
9401 | } |
9402 | |
9403 | LogicalResult StatefulWhileOp::verifySymbolUses( |
9404 | SymbolTableCollection &symbol_table) { |
9405 | return VerifyWhileLikeOp(*this, symbol_table); |
9406 | } |
9407 | } // namespace tfg |
9408 | } // namespace mlir |
9409 | MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::tfg::StatefulWhileOp) |
9410 | |
9411 | namespace mlir { |
9412 | namespace tfg { |
9413 | |
9414 | //===----------------------------------------------------------------------===// |
9415 | // ::mlir::tfg::StatefulWhileRegionOp definitions |
9416 | //===----------------------------------------------------------------------===// |
9417 | |
9418 | StatefulWhileRegionOpAdaptor::StatefulWhileRegionOpAdaptor(::mlir::ValueRange values, ::mlir::DictionaryAttr attrs, ::mlir::RegionRange regions) : odsOperands(values), odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) |
9419 | odsOpName.emplace("tfg.StatefulWhileRegion" , odsAttrs.getContext()); |
9420 | } |
9421 | |
9422 | StatefulWhileRegionOpAdaptor::StatefulWhileRegionOpAdaptor(StatefulWhileRegionOp op) : odsOperands(op->getOperands()), odsAttrs(op->getAttrDictionary()), odsRegions(op->getRegions()), odsOpName(op->getName()) {} |
9423 | |
9424 | ::mlir::ValueRange StatefulWhileRegionOpAdaptor::getOperands() { |
9425 | return odsOperands; |
9426 | } |
9427 | |
9428 | std::pair<unsigned, unsigned> StatefulWhileRegionOpAdaptor::getODSOperandIndexAndLength(unsigned index) { |
9429 | assert(odsAttrs && "missing segment size attribute for op" ); |
9430 | auto sizeAttr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 1, StatefulWhileRegionOp::getOperandSegmentSizesAttrName(*odsOpName)).cast<::mlir::DenseI32ArrayAttr>(); |
9431 | |
9432 | unsigned start = 0; |
9433 | for (unsigned i = 0; i < index; ++i) |
9434 | start += sizeAttr[i]; |
9435 | return {start, sizeAttr[index]}; |
9436 | } |
9437 | |
9438 | ::mlir::ValueRange StatefulWhileRegionOpAdaptor::getODSOperands(unsigned index) { |
9439 | auto valueRange = getODSOperandIndexAndLength(index); |
9440 | return {std::next(odsOperands.begin(), valueRange.first), |
9441 | std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; |
9442 | } |
9443 | |
9444 | ::mlir::ValueRange StatefulWhileRegionOpAdaptor::getInit() { |
9445 | return getODSOperands(0); |
9446 | } |
9447 | |
9448 | ::mlir::ValueRange StatefulWhileRegionOpAdaptor::init() { |
9449 | return getODSOperands(0); |
9450 | } |
9451 | |
9452 | ::mlir::ValueRange StatefulWhileRegionOpAdaptor::getCtls() { |
9453 | return getODSOperands(1); |
9454 | } |
9455 | |
9456 | ::mlir::ValueRange StatefulWhileRegionOpAdaptor::ctls() { |
9457 | return getODSOperands(1); |
9458 | } |
9459 | |
9460 | ::mlir::DictionaryAttr StatefulWhileRegionOpAdaptor::getAttributes() { |
9461 | return odsAttrs; |
9462 | } |
9463 | |
9464 | ::mlir::IntegerAttr StatefulWhileRegionOpAdaptor::getParallelIterationsAttr() { |
9465 | assert(odsAttrs && "no attributes when constructing adapter" ); |
9466 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 0, StatefulWhileRegionOp::getParallelIterationsAttrName(*odsOpName)).cast<::mlir::IntegerAttr>(); |
9467 | return attr; |
9468 | } |
9469 | |
9470 | uint64_t StatefulWhileRegionOpAdaptor::getParallelIterations() { |
9471 | auto attr = getParallelIterationsAttr(); |
9472 | return attr.getValue().getZExtValue(); |
9473 | } |
9474 | |
9475 | ::mlir::IntegerAttr StatefulWhileRegionOpAdaptor::parallel_iterationsAttr() { |
9476 | assert(odsAttrs && "no attributes when constructing adapter" ); |
9477 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 0, StatefulWhileRegionOp::getParallelIterationsAttrName(*odsOpName)).cast<::mlir::IntegerAttr>(); |
9478 | return attr; |
9479 | } |
9480 | |
9481 | uint64_t StatefulWhileRegionOpAdaptor::parallel_iterations() { |
9482 | auto attr = parallel_iterationsAttr(); |
9483 | return attr.getValue().getZExtValue(); |
9484 | } |
9485 | |
9486 | ::mlir::DictionaryAttr StatefulWhileRegionOpAdaptor::getCondAttrsAttr() { |
9487 | assert(odsAttrs && "no attributes when constructing adapter" ); |
9488 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, StatefulWhileRegionOp::getCondAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
9489 | return attr; |
9490 | } |
9491 | |
9492 | ::llvm::Optional< ::mlir::DictionaryAttr > StatefulWhileRegionOpAdaptor::getCondAttrs() { |
9493 | auto attr = getCondAttrsAttr(); |
9494 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
9495 | } |
9496 | |
9497 | ::mlir::DictionaryAttr StatefulWhileRegionOpAdaptor::cond_attrsAttr() { |
9498 | assert(odsAttrs && "no attributes when constructing adapter" ); |
9499 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, StatefulWhileRegionOp::getCondAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
9500 | return attr; |
9501 | } |
9502 | |
9503 | ::llvm::Optional< ::mlir::DictionaryAttr > StatefulWhileRegionOpAdaptor::cond_attrs() { |
9504 | auto attr = cond_attrsAttr(); |
9505 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
9506 | } |
9507 | |
9508 | ::mlir::DictionaryAttr StatefulWhileRegionOpAdaptor::getBodyAttrsAttr() { |
9509 | assert(odsAttrs && "no attributes when constructing adapter" ); |
9510 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, StatefulWhileRegionOp::getBodyAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
9511 | return attr; |
9512 | } |
9513 | |
9514 | ::llvm::Optional< ::mlir::DictionaryAttr > StatefulWhileRegionOpAdaptor::getBodyAttrs() { |
9515 | auto attr = getBodyAttrsAttr(); |
9516 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
9517 | } |
9518 | |
9519 | ::mlir::DictionaryAttr StatefulWhileRegionOpAdaptor::body_attrsAttr() { |
9520 | assert(odsAttrs && "no attributes when constructing adapter" ); |
9521 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, StatefulWhileRegionOp::getBodyAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
9522 | return attr; |
9523 | } |
9524 | |
9525 | ::llvm::Optional< ::mlir::DictionaryAttr > StatefulWhileRegionOpAdaptor::body_attrs() { |
9526 | auto attr = body_attrsAttr(); |
9527 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
9528 | } |
9529 | |
9530 | ::mlir::tfg::RegionAttr StatefulWhileRegionOpAdaptor::getCondRegionAttrsAttr() { |
9531 | assert(odsAttrs && "no attributes when constructing adapter" ); |
9532 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, StatefulWhileRegionOp::getCondRegionAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
9533 | return attr; |
9534 | } |
9535 | |
9536 | ::llvm::Optional<::mlir::tfg::RegionAttr> StatefulWhileRegionOpAdaptor::getCondRegionAttrs() { |
9537 | auto attr = getCondRegionAttrsAttr(); |
9538 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
9539 | } |
9540 | |
9541 | ::mlir::tfg::RegionAttr StatefulWhileRegionOpAdaptor::cond_region_attrsAttr() { |
9542 | assert(odsAttrs && "no attributes when constructing adapter" ); |
9543 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, StatefulWhileRegionOp::getCondRegionAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
9544 | return attr; |
9545 | } |
9546 | |
9547 | ::llvm::Optional<::mlir::tfg::RegionAttr> StatefulWhileRegionOpAdaptor::cond_region_attrs() { |
9548 | auto attr = cond_region_attrsAttr(); |
9549 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
9550 | } |
9551 | |
9552 | ::mlir::tfg::RegionAttr StatefulWhileRegionOpAdaptor::getBodyRegionAttrsAttr() { |
9553 | assert(odsAttrs && "no attributes when constructing adapter" ); |
9554 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, StatefulWhileRegionOp::getBodyRegionAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
9555 | return attr; |
9556 | } |
9557 | |
9558 | ::llvm::Optional<::mlir::tfg::RegionAttr> StatefulWhileRegionOpAdaptor::getBodyRegionAttrs() { |
9559 | auto attr = getBodyRegionAttrsAttr(); |
9560 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
9561 | } |
9562 | |
9563 | ::mlir::tfg::RegionAttr StatefulWhileRegionOpAdaptor::body_region_attrsAttr() { |
9564 | assert(odsAttrs && "no attributes when constructing adapter" ); |
9565 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, StatefulWhileRegionOp::getBodyRegionAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
9566 | return attr; |
9567 | } |
9568 | |
9569 | ::llvm::Optional<::mlir::tfg::RegionAttr> StatefulWhileRegionOpAdaptor::body_region_attrs() { |
9570 | auto attr = body_region_attrsAttr(); |
9571 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
9572 | } |
9573 | |
9574 | ::mlir::RegionRange StatefulWhileRegionOpAdaptor::getRegions() { |
9575 | return odsRegions; |
9576 | } |
9577 | |
9578 | ::mlir::Region &StatefulWhileRegionOpAdaptor::getCondRegion() { |
9579 | return *odsRegions[0]; |
9580 | } |
9581 | |
9582 | ::mlir::Region &StatefulWhileRegionOpAdaptor::cond_region() { |
9583 | return *odsRegions[0]; |
9584 | } |
9585 | |
9586 | ::mlir::Region &StatefulWhileRegionOpAdaptor::getBodyRegion() { |
9587 | return *odsRegions[1]; |
9588 | } |
9589 | |
9590 | ::mlir::Region &StatefulWhileRegionOpAdaptor::body_region() { |
9591 | return *odsRegions[1]; |
9592 | } |
9593 | |
9594 | ::mlir::LogicalResult StatefulWhileRegionOpAdaptor::verify(::mlir::Location loc) { |
9595 | auto namedAttrRange = odsAttrs; |
9596 | auto namedAttrIt = namedAttrRange.begin(); |
9597 | ::mlir::Attribute tblgen_operand_segment_sizes; |
9598 | ::mlir::Attribute tblgen_body_attrs; |
9599 | ::mlir::Attribute tblgen_body_region_attrs; |
9600 | ::mlir::Attribute tblgen_cond_attrs; |
9601 | ::mlir::Attribute tblgen_cond_region_attrs; |
9602 | while (true) { |
9603 | if (namedAttrIt == namedAttrRange.end()) |
9604 | return emitError(loc, "'tfg.StatefulWhileRegion' op " "requires attribute 'operand_segment_sizes'" ); |
9605 | if (namedAttrIt->getName() == StatefulWhileRegionOp::getOperandSegmentSizesAttrName(*odsOpName)) { |
9606 | tblgen_operand_segment_sizes = namedAttrIt->getValue(); |
9607 | break; |
9608 | } |
9609 | else if (namedAttrIt->getName() == StatefulWhileRegionOp::getBodyAttrsAttrName(*odsOpName)) { |
9610 | tblgen_body_attrs = namedAttrIt->getValue(); |
9611 | } |
9612 | else if (namedAttrIt->getName() == StatefulWhileRegionOp::getBodyRegionAttrsAttrName(*odsOpName)) { |
9613 | tblgen_body_region_attrs = namedAttrIt->getValue(); |
9614 | } |
9615 | else if (namedAttrIt->getName() == StatefulWhileRegionOp::getCondAttrsAttrName(*odsOpName)) { |
9616 | tblgen_cond_attrs = namedAttrIt->getValue(); |
9617 | } |
9618 | else if (namedAttrIt->getName() == StatefulWhileRegionOp::getCondRegionAttrsAttrName(*odsOpName)) { |
9619 | tblgen_cond_region_attrs = namedAttrIt->getValue(); |
9620 | } |
9621 | ++namedAttrIt; |
9622 | } |
9623 | ::mlir::Attribute tblgen_parallel_iterations; |
9624 | while (true) { |
9625 | if (namedAttrIt == namedAttrRange.end()) |
9626 | return emitError(loc, "'tfg.StatefulWhileRegion' op " "requires attribute 'parallel_iterations'" ); |
9627 | if (namedAttrIt->getName() == StatefulWhileRegionOp::getParallelIterationsAttrName(*odsOpName)) { |
9628 | tblgen_parallel_iterations = namedAttrIt->getValue(); |
9629 | break; |
9630 | } |
9631 | ++namedAttrIt; |
9632 | } |
9633 | |
9634 | { |
9635 | auto sizeAttr = tblgen_operand_segment_sizes.cast<::mlir::DenseI32ArrayAttr>(); |
9636 | auto numElements = sizeAttr.asArrayRef().size(); |
9637 | if (numElements != 2) |
9638 | return emitError(loc, "'tfg.StatefulWhileRegion' op " "'operand_segment_sizes' attribute for specifying operand segments must have 2 " |
9639 | "elements, but got " ) << numElements; |
9640 | } |
9641 | |
9642 | if (tblgen_parallel_iterations && !(((tblgen_parallel_iterations.isa<::mlir::IntegerAttr>())) && ((tblgen_parallel_iterations.cast<::mlir::IntegerAttr>().getType().isSignlessInteger(64))))) |
9643 | return emitError(loc, "'tfg.StatefulWhileRegion' op " "attribute 'parallel_iterations' failed to satisfy constraint: 64-bit signless integer attribute" ); |
9644 | |
9645 | if (tblgen_cond_attrs && !((tblgen_cond_attrs.isa<::mlir::DictionaryAttr>()))) |
9646 | return emitError(loc, "'tfg.StatefulWhileRegion' op " "attribute 'cond_attrs' failed to satisfy constraint: dictionary of named attribute values" ); |
9647 | |
9648 | if (tblgen_body_attrs && !((tblgen_body_attrs.isa<::mlir::DictionaryAttr>()))) |
9649 | return emitError(loc, "'tfg.StatefulWhileRegion' op " "attribute 'body_attrs' failed to satisfy constraint: dictionary of named attribute values" ); |
9650 | |
9651 | if (tblgen_cond_region_attrs && !((tblgen_cond_region_attrs.isa<::mlir::tfg::RegionAttr>()))) |
9652 | return emitError(loc, "'tfg.StatefulWhileRegion' op " "attribute 'cond_region_attrs' failed to satisfy constraint: Region attributes, argument and result attributes." ); |
9653 | |
9654 | if (tblgen_body_region_attrs && !((tblgen_body_region_attrs.isa<::mlir::tfg::RegionAttr>()))) |
9655 | return emitError(loc, "'tfg.StatefulWhileRegion' op " "attribute 'body_region_attrs' failed to satisfy constraint: Region attributes, argument and result attributes." ); |
9656 | return ::mlir::success(); |
9657 | } |
9658 | |
9659 | std::pair<unsigned, unsigned> StatefulWhileRegionOp::getODSOperandIndexAndLength(unsigned index) { |
9660 | auto sizeAttr = ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getOperandSegmentSizesAttrName()).cast<::mlir::DenseI32ArrayAttr>(); |
9661 | |
9662 | unsigned start = 0; |
9663 | for (unsigned i = 0; i < index; ++i) |
9664 | start += sizeAttr[i]; |
9665 | return {start, sizeAttr[index]}; |
9666 | } |
9667 | |
9668 | ::mlir::Operation::operand_range StatefulWhileRegionOp::getODSOperands(unsigned index) { |
9669 | auto valueRange = getODSOperandIndexAndLength(index); |
9670 | return {std::next(getOperation()->operand_begin(), valueRange.first), |
9671 | std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; |
9672 | } |
9673 | |
9674 | ::mlir::Operation::operand_range StatefulWhileRegionOp::getInit() { |
9675 | return getODSOperands(0); |
9676 | } |
9677 | |
9678 | ::mlir::Operation::operand_range StatefulWhileRegionOp::init() { |
9679 | return getODSOperands(0); |
9680 | } |
9681 | |
9682 | ::mlir::Operation::operand_range StatefulWhileRegionOp::getCtls() { |
9683 | return getODSOperands(1); |
9684 | } |
9685 | |
9686 | ::mlir::Operation::operand_range StatefulWhileRegionOp::ctls() { |
9687 | return getODSOperands(1); |
9688 | } |
9689 | |
9690 | ::mlir::MutableOperandRange StatefulWhileRegionOp::getInitMutable() { |
9691 | auto range = getODSOperandIndexAndLength(0); |
9692 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(0u, *::mlir::impl::getNamedAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getOperandSegmentSizesAttrName()))); |
9693 | return mutableRange; |
9694 | } |
9695 | |
9696 | ::mlir::MutableOperandRange StatefulWhileRegionOp::initMutable() { |
9697 | auto range = getODSOperandIndexAndLength(0); |
9698 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(0u, *::mlir::impl::getNamedAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getOperandSegmentSizesAttrName()))); |
9699 | return mutableRange; |
9700 | } |
9701 | |
9702 | ::mlir::MutableOperandRange StatefulWhileRegionOp::getCtlsMutable() { |
9703 | auto range = getODSOperandIndexAndLength(1); |
9704 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(1u, *::mlir::impl::getNamedAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getOperandSegmentSizesAttrName()))); |
9705 | return mutableRange; |
9706 | } |
9707 | |
9708 | ::mlir::MutableOperandRange StatefulWhileRegionOp::ctlsMutable() { |
9709 | auto range = getODSOperandIndexAndLength(1); |
9710 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(1u, *::mlir::impl::getNamedAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getOperandSegmentSizesAttrName()))); |
9711 | return mutableRange; |
9712 | } |
9713 | |
9714 | std::pair<unsigned, unsigned> StatefulWhileRegionOp::getODSResultIndexAndLength(unsigned index) { |
9715 | bool isVariadic[] = {true, false}; |
9716 | int prevVariadicCount = 0; |
9717 | for (unsigned i = 0; i < index; ++i) |
9718 | if (isVariadic[i]) ++prevVariadicCount; |
9719 | |
9720 | // Calculate how many dynamic values a static variadic operand corresponds to. |
9721 | // This assumes all static variadic operands have the same dynamic value count. |
9722 | int variadicSize = (getOperation()->getNumResults() - 1) / 1; |
9723 | // `index` passed in as the parameter is the static index which counts each |
9724 | // operand (variadic or not) as size 1. So here for each previous static variadic |
9725 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
9726 | // value pack for this static operand starts. |
9727 | int start = index + (variadicSize - 1) * prevVariadicCount; |
9728 | int size = isVariadic[index] ? variadicSize : 1; |
9729 | return {start, size}; |
9730 | } |
9731 | |
9732 | ::mlir::Operation::result_range StatefulWhileRegionOp::getODSResults(unsigned index) { |
9733 | auto valueRange = getODSResultIndexAndLength(index); |
9734 | return {std::next(getOperation()->result_begin(), valueRange.first), |
9735 | std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; |
9736 | } |
9737 | |
9738 | ::mlir::Operation::result_range StatefulWhileRegionOp::getOuts() { |
9739 | return getODSResults(0); |
9740 | } |
9741 | |
9742 | ::mlir::Operation::result_range StatefulWhileRegionOp::outs() { |
9743 | return getODSResults(0); |
9744 | } |
9745 | |
9746 | ::mlir::TypedValue<::mlir::tf_type::ControlType> StatefulWhileRegionOp::getCtl() { |
9747 | return *getODSResults(1).begin(); |
9748 | } |
9749 | |
9750 | ::mlir::TypedValue<::mlir::tf_type::ControlType> StatefulWhileRegionOp::ctl() { |
9751 | return *getODSResults(1).begin(); |
9752 | } |
9753 | |
9754 | ::mlir::Region &StatefulWhileRegionOp::getCondRegion() { |
9755 | return (*this)->getRegion(0); |
9756 | } |
9757 | |
9758 | ::mlir::Region &StatefulWhileRegionOp::cond_region() { |
9759 | return (*this)->getRegion(0); |
9760 | } |
9761 | |
9762 | ::mlir::Region &StatefulWhileRegionOp::getBodyRegion() { |
9763 | return (*this)->getRegion(1); |
9764 | } |
9765 | |
9766 | ::mlir::Region &StatefulWhileRegionOp::body_region() { |
9767 | return (*this)->getRegion(1); |
9768 | } |
9769 | |
9770 | ::mlir::IntegerAttr StatefulWhileRegionOp::getParallelIterationsAttr() { |
9771 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getParallelIterationsAttrName()).cast<::mlir::IntegerAttr>(); |
9772 | } |
9773 | |
9774 | uint64_t StatefulWhileRegionOp::getParallelIterations() { |
9775 | auto attr = getParallelIterationsAttr(); |
9776 | return attr.getValue().getZExtValue(); |
9777 | } |
9778 | |
9779 | ::mlir::IntegerAttr StatefulWhileRegionOp::parallel_iterationsAttr() { |
9780 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getParallelIterationsAttrName()).cast<::mlir::IntegerAttr>(); |
9781 | } |
9782 | |
9783 | uint64_t StatefulWhileRegionOp::parallel_iterations() { |
9784 | auto attr = parallel_iterationsAttr(); |
9785 | return attr.getValue().getZExtValue(); |
9786 | } |
9787 | |
9788 | ::mlir::DictionaryAttr StatefulWhileRegionOp::getCondAttrsAttr() { |
9789 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getCondAttrsAttrName()).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
9790 | } |
9791 | |
9792 | ::llvm::Optional< ::mlir::DictionaryAttr > StatefulWhileRegionOp::getCondAttrs() { |
9793 | auto attr = getCondAttrsAttr(); |
9794 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
9795 | } |
9796 | |
9797 | ::mlir::DictionaryAttr StatefulWhileRegionOp::cond_attrsAttr() { |
9798 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getCondAttrsAttrName()).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
9799 | } |
9800 | |
9801 | ::llvm::Optional< ::mlir::DictionaryAttr > StatefulWhileRegionOp::cond_attrs() { |
9802 | auto attr = cond_attrsAttr(); |
9803 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
9804 | } |
9805 | |
9806 | ::mlir::DictionaryAttr StatefulWhileRegionOp::getBodyAttrsAttr() { |
9807 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getBodyAttrsAttrName()).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
9808 | } |
9809 | |
9810 | ::llvm::Optional< ::mlir::DictionaryAttr > StatefulWhileRegionOp::getBodyAttrs() { |
9811 | auto attr = getBodyAttrsAttr(); |
9812 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
9813 | } |
9814 | |
9815 | ::mlir::DictionaryAttr StatefulWhileRegionOp::body_attrsAttr() { |
9816 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getBodyAttrsAttrName()).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
9817 | } |
9818 | |
9819 | ::llvm::Optional< ::mlir::DictionaryAttr > StatefulWhileRegionOp::body_attrs() { |
9820 | auto attr = body_attrsAttr(); |
9821 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
9822 | } |
9823 | |
9824 | ::mlir::tfg::RegionAttr StatefulWhileRegionOp::getCondRegionAttrsAttr() { |
9825 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getCondRegionAttrsAttrName()).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
9826 | } |
9827 | |
9828 | ::llvm::Optional<::mlir::tfg::RegionAttr> StatefulWhileRegionOp::getCondRegionAttrs() { |
9829 | auto attr = getCondRegionAttrsAttr(); |
9830 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
9831 | } |
9832 | |
9833 | ::mlir::tfg::RegionAttr StatefulWhileRegionOp::cond_region_attrsAttr() { |
9834 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getCondRegionAttrsAttrName()).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
9835 | } |
9836 | |
9837 | ::llvm::Optional<::mlir::tfg::RegionAttr> StatefulWhileRegionOp::cond_region_attrs() { |
9838 | auto attr = cond_region_attrsAttr(); |
9839 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
9840 | } |
9841 | |
9842 | ::mlir::tfg::RegionAttr StatefulWhileRegionOp::getBodyRegionAttrsAttr() { |
9843 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getBodyRegionAttrsAttrName()).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
9844 | } |
9845 | |
9846 | ::llvm::Optional<::mlir::tfg::RegionAttr> StatefulWhileRegionOp::getBodyRegionAttrs() { |
9847 | auto attr = getBodyRegionAttrsAttr(); |
9848 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
9849 | } |
9850 | |
9851 | ::mlir::tfg::RegionAttr StatefulWhileRegionOp::body_region_attrsAttr() { |
9852 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getBodyRegionAttrsAttrName()).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
9853 | } |
9854 | |
9855 | ::llvm::Optional<::mlir::tfg::RegionAttr> StatefulWhileRegionOp::body_region_attrs() { |
9856 | auto attr = body_region_attrsAttr(); |
9857 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
9858 | } |
9859 | |
9860 | void StatefulWhileRegionOp::setParallelIterationsAttr(::mlir::IntegerAttr attr) { |
9861 | (*this)->setAttr(getParallelIterationsAttrName(), attr); |
9862 | } |
9863 | |
9864 | void StatefulWhileRegionOp::parallel_iterationsAttr(::mlir::IntegerAttr attr) { |
9865 | (*this)->setAttr(parallel_iterationsAttrName(), attr); |
9866 | } |
9867 | |
9868 | void StatefulWhileRegionOp::setCondAttrsAttr(::mlir::DictionaryAttr attr) { |
9869 | (*this)->setAttr(getCondAttrsAttrName(), attr); |
9870 | } |
9871 | |
9872 | void StatefulWhileRegionOp::cond_attrsAttr(::mlir::DictionaryAttr attr) { |
9873 | (*this)->setAttr(cond_attrsAttrName(), attr); |
9874 | } |
9875 | |
9876 | void StatefulWhileRegionOp::setBodyAttrsAttr(::mlir::DictionaryAttr attr) { |
9877 | (*this)->setAttr(getBodyAttrsAttrName(), attr); |
9878 | } |
9879 | |
9880 | void StatefulWhileRegionOp::body_attrsAttr(::mlir::DictionaryAttr attr) { |
9881 | (*this)->setAttr(body_attrsAttrName(), attr); |
9882 | } |
9883 | |
9884 | void StatefulWhileRegionOp::setCondRegionAttrsAttr(::mlir::tfg::RegionAttr attr) { |
9885 | (*this)->setAttr(getCondRegionAttrsAttrName(), attr); |
9886 | } |
9887 | |
9888 | void StatefulWhileRegionOp::cond_region_attrsAttr(::mlir::tfg::RegionAttr attr) { |
9889 | (*this)->setAttr(cond_region_attrsAttrName(), attr); |
9890 | } |
9891 | |
9892 | void StatefulWhileRegionOp::setBodyRegionAttrsAttr(::mlir::tfg::RegionAttr attr) { |
9893 | (*this)->setAttr(getBodyRegionAttrsAttrName(), attr); |
9894 | } |
9895 | |
9896 | void StatefulWhileRegionOp::body_region_attrsAttr(::mlir::tfg::RegionAttr attr) { |
9897 | (*this)->setAttr(body_region_attrsAttrName(), attr); |
9898 | } |
9899 | |
9900 | ::mlir::Attribute StatefulWhileRegionOp::removeCond_attrsAttr() { |
9901 | return (*this)->removeAttr(getCondAttrsAttrName()); |
9902 | } |
9903 | |
9904 | ::mlir::Attribute StatefulWhileRegionOp::removeBody_attrsAttr() { |
9905 | return (*this)->removeAttr(getBodyAttrsAttrName()); |
9906 | } |
9907 | |
9908 | ::mlir::Attribute StatefulWhileRegionOp::removeCond_region_attrsAttr() { |
9909 | return (*this)->removeAttr(getCondRegionAttrsAttrName()); |
9910 | } |
9911 | |
9912 | ::mlir::Attribute StatefulWhileRegionOp::removeBody_region_attrsAttr() { |
9913 | return (*this)->removeAttr(getBodyRegionAttrsAttrName()); |
9914 | } |
9915 | |
9916 | void StatefulWhileRegionOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange outs, ::mlir::Type ctl, ::mlir::ValueRange init, ::mlir::ValueRange ctls, ::mlir::IntegerAttr parallel_iterations, /*optional*/::mlir::DictionaryAttr cond_attrs, /*optional*/::mlir::DictionaryAttr body_attrs, /*optional*/::mlir::tfg::RegionAttr cond_region_attrs, /*optional*/::mlir::tfg::RegionAttr body_region_attrs) { |
9917 | odsState.addOperands(init); |
9918 | odsState.addOperands(ctls); |
9919 | odsState.addAttribute(getOperandSegmentSizesAttrName(odsState.name), odsBuilder.getDenseI32ArrayAttr({static_cast<int32_t>(init.size()), static_cast<int32_t>(ctls.size())})); |
9920 | odsState.addAttribute(getParallelIterationsAttrName(odsState.name), parallel_iterations); |
9921 | if (cond_attrs) { |
9922 | odsState.addAttribute(getCondAttrsAttrName(odsState.name), cond_attrs); |
9923 | } |
9924 | if (body_attrs) { |
9925 | odsState.addAttribute(getBodyAttrsAttrName(odsState.name), body_attrs); |
9926 | } |
9927 | if (cond_region_attrs) { |
9928 | odsState.addAttribute(getCondRegionAttrsAttrName(odsState.name), cond_region_attrs); |
9929 | } |
9930 | if (body_region_attrs) { |
9931 | odsState.addAttribute(getBodyRegionAttrsAttrName(odsState.name), body_region_attrs); |
9932 | } |
9933 | (void)odsState.addRegion(); |
9934 | (void)odsState.addRegion(); |
9935 | odsState.addTypes(outs); |
9936 | odsState.addTypes(ctl); |
9937 | } |
9938 | |
9939 | void StatefulWhileRegionOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange init, ::mlir::ValueRange ctls, ::mlir::IntegerAttr parallel_iterations, /*optional*/::mlir::DictionaryAttr cond_attrs, /*optional*/::mlir::DictionaryAttr body_attrs, /*optional*/::mlir::tfg::RegionAttr cond_region_attrs, /*optional*/::mlir::tfg::RegionAttr body_region_attrs) { |
9940 | odsState.addOperands(init); |
9941 | odsState.addOperands(ctls); |
9942 | odsState.addAttribute(getOperandSegmentSizesAttrName(odsState.name), odsBuilder.getDenseI32ArrayAttr({static_cast<int32_t>(init.size()), static_cast<int32_t>(ctls.size())})); |
9943 | odsState.addAttribute(getParallelIterationsAttrName(odsState.name), parallel_iterations); |
9944 | if (cond_attrs) { |
9945 | odsState.addAttribute(getCondAttrsAttrName(odsState.name), cond_attrs); |
9946 | } |
9947 | if (body_attrs) { |
9948 | odsState.addAttribute(getBodyAttrsAttrName(odsState.name), body_attrs); |
9949 | } |
9950 | if (cond_region_attrs) { |
9951 | odsState.addAttribute(getCondRegionAttrsAttrName(odsState.name), cond_region_attrs); |
9952 | } |
9953 | if (body_region_attrs) { |
9954 | odsState.addAttribute(getBodyRegionAttrsAttrName(odsState.name), body_region_attrs); |
9955 | } |
9956 | (void)odsState.addRegion(); |
9957 | (void)odsState.addRegion(); |
9958 | assert(resultTypes.size() >= 1u && "mismatched number of results" ); |
9959 | odsState.addTypes(resultTypes); |
9960 | } |
9961 | |
9962 | void StatefulWhileRegionOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange outs, ::mlir::Type ctl, ::mlir::ValueRange init, ::mlir::ValueRange ctls, uint64_t parallel_iterations, /*optional*/::mlir::DictionaryAttr cond_attrs, /*optional*/::mlir::DictionaryAttr body_attrs, /*optional*/::mlir::tfg::RegionAttr cond_region_attrs, /*optional*/::mlir::tfg::RegionAttr body_region_attrs) { |
9963 | odsState.addOperands(init); |
9964 | odsState.addOperands(ctls); |
9965 | odsState.addAttribute(getOperandSegmentSizesAttrName(odsState.name), odsBuilder.getDenseI32ArrayAttr({static_cast<int32_t>(init.size()), static_cast<int32_t>(ctls.size())})); |
9966 | odsState.addAttribute(getParallelIterationsAttrName(odsState.name), odsBuilder.getIntegerAttr(odsBuilder.getIntegerType(64), parallel_iterations)); |
9967 | if (cond_attrs) { |
9968 | odsState.addAttribute(getCondAttrsAttrName(odsState.name), cond_attrs); |
9969 | } |
9970 | if (body_attrs) { |
9971 | odsState.addAttribute(getBodyAttrsAttrName(odsState.name), body_attrs); |
9972 | } |
9973 | if (cond_region_attrs) { |
9974 | odsState.addAttribute(getCondRegionAttrsAttrName(odsState.name), cond_region_attrs); |
9975 | } |
9976 | if (body_region_attrs) { |
9977 | odsState.addAttribute(getBodyRegionAttrsAttrName(odsState.name), body_region_attrs); |
9978 | } |
9979 | (void)odsState.addRegion(); |
9980 | (void)odsState.addRegion(); |
9981 | odsState.addTypes(outs); |
9982 | odsState.addTypes(ctl); |
9983 | } |
9984 | |
9985 | void StatefulWhileRegionOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange init, ::mlir::ValueRange ctls, uint64_t parallel_iterations, /*optional*/::mlir::DictionaryAttr cond_attrs, /*optional*/::mlir::DictionaryAttr body_attrs, /*optional*/::mlir::tfg::RegionAttr cond_region_attrs, /*optional*/::mlir::tfg::RegionAttr body_region_attrs) { |
9986 | odsState.addOperands(init); |
9987 | odsState.addOperands(ctls); |
9988 | odsState.addAttribute(getOperandSegmentSizesAttrName(odsState.name), odsBuilder.getDenseI32ArrayAttr({static_cast<int32_t>(init.size()), static_cast<int32_t>(ctls.size())})); |
9989 | odsState.addAttribute(getParallelIterationsAttrName(odsState.name), odsBuilder.getIntegerAttr(odsBuilder.getIntegerType(64), parallel_iterations)); |
9990 | if (cond_attrs) { |
9991 | odsState.addAttribute(getCondAttrsAttrName(odsState.name), cond_attrs); |
9992 | } |
9993 | if (body_attrs) { |
9994 | odsState.addAttribute(getBodyAttrsAttrName(odsState.name), body_attrs); |
9995 | } |
9996 | if (cond_region_attrs) { |
9997 | odsState.addAttribute(getCondRegionAttrsAttrName(odsState.name), cond_region_attrs); |
9998 | } |
9999 | if (body_region_attrs) { |
10000 | odsState.addAttribute(getBodyRegionAttrsAttrName(odsState.name), body_region_attrs); |
10001 | } |
10002 | (void)odsState.addRegion(); |
10003 | (void)odsState.addRegion(); |
10004 | assert(resultTypes.size() >= 1u && "mismatched number of results" ); |
10005 | odsState.addTypes(resultTypes); |
10006 | } |
10007 | |
10008 | void StatefulWhileRegionOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { |
10009 | odsState.addOperands(operands); |
10010 | odsState.addAttributes(attributes); |
10011 | for (unsigned i = 0; i != 2; ++i) |
10012 | (void)odsState.addRegion(); |
10013 | assert(resultTypes.size() >= 1u && "mismatched number of return types" ); |
10014 | odsState.addTypes(resultTypes); |
10015 | } |
10016 | |
10017 | ::mlir::LogicalResult StatefulWhileRegionOp::verifyInvariantsImpl() { |
10018 | auto namedAttrRange = (*this)->getAttrs(); |
10019 | auto namedAttrIt = namedAttrRange.begin(); |
10020 | ::mlir::Attribute tblgen_operand_segment_sizes; |
10021 | ::mlir::Attribute tblgen_body_attrs; |
10022 | ::mlir::Attribute tblgen_body_region_attrs; |
10023 | ::mlir::Attribute tblgen_cond_attrs; |
10024 | ::mlir::Attribute tblgen_cond_region_attrs; |
10025 | while (true) { |
10026 | if (namedAttrIt == namedAttrRange.end()) |
10027 | return emitOpError("requires attribute 'operand_segment_sizes'" ); |
10028 | if (namedAttrIt->getName() == getOperandSegmentSizesAttrName()) { |
10029 | tblgen_operand_segment_sizes = namedAttrIt->getValue(); |
10030 | break; |
10031 | } |
10032 | else if (namedAttrIt->getName() == getBodyAttrsAttrName()) { |
10033 | tblgen_body_attrs = namedAttrIt->getValue(); |
10034 | } |
10035 | else if (namedAttrIt->getName() == getBodyRegionAttrsAttrName()) { |
10036 | tblgen_body_region_attrs = namedAttrIt->getValue(); |
10037 | } |
10038 | else if (namedAttrIt->getName() == getCondAttrsAttrName()) { |
10039 | tblgen_cond_attrs = namedAttrIt->getValue(); |
10040 | } |
10041 | else if (namedAttrIt->getName() == getCondRegionAttrsAttrName()) { |
10042 | tblgen_cond_region_attrs = namedAttrIt->getValue(); |
10043 | } |
10044 | ++namedAttrIt; |
10045 | } |
10046 | ::mlir::Attribute tblgen_parallel_iterations; |
10047 | while (true) { |
10048 | if (namedAttrIt == namedAttrRange.end()) |
10049 | return emitOpError("requires attribute 'parallel_iterations'" ); |
10050 | if (namedAttrIt->getName() == getParallelIterationsAttrName()) { |
10051 | tblgen_parallel_iterations = namedAttrIt->getValue(); |
10052 | break; |
10053 | } |
10054 | ++namedAttrIt; |
10055 | } |
10056 | |
10057 | { |
10058 | auto sizeAttr = tblgen_operand_segment_sizes.cast<::mlir::DenseI32ArrayAttr>(); |
10059 | auto numElements = sizeAttr.asArrayRef().size(); |
10060 | if (numElements != 2) |
10061 | return emitOpError("'operand_segment_sizes' attribute for specifying operand segments must have 2 " |
10062 | "elements, but got " ) << numElements; |
10063 | } |
10064 | |
10065 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops18(*this, tblgen_parallel_iterations, "parallel_iterations" ))) |
10066 | return ::mlir::failure(); |
10067 | |
10068 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops6(*this, tblgen_cond_attrs, "cond_attrs" ))) |
10069 | return ::mlir::failure(); |
10070 | |
10071 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops6(*this, tblgen_body_attrs, "body_attrs" ))) |
10072 | return ::mlir::failure(); |
10073 | |
10074 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops7(*this, tblgen_cond_region_attrs, "cond_region_attrs" ))) |
10075 | return ::mlir::failure(); |
10076 | |
10077 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops7(*this, tblgen_body_region_attrs, "body_region_attrs" ))) |
10078 | return ::mlir::failure(); |
10079 | { |
10080 | unsigned index = 0; (void)index; |
10081 | auto valueGroup0 = getODSOperands(0); |
10082 | |
10083 | for (auto v : valueGroup0) { |
10084 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops2(*this, v.getType(), "operand" , index++))) |
10085 | return ::mlir::failure(); |
10086 | } |
10087 | auto valueGroup1 = getODSOperands(1); |
10088 | |
10089 | for (auto v : valueGroup1) { |
10090 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops3(*this, v.getType(), "operand" , index++))) |
10091 | return ::mlir::failure(); |
10092 | } |
10093 | } |
10094 | { |
10095 | unsigned index = 0; (void)index; |
10096 | auto valueGroup0 = getODSResults(0); |
10097 | |
10098 | for (auto v : valueGroup0) { |
10099 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops2(*this, v.getType(), "result" , index++))) |
10100 | return ::mlir::failure(); |
10101 | } |
10102 | auto valueGroup1 = getODSResults(1); |
10103 | |
10104 | for (auto v : valueGroup1) { |
10105 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops3(*this, v.getType(), "result" , index++))) |
10106 | return ::mlir::failure(); |
10107 | } |
10108 | } |
10109 | { |
10110 | unsigned index = 0; (void)index; |
10111 | |
10112 | for (auto ®ion : ::llvm::makeMutableArrayRef((*this)->getRegion(0))) |
10113 | if (::mlir::failed(__mlir_ods_local_region_constraint_ops0(*this, region, "cond_region" , index++))) |
10114 | return ::mlir::failure(); |
10115 | |
10116 | for (auto ®ion : ::llvm::makeMutableArrayRef((*this)->getRegion(1))) |
10117 | if (::mlir::failed(__mlir_ods_local_region_constraint_ops0(*this, region, "body_region" , index++))) |
10118 | return ::mlir::failure(); |
10119 | } |
10120 | return ::mlir::success(); |
10121 | } |
10122 | |
10123 | ::mlir::LogicalResult StatefulWhileRegionOp::verifyInvariants() { |
10124 | if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) |
10125 | return ::mlir::success(); |
10126 | return ::mlir::failure(); |
10127 | } |
10128 | |
10129 | ::mlir::ParseResult StatefulWhileRegionOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { |
10130 | ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> initOperands; |
10131 | ::llvm::SMLoc initOperandsLoc; |
10132 | (void)initOperandsLoc; |
10133 | ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> ctlsOperands; |
10134 | ::llvm::SMLoc ctlsOperandsLoc; |
10135 | (void)ctlsOperandsLoc; |
10136 | std::unique_ptr<::mlir::Region> cond_regionRegion = std::make_unique<::mlir::Region>(); |
10137 | std::unique_ptr<::mlir::Region> body_regionRegion = std::make_unique<::mlir::Region>(); |
10138 | ::llvm::ArrayRef<::mlir::Type> initTypes; |
10139 | ::llvm::ArrayRef<::mlir::Type> outsTypes; |
10140 | if (::mlir::succeeded(parser.parseOptionalLParen())) { |
10141 | |
10142 | initOperandsLoc = parser.getCurrentLocation(); |
10143 | if (parser.parseOperandList(initOperands)) |
10144 | return ::mlir::failure(); |
10145 | if (parser.parseRParen()) |
10146 | return ::mlir::failure(); |
10147 | } |
10148 | if (::mlir::succeeded(parser.parseOptionalLSquare())) { |
10149 | |
10150 | ctlsOperandsLoc = parser.getCurrentLocation(); |
10151 | if (parser.parseOperandList(ctlsOperands)) |
10152 | return ::mlir::failure(); |
10153 | if (parser.parseRSquare()) |
10154 | return ::mlir::failure(); |
10155 | } |
10156 | |
10157 | if (parser.parseRegion(*cond_regionRegion)) |
10158 | return ::mlir::failure(); |
10159 | |
10160 | if (cond_regionRegion->empty()) cond_regionRegion->emplaceBlock(); |
10161 | if (parser.parseKeyword("do" )) |
10162 | return ::mlir::failure(); |
10163 | |
10164 | if (parser.parseRegion(*body_regionRegion)) |
10165 | return ::mlir::failure(); |
10166 | |
10167 | if (body_regionRegion->empty()) body_regionRegion->emplaceBlock(); |
10168 | if (parser.parseOptionalAttrDict(result.attributes)) |
10169 | return ::mlir::failure(); |
10170 | if (::mlir::succeeded(parser.parseOptionalColon())) { |
10171 | |
10172 | ::mlir::FunctionType init__outs_functionType; |
10173 | if (parser.parseType(init__outs_functionType)) |
10174 | return ::mlir::failure(); |
10175 | initTypes = init__outs_functionType.getInputs(); |
10176 | outsTypes = init__outs_functionType.getResults(); |
10177 | } |
10178 | result.addRegion(std::move(cond_regionRegion)); |
10179 | result.addRegion(std::move(body_regionRegion)); |
10180 | result.addAttribute("operand_segment_sizes" , parser.getBuilder().getDenseI32ArrayAttr({static_cast<int32_t>(initOperands.size()), static_cast<int32_t>(ctlsOperands.size())})); |
10181 | ::mlir::Type odsBuildableType0 = parser.getBuilder().getType<::mlir::tf_type::ControlType>(); |
10182 | result.addTypes(outsTypes); |
10183 | result.addTypes(odsBuildableType0); |
10184 | if (parser.resolveOperands(initOperands, initTypes, initOperandsLoc, result.operands)) |
10185 | return ::mlir::failure(); |
10186 | if (parser.resolveOperands(ctlsOperands, odsBuildableType0, ctlsOperandsLoc, result.operands)) |
10187 | return ::mlir::failure(); |
10188 | return ::mlir::success(); |
10189 | } |
10190 | |
10191 | void StatefulWhileRegionOp::print(::mlir::OpAsmPrinter &_odsPrinter) { |
10192 | if (!getInit().empty()) { |
10193 | _odsPrinter << "(" ; |
10194 | _odsPrinter << getInit(); |
10195 | _odsPrinter << ")" ; |
10196 | } |
10197 | if (!getCtls().empty()) { |
10198 | _odsPrinter << ' ' << "[" ; |
10199 | _odsPrinter << getCtls(); |
10200 | _odsPrinter << "]" ; |
10201 | } |
10202 | _odsPrinter << ' '; |
10203 | _odsPrinter.printRegion(getCondRegion()); |
10204 | _odsPrinter << ' ' << "do" ; |
10205 | _odsPrinter << ' '; |
10206 | _odsPrinter.printRegion(getBodyRegion()); |
10207 | _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), /*elidedAttrs=*/{"operand_segment_sizes" , }); |
10208 | if (!getInit().empty()) { |
10209 | _odsPrinter << ' ' << ":" ; |
10210 | _odsPrinter << ' '; |
10211 | _odsPrinter.printFunctionalType(getInit().getTypes(), getOuts().getTypes()); |
10212 | } |
10213 | } |
10214 | |
10215 | StringRef StatefulWhileRegionOp::getDefaultDialect() { return "tfg" ; } |
10216 | void StatefulWhileRegionOp::getAsmResultNames(OpAsmSetValueNameFn setNameFn) { |
10217 | GenericGetAsmResultNames(*this, setNameFn); |
10218 | } |
10219 | |
10220 | ConditionOp StatefulWhileRegionOp::cond_condition() { |
10221 | return cast<ConditionOp>(cond_block().getTerminator()); |
10222 | } |
10223 | YieldOp StatefulWhileRegionOp::body_yield() { |
10224 | return cast<YieldOp>(body_block().getTerminator()); |
10225 | } |
10226 | |
10227 | OperandRange StatefulWhileRegionOp::getSuccessorEntryOperands( |
10228 | Optional<unsigned> index) { |
10229 | return init(); |
10230 | } |
10231 | void StatefulWhileRegionOp::getSuccessorRegions( |
10232 | Optional<unsigned> index, ArrayRef<Attribute> operands, |
10233 | SmallVectorImpl<RegionSuccessor> ®ions) { |
10234 | return GetWhileLikeRegionOpSuccessorRegions(*this, index, operands, |
10235 | regions); |
10236 | } |
10237 | |
10238 | LogicalResult StatefulWhileRegionOp::verify() { return VerifyWhileLikeRegionOp(*this); } |
10239 | |
10240 | BlockArgument StatefulWhileRegionOp::getDataValueOf(BlockArgument ctl) { |
10241 | return GetLoopRegionDataOf(ctl); |
10242 | } |
10243 | BlockArgument StatefulWhileRegionOp::getControlTokenOf(BlockArgument data) { |
10244 | return GetLoopRegionControlOf(data); |
10245 | } |
10246 | BlockArgument StatefulWhileRegionOp::getDataValue(Region ®ion, unsigned idx) { |
10247 | return GetLoopRegionDataArgs(region)[idx]; |
10248 | } |
10249 | BlockArgument StatefulWhileRegionOp::getControlToken(Region ®ion, unsigned idx) { |
10250 | return GetLoopRegionControlTokens(region)[idx]; |
10251 | } |
10252 | } // namespace tfg |
10253 | } // namespace mlir |
10254 | MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::tfg::StatefulWhileRegionOp) |
10255 | |
10256 | namespace mlir { |
10257 | namespace tfg { |
10258 | |
10259 | //===----------------------------------------------------------------------===// |
10260 | // ::mlir::tfg::StatelessCaseOp definitions |
10261 | //===----------------------------------------------------------------------===// |
10262 | |
10263 | StatelessCaseOpAdaptor::StatelessCaseOpAdaptor(::mlir::ValueRange values, ::mlir::DictionaryAttr attrs, ::mlir::RegionRange regions) : odsOperands(values), odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) |
10264 | odsOpName.emplace("tfg.StatelessCase" , odsAttrs.getContext()); |
10265 | } |
10266 | |
10267 | StatelessCaseOpAdaptor::StatelessCaseOpAdaptor(StatelessCaseOp op) : odsOperands(op->getOperands()), odsAttrs(op->getAttrDictionary()), odsRegions(op->getRegions()), odsOpName(op->getName()) {} |
10268 | |
10269 | ::mlir::ValueRange StatelessCaseOpAdaptor::getOperands() { |
10270 | return odsOperands; |
10271 | } |
10272 | |
10273 | std::pair<unsigned, unsigned> StatelessCaseOpAdaptor::getODSOperandIndexAndLength(unsigned index) { |
10274 | bool isVariadic[] = {false, true}; |
10275 | int prevVariadicCount = 0; |
10276 | for (unsigned i = 0; i < index; ++i) |
10277 | if (isVariadic[i]) ++prevVariadicCount; |
10278 | |
10279 | // Calculate how many dynamic values a static variadic operand corresponds to. |
10280 | // This assumes all static variadic operands have the same dynamic value count. |
10281 | int variadicSize = (odsOperands.size() - 1) / 1; |
10282 | // `index` passed in as the parameter is the static index which counts each |
10283 | // operand (variadic or not) as size 1. So here for each previous static variadic |
10284 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
10285 | // value pack for this static operand starts. |
10286 | int start = index + (variadicSize - 1) * prevVariadicCount; |
10287 | int size = isVariadic[index] ? variadicSize : 1; |
10288 | return {start, size}; |
10289 | } |
10290 | |
10291 | ::mlir::ValueRange StatelessCaseOpAdaptor::getODSOperands(unsigned index) { |
10292 | auto valueRange = getODSOperandIndexAndLength(index); |
10293 | return {std::next(odsOperands.begin(), valueRange.first), |
10294 | std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; |
10295 | } |
10296 | |
10297 | ::mlir::Value StatelessCaseOpAdaptor::getBranchIndex() { |
10298 | return *getODSOperands(0).begin(); |
10299 | } |
10300 | |
10301 | ::mlir::Value StatelessCaseOpAdaptor::branch_index() { |
10302 | return *getODSOperands(0).begin(); |
10303 | } |
10304 | |
10305 | ::mlir::ValueRange StatelessCaseOpAdaptor::getArgs() { |
10306 | return getODSOperands(1); |
10307 | } |
10308 | |
10309 | ::mlir::ValueRange StatelessCaseOpAdaptor::args() { |
10310 | return getODSOperands(1); |
10311 | } |
10312 | |
10313 | ::mlir::DictionaryAttr StatelessCaseOpAdaptor::getAttributes() { |
10314 | return odsAttrs; |
10315 | } |
10316 | |
10317 | ::mlir::ArrayAttr StatelessCaseOpAdaptor::getBranchesAttr() { |
10318 | assert(odsAttrs && "no attributes when constructing adapter" ); |
10319 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, StatelessCaseOp::getBranchesAttrName(*odsOpName)).cast<::mlir::ArrayAttr>(); |
10320 | return attr; |
10321 | } |
10322 | |
10323 | ::mlir::ArrayAttr StatelessCaseOpAdaptor::getBranches() { |
10324 | auto attr = getBranchesAttr(); |
10325 | return attr; |
10326 | } |
10327 | |
10328 | ::mlir::ArrayAttr StatelessCaseOpAdaptor::branchesAttr() { |
10329 | assert(odsAttrs && "no attributes when constructing adapter" ); |
10330 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, StatelessCaseOp::getBranchesAttrName(*odsOpName)).cast<::mlir::ArrayAttr>(); |
10331 | return attr; |
10332 | } |
10333 | |
10334 | ::mlir::ArrayAttr StatelessCaseOpAdaptor::branches() { |
10335 | auto attr = branchesAttr(); |
10336 | return attr; |
10337 | } |
10338 | |
10339 | ::mlir::ArrayAttr StatelessCaseOpAdaptor::getTinAttr() { |
10340 | assert(odsAttrs && "no attributes when constructing adapter" ); |
10341 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 1, StatelessCaseOp::getTinAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
10342 | return attr; |
10343 | } |
10344 | |
10345 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessCaseOpAdaptor::getTin() { |
10346 | auto attr = getTinAttr(); |
10347 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
10348 | } |
10349 | |
10350 | ::mlir::ArrayAttr StatelessCaseOpAdaptor::TinAttr() { |
10351 | assert(odsAttrs && "no attributes when constructing adapter" ); |
10352 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 1, StatelessCaseOp::getTinAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
10353 | return attr; |
10354 | } |
10355 | |
10356 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessCaseOpAdaptor::Tin() { |
10357 | auto attr = TinAttr(); |
10358 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
10359 | } |
10360 | |
10361 | ::mlir::ArrayAttr StatelessCaseOpAdaptor::getToutAttr() { |
10362 | assert(odsAttrs && "no attributes when constructing adapter" ); |
10363 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 1, StatelessCaseOp::getToutAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
10364 | return attr; |
10365 | } |
10366 | |
10367 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessCaseOpAdaptor::getTout() { |
10368 | auto attr = getToutAttr(); |
10369 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
10370 | } |
10371 | |
10372 | ::mlir::ArrayAttr StatelessCaseOpAdaptor::ToutAttr() { |
10373 | assert(odsAttrs && "no attributes when constructing adapter" ); |
10374 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 1, StatelessCaseOp::getToutAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
10375 | return attr; |
10376 | } |
10377 | |
10378 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessCaseOpAdaptor::Tout() { |
10379 | auto attr = ToutAttr(); |
10380 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
10381 | } |
10382 | |
10383 | ::mlir::ArrayAttr StatelessCaseOpAdaptor::getOutputShapesAttr() { |
10384 | assert(odsAttrs && "no attributes when constructing adapter" ); |
10385 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 0, StatelessCaseOp::getOutputShapesAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
10386 | return attr; |
10387 | } |
10388 | |
10389 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessCaseOpAdaptor::getOutputShapes() { |
10390 | auto attr = getOutputShapesAttr(); |
10391 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
10392 | } |
10393 | |
10394 | ::mlir::ArrayAttr StatelessCaseOpAdaptor::output_shapesAttr() { |
10395 | assert(odsAttrs && "no attributes when constructing adapter" ); |
10396 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 0, StatelessCaseOp::getOutputShapesAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
10397 | return attr; |
10398 | } |
10399 | |
10400 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessCaseOpAdaptor::output_shapes() { |
10401 | auto attr = output_shapesAttr(); |
10402 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
10403 | } |
10404 | |
10405 | ::mlir::LogicalResult StatelessCaseOpAdaptor::verify(::mlir::Location loc) { |
10406 | auto namedAttrRange = odsAttrs; |
10407 | auto namedAttrIt = namedAttrRange.begin(); |
10408 | ::mlir::Attribute tblgen_branches; |
10409 | ::mlir::Attribute tblgen_Tin; |
10410 | ::mlir::Attribute tblgen_Tout; |
10411 | while (true) { |
10412 | if (namedAttrIt == namedAttrRange.end()) |
10413 | return emitError(loc, "'tfg.StatelessCase' op " "requires attribute 'branches'" ); |
10414 | if (namedAttrIt->getName() == StatelessCaseOp::getBranchesAttrName(*odsOpName)) { |
10415 | tblgen_branches = namedAttrIt->getValue(); |
10416 | break; |
10417 | } |
10418 | else if (namedAttrIt->getName() == StatelessCaseOp::getTinAttrName(*odsOpName)) { |
10419 | tblgen_Tin = namedAttrIt->getValue(); |
10420 | } |
10421 | else if (namedAttrIt->getName() == StatelessCaseOp::getToutAttrName(*odsOpName)) { |
10422 | tblgen_Tout = namedAttrIt->getValue(); |
10423 | } |
10424 | ++namedAttrIt; |
10425 | } |
10426 | ::mlir::Attribute tblgen_output_shapes; |
10427 | while (true) { |
10428 | if (namedAttrIt == namedAttrRange.end()) { |
10429 | break; |
10430 | } |
10431 | else if (namedAttrIt->getName() == StatelessCaseOp::getOutputShapesAttrName(*odsOpName)) { |
10432 | tblgen_output_shapes = namedAttrIt->getValue(); |
10433 | } |
10434 | ++namedAttrIt; |
10435 | } |
10436 | |
10437 | if (tblgen_branches && !(((tblgen_branches.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_branches.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && ((attr.isa<::mlir::tf_type::FuncAttr>())); })))) |
10438 | return emitError(loc, "'tfg.StatelessCase' op " "attribute 'branches' failed to satisfy constraint: an array of functions" ); |
10439 | |
10440 | if (tblgen_Tin && !(((tblgen_Tin.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_Tin.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && (((attr.isa<::mlir::TypeAttr>())) && ((attr.cast<::mlir::TypeAttr>().getValue().isa<::mlir::Type>()))); })))) |
10441 | return emitError(loc, "'tfg.StatelessCase' op " "attribute 'Tin' failed to satisfy constraint: type array attribute" ); |
10442 | |
10443 | if (tblgen_Tout && !(((tblgen_Tout.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_Tout.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && (((attr.isa<::mlir::TypeAttr>())) && ((attr.cast<::mlir::TypeAttr>().getValue().isa<::mlir::Type>()))); })))) |
10444 | return emitError(loc, "'tfg.StatelessCase' op " "attribute 'Tout' failed to satisfy constraint: type array attribute" ); |
10445 | |
10446 | if (tblgen_output_shapes && !(((tblgen_output_shapes.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_output_shapes.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && ((attr.isa<::mlir::tf_type::ShapeAttr>())); })))) |
10447 | return emitError(loc, "'tfg.StatelessCase' op " "attribute 'output_shapes' failed to satisfy constraint: An array of shapes." ); |
10448 | return ::mlir::success(); |
10449 | } |
10450 | |
10451 | void StatelessCaseOp::getAsmResultNames(::mlir::OpAsmSetValueNameFn setNameFn) { |
10452 | auto resultGroup0 = getODSResults(0); |
10453 | if (!resultGroup0.empty()) |
10454 | setNameFn(*resultGroup0.begin(), "outs" ); |
10455 | auto resultGroup1 = getODSResults(1); |
10456 | if (!resultGroup1.empty()) |
10457 | setNameFn(*resultGroup1.begin(), "ctl" ); |
10458 | } |
10459 | |
10460 | std::pair<unsigned, unsigned> StatelessCaseOp::getODSOperandIndexAndLength(unsigned index) { |
10461 | bool isVariadic[] = {false, true}; |
10462 | int prevVariadicCount = 0; |
10463 | for (unsigned i = 0; i < index; ++i) |
10464 | if (isVariadic[i]) ++prevVariadicCount; |
10465 | |
10466 | // Calculate how many dynamic values a static variadic operand corresponds to. |
10467 | // This assumes all static variadic operands have the same dynamic value count. |
10468 | int variadicSize = (getOperation()->getNumOperands() - 1) / 1; |
10469 | // `index` passed in as the parameter is the static index which counts each |
10470 | // operand (variadic or not) as size 1. So here for each previous static variadic |
10471 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
10472 | // value pack for this static operand starts. |
10473 | int start = index + (variadicSize - 1) * prevVariadicCount; |
10474 | int size = isVariadic[index] ? variadicSize : 1; |
10475 | return {start, size}; |
10476 | } |
10477 | |
10478 | ::mlir::Operation::operand_range StatelessCaseOp::getODSOperands(unsigned index) { |
10479 | auto valueRange = getODSOperandIndexAndLength(index); |
10480 | return {std::next(getOperation()->operand_begin(), valueRange.first), |
10481 | std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; |
10482 | } |
10483 | |
10484 | ::mlir::Value StatelessCaseOp::getBranchIndex() { |
10485 | return *getODSOperands(0).begin(); |
10486 | } |
10487 | |
10488 | ::mlir::Value StatelessCaseOp::branch_index() { |
10489 | return *getODSOperands(0).begin(); |
10490 | } |
10491 | |
10492 | ::mlir::Operation::operand_range StatelessCaseOp::getArgs() { |
10493 | return getODSOperands(1); |
10494 | } |
10495 | |
10496 | ::mlir::Operation::operand_range StatelessCaseOp::args() { |
10497 | return getODSOperands(1); |
10498 | } |
10499 | |
10500 | ::mlir::MutableOperandRange StatelessCaseOp::getBranchIndexMutable() { |
10501 | auto range = getODSOperandIndexAndLength(0); |
10502 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
10503 | return mutableRange; |
10504 | } |
10505 | |
10506 | ::mlir::MutableOperandRange StatelessCaseOp::branch_indexMutable() { |
10507 | auto range = getODSOperandIndexAndLength(0); |
10508 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
10509 | return mutableRange; |
10510 | } |
10511 | |
10512 | ::mlir::MutableOperandRange StatelessCaseOp::getArgsMutable() { |
10513 | auto range = getODSOperandIndexAndLength(1); |
10514 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
10515 | return mutableRange; |
10516 | } |
10517 | |
10518 | ::mlir::MutableOperandRange StatelessCaseOp::argsMutable() { |
10519 | auto range = getODSOperandIndexAndLength(1); |
10520 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
10521 | return mutableRange; |
10522 | } |
10523 | |
10524 | std::pair<unsigned, unsigned> StatelessCaseOp::getODSResultIndexAndLength(unsigned index) { |
10525 | bool isVariadic[] = {true, false}; |
10526 | int prevVariadicCount = 0; |
10527 | for (unsigned i = 0; i < index; ++i) |
10528 | if (isVariadic[i]) ++prevVariadicCount; |
10529 | |
10530 | // Calculate how many dynamic values a static variadic operand corresponds to. |
10531 | // This assumes all static variadic operands have the same dynamic value count. |
10532 | int variadicSize = (getOperation()->getNumResults() - 1) / 1; |
10533 | // `index` passed in as the parameter is the static index which counts each |
10534 | // operand (variadic or not) as size 1. So here for each previous static variadic |
10535 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
10536 | // value pack for this static operand starts. |
10537 | int start = index + (variadicSize - 1) * prevVariadicCount; |
10538 | int size = isVariadic[index] ? variadicSize : 1; |
10539 | return {start, size}; |
10540 | } |
10541 | |
10542 | ::mlir::Operation::result_range StatelessCaseOp::getODSResults(unsigned index) { |
10543 | auto valueRange = getODSResultIndexAndLength(index); |
10544 | return {std::next(getOperation()->result_begin(), valueRange.first), |
10545 | std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; |
10546 | } |
10547 | |
10548 | ::mlir::Operation::result_range StatelessCaseOp::getOuts() { |
10549 | return getODSResults(0); |
10550 | } |
10551 | |
10552 | ::mlir::Operation::result_range StatelessCaseOp::outs() { |
10553 | return getODSResults(0); |
10554 | } |
10555 | |
10556 | ::mlir::TypedValue<::mlir::tf_type::ControlType> StatelessCaseOp::getCtl() { |
10557 | return *getODSResults(1).begin(); |
10558 | } |
10559 | |
10560 | ::mlir::TypedValue<::mlir::tf_type::ControlType> StatelessCaseOp::ctl() { |
10561 | return *getODSResults(1).begin(); |
10562 | } |
10563 | |
10564 | ::mlir::ArrayAttr StatelessCaseOp::getBranchesAttr() { |
10565 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getBranchesAttrName()).cast<::mlir::ArrayAttr>(); |
10566 | } |
10567 | |
10568 | ::mlir::ArrayAttr StatelessCaseOp::getBranches() { |
10569 | auto attr = getBranchesAttr(); |
10570 | return attr; |
10571 | } |
10572 | |
10573 | ::mlir::ArrayAttr StatelessCaseOp::branchesAttr() { |
10574 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getBranchesAttrName()).cast<::mlir::ArrayAttr>(); |
10575 | } |
10576 | |
10577 | ::mlir::ArrayAttr StatelessCaseOp::branches() { |
10578 | auto attr = branchesAttr(); |
10579 | return attr; |
10580 | } |
10581 | |
10582 | ::mlir::ArrayAttr StatelessCaseOp::getTinAttr() { |
10583 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getTinAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
10584 | } |
10585 | |
10586 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessCaseOp::getTin() { |
10587 | auto attr = getTinAttr(); |
10588 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
10589 | } |
10590 | |
10591 | ::mlir::ArrayAttr StatelessCaseOp::TinAttr() { |
10592 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getTinAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
10593 | } |
10594 | |
10595 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessCaseOp::Tin() { |
10596 | auto attr = TinAttr(); |
10597 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
10598 | } |
10599 | |
10600 | ::mlir::ArrayAttr StatelessCaseOp::getToutAttr() { |
10601 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getToutAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
10602 | } |
10603 | |
10604 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessCaseOp::getTout() { |
10605 | auto attr = getToutAttr(); |
10606 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
10607 | } |
10608 | |
10609 | ::mlir::ArrayAttr StatelessCaseOp::ToutAttr() { |
10610 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getToutAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
10611 | } |
10612 | |
10613 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessCaseOp::Tout() { |
10614 | auto attr = ToutAttr(); |
10615 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
10616 | } |
10617 | |
10618 | ::mlir::ArrayAttr StatelessCaseOp::getOutputShapesAttr() { |
10619 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getOutputShapesAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
10620 | } |
10621 | |
10622 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessCaseOp::getOutputShapes() { |
10623 | auto attr = getOutputShapesAttr(); |
10624 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
10625 | } |
10626 | |
10627 | ::mlir::ArrayAttr StatelessCaseOp::output_shapesAttr() { |
10628 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getOutputShapesAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
10629 | } |
10630 | |
10631 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessCaseOp::output_shapes() { |
10632 | auto attr = output_shapesAttr(); |
10633 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
10634 | } |
10635 | |
10636 | void StatelessCaseOp::setBranchesAttr(::mlir::ArrayAttr attr) { |
10637 | (*this)->setAttr(getBranchesAttrName(), attr); |
10638 | } |
10639 | |
10640 | void StatelessCaseOp::branchesAttr(::mlir::ArrayAttr attr) { |
10641 | (*this)->setAttr(branchesAttrName(), attr); |
10642 | } |
10643 | |
10644 | void StatelessCaseOp::setTinAttr(::mlir::ArrayAttr attr) { |
10645 | (*this)->setAttr(getTinAttrName(), attr); |
10646 | } |
10647 | |
10648 | void StatelessCaseOp::TinAttr(::mlir::ArrayAttr attr) { |
10649 | (*this)->setAttr(TinAttrName(), attr); |
10650 | } |
10651 | |
10652 | void StatelessCaseOp::setToutAttr(::mlir::ArrayAttr attr) { |
10653 | (*this)->setAttr(getToutAttrName(), attr); |
10654 | } |
10655 | |
10656 | void StatelessCaseOp::ToutAttr(::mlir::ArrayAttr attr) { |
10657 | (*this)->setAttr(ToutAttrName(), attr); |
10658 | } |
10659 | |
10660 | void StatelessCaseOp::setOutputShapesAttr(::mlir::ArrayAttr attr) { |
10661 | (*this)->setAttr(getOutputShapesAttrName(), attr); |
10662 | } |
10663 | |
10664 | void StatelessCaseOp::output_shapesAttr(::mlir::ArrayAttr attr) { |
10665 | (*this)->setAttr(output_shapesAttrName(), attr); |
10666 | } |
10667 | |
10668 | ::mlir::Attribute StatelessCaseOp::removeTinAttr() { |
10669 | return (*this)->removeAttr(getTinAttrName()); |
10670 | } |
10671 | |
10672 | ::mlir::Attribute StatelessCaseOp::removeToutAttr() { |
10673 | return (*this)->removeAttr(getToutAttrName()); |
10674 | } |
10675 | |
10676 | ::mlir::Attribute StatelessCaseOp::removeOutput_shapesAttr() { |
10677 | return (*this)->removeAttr(getOutputShapesAttrName()); |
10678 | } |
10679 | |
10680 | void StatelessCaseOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, TypeRange results, Value branch_index, ValueRange args, ArrayAttr branches) { |
10681 | build(odsBuilder, odsState, results, branch_index, args, branches, |
10682 | /*Tin=*/{}, /*Tout=*/{}, /*output_shapes=*/{}); |
10683 | |
10684 | } |
10685 | |
10686 | void StatelessCaseOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange outs, ::mlir::Type ctl, ::mlir::Value branch_index, ::mlir::ValueRange args, ::mlir::ArrayAttr branches, /*optional*/::mlir::ArrayAttr Tin, /*optional*/::mlir::ArrayAttr Tout, /*optional*/::mlir::ArrayAttr output_shapes) { |
10687 | odsState.addOperands(branch_index); |
10688 | odsState.addOperands(args); |
10689 | odsState.addAttribute(getBranchesAttrName(odsState.name), branches); |
10690 | if (Tin) { |
10691 | odsState.addAttribute(getTinAttrName(odsState.name), Tin); |
10692 | } |
10693 | if (Tout) { |
10694 | odsState.addAttribute(getToutAttrName(odsState.name), Tout); |
10695 | } |
10696 | if (output_shapes) { |
10697 | odsState.addAttribute(getOutputShapesAttrName(odsState.name), output_shapes); |
10698 | } |
10699 | odsState.addTypes(outs); |
10700 | odsState.addTypes(ctl); |
10701 | } |
10702 | |
10703 | void StatelessCaseOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value branch_index, ::mlir::ValueRange args, ::mlir::ArrayAttr branches, /*optional*/::mlir::ArrayAttr Tin, /*optional*/::mlir::ArrayAttr Tout, /*optional*/::mlir::ArrayAttr output_shapes) { |
10704 | odsState.addOperands(branch_index); |
10705 | odsState.addOperands(args); |
10706 | odsState.addAttribute(getBranchesAttrName(odsState.name), branches); |
10707 | if (Tin) { |
10708 | odsState.addAttribute(getTinAttrName(odsState.name), Tin); |
10709 | } |
10710 | if (Tout) { |
10711 | odsState.addAttribute(getToutAttrName(odsState.name), Tout); |
10712 | } |
10713 | if (output_shapes) { |
10714 | odsState.addAttribute(getOutputShapesAttrName(odsState.name), output_shapes); |
10715 | } |
10716 | assert(resultTypes.size() >= 1u && "mismatched number of results" ); |
10717 | odsState.addTypes(resultTypes); |
10718 | } |
10719 | |
10720 | void StatelessCaseOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { |
10721 | assert(operands.size() >= 1u && "mismatched number of parameters" ); |
10722 | odsState.addOperands(operands); |
10723 | odsState.addAttributes(attributes); |
10724 | assert(resultTypes.size() >= 1u && "mismatched number of return types" ); |
10725 | odsState.addTypes(resultTypes); |
10726 | } |
10727 | |
10728 | ::mlir::LogicalResult StatelessCaseOp::verifyInvariantsImpl() { |
10729 | auto namedAttrRange = (*this)->getAttrs(); |
10730 | auto namedAttrIt = namedAttrRange.begin(); |
10731 | ::mlir::Attribute tblgen_branches; |
10732 | ::mlir::Attribute tblgen_Tin; |
10733 | ::mlir::Attribute tblgen_Tout; |
10734 | while (true) { |
10735 | if (namedAttrIt == namedAttrRange.end()) |
10736 | return emitOpError("requires attribute 'branches'" ); |
10737 | if (namedAttrIt->getName() == getBranchesAttrName()) { |
10738 | tblgen_branches = namedAttrIt->getValue(); |
10739 | break; |
10740 | } |
10741 | else if (namedAttrIt->getName() == getTinAttrName()) { |
10742 | tblgen_Tin = namedAttrIt->getValue(); |
10743 | } |
10744 | else if (namedAttrIt->getName() == getToutAttrName()) { |
10745 | tblgen_Tout = namedAttrIt->getValue(); |
10746 | } |
10747 | ++namedAttrIt; |
10748 | } |
10749 | ::mlir::Attribute tblgen_output_shapes; |
10750 | while (true) { |
10751 | if (namedAttrIt == namedAttrRange.end()) { |
10752 | break; |
10753 | } |
10754 | else if (namedAttrIt->getName() == getOutputShapesAttrName()) { |
10755 | tblgen_output_shapes = namedAttrIt->getValue(); |
10756 | } |
10757 | ++namedAttrIt; |
10758 | } |
10759 | |
10760 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops0(*this, tblgen_branches, "branches" ))) |
10761 | return ::mlir::failure(); |
10762 | |
10763 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops1(*this, tblgen_Tin, "Tin" ))) |
10764 | return ::mlir::failure(); |
10765 | |
10766 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops1(*this, tblgen_Tout, "Tout" ))) |
10767 | return ::mlir::failure(); |
10768 | |
10769 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops2(*this, tblgen_output_shapes, "output_shapes" ))) |
10770 | return ::mlir::failure(); |
10771 | { |
10772 | unsigned index = 0; (void)index; |
10773 | auto valueGroup0 = getODSOperands(0); |
10774 | |
10775 | for (auto v : valueGroup0) { |
10776 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops0(*this, v.getType(), "operand" , index++))) |
10777 | return ::mlir::failure(); |
10778 | } |
10779 | auto valueGroup1 = getODSOperands(1); |
10780 | |
10781 | for (auto v : valueGroup1) { |
10782 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops1(*this, v.getType(), "operand" , index++))) |
10783 | return ::mlir::failure(); |
10784 | } |
10785 | } |
10786 | { |
10787 | unsigned index = 0; (void)index; |
10788 | auto valueGroup0 = getODSResults(0); |
10789 | |
10790 | for (auto v : valueGroup0) { |
10791 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops2(*this, v.getType(), "result" , index++))) |
10792 | return ::mlir::failure(); |
10793 | } |
10794 | auto valueGroup1 = getODSResults(1); |
10795 | |
10796 | for (auto v : valueGroup1) { |
10797 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops3(*this, v.getType(), "result" , index++))) |
10798 | return ::mlir::failure(); |
10799 | } |
10800 | } |
10801 | return ::mlir::success(); |
10802 | } |
10803 | |
10804 | ::mlir::LogicalResult StatelessCaseOp::verifyInvariants() { |
10805 | return verifyInvariantsImpl(); |
10806 | } |
10807 | |
10808 | LogicalResult StatelessCaseOp::verifySymbolUses( |
10809 | SymbolTableCollection &symbol_table) { |
10810 | return VerifyCaseLikeOp(*this, symbol_table); |
10811 | } |
10812 | } // namespace tfg |
10813 | } // namespace mlir |
10814 | MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::tfg::StatelessCaseOp) |
10815 | |
10816 | namespace mlir { |
10817 | namespace tfg { |
10818 | |
10819 | //===----------------------------------------------------------------------===// |
10820 | // ::mlir::tfg::StatelessCaseRegionOp definitions |
10821 | //===----------------------------------------------------------------------===// |
10822 | |
10823 | StatelessCaseRegionOpAdaptor::StatelessCaseRegionOpAdaptor(::mlir::ValueRange values, ::mlir::DictionaryAttr attrs, ::mlir::RegionRange regions) : odsOperands(values), odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) |
10824 | odsOpName.emplace("tfg.StatelessCaseRegion" , odsAttrs.getContext()); |
10825 | } |
10826 | |
10827 | StatelessCaseRegionOpAdaptor::StatelessCaseRegionOpAdaptor(StatelessCaseRegionOp op) : odsOperands(op->getOperands()), odsAttrs(op->getAttrDictionary()), odsRegions(op->getRegions()), odsOpName(op->getName()) {} |
10828 | |
10829 | ::mlir::ValueRange StatelessCaseRegionOpAdaptor::getOperands() { |
10830 | return odsOperands; |
10831 | } |
10832 | |
10833 | std::pair<unsigned, unsigned> StatelessCaseRegionOpAdaptor::getODSOperandIndexAndLength(unsigned index) { |
10834 | bool isVariadic[] = {false, true}; |
10835 | int prevVariadicCount = 0; |
10836 | for (unsigned i = 0; i < index; ++i) |
10837 | if (isVariadic[i]) ++prevVariadicCount; |
10838 | |
10839 | // Calculate how many dynamic values a static variadic operand corresponds to. |
10840 | // This assumes all static variadic operands have the same dynamic value count. |
10841 | int variadicSize = (odsOperands.size() - 1) / 1; |
10842 | // `index` passed in as the parameter is the static index which counts each |
10843 | // operand (variadic or not) as size 1. So here for each previous static variadic |
10844 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
10845 | // value pack for this static operand starts. |
10846 | int start = index + (variadicSize - 1) * prevVariadicCount; |
10847 | int size = isVariadic[index] ? variadicSize : 1; |
10848 | return {start, size}; |
10849 | } |
10850 | |
10851 | ::mlir::ValueRange StatelessCaseRegionOpAdaptor::getODSOperands(unsigned index) { |
10852 | auto valueRange = getODSOperandIndexAndLength(index); |
10853 | return {std::next(odsOperands.begin(), valueRange.first), |
10854 | std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; |
10855 | } |
10856 | |
10857 | ::mlir::Value StatelessCaseRegionOpAdaptor::getBranchIndex() { |
10858 | return *getODSOperands(0).begin(); |
10859 | } |
10860 | |
10861 | ::mlir::Value StatelessCaseRegionOpAdaptor::branch_index() { |
10862 | return *getODSOperands(0).begin(); |
10863 | } |
10864 | |
10865 | ::mlir::ValueRange StatelessCaseRegionOpAdaptor::getCtls() { |
10866 | return getODSOperands(1); |
10867 | } |
10868 | |
10869 | ::mlir::ValueRange StatelessCaseRegionOpAdaptor::ctls() { |
10870 | return getODSOperands(1); |
10871 | } |
10872 | |
10873 | ::mlir::DictionaryAttr StatelessCaseRegionOpAdaptor::getAttributes() { |
10874 | return odsAttrs; |
10875 | } |
10876 | |
10877 | ::mlir::ArrayAttr StatelessCaseRegionOpAdaptor::getBranchAttrsAttr() { |
10878 | assert(odsAttrs && "no attributes when constructing adapter" ); |
10879 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, StatelessCaseRegionOp::getBranchAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
10880 | return attr; |
10881 | } |
10882 | |
10883 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessCaseRegionOpAdaptor::getBranchAttrs() { |
10884 | auto attr = getBranchAttrsAttr(); |
10885 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
10886 | } |
10887 | |
10888 | ::mlir::ArrayAttr StatelessCaseRegionOpAdaptor::branch_attrsAttr() { |
10889 | assert(odsAttrs && "no attributes when constructing adapter" ); |
10890 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, StatelessCaseRegionOp::getBranchAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
10891 | return attr; |
10892 | } |
10893 | |
10894 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessCaseRegionOpAdaptor::branch_attrs() { |
10895 | auto attr = branch_attrsAttr(); |
10896 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
10897 | } |
10898 | |
10899 | ::mlir::ArrayAttr StatelessCaseRegionOpAdaptor::getRegionAttrsAttr() { |
10900 | assert(odsAttrs && "no attributes when constructing adapter" ); |
10901 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, StatelessCaseRegionOp::getRegionAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
10902 | return attr; |
10903 | } |
10904 | |
10905 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessCaseRegionOpAdaptor::getRegionAttrs() { |
10906 | auto attr = getRegionAttrsAttr(); |
10907 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
10908 | } |
10909 | |
10910 | ::mlir::ArrayAttr StatelessCaseRegionOpAdaptor::region_attrsAttr() { |
10911 | assert(odsAttrs && "no attributes when constructing adapter" ); |
10912 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, StatelessCaseRegionOp::getRegionAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
10913 | return attr; |
10914 | } |
10915 | |
10916 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessCaseRegionOpAdaptor::region_attrs() { |
10917 | auto attr = region_attrsAttr(); |
10918 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
10919 | } |
10920 | |
10921 | ::mlir::RegionRange StatelessCaseRegionOpAdaptor::getRegions() { |
10922 | return odsRegions; |
10923 | } |
10924 | |
10925 | ::mlir::RegionRange StatelessCaseRegionOpAdaptor::getBranches() { |
10926 | return odsRegions.drop_front(0); |
10927 | } |
10928 | |
10929 | ::mlir::RegionRange StatelessCaseRegionOpAdaptor::branches() { |
10930 | return odsRegions.drop_front(0); |
10931 | } |
10932 | |
10933 | ::mlir::LogicalResult StatelessCaseRegionOpAdaptor::verify(::mlir::Location loc) { |
10934 | auto namedAttrRange = odsAttrs; |
10935 | auto namedAttrIt = namedAttrRange.begin(); |
10936 | ::mlir::Attribute tblgen_branch_attrs; |
10937 | ::mlir::Attribute tblgen_region_attrs; |
10938 | while (true) { |
10939 | if (namedAttrIt == namedAttrRange.end()) { |
10940 | break; |
10941 | } |
10942 | else if (namedAttrIt->getName() == StatelessCaseRegionOp::getBranchAttrsAttrName(*odsOpName)) { |
10943 | tblgen_branch_attrs = namedAttrIt->getValue(); |
10944 | } |
10945 | else if (namedAttrIt->getName() == StatelessCaseRegionOp::getRegionAttrsAttrName(*odsOpName)) { |
10946 | tblgen_region_attrs = namedAttrIt->getValue(); |
10947 | } |
10948 | ++namedAttrIt; |
10949 | } |
10950 | |
10951 | if (tblgen_branch_attrs && !(((tblgen_branch_attrs.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_branch_attrs.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && ((attr.isa<::mlir::DictionaryAttr>())); })))) |
10952 | return emitError(loc, "'tfg.StatelessCaseRegion' op " "attribute 'branch_attrs' failed to satisfy constraint: an array of dictionaries" ); |
10953 | |
10954 | if (tblgen_region_attrs && !(((tblgen_region_attrs.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_region_attrs.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && ((attr.isa<::mlir::tfg::RegionAttr>())); })))) |
10955 | return emitError(loc, "'tfg.StatelessCaseRegion' op " "attribute 'region_attrs' failed to satisfy constraint: case region preserved attributes" ); |
10956 | return ::mlir::success(); |
10957 | } |
10958 | |
10959 | std::pair<unsigned, unsigned> StatelessCaseRegionOp::getODSOperandIndexAndLength(unsigned index) { |
10960 | bool isVariadic[] = {false, true}; |
10961 | int prevVariadicCount = 0; |
10962 | for (unsigned i = 0; i < index; ++i) |
10963 | if (isVariadic[i]) ++prevVariadicCount; |
10964 | |
10965 | // Calculate how many dynamic values a static variadic operand corresponds to. |
10966 | // This assumes all static variadic operands have the same dynamic value count. |
10967 | int variadicSize = (getOperation()->getNumOperands() - 1) / 1; |
10968 | // `index` passed in as the parameter is the static index which counts each |
10969 | // operand (variadic or not) as size 1. So here for each previous static variadic |
10970 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
10971 | // value pack for this static operand starts. |
10972 | int start = index + (variadicSize - 1) * prevVariadicCount; |
10973 | int size = isVariadic[index] ? variadicSize : 1; |
10974 | return {start, size}; |
10975 | } |
10976 | |
10977 | ::mlir::Operation::operand_range StatelessCaseRegionOp::getODSOperands(unsigned index) { |
10978 | auto valueRange = getODSOperandIndexAndLength(index); |
10979 | return {std::next(getOperation()->operand_begin(), valueRange.first), |
10980 | std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; |
10981 | } |
10982 | |
10983 | ::mlir::TypedValue<::mlir::TensorType> StatelessCaseRegionOp::getBranchIndex() { |
10984 | return *getODSOperands(0).begin(); |
10985 | } |
10986 | |
10987 | ::mlir::TypedValue<::mlir::TensorType> StatelessCaseRegionOp::branch_index() { |
10988 | return *getODSOperands(0).begin(); |
10989 | } |
10990 | |
10991 | ::mlir::Operation::operand_range StatelessCaseRegionOp::getCtls() { |
10992 | return getODSOperands(1); |
10993 | } |
10994 | |
10995 | ::mlir::Operation::operand_range StatelessCaseRegionOp::ctls() { |
10996 | return getODSOperands(1); |
10997 | } |
10998 | |
10999 | ::mlir::MutableOperandRange StatelessCaseRegionOp::getBranchIndexMutable() { |
11000 | auto range = getODSOperandIndexAndLength(0); |
11001 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
11002 | return mutableRange; |
11003 | } |
11004 | |
11005 | ::mlir::MutableOperandRange StatelessCaseRegionOp::branch_indexMutable() { |
11006 | auto range = getODSOperandIndexAndLength(0); |
11007 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
11008 | return mutableRange; |
11009 | } |
11010 | |
11011 | ::mlir::MutableOperandRange StatelessCaseRegionOp::getCtlsMutable() { |
11012 | auto range = getODSOperandIndexAndLength(1); |
11013 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
11014 | return mutableRange; |
11015 | } |
11016 | |
11017 | ::mlir::MutableOperandRange StatelessCaseRegionOp::ctlsMutable() { |
11018 | auto range = getODSOperandIndexAndLength(1); |
11019 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
11020 | return mutableRange; |
11021 | } |
11022 | |
11023 | std::pair<unsigned, unsigned> StatelessCaseRegionOp::getODSResultIndexAndLength(unsigned index) { |
11024 | bool isVariadic[] = {true, false}; |
11025 | int prevVariadicCount = 0; |
11026 | for (unsigned i = 0; i < index; ++i) |
11027 | if (isVariadic[i]) ++prevVariadicCount; |
11028 | |
11029 | // Calculate how many dynamic values a static variadic operand corresponds to. |
11030 | // This assumes all static variadic operands have the same dynamic value count. |
11031 | int variadicSize = (getOperation()->getNumResults() - 1) / 1; |
11032 | // `index` passed in as the parameter is the static index which counts each |
11033 | // operand (variadic or not) as size 1. So here for each previous static variadic |
11034 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
11035 | // value pack for this static operand starts. |
11036 | int start = index + (variadicSize - 1) * prevVariadicCount; |
11037 | int size = isVariadic[index] ? variadicSize : 1; |
11038 | return {start, size}; |
11039 | } |
11040 | |
11041 | ::mlir::Operation::result_range StatelessCaseRegionOp::getODSResults(unsigned index) { |
11042 | auto valueRange = getODSResultIndexAndLength(index); |
11043 | return {std::next(getOperation()->result_begin(), valueRange.first), |
11044 | std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; |
11045 | } |
11046 | |
11047 | ::mlir::Operation::result_range StatelessCaseRegionOp::getOuts() { |
11048 | return getODSResults(0); |
11049 | } |
11050 | |
11051 | ::mlir::Operation::result_range StatelessCaseRegionOp::outs() { |
11052 | return getODSResults(0); |
11053 | } |
11054 | |
11055 | ::mlir::TypedValue<::mlir::tf_type::ControlType> StatelessCaseRegionOp::getCtl() { |
11056 | return *getODSResults(1).begin(); |
11057 | } |
11058 | |
11059 | ::mlir::TypedValue<::mlir::tf_type::ControlType> StatelessCaseRegionOp::ctl() { |
11060 | return *getODSResults(1).begin(); |
11061 | } |
11062 | |
11063 | ::mlir::MutableArrayRef<::mlir::Region> StatelessCaseRegionOp::getBranches() { |
11064 | return (*this)->getRegions().drop_front(0); |
11065 | } |
11066 | |
11067 | ::mlir::MutableArrayRef<::mlir::Region> StatelessCaseRegionOp::branches() { |
11068 | return (*this)->getRegions().drop_front(0); |
11069 | } |
11070 | |
11071 | ::mlir::ArrayAttr StatelessCaseRegionOp::getBranchAttrsAttr() { |
11072 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getBranchAttrsAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
11073 | } |
11074 | |
11075 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessCaseRegionOp::getBranchAttrs() { |
11076 | auto attr = getBranchAttrsAttr(); |
11077 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
11078 | } |
11079 | |
11080 | ::mlir::ArrayAttr StatelessCaseRegionOp::branch_attrsAttr() { |
11081 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getBranchAttrsAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
11082 | } |
11083 | |
11084 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessCaseRegionOp::branch_attrs() { |
11085 | auto attr = branch_attrsAttr(); |
11086 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
11087 | } |
11088 | |
11089 | ::mlir::ArrayAttr StatelessCaseRegionOp::getRegionAttrsAttr() { |
11090 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getRegionAttrsAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
11091 | } |
11092 | |
11093 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessCaseRegionOp::getRegionAttrs() { |
11094 | auto attr = getRegionAttrsAttr(); |
11095 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
11096 | } |
11097 | |
11098 | ::mlir::ArrayAttr StatelessCaseRegionOp::region_attrsAttr() { |
11099 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getRegionAttrsAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
11100 | } |
11101 | |
11102 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessCaseRegionOp::region_attrs() { |
11103 | auto attr = region_attrsAttr(); |
11104 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
11105 | } |
11106 | |
11107 | void StatelessCaseRegionOp::setBranchAttrsAttr(::mlir::ArrayAttr attr) { |
11108 | (*this)->setAttr(getBranchAttrsAttrName(), attr); |
11109 | } |
11110 | |
11111 | void StatelessCaseRegionOp::branch_attrsAttr(::mlir::ArrayAttr attr) { |
11112 | (*this)->setAttr(branch_attrsAttrName(), attr); |
11113 | } |
11114 | |
11115 | void StatelessCaseRegionOp::setRegionAttrsAttr(::mlir::ArrayAttr attr) { |
11116 | (*this)->setAttr(getRegionAttrsAttrName(), attr); |
11117 | } |
11118 | |
11119 | void StatelessCaseRegionOp::region_attrsAttr(::mlir::ArrayAttr attr) { |
11120 | (*this)->setAttr(region_attrsAttrName(), attr); |
11121 | } |
11122 | |
11123 | ::mlir::Attribute StatelessCaseRegionOp::removeBranch_attrsAttr() { |
11124 | return (*this)->removeAttr(getBranchAttrsAttrName()); |
11125 | } |
11126 | |
11127 | ::mlir::Attribute StatelessCaseRegionOp::removeRegion_attrsAttr() { |
11128 | return (*this)->removeAttr(getRegionAttrsAttrName()); |
11129 | } |
11130 | |
11131 | void StatelessCaseRegionOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange outs, ::mlir::Type ctl, ::mlir::Value branch_index, ::mlir::ValueRange ctls, /*optional*/::mlir::ArrayAttr branch_attrs, /*optional*/::mlir::ArrayAttr region_attrs, unsigned branchesCount) { |
11132 | odsState.addOperands(branch_index); |
11133 | odsState.addOperands(ctls); |
11134 | if (branch_attrs) { |
11135 | odsState.addAttribute(getBranchAttrsAttrName(odsState.name), branch_attrs); |
11136 | } |
11137 | if (region_attrs) { |
11138 | odsState.addAttribute(getRegionAttrsAttrName(odsState.name), region_attrs); |
11139 | } |
11140 | for (unsigned i = 0; i < branchesCount; ++i) |
11141 | (void)odsState.addRegion(); |
11142 | odsState.addTypes(outs); |
11143 | odsState.addTypes(ctl); |
11144 | } |
11145 | |
11146 | void StatelessCaseRegionOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value branch_index, ::mlir::ValueRange ctls, /*optional*/::mlir::ArrayAttr branch_attrs, /*optional*/::mlir::ArrayAttr region_attrs, unsigned branchesCount) { |
11147 | odsState.addOperands(branch_index); |
11148 | odsState.addOperands(ctls); |
11149 | if (branch_attrs) { |
11150 | odsState.addAttribute(getBranchAttrsAttrName(odsState.name), branch_attrs); |
11151 | } |
11152 | if (region_attrs) { |
11153 | odsState.addAttribute(getRegionAttrsAttrName(odsState.name), region_attrs); |
11154 | } |
11155 | for (unsigned i = 0; i < branchesCount; ++i) |
11156 | (void)odsState.addRegion(); |
11157 | assert(resultTypes.size() >= 1u && "mismatched number of results" ); |
11158 | odsState.addTypes(resultTypes); |
11159 | } |
11160 | |
11161 | void StatelessCaseRegionOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes, unsigned numRegions) { |
11162 | assert(operands.size() >= 1u && "mismatched number of parameters" ); |
11163 | odsState.addOperands(operands); |
11164 | odsState.addAttributes(attributes); |
11165 | for (unsigned i = 0; i != numRegions; ++i) |
11166 | (void)odsState.addRegion(); |
11167 | assert(resultTypes.size() >= 1u && "mismatched number of return types" ); |
11168 | odsState.addTypes(resultTypes); |
11169 | } |
11170 | |
11171 | ::mlir::LogicalResult StatelessCaseRegionOp::verifyInvariantsImpl() { |
11172 | auto namedAttrRange = (*this)->getAttrs(); |
11173 | auto namedAttrIt = namedAttrRange.begin(); |
11174 | ::mlir::Attribute tblgen_branch_attrs; |
11175 | ::mlir::Attribute tblgen_region_attrs; |
11176 | while (true) { |
11177 | if (namedAttrIt == namedAttrRange.end()) { |
11178 | break; |
11179 | } |
11180 | else if (namedAttrIt->getName() == getBranchAttrsAttrName()) { |
11181 | tblgen_branch_attrs = namedAttrIt->getValue(); |
11182 | } |
11183 | else if (namedAttrIt->getName() == getRegionAttrsAttrName()) { |
11184 | tblgen_region_attrs = namedAttrIt->getValue(); |
11185 | } |
11186 | ++namedAttrIt; |
11187 | } |
11188 | |
11189 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops3(*this, tblgen_branch_attrs, "branch_attrs" ))) |
11190 | return ::mlir::failure(); |
11191 | |
11192 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops4(*this, tblgen_region_attrs, "region_attrs" ))) |
11193 | return ::mlir::failure(); |
11194 | { |
11195 | unsigned index = 0; (void)index; |
11196 | auto valueGroup0 = getODSOperands(0); |
11197 | |
11198 | for (auto v : valueGroup0) { |
11199 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops4(*this, v.getType(), "operand" , index++))) |
11200 | return ::mlir::failure(); |
11201 | } |
11202 | auto valueGroup1 = getODSOperands(1); |
11203 | |
11204 | for (auto v : valueGroup1) { |
11205 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops3(*this, v.getType(), "operand" , index++))) |
11206 | return ::mlir::failure(); |
11207 | } |
11208 | } |
11209 | { |
11210 | unsigned index = 0; (void)index; |
11211 | auto valueGroup0 = getODSResults(0); |
11212 | |
11213 | for (auto v : valueGroup0) { |
11214 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops2(*this, v.getType(), "result" , index++))) |
11215 | return ::mlir::failure(); |
11216 | } |
11217 | auto valueGroup1 = getODSResults(1); |
11218 | |
11219 | for (auto v : valueGroup1) { |
11220 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops3(*this, v.getType(), "result" , index++))) |
11221 | return ::mlir::failure(); |
11222 | } |
11223 | } |
11224 | { |
11225 | unsigned index = 0; (void)index; |
11226 | |
11227 | for (auto ®ion : getBranches()) |
11228 | if (::mlir::failed(__mlir_ods_local_region_constraint_ops0(*this, region, "branches" , index++))) |
11229 | return ::mlir::failure(); |
11230 | } |
11231 | return ::mlir::success(); |
11232 | } |
11233 | |
11234 | ::mlir::LogicalResult StatelessCaseRegionOp::verifyInvariants() { |
11235 | if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) |
11236 | return ::mlir::success(); |
11237 | return ::mlir::failure(); |
11238 | } |
11239 | |
11240 | ::mlir::ParseResult StatelessCaseRegionOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { |
11241 | ::mlir::OpAsmParser::UnresolvedOperand branch_indexRawOperands[1]; |
11242 | ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> branch_indexOperands(branch_indexRawOperands); ::llvm::SMLoc branch_indexOperandsLoc; |
11243 | (void)branch_indexOperandsLoc; |
11244 | ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> ctlsOperands; |
11245 | ::llvm::SMLoc ctlsOperandsLoc; |
11246 | (void)ctlsOperandsLoc; |
11247 | ::llvm::SmallVector<std::unique_ptr<::mlir::Region>, 2> branchesRegions; |
11248 | ::llvm::ArrayRef<::mlir::Type> branch_indexTypes; |
11249 | ::llvm::ArrayRef<::mlir::Type> outsTypes; |
11250 | |
11251 | branch_indexOperandsLoc = parser.getCurrentLocation(); |
11252 | if (parser.parseOperand(branch_indexRawOperands[0])) |
11253 | return ::mlir::failure(); |
11254 | if (::mlir::succeeded(parser.parseOptionalLSquare())) { |
11255 | |
11256 | ctlsOperandsLoc = parser.getCurrentLocation(); |
11257 | if (parser.parseOperandList(ctlsOperands)) |
11258 | return ::mlir::failure(); |
11259 | if (parser.parseRSquare()) |
11260 | return ::mlir::failure(); |
11261 | } |
11262 | |
11263 | { |
11264 | std::unique_ptr<::mlir::Region> region; |
11265 | auto firstRegionResult = parser.parseOptionalRegion(region); |
11266 | if (firstRegionResult.has_value()) { |
11267 | if (failed(*firstRegionResult)) |
11268 | return ::mlir::failure(); |
11269 | branchesRegions.emplace_back(std::move(region)); |
11270 | |
11271 | // Parse any trailing regions. |
11272 | while (succeeded(parser.parseOptionalComma())) { |
11273 | region = std::make_unique<::mlir::Region>(); |
11274 | if (parser.parseRegion(*region)) |
11275 | return ::mlir::failure(); |
11276 | branchesRegions.emplace_back(std::move(region)); |
11277 | } |
11278 | } |
11279 | } |
11280 | |
11281 | for (auto ®ion : branchesRegions) |
11282 | if (region->empty()) region->emplaceBlock(); |
11283 | if (parser.parseOptionalAttrDict(result.attributes)) |
11284 | return ::mlir::failure(); |
11285 | if (parser.parseColon()) |
11286 | return ::mlir::failure(); |
11287 | |
11288 | ::mlir::FunctionType branch_index__outs_functionType; |
11289 | if (parser.parseType(branch_index__outs_functionType)) |
11290 | return ::mlir::failure(); |
11291 | branch_indexTypes = branch_index__outs_functionType.getInputs(); |
11292 | outsTypes = branch_index__outs_functionType.getResults(); |
11293 | result.addRegions(branchesRegions); |
11294 | ::mlir::Type odsBuildableType0 = parser.getBuilder().getType<::mlir::tf_type::ControlType>(); |
11295 | result.addTypes(outsTypes); |
11296 | result.addTypes(odsBuildableType0); |
11297 | if (parser.resolveOperands(branch_indexOperands, branch_indexTypes, branch_indexOperandsLoc, result.operands)) |
11298 | return ::mlir::failure(); |
11299 | if (parser.resolveOperands(ctlsOperands, odsBuildableType0, ctlsOperandsLoc, result.operands)) |
11300 | return ::mlir::failure(); |
11301 | return ::mlir::success(); |
11302 | } |
11303 | |
11304 | void StatelessCaseRegionOp::print(::mlir::OpAsmPrinter &_odsPrinter) { |
11305 | _odsPrinter << ' '; |
11306 | _odsPrinter << getBranchIndex(); |
11307 | if (!getCtls().empty()) { |
11308 | _odsPrinter << ' '; |
11309 | _odsPrinter << "[" ; |
11310 | _odsPrinter << getCtls(); |
11311 | _odsPrinter << "]" ; |
11312 | } |
11313 | _odsPrinter << ' '; |
11314 | llvm::interleaveComma(getBranches(), _odsPrinter, [&](::mlir::Region ®ion) { |
11315 | _odsPrinter.printRegion(region); |
11316 | }); |
11317 | _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), /*elidedAttrs=*/{}); |
11318 | _odsPrinter << ' ' << ":" ; |
11319 | _odsPrinter << ' '; |
11320 | _odsPrinter.printFunctionalType(::llvm::ArrayRef<::mlir::Type>(getBranchIndex().getType()), getOuts().getTypes()); |
11321 | } |
11322 | |
11323 | StringRef StatelessCaseRegionOp::getDefaultDialect() { return "tfg" ; } |
11324 | void StatelessCaseRegionOp::getAsmResultNames(OpAsmSetValueNameFn setNameFn) { |
11325 | GenericGetAsmResultNames(*this, setNameFn); |
11326 | } |
11327 | |
11328 | YieldOp StatelessCaseRegionOp::branch_yield(unsigned idx) { |
11329 | return cast<YieldOp>(branch_block(idx).getTerminator()); |
11330 | } |
11331 | |
11332 | void StatelessCaseRegionOp::getSuccessorRegions( |
11333 | Optional<unsigned> index, ArrayRef<Attribute> operands, |
11334 | SmallVectorImpl<RegionSuccessor> ®ions) { |
11335 | GetCaseLikeRegionOpSuccessorRegions(*this, index, operands, regions); |
11336 | } |
11337 | void StatelessCaseRegionOp::getRegionInvocationBounds( |
11338 | ArrayRef<Attribute> operands, |
11339 | SmallVectorImpl<InvocationBounds> &invocationBounds) { |
11340 | invocationBounds.append(getNumRegions(), /*Elt=*/{0, 1}); |
11341 | } |
11342 | |
11343 | LogicalResult StatelessCaseRegionOp::verify() { return VerifyCaseLikeRegionOp(*this); } |
11344 | |
11345 | BlockArgument StatelessCaseRegionOp::getDataValueOf(BlockArgument ctl) { |
11346 | return GetLoopRegionDataOf(ctl); |
11347 | } |
11348 | BlockArgument StatelessCaseRegionOp::getControlTokenOf(BlockArgument data) { |
11349 | return GetLoopRegionControlOf(data); |
11350 | } |
11351 | BlockArgument StatelessCaseRegionOp::getDataValue(Region ®ion, unsigned idx) { |
11352 | return GetLoopRegionDataArgs(region)[idx]; |
11353 | } |
11354 | BlockArgument StatelessCaseRegionOp::getControlToken(Region ®ion, unsigned idx) { |
11355 | return GetLoopRegionControlTokens(region)[idx]; |
11356 | } |
11357 | } // namespace tfg |
11358 | } // namespace mlir |
11359 | MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::tfg::StatelessCaseRegionOp) |
11360 | |
11361 | namespace mlir { |
11362 | namespace tfg { |
11363 | |
11364 | //===----------------------------------------------------------------------===// |
11365 | // ::mlir::tfg::StatelessIfOp definitions |
11366 | //===----------------------------------------------------------------------===// |
11367 | |
11368 | StatelessIfOpAdaptor::StatelessIfOpAdaptor(::mlir::ValueRange values, ::mlir::DictionaryAttr attrs, ::mlir::RegionRange regions) : odsOperands(values), odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) |
11369 | odsOpName.emplace("tfg.StatelessIf" , odsAttrs.getContext()); |
11370 | } |
11371 | |
11372 | StatelessIfOpAdaptor::StatelessIfOpAdaptor(StatelessIfOp op) : odsOperands(op->getOperands()), odsAttrs(op->getAttrDictionary()), odsRegions(op->getRegions()), odsOpName(op->getName()) {} |
11373 | |
11374 | ::mlir::ValueRange StatelessIfOpAdaptor::getOperands() { |
11375 | return odsOperands; |
11376 | } |
11377 | |
11378 | std::pair<unsigned, unsigned> StatelessIfOpAdaptor::getODSOperandIndexAndLength(unsigned index) { |
11379 | bool isVariadic[] = {false, true}; |
11380 | int prevVariadicCount = 0; |
11381 | for (unsigned i = 0; i < index; ++i) |
11382 | if (isVariadic[i]) ++prevVariadicCount; |
11383 | |
11384 | // Calculate how many dynamic values a static variadic operand corresponds to. |
11385 | // This assumes all static variadic operands have the same dynamic value count. |
11386 | int variadicSize = (odsOperands.size() - 1) / 1; |
11387 | // `index` passed in as the parameter is the static index which counts each |
11388 | // operand (variadic or not) as size 1. So here for each previous static variadic |
11389 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
11390 | // value pack for this static operand starts. |
11391 | int start = index + (variadicSize - 1) * prevVariadicCount; |
11392 | int size = isVariadic[index] ? variadicSize : 1; |
11393 | return {start, size}; |
11394 | } |
11395 | |
11396 | ::mlir::ValueRange StatelessIfOpAdaptor::getODSOperands(unsigned index) { |
11397 | auto valueRange = getODSOperandIndexAndLength(index); |
11398 | return {std::next(odsOperands.begin(), valueRange.first), |
11399 | std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; |
11400 | } |
11401 | |
11402 | ::mlir::Value StatelessIfOpAdaptor::getCond() { |
11403 | return *getODSOperands(0).begin(); |
11404 | } |
11405 | |
11406 | ::mlir::Value StatelessIfOpAdaptor::cond() { |
11407 | return *getODSOperands(0).begin(); |
11408 | } |
11409 | |
11410 | ::mlir::ValueRange StatelessIfOpAdaptor::getArgs() { |
11411 | return getODSOperands(1); |
11412 | } |
11413 | |
11414 | ::mlir::ValueRange StatelessIfOpAdaptor::args() { |
11415 | return getODSOperands(1); |
11416 | } |
11417 | |
11418 | ::mlir::DictionaryAttr StatelessIfOpAdaptor::getAttributes() { |
11419 | return odsAttrs; |
11420 | } |
11421 | |
11422 | ::mlir::tf_type::FuncAttr StatelessIfOpAdaptor::getThenBranchAttr() { |
11423 | assert(odsAttrs && "no attributes when constructing adapter" ); |
11424 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 0, StatelessIfOp::getThenBranchAttrName(*odsOpName)).cast<::mlir::tf_type::FuncAttr>(); |
11425 | return attr; |
11426 | } |
11427 | |
11428 | ::mlir::tf_type::FuncAttr StatelessIfOpAdaptor::getThenBranch() { |
11429 | auto attr = getThenBranchAttr(); |
11430 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
11431 | } |
11432 | |
11433 | ::mlir::tf_type::FuncAttr StatelessIfOpAdaptor::then_branchAttr() { |
11434 | assert(odsAttrs && "no attributes when constructing adapter" ); |
11435 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 0, StatelessIfOp::getThenBranchAttrName(*odsOpName)).cast<::mlir::tf_type::FuncAttr>(); |
11436 | return attr; |
11437 | } |
11438 | |
11439 | ::mlir::tf_type::FuncAttr StatelessIfOpAdaptor::then_branch() { |
11440 | auto attr = then_branchAttr(); |
11441 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
11442 | } |
11443 | |
11444 | ::mlir::tf_type::FuncAttr StatelessIfOpAdaptor::getElseBranchAttr() { |
11445 | assert(odsAttrs && "no attributes when constructing adapter" ); |
11446 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 1, StatelessIfOp::getElseBranchAttrName(*odsOpName)).cast<::mlir::tf_type::FuncAttr>(); |
11447 | return attr; |
11448 | } |
11449 | |
11450 | ::mlir::tf_type::FuncAttr StatelessIfOpAdaptor::getElseBranch() { |
11451 | auto attr = getElseBranchAttr(); |
11452 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
11453 | } |
11454 | |
11455 | ::mlir::tf_type::FuncAttr StatelessIfOpAdaptor::else_branchAttr() { |
11456 | assert(odsAttrs && "no attributes when constructing adapter" ); |
11457 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 1, StatelessIfOp::getElseBranchAttrName(*odsOpName)).cast<::mlir::tf_type::FuncAttr>(); |
11458 | return attr; |
11459 | } |
11460 | |
11461 | ::mlir::tf_type::FuncAttr StatelessIfOpAdaptor::else_branch() { |
11462 | auto attr = else_branchAttr(); |
11463 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
11464 | } |
11465 | |
11466 | ::mlir::TypeAttr StatelessIfOpAdaptor::getTcondAttr() { |
11467 | assert(odsAttrs && "no attributes when constructing adapter" ); |
11468 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, StatelessIfOp::getTcondAttrName(*odsOpName)).dyn_cast_or_null<::mlir::TypeAttr>(); |
11469 | return attr; |
11470 | } |
11471 | |
11472 | ::llvm::Optional<::mlir::Type> StatelessIfOpAdaptor::getTcond() { |
11473 | auto attr = getTcondAttr(); |
11474 | return attr ? ::llvm::Optional<::mlir::Type>(attr.getValue().cast<::mlir::Type>()) : (::llvm::None); |
11475 | } |
11476 | |
11477 | ::mlir::TypeAttr StatelessIfOpAdaptor::TcondAttr() { |
11478 | assert(odsAttrs && "no attributes when constructing adapter" ); |
11479 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, StatelessIfOp::getTcondAttrName(*odsOpName)).dyn_cast_or_null<::mlir::TypeAttr>(); |
11480 | return attr; |
11481 | } |
11482 | |
11483 | ::llvm::Optional<::mlir::Type> StatelessIfOpAdaptor::Tcond() { |
11484 | auto attr = TcondAttr(); |
11485 | return attr ? ::llvm::Optional<::mlir::Type>(attr.getValue().cast<::mlir::Type>()) : (::llvm::None); |
11486 | } |
11487 | |
11488 | ::mlir::ArrayAttr StatelessIfOpAdaptor::getTinAttr() { |
11489 | assert(odsAttrs && "no attributes when constructing adapter" ); |
11490 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, StatelessIfOp::getTinAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
11491 | return attr; |
11492 | } |
11493 | |
11494 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessIfOpAdaptor::getTin() { |
11495 | auto attr = getTinAttr(); |
11496 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
11497 | } |
11498 | |
11499 | ::mlir::ArrayAttr StatelessIfOpAdaptor::TinAttr() { |
11500 | assert(odsAttrs && "no attributes when constructing adapter" ); |
11501 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, StatelessIfOp::getTinAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
11502 | return attr; |
11503 | } |
11504 | |
11505 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessIfOpAdaptor::Tin() { |
11506 | auto attr = TinAttr(); |
11507 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
11508 | } |
11509 | |
11510 | ::mlir::ArrayAttr StatelessIfOpAdaptor::getToutAttr() { |
11511 | assert(odsAttrs && "no attributes when constructing adapter" ); |
11512 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, StatelessIfOp::getToutAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
11513 | return attr; |
11514 | } |
11515 | |
11516 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessIfOpAdaptor::getTout() { |
11517 | auto attr = getToutAttr(); |
11518 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
11519 | } |
11520 | |
11521 | ::mlir::ArrayAttr StatelessIfOpAdaptor::ToutAttr() { |
11522 | assert(odsAttrs && "no attributes when constructing adapter" ); |
11523 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, StatelessIfOp::getToutAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
11524 | return attr; |
11525 | } |
11526 | |
11527 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessIfOpAdaptor::Tout() { |
11528 | auto attr = ToutAttr(); |
11529 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
11530 | } |
11531 | |
11532 | ::mlir::ArrayAttr StatelessIfOpAdaptor::getOutputShapesAttr() { |
11533 | assert(odsAttrs && "no attributes when constructing adapter" ); |
11534 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 1, StatelessIfOp::getOutputShapesAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
11535 | return attr; |
11536 | } |
11537 | |
11538 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessIfOpAdaptor::getOutputShapes() { |
11539 | auto attr = getOutputShapesAttr(); |
11540 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
11541 | } |
11542 | |
11543 | ::mlir::ArrayAttr StatelessIfOpAdaptor::output_shapesAttr() { |
11544 | assert(odsAttrs && "no attributes when constructing adapter" ); |
11545 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 1, StatelessIfOp::getOutputShapesAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
11546 | return attr; |
11547 | } |
11548 | |
11549 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessIfOpAdaptor::output_shapes() { |
11550 | auto attr = output_shapesAttr(); |
11551 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
11552 | } |
11553 | |
11554 | ::mlir::LogicalResult StatelessIfOpAdaptor::verify(::mlir::Location loc) { |
11555 | auto namedAttrRange = odsAttrs; |
11556 | auto namedAttrIt = namedAttrRange.begin(); |
11557 | ::mlir::Attribute tblgen_else_branch; |
11558 | ::mlir::Attribute tblgen_Tcond; |
11559 | ::mlir::Attribute tblgen_Tin; |
11560 | ::mlir::Attribute tblgen_Tout; |
11561 | while (true) { |
11562 | if (namedAttrIt == namedAttrRange.end()) |
11563 | return emitError(loc, "'tfg.StatelessIf' op " "requires attribute 'else_branch'" ); |
11564 | if (namedAttrIt->getName() == StatelessIfOp::getElseBranchAttrName(*odsOpName)) { |
11565 | tblgen_else_branch = namedAttrIt->getValue(); |
11566 | break; |
11567 | } |
11568 | else if (namedAttrIt->getName() == StatelessIfOp::getTcondAttrName(*odsOpName)) { |
11569 | tblgen_Tcond = namedAttrIt->getValue(); |
11570 | } |
11571 | else if (namedAttrIt->getName() == StatelessIfOp::getTinAttrName(*odsOpName)) { |
11572 | tblgen_Tin = namedAttrIt->getValue(); |
11573 | } |
11574 | else if (namedAttrIt->getName() == StatelessIfOp::getToutAttrName(*odsOpName)) { |
11575 | tblgen_Tout = namedAttrIt->getValue(); |
11576 | } |
11577 | ++namedAttrIt; |
11578 | } |
11579 | ::mlir::Attribute tblgen_then_branch; |
11580 | ::mlir::Attribute tblgen_output_shapes; |
11581 | while (true) { |
11582 | if (namedAttrIt == namedAttrRange.end()) |
11583 | return emitError(loc, "'tfg.StatelessIf' op " "requires attribute 'then_branch'" ); |
11584 | if (namedAttrIt->getName() == StatelessIfOp::getThenBranchAttrName(*odsOpName)) { |
11585 | tblgen_then_branch = namedAttrIt->getValue(); |
11586 | break; |
11587 | } |
11588 | else if (namedAttrIt->getName() == StatelessIfOp::getOutputShapesAttrName(*odsOpName)) { |
11589 | tblgen_output_shapes = namedAttrIt->getValue(); |
11590 | } |
11591 | ++namedAttrIt; |
11592 | } |
11593 | |
11594 | if (tblgen_then_branch && !((tblgen_then_branch.isa<::mlir::tf_type::FuncAttr>()))) |
11595 | return emitError(loc, "'tfg.StatelessIf' op " "attribute 'then_branch' failed to satisfy constraint: Models the `AttrValue.value.func` proto attribute value as a pair of SymbolRef and DictionaryAttr" ); |
11596 | |
11597 | if (tblgen_else_branch && !((tblgen_else_branch.isa<::mlir::tf_type::FuncAttr>()))) |
11598 | return emitError(loc, "'tfg.StatelessIf' op " "attribute 'else_branch' failed to satisfy constraint: Models the `AttrValue.value.func` proto attribute value as a pair of SymbolRef and DictionaryAttr" ); |
11599 | |
11600 | if (tblgen_Tcond && !(((tblgen_Tcond.isa<::mlir::TypeAttr>())) && ((tblgen_Tcond.cast<::mlir::TypeAttr>().getValue().isa<::mlir::Type>())))) |
11601 | return emitError(loc, "'tfg.StatelessIf' op " "attribute 'Tcond' failed to satisfy constraint: any type attribute" ); |
11602 | |
11603 | if (tblgen_Tin && !(((tblgen_Tin.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_Tin.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && (((attr.isa<::mlir::TypeAttr>())) && ((attr.cast<::mlir::TypeAttr>().getValue().isa<::mlir::Type>()))); })))) |
11604 | return emitError(loc, "'tfg.StatelessIf' op " "attribute 'Tin' failed to satisfy constraint: type array attribute" ); |
11605 | |
11606 | if (tblgen_Tout && !(((tblgen_Tout.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_Tout.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && (((attr.isa<::mlir::TypeAttr>())) && ((attr.cast<::mlir::TypeAttr>().getValue().isa<::mlir::Type>()))); })))) |
11607 | return emitError(loc, "'tfg.StatelessIf' op " "attribute 'Tout' failed to satisfy constraint: type array attribute" ); |
11608 | |
11609 | if (tblgen_output_shapes && !(((tblgen_output_shapes.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_output_shapes.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && ((attr.isa<::mlir::tf_type::ShapeAttr>())); })))) |
11610 | return emitError(loc, "'tfg.StatelessIf' op " "attribute 'output_shapes' failed to satisfy constraint: An array of shapes." ); |
11611 | return ::mlir::success(); |
11612 | } |
11613 | |
11614 | void StatelessIfOp::getAsmResultNames(::mlir::OpAsmSetValueNameFn setNameFn) { |
11615 | auto resultGroup0 = getODSResults(0); |
11616 | if (!resultGroup0.empty()) |
11617 | setNameFn(*resultGroup0.begin(), "outs" ); |
11618 | auto resultGroup1 = getODSResults(1); |
11619 | if (!resultGroup1.empty()) |
11620 | setNameFn(*resultGroup1.begin(), "ctl" ); |
11621 | } |
11622 | |
11623 | std::pair<unsigned, unsigned> StatelessIfOp::getODSOperandIndexAndLength(unsigned index) { |
11624 | bool isVariadic[] = {false, true}; |
11625 | int prevVariadicCount = 0; |
11626 | for (unsigned i = 0; i < index; ++i) |
11627 | if (isVariadic[i]) ++prevVariadicCount; |
11628 | |
11629 | // Calculate how many dynamic values a static variadic operand corresponds to. |
11630 | // This assumes all static variadic operands have the same dynamic value count. |
11631 | int variadicSize = (getOperation()->getNumOperands() - 1) / 1; |
11632 | // `index` passed in as the parameter is the static index which counts each |
11633 | // operand (variadic or not) as size 1. So here for each previous static variadic |
11634 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
11635 | // value pack for this static operand starts. |
11636 | int start = index + (variadicSize - 1) * prevVariadicCount; |
11637 | int size = isVariadic[index] ? variadicSize : 1; |
11638 | return {start, size}; |
11639 | } |
11640 | |
11641 | ::mlir::Operation::operand_range StatelessIfOp::getODSOperands(unsigned index) { |
11642 | auto valueRange = getODSOperandIndexAndLength(index); |
11643 | return {std::next(getOperation()->operand_begin(), valueRange.first), |
11644 | std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; |
11645 | } |
11646 | |
11647 | ::mlir::Value StatelessIfOp::getCond() { |
11648 | return *getODSOperands(0).begin(); |
11649 | } |
11650 | |
11651 | ::mlir::Value StatelessIfOp::cond() { |
11652 | return *getODSOperands(0).begin(); |
11653 | } |
11654 | |
11655 | ::mlir::Operation::operand_range StatelessIfOp::getArgs() { |
11656 | return getODSOperands(1); |
11657 | } |
11658 | |
11659 | ::mlir::Operation::operand_range StatelessIfOp::args() { |
11660 | return getODSOperands(1); |
11661 | } |
11662 | |
11663 | ::mlir::MutableOperandRange StatelessIfOp::getCondMutable() { |
11664 | auto range = getODSOperandIndexAndLength(0); |
11665 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
11666 | return mutableRange; |
11667 | } |
11668 | |
11669 | ::mlir::MutableOperandRange StatelessIfOp::condMutable() { |
11670 | auto range = getODSOperandIndexAndLength(0); |
11671 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
11672 | return mutableRange; |
11673 | } |
11674 | |
11675 | ::mlir::MutableOperandRange StatelessIfOp::getArgsMutable() { |
11676 | auto range = getODSOperandIndexAndLength(1); |
11677 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
11678 | return mutableRange; |
11679 | } |
11680 | |
11681 | ::mlir::MutableOperandRange StatelessIfOp::argsMutable() { |
11682 | auto range = getODSOperandIndexAndLength(1); |
11683 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
11684 | return mutableRange; |
11685 | } |
11686 | |
11687 | std::pair<unsigned, unsigned> StatelessIfOp::getODSResultIndexAndLength(unsigned index) { |
11688 | bool isVariadic[] = {true, false}; |
11689 | int prevVariadicCount = 0; |
11690 | for (unsigned i = 0; i < index; ++i) |
11691 | if (isVariadic[i]) ++prevVariadicCount; |
11692 | |
11693 | // Calculate how many dynamic values a static variadic operand corresponds to. |
11694 | // This assumes all static variadic operands have the same dynamic value count. |
11695 | int variadicSize = (getOperation()->getNumResults() - 1) / 1; |
11696 | // `index` passed in as the parameter is the static index which counts each |
11697 | // operand (variadic or not) as size 1. So here for each previous static variadic |
11698 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
11699 | // value pack for this static operand starts. |
11700 | int start = index + (variadicSize - 1) * prevVariadicCount; |
11701 | int size = isVariadic[index] ? variadicSize : 1; |
11702 | return {start, size}; |
11703 | } |
11704 | |
11705 | ::mlir::Operation::result_range StatelessIfOp::getODSResults(unsigned index) { |
11706 | auto valueRange = getODSResultIndexAndLength(index); |
11707 | return {std::next(getOperation()->result_begin(), valueRange.first), |
11708 | std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; |
11709 | } |
11710 | |
11711 | ::mlir::Operation::result_range StatelessIfOp::getOuts() { |
11712 | return getODSResults(0); |
11713 | } |
11714 | |
11715 | ::mlir::Operation::result_range StatelessIfOp::outs() { |
11716 | return getODSResults(0); |
11717 | } |
11718 | |
11719 | ::mlir::TypedValue<::mlir::tf_type::ControlType> StatelessIfOp::getCtl() { |
11720 | return *getODSResults(1).begin(); |
11721 | } |
11722 | |
11723 | ::mlir::TypedValue<::mlir::tf_type::ControlType> StatelessIfOp::ctl() { |
11724 | return *getODSResults(1).begin(); |
11725 | } |
11726 | |
11727 | ::mlir::tf_type::FuncAttr StatelessIfOp::getThenBranchAttr() { |
11728 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getThenBranchAttrName()).cast<::mlir::tf_type::FuncAttr>(); |
11729 | } |
11730 | |
11731 | ::mlir::tf_type::FuncAttr StatelessIfOp::getThenBranch() { |
11732 | auto attr = getThenBranchAttr(); |
11733 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
11734 | } |
11735 | |
11736 | ::mlir::tf_type::FuncAttr StatelessIfOp::then_branchAttr() { |
11737 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getThenBranchAttrName()).cast<::mlir::tf_type::FuncAttr>(); |
11738 | } |
11739 | |
11740 | ::mlir::tf_type::FuncAttr StatelessIfOp::then_branch() { |
11741 | auto attr = then_branchAttr(); |
11742 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
11743 | } |
11744 | |
11745 | ::mlir::tf_type::FuncAttr StatelessIfOp::getElseBranchAttr() { |
11746 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getElseBranchAttrName()).cast<::mlir::tf_type::FuncAttr>(); |
11747 | } |
11748 | |
11749 | ::mlir::tf_type::FuncAttr StatelessIfOp::getElseBranch() { |
11750 | auto attr = getElseBranchAttr(); |
11751 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
11752 | } |
11753 | |
11754 | ::mlir::tf_type::FuncAttr StatelessIfOp::else_branchAttr() { |
11755 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getElseBranchAttrName()).cast<::mlir::tf_type::FuncAttr>(); |
11756 | } |
11757 | |
11758 | ::mlir::tf_type::FuncAttr StatelessIfOp::else_branch() { |
11759 | auto attr = else_branchAttr(); |
11760 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
11761 | } |
11762 | |
11763 | ::mlir::TypeAttr StatelessIfOp::getTcondAttr() { |
11764 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getTcondAttrName()).dyn_cast_or_null<::mlir::TypeAttr>(); |
11765 | } |
11766 | |
11767 | ::llvm::Optional<::mlir::Type> StatelessIfOp::getTcond() { |
11768 | auto attr = getTcondAttr(); |
11769 | return attr ? ::llvm::Optional<::mlir::Type>(attr.getValue().cast<::mlir::Type>()) : (::llvm::None); |
11770 | } |
11771 | |
11772 | ::mlir::TypeAttr StatelessIfOp::TcondAttr() { |
11773 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getTcondAttrName()).dyn_cast_or_null<::mlir::TypeAttr>(); |
11774 | } |
11775 | |
11776 | ::llvm::Optional<::mlir::Type> StatelessIfOp::Tcond() { |
11777 | auto attr = TcondAttr(); |
11778 | return attr ? ::llvm::Optional<::mlir::Type>(attr.getValue().cast<::mlir::Type>()) : (::llvm::None); |
11779 | } |
11780 | |
11781 | ::mlir::ArrayAttr StatelessIfOp::getTinAttr() { |
11782 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getTinAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
11783 | } |
11784 | |
11785 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessIfOp::getTin() { |
11786 | auto attr = getTinAttr(); |
11787 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
11788 | } |
11789 | |
11790 | ::mlir::ArrayAttr StatelessIfOp::TinAttr() { |
11791 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getTinAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
11792 | } |
11793 | |
11794 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessIfOp::Tin() { |
11795 | auto attr = TinAttr(); |
11796 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
11797 | } |
11798 | |
11799 | ::mlir::ArrayAttr StatelessIfOp::getToutAttr() { |
11800 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getToutAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
11801 | } |
11802 | |
11803 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessIfOp::getTout() { |
11804 | auto attr = getToutAttr(); |
11805 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
11806 | } |
11807 | |
11808 | ::mlir::ArrayAttr StatelessIfOp::ToutAttr() { |
11809 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getToutAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
11810 | } |
11811 | |
11812 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessIfOp::Tout() { |
11813 | auto attr = ToutAttr(); |
11814 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
11815 | } |
11816 | |
11817 | ::mlir::ArrayAttr StatelessIfOp::getOutputShapesAttr() { |
11818 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 1, getOutputShapesAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
11819 | } |
11820 | |
11821 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessIfOp::getOutputShapes() { |
11822 | auto attr = getOutputShapesAttr(); |
11823 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
11824 | } |
11825 | |
11826 | ::mlir::ArrayAttr StatelessIfOp::output_shapesAttr() { |
11827 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 1, getOutputShapesAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
11828 | } |
11829 | |
11830 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessIfOp::output_shapes() { |
11831 | auto attr = output_shapesAttr(); |
11832 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
11833 | } |
11834 | |
11835 | void StatelessIfOp::setThenBranchAttr(::mlir::tf_type::FuncAttr attr) { |
11836 | (*this)->setAttr(getThenBranchAttrName(), attr); |
11837 | } |
11838 | |
11839 | void StatelessIfOp::then_branchAttr(::mlir::tf_type::FuncAttr attr) { |
11840 | (*this)->setAttr(then_branchAttrName(), attr); |
11841 | } |
11842 | |
11843 | void StatelessIfOp::setElseBranchAttr(::mlir::tf_type::FuncAttr attr) { |
11844 | (*this)->setAttr(getElseBranchAttrName(), attr); |
11845 | } |
11846 | |
11847 | void StatelessIfOp::else_branchAttr(::mlir::tf_type::FuncAttr attr) { |
11848 | (*this)->setAttr(else_branchAttrName(), attr); |
11849 | } |
11850 | |
11851 | void StatelessIfOp::setTcondAttr(::mlir::TypeAttr attr) { |
11852 | (*this)->setAttr(getTcondAttrName(), attr); |
11853 | } |
11854 | |
11855 | void StatelessIfOp::TcondAttr(::mlir::TypeAttr attr) { |
11856 | (*this)->setAttr(TcondAttrName(), attr); |
11857 | } |
11858 | |
11859 | void StatelessIfOp::setTinAttr(::mlir::ArrayAttr attr) { |
11860 | (*this)->setAttr(getTinAttrName(), attr); |
11861 | } |
11862 | |
11863 | void StatelessIfOp::TinAttr(::mlir::ArrayAttr attr) { |
11864 | (*this)->setAttr(TinAttrName(), attr); |
11865 | } |
11866 | |
11867 | void StatelessIfOp::setToutAttr(::mlir::ArrayAttr attr) { |
11868 | (*this)->setAttr(getToutAttrName(), attr); |
11869 | } |
11870 | |
11871 | void StatelessIfOp::ToutAttr(::mlir::ArrayAttr attr) { |
11872 | (*this)->setAttr(ToutAttrName(), attr); |
11873 | } |
11874 | |
11875 | void StatelessIfOp::setOutputShapesAttr(::mlir::ArrayAttr attr) { |
11876 | (*this)->setAttr(getOutputShapesAttrName(), attr); |
11877 | } |
11878 | |
11879 | void StatelessIfOp::output_shapesAttr(::mlir::ArrayAttr attr) { |
11880 | (*this)->setAttr(output_shapesAttrName(), attr); |
11881 | } |
11882 | |
11883 | ::mlir::Attribute StatelessIfOp::removeTcondAttr() { |
11884 | return (*this)->removeAttr(getTcondAttrName()); |
11885 | } |
11886 | |
11887 | ::mlir::Attribute StatelessIfOp::removeTinAttr() { |
11888 | return (*this)->removeAttr(getTinAttrName()); |
11889 | } |
11890 | |
11891 | ::mlir::Attribute StatelessIfOp::removeToutAttr() { |
11892 | return (*this)->removeAttr(getToutAttrName()); |
11893 | } |
11894 | |
11895 | ::mlir::Attribute StatelessIfOp::removeOutput_shapesAttr() { |
11896 | return (*this)->removeAttr(getOutputShapesAttrName()); |
11897 | } |
11898 | |
11899 | void StatelessIfOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, TypeRange results, Value cond, ValueRange args, FuncAttr then_branch, FuncAttr else_branch) { |
11900 | build(odsBuilder, odsState, results, cond, args, then_branch, else_branch, |
11901 | /*Tcond=*/{}, /*Tin=*/{}, /*Tout=*/{}, /*output_shapes=*/{}); |
11902 | |
11903 | } |
11904 | |
11905 | void StatelessIfOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange outs, ::mlir::Type ctl, ::mlir::Value cond, ::mlir::ValueRange args, ::mlir::tf_type::FuncAttr then_branch, ::mlir::tf_type::FuncAttr else_branch, /*optional*/::mlir::TypeAttr Tcond, /*optional*/::mlir::ArrayAttr Tin, /*optional*/::mlir::ArrayAttr Tout, /*optional*/::mlir::ArrayAttr output_shapes) { |
11906 | odsState.addOperands(cond); |
11907 | odsState.addOperands(args); |
11908 | odsState.addAttribute(getThenBranchAttrName(odsState.name), then_branch); |
11909 | odsState.addAttribute(getElseBranchAttrName(odsState.name), else_branch); |
11910 | if (Tcond) { |
11911 | odsState.addAttribute(getTcondAttrName(odsState.name), Tcond); |
11912 | } |
11913 | if (Tin) { |
11914 | odsState.addAttribute(getTinAttrName(odsState.name), Tin); |
11915 | } |
11916 | if (Tout) { |
11917 | odsState.addAttribute(getToutAttrName(odsState.name), Tout); |
11918 | } |
11919 | if (output_shapes) { |
11920 | odsState.addAttribute(getOutputShapesAttrName(odsState.name), output_shapes); |
11921 | } |
11922 | odsState.addTypes(outs); |
11923 | odsState.addTypes(ctl); |
11924 | } |
11925 | |
11926 | void StatelessIfOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value cond, ::mlir::ValueRange args, ::mlir::tf_type::FuncAttr then_branch, ::mlir::tf_type::FuncAttr else_branch, /*optional*/::mlir::TypeAttr Tcond, /*optional*/::mlir::ArrayAttr Tin, /*optional*/::mlir::ArrayAttr Tout, /*optional*/::mlir::ArrayAttr output_shapes) { |
11927 | odsState.addOperands(cond); |
11928 | odsState.addOperands(args); |
11929 | odsState.addAttribute(getThenBranchAttrName(odsState.name), then_branch); |
11930 | odsState.addAttribute(getElseBranchAttrName(odsState.name), else_branch); |
11931 | if (Tcond) { |
11932 | odsState.addAttribute(getTcondAttrName(odsState.name), Tcond); |
11933 | } |
11934 | if (Tin) { |
11935 | odsState.addAttribute(getTinAttrName(odsState.name), Tin); |
11936 | } |
11937 | if (Tout) { |
11938 | odsState.addAttribute(getToutAttrName(odsState.name), Tout); |
11939 | } |
11940 | if (output_shapes) { |
11941 | odsState.addAttribute(getOutputShapesAttrName(odsState.name), output_shapes); |
11942 | } |
11943 | assert(resultTypes.size() >= 1u && "mismatched number of results" ); |
11944 | odsState.addTypes(resultTypes); |
11945 | } |
11946 | |
11947 | void StatelessIfOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { |
11948 | assert(operands.size() >= 1u && "mismatched number of parameters" ); |
11949 | odsState.addOperands(operands); |
11950 | odsState.addAttributes(attributes); |
11951 | assert(resultTypes.size() >= 1u && "mismatched number of return types" ); |
11952 | odsState.addTypes(resultTypes); |
11953 | } |
11954 | |
11955 | ::mlir::LogicalResult StatelessIfOp::verifyInvariantsImpl() { |
11956 | auto namedAttrRange = (*this)->getAttrs(); |
11957 | auto namedAttrIt = namedAttrRange.begin(); |
11958 | ::mlir::Attribute tblgen_else_branch; |
11959 | ::mlir::Attribute tblgen_Tcond; |
11960 | ::mlir::Attribute tblgen_Tin; |
11961 | ::mlir::Attribute tblgen_Tout; |
11962 | while (true) { |
11963 | if (namedAttrIt == namedAttrRange.end()) |
11964 | return emitOpError("requires attribute 'else_branch'" ); |
11965 | if (namedAttrIt->getName() == getElseBranchAttrName()) { |
11966 | tblgen_else_branch = namedAttrIt->getValue(); |
11967 | break; |
11968 | } |
11969 | else if (namedAttrIt->getName() == getTcondAttrName()) { |
11970 | tblgen_Tcond = namedAttrIt->getValue(); |
11971 | } |
11972 | else if (namedAttrIt->getName() == getTinAttrName()) { |
11973 | tblgen_Tin = namedAttrIt->getValue(); |
11974 | } |
11975 | else if (namedAttrIt->getName() == getToutAttrName()) { |
11976 | tblgen_Tout = namedAttrIt->getValue(); |
11977 | } |
11978 | ++namedAttrIt; |
11979 | } |
11980 | ::mlir::Attribute tblgen_then_branch; |
11981 | ::mlir::Attribute tblgen_output_shapes; |
11982 | while (true) { |
11983 | if (namedAttrIt == namedAttrRange.end()) |
11984 | return emitOpError("requires attribute 'then_branch'" ); |
11985 | if (namedAttrIt->getName() == getThenBranchAttrName()) { |
11986 | tblgen_then_branch = namedAttrIt->getValue(); |
11987 | break; |
11988 | } |
11989 | else if (namedAttrIt->getName() == getOutputShapesAttrName()) { |
11990 | tblgen_output_shapes = namedAttrIt->getValue(); |
11991 | } |
11992 | ++namedAttrIt; |
11993 | } |
11994 | |
11995 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops5(*this, tblgen_then_branch, "then_branch" ))) |
11996 | return ::mlir::failure(); |
11997 | |
11998 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops5(*this, tblgen_else_branch, "else_branch" ))) |
11999 | return ::mlir::failure(); |
12000 | |
12001 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops17(*this, tblgen_Tcond, "Tcond" ))) |
12002 | return ::mlir::failure(); |
12003 | |
12004 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops1(*this, tblgen_Tin, "Tin" ))) |
12005 | return ::mlir::failure(); |
12006 | |
12007 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops1(*this, tblgen_Tout, "Tout" ))) |
12008 | return ::mlir::failure(); |
12009 | |
12010 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops2(*this, tblgen_output_shapes, "output_shapes" ))) |
12011 | return ::mlir::failure(); |
12012 | { |
12013 | unsigned index = 0; (void)index; |
12014 | auto valueGroup0 = getODSOperands(0); |
12015 | |
12016 | for (auto v : valueGroup0) { |
12017 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops7(*this, v.getType(), "operand" , index++))) |
12018 | return ::mlir::failure(); |
12019 | } |
12020 | auto valueGroup1 = getODSOperands(1); |
12021 | |
12022 | for (auto v : valueGroup1) { |
12023 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops1(*this, v.getType(), "operand" , index++))) |
12024 | return ::mlir::failure(); |
12025 | } |
12026 | } |
12027 | { |
12028 | unsigned index = 0; (void)index; |
12029 | auto valueGroup0 = getODSResults(0); |
12030 | |
12031 | for (auto v : valueGroup0) { |
12032 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops2(*this, v.getType(), "result" , index++))) |
12033 | return ::mlir::failure(); |
12034 | } |
12035 | auto valueGroup1 = getODSResults(1); |
12036 | |
12037 | for (auto v : valueGroup1) { |
12038 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops3(*this, v.getType(), "result" , index++))) |
12039 | return ::mlir::failure(); |
12040 | } |
12041 | } |
12042 | return ::mlir::success(); |
12043 | } |
12044 | |
12045 | ::mlir::LogicalResult StatelessIfOp::verifyInvariants() { |
12046 | return verifyInvariantsImpl(); |
12047 | } |
12048 | |
12049 | LogicalResult StatelessIfOp::verifySymbolUses( |
12050 | SymbolTableCollection &symbol_table) { |
12051 | return VerifyIfLikeOp(*this, symbol_table); |
12052 | } |
12053 | } // namespace tfg |
12054 | } // namespace mlir |
12055 | MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::tfg::StatelessIfOp) |
12056 | |
12057 | namespace mlir { |
12058 | namespace tfg { |
12059 | |
12060 | //===----------------------------------------------------------------------===// |
12061 | // ::mlir::tfg::StatelessIfRegionOp definitions |
12062 | //===----------------------------------------------------------------------===// |
12063 | |
12064 | StatelessIfRegionOpAdaptor::StatelessIfRegionOpAdaptor(::mlir::ValueRange values, ::mlir::DictionaryAttr attrs, ::mlir::RegionRange regions) : odsOperands(values), odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) |
12065 | odsOpName.emplace("tfg.StatelessIfRegion" , odsAttrs.getContext()); |
12066 | } |
12067 | |
12068 | StatelessIfRegionOpAdaptor::StatelessIfRegionOpAdaptor(StatelessIfRegionOp op) : odsOperands(op->getOperands()), odsAttrs(op->getAttrDictionary()), odsRegions(op->getRegions()), odsOpName(op->getName()) {} |
12069 | |
12070 | ::mlir::ValueRange StatelessIfRegionOpAdaptor::getOperands() { |
12071 | return odsOperands; |
12072 | } |
12073 | |
12074 | std::pair<unsigned, unsigned> StatelessIfRegionOpAdaptor::getODSOperandIndexAndLength(unsigned index) { |
12075 | bool isVariadic[] = {false, true}; |
12076 | int prevVariadicCount = 0; |
12077 | for (unsigned i = 0; i < index; ++i) |
12078 | if (isVariadic[i]) ++prevVariadicCount; |
12079 | |
12080 | // Calculate how many dynamic values a static variadic operand corresponds to. |
12081 | // This assumes all static variadic operands have the same dynamic value count. |
12082 | int variadicSize = (odsOperands.size() - 1) / 1; |
12083 | // `index` passed in as the parameter is the static index which counts each |
12084 | // operand (variadic or not) as size 1. So here for each previous static variadic |
12085 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
12086 | // value pack for this static operand starts. |
12087 | int start = index + (variadicSize - 1) * prevVariadicCount; |
12088 | int size = isVariadic[index] ? variadicSize : 1; |
12089 | return {start, size}; |
12090 | } |
12091 | |
12092 | ::mlir::ValueRange StatelessIfRegionOpAdaptor::getODSOperands(unsigned index) { |
12093 | auto valueRange = getODSOperandIndexAndLength(index); |
12094 | return {std::next(odsOperands.begin(), valueRange.first), |
12095 | std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; |
12096 | } |
12097 | |
12098 | ::mlir::Value StatelessIfRegionOpAdaptor::getCond() { |
12099 | return *getODSOperands(0).begin(); |
12100 | } |
12101 | |
12102 | ::mlir::Value StatelessIfRegionOpAdaptor::cond() { |
12103 | return *getODSOperands(0).begin(); |
12104 | } |
12105 | |
12106 | ::mlir::ValueRange StatelessIfRegionOpAdaptor::getCtls() { |
12107 | return getODSOperands(1); |
12108 | } |
12109 | |
12110 | ::mlir::ValueRange StatelessIfRegionOpAdaptor::ctls() { |
12111 | return getODSOperands(1); |
12112 | } |
12113 | |
12114 | ::mlir::DictionaryAttr StatelessIfRegionOpAdaptor::getAttributes() { |
12115 | return odsAttrs; |
12116 | } |
12117 | |
12118 | ::mlir::DictionaryAttr StatelessIfRegionOpAdaptor::getThenAttrsAttr() { |
12119 | assert(odsAttrs && "no attributes when constructing adapter" ); |
12120 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, StatelessIfRegionOp::getThenAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
12121 | return attr; |
12122 | } |
12123 | |
12124 | ::llvm::Optional< ::mlir::DictionaryAttr > StatelessIfRegionOpAdaptor::getThenAttrs() { |
12125 | auto attr = getThenAttrsAttr(); |
12126 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
12127 | } |
12128 | |
12129 | ::mlir::DictionaryAttr StatelessIfRegionOpAdaptor::then_attrsAttr() { |
12130 | assert(odsAttrs && "no attributes when constructing adapter" ); |
12131 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, StatelessIfRegionOp::getThenAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
12132 | return attr; |
12133 | } |
12134 | |
12135 | ::llvm::Optional< ::mlir::DictionaryAttr > StatelessIfRegionOpAdaptor::then_attrs() { |
12136 | auto attr = then_attrsAttr(); |
12137 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
12138 | } |
12139 | |
12140 | ::mlir::DictionaryAttr StatelessIfRegionOpAdaptor::getElseAttrsAttr() { |
12141 | assert(odsAttrs && "no attributes when constructing adapter" ); |
12142 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, StatelessIfRegionOp::getElseAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
12143 | return attr; |
12144 | } |
12145 | |
12146 | ::llvm::Optional< ::mlir::DictionaryAttr > StatelessIfRegionOpAdaptor::getElseAttrs() { |
12147 | auto attr = getElseAttrsAttr(); |
12148 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
12149 | } |
12150 | |
12151 | ::mlir::DictionaryAttr StatelessIfRegionOpAdaptor::else_attrsAttr() { |
12152 | assert(odsAttrs && "no attributes when constructing adapter" ); |
12153 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, StatelessIfRegionOp::getElseAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
12154 | return attr; |
12155 | } |
12156 | |
12157 | ::llvm::Optional< ::mlir::DictionaryAttr > StatelessIfRegionOpAdaptor::else_attrs() { |
12158 | auto attr = else_attrsAttr(); |
12159 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
12160 | } |
12161 | |
12162 | ::mlir::tfg::RegionAttr StatelessIfRegionOpAdaptor::getThenRegionAttrsAttr() { |
12163 | assert(odsAttrs && "no attributes when constructing adapter" ); |
12164 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, StatelessIfRegionOp::getThenRegionAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
12165 | return attr; |
12166 | } |
12167 | |
12168 | ::llvm::Optional<::mlir::tfg::RegionAttr> StatelessIfRegionOpAdaptor::getThenRegionAttrs() { |
12169 | auto attr = getThenRegionAttrsAttr(); |
12170 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
12171 | } |
12172 | |
12173 | ::mlir::tfg::RegionAttr StatelessIfRegionOpAdaptor::then_region_attrsAttr() { |
12174 | assert(odsAttrs && "no attributes when constructing adapter" ); |
12175 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, StatelessIfRegionOp::getThenRegionAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
12176 | return attr; |
12177 | } |
12178 | |
12179 | ::llvm::Optional<::mlir::tfg::RegionAttr> StatelessIfRegionOpAdaptor::then_region_attrs() { |
12180 | auto attr = then_region_attrsAttr(); |
12181 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
12182 | } |
12183 | |
12184 | ::mlir::tfg::RegionAttr StatelessIfRegionOpAdaptor::getElseRegionAttrsAttr() { |
12185 | assert(odsAttrs && "no attributes when constructing adapter" ); |
12186 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, StatelessIfRegionOp::getElseRegionAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
12187 | return attr; |
12188 | } |
12189 | |
12190 | ::llvm::Optional<::mlir::tfg::RegionAttr> StatelessIfRegionOpAdaptor::getElseRegionAttrs() { |
12191 | auto attr = getElseRegionAttrsAttr(); |
12192 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
12193 | } |
12194 | |
12195 | ::mlir::tfg::RegionAttr StatelessIfRegionOpAdaptor::else_region_attrsAttr() { |
12196 | assert(odsAttrs && "no attributes when constructing adapter" ); |
12197 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, StatelessIfRegionOp::getElseRegionAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
12198 | return attr; |
12199 | } |
12200 | |
12201 | ::llvm::Optional<::mlir::tfg::RegionAttr> StatelessIfRegionOpAdaptor::else_region_attrs() { |
12202 | auto attr = else_region_attrsAttr(); |
12203 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
12204 | } |
12205 | |
12206 | ::mlir::RegionRange StatelessIfRegionOpAdaptor::getRegions() { |
12207 | return odsRegions; |
12208 | } |
12209 | |
12210 | ::mlir::Region &StatelessIfRegionOpAdaptor::getThenRegion() { |
12211 | return *odsRegions[0]; |
12212 | } |
12213 | |
12214 | ::mlir::Region &StatelessIfRegionOpAdaptor::then_region() { |
12215 | return *odsRegions[0]; |
12216 | } |
12217 | |
12218 | ::mlir::Region &StatelessIfRegionOpAdaptor::getElseRegion() { |
12219 | return *odsRegions[1]; |
12220 | } |
12221 | |
12222 | ::mlir::Region &StatelessIfRegionOpAdaptor::else_region() { |
12223 | return *odsRegions[1]; |
12224 | } |
12225 | |
12226 | ::mlir::LogicalResult StatelessIfRegionOpAdaptor::verify(::mlir::Location loc) { |
12227 | auto namedAttrRange = odsAttrs; |
12228 | auto namedAttrIt = namedAttrRange.begin(); |
12229 | ::mlir::Attribute tblgen_else_attrs; |
12230 | ::mlir::Attribute tblgen_else_region_attrs; |
12231 | ::mlir::Attribute tblgen_then_attrs; |
12232 | ::mlir::Attribute tblgen_then_region_attrs; |
12233 | while (true) { |
12234 | if (namedAttrIt == namedAttrRange.end()) { |
12235 | break; |
12236 | } |
12237 | else if (namedAttrIt->getName() == StatelessIfRegionOp::getElseAttrsAttrName(*odsOpName)) { |
12238 | tblgen_else_attrs = namedAttrIt->getValue(); |
12239 | } |
12240 | else if (namedAttrIt->getName() == StatelessIfRegionOp::getElseRegionAttrsAttrName(*odsOpName)) { |
12241 | tblgen_else_region_attrs = namedAttrIt->getValue(); |
12242 | } |
12243 | else if (namedAttrIt->getName() == StatelessIfRegionOp::getThenAttrsAttrName(*odsOpName)) { |
12244 | tblgen_then_attrs = namedAttrIt->getValue(); |
12245 | } |
12246 | else if (namedAttrIt->getName() == StatelessIfRegionOp::getThenRegionAttrsAttrName(*odsOpName)) { |
12247 | tblgen_then_region_attrs = namedAttrIt->getValue(); |
12248 | } |
12249 | ++namedAttrIt; |
12250 | } |
12251 | |
12252 | if (tblgen_then_attrs && !((tblgen_then_attrs.isa<::mlir::DictionaryAttr>()))) |
12253 | return emitError(loc, "'tfg.StatelessIfRegion' op " "attribute 'then_attrs' failed to satisfy constraint: dictionary of named attribute values" ); |
12254 | |
12255 | if (tblgen_else_attrs && !((tblgen_else_attrs.isa<::mlir::DictionaryAttr>()))) |
12256 | return emitError(loc, "'tfg.StatelessIfRegion' op " "attribute 'else_attrs' failed to satisfy constraint: dictionary of named attribute values" ); |
12257 | |
12258 | if (tblgen_then_region_attrs && !((tblgen_then_region_attrs.isa<::mlir::tfg::RegionAttr>()))) |
12259 | return emitError(loc, "'tfg.StatelessIfRegion' op " "attribute 'then_region_attrs' failed to satisfy constraint: Region attributes, argument and result attributes." ); |
12260 | |
12261 | if (tblgen_else_region_attrs && !((tblgen_else_region_attrs.isa<::mlir::tfg::RegionAttr>()))) |
12262 | return emitError(loc, "'tfg.StatelessIfRegion' op " "attribute 'else_region_attrs' failed to satisfy constraint: Region attributes, argument and result attributes." ); |
12263 | return ::mlir::success(); |
12264 | } |
12265 | |
12266 | std::pair<unsigned, unsigned> StatelessIfRegionOp::getODSOperandIndexAndLength(unsigned index) { |
12267 | bool isVariadic[] = {false, true}; |
12268 | int prevVariadicCount = 0; |
12269 | for (unsigned i = 0; i < index; ++i) |
12270 | if (isVariadic[i]) ++prevVariadicCount; |
12271 | |
12272 | // Calculate how many dynamic values a static variadic operand corresponds to. |
12273 | // This assumes all static variadic operands have the same dynamic value count. |
12274 | int variadicSize = (getOperation()->getNumOperands() - 1) / 1; |
12275 | // `index` passed in as the parameter is the static index which counts each |
12276 | // operand (variadic or not) as size 1. So here for each previous static variadic |
12277 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
12278 | // value pack for this static operand starts. |
12279 | int start = index + (variadicSize - 1) * prevVariadicCount; |
12280 | int size = isVariadic[index] ? variadicSize : 1; |
12281 | return {start, size}; |
12282 | } |
12283 | |
12284 | ::mlir::Operation::operand_range StatelessIfRegionOp::getODSOperands(unsigned index) { |
12285 | auto valueRange = getODSOperandIndexAndLength(index); |
12286 | return {std::next(getOperation()->operand_begin(), valueRange.first), |
12287 | std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; |
12288 | } |
12289 | |
12290 | ::mlir::TypedValue<::mlir::TensorType> StatelessIfRegionOp::getCond() { |
12291 | return *getODSOperands(0).begin(); |
12292 | } |
12293 | |
12294 | ::mlir::TypedValue<::mlir::TensorType> StatelessIfRegionOp::cond() { |
12295 | return *getODSOperands(0).begin(); |
12296 | } |
12297 | |
12298 | ::mlir::Operation::operand_range StatelessIfRegionOp::getCtls() { |
12299 | return getODSOperands(1); |
12300 | } |
12301 | |
12302 | ::mlir::Operation::operand_range StatelessIfRegionOp::ctls() { |
12303 | return getODSOperands(1); |
12304 | } |
12305 | |
12306 | ::mlir::MutableOperandRange StatelessIfRegionOp::getCondMutable() { |
12307 | auto range = getODSOperandIndexAndLength(0); |
12308 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
12309 | return mutableRange; |
12310 | } |
12311 | |
12312 | ::mlir::MutableOperandRange StatelessIfRegionOp::condMutable() { |
12313 | auto range = getODSOperandIndexAndLength(0); |
12314 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
12315 | return mutableRange; |
12316 | } |
12317 | |
12318 | ::mlir::MutableOperandRange StatelessIfRegionOp::getCtlsMutable() { |
12319 | auto range = getODSOperandIndexAndLength(1); |
12320 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
12321 | return mutableRange; |
12322 | } |
12323 | |
12324 | ::mlir::MutableOperandRange StatelessIfRegionOp::ctlsMutable() { |
12325 | auto range = getODSOperandIndexAndLength(1); |
12326 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
12327 | return mutableRange; |
12328 | } |
12329 | |
12330 | std::pair<unsigned, unsigned> StatelessIfRegionOp::getODSResultIndexAndLength(unsigned index) { |
12331 | bool isVariadic[] = {true, false}; |
12332 | int prevVariadicCount = 0; |
12333 | for (unsigned i = 0; i < index; ++i) |
12334 | if (isVariadic[i]) ++prevVariadicCount; |
12335 | |
12336 | // Calculate how many dynamic values a static variadic operand corresponds to. |
12337 | // This assumes all static variadic operands have the same dynamic value count. |
12338 | int variadicSize = (getOperation()->getNumResults() - 1) / 1; |
12339 | // `index` passed in as the parameter is the static index which counts each |
12340 | // operand (variadic or not) as size 1. So here for each previous static variadic |
12341 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
12342 | // value pack for this static operand starts. |
12343 | int start = index + (variadicSize - 1) * prevVariadicCount; |
12344 | int size = isVariadic[index] ? variadicSize : 1; |
12345 | return {start, size}; |
12346 | } |
12347 | |
12348 | ::mlir::Operation::result_range StatelessIfRegionOp::getODSResults(unsigned index) { |
12349 | auto valueRange = getODSResultIndexAndLength(index); |
12350 | return {std::next(getOperation()->result_begin(), valueRange.first), |
12351 | std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; |
12352 | } |
12353 | |
12354 | ::mlir::Operation::result_range StatelessIfRegionOp::getOuts() { |
12355 | return getODSResults(0); |
12356 | } |
12357 | |
12358 | ::mlir::Operation::result_range StatelessIfRegionOp::outs() { |
12359 | return getODSResults(0); |
12360 | } |
12361 | |
12362 | ::mlir::TypedValue<::mlir::tf_type::ControlType> StatelessIfRegionOp::getCtl() { |
12363 | return *getODSResults(1).begin(); |
12364 | } |
12365 | |
12366 | ::mlir::TypedValue<::mlir::tf_type::ControlType> StatelessIfRegionOp::ctl() { |
12367 | return *getODSResults(1).begin(); |
12368 | } |
12369 | |
12370 | ::mlir::Region &StatelessIfRegionOp::getThenRegion() { |
12371 | return (*this)->getRegion(0); |
12372 | } |
12373 | |
12374 | ::mlir::Region &StatelessIfRegionOp::then_region() { |
12375 | return (*this)->getRegion(0); |
12376 | } |
12377 | |
12378 | ::mlir::Region &StatelessIfRegionOp::getElseRegion() { |
12379 | return (*this)->getRegion(1); |
12380 | } |
12381 | |
12382 | ::mlir::Region &StatelessIfRegionOp::else_region() { |
12383 | return (*this)->getRegion(1); |
12384 | } |
12385 | |
12386 | ::mlir::DictionaryAttr StatelessIfRegionOp::getThenAttrsAttr() { |
12387 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getThenAttrsAttrName()).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
12388 | } |
12389 | |
12390 | ::llvm::Optional< ::mlir::DictionaryAttr > StatelessIfRegionOp::getThenAttrs() { |
12391 | auto attr = getThenAttrsAttr(); |
12392 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
12393 | } |
12394 | |
12395 | ::mlir::DictionaryAttr StatelessIfRegionOp::then_attrsAttr() { |
12396 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getThenAttrsAttrName()).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
12397 | } |
12398 | |
12399 | ::llvm::Optional< ::mlir::DictionaryAttr > StatelessIfRegionOp::then_attrs() { |
12400 | auto attr = then_attrsAttr(); |
12401 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
12402 | } |
12403 | |
12404 | ::mlir::DictionaryAttr StatelessIfRegionOp::getElseAttrsAttr() { |
12405 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getElseAttrsAttrName()).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
12406 | } |
12407 | |
12408 | ::llvm::Optional< ::mlir::DictionaryAttr > StatelessIfRegionOp::getElseAttrs() { |
12409 | auto attr = getElseAttrsAttr(); |
12410 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
12411 | } |
12412 | |
12413 | ::mlir::DictionaryAttr StatelessIfRegionOp::else_attrsAttr() { |
12414 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getElseAttrsAttrName()).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
12415 | } |
12416 | |
12417 | ::llvm::Optional< ::mlir::DictionaryAttr > StatelessIfRegionOp::else_attrs() { |
12418 | auto attr = else_attrsAttr(); |
12419 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
12420 | } |
12421 | |
12422 | ::mlir::tfg::RegionAttr StatelessIfRegionOp::getThenRegionAttrsAttr() { |
12423 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getThenRegionAttrsAttrName()).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
12424 | } |
12425 | |
12426 | ::llvm::Optional<::mlir::tfg::RegionAttr> StatelessIfRegionOp::getThenRegionAttrs() { |
12427 | auto attr = getThenRegionAttrsAttr(); |
12428 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
12429 | } |
12430 | |
12431 | ::mlir::tfg::RegionAttr StatelessIfRegionOp::then_region_attrsAttr() { |
12432 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getThenRegionAttrsAttrName()).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
12433 | } |
12434 | |
12435 | ::llvm::Optional<::mlir::tfg::RegionAttr> StatelessIfRegionOp::then_region_attrs() { |
12436 | auto attr = then_region_attrsAttr(); |
12437 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
12438 | } |
12439 | |
12440 | ::mlir::tfg::RegionAttr StatelessIfRegionOp::getElseRegionAttrsAttr() { |
12441 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getElseRegionAttrsAttrName()).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
12442 | } |
12443 | |
12444 | ::llvm::Optional<::mlir::tfg::RegionAttr> StatelessIfRegionOp::getElseRegionAttrs() { |
12445 | auto attr = getElseRegionAttrsAttr(); |
12446 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
12447 | } |
12448 | |
12449 | ::mlir::tfg::RegionAttr StatelessIfRegionOp::else_region_attrsAttr() { |
12450 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getElseRegionAttrsAttrName()).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
12451 | } |
12452 | |
12453 | ::llvm::Optional<::mlir::tfg::RegionAttr> StatelessIfRegionOp::else_region_attrs() { |
12454 | auto attr = else_region_attrsAttr(); |
12455 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
12456 | } |
12457 | |
12458 | void StatelessIfRegionOp::setThenAttrsAttr(::mlir::DictionaryAttr attr) { |
12459 | (*this)->setAttr(getThenAttrsAttrName(), attr); |
12460 | } |
12461 | |
12462 | void StatelessIfRegionOp::then_attrsAttr(::mlir::DictionaryAttr attr) { |
12463 | (*this)->setAttr(then_attrsAttrName(), attr); |
12464 | } |
12465 | |
12466 | void StatelessIfRegionOp::setElseAttrsAttr(::mlir::DictionaryAttr attr) { |
12467 | (*this)->setAttr(getElseAttrsAttrName(), attr); |
12468 | } |
12469 | |
12470 | void StatelessIfRegionOp::else_attrsAttr(::mlir::DictionaryAttr attr) { |
12471 | (*this)->setAttr(else_attrsAttrName(), attr); |
12472 | } |
12473 | |
12474 | void StatelessIfRegionOp::setThenRegionAttrsAttr(::mlir::tfg::RegionAttr attr) { |
12475 | (*this)->setAttr(getThenRegionAttrsAttrName(), attr); |
12476 | } |
12477 | |
12478 | void StatelessIfRegionOp::then_region_attrsAttr(::mlir::tfg::RegionAttr attr) { |
12479 | (*this)->setAttr(then_region_attrsAttrName(), attr); |
12480 | } |
12481 | |
12482 | void StatelessIfRegionOp::setElseRegionAttrsAttr(::mlir::tfg::RegionAttr attr) { |
12483 | (*this)->setAttr(getElseRegionAttrsAttrName(), attr); |
12484 | } |
12485 | |
12486 | void StatelessIfRegionOp::else_region_attrsAttr(::mlir::tfg::RegionAttr attr) { |
12487 | (*this)->setAttr(else_region_attrsAttrName(), attr); |
12488 | } |
12489 | |
12490 | ::mlir::Attribute StatelessIfRegionOp::removeThen_attrsAttr() { |
12491 | return (*this)->removeAttr(getThenAttrsAttrName()); |
12492 | } |
12493 | |
12494 | ::mlir::Attribute StatelessIfRegionOp::removeElse_attrsAttr() { |
12495 | return (*this)->removeAttr(getElseAttrsAttrName()); |
12496 | } |
12497 | |
12498 | ::mlir::Attribute StatelessIfRegionOp::removeThen_region_attrsAttr() { |
12499 | return (*this)->removeAttr(getThenRegionAttrsAttrName()); |
12500 | } |
12501 | |
12502 | ::mlir::Attribute StatelessIfRegionOp::removeElse_region_attrsAttr() { |
12503 | return (*this)->removeAttr(getElseRegionAttrsAttrName()); |
12504 | } |
12505 | |
12506 | void StatelessIfRegionOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange outs, ::mlir::Type ctl, ::mlir::Value cond, ::mlir::ValueRange ctls, /*optional*/::mlir::DictionaryAttr then_attrs, /*optional*/::mlir::DictionaryAttr else_attrs, /*optional*/::mlir::tfg::RegionAttr then_region_attrs, /*optional*/::mlir::tfg::RegionAttr else_region_attrs) { |
12507 | odsState.addOperands(cond); |
12508 | odsState.addOperands(ctls); |
12509 | if (then_attrs) { |
12510 | odsState.addAttribute(getThenAttrsAttrName(odsState.name), then_attrs); |
12511 | } |
12512 | if (else_attrs) { |
12513 | odsState.addAttribute(getElseAttrsAttrName(odsState.name), else_attrs); |
12514 | } |
12515 | if (then_region_attrs) { |
12516 | odsState.addAttribute(getThenRegionAttrsAttrName(odsState.name), then_region_attrs); |
12517 | } |
12518 | if (else_region_attrs) { |
12519 | odsState.addAttribute(getElseRegionAttrsAttrName(odsState.name), else_region_attrs); |
12520 | } |
12521 | (void)odsState.addRegion(); |
12522 | (void)odsState.addRegion(); |
12523 | odsState.addTypes(outs); |
12524 | odsState.addTypes(ctl); |
12525 | } |
12526 | |
12527 | void StatelessIfRegionOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::Value cond, ::mlir::ValueRange ctls, /*optional*/::mlir::DictionaryAttr then_attrs, /*optional*/::mlir::DictionaryAttr else_attrs, /*optional*/::mlir::tfg::RegionAttr then_region_attrs, /*optional*/::mlir::tfg::RegionAttr else_region_attrs) { |
12528 | odsState.addOperands(cond); |
12529 | odsState.addOperands(ctls); |
12530 | if (then_attrs) { |
12531 | odsState.addAttribute(getThenAttrsAttrName(odsState.name), then_attrs); |
12532 | } |
12533 | if (else_attrs) { |
12534 | odsState.addAttribute(getElseAttrsAttrName(odsState.name), else_attrs); |
12535 | } |
12536 | if (then_region_attrs) { |
12537 | odsState.addAttribute(getThenRegionAttrsAttrName(odsState.name), then_region_attrs); |
12538 | } |
12539 | if (else_region_attrs) { |
12540 | odsState.addAttribute(getElseRegionAttrsAttrName(odsState.name), else_region_attrs); |
12541 | } |
12542 | (void)odsState.addRegion(); |
12543 | (void)odsState.addRegion(); |
12544 | assert(resultTypes.size() >= 1u && "mismatched number of results" ); |
12545 | odsState.addTypes(resultTypes); |
12546 | } |
12547 | |
12548 | void StatelessIfRegionOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { |
12549 | assert(operands.size() >= 1u && "mismatched number of parameters" ); |
12550 | odsState.addOperands(operands); |
12551 | odsState.addAttributes(attributes); |
12552 | for (unsigned i = 0; i != 2; ++i) |
12553 | (void)odsState.addRegion(); |
12554 | assert(resultTypes.size() >= 1u && "mismatched number of return types" ); |
12555 | odsState.addTypes(resultTypes); |
12556 | } |
12557 | |
12558 | ::mlir::LogicalResult StatelessIfRegionOp::verifyInvariantsImpl() { |
12559 | auto namedAttrRange = (*this)->getAttrs(); |
12560 | auto namedAttrIt = namedAttrRange.begin(); |
12561 | ::mlir::Attribute tblgen_else_attrs; |
12562 | ::mlir::Attribute tblgen_else_region_attrs; |
12563 | ::mlir::Attribute tblgen_then_attrs; |
12564 | ::mlir::Attribute tblgen_then_region_attrs; |
12565 | while (true) { |
12566 | if (namedAttrIt == namedAttrRange.end()) { |
12567 | break; |
12568 | } |
12569 | else if (namedAttrIt->getName() == getElseAttrsAttrName()) { |
12570 | tblgen_else_attrs = namedAttrIt->getValue(); |
12571 | } |
12572 | else if (namedAttrIt->getName() == getElseRegionAttrsAttrName()) { |
12573 | tblgen_else_region_attrs = namedAttrIt->getValue(); |
12574 | } |
12575 | else if (namedAttrIt->getName() == getThenAttrsAttrName()) { |
12576 | tblgen_then_attrs = namedAttrIt->getValue(); |
12577 | } |
12578 | else if (namedAttrIt->getName() == getThenRegionAttrsAttrName()) { |
12579 | tblgen_then_region_attrs = namedAttrIt->getValue(); |
12580 | } |
12581 | ++namedAttrIt; |
12582 | } |
12583 | |
12584 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops6(*this, tblgen_then_attrs, "then_attrs" ))) |
12585 | return ::mlir::failure(); |
12586 | |
12587 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops6(*this, tblgen_else_attrs, "else_attrs" ))) |
12588 | return ::mlir::failure(); |
12589 | |
12590 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops7(*this, tblgen_then_region_attrs, "then_region_attrs" ))) |
12591 | return ::mlir::failure(); |
12592 | |
12593 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops7(*this, tblgen_else_region_attrs, "else_region_attrs" ))) |
12594 | return ::mlir::failure(); |
12595 | { |
12596 | unsigned index = 0; (void)index; |
12597 | auto valueGroup0 = getODSOperands(0); |
12598 | |
12599 | for (auto v : valueGroup0) { |
12600 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops5(*this, v.getType(), "operand" , index++))) |
12601 | return ::mlir::failure(); |
12602 | } |
12603 | auto valueGroup1 = getODSOperands(1); |
12604 | |
12605 | for (auto v : valueGroup1) { |
12606 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops3(*this, v.getType(), "operand" , index++))) |
12607 | return ::mlir::failure(); |
12608 | } |
12609 | } |
12610 | { |
12611 | unsigned index = 0; (void)index; |
12612 | auto valueGroup0 = getODSResults(0); |
12613 | |
12614 | for (auto v : valueGroup0) { |
12615 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops2(*this, v.getType(), "result" , index++))) |
12616 | return ::mlir::failure(); |
12617 | } |
12618 | auto valueGroup1 = getODSResults(1); |
12619 | |
12620 | for (auto v : valueGroup1) { |
12621 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops3(*this, v.getType(), "result" , index++))) |
12622 | return ::mlir::failure(); |
12623 | } |
12624 | } |
12625 | { |
12626 | unsigned index = 0; (void)index; |
12627 | |
12628 | for (auto ®ion : ::llvm::makeMutableArrayRef((*this)->getRegion(0))) |
12629 | if (::mlir::failed(__mlir_ods_local_region_constraint_ops0(*this, region, "then_region" , index++))) |
12630 | return ::mlir::failure(); |
12631 | |
12632 | for (auto ®ion : ::llvm::makeMutableArrayRef((*this)->getRegion(1))) |
12633 | if (::mlir::failed(__mlir_ods_local_region_constraint_ops0(*this, region, "else_region" , index++))) |
12634 | return ::mlir::failure(); |
12635 | } |
12636 | return ::mlir::success(); |
12637 | } |
12638 | |
12639 | ::mlir::LogicalResult StatelessIfRegionOp::verifyInvariants() { |
12640 | if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) |
12641 | return ::mlir::success(); |
12642 | return ::mlir::failure(); |
12643 | } |
12644 | |
12645 | ::mlir::ParseResult StatelessIfRegionOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { |
12646 | ::mlir::OpAsmParser::UnresolvedOperand condRawOperands[1]; |
12647 | ::llvm::ArrayRef<::mlir::OpAsmParser::UnresolvedOperand> condOperands(condRawOperands); ::llvm::SMLoc condOperandsLoc; |
12648 | (void)condOperandsLoc; |
12649 | ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> ctlsOperands; |
12650 | ::llvm::SMLoc ctlsOperandsLoc; |
12651 | (void)ctlsOperandsLoc; |
12652 | std::unique_ptr<::mlir::Region> then_regionRegion = std::make_unique<::mlir::Region>(); |
12653 | std::unique_ptr<::mlir::Region> else_regionRegion = std::make_unique<::mlir::Region>(); |
12654 | ::llvm::ArrayRef<::mlir::Type> condTypes; |
12655 | ::llvm::ArrayRef<::mlir::Type> outsTypes; |
12656 | |
12657 | condOperandsLoc = parser.getCurrentLocation(); |
12658 | if (parser.parseOperand(condRawOperands[0])) |
12659 | return ::mlir::failure(); |
12660 | if (::mlir::succeeded(parser.parseOptionalLSquare())) { |
12661 | |
12662 | ctlsOperandsLoc = parser.getCurrentLocation(); |
12663 | if (parser.parseOperandList(ctlsOperands)) |
12664 | return ::mlir::failure(); |
12665 | if (parser.parseRSquare()) |
12666 | return ::mlir::failure(); |
12667 | } |
12668 | if (parser.parseKeyword("then" )) |
12669 | return ::mlir::failure(); |
12670 | |
12671 | if (parser.parseRegion(*then_regionRegion)) |
12672 | return ::mlir::failure(); |
12673 | |
12674 | if (then_regionRegion->empty()) then_regionRegion->emplaceBlock(); |
12675 | if (parser.parseKeyword("else" )) |
12676 | return ::mlir::failure(); |
12677 | |
12678 | if (parser.parseRegion(*else_regionRegion)) |
12679 | return ::mlir::failure(); |
12680 | |
12681 | if (else_regionRegion->empty()) else_regionRegion->emplaceBlock(); |
12682 | if (parser.parseOptionalAttrDict(result.attributes)) |
12683 | return ::mlir::failure(); |
12684 | if (parser.parseColon()) |
12685 | return ::mlir::failure(); |
12686 | |
12687 | ::mlir::FunctionType cond__outs_functionType; |
12688 | if (parser.parseType(cond__outs_functionType)) |
12689 | return ::mlir::failure(); |
12690 | condTypes = cond__outs_functionType.getInputs(); |
12691 | outsTypes = cond__outs_functionType.getResults(); |
12692 | result.addRegion(std::move(then_regionRegion)); |
12693 | result.addRegion(std::move(else_regionRegion)); |
12694 | ::mlir::Type odsBuildableType0 = parser.getBuilder().getType<::mlir::tf_type::ControlType>(); |
12695 | result.addTypes(outsTypes); |
12696 | result.addTypes(odsBuildableType0); |
12697 | if (parser.resolveOperands(condOperands, condTypes, condOperandsLoc, result.operands)) |
12698 | return ::mlir::failure(); |
12699 | if (parser.resolveOperands(ctlsOperands, odsBuildableType0, ctlsOperandsLoc, result.operands)) |
12700 | return ::mlir::failure(); |
12701 | return ::mlir::success(); |
12702 | } |
12703 | |
12704 | void StatelessIfRegionOp::print(::mlir::OpAsmPrinter &_odsPrinter) { |
12705 | _odsPrinter << ' '; |
12706 | _odsPrinter << getCond(); |
12707 | if (!getCtls().empty()) { |
12708 | _odsPrinter << ' '; |
12709 | _odsPrinter << "[" ; |
12710 | _odsPrinter << getCtls(); |
12711 | _odsPrinter << "]" ; |
12712 | } |
12713 | _odsPrinter << ' ' << "then" ; |
12714 | _odsPrinter << ' '; |
12715 | _odsPrinter.printRegion(getThenRegion()); |
12716 | _odsPrinter << ' ' << "else" ; |
12717 | _odsPrinter << ' '; |
12718 | _odsPrinter.printRegion(getElseRegion()); |
12719 | _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), /*elidedAttrs=*/{}); |
12720 | _odsPrinter << ' ' << ":" ; |
12721 | _odsPrinter << ' '; |
12722 | _odsPrinter.printFunctionalType(::llvm::ArrayRef<::mlir::Type>(getCond().getType()), getOuts().getTypes()); |
12723 | } |
12724 | |
12725 | StringRef StatelessIfRegionOp::getDefaultDialect() { return "tfg" ; } |
12726 | void StatelessIfRegionOp::getAsmResultNames(OpAsmSetValueNameFn setNameFn) { |
12727 | GenericGetAsmResultNames(*this, setNameFn); |
12728 | } |
12729 | |
12730 | YieldOp StatelessIfRegionOp::then_yield() { |
12731 | return cast<YieldOp>(then_block().getTerminator()); |
12732 | } |
12733 | YieldOp StatelessIfRegionOp::else_yield() { |
12734 | return cast<YieldOp>(else_block().getTerminator()); |
12735 | } |
12736 | |
12737 | void StatelessIfRegionOp::getSuccessorRegions( |
12738 | Optional<unsigned> index, ArrayRef<Attribute> operands, |
12739 | SmallVectorImpl<RegionSuccessor> ®ions) { |
12740 | GetIfLikeRegionOpSuccessorRegions(*this, index, operands, regions); |
12741 | } |
12742 | void StatelessIfRegionOp::getRegionInvocationBounds( |
12743 | ArrayRef<Attribute> operands, |
12744 | SmallVectorImpl<InvocationBounds> &invocationBounds) { |
12745 | invocationBounds.append(/*NumInputs=*/2, /*Elt=*/{0, 1}); |
12746 | } |
12747 | |
12748 | LogicalResult StatelessIfRegionOp::verify() { return VerifyIfLikeRegionOp(*this); } |
12749 | |
12750 | BlockArgument StatelessIfRegionOp::getDataValueOf(BlockArgument ctl) { |
12751 | return GetLoopRegionDataOf(ctl); |
12752 | } |
12753 | BlockArgument StatelessIfRegionOp::getControlTokenOf(BlockArgument data) { |
12754 | return GetLoopRegionControlOf(data); |
12755 | } |
12756 | BlockArgument StatelessIfRegionOp::getDataValue(Region ®ion, unsigned idx) { |
12757 | return GetLoopRegionDataArgs(region)[idx]; |
12758 | } |
12759 | BlockArgument StatelessIfRegionOp::getControlToken(Region ®ion, unsigned idx) { |
12760 | return GetLoopRegionControlTokens(region)[idx]; |
12761 | } |
12762 | } // namespace tfg |
12763 | } // namespace mlir |
12764 | MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::tfg::StatelessIfRegionOp) |
12765 | |
12766 | namespace mlir { |
12767 | namespace tfg { |
12768 | |
12769 | //===----------------------------------------------------------------------===// |
12770 | // ::mlir::tfg::StatelessWhileOp definitions |
12771 | //===----------------------------------------------------------------------===// |
12772 | |
12773 | StatelessWhileOpAdaptor::StatelessWhileOpAdaptor(::mlir::ValueRange values, ::mlir::DictionaryAttr attrs, ::mlir::RegionRange regions) : odsOperands(values), odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) |
12774 | odsOpName.emplace("tfg.StatelessWhile" , odsAttrs.getContext()); |
12775 | } |
12776 | |
12777 | StatelessWhileOpAdaptor::StatelessWhileOpAdaptor(StatelessWhileOp op) : odsOperands(op->getOperands()), odsAttrs(op->getAttrDictionary()), odsRegions(op->getRegions()), odsOpName(op->getName()) {} |
12778 | |
12779 | ::mlir::ValueRange StatelessWhileOpAdaptor::getOperands() { |
12780 | return odsOperands; |
12781 | } |
12782 | |
12783 | std::pair<unsigned, unsigned> StatelessWhileOpAdaptor::getODSOperandIndexAndLength(unsigned index) { |
12784 | bool isVariadic[] = {true}; |
12785 | int prevVariadicCount = 0; |
12786 | for (unsigned i = 0; i < index; ++i) |
12787 | if (isVariadic[i]) ++prevVariadicCount; |
12788 | |
12789 | // Calculate how many dynamic values a static variadic operand corresponds to. |
12790 | // This assumes all static variadic operands have the same dynamic value count. |
12791 | int variadicSize = (odsOperands.size() - 0) / 1; |
12792 | // `index` passed in as the parameter is the static index which counts each |
12793 | // operand (variadic or not) as size 1. So here for each previous static variadic |
12794 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
12795 | // value pack for this static operand starts. |
12796 | int start = index + (variadicSize - 1) * prevVariadicCount; |
12797 | int size = isVariadic[index] ? variadicSize : 1; |
12798 | return {start, size}; |
12799 | } |
12800 | |
12801 | ::mlir::ValueRange StatelessWhileOpAdaptor::getODSOperands(unsigned index) { |
12802 | auto valueRange = getODSOperandIndexAndLength(index); |
12803 | return {std::next(odsOperands.begin(), valueRange.first), |
12804 | std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; |
12805 | } |
12806 | |
12807 | ::mlir::ValueRange StatelessWhileOpAdaptor::getArgs() { |
12808 | return getODSOperands(0); |
12809 | } |
12810 | |
12811 | ::mlir::ValueRange StatelessWhileOpAdaptor::args() { |
12812 | return getODSOperands(0); |
12813 | } |
12814 | |
12815 | ::mlir::DictionaryAttr StatelessWhileOpAdaptor::getAttributes() { |
12816 | return odsAttrs; |
12817 | } |
12818 | |
12819 | ::mlir::tf_type::FuncAttr StatelessWhileOpAdaptor::getCondAttr() { |
12820 | assert(odsAttrs && "no attributes when constructing adapter" ); |
12821 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 1, StatelessWhileOp::getCondAttrName(*odsOpName)).cast<::mlir::tf_type::FuncAttr>(); |
12822 | return attr; |
12823 | } |
12824 | |
12825 | ::mlir::tf_type::FuncAttr StatelessWhileOpAdaptor::getCond() { |
12826 | auto attr = getCondAttr(); |
12827 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
12828 | } |
12829 | |
12830 | ::mlir::tf_type::FuncAttr StatelessWhileOpAdaptor::condAttr() { |
12831 | assert(odsAttrs && "no attributes when constructing adapter" ); |
12832 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 1, StatelessWhileOp::getCondAttrName(*odsOpName)).cast<::mlir::tf_type::FuncAttr>(); |
12833 | return attr; |
12834 | } |
12835 | |
12836 | ::mlir::tf_type::FuncAttr StatelessWhileOpAdaptor::cond() { |
12837 | auto attr = condAttr(); |
12838 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
12839 | } |
12840 | |
12841 | ::mlir::tf_type::FuncAttr StatelessWhileOpAdaptor::getBodyAttr() { |
12842 | assert(odsAttrs && "no attributes when constructing adapter" ); |
12843 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, StatelessWhileOp::getBodyAttrName(*odsOpName)).cast<::mlir::tf_type::FuncAttr>(); |
12844 | return attr; |
12845 | } |
12846 | |
12847 | ::mlir::tf_type::FuncAttr StatelessWhileOpAdaptor::getBody() { |
12848 | auto attr = getBodyAttr(); |
12849 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
12850 | } |
12851 | |
12852 | ::mlir::tf_type::FuncAttr StatelessWhileOpAdaptor::bodyAttr() { |
12853 | assert(odsAttrs && "no attributes when constructing adapter" ); |
12854 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, StatelessWhileOp::getBodyAttrName(*odsOpName)).cast<::mlir::tf_type::FuncAttr>(); |
12855 | return attr; |
12856 | } |
12857 | |
12858 | ::mlir::tf_type::FuncAttr StatelessWhileOpAdaptor::body() { |
12859 | auto attr = bodyAttr(); |
12860 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
12861 | } |
12862 | |
12863 | ::mlir::IntegerAttr StatelessWhileOpAdaptor::getParallelIterationsAttr() { |
12864 | assert(odsAttrs && "no attributes when constructing adapter" ); |
12865 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 2, odsAttrs.end() - 0, StatelessWhileOp::getParallelIterationsAttrName(*odsOpName)).cast<::mlir::IntegerAttr>(); |
12866 | return attr; |
12867 | } |
12868 | |
12869 | uint64_t StatelessWhileOpAdaptor::getParallelIterations() { |
12870 | auto attr = getParallelIterationsAttr(); |
12871 | return attr.getValue().getZExtValue(); |
12872 | } |
12873 | |
12874 | ::mlir::IntegerAttr StatelessWhileOpAdaptor::parallel_iterationsAttr() { |
12875 | assert(odsAttrs && "no attributes when constructing adapter" ); |
12876 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 2, odsAttrs.end() - 0, StatelessWhileOp::getParallelIterationsAttrName(*odsOpName)).cast<::mlir::IntegerAttr>(); |
12877 | return attr; |
12878 | } |
12879 | |
12880 | uint64_t StatelessWhileOpAdaptor::parallel_iterations() { |
12881 | auto attr = parallel_iterationsAttr(); |
12882 | return attr.getValue().getZExtValue(); |
12883 | } |
12884 | |
12885 | ::mlir::ArrayAttr StatelessWhileOpAdaptor::getTAttr() { |
12886 | assert(odsAttrs && "no attributes when constructing adapter" ); |
12887 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 3, StatelessWhileOp::getTAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
12888 | return attr; |
12889 | } |
12890 | |
12891 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessWhileOpAdaptor::getT() { |
12892 | auto attr = getTAttr(); |
12893 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
12894 | } |
12895 | |
12896 | ::mlir::ArrayAttr StatelessWhileOpAdaptor::TAttr() { |
12897 | assert(odsAttrs && "no attributes when constructing adapter" ); |
12898 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 3, StatelessWhileOp::getTAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
12899 | return attr; |
12900 | } |
12901 | |
12902 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessWhileOpAdaptor::T() { |
12903 | auto attr = TAttr(); |
12904 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
12905 | } |
12906 | |
12907 | ::mlir::ArrayAttr StatelessWhileOpAdaptor::getOutputShapesAttr() { |
12908 | assert(odsAttrs && "no attributes when constructing adapter" ); |
12909 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 2, odsAttrs.end() - 1, StatelessWhileOp::getOutputShapesAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
12910 | return attr; |
12911 | } |
12912 | |
12913 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessWhileOpAdaptor::getOutputShapes() { |
12914 | auto attr = getOutputShapesAttr(); |
12915 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
12916 | } |
12917 | |
12918 | ::mlir::ArrayAttr StatelessWhileOpAdaptor::output_shapesAttr() { |
12919 | assert(odsAttrs && "no attributes when constructing adapter" ); |
12920 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 2, odsAttrs.end() - 1, StatelessWhileOp::getOutputShapesAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
12921 | return attr; |
12922 | } |
12923 | |
12924 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessWhileOpAdaptor::output_shapes() { |
12925 | auto attr = output_shapesAttr(); |
12926 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
12927 | } |
12928 | |
12929 | ::mlir::LogicalResult StatelessWhileOpAdaptor::verify(::mlir::Location loc) { |
12930 | auto namedAttrRange = odsAttrs; |
12931 | auto namedAttrIt = namedAttrRange.begin(); |
12932 | ::mlir::Attribute tblgen_body; |
12933 | ::mlir::Attribute tblgen_T; |
12934 | while (true) { |
12935 | if (namedAttrIt == namedAttrRange.end()) |
12936 | return emitError(loc, "'tfg.StatelessWhile' op " "requires attribute 'body'" ); |
12937 | if (namedAttrIt->getName() == StatelessWhileOp::getBodyAttrName(*odsOpName)) { |
12938 | tblgen_body = namedAttrIt->getValue(); |
12939 | break; |
12940 | } |
12941 | else if (namedAttrIt->getName() == StatelessWhileOp::getTAttrName(*odsOpName)) { |
12942 | tblgen_T = namedAttrIt->getValue(); |
12943 | } |
12944 | ++namedAttrIt; |
12945 | } |
12946 | ::mlir::Attribute tblgen_cond; |
12947 | while (true) { |
12948 | if (namedAttrIt == namedAttrRange.end()) |
12949 | return emitError(loc, "'tfg.StatelessWhile' op " "requires attribute 'cond'" ); |
12950 | if (namedAttrIt->getName() == StatelessWhileOp::getCondAttrName(*odsOpName)) { |
12951 | tblgen_cond = namedAttrIt->getValue(); |
12952 | break; |
12953 | } |
12954 | ++namedAttrIt; |
12955 | } |
12956 | ::mlir::Attribute tblgen_parallel_iterations; |
12957 | ::mlir::Attribute tblgen_output_shapes; |
12958 | while (true) { |
12959 | if (namedAttrIt == namedAttrRange.end()) |
12960 | return emitError(loc, "'tfg.StatelessWhile' op " "requires attribute 'parallel_iterations'" ); |
12961 | if (namedAttrIt->getName() == StatelessWhileOp::getParallelIterationsAttrName(*odsOpName)) { |
12962 | tblgen_parallel_iterations = namedAttrIt->getValue(); |
12963 | break; |
12964 | } |
12965 | else if (namedAttrIt->getName() == StatelessWhileOp::getOutputShapesAttrName(*odsOpName)) { |
12966 | tblgen_output_shapes = namedAttrIt->getValue(); |
12967 | } |
12968 | ++namedAttrIt; |
12969 | } |
12970 | |
12971 | if (tblgen_cond && !((tblgen_cond.isa<::mlir::tf_type::FuncAttr>()))) |
12972 | return emitError(loc, "'tfg.StatelessWhile' op " "attribute 'cond' failed to satisfy constraint: Models the `AttrValue.value.func` proto attribute value as a pair of SymbolRef and DictionaryAttr" ); |
12973 | |
12974 | if (tblgen_body && !((tblgen_body.isa<::mlir::tf_type::FuncAttr>()))) |
12975 | return emitError(loc, "'tfg.StatelessWhile' op " "attribute 'body' failed to satisfy constraint: Models the `AttrValue.value.func` proto attribute value as a pair of SymbolRef and DictionaryAttr" ); |
12976 | |
12977 | if (tblgen_parallel_iterations && !(((tblgen_parallel_iterations.isa<::mlir::IntegerAttr>())) && ((tblgen_parallel_iterations.cast<::mlir::IntegerAttr>().getType().isSignlessInteger(64))))) |
12978 | return emitError(loc, "'tfg.StatelessWhile' op " "attribute 'parallel_iterations' failed to satisfy constraint: 64-bit signless integer attribute" ); |
12979 | |
12980 | if (tblgen_T && !(((tblgen_T.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_T.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && (((attr.isa<::mlir::TypeAttr>())) && ((attr.cast<::mlir::TypeAttr>().getValue().isa<::mlir::Type>()))); })))) |
12981 | return emitError(loc, "'tfg.StatelessWhile' op " "attribute 'T' failed to satisfy constraint: type array attribute" ); |
12982 | |
12983 | if (tblgen_output_shapes && !(((tblgen_output_shapes.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_output_shapes.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && ((attr.isa<::mlir::tf_type::ShapeAttr>())); })))) |
12984 | return emitError(loc, "'tfg.StatelessWhile' op " "attribute 'output_shapes' failed to satisfy constraint: An array of shapes." ); |
12985 | return ::mlir::success(); |
12986 | } |
12987 | |
12988 | void StatelessWhileOp::getAsmResultNames(::mlir::OpAsmSetValueNameFn setNameFn) { |
12989 | auto resultGroup0 = getODSResults(0); |
12990 | if (!resultGroup0.empty()) |
12991 | setNameFn(*resultGroup0.begin(), "outs" ); |
12992 | auto resultGroup1 = getODSResults(1); |
12993 | if (!resultGroup1.empty()) |
12994 | setNameFn(*resultGroup1.begin(), "ctl" ); |
12995 | } |
12996 | |
12997 | std::pair<unsigned, unsigned> StatelessWhileOp::getODSOperandIndexAndLength(unsigned index) { |
12998 | bool isVariadic[] = {true}; |
12999 | int prevVariadicCount = 0; |
13000 | for (unsigned i = 0; i < index; ++i) |
13001 | if (isVariadic[i]) ++prevVariadicCount; |
13002 | |
13003 | // Calculate how many dynamic values a static variadic operand corresponds to. |
13004 | // This assumes all static variadic operands have the same dynamic value count. |
13005 | int variadicSize = (getOperation()->getNumOperands() - 0) / 1; |
13006 | // `index` passed in as the parameter is the static index which counts each |
13007 | // operand (variadic or not) as size 1. So here for each previous static variadic |
13008 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
13009 | // value pack for this static operand starts. |
13010 | int start = index + (variadicSize - 1) * prevVariadicCount; |
13011 | int size = isVariadic[index] ? variadicSize : 1; |
13012 | return {start, size}; |
13013 | } |
13014 | |
13015 | ::mlir::Operation::operand_range StatelessWhileOp::getODSOperands(unsigned index) { |
13016 | auto valueRange = getODSOperandIndexAndLength(index); |
13017 | return {std::next(getOperation()->operand_begin(), valueRange.first), |
13018 | std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; |
13019 | } |
13020 | |
13021 | ::mlir::Operation::operand_range StatelessWhileOp::getArgs() { |
13022 | return getODSOperands(0); |
13023 | } |
13024 | |
13025 | ::mlir::Operation::operand_range StatelessWhileOp::args() { |
13026 | return getODSOperands(0); |
13027 | } |
13028 | |
13029 | ::mlir::MutableOperandRange StatelessWhileOp::getArgsMutable() { |
13030 | auto range = getODSOperandIndexAndLength(0); |
13031 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
13032 | return mutableRange; |
13033 | } |
13034 | |
13035 | ::mlir::MutableOperandRange StatelessWhileOp::argsMutable() { |
13036 | auto range = getODSOperandIndexAndLength(0); |
13037 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
13038 | return mutableRange; |
13039 | } |
13040 | |
13041 | std::pair<unsigned, unsigned> StatelessWhileOp::getODSResultIndexAndLength(unsigned index) { |
13042 | bool isVariadic[] = {true, false}; |
13043 | int prevVariadicCount = 0; |
13044 | for (unsigned i = 0; i < index; ++i) |
13045 | if (isVariadic[i]) ++prevVariadicCount; |
13046 | |
13047 | // Calculate how many dynamic values a static variadic operand corresponds to. |
13048 | // This assumes all static variadic operands have the same dynamic value count. |
13049 | int variadicSize = (getOperation()->getNumResults() - 1) / 1; |
13050 | // `index` passed in as the parameter is the static index which counts each |
13051 | // operand (variadic or not) as size 1. So here for each previous static variadic |
13052 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
13053 | // value pack for this static operand starts. |
13054 | int start = index + (variadicSize - 1) * prevVariadicCount; |
13055 | int size = isVariadic[index] ? variadicSize : 1; |
13056 | return {start, size}; |
13057 | } |
13058 | |
13059 | ::mlir::Operation::result_range StatelessWhileOp::getODSResults(unsigned index) { |
13060 | auto valueRange = getODSResultIndexAndLength(index); |
13061 | return {std::next(getOperation()->result_begin(), valueRange.first), |
13062 | std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; |
13063 | } |
13064 | |
13065 | ::mlir::Operation::result_range StatelessWhileOp::getOuts() { |
13066 | return getODSResults(0); |
13067 | } |
13068 | |
13069 | ::mlir::Operation::result_range StatelessWhileOp::outs() { |
13070 | return getODSResults(0); |
13071 | } |
13072 | |
13073 | ::mlir::TypedValue<::mlir::tf_type::ControlType> StatelessWhileOp::getCtl() { |
13074 | return *getODSResults(1).begin(); |
13075 | } |
13076 | |
13077 | ::mlir::TypedValue<::mlir::tf_type::ControlType> StatelessWhileOp::ctl() { |
13078 | return *getODSResults(1).begin(); |
13079 | } |
13080 | |
13081 | ::mlir::tf_type::FuncAttr StatelessWhileOp::getCondAttr() { |
13082 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 1, getCondAttrName()).cast<::mlir::tf_type::FuncAttr>(); |
13083 | } |
13084 | |
13085 | ::mlir::tf_type::FuncAttr StatelessWhileOp::getCond() { |
13086 | auto attr = getCondAttr(); |
13087 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
13088 | } |
13089 | |
13090 | ::mlir::tf_type::FuncAttr StatelessWhileOp::condAttr() { |
13091 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 1, getCondAttrName()).cast<::mlir::tf_type::FuncAttr>(); |
13092 | } |
13093 | |
13094 | ::mlir::tf_type::FuncAttr StatelessWhileOp::cond() { |
13095 | auto attr = condAttr(); |
13096 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
13097 | } |
13098 | |
13099 | ::mlir::tf_type::FuncAttr StatelessWhileOp::getBodyAttr() { |
13100 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getBodyAttrName()).cast<::mlir::tf_type::FuncAttr>(); |
13101 | } |
13102 | |
13103 | ::mlir::tf_type::FuncAttr StatelessWhileOp::getBody() { |
13104 | auto attr = getBodyAttr(); |
13105 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
13106 | } |
13107 | |
13108 | ::mlir::tf_type::FuncAttr StatelessWhileOp::bodyAttr() { |
13109 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getBodyAttrName()).cast<::mlir::tf_type::FuncAttr>(); |
13110 | } |
13111 | |
13112 | ::mlir::tf_type::FuncAttr StatelessWhileOp::body() { |
13113 | auto attr = bodyAttr(); |
13114 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
13115 | } |
13116 | |
13117 | ::mlir::IntegerAttr StatelessWhileOp::getParallelIterationsAttr() { |
13118 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 2, (*this)->getAttrs().end() - 0, getParallelIterationsAttrName()).cast<::mlir::IntegerAttr>(); |
13119 | } |
13120 | |
13121 | uint64_t StatelessWhileOp::getParallelIterations() { |
13122 | auto attr = getParallelIterationsAttr(); |
13123 | return attr.getValue().getZExtValue(); |
13124 | } |
13125 | |
13126 | ::mlir::IntegerAttr StatelessWhileOp::parallel_iterationsAttr() { |
13127 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 2, (*this)->getAttrs().end() - 0, getParallelIterationsAttrName()).cast<::mlir::IntegerAttr>(); |
13128 | } |
13129 | |
13130 | uint64_t StatelessWhileOp::parallel_iterations() { |
13131 | auto attr = parallel_iterationsAttr(); |
13132 | return attr.getValue().getZExtValue(); |
13133 | } |
13134 | |
13135 | ::mlir::ArrayAttr StatelessWhileOp::getTAttr() { |
13136 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 3, getTAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
13137 | } |
13138 | |
13139 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessWhileOp::getT() { |
13140 | auto attr = getTAttr(); |
13141 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
13142 | } |
13143 | |
13144 | ::mlir::ArrayAttr StatelessWhileOp::TAttr() { |
13145 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 3, getTAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
13146 | } |
13147 | |
13148 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessWhileOp::T() { |
13149 | auto attr = TAttr(); |
13150 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
13151 | } |
13152 | |
13153 | ::mlir::ArrayAttr StatelessWhileOp::getOutputShapesAttr() { |
13154 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 2, (*this)->getAttrs().end() - 1, getOutputShapesAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
13155 | } |
13156 | |
13157 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessWhileOp::getOutputShapes() { |
13158 | auto attr = getOutputShapesAttr(); |
13159 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
13160 | } |
13161 | |
13162 | ::mlir::ArrayAttr StatelessWhileOp::output_shapesAttr() { |
13163 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 2, (*this)->getAttrs().end() - 1, getOutputShapesAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
13164 | } |
13165 | |
13166 | ::llvm::Optional< ::mlir::ArrayAttr > StatelessWhileOp::output_shapes() { |
13167 | auto attr = output_shapesAttr(); |
13168 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
13169 | } |
13170 | |
13171 | void StatelessWhileOp::setCondAttr(::mlir::tf_type::FuncAttr attr) { |
13172 | (*this)->setAttr(getCondAttrName(), attr); |
13173 | } |
13174 | |
13175 | void StatelessWhileOp::condAttr(::mlir::tf_type::FuncAttr attr) { |
13176 | (*this)->setAttr(condAttrName(), attr); |
13177 | } |
13178 | |
13179 | void StatelessWhileOp::setBodyAttr(::mlir::tf_type::FuncAttr attr) { |
13180 | (*this)->setAttr(getBodyAttrName(), attr); |
13181 | } |
13182 | |
13183 | void StatelessWhileOp::bodyAttr(::mlir::tf_type::FuncAttr attr) { |
13184 | (*this)->setAttr(bodyAttrName(), attr); |
13185 | } |
13186 | |
13187 | void StatelessWhileOp::setParallelIterationsAttr(::mlir::IntegerAttr attr) { |
13188 | (*this)->setAttr(getParallelIterationsAttrName(), attr); |
13189 | } |
13190 | |
13191 | void StatelessWhileOp::parallel_iterationsAttr(::mlir::IntegerAttr attr) { |
13192 | (*this)->setAttr(parallel_iterationsAttrName(), attr); |
13193 | } |
13194 | |
13195 | void StatelessWhileOp::setTAttr(::mlir::ArrayAttr attr) { |
13196 | (*this)->setAttr(getTAttrName(), attr); |
13197 | } |
13198 | |
13199 | void StatelessWhileOp::TAttr(::mlir::ArrayAttr attr) { |
13200 | (*this)->setAttr(TAttrName(), attr); |
13201 | } |
13202 | |
13203 | void StatelessWhileOp::setOutputShapesAttr(::mlir::ArrayAttr attr) { |
13204 | (*this)->setAttr(getOutputShapesAttrName(), attr); |
13205 | } |
13206 | |
13207 | void StatelessWhileOp::output_shapesAttr(::mlir::ArrayAttr attr) { |
13208 | (*this)->setAttr(output_shapesAttrName(), attr); |
13209 | } |
13210 | |
13211 | ::mlir::Attribute StatelessWhileOp::removeTAttr() { |
13212 | return (*this)->removeAttr(getTAttrName()); |
13213 | } |
13214 | |
13215 | ::mlir::Attribute StatelessWhileOp::removeOutput_shapesAttr() { |
13216 | return (*this)->removeAttr(getOutputShapesAttrName()); |
13217 | } |
13218 | |
13219 | void StatelessWhileOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, TypeRange results, ValueRange args, FuncAttr cond, FuncAttr body, IntegerAttr parallel_iterations) { |
13220 | build(odsBuilder, odsState, results, args, cond, body, parallel_iterations, |
13221 | /*T=*/{}, /*output_shapes=*/{}); |
13222 | |
13223 | } |
13224 | |
13225 | void StatelessWhileOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange outs, ::mlir::Type ctl, ::mlir::ValueRange args, ::mlir::tf_type::FuncAttr cond, ::mlir::tf_type::FuncAttr body, ::mlir::IntegerAttr parallel_iterations, /*optional*/::mlir::ArrayAttr T, /*optional*/::mlir::ArrayAttr output_shapes) { |
13226 | odsState.addOperands(args); |
13227 | odsState.addAttribute(getCondAttrName(odsState.name), cond); |
13228 | odsState.addAttribute(getBodyAttrName(odsState.name), body); |
13229 | odsState.addAttribute(getParallelIterationsAttrName(odsState.name), parallel_iterations); |
13230 | if (T) { |
13231 | odsState.addAttribute(getTAttrName(odsState.name), T); |
13232 | } |
13233 | if (output_shapes) { |
13234 | odsState.addAttribute(getOutputShapesAttrName(odsState.name), output_shapes); |
13235 | } |
13236 | odsState.addTypes(outs); |
13237 | odsState.addTypes(ctl); |
13238 | } |
13239 | |
13240 | void StatelessWhileOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange args, ::mlir::tf_type::FuncAttr cond, ::mlir::tf_type::FuncAttr body, ::mlir::IntegerAttr parallel_iterations, /*optional*/::mlir::ArrayAttr T, /*optional*/::mlir::ArrayAttr output_shapes) { |
13241 | odsState.addOperands(args); |
13242 | odsState.addAttribute(getCondAttrName(odsState.name), cond); |
13243 | odsState.addAttribute(getBodyAttrName(odsState.name), body); |
13244 | odsState.addAttribute(getParallelIterationsAttrName(odsState.name), parallel_iterations); |
13245 | if (T) { |
13246 | odsState.addAttribute(getTAttrName(odsState.name), T); |
13247 | } |
13248 | if (output_shapes) { |
13249 | odsState.addAttribute(getOutputShapesAttrName(odsState.name), output_shapes); |
13250 | } |
13251 | assert(resultTypes.size() >= 1u && "mismatched number of results" ); |
13252 | odsState.addTypes(resultTypes); |
13253 | } |
13254 | |
13255 | void StatelessWhileOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange outs, ::mlir::Type ctl, ::mlir::ValueRange args, ::mlir::tf_type::FuncAttr cond, ::mlir::tf_type::FuncAttr body, uint64_t parallel_iterations, /*optional*/::mlir::ArrayAttr T, /*optional*/::mlir::ArrayAttr output_shapes) { |
13256 | odsState.addOperands(args); |
13257 | odsState.addAttribute(getCondAttrName(odsState.name), cond); |
13258 | odsState.addAttribute(getBodyAttrName(odsState.name), body); |
13259 | odsState.addAttribute(getParallelIterationsAttrName(odsState.name), odsBuilder.getIntegerAttr(odsBuilder.getIntegerType(64), parallel_iterations)); |
13260 | if (T) { |
13261 | odsState.addAttribute(getTAttrName(odsState.name), T); |
13262 | } |
13263 | if (output_shapes) { |
13264 | odsState.addAttribute(getOutputShapesAttrName(odsState.name), output_shapes); |
13265 | } |
13266 | odsState.addTypes(outs); |
13267 | odsState.addTypes(ctl); |
13268 | } |
13269 | |
13270 | void StatelessWhileOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange args, ::mlir::tf_type::FuncAttr cond, ::mlir::tf_type::FuncAttr body, uint64_t parallel_iterations, /*optional*/::mlir::ArrayAttr T, /*optional*/::mlir::ArrayAttr output_shapes) { |
13271 | odsState.addOperands(args); |
13272 | odsState.addAttribute(getCondAttrName(odsState.name), cond); |
13273 | odsState.addAttribute(getBodyAttrName(odsState.name), body); |
13274 | odsState.addAttribute(getParallelIterationsAttrName(odsState.name), odsBuilder.getIntegerAttr(odsBuilder.getIntegerType(64), parallel_iterations)); |
13275 | if (T) { |
13276 | odsState.addAttribute(getTAttrName(odsState.name), T); |
13277 | } |
13278 | if (output_shapes) { |
13279 | odsState.addAttribute(getOutputShapesAttrName(odsState.name), output_shapes); |
13280 | } |
13281 | assert(resultTypes.size() >= 1u && "mismatched number of results" ); |
13282 | odsState.addTypes(resultTypes); |
13283 | } |
13284 | |
13285 | void StatelessWhileOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { |
13286 | odsState.addOperands(operands); |
13287 | odsState.addAttributes(attributes); |
13288 | assert(resultTypes.size() >= 1u && "mismatched number of return types" ); |
13289 | odsState.addTypes(resultTypes); |
13290 | } |
13291 | |
13292 | ::mlir::LogicalResult StatelessWhileOp::verifyInvariantsImpl() { |
13293 | auto namedAttrRange = (*this)->getAttrs(); |
13294 | auto namedAttrIt = namedAttrRange.begin(); |
13295 | ::mlir::Attribute tblgen_body; |
13296 | ::mlir::Attribute tblgen_T; |
13297 | while (true) { |
13298 | if (namedAttrIt == namedAttrRange.end()) |
13299 | return emitOpError("requires attribute 'body'" ); |
13300 | if (namedAttrIt->getName() == getBodyAttrName()) { |
13301 | tblgen_body = namedAttrIt->getValue(); |
13302 | break; |
13303 | } |
13304 | else if (namedAttrIt->getName() == getTAttrName()) { |
13305 | tblgen_T = namedAttrIt->getValue(); |
13306 | } |
13307 | ++namedAttrIt; |
13308 | } |
13309 | ::mlir::Attribute tblgen_cond; |
13310 | while (true) { |
13311 | if (namedAttrIt == namedAttrRange.end()) |
13312 | return emitOpError("requires attribute 'cond'" ); |
13313 | if (namedAttrIt->getName() == getCondAttrName()) { |
13314 | tblgen_cond = namedAttrIt->getValue(); |
13315 | break; |
13316 | } |
13317 | ++namedAttrIt; |
13318 | } |
13319 | ::mlir::Attribute tblgen_parallel_iterations; |
13320 | ::mlir::Attribute tblgen_output_shapes; |
13321 | while (true) { |
13322 | if (namedAttrIt == namedAttrRange.end()) |
13323 | return emitOpError("requires attribute 'parallel_iterations'" ); |
13324 | if (namedAttrIt->getName() == getParallelIterationsAttrName()) { |
13325 | tblgen_parallel_iterations = namedAttrIt->getValue(); |
13326 | break; |
13327 | } |
13328 | else if (namedAttrIt->getName() == getOutputShapesAttrName()) { |
13329 | tblgen_output_shapes = namedAttrIt->getValue(); |
13330 | } |
13331 | ++namedAttrIt; |
13332 | } |
13333 | |
13334 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops5(*this, tblgen_cond, "cond" ))) |
13335 | return ::mlir::failure(); |
13336 | |
13337 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops5(*this, tblgen_body, "body" ))) |
13338 | return ::mlir::failure(); |
13339 | |
13340 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops18(*this, tblgen_parallel_iterations, "parallel_iterations" ))) |
13341 | return ::mlir::failure(); |
13342 | |
13343 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops1(*this, tblgen_T, "T" ))) |
13344 | return ::mlir::failure(); |
13345 | |
13346 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops2(*this, tblgen_output_shapes, "output_shapes" ))) |
13347 | return ::mlir::failure(); |
13348 | { |
13349 | unsigned index = 0; (void)index; |
13350 | auto valueGroup0 = getODSOperands(0); |
13351 | |
13352 | for (auto v : valueGroup0) { |
13353 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops1(*this, v.getType(), "operand" , index++))) |
13354 | return ::mlir::failure(); |
13355 | } |
13356 | } |
13357 | { |
13358 | unsigned index = 0; (void)index; |
13359 | auto valueGroup0 = getODSResults(0); |
13360 | |
13361 | for (auto v : valueGroup0) { |
13362 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops2(*this, v.getType(), "result" , index++))) |
13363 | return ::mlir::failure(); |
13364 | } |
13365 | auto valueGroup1 = getODSResults(1); |
13366 | |
13367 | for (auto v : valueGroup1) { |
13368 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops3(*this, v.getType(), "result" , index++))) |
13369 | return ::mlir::failure(); |
13370 | } |
13371 | } |
13372 | return ::mlir::success(); |
13373 | } |
13374 | |
13375 | ::mlir::LogicalResult StatelessWhileOp::verifyInvariants() { |
13376 | return verifyInvariantsImpl(); |
13377 | } |
13378 | |
13379 | LogicalResult StatelessWhileOp::verifySymbolUses( |
13380 | SymbolTableCollection &symbol_table) { |
13381 | return VerifyWhileLikeOp(*this, symbol_table); |
13382 | } |
13383 | } // namespace tfg |
13384 | } // namespace mlir |
13385 | MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::tfg::StatelessWhileOp) |
13386 | |
13387 | namespace mlir { |
13388 | namespace tfg { |
13389 | |
13390 | //===----------------------------------------------------------------------===// |
13391 | // ::mlir::tfg::StatelessWhileRegionOp definitions |
13392 | //===----------------------------------------------------------------------===// |
13393 | |
13394 | StatelessWhileRegionOpAdaptor::StatelessWhileRegionOpAdaptor(::mlir::ValueRange values, ::mlir::DictionaryAttr attrs, ::mlir::RegionRange regions) : odsOperands(values), odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) |
13395 | odsOpName.emplace("tfg.StatelessWhileRegion" , odsAttrs.getContext()); |
13396 | } |
13397 | |
13398 | StatelessWhileRegionOpAdaptor::StatelessWhileRegionOpAdaptor(StatelessWhileRegionOp op) : odsOperands(op->getOperands()), odsAttrs(op->getAttrDictionary()), odsRegions(op->getRegions()), odsOpName(op->getName()) {} |
13399 | |
13400 | ::mlir::ValueRange StatelessWhileRegionOpAdaptor::getOperands() { |
13401 | return odsOperands; |
13402 | } |
13403 | |
13404 | std::pair<unsigned, unsigned> StatelessWhileRegionOpAdaptor::getODSOperandIndexAndLength(unsigned index) { |
13405 | assert(odsAttrs && "missing segment size attribute for op" ); |
13406 | auto sizeAttr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 1, StatelessWhileRegionOp::getOperandSegmentSizesAttrName(*odsOpName)).cast<::mlir::DenseI32ArrayAttr>(); |
13407 | |
13408 | unsigned start = 0; |
13409 | for (unsigned i = 0; i < index; ++i) |
13410 | start += sizeAttr[i]; |
13411 | return {start, sizeAttr[index]}; |
13412 | } |
13413 | |
13414 | ::mlir::ValueRange StatelessWhileRegionOpAdaptor::getODSOperands(unsigned index) { |
13415 | auto valueRange = getODSOperandIndexAndLength(index); |
13416 | return {std::next(odsOperands.begin(), valueRange.first), |
13417 | std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; |
13418 | } |
13419 | |
13420 | ::mlir::ValueRange StatelessWhileRegionOpAdaptor::getInit() { |
13421 | return getODSOperands(0); |
13422 | } |
13423 | |
13424 | ::mlir::ValueRange StatelessWhileRegionOpAdaptor::init() { |
13425 | return getODSOperands(0); |
13426 | } |
13427 | |
13428 | ::mlir::ValueRange StatelessWhileRegionOpAdaptor::getCtls() { |
13429 | return getODSOperands(1); |
13430 | } |
13431 | |
13432 | ::mlir::ValueRange StatelessWhileRegionOpAdaptor::ctls() { |
13433 | return getODSOperands(1); |
13434 | } |
13435 | |
13436 | ::mlir::DictionaryAttr StatelessWhileRegionOpAdaptor::getAttributes() { |
13437 | return odsAttrs; |
13438 | } |
13439 | |
13440 | ::mlir::IntegerAttr StatelessWhileRegionOpAdaptor::getParallelIterationsAttr() { |
13441 | assert(odsAttrs && "no attributes when constructing adapter" ); |
13442 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 0, StatelessWhileRegionOp::getParallelIterationsAttrName(*odsOpName)).cast<::mlir::IntegerAttr>(); |
13443 | return attr; |
13444 | } |
13445 | |
13446 | uint64_t StatelessWhileRegionOpAdaptor::getParallelIterations() { |
13447 | auto attr = getParallelIterationsAttr(); |
13448 | return attr.getValue().getZExtValue(); |
13449 | } |
13450 | |
13451 | ::mlir::IntegerAttr StatelessWhileRegionOpAdaptor::parallel_iterationsAttr() { |
13452 | assert(odsAttrs && "no attributes when constructing adapter" ); |
13453 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 0, StatelessWhileRegionOp::getParallelIterationsAttrName(*odsOpName)).cast<::mlir::IntegerAttr>(); |
13454 | return attr; |
13455 | } |
13456 | |
13457 | uint64_t StatelessWhileRegionOpAdaptor::parallel_iterations() { |
13458 | auto attr = parallel_iterationsAttr(); |
13459 | return attr.getValue().getZExtValue(); |
13460 | } |
13461 | |
13462 | ::mlir::DictionaryAttr StatelessWhileRegionOpAdaptor::getCondAttrsAttr() { |
13463 | assert(odsAttrs && "no attributes when constructing adapter" ); |
13464 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, StatelessWhileRegionOp::getCondAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
13465 | return attr; |
13466 | } |
13467 | |
13468 | ::llvm::Optional< ::mlir::DictionaryAttr > StatelessWhileRegionOpAdaptor::getCondAttrs() { |
13469 | auto attr = getCondAttrsAttr(); |
13470 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
13471 | } |
13472 | |
13473 | ::mlir::DictionaryAttr StatelessWhileRegionOpAdaptor::cond_attrsAttr() { |
13474 | assert(odsAttrs && "no attributes when constructing adapter" ); |
13475 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, StatelessWhileRegionOp::getCondAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
13476 | return attr; |
13477 | } |
13478 | |
13479 | ::llvm::Optional< ::mlir::DictionaryAttr > StatelessWhileRegionOpAdaptor::cond_attrs() { |
13480 | auto attr = cond_attrsAttr(); |
13481 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
13482 | } |
13483 | |
13484 | ::mlir::DictionaryAttr StatelessWhileRegionOpAdaptor::getBodyAttrsAttr() { |
13485 | assert(odsAttrs && "no attributes when constructing adapter" ); |
13486 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, StatelessWhileRegionOp::getBodyAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
13487 | return attr; |
13488 | } |
13489 | |
13490 | ::llvm::Optional< ::mlir::DictionaryAttr > StatelessWhileRegionOpAdaptor::getBodyAttrs() { |
13491 | auto attr = getBodyAttrsAttr(); |
13492 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
13493 | } |
13494 | |
13495 | ::mlir::DictionaryAttr StatelessWhileRegionOpAdaptor::body_attrsAttr() { |
13496 | assert(odsAttrs && "no attributes when constructing adapter" ); |
13497 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, StatelessWhileRegionOp::getBodyAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
13498 | return attr; |
13499 | } |
13500 | |
13501 | ::llvm::Optional< ::mlir::DictionaryAttr > StatelessWhileRegionOpAdaptor::body_attrs() { |
13502 | auto attr = body_attrsAttr(); |
13503 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
13504 | } |
13505 | |
13506 | ::mlir::tfg::RegionAttr StatelessWhileRegionOpAdaptor::getCondRegionAttrsAttr() { |
13507 | assert(odsAttrs && "no attributes when constructing adapter" ); |
13508 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, StatelessWhileRegionOp::getCondRegionAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
13509 | return attr; |
13510 | } |
13511 | |
13512 | ::llvm::Optional<::mlir::tfg::RegionAttr> StatelessWhileRegionOpAdaptor::getCondRegionAttrs() { |
13513 | auto attr = getCondRegionAttrsAttr(); |
13514 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
13515 | } |
13516 | |
13517 | ::mlir::tfg::RegionAttr StatelessWhileRegionOpAdaptor::cond_region_attrsAttr() { |
13518 | assert(odsAttrs && "no attributes when constructing adapter" ); |
13519 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, StatelessWhileRegionOp::getCondRegionAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
13520 | return attr; |
13521 | } |
13522 | |
13523 | ::llvm::Optional<::mlir::tfg::RegionAttr> StatelessWhileRegionOpAdaptor::cond_region_attrs() { |
13524 | auto attr = cond_region_attrsAttr(); |
13525 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
13526 | } |
13527 | |
13528 | ::mlir::tfg::RegionAttr StatelessWhileRegionOpAdaptor::getBodyRegionAttrsAttr() { |
13529 | assert(odsAttrs && "no attributes when constructing adapter" ); |
13530 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, StatelessWhileRegionOp::getBodyRegionAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
13531 | return attr; |
13532 | } |
13533 | |
13534 | ::llvm::Optional<::mlir::tfg::RegionAttr> StatelessWhileRegionOpAdaptor::getBodyRegionAttrs() { |
13535 | auto attr = getBodyRegionAttrsAttr(); |
13536 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
13537 | } |
13538 | |
13539 | ::mlir::tfg::RegionAttr StatelessWhileRegionOpAdaptor::body_region_attrsAttr() { |
13540 | assert(odsAttrs && "no attributes when constructing adapter" ); |
13541 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, StatelessWhileRegionOp::getBodyRegionAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
13542 | return attr; |
13543 | } |
13544 | |
13545 | ::llvm::Optional<::mlir::tfg::RegionAttr> StatelessWhileRegionOpAdaptor::body_region_attrs() { |
13546 | auto attr = body_region_attrsAttr(); |
13547 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
13548 | } |
13549 | |
13550 | ::mlir::RegionRange StatelessWhileRegionOpAdaptor::getRegions() { |
13551 | return odsRegions; |
13552 | } |
13553 | |
13554 | ::mlir::Region &StatelessWhileRegionOpAdaptor::getCondRegion() { |
13555 | return *odsRegions[0]; |
13556 | } |
13557 | |
13558 | ::mlir::Region &StatelessWhileRegionOpAdaptor::cond_region() { |
13559 | return *odsRegions[0]; |
13560 | } |
13561 | |
13562 | ::mlir::Region &StatelessWhileRegionOpAdaptor::getBodyRegion() { |
13563 | return *odsRegions[1]; |
13564 | } |
13565 | |
13566 | ::mlir::Region &StatelessWhileRegionOpAdaptor::body_region() { |
13567 | return *odsRegions[1]; |
13568 | } |
13569 | |
13570 | ::mlir::LogicalResult StatelessWhileRegionOpAdaptor::verify(::mlir::Location loc) { |
13571 | auto namedAttrRange = odsAttrs; |
13572 | auto namedAttrIt = namedAttrRange.begin(); |
13573 | ::mlir::Attribute tblgen_operand_segment_sizes; |
13574 | ::mlir::Attribute tblgen_body_attrs; |
13575 | ::mlir::Attribute tblgen_body_region_attrs; |
13576 | ::mlir::Attribute tblgen_cond_attrs; |
13577 | ::mlir::Attribute tblgen_cond_region_attrs; |
13578 | while (true) { |
13579 | if (namedAttrIt == namedAttrRange.end()) |
13580 | return emitError(loc, "'tfg.StatelessWhileRegion' op " "requires attribute 'operand_segment_sizes'" ); |
13581 | if (namedAttrIt->getName() == StatelessWhileRegionOp::getOperandSegmentSizesAttrName(*odsOpName)) { |
13582 | tblgen_operand_segment_sizes = namedAttrIt->getValue(); |
13583 | break; |
13584 | } |
13585 | else if (namedAttrIt->getName() == StatelessWhileRegionOp::getBodyAttrsAttrName(*odsOpName)) { |
13586 | tblgen_body_attrs = namedAttrIt->getValue(); |
13587 | } |
13588 | else if (namedAttrIt->getName() == StatelessWhileRegionOp::getBodyRegionAttrsAttrName(*odsOpName)) { |
13589 | tblgen_body_region_attrs = namedAttrIt->getValue(); |
13590 | } |
13591 | else if (namedAttrIt->getName() == StatelessWhileRegionOp::getCondAttrsAttrName(*odsOpName)) { |
13592 | tblgen_cond_attrs = namedAttrIt->getValue(); |
13593 | } |
13594 | else if (namedAttrIt->getName() == StatelessWhileRegionOp::getCondRegionAttrsAttrName(*odsOpName)) { |
13595 | tblgen_cond_region_attrs = namedAttrIt->getValue(); |
13596 | } |
13597 | ++namedAttrIt; |
13598 | } |
13599 | ::mlir::Attribute tblgen_parallel_iterations; |
13600 | while (true) { |
13601 | if (namedAttrIt == namedAttrRange.end()) |
13602 | return emitError(loc, "'tfg.StatelessWhileRegion' op " "requires attribute 'parallel_iterations'" ); |
13603 | if (namedAttrIt->getName() == StatelessWhileRegionOp::getParallelIterationsAttrName(*odsOpName)) { |
13604 | tblgen_parallel_iterations = namedAttrIt->getValue(); |
13605 | break; |
13606 | } |
13607 | ++namedAttrIt; |
13608 | } |
13609 | |
13610 | { |
13611 | auto sizeAttr = tblgen_operand_segment_sizes.cast<::mlir::DenseI32ArrayAttr>(); |
13612 | auto numElements = sizeAttr.asArrayRef().size(); |
13613 | if (numElements != 2) |
13614 | return emitError(loc, "'tfg.StatelessWhileRegion' op " "'operand_segment_sizes' attribute for specifying operand segments must have 2 " |
13615 | "elements, but got " ) << numElements; |
13616 | } |
13617 | |
13618 | if (tblgen_parallel_iterations && !(((tblgen_parallel_iterations.isa<::mlir::IntegerAttr>())) && ((tblgen_parallel_iterations.cast<::mlir::IntegerAttr>().getType().isSignlessInteger(64))))) |
13619 | return emitError(loc, "'tfg.StatelessWhileRegion' op " "attribute 'parallel_iterations' failed to satisfy constraint: 64-bit signless integer attribute" ); |
13620 | |
13621 | if (tblgen_cond_attrs && !((tblgen_cond_attrs.isa<::mlir::DictionaryAttr>()))) |
13622 | return emitError(loc, "'tfg.StatelessWhileRegion' op " "attribute 'cond_attrs' failed to satisfy constraint: dictionary of named attribute values" ); |
13623 | |
13624 | if (tblgen_body_attrs && !((tblgen_body_attrs.isa<::mlir::DictionaryAttr>()))) |
13625 | return emitError(loc, "'tfg.StatelessWhileRegion' op " "attribute 'body_attrs' failed to satisfy constraint: dictionary of named attribute values" ); |
13626 | |
13627 | if (tblgen_cond_region_attrs && !((tblgen_cond_region_attrs.isa<::mlir::tfg::RegionAttr>()))) |
13628 | return emitError(loc, "'tfg.StatelessWhileRegion' op " "attribute 'cond_region_attrs' failed to satisfy constraint: Region attributes, argument and result attributes." ); |
13629 | |
13630 | if (tblgen_body_region_attrs && !((tblgen_body_region_attrs.isa<::mlir::tfg::RegionAttr>()))) |
13631 | return emitError(loc, "'tfg.StatelessWhileRegion' op " "attribute 'body_region_attrs' failed to satisfy constraint: Region attributes, argument and result attributes." ); |
13632 | return ::mlir::success(); |
13633 | } |
13634 | |
13635 | std::pair<unsigned, unsigned> StatelessWhileRegionOp::getODSOperandIndexAndLength(unsigned index) { |
13636 | auto sizeAttr = ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getOperandSegmentSizesAttrName()).cast<::mlir::DenseI32ArrayAttr>(); |
13637 | |
13638 | unsigned start = 0; |
13639 | for (unsigned i = 0; i < index; ++i) |
13640 | start += sizeAttr[i]; |
13641 | return {start, sizeAttr[index]}; |
13642 | } |
13643 | |
13644 | ::mlir::Operation::operand_range StatelessWhileRegionOp::getODSOperands(unsigned index) { |
13645 | auto valueRange = getODSOperandIndexAndLength(index); |
13646 | return {std::next(getOperation()->operand_begin(), valueRange.first), |
13647 | std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; |
13648 | } |
13649 | |
13650 | ::mlir::Operation::operand_range StatelessWhileRegionOp::getInit() { |
13651 | return getODSOperands(0); |
13652 | } |
13653 | |
13654 | ::mlir::Operation::operand_range StatelessWhileRegionOp::init() { |
13655 | return getODSOperands(0); |
13656 | } |
13657 | |
13658 | ::mlir::Operation::operand_range StatelessWhileRegionOp::getCtls() { |
13659 | return getODSOperands(1); |
13660 | } |
13661 | |
13662 | ::mlir::Operation::operand_range StatelessWhileRegionOp::ctls() { |
13663 | return getODSOperands(1); |
13664 | } |
13665 | |
13666 | ::mlir::MutableOperandRange StatelessWhileRegionOp::getInitMutable() { |
13667 | auto range = getODSOperandIndexAndLength(0); |
13668 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(0u, *::mlir::impl::getNamedAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getOperandSegmentSizesAttrName()))); |
13669 | return mutableRange; |
13670 | } |
13671 | |
13672 | ::mlir::MutableOperandRange StatelessWhileRegionOp::initMutable() { |
13673 | auto range = getODSOperandIndexAndLength(0); |
13674 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(0u, *::mlir::impl::getNamedAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getOperandSegmentSizesAttrName()))); |
13675 | return mutableRange; |
13676 | } |
13677 | |
13678 | ::mlir::MutableOperandRange StatelessWhileRegionOp::getCtlsMutable() { |
13679 | auto range = getODSOperandIndexAndLength(1); |
13680 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(1u, *::mlir::impl::getNamedAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getOperandSegmentSizesAttrName()))); |
13681 | return mutableRange; |
13682 | } |
13683 | |
13684 | ::mlir::MutableOperandRange StatelessWhileRegionOp::ctlsMutable() { |
13685 | auto range = getODSOperandIndexAndLength(1); |
13686 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(1u, *::mlir::impl::getNamedAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getOperandSegmentSizesAttrName()))); |
13687 | return mutableRange; |
13688 | } |
13689 | |
13690 | std::pair<unsigned, unsigned> StatelessWhileRegionOp::getODSResultIndexAndLength(unsigned index) { |
13691 | bool isVariadic[] = {true, false}; |
13692 | int prevVariadicCount = 0; |
13693 | for (unsigned i = 0; i < index; ++i) |
13694 | if (isVariadic[i]) ++prevVariadicCount; |
13695 | |
13696 | // Calculate how many dynamic values a static variadic operand corresponds to. |
13697 | // This assumes all static variadic operands have the same dynamic value count. |
13698 | int variadicSize = (getOperation()->getNumResults() - 1) / 1; |
13699 | // `index` passed in as the parameter is the static index which counts each |
13700 | // operand (variadic or not) as size 1. So here for each previous static variadic |
13701 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
13702 | // value pack for this static operand starts. |
13703 | int start = index + (variadicSize - 1) * prevVariadicCount; |
13704 | int size = isVariadic[index] ? variadicSize : 1; |
13705 | return {start, size}; |
13706 | } |
13707 | |
13708 | ::mlir::Operation::result_range StatelessWhileRegionOp::getODSResults(unsigned index) { |
13709 | auto valueRange = getODSResultIndexAndLength(index); |
13710 | return {std::next(getOperation()->result_begin(), valueRange.first), |
13711 | std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; |
13712 | } |
13713 | |
13714 | ::mlir::Operation::result_range StatelessWhileRegionOp::getOuts() { |
13715 | return getODSResults(0); |
13716 | } |
13717 | |
13718 | ::mlir::Operation::result_range StatelessWhileRegionOp::outs() { |
13719 | return getODSResults(0); |
13720 | } |
13721 | |
13722 | ::mlir::TypedValue<::mlir::tf_type::ControlType> StatelessWhileRegionOp::getCtl() { |
13723 | return *getODSResults(1).begin(); |
13724 | } |
13725 | |
13726 | ::mlir::TypedValue<::mlir::tf_type::ControlType> StatelessWhileRegionOp::ctl() { |
13727 | return *getODSResults(1).begin(); |
13728 | } |
13729 | |
13730 | ::mlir::Region &StatelessWhileRegionOp::getCondRegion() { |
13731 | return (*this)->getRegion(0); |
13732 | } |
13733 | |
13734 | ::mlir::Region &StatelessWhileRegionOp::cond_region() { |
13735 | return (*this)->getRegion(0); |
13736 | } |
13737 | |
13738 | ::mlir::Region &StatelessWhileRegionOp::getBodyRegion() { |
13739 | return (*this)->getRegion(1); |
13740 | } |
13741 | |
13742 | ::mlir::Region &StatelessWhileRegionOp::body_region() { |
13743 | return (*this)->getRegion(1); |
13744 | } |
13745 | |
13746 | ::mlir::IntegerAttr StatelessWhileRegionOp::getParallelIterationsAttr() { |
13747 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getParallelIterationsAttrName()).cast<::mlir::IntegerAttr>(); |
13748 | } |
13749 | |
13750 | uint64_t StatelessWhileRegionOp::getParallelIterations() { |
13751 | auto attr = getParallelIterationsAttr(); |
13752 | return attr.getValue().getZExtValue(); |
13753 | } |
13754 | |
13755 | ::mlir::IntegerAttr StatelessWhileRegionOp::parallel_iterationsAttr() { |
13756 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getParallelIterationsAttrName()).cast<::mlir::IntegerAttr>(); |
13757 | } |
13758 | |
13759 | uint64_t StatelessWhileRegionOp::parallel_iterations() { |
13760 | auto attr = parallel_iterationsAttr(); |
13761 | return attr.getValue().getZExtValue(); |
13762 | } |
13763 | |
13764 | ::mlir::DictionaryAttr StatelessWhileRegionOp::getCondAttrsAttr() { |
13765 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getCondAttrsAttrName()).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
13766 | } |
13767 | |
13768 | ::llvm::Optional< ::mlir::DictionaryAttr > StatelessWhileRegionOp::getCondAttrs() { |
13769 | auto attr = getCondAttrsAttr(); |
13770 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
13771 | } |
13772 | |
13773 | ::mlir::DictionaryAttr StatelessWhileRegionOp::cond_attrsAttr() { |
13774 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getCondAttrsAttrName()).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
13775 | } |
13776 | |
13777 | ::llvm::Optional< ::mlir::DictionaryAttr > StatelessWhileRegionOp::cond_attrs() { |
13778 | auto attr = cond_attrsAttr(); |
13779 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
13780 | } |
13781 | |
13782 | ::mlir::DictionaryAttr StatelessWhileRegionOp::getBodyAttrsAttr() { |
13783 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getBodyAttrsAttrName()).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
13784 | } |
13785 | |
13786 | ::llvm::Optional< ::mlir::DictionaryAttr > StatelessWhileRegionOp::getBodyAttrs() { |
13787 | auto attr = getBodyAttrsAttr(); |
13788 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
13789 | } |
13790 | |
13791 | ::mlir::DictionaryAttr StatelessWhileRegionOp::body_attrsAttr() { |
13792 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getBodyAttrsAttrName()).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
13793 | } |
13794 | |
13795 | ::llvm::Optional< ::mlir::DictionaryAttr > StatelessWhileRegionOp::body_attrs() { |
13796 | auto attr = body_attrsAttr(); |
13797 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
13798 | } |
13799 | |
13800 | ::mlir::tfg::RegionAttr StatelessWhileRegionOp::getCondRegionAttrsAttr() { |
13801 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getCondRegionAttrsAttrName()).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
13802 | } |
13803 | |
13804 | ::llvm::Optional<::mlir::tfg::RegionAttr> StatelessWhileRegionOp::getCondRegionAttrs() { |
13805 | auto attr = getCondRegionAttrsAttr(); |
13806 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
13807 | } |
13808 | |
13809 | ::mlir::tfg::RegionAttr StatelessWhileRegionOp::cond_region_attrsAttr() { |
13810 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getCondRegionAttrsAttrName()).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
13811 | } |
13812 | |
13813 | ::llvm::Optional<::mlir::tfg::RegionAttr> StatelessWhileRegionOp::cond_region_attrs() { |
13814 | auto attr = cond_region_attrsAttr(); |
13815 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
13816 | } |
13817 | |
13818 | ::mlir::tfg::RegionAttr StatelessWhileRegionOp::getBodyRegionAttrsAttr() { |
13819 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getBodyRegionAttrsAttrName()).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
13820 | } |
13821 | |
13822 | ::llvm::Optional<::mlir::tfg::RegionAttr> StatelessWhileRegionOp::getBodyRegionAttrs() { |
13823 | auto attr = getBodyRegionAttrsAttr(); |
13824 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
13825 | } |
13826 | |
13827 | ::mlir::tfg::RegionAttr StatelessWhileRegionOp::body_region_attrsAttr() { |
13828 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getBodyRegionAttrsAttrName()).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
13829 | } |
13830 | |
13831 | ::llvm::Optional<::mlir::tfg::RegionAttr> StatelessWhileRegionOp::body_region_attrs() { |
13832 | auto attr = body_region_attrsAttr(); |
13833 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
13834 | } |
13835 | |
13836 | void StatelessWhileRegionOp::setParallelIterationsAttr(::mlir::IntegerAttr attr) { |
13837 | (*this)->setAttr(getParallelIterationsAttrName(), attr); |
13838 | } |
13839 | |
13840 | void StatelessWhileRegionOp::parallel_iterationsAttr(::mlir::IntegerAttr attr) { |
13841 | (*this)->setAttr(parallel_iterationsAttrName(), attr); |
13842 | } |
13843 | |
13844 | void StatelessWhileRegionOp::setCondAttrsAttr(::mlir::DictionaryAttr attr) { |
13845 | (*this)->setAttr(getCondAttrsAttrName(), attr); |
13846 | } |
13847 | |
13848 | void StatelessWhileRegionOp::cond_attrsAttr(::mlir::DictionaryAttr attr) { |
13849 | (*this)->setAttr(cond_attrsAttrName(), attr); |
13850 | } |
13851 | |
13852 | void StatelessWhileRegionOp::setBodyAttrsAttr(::mlir::DictionaryAttr attr) { |
13853 | (*this)->setAttr(getBodyAttrsAttrName(), attr); |
13854 | } |
13855 | |
13856 | void StatelessWhileRegionOp::body_attrsAttr(::mlir::DictionaryAttr attr) { |
13857 | (*this)->setAttr(body_attrsAttrName(), attr); |
13858 | } |
13859 | |
13860 | void StatelessWhileRegionOp::setCondRegionAttrsAttr(::mlir::tfg::RegionAttr attr) { |
13861 | (*this)->setAttr(getCondRegionAttrsAttrName(), attr); |
13862 | } |
13863 | |
13864 | void StatelessWhileRegionOp::cond_region_attrsAttr(::mlir::tfg::RegionAttr attr) { |
13865 | (*this)->setAttr(cond_region_attrsAttrName(), attr); |
13866 | } |
13867 | |
13868 | void StatelessWhileRegionOp::setBodyRegionAttrsAttr(::mlir::tfg::RegionAttr attr) { |
13869 | (*this)->setAttr(getBodyRegionAttrsAttrName(), attr); |
13870 | } |
13871 | |
13872 | void StatelessWhileRegionOp::body_region_attrsAttr(::mlir::tfg::RegionAttr attr) { |
13873 | (*this)->setAttr(body_region_attrsAttrName(), attr); |
13874 | } |
13875 | |
13876 | ::mlir::Attribute StatelessWhileRegionOp::removeCond_attrsAttr() { |
13877 | return (*this)->removeAttr(getCondAttrsAttrName()); |
13878 | } |
13879 | |
13880 | ::mlir::Attribute StatelessWhileRegionOp::removeBody_attrsAttr() { |
13881 | return (*this)->removeAttr(getBodyAttrsAttrName()); |
13882 | } |
13883 | |
13884 | ::mlir::Attribute StatelessWhileRegionOp::removeCond_region_attrsAttr() { |
13885 | return (*this)->removeAttr(getCondRegionAttrsAttrName()); |
13886 | } |
13887 | |
13888 | ::mlir::Attribute StatelessWhileRegionOp::removeBody_region_attrsAttr() { |
13889 | return (*this)->removeAttr(getBodyRegionAttrsAttrName()); |
13890 | } |
13891 | |
13892 | void StatelessWhileRegionOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange outs, ::mlir::Type ctl, ::mlir::ValueRange init, ::mlir::ValueRange ctls, ::mlir::IntegerAttr parallel_iterations, /*optional*/::mlir::DictionaryAttr cond_attrs, /*optional*/::mlir::DictionaryAttr body_attrs, /*optional*/::mlir::tfg::RegionAttr cond_region_attrs, /*optional*/::mlir::tfg::RegionAttr body_region_attrs) { |
13893 | odsState.addOperands(init); |
13894 | odsState.addOperands(ctls); |
13895 | odsState.addAttribute(getOperandSegmentSizesAttrName(odsState.name), odsBuilder.getDenseI32ArrayAttr({static_cast<int32_t>(init.size()), static_cast<int32_t>(ctls.size())})); |
13896 | odsState.addAttribute(getParallelIterationsAttrName(odsState.name), parallel_iterations); |
13897 | if (cond_attrs) { |
13898 | odsState.addAttribute(getCondAttrsAttrName(odsState.name), cond_attrs); |
13899 | } |
13900 | if (body_attrs) { |
13901 | odsState.addAttribute(getBodyAttrsAttrName(odsState.name), body_attrs); |
13902 | } |
13903 | if (cond_region_attrs) { |
13904 | odsState.addAttribute(getCondRegionAttrsAttrName(odsState.name), cond_region_attrs); |
13905 | } |
13906 | if (body_region_attrs) { |
13907 | odsState.addAttribute(getBodyRegionAttrsAttrName(odsState.name), body_region_attrs); |
13908 | } |
13909 | (void)odsState.addRegion(); |
13910 | (void)odsState.addRegion(); |
13911 | odsState.addTypes(outs); |
13912 | odsState.addTypes(ctl); |
13913 | } |
13914 | |
13915 | void StatelessWhileRegionOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange init, ::mlir::ValueRange ctls, ::mlir::IntegerAttr parallel_iterations, /*optional*/::mlir::DictionaryAttr cond_attrs, /*optional*/::mlir::DictionaryAttr body_attrs, /*optional*/::mlir::tfg::RegionAttr cond_region_attrs, /*optional*/::mlir::tfg::RegionAttr body_region_attrs) { |
13916 | odsState.addOperands(init); |
13917 | odsState.addOperands(ctls); |
13918 | odsState.addAttribute(getOperandSegmentSizesAttrName(odsState.name), odsBuilder.getDenseI32ArrayAttr({static_cast<int32_t>(init.size()), static_cast<int32_t>(ctls.size())})); |
13919 | odsState.addAttribute(getParallelIterationsAttrName(odsState.name), parallel_iterations); |
13920 | if (cond_attrs) { |
13921 | odsState.addAttribute(getCondAttrsAttrName(odsState.name), cond_attrs); |
13922 | } |
13923 | if (body_attrs) { |
13924 | odsState.addAttribute(getBodyAttrsAttrName(odsState.name), body_attrs); |
13925 | } |
13926 | if (cond_region_attrs) { |
13927 | odsState.addAttribute(getCondRegionAttrsAttrName(odsState.name), cond_region_attrs); |
13928 | } |
13929 | if (body_region_attrs) { |
13930 | odsState.addAttribute(getBodyRegionAttrsAttrName(odsState.name), body_region_attrs); |
13931 | } |
13932 | (void)odsState.addRegion(); |
13933 | (void)odsState.addRegion(); |
13934 | assert(resultTypes.size() >= 1u && "mismatched number of results" ); |
13935 | odsState.addTypes(resultTypes); |
13936 | } |
13937 | |
13938 | void StatelessWhileRegionOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange outs, ::mlir::Type ctl, ::mlir::ValueRange init, ::mlir::ValueRange ctls, uint64_t parallel_iterations, /*optional*/::mlir::DictionaryAttr cond_attrs, /*optional*/::mlir::DictionaryAttr body_attrs, /*optional*/::mlir::tfg::RegionAttr cond_region_attrs, /*optional*/::mlir::tfg::RegionAttr body_region_attrs) { |
13939 | odsState.addOperands(init); |
13940 | odsState.addOperands(ctls); |
13941 | odsState.addAttribute(getOperandSegmentSizesAttrName(odsState.name), odsBuilder.getDenseI32ArrayAttr({static_cast<int32_t>(init.size()), static_cast<int32_t>(ctls.size())})); |
13942 | odsState.addAttribute(getParallelIterationsAttrName(odsState.name), odsBuilder.getIntegerAttr(odsBuilder.getIntegerType(64), parallel_iterations)); |
13943 | if (cond_attrs) { |
13944 | odsState.addAttribute(getCondAttrsAttrName(odsState.name), cond_attrs); |
13945 | } |
13946 | if (body_attrs) { |
13947 | odsState.addAttribute(getBodyAttrsAttrName(odsState.name), body_attrs); |
13948 | } |
13949 | if (cond_region_attrs) { |
13950 | odsState.addAttribute(getCondRegionAttrsAttrName(odsState.name), cond_region_attrs); |
13951 | } |
13952 | if (body_region_attrs) { |
13953 | odsState.addAttribute(getBodyRegionAttrsAttrName(odsState.name), body_region_attrs); |
13954 | } |
13955 | (void)odsState.addRegion(); |
13956 | (void)odsState.addRegion(); |
13957 | odsState.addTypes(outs); |
13958 | odsState.addTypes(ctl); |
13959 | } |
13960 | |
13961 | void StatelessWhileRegionOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange init, ::mlir::ValueRange ctls, uint64_t parallel_iterations, /*optional*/::mlir::DictionaryAttr cond_attrs, /*optional*/::mlir::DictionaryAttr body_attrs, /*optional*/::mlir::tfg::RegionAttr cond_region_attrs, /*optional*/::mlir::tfg::RegionAttr body_region_attrs) { |
13962 | odsState.addOperands(init); |
13963 | odsState.addOperands(ctls); |
13964 | odsState.addAttribute(getOperandSegmentSizesAttrName(odsState.name), odsBuilder.getDenseI32ArrayAttr({static_cast<int32_t>(init.size()), static_cast<int32_t>(ctls.size())})); |
13965 | odsState.addAttribute(getParallelIterationsAttrName(odsState.name), odsBuilder.getIntegerAttr(odsBuilder.getIntegerType(64), parallel_iterations)); |
13966 | if (cond_attrs) { |
13967 | odsState.addAttribute(getCondAttrsAttrName(odsState.name), cond_attrs); |
13968 | } |
13969 | if (body_attrs) { |
13970 | odsState.addAttribute(getBodyAttrsAttrName(odsState.name), body_attrs); |
13971 | } |
13972 | if (cond_region_attrs) { |
13973 | odsState.addAttribute(getCondRegionAttrsAttrName(odsState.name), cond_region_attrs); |
13974 | } |
13975 | if (body_region_attrs) { |
13976 | odsState.addAttribute(getBodyRegionAttrsAttrName(odsState.name), body_region_attrs); |
13977 | } |
13978 | (void)odsState.addRegion(); |
13979 | (void)odsState.addRegion(); |
13980 | assert(resultTypes.size() >= 1u && "mismatched number of results" ); |
13981 | odsState.addTypes(resultTypes); |
13982 | } |
13983 | |
13984 | void StatelessWhileRegionOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { |
13985 | odsState.addOperands(operands); |
13986 | odsState.addAttributes(attributes); |
13987 | for (unsigned i = 0; i != 2; ++i) |
13988 | (void)odsState.addRegion(); |
13989 | assert(resultTypes.size() >= 1u && "mismatched number of return types" ); |
13990 | odsState.addTypes(resultTypes); |
13991 | } |
13992 | |
13993 | ::mlir::LogicalResult StatelessWhileRegionOp::verifyInvariantsImpl() { |
13994 | auto namedAttrRange = (*this)->getAttrs(); |
13995 | auto namedAttrIt = namedAttrRange.begin(); |
13996 | ::mlir::Attribute tblgen_operand_segment_sizes; |
13997 | ::mlir::Attribute tblgen_body_attrs; |
13998 | ::mlir::Attribute tblgen_body_region_attrs; |
13999 | ::mlir::Attribute tblgen_cond_attrs; |
14000 | ::mlir::Attribute tblgen_cond_region_attrs; |
14001 | while (true) { |
14002 | if (namedAttrIt == namedAttrRange.end()) |
14003 | return emitOpError("requires attribute 'operand_segment_sizes'" ); |
14004 | if (namedAttrIt->getName() == getOperandSegmentSizesAttrName()) { |
14005 | tblgen_operand_segment_sizes = namedAttrIt->getValue(); |
14006 | break; |
14007 | } |
14008 | else if (namedAttrIt->getName() == getBodyAttrsAttrName()) { |
14009 | tblgen_body_attrs = namedAttrIt->getValue(); |
14010 | } |
14011 | else if (namedAttrIt->getName() == getBodyRegionAttrsAttrName()) { |
14012 | tblgen_body_region_attrs = namedAttrIt->getValue(); |
14013 | } |
14014 | else if (namedAttrIt->getName() == getCondAttrsAttrName()) { |
14015 | tblgen_cond_attrs = namedAttrIt->getValue(); |
14016 | } |
14017 | else if (namedAttrIt->getName() == getCondRegionAttrsAttrName()) { |
14018 | tblgen_cond_region_attrs = namedAttrIt->getValue(); |
14019 | } |
14020 | ++namedAttrIt; |
14021 | } |
14022 | ::mlir::Attribute tblgen_parallel_iterations; |
14023 | while (true) { |
14024 | if (namedAttrIt == namedAttrRange.end()) |
14025 | return emitOpError("requires attribute 'parallel_iterations'" ); |
14026 | if (namedAttrIt->getName() == getParallelIterationsAttrName()) { |
14027 | tblgen_parallel_iterations = namedAttrIt->getValue(); |
14028 | break; |
14029 | } |
14030 | ++namedAttrIt; |
14031 | } |
14032 | |
14033 | { |
14034 | auto sizeAttr = tblgen_operand_segment_sizes.cast<::mlir::DenseI32ArrayAttr>(); |
14035 | auto numElements = sizeAttr.asArrayRef().size(); |
14036 | if (numElements != 2) |
14037 | return emitOpError("'operand_segment_sizes' attribute for specifying operand segments must have 2 " |
14038 | "elements, but got " ) << numElements; |
14039 | } |
14040 | |
14041 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops18(*this, tblgen_parallel_iterations, "parallel_iterations" ))) |
14042 | return ::mlir::failure(); |
14043 | |
14044 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops6(*this, tblgen_cond_attrs, "cond_attrs" ))) |
14045 | return ::mlir::failure(); |
14046 | |
14047 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops6(*this, tblgen_body_attrs, "body_attrs" ))) |
14048 | return ::mlir::failure(); |
14049 | |
14050 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops7(*this, tblgen_cond_region_attrs, "cond_region_attrs" ))) |
14051 | return ::mlir::failure(); |
14052 | |
14053 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops7(*this, tblgen_body_region_attrs, "body_region_attrs" ))) |
14054 | return ::mlir::failure(); |
14055 | { |
14056 | unsigned index = 0; (void)index; |
14057 | auto valueGroup0 = getODSOperands(0); |
14058 | |
14059 | for (auto v : valueGroup0) { |
14060 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops2(*this, v.getType(), "operand" , index++))) |
14061 | return ::mlir::failure(); |
14062 | } |
14063 | auto valueGroup1 = getODSOperands(1); |
14064 | |
14065 | for (auto v : valueGroup1) { |
14066 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops3(*this, v.getType(), "operand" , index++))) |
14067 | return ::mlir::failure(); |
14068 | } |
14069 | } |
14070 | { |
14071 | unsigned index = 0; (void)index; |
14072 | auto valueGroup0 = getODSResults(0); |
14073 | |
14074 | for (auto v : valueGroup0) { |
14075 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops2(*this, v.getType(), "result" , index++))) |
14076 | return ::mlir::failure(); |
14077 | } |
14078 | auto valueGroup1 = getODSResults(1); |
14079 | |
14080 | for (auto v : valueGroup1) { |
14081 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops3(*this, v.getType(), "result" , index++))) |
14082 | return ::mlir::failure(); |
14083 | } |
14084 | } |
14085 | { |
14086 | unsigned index = 0; (void)index; |
14087 | |
14088 | for (auto ®ion : ::llvm::makeMutableArrayRef((*this)->getRegion(0))) |
14089 | if (::mlir::failed(__mlir_ods_local_region_constraint_ops0(*this, region, "cond_region" , index++))) |
14090 | return ::mlir::failure(); |
14091 | |
14092 | for (auto ®ion : ::llvm::makeMutableArrayRef((*this)->getRegion(1))) |
14093 | if (::mlir::failed(__mlir_ods_local_region_constraint_ops0(*this, region, "body_region" , index++))) |
14094 | return ::mlir::failure(); |
14095 | } |
14096 | return ::mlir::success(); |
14097 | } |
14098 | |
14099 | ::mlir::LogicalResult StatelessWhileRegionOp::verifyInvariants() { |
14100 | if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) |
14101 | return ::mlir::success(); |
14102 | return ::mlir::failure(); |
14103 | } |
14104 | |
14105 | ::mlir::ParseResult StatelessWhileRegionOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { |
14106 | ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> initOperands; |
14107 | ::llvm::SMLoc initOperandsLoc; |
14108 | (void)initOperandsLoc; |
14109 | ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> ctlsOperands; |
14110 | ::llvm::SMLoc ctlsOperandsLoc; |
14111 | (void)ctlsOperandsLoc; |
14112 | std::unique_ptr<::mlir::Region> cond_regionRegion = std::make_unique<::mlir::Region>(); |
14113 | std::unique_ptr<::mlir::Region> body_regionRegion = std::make_unique<::mlir::Region>(); |
14114 | ::llvm::ArrayRef<::mlir::Type> initTypes; |
14115 | ::llvm::ArrayRef<::mlir::Type> outsTypes; |
14116 | if (::mlir::succeeded(parser.parseOptionalLParen())) { |
14117 | |
14118 | initOperandsLoc = parser.getCurrentLocation(); |
14119 | if (parser.parseOperandList(initOperands)) |
14120 | return ::mlir::failure(); |
14121 | if (parser.parseRParen()) |
14122 | return ::mlir::failure(); |
14123 | } |
14124 | if (::mlir::succeeded(parser.parseOptionalLSquare())) { |
14125 | |
14126 | ctlsOperandsLoc = parser.getCurrentLocation(); |
14127 | if (parser.parseOperandList(ctlsOperands)) |
14128 | return ::mlir::failure(); |
14129 | if (parser.parseRSquare()) |
14130 | return ::mlir::failure(); |
14131 | } |
14132 | |
14133 | if (parser.parseRegion(*cond_regionRegion)) |
14134 | return ::mlir::failure(); |
14135 | |
14136 | if (cond_regionRegion->empty()) cond_regionRegion->emplaceBlock(); |
14137 | if (parser.parseKeyword("do" )) |
14138 | return ::mlir::failure(); |
14139 | |
14140 | if (parser.parseRegion(*body_regionRegion)) |
14141 | return ::mlir::failure(); |
14142 | |
14143 | if (body_regionRegion->empty()) body_regionRegion->emplaceBlock(); |
14144 | if (parser.parseOptionalAttrDict(result.attributes)) |
14145 | return ::mlir::failure(); |
14146 | if (::mlir::succeeded(parser.parseOptionalColon())) { |
14147 | |
14148 | ::mlir::FunctionType init__outs_functionType; |
14149 | if (parser.parseType(init__outs_functionType)) |
14150 | return ::mlir::failure(); |
14151 | initTypes = init__outs_functionType.getInputs(); |
14152 | outsTypes = init__outs_functionType.getResults(); |
14153 | } |
14154 | result.addRegion(std::move(cond_regionRegion)); |
14155 | result.addRegion(std::move(body_regionRegion)); |
14156 | result.addAttribute("operand_segment_sizes" , parser.getBuilder().getDenseI32ArrayAttr({static_cast<int32_t>(initOperands.size()), static_cast<int32_t>(ctlsOperands.size())})); |
14157 | ::mlir::Type odsBuildableType0 = parser.getBuilder().getType<::mlir::tf_type::ControlType>(); |
14158 | result.addTypes(outsTypes); |
14159 | result.addTypes(odsBuildableType0); |
14160 | if (parser.resolveOperands(initOperands, initTypes, initOperandsLoc, result.operands)) |
14161 | return ::mlir::failure(); |
14162 | if (parser.resolveOperands(ctlsOperands, odsBuildableType0, ctlsOperandsLoc, result.operands)) |
14163 | return ::mlir::failure(); |
14164 | return ::mlir::success(); |
14165 | } |
14166 | |
14167 | void StatelessWhileRegionOp::print(::mlir::OpAsmPrinter &_odsPrinter) { |
14168 | if (!getInit().empty()) { |
14169 | _odsPrinter << "(" ; |
14170 | _odsPrinter << getInit(); |
14171 | _odsPrinter << ")" ; |
14172 | } |
14173 | if (!getCtls().empty()) { |
14174 | _odsPrinter << ' ' << "[" ; |
14175 | _odsPrinter << getCtls(); |
14176 | _odsPrinter << "]" ; |
14177 | } |
14178 | _odsPrinter << ' '; |
14179 | _odsPrinter.printRegion(getCondRegion()); |
14180 | _odsPrinter << ' ' << "do" ; |
14181 | _odsPrinter << ' '; |
14182 | _odsPrinter.printRegion(getBodyRegion()); |
14183 | _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), /*elidedAttrs=*/{"operand_segment_sizes" , }); |
14184 | if (!getInit().empty()) { |
14185 | _odsPrinter << ' ' << ":" ; |
14186 | _odsPrinter << ' '; |
14187 | _odsPrinter.printFunctionalType(getInit().getTypes(), getOuts().getTypes()); |
14188 | } |
14189 | } |
14190 | |
14191 | StringRef StatelessWhileRegionOp::getDefaultDialect() { return "tfg" ; } |
14192 | void StatelessWhileRegionOp::getAsmResultNames(OpAsmSetValueNameFn setNameFn) { |
14193 | GenericGetAsmResultNames(*this, setNameFn); |
14194 | } |
14195 | |
14196 | ConditionOp StatelessWhileRegionOp::cond_condition() { |
14197 | return cast<ConditionOp>(cond_block().getTerminator()); |
14198 | } |
14199 | YieldOp StatelessWhileRegionOp::body_yield() { |
14200 | return cast<YieldOp>(body_block().getTerminator()); |
14201 | } |
14202 | |
14203 | OperandRange StatelessWhileRegionOp::getSuccessorEntryOperands( |
14204 | Optional<unsigned> index) { |
14205 | return init(); |
14206 | } |
14207 | void StatelessWhileRegionOp::getSuccessorRegions( |
14208 | Optional<unsigned> index, ArrayRef<Attribute> operands, |
14209 | SmallVectorImpl<RegionSuccessor> ®ions) { |
14210 | return GetWhileLikeRegionOpSuccessorRegions(*this, index, operands, |
14211 | regions); |
14212 | } |
14213 | |
14214 | LogicalResult StatelessWhileRegionOp::verify() { return VerifyWhileLikeRegionOp(*this); } |
14215 | |
14216 | BlockArgument StatelessWhileRegionOp::getDataValueOf(BlockArgument ctl) { |
14217 | return GetLoopRegionDataOf(ctl); |
14218 | } |
14219 | BlockArgument StatelessWhileRegionOp::getControlTokenOf(BlockArgument data) { |
14220 | return GetLoopRegionControlOf(data); |
14221 | } |
14222 | BlockArgument StatelessWhileRegionOp::getDataValue(Region ®ion, unsigned idx) { |
14223 | return GetLoopRegionDataArgs(region)[idx]; |
14224 | } |
14225 | BlockArgument StatelessWhileRegionOp::getControlToken(Region ®ion, unsigned idx) { |
14226 | return GetLoopRegionControlTokens(region)[idx]; |
14227 | } |
14228 | } // namespace tfg |
14229 | } // namespace mlir |
14230 | MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::tfg::StatelessWhileRegionOp) |
14231 | |
14232 | namespace mlir { |
14233 | namespace tfg { |
14234 | |
14235 | //===----------------------------------------------------------------------===// |
14236 | // ::mlir::tfg::WhileOp definitions |
14237 | //===----------------------------------------------------------------------===// |
14238 | |
14239 | WhileOpAdaptor::WhileOpAdaptor(::mlir::ValueRange values, ::mlir::DictionaryAttr attrs, ::mlir::RegionRange regions) : odsOperands(values), odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) |
14240 | odsOpName.emplace("tfg.While" , odsAttrs.getContext()); |
14241 | } |
14242 | |
14243 | WhileOpAdaptor::WhileOpAdaptor(WhileOp op) : odsOperands(op->getOperands()), odsAttrs(op->getAttrDictionary()), odsRegions(op->getRegions()), odsOpName(op->getName()) {} |
14244 | |
14245 | ::mlir::ValueRange WhileOpAdaptor::getOperands() { |
14246 | return odsOperands; |
14247 | } |
14248 | |
14249 | std::pair<unsigned, unsigned> WhileOpAdaptor::getODSOperandIndexAndLength(unsigned index) { |
14250 | bool isVariadic[] = {true}; |
14251 | int prevVariadicCount = 0; |
14252 | for (unsigned i = 0; i < index; ++i) |
14253 | if (isVariadic[i]) ++prevVariadicCount; |
14254 | |
14255 | // Calculate how many dynamic values a static variadic operand corresponds to. |
14256 | // This assumes all static variadic operands have the same dynamic value count. |
14257 | int variadicSize = (odsOperands.size() - 0) / 1; |
14258 | // `index` passed in as the parameter is the static index which counts each |
14259 | // operand (variadic or not) as size 1. So here for each previous static variadic |
14260 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
14261 | // value pack for this static operand starts. |
14262 | int start = index + (variadicSize - 1) * prevVariadicCount; |
14263 | int size = isVariadic[index] ? variadicSize : 1; |
14264 | return {start, size}; |
14265 | } |
14266 | |
14267 | ::mlir::ValueRange WhileOpAdaptor::getODSOperands(unsigned index) { |
14268 | auto valueRange = getODSOperandIndexAndLength(index); |
14269 | return {std::next(odsOperands.begin(), valueRange.first), |
14270 | std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; |
14271 | } |
14272 | |
14273 | ::mlir::ValueRange WhileOpAdaptor::getArgs() { |
14274 | return getODSOperands(0); |
14275 | } |
14276 | |
14277 | ::mlir::ValueRange WhileOpAdaptor::args() { |
14278 | return getODSOperands(0); |
14279 | } |
14280 | |
14281 | ::mlir::DictionaryAttr WhileOpAdaptor::getAttributes() { |
14282 | return odsAttrs; |
14283 | } |
14284 | |
14285 | ::mlir::tf_type::FuncAttr WhileOpAdaptor::getCondAttr() { |
14286 | assert(odsAttrs && "no attributes when constructing adapter" ); |
14287 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 1, WhileOp::getCondAttrName(*odsOpName)).cast<::mlir::tf_type::FuncAttr>(); |
14288 | return attr; |
14289 | } |
14290 | |
14291 | ::mlir::tf_type::FuncAttr WhileOpAdaptor::getCond() { |
14292 | auto attr = getCondAttr(); |
14293 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
14294 | } |
14295 | |
14296 | ::mlir::tf_type::FuncAttr WhileOpAdaptor::condAttr() { |
14297 | assert(odsAttrs && "no attributes when constructing adapter" ); |
14298 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 1, WhileOp::getCondAttrName(*odsOpName)).cast<::mlir::tf_type::FuncAttr>(); |
14299 | return attr; |
14300 | } |
14301 | |
14302 | ::mlir::tf_type::FuncAttr WhileOpAdaptor::cond() { |
14303 | auto attr = condAttr(); |
14304 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
14305 | } |
14306 | |
14307 | ::mlir::tf_type::FuncAttr WhileOpAdaptor::getBodyAttr() { |
14308 | assert(odsAttrs && "no attributes when constructing adapter" ); |
14309 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, WhileOp::getBodyAttrName(*odsOpName)).cast<::mlir::tf_type::FuncAttr>(); |
14310 | return attr; |
14311 | } |
14312 | |
14313 | ::mlir::tf_type::FuncAttr WhileOpAdaptor::getBody() { |
14314 | auto attr = getBodyAttr(); |
14315 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
14316 | } |
14317 | |
14318 | ::mlir::tf_type::FuncAttr WhileOpAdaptor::bodyAttr() { |
14319 | assert(odsAttrs && "no attributes when constructing adapter" ); |
14320 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, WhileOp::getBodyAttrName(*odsOpName)).cast<::mlir::tf_type::FuncAttr>(); |
14321 | return attr; |
14322 | } |
14323 | |
14324 | ::mlir::tf_type::FuncAttr WhileOpAdaptor::body() { |
14325 | auto attr = bodyAttr(); |
14326 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
14327 | } |
14328 | |
14329 | ::mlir::IntegerAttr WhileOpAdaptor::getParallelIterationsAttr() { |
14330 | assert(odsAttrs && "no attributes when constructing adapter" ); |
14331 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 2, odsAttrs.end() - 0, WhileOp::getParallelIterationsAttrName(*odsOpName)).cast<::mlir::IntegerAttr>(); |
14332 | return attr; |
14333 | } |
14334 | |
14335 | uint64_t WhileOpAdaptor::getParallelIterations() { |
14336 | auto attr = getParallelIterationsAttr(); |
14337 | return attr.getValue().getZExtValue(); |
14338 | } |
14339 | |
14340 | ::mlir::IntegerAttr WhileOpAdaptor::parallel_iterationsAttr() { |
14341 | assert(odsAttrs && "no attributes when constructing adapter" ); |
14342 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 2, odsAttrs.end() - 0, WhileOp::getParallelIterationsAttrName(*odsOpName)).cast<::mlir::IntegerAttr>(); |
14343 | return attr; |
14344 | } |
14345 | |
14346 | uint64_t WhileOpAdaptor::parallel_iterations() { |
14347 | auto attr = parallel_iterationsAttr(); |
14348 | return attr.getValue().getZExtValue(); |
14349 | } |
14350 | |
14351 | ::mlir::ArrayAttr WhileOpAdaptor::getTAttr() { |
14352 | assert(odsAttrs && "no attributes when constructing adapter" ); |
14353 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 3, WhileOp::getTAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
14354 | return attr; |
14355 | } |
14356 | |
14357 | ::llvm::Optional< ::mlir::ArrayAttr > WhileOpAdaptor::getT() { |
14358 | auto attr = getTAttr(); |
14359 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
14360 | } |
14361 | |
14362 | ::mlir::ArrayAttr WhileOpAdaptor::TAttr() { |
14363 | assert(odsAttrs && "no attributes when constructing adapter" ); |
14364 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 3, WhileOp::getTAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
14365 | return attr; |
14366 | } |
14367 | |
14368 | ::llvm::Optional< ::mlir::ArrayAttr > WhileOpAdaptor::T() { |
14369 | auto attr = TAttr(); |
14370 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
14371 | } |
14372 | |
14373 | ::mlir::ArrayAttr WhileOpAdaptor::getOutputShapesAttr() { |
14374 | assert(odsAttrs && "no attributes when constructing adapter" ); |
14375 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 2, odsAttrs.end() - 1, WhileOp::getOutputShapesAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
14376 | return attr; |
14377 | } |
14378 | |
14379 | ::llvm::Optional< ::mlir::ArrayAttr > WhileOpAdaptor::getOutputShapes() { |
14380 | auto attr = getOutputShapesAttr(); |
14381 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
14382 | } |
14383 | |
14384 | ::mlir::ArrayAttr WhileOpAdaptor::output_shapesAttr() { |
14385 | assert(odsAttrs && "no attributes when constructing adapter" ); |
14386 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 2, odsAttrs.end() - 1, WhileOp::getOutputShapesAttrName(*odsOpName)).dyn_cast_or_null<::mlir::ArrayAttr>(); |
14387 | return attr; |
14388 | } |
14389 | |
14390 | ::llvm::Optional< ::mlir::ArrayAttr > WhileOpAdaptor::output_shapes() { |
14391 | auto attr = output_shapesAttr(); |
14392 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
14393 | } |
14394 | |
14395 | ::mlir::LogicalResult WhileOpAdaptor::verify(::mlir::Location loc) { |
14396 | auto namedAttrRange = odsAttrs; |
14397 | auto namedAttrIt = namedAttrRange.begin(); |
14398 | ::mlir::Attribute tblgen_body; |
14399 | ::mlir::Attribute tblgen_T; |
14400 | while (true) { |
14401 | if (namedAttrIt == namedAttrRange.end()) |
14402 | return emitError(loc, "'tfg.While' op " "requires attribute 'body'" ); |
14403 | if (namedAttrIt->getName() == WhileOp::getBodyAttrName(*odsOpName)) { |
14404 | tblgen_body = namedAttrIt->getValue(); |
14405 | break; |
14406 | } |
14407 | else if (namedAttrIt->getName() == WhileOp::getTAttrName(*odsOpName)) { |
14408 | tblgen_T = namedAttrIt->getValue(); |
14409 | } |
14410 | ++namedAttrIt; |
14411 | } |
14412 | ::mlir::Attribute tblgen_cond; |
14413 | while (true) { |
14414 | if (namedAttrIt == namedAttrRange.end()) |
14415 | return emitError(loc, "'tfg.While' op " "requires attribute 'cond'" ); |
14416 | if (namedAttrIt->getName() == WhileOp::getCondAttrName(*odsOpName)) { |
14417 | tblgen_cond = namedAttrIt->getValue(); |
14418 | break; |
14419 | } |
14420 | ++namedAttrIt; |
14421 | } |
14422 | ::mlir::Attribute tblgen_parallel_iterations; |
14423 | ::mlir::Attribute tblgen_output_shapes; |
14424 | while (true) { |
14425 | if (namedAttrIt == namedAttrRange.end()) |
14426 | return emitError(loc, "'tfg.While' op " "requires attribute 'parallel_iterations'" ); |
14427 | if (namedAttrIt->getName() == WhileOp::getParallelIterationsAttrName(*odsOpName)) { |
14428 | tblgen_parallel_iterations = namedAttrIt->getValue(); |
14429 | break; |
14430 | } |
14431 | else if (namedAttrIt->getName() == WhileOp::getOutputShapesAttrName(*odsOpName)) { |
14432 | tblgen_output_shapes = namedAttrIt->getValue(); |
14433 | } |
14434 | ++namedAttrIt; |
14435 | } |
14436 | |
14437 | if (tblgen_cond && !((tblgen_cond.isa<::mlir::tf_type::FuncAttr>()))) |
14438 | return emitError(loc, "'tfg.While' op " "attribute 'cond' failed to satisfy constraint: Models the `AttrValue.value.func` proto attribute value as a pair of SymbolRef and DictionaryAttr" ); |
14439 | |
14440 | if (tblgen_body && !((tblgen_body.isa<::mlir::tf_type::FuncAttr>()))) |
14441 | return emitError(loc, "'tfg.While' op " "attribute 'body' failed to satisfy constraint: Models the `AttrValue.value.func` proto attribute value as a pair of SymbolRef and DictionaryAttr" ); |
14442 | |
14443 | if (tblgen_parallel_iterations && !(((tblgen_parallel_iterations.isa<::mlir::IntegerAttr>())) && ((tblgen_parallel_iterations.cast<::mlir::IntegerAttr>().getType().isSignlessInteger(64))))) |
14444 | return emitError(loc, "'tfg.While' op " "attribute 'parallel_iterations' failed to satisfy constraint: 64-bit signless integer attribute" ); |
14445 | |
14446 | if (tblgen_T && !(((tblgen_T.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_T.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && (((attr.isa<::mlir::TypeAttr>())) && ((attr.cast<::mlir::TypeAttr>().getValue().isa<::mlir::Type>()))); })))) |
14447 | return emitError(loc, "'tfg.While' op " "attribute 'T' failed to satisfy constraint: type array attribute" ); |
14448 | |
14449 | if (tblgen_output_shapes && !(((tblgen_output_shapes.isa<::mlir::ArrayAttr>())) && (::llvm::all_of(tblgen_output_shapes.cast<::mlir::ArrayAttr>(), [&](::mlir::Attribute attr) { return attr && ((attr.isa<::mlir::tf_type::ShapeAttr>())); })))) |
14450 | return emitError(loc, "'tfg.While' op " "attribute 'output_shapes' failed to satisfy constraint: An array of shapes." ); |
14451 | return ::mlir::success(); |
14452 | } |
14453 | |
14454 | void WhileOp::getAsmResultNames(::mlir::OpAsmSetValueNameFn setNameFn) { |
14455 | auto resultGroup0 = getODSResults(0); |
14456 | if (!resultGroup0.empty()) |
14457 | setNameFn(*resultGroup0.begin(), "outs" ); |
14458 | auto resultGroup1 = getODSResults(1); |
14459 | if (!resultGroup1.empty()) |
14460 | setNameFn(*resultGroup1.begin(), "ctl" ); |
14461 | } |
14462 | |
14463 | std::pair<unsigned, unsigned> WhileOp::getODSOperandIndexAndLength(unsigned index) { |
14464 | bool isVariadic[] = {true}; |
14465 | int prevVariadicCount = 0; |
14466 | for (unsigned i = 0; i < index; ++i) |
14467 | if (isVariadic[i]) ++prevVariadicCount; |
14468 | |
14469 | // Calculate how many dynamic values a static variadic operand corresponds to. |
14470 | // This assumes all static variadic operands have the same dynamic value count. |
14471 | int variadicSize = (getOperation()->getNumOperands() - 0) / 1; |
14472 | // `index` passed in as the parameter is the static index which counts each |
14473 | // operand (variadic or not) as size 1. So here for each previous static variadic |
14474 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
14475 | // value pack for this static operand starts. |
14476 | int start = index + (variadicSize - 1) * prevVariadicCount; |
14477 | int size = isVariadic[index] ? variadicSize : 1; |
14478 | return {start, size}; |
14479 | } |
14480 | |
14481 | ::mlir::Operation::operand_range WhileOp::getODSOperands(unsigned index) { |
14482 | auto valueRange = getODSOperandIndexAndLength(index); |
14483 | return {std::next(getOperation()->operand_begin(), valueRange.first), |
14484 | std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; |
14485 | } |
14486 | |
14487 | ::mlir::Operation::operand_range WhileOp::getArgs() { |
14488 | return getODSOperands(0); |
14489 | } |
14490 | |
14491 | ::mlir::Operation::operand_range WhileOp::args() { |
14492 | return getODSOperands(0); |
14493 | } |
14494 | |
14495 | ::mlir::MutableOperandRange WhileOp::getArgsMutable() { |
14496 | auto range = getODSOperandIndexAndLength(0); |
14497 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
14498 | return mutableRange; |
14499 | } |
14500 | |
14501 | ::mlir::MutableOperandRange WhileOp::argsMutable() { |
14502 | auto range = getODSOperandIndexAndLength(0); |
14503 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second); |
14504 | return mutableRange; |
14505 | } |
14506 | |
14507 | std::pair<unsigned, unsigned> WhileOp::getODSResultIndexAndLength(unsigned index) { |
14508 | bool isVariadic[] = {true, false}; |
14509 | int prevVariadicCount = 0; |
14510 | for (unsigned i = 0; i < index; ++i) |
14511 | if (isVariadic[i]) ++prevVariadicCount; |
14512 | |
14513 | // Calculate how many dynamic values a static variadic operand corresponds to. |
14514 | // This assumes all static variadic operands have the same dynamic value count. |
14515 | int variadicSize = (getOperation()->getNumResults() - 1) / 1; |
14516 | // `index` passed in as the parameter is the static index which counts each |
14517 | // operand (variadic or not) as size 1. So here for each previous static variadic |
14518 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
14519 | // value pack for this static operand starts. |
14520 | int start = index + (variadicSize - 1) * prevVariadicCount; |
14521 | int size = isVariadic[index] ? variadicSize : 1; |
14522 | return {start, size}; |
14523 | } |
14524 | |
14525 | ::mlir::Operation::result_range WhileOp::getODSResults(unsigned index) { |
14526 | auto valueRange = getODSResultIndexAndLength(index); |
14527 | return {std::next(getOperation()->result_begin(), valueRange.first), |
14528 | std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; |
14529 | } |
14530 | |
14531 | ::mlir::Operation::result_range WhileOp::getOuts() { |
14532 | return getODSResults(0); |
14533 | } |
14534 | |
14535 | ::mlir::Operation::result_range WhileOp::outs() { |
14536 | return getODSResults(0); |
14537 | } |
14538 | |
14539 | ::mlir::TypedValue<::mlir::tf_type::ControlType> WhileOp::getCtl() { |
14540 | return *getODSResults(1).begin(); |
14541 | } |
14542 | |
14543 | ::mlir::TypedValue<::mlir::tf_type::ControlType> WhileOp::ctl() { |
14544 | return *getODSResults(1).begin(); |
14545 | } |
14546 | |
14547 | ::mlir::tf_type::FuncAttr WhileOp::getCondAttr() { |
14548 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 1, getCondAttrName()).cast<::mlir::tf_type::FuncAttr>(); |
14549 | } |
14550 | |
14551 | ::mlir::tf_type::FuncAttr WhileOp::getCond() { |
14552 | auto attr = getCondAttr(); |
14553 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
14554 | } |
14555 | |
14556 | ::mlir::tf_type::FuncAttr WhileOp::condAttr() { |
14557 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 1, getCondAttrName()).cast<::mlir::tf_type::FuncAttr>(); |
14558 | } |
14559 | |
14560 | ::mlir::tf_type::FuncAttr WhileOp::cond() { |
14561 | auto attr = condAttr(); |
14562 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
14563 | } |
14564 | |
14565 | ::mlir::tf_type::FuncAttr WhileOp::getBodyAttr() { |
14566 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getBodyAttrName()).cast<::mlir::tf_type::FuncAttr>(); |
14567 | } |
14568 | |
14569 | ::mlir::tf_type::FuncAttr WhileOp::getBody() { |
14570 | auto attr = getBodyAttr(); |
14571 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
14572 | } |
14573 | |
14574 | ::mlir::tf_type::FuncAttr WhileOp::bodyAttr() { |
14575 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getBodyAttrName()).cast<::mlir::tf_type::FuncAttr>(); |
14576 | } |
14577 | |
14578 | ::mlir::tf_type::FuncAttr WhileOp::body() { |
14579 | auto attr = bodyAttr(); |
14580 | return attr.cast<::mlir::tf_type::FuncAttr>(); |
14581 | } |
14582 | |
14583 | ::mlir::IntegerAttr WhileOp::getParallelIterationsAttr() { |
14584 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 2, (*this)->getAttrs().end() - 0, getParallelIterationsAttrName()).cast<::mlir::IntegerAttr>(); |
14585 | } |
14586 | |
14587 | uint64_t WhileOp::getParallelIterations() { |
14588 | auto attr = getParallelIterationsAttr(); |
14589 | return attr.getValue().getZExtValue(); |
14590 | } |
14591 | |
14592 | ::mlir::IntegerAttr WhileOp::parallel_iterationsAttr() { |
14593 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 2, (*this)->getAttrs().end() - 0, getParallelIterationsAttrName()).cast<::mlir::IntegerAttr>(); |
14594 | } |
14595 | |
14596 | uint64_t WhileOp::parallel_iterations() { |
14597 | auto attr = parallel_iterationsAttr(); |
14598 | return attr.getValue().getZExtValue(); |
14599 | } |
14600 | |
14601 | ::mlir::ArrayAttr WhileOp::getTAttr() { |
14602 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 3, getTAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
14603 | } |
14604 | |
14605 | ::llvm::Optional< ::mlir::ArrayAttr > WhileOp::getT() { |
14606 | auto attr = getTAttr(); |
14607 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
14608 | } |
14609 | |
14610 | ::mlir::ArrayAttr WhileOp::TAttr() { |
14611 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 3, getTAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
14612 | } |
14613 | |
14614 | ::llvm::Optional< ::mlir::ArrayAttr > WhileOp::T() { |
14615 | auto attr = TAttr(); |
14616 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
14617 | } |
14618 | |
14619 | ::mlir::ArrayAttr WhileOp::getOutputShapesAttr() { |
14620 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 2, (*this)->getAttrs().end() - 1, getOutputShapesAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
14621 | } |
14622 | |
14623 | ::llvm::Optional< ::mlir::ArrayAttr > WhileOp::getOutputShapes() { |
14624 | auto attr = getOutputShapesAttr(); |
14625 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
14626 | } |
14627 | |
14628 | ::mlir::ArrayAttr WhileOp::output_shapesAttr() { |
14629 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 2, (*this)->getAttrs().end() - 1, getOutputShapesAttrName()).dyn_cast_or_null<::mlir::ArrayAttr>(); |
14630 | } |
14631 | |
14632 | ::llvm::Optional< ::mlir::ArrayAttr > WhileOp::output_shapes() { |
14633 | auto attr = output_shapesAttr(); |
14634 | return attr ? ::llvm::Optional< ::mlir::ArrayAttr >(attr) : (::llvm::None); |
14635 | } |
14636 | |
14637 | void WhileOp::setCondAttr(::mlir::tf_type::FuncAttr attr) { |
14638 | (*this)->setAttr(getCondAttrName(), attr); |
14639 | } |
14640 | |
14641 | void WhileOp::condAttr(::mlir::tf_type::FuncAttr attr) { |
14642 | (*this)->setAttr(condAttrName(), attr); |
14643 | } |
14644 | |
14645 | void WhileOp::setBodyAttr(::mlir::tf_type::FuncAttr attr) { |
14646 | (*this)->setAttr(getBodyAttrName(), attr); |
14647 | } |
14648 | |
14649 | void WhileOp::bodyAttr(::mlir::tf_type::FuncAttr attr) { |
14650 | (*this)->setAttr(bodyAttrName(), attr); |
14651 | } |
14652 | |
14653 | void WhileOp::setParallelIterationsAttr(::mlir::IntegerAttr attr) { |
14654 | (*this)->setAttr(getParallelIterationsAttrName(), attr); |
14655 | } |
14656 | |
14657 | void WhileOp::parallel_iterationsAttr(::mlir::IntegerAttr attr) { |
14658 | (*this)->setAttr(parallel_iterationsAttrName(), attr); |
14659 | } |
14660 | |
14661 | void WhileOp::setTAttr(::mlir::ArrayAttr attr) { |
14662 | (*this)->setAttr(getTAttrName(), attr); |
14663 | } |
14664 | |
14665 | void WhileOp::TAttr(::mlir::ArrayAttr attr) { |
14666 | (*this)->setAttr(TAttrName(), attr); |
14667 | } |
14668 | |
14669 | void WhileOp::setOutputShapesAttr(::mlir::ArrayAttr attr) { |
14670 | (*this)->setAttr(getOutputShapesAttrName(), attr); |
14671 | } |
14672 | |
14673 | void WhileOp::output_shapesAttr(::mlir::ArrayAttr attr) { |
14674 | (*this)->setAttr(output_shapesAttrName(), attr); |
14675 | } |
14676 | |
14677 | ::mlir::Attribute WhileOp::removeTAttr() { |
14678 | return (*this)->removeAttr(getTAttrName()); |
14679 | } |
14680 | |
14681 | ::mlir::Attribute WhileOp::removeOutput_shapesAttr() { |
14682 | return (*this)->removeAttr(getOutputShapesAttrName()); |
14683 | } |
14684 | |
14685 | void WhileOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, TypeRange results, ValueRange args, FuncAttr cond, FuncAttr body, IntegerAttr parallel_iterations) { |
14686 | build(odsBuilder, odsState, results, args, cond, body, parallel_iterations, |
14687 | /*T=*/{}, /*output_shapes=*/{}); |
14688 | |
14689 | } |
14690 | |
14691 | void WhileOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange outs, ::mlir::Type ctl, ::mlir::ValueRange args, ::mlir::tf_type::FuncAttr cond, ::mlir::tf_type::FuncAttr body, ::mlir::IntegerAttr parallel_iterations, /*optional*/::mlir::ArrayAttr T, /*optional*/::mlir::ArrayAttr output_shapes) { |
14692 | odsState.addOperands(args); |
14693 | odsState.addAttribute(getCondAttrName(odsState.name), cond); |
14694 | odsState.addAttribute(getBodyAttrName(odsState.name), body); |
14695 | odsState.addAttribute(getParallelIterationsAttrName(odsState.name), parallel_iterations); |
14696 | if (T) { |
14697 | odsState.addAttribute(getTAttrName(odsState.name), T); |
14698 | } |
14699 | if (output_shapes) { |
14700 | odsState.addAttribute(getOutputShapesAttrName(odsState.name), output_shapes); |
14701 | } |
14702 | odsState.addTypes(outs); |
14703 | odsState.addTypes(ctl); |
14704 | } |
14705 | |
14706 | void WhileOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange args, ::mlir::tf_type::FuncAttr cond, ::mlir::tf_type::FuncAttr body, ::mlir::IntegerAttr parallel_iterations, /*optional*/::mlir::ArrayAttr T, /*optional*/::mlir::ArrayAttr output_shapes) { |
14707 | odsState.addOperands(args); |
14708 | odsState.addAttribute(getCondAttrName(odsState.name), cond); |
14709 | odsState.addAttribute(getBodyAttrName(odsState.name), body); |
14710 | odsState.addAttribute(getParallelIterationsAttrName(odsState.name), parallel_iterations); |
14711 | if (T) { |
14712 | odsState.addAttribute(getTAttrName(odsState.name), T); |
14713 | } |
14714 | if (output_shapes) { |
14715 | odsState.addAttribute(getOutputShapesAttrName(odsState.name), output_shapes); |
14716 | } |
14717 | assert(resultTypes.size() >= 1u && "mismatched number of results" ); |
14718 | odsState.addTypes(resultTypes); |
14719 | } |
14720 | |
14721 | void WhileOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange outs, ::mlir::Type ctl, ::mlir::ValueRange args, ::mlir::tf_type::FuncAttr cond, ::mlir::tf_type::FuncAttr body, uint64_t parallel_iterations, /*optional*/::mlir::ArrayAttr T, /*optional*/::mlir::ArrayAttr output_shapes) { |
14722 | odsState.addOperands(args); |
14723 | odsState.addAttribute(getCondAttrName(odsState.name), cond); |
14724 | odsState.addAttribute(getBodyAttrName(odsState.name), body); |
14725 | odsState.addAttribute(getParallelIterationsAttrName(odsState.name), odsBuilder.getIntegerAttr(odsBuilder.getIntegerType(64), parallel_iterations)); |
14726 | if (T) { |
14727 | odsState.addAttribute(getTAttrName(odsState.name), T); |
14728 | } |
14729 | if (output_shapes) { |
14730 | odsState.addAttribute(getOutputShapesAttrName(odsState.name), output_shapes); |
14731 | } |
14732 | odsState.addTypes(outs); |
14733 | odsState.addTypes(ctl); |
14734 | } |
14735 | |
14736 | void WhileOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange args, ::mlir::tf_type::FuncAttr cond, ::mlir::tf_type::FuncAttr body, uint64_t parallel_iterations, /*optional*/::mlir::ArrayAttr T, /*optional*/::mlir::ArrayAttr output_shapes) { |
14737 | odsState.addOperands(args); |
14738 | odsState.addAttribute(getCondAttrName(odsState.name), cond); |
14739 | odsState.addAttribute(getBodyAttrName(odsState.name), body); |
14740 | odsState.addAttribute(getParallelIterationsAttrName(odsState.name), odsBuilder.getIntegerAttr(odsBuilder.getIntegerType(64), parallel_iterations)); |
14741 | if (T) { |
14742 | odsState.addAttribute(getTAttrName(odsState.name), T); |
14743 | } |
14744 | if (output_shapes) { |
14745 | odsState.addAttribute(getOutputShapesAttrName(odsState.name), output_shapes); |
14746 | } |
14747 | assert(resultTypes.size() >= 1u && "mismatched number of results" ); |
14748 | odsState.addTypes(resultTypes); |
14749 | } |
14750 | |
14751 | void WhileOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { |
14752 | odsState.addOperands(operands); |
14753 | odsState.addAttributes(attributes); |
14754 | assert(resultTypes.size() >= 1u && "mismatched number of return types" ); |
14755 | odsState.addTypes(resultTypes); |
14756 | } |
14757 | |
14758 | ::mlir::LogicalResult WhileOp::verifyInvariantsImpl() { |
14759 | auto namedAttrRange = (*this)->getAttrs(); |
14760 | auto namedAttrIt = namedAttrRange.begin(); |
14761 | ::mlir::Attribute tblgen_body; |
14762 | ::mlir::Attribute tblgen_T; |
14763 | while (true) { |
14764 | if (namedAttrIt == namedAttrRange.end()) |
14765 | return emitOpError("requires attribute 'body'" ); |
14766 | if (namedAttrIt->getName() == getBodyAttrName()) { |
14767 | tblgen_body = namedAttrIt->getValue(); |
14768 | break; |
14769 | } |
14770 | else if (namedAttrIt->getName() == getTAttrName()) { |
14771 | tblgen_T = namedAttrIt->getValue(); |
14772 | } |
14773 | ++namedAttrIt; |
14774 | } |
14775 | ::mlir::Attribute tblgen_cond; |
14776 | while (true) { |
14777 | if (namedAttrIt == namedAttrRange.end()) |
14778 | return emitOpError("requires attribute 'cond'" ); |
14779 | if (namedAttrIt->getName() == getCondAttrName()) { |
14780 | tblgen_cond = namedAttrIt->getValue(); |
14781 | break; |
14782 | } |
14783 | ++namedAttrIt; |
14784 | } |
14785 | ::mlir::Attribute tblgen_parallel_iterations; |
14786 | ::mlir::Attribute tblgen_output_shapes; |
14787 | while (true) { |
14788 | if (namedAttrIt == namedAttrRange.end()) |
14789 | return emitOpError("requires attribute 'parallel_iterations'" ); |
14790 | if (namedAttrIt->getName() == getParallelIterationsAttrName()) { |
14791 | tblgen_parallel_iterations = namedAttrIt->getValue(); |
14792 | break; |
14793 | } |
14794 | else if (namedAttrIt->getName() == getOutputShapesAttrName()) { |
14795 | tblgen_output_shapes = namedAttrIt->getValue(); |
14796 | } |
14797 | ++namedAttrIt; |
14798 | } |
14799 | |
14800 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops5(*this, tblgen_cond, "cond" ))) |
14801 | return ::mlir::failure(); |
14802 | |
14803 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops5(*this, tblgen_body, "body" ))) |
14804 | return ::mlir::failure(); |
14805 | |
14806 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops18(*this, tblgen_parallel_iterations, "parallel_iterations" ))) |
14807 | return ::mlir::failure(); |
14808 | |
14809 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops1(*this, tblgen_T, "T" ))) |
14810 | return ::mlir::failure(); |
14811 | |
14812 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops2(*this, tblgen_output_shapes, "output_shapes" ))) |
14813 | return ::mlir::failure(); |
14814 | { |
14815 | unsigned index = 0; (void)index; |
14816 | auto valueGroup0 = getODSOperands(0); |
14817 | |
14818 | for (auto v : valueGroup0) { |
14819 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops1(*this, v.getType(), "operand" , index++))) |
14820 | return ::mlir::failure(); |
14821 | } |
14822 | } |
14823 | { |
14824 | unsigned index = 0; (void)index; |
14825 | auto valueGroup0 = getODSResults(0); |
14826 | |
14827 | for (auto v : valueGroup0) { |
14828 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops2(*this, v.getType(), "result" , index++))) |
14829 | return ::mlir::failure(); |
14830 | } |
14831 | auto valueGroup1 = getODSResults(1); |
14832 | |
14833 | for (auto v : valueGroup1) { |
14834 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops3(*this, v.getType(), "result" , index++))) |
14835 | return ::mlir::failure(); |
14836 | } |
14837 | } |
14838 | return ::mlir::success(); |
14839 | } |
14840 | |
14841 | ::mlir::LogicalResult WhileOp::verifyInvariants() { |
14842 | return verifyInvariantsImpl(); |
14843 | } |
14844 | |
14845 | LogicalResult WhileOp::verifySymbolUses( |
14846 | SymbolTableCollection &symbol_table) { |
14847 | return VerifyWhileLikeOp(*this, symbol_table); |
14848 | } |
14849 | } // namespace tfg |
14850 | } // namespace mlir |
14851 | MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::tfg::WhileOp) |
14852 | |
14853 | namespace mlir { |
14854 | namespace tfg { |
14855 | |
14856 | //===----------------------------------------------------------------------===// |
14857 | // ::mlir::tfg::WhileRegionOp definitions |
14858 | //===----------------------------------------------------------------------===// |
14859 | |
14860 | WhileRegionOpAdaptor::WhileRegionOpAdaptor(::mlir::ValueRange values, ::mlir::DictionaryAttr attrs, ::mlir::RegionRange regions) : odsOperands(values), odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) |
14861 | odsOpName.emplace("tfg.WhileRegion" , odsAttrs.getContext()); |
14862 | } |
14863 | |
14864 | WhileRegionOpAdaptor::WhileRegionOpAdaptor(WhileRegionOp op) : odsOperands(op->getOperands()), odsAttrs(op->getAttrDictionary()), odsRegions(op->getRegions()), odsOpName(op->getName()) {} |
14865 | |
14866 | ::mlir::ValueRange WhileRegionOpAdaptor::getOperands() { |
14867 | return odsOperands; |
14868 | } |
14869 | |
14870 | std::pair<unsigned, unsigned> WhileRegionOpAdaptor::getODSOperandIndexAndLength(unsigned index) { |
14871 | assert(odsAttrs && "missing segment size attribute for op" ); |
14872 | auto sizeAttr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 1, WhileRegionOp::getOperandSegmentSizesAttrName(*odsOpName)).cast<::mlir::DenseI32ArrayAttr>(); |
14873 | |
14874 | unsigned start = 0; |
14875 | for (unsigned i = 0; i < index; ++i) |
14876 | start += sizeAttr[i]; |
14877 | return {start, sizeAttr[index]}; |
14878 | } |
14879 | |
14880 | ::mlir::ValueRange WhileRegionOpAdaptor::getODSOperands(unsigned index) { |
14881 | auto valueRange = getODSOperandIndexAndLength(index); |
14882 | return {std::next(odsOperands.begin(), valueRange.first), |
14883 | std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; |
14884 | } |
14885 | |
14886 | ::mlir::ValueRange WhileRegionOpAdaptor::getInit() { |
14887 | return getODSOperands(0); |
14888 | } |
14889 | |
14890 | ::mlir::ValueRange WhileRegionOpAdaptor::init() { |
14891 | return getODSOperands(0); |
14892 | } |
14893 | |
14894 | ::mlir::ValueRange WhileRegionOpAdaptor::getCtls() { |
14895 | return getODSOperands(1); |
14896 | } |
14897 | |
14898 | ::mlir::ValueRange WhileRegionOpAdaptor::ctls() { |
14899 | return getODSOperands(1); |
14900 | } |
14901 | |
14902 | ::mlir::DictionaryAttr WhileRegionOpAdaptor::getAttributes() { |
14903 | return odsAttrs; |
14904 | } |
14905 | |
14906 | ::mlir::IntegerAttr WhileRegionOpAdaptor::getParallelIterationsAttr() { |
14907 | assert(odsAttrs && "no attributes when constructing adapter" ); |
14908 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 0, WhileRegionOp::getParallelIterationsAttrName(*odsOpName)).cast<::mlir::IntegerAttr>(); |
14909 | return attr; |
14910 | } |
14911 | |
14912 | uint64_t WhileRegionOpAdaptor::getParallelIterations() { |
14913 | auto attr = getParallelIterationsAttr(); |
14914 | return attr.getValue().getZExtValue(); |
14915 | } |
14916 | |
14917 | ::mlir::IntegerAttr WhileRegionOpAdaptor::parallel_iterationsAttr() { |
14918 | assert(odsAttrs && "no attributes when constructing adapter" ); |
14919 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 1, odsAttrs.end() - 0, WhileRegionOp::getParallelIterationsAttrName(*odsOpName)).cast<::mlir::IntegerAttr>(); |
14920 | return attr; |
14921 | } |
14922 | |
14923 | uint64_t WhileRegionOpAdaptor::parallel_iterations() { |
14924 | auto attr = parallel_iterationsAttr(); |
14925 | return attr.getValue().getZExtValue(); |
14926 | } |
14927 | |
14928 | ::mlir::DictionaryAttr WhileRegionOpAdaptor::getCondAttrsAttr() { |
14929 | assert(odsAttrs && "no attributes when constructing adapter" ); |
14930 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, WhileRegionOp::getCondAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
14931 | return attr; |
14932 | } |
14933 | |
14934 | ::llvm::Optional< ::mlir::DictionaryAttr > WhileRegionOpAdaptor::getCondAttrs() { |
14935 | auto attr = getCondAttrsAttr(); |
14936 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
14937 | } |
14938 | |
14939 | ::mlir::DictionaryAttr WhileRegionOpAdaptor::cond_attrsAttr() { |
14940 | assert(odsAttrs && "no attributes when constructing adapter" ); |
14941 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, WhileRegionOp::getCondAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
14942 | return attr; |
14943 | } |
14944 | |
14945 | ::llvm::Optional< ::mlir::DictionaryAttr > WhileRegionOpAdaptor::cond_attrs() { |
14946 | auto attr = cond_attrsAttr(); |
14947 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
14948 | } |
14949 | |
14950 | ::mlir::DictionaryAttr WhileRegionOpAdaptor::getBodyAttrsAttr() { |
14951 | assert(odsAttrs && "no attributes when constructing adapter" ); |
14952 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, WhileRegionOp::getBodyAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
14953 | return attr; |
14954 | } |
14955 | |
14956 | ::llvm::Optional< ::mlir::DictionaryAttr > WhileRegionOpAdaptor::getBodyAttrs() { |
14957 | auto attr = getBodyAttrsAttr(); |
14958 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
14959 | } |
14960 | |
14961 | ::mlir::DictionaryAttr WhileRegionOpAdaptor::body_attrsAttr() { |
14962 | assert(odsAttrs && "no attributes when constructing adapter" ); |
14963 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, WhileRegionOp::getBodyAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
14964 | return attr; |
14965 | } |
14966 | |
14967 | ::llvm::Optional< ::mlir::DictionaryAttr > WhileRegionOpAdaptor::body_attrs() { |
14968 | auto attr = body_attrsAttr(); |
14969 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
14970 | } |
14971 | |
14972 | ::mlir::tfg::RegionAttr WhileRegionOpAdaptor::getCondRegionAttrsAttr() { |
14973 | assert(odsAttrs && "no attributes when constructing adapter" ); |
14974 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, WhileRegionOp::getCondRegionAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
14975 | return attr; |
14976 | } |
14977 | |
14978 | ::llvm::Optional<::mlir::tfg::RegionAttr> WhileRegionOpAdaptor::getCondRegionAttrs() { |
14979 | auto attr = getCondRegionAttrsAttr(); |
14980 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
14981 | } |
14982 | |
14983 | ::mlir::tfg::RegionAttr WhileRegionOpAdaptor::cond_region_attrsAttr() { |
14984 | assert(odsAttrs && "no attributes when constructing adapter" ); |
14985 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, WhileRegionOp::getCondRegionAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
14986 | return attr; |
14987 | } |
14988 | |
14989 | ::llvm::Optional<::mlir::tfg::RegionAttr> WhileRegionOpAdaptor::cond_region_attrs() { |
14990 | auto attr = cond_region_attrsAttr(); |
14991 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
14992 | } |
14993 | |
14994 | ::mlir::tfg::RegionAttr WhileRegionOpAdaptor::getBodyRegionAttrsAttr() { |
14995 | assert(odsAttrs && "no attributes when constructing adapter" ); |
14996 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, WhileRegionOp::getBodyRegionAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
14997 | return attr; |
14998 | } |
14999 | |
15000 | ::llvm::Optional<::mlir::tfg::RegionAttr> WhileRegionOpAdaptor::getBodyRegionAttrs() { |
15001 | auto attr = getBodyRegionAttrsAttr(); |
15002 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
15003 | } |
15004 | |
15005 | ::mlir::tfg::RegionAttr WhileRegionOpAdaptor::body_region_attrsAttr() { |
15006 | assert(odsAttrs && "no attributes when constructing adapter" ); |
15007 | auto attr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 2, WhileRegionOp::getBodyRegionAttrsAttrName(*odsOpName)).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
15008 | return attr; |
15009 | } |
15010 | |
15011 | ::llvm::Optional<::mlir::tfg::RegionAttr> WhileRegionOpAdaptor::body_region_attrs() { |
15012 | auto attr = body_region_attrsAttr(); |
15013 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
15014 | } |
15015 | |
15016 | ::mlir::RegionRange WhileRegionOpAdaptor::getRegions() { |
15017 | return odsRegions; |
15018 | } |
15019 | |
15020 | ::mlir::Region &WhileRegionOpAdaptor::getCondRegion() { |
15021 | return *odsRegions[0]; |
15022 | } |
15023 | |
15024 | ::mlir::Region &WhileRegionOpAdaptor::cond_region() { |
15025 | return *odsRegions[0]; |
15026 | } |
15027 | |
15028 | ::mlir::Region &WhileRegionOpAdaptor::getBodyRegion() { |
15029 | return *odsRegions[1]; |
15030 | } |
15031 | |
15032 | ::mlir::Region &WhileRegionOpAdaptor::body_region() { |
15033 | return *odsRegions[1]; |
15034 | } |
15035 | |
15036 | ::mlir::LogicalResult WhileRegionOpAdaptor::verify(::mlir::Location loc) { |
15037 | auto namedAttrRange = odsAttrs; |
15038 | auto namedAttrIt = namedAttrRange.begin(); |
15039 | ::mlir::Attribute tblgen_operand_segment_sizes; |
15040 | ::mlir::Attribute tblgen_body_attrs; |
15041 | ::mlir::Attribute tblgen_body_region_attrs; |
15042 | ::mlir::Attribute tblgen_cond_attrs; |
15043 | ::mlir::Attribute tblgen_cond_region_attrs; |
15044 | while (true) { |
15045 | if (namedAttrIt == namedAttrRange.end()) |
15046 | return emitError(loc, "'tfg.WhileRegion' op " "requires attribute 'operand_segment_sizes'" ); |
15047 | if (namedAttrIt->getName() == WhileRegionOp::getOperandSegmentSizesAttrName(*odsOpName)) { |
15048 | tblgen_operand_segment_sizes = namedAttrIt->getValue(); |
15049 | break; |
15050 | } |
15051 | else if (namedAttrIt->getName() == WhileRegionOp::getBodyAttrsAttrName(*odsOpName)) { |
15052 | tblgen_body_attrs = namedAttrIt->getValue(); |
15053 | } |
15054 | else if (namedAttrIt->getName() == WhileRegionOp::getBodyRegionAttrsAttrName(*odsOpName)) { |
15055 | tblgen_body_region_attrs = namedAttrIt->getValue(); |
15056 | } |
15057 | else if (namedAttrIt->getName() == WhileRegionOp::getCondAttrsAttrName(*odsOpName)) { |
15058 | tblgen_cond_attrs = namedAttrIt->getValue(); |
15059 | } |
15060 | else if (namedAttrIt->getName() == WhileRegionOp::getCondRegionAttrsAttrName(*odsOpName)) { |
15061 | tblgen_cond_region_attrs = namedAttrIt->getValue(); |
15062 | } |
15063 | ++namedAttrIt; |
15064 | } |
15065 | ::mlir::Attribute tblgen_parallel_iterations; |
15066 | while (true) { |
15067 | if (namedAttrIt == namedAttrRange.end()) |
15068 | return emitError(loc, "'tfg.WhileRegion' op " "requires attribute 'parallel_iterations'" ); |
15069 | if (namedAttrIt->getName() == WhileRegionOp::getParallelIterationsAttrName(*odsOpName)) { |
15070 | tblgen_parallel_iterations = namedAttrIt->getValue(); |
15071 | break; |
15072 | } |
15073 | ++namedAttrIt; |
15074 | } |
15075 | |
15076 | { |
15077 | auto sizeAttr = tblgen_operand_segment_sizes.cast<::mlir::DenseI32ArrayAttr>(); |
15078 | auto numElements = sizeAttr.asArrayRef().size(); |
15079 | if (numElements != 2) |
15080 | return emitError(loc, "'tfg.WhileRegion' op " "'operand_segment_sizes' attribute for specifying operand segments must have 2 " |
15081 | "elements, but got " ) << numElements; |
15082 | } |
15083 | |
15084 | if (tblgen_parallel_iterations && !(((tblgen_parallel_iterations.isa<::mlir::IntegerAttr>())) && ((tblgen_parallel_iterations.cast<::mlir::IntegerAttr>().getType().isSignlessInteger(64))))) |
15085 | return emitError(loc, "'tfg.WhileRegion' op " "attribute 'parallel_iterations' failed to satisfy constraint: 64-bit signless integer attribute" ); |
15086 | |
15087 | if (tblgen_cond_attrs && !((tblgen_cond_attrs.isa<::mlir::DictionaryAttr>()))) |
15088 | return emitError(loc, "'tfg.WhileRegion' op " "attribute 'cond_attrs' failed to satisfy constraint: dictionary of named attribute values" ); |
15089 | |
15090 | if (tblgen_body_attrs && !((tblgen_body_attrs.isa<::mlir::DictionaryAttr>()))) |
15091 | return emitError(loc, "'tfg.WhileRegion' op " "attribute 'body_attrs' failed to satisfy constraint: dictionary of named attribute values" ); |
15092 | |
15093 | if (tblgen_cond_region_attrs && !((tblgen_cond_region_attrs.isa<::mlir::tfg::RegionAttr>()))) |
15094 | return emitError(loc, "'tfg.WhileRegion' op " "attribute 'cond_region_attrs' failed to satisfy constraint: Region attributes, argument and result attributes." ); |
15095 | |
15096 | if (tblgen_body_region_attrs && !((tblgen_body_region_attrs.isa<::mlir::tfg::RegionAttr>()))) |
15097 | return emitError(loc, "'tfg.WhileRegion' op " "attribute 'body_region_attrs' failed to satisfy constraint: Region attributes, argument and result attributes." ); |
15098 | return ::mlir::success(); |
15099 | } |
15100 | |
15101 | std::pair<unsigned, unsigned> WhileRegionOp::getODSOperandIndexAndLength(unsigned index) { |
15102 | auto sizeAttr = ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getOperandSegmentSizesAttrName()).cast<::mlir::DenseI32ArrayAttr>(); |
15103 | |
15104 | unsigned start = 0; |
15105 | for (unsigned i = 0; i < index; ++i) |
15106 | start += sizeAttr[i]; |
15107 | return {start, sizeAttr[index]}; |
15108 | } |
15109 | |
15110 | ::mlir::Operation::operand_range WhileRegionOp::getODSOperands(unsigned index) { |
15111 | auto valueRange = getODSOperandIndexAndLength(index); |
15112 | return {std::next(getOperation()->operand_begin(), valueRange.first), |
15113 | std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; |
15114 | } |
15115 | |
15116 | ::mlir::Operation::operand_range WhileRegionOp::getInit() { |
15117 | return getODSOperands(0); |
15118 | } |
15119 | |
15120 | ::mlir::Operation::operand_range WhileRegionOp::init() { |
15121 | return getODSOperands(0); |
15122 | } |
15123 | |
15124 | ::mlir::Operation::operand_range WhileRegionOp::getCtls() { |
15125 | return getODSOperands(1); |
15126 | } |
15127 | |
15128 | ::mlir::Operation::operand_range WhileRegionOp::ctls() { |
15129 | return getODSOperands(1); |
15130 | } |
15131 | |
15132 | ::mlir::MutableOperandRange WhileRegionOp::getInitMutable() { |
15133 | auto range = getODSOperandIndexAndLength(0); |
15134 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(0u, *::mlir::impl::getNamedAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getOperandSegmentSizesAttrName()))); |
15135 | return mutableRange; |
15136 | } |
15137 | |
15138 | ::mlir::MutableOperandRange WhileRegionOp::initMutable() { |
15139 | auto range = getODSOperandIndexAndLength(0); |
15140 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(0u, *::mlir::impl::getNamedAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getOperandSegmentSizesAttrName()))); |
15141 | return mutableRange; |
15142 | } |
15143 | |
15144 | ::mlir::MutableOperandRange WhileRegionOp::getCtlsMutable() { |
15145 | auto range = getODSOperandIndexAndLength(1); |
15146 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(1u, *::mlir::impl::getNamedAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getOperandSegmentSizesAttrName()))); |
15147 | return mutableRange; |
15148 | } |
15149 | |
15150 | ::mlir::MutableOperandRange WhileRegionOp::ctlsMutable() { |
15151 | auto range = getODSOperandIndexAndLength(1); |
15152 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(1u, *::mlir::impl::getNamedAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 1, getOperandSegmentSizesAttrName()))); |
15153 | return mutableRange; |
15154 | } |
15155 | |
15156 | std::pair<unsigned, unsigned> WhileRegionOp::getODSResultIndexAndLength(unsigned index) { |
15157 | bool isVariadic[] = {true, false}; |
15158 | int prevVariadicCount = 0; |
15159 | for (unsigned i = 0; i < index; ++i) |
15160 | if (isVariadic[i]) ++prevVariadicCount; |
15161 | |
15162 | // Calculate how many dynamic values a static variadic operand corresponds to. |
15163 | // This assumes all static variadic operands have the same dynamic value count. |
15164 | int variadicSize = (getOperation()->getNumResults() - 1) / 1; |
15165 | // `index` passed in as the parameter is the static index which counts each |
15166 | // operand (variadic or not) as size 1. So here for each previous static variadic |
15167 | // operand, we need to offset by (variadicSize - 1) to get where the dynamic |
15168 | // value pack for this static operand starts. |
15169 | int start = index + (variadicSize - 1) * prevVariadicCount; |
15170 | int size = isVariadic[index] ? variadicSize : 1; |
15171 | return {start, size}; |
15172 | } |
15173 | |
15174 | ::mlir::Operation::result_range WhileRegionOp::getODSResults(unsigned index) { |
15175 | auto valueRange = getODSResultIndexAndLength(index); |
15176 | return {std::next(getOperation()->result_begin(), valueRange.first), |
15177 | std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; |
15178 | } |
15179 | |
15180 | ::mlir::Operation::result_range WhileRegionOp::getOuts() { |
15181 | return getODSResults(0); |
15182 | } |
15183 | |
15184 | ::mlir::Operation::result_range WhileRegionOp::outs() { |
15185 | return getODSResults(0); |
15186 | } |
15187 | |
15188 | ::mlir::TypedValue<::mlir::tf_type::ControlType> WhileRegionOp::getCtl() { |
15189 | return *getODSResults(1).begin(); |
15190 | } |
15191 | |
15192 | ::mlir::TypedValue<::mlir::tf_type::ControlType> WhileRegionOp::ctl() { |
15193 | return *getODSResults(1).begin(); |
15194 | } |
15195 | |
15196 | ::mlir::Region &WhileRegionOp::getCondRegion() { |
15197 | return (*this)->getRegion(0); |
15198 | } |
15199 | |
15200 | ::mlir::Region &WhileRegionOp::cond_region() { |
15201 | return (*this)->getRegion(0); |
15202 | } |
15203 | |
15204 | ::mlir::Region &WhileRegionOp::getBodyRegion() { |
15205 | return (*this)->getRegion(1); |
15206 | } |
15207 | |
15208 | ::mlir::Region &WhileRegionOp::body_region() { |
15209 | return (*this)->getRegion(1); |
15210 | } |
15211 | |
15212 | ::mlir::IntegerAttr WhileRegionOp::getParallelIterationsAttr() { |
15213 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getParallelIterationsAttrName()).cast<::mlir::IntegerAttr>(); |
15214 | } |
15215 | |
15216 | uint64_t WhileRegionOp::getParallelIterations() { |
15217 | auto attr = getParallelIterationsAttr(); |
15218 | return attr.getValue().getZExtValue(); |
15219 | } |
15220 | |
15221 | ::mlir::IntegerAttr WhileRegionOp::parallel_iterationsAttr() { |
15222 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 1, (*this)->getAttrs().end() - 0, getParallelIterationsAttrName()).cast<::mlir::IntegerAttr>(); |
15223 | } |
15224 | |
15225 | uint64_t WhileRegionOp::parallel_iterations() { |
15226 | auto attr = parallel_iterationsAttr(); |
15227 | return attr.getValue().getZExtValue(); |
15228 | } |
15229 | |
15230 | ::mlir::DictionaryAttr WhileRegionOp::getCondAttrsAttr() { |
15231 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getCondAttrsAttrName()).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
15232 | } |
15233 | |
15234 | ::llvm::Optional< ::mlir::DictionaryAttr > WhileRegionOp::getCondAttrs() { |
15235 | auto attr = getCondAttrsAttr(); |
15236 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
15237 | } |
15238 | |
15239 | ::mlir::DictionaryAttr WhileRegionOp::cond_attrsAttr() { |
15240 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getCondAttrsAttrName()).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
15241 | } |
15242 | |
15243 | ::llvm::Optional< ::mlir::DictionaryAttr > WhileRegionOp::cond_attrs() { |
15244 | auto attr = cond_attrsAttr(); |
15245 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
15246 | } |
15247 | |
15248 | ::mlir::DictionaryAttr WhileRegionOp::getBodyAttrsAttr() { |
15249 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getBodyAttrsAttrName()).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
15250 | } |
15251 | |
15252 | ::llvm::Optional< ::mlir::DictionaryAttr > WhileRegionOp::getBodyAttrs() { |
15253 | auto attr = getBodyAttrsAttr(); |
15254 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
15255 | } |
15256 | |
15257 | ::mlir::DictionaryAttr WhileRegionOp::body_attrsAttr() { |
15258 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getBodyAttrsAttrName()).dyn_cast_or_null<::mlir::DictionaryAttr>(); |
15259 | } |
15260 | |
15261 | ::llvm::Optional< ::mlir::DictionaryAttr > WhileRegionOp::body_attrs() { |
15262 | auto attr = body_attrsAttr(); |
15263 | return attr ? ::llvm::Optional< ::mlir::DictionaryAttr >(attr) : (::llvm::None); |
15264 | } |
15265 | |
15266 | ::mlir::tfg::RegionAttr WhileRegionOp::getCondRegionAttrsAttr() { |
15267 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getCondRegionAttrsAttrName()).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
15268 | } |
15269 | |
15270 | ::llvm::Optional<::mlir::tfg::RegionAttr> WhileRegionOp::getCondRegionAttrs() { |
15271 | auto attr = getCondRegionAttrsAttr(); |
15272 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
15273 | } |
15274 | |
15275 | ::mlir::tfg::RegionAttr WhileRegionOp::cond_region_attrsAttr() { |
15276 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getCondRegionAttrsAttrName()).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
15277 | } |
15278 | |
15279 | ::llvm::Optional<::mlir::tfg::RegionAttr> WhileRegionOp::cond_region_attrs() { |
15280 | auto attr = cond_region_attrsAttr(); |
15281 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
15282 | } |
15283 | |
15284 | ::mlir::tfg::RegionAttr WhileRegionOp::getBodyRegionAttrsAttr() { |
15285 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getBodyRegionAttrsAttrName()).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
15286 | } |
15287 | |
15288 | ::llvm::Optional<::mlir::tfg::RegionAttr> WhileRegionOp::getBodyRegionAttrs() { |
15289 | auto attr = getBodyRegionAttrsAttr(); |
15290 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
15291 | } |
15292 | |
15293 | ::mlir::tfg::RegionAttr WhileRegionOp::body_region_attrsAttr() { |
15294 | return ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 2, getBodyRegionAttrsAttrName()).dyn_cast_or_null<::mlir::tfg::RegionAttr>(); |
15295 | } |
15296 | |
15297 | ::llvm::Optional<::mlir::tfg::RegionAttr> WhileRegionOp::body_region_attrs() { |
15298 | auto attr = body_region_attrsAttr(); |
15299 | return attr ? ::llvm::Optional<::mlir::tfg::RegionAttr>(attr.cast<::mlir::tfg::RegionAttr>()) : (::llvm::None); |
15300 | } |
15301 | |
15302 | void WhileRegionOp::setParallelIterationsAttr(::mlir::IntegerAttr attr) { |
15303 | (*this)->setAttr(getParallelIterationsAttrName(), attr); |
15304 | } |
15305 | |
15306 | void WhileRegionOp::parallel_iterationsAttr(::mlir::IntegerAttr attr) { |
15307 | (*this)->setAttr(parallel_iterationsAttrName(), attr); |
15308 | } |
15309 | |
15310 | void WhileRegionOp::setCondAttrsAttr(::mlir::DictionaryAttr attr) { |
15311 | (*this)->setAttr(getCondAttrsAttrName(), attr); |
15312 | } |
15313 | |
15314 | void WhileRegionOp::cond_attrsAttr(::mlir::DictionaryAttr attr) { |
15315 | (*this)->setAttr(cond_attrsAttrName(), attr); |
15316 | } |
15317 | |
15318 | void WhileRegionOp::setBodyAttrsAttr(::mlir::DictionaryAttr attr) { |
15319 | (*this)->setAttr(getBodyAttrsAttrName(), attr); |
15320 | } |
15321 | |
15322 | void WhileRegionOp::body_attrsAttr(::mlir::DictionaryAttr attr) { |
15323 | (*this)->setAttr(body_attrsAttrName(), attr); |
15324 | } |
15325 | |
15326 | void WhileRegionOp::setCondRegionAttrsAttr(::mlir::tfg::RegionAttr attr) { |
15327 | (*this)->setAttr(getCondRegionAttrsAttrName(), attr); |
15328 | } |
15329 | |
15330 | void WhileRegionOp::cond_region_attrsAttr(::mlir::tfg::RegionAttr attr) { |
15331 | (*this)->setAttr(cond_region_attrsAttrName(), attr); |
15332 | } |
15333 | |
15334 | void WhileRegionOp::setBodyRegionAttrsAttr(::mlir::tfg::RegionAttr attr) { |
15335 | (*this)->setAttr(getBodyRegionAttrsAttrName(), attr); |
15336 | } |
15337 | |
15338 | void WhileRegionOp::body_region_attrsAttr(::mlir::tfg::RegionAttr attr) { |
15339 | (*this)->setAttr(body_region_attrsAttrName(), attr); |
15340 | } |
15341 | |
15342 | ::mlir::Attribute WhileRegionOp::removeCond_attrsAttr() { |
15343 | return (*this)->removeAttr(getCondAttrsAttrName()); |
15344 | } |
15345 | |
15346 | ::mlir::Attribute WhileRegionOp::removeBody_attrsAttr() { |
15347 | return (*this)->removeAttr(getBodyAttrsAttrName()); |
15348 | } |
15349 | |
15350 | ::mlir::Attribute WhileRegionOp::removeCond_region_attrsAttr() { |
15351 | return (*this)->removeAttr(getCondRegionAttrsAttrName()); |
15352 | } |
15353 | |
15354 | ::mlir::Attribute WhileRegionOp::removeBody_region_attrsAttr() { |
15355 | return (*this)->removeAttr(getBodyRegionAttrsAttrName()); |
15356 | } |
15357 | |
15358 | void WhileRegionOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange outs, ::mlir::Type ctl, ::mlir::ValueRange init, ::mlir::ValueRange ctls, ::mlir::IntegerAttr parallel_iterations, /*optional*/::mlir::DictionaryAttr cond_attrs, /*optional*/::mlir::DictionaryAttr body_attrs, /*optional*/::mlir::tfg::RegionAttr cond_region_attrs, /*optional*/::mlir::tfg::RegionAttr body_region_attrs) { |
15359 | odsState.addOperands(init); |
15360 | odsState.addOperands(ctls); |
15361 | odsState.addAttribute(getOperandSegmentSizesAttrName(odsState.name), odsBuilder.getDenseI32ArrayAttr({static_cast<int32_t>(init.size()), static_cast<int32_t>(ctls.size())})); |
15362 | odsState.addAttribute(getParallelIterationsAttrName(odsState.name), parallel_iterations); |
15363 | if (cond_attrs) { |
15364 | odsState.addAttribute(getCondAttrsAttrName(odsState.name), cond_attrs); |
15365 | } |
15366 | if (body_attrs) { |
15367 | odsState.addAttribute(getBodyAttrsAttrName(odsState.name), body_attrs); |
15368 | } |
15369 | if (cond_region_attrs) { |
15370 | odsState.addAttribute(getCondRegionAttrsAttrName(odsState.name), cond_region_attrs); |
15371 | } |
15372 | if (body_region_attrs) { |
15373 | odsState.addAttribute(getBodyRegionAttrsAttrName(odsState.name), body_region_attrs); |
15374 | } |
15375 | (void)odsState.addRegion(); |
15376 | (void)odsState.addRegion(); |
15377 | odsState.addTypes(outs); |
15378 | odsState.addTypes(ctl); |
15379 | } |
15380 | |
15381 | void WhileRegionOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange init, ::mlir::ValueRange ctls, ::mlir::IntegerAttr parallel_iterations, /*optional*/::mlir::DictionaryAttr cond_attrs, /*optional*/::mlir::DictionaryAttr body_attrs, /*optional*/::mlir::tfg::RegionAttr cond_region_attrs, /*optional*/::mlir::tfg::RegionAttr body_region_attrs) { |
15382 | odsState.addOperands(init); |
15383 | odsState.addOperands(ctls); |
15384 | odsState.addAttribute(getOperandSegmentSizesAttrName(odsState.name), odsBuilder.getDenseI32ArrayAttr({static_cast<int32_t>(init.size()), static_cast<int32_t>(ctls.size())})); |
15385 | odsState.addAttribute(getParallelIterationsAttrName(odsState.name), parallel_iterations); |
15386 | if (cond_attrs) { |
15387 | odsState.addAttribute(getCondAttrsAttrName(odsState.name), cond_attrs); |
15388 | } |
15389 | if (body_attrs) { |
15390 | odsState.addAttribute(getBodyAttrsAttrName(odsState.name), body_attrs); |
15391 | } |
15392 | if (cond_region_attrs) { |
15393 | odsState.addAttribute(getCondRegionAttrsAttrName(odsState.name), cond_region_attrs); |
15394 | } |
15395 | if (body_region_attrs) { |
15396 | odsState.addAttribute(getBodyRegionAttrsAttrName(odsState.name), body_region_attrs); |
15397 | } |
15398 | (void)odsState.addRegion(); |
15399 | (void)odsState.addRegion(); |
15400 | assert(resultTypes.size() >= 1u && "mismatched number of results" ); |
15401 | odsState.addTypes(resultTypes); |
15402 | } |
15403 | |
15404 | void WhileRegionOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange outs, ::mlir::Type ctl, ::mlir::ValueRange init, ::mlir::ValueRange ctls, uint64_t parallel_iterations, /*optional*/::mlir::DictionaryAttr cond_attrs, /*optional*/::mlir::DictionaryAttr body_attrs, /*optional*/::mlir::tfg::RegionAttr cond_region_attrs, /*optional*/::mlir::tfg::RegionAttr body_region_attrs) { |
15405 | odsState.addOperands(init); |
15406 | odsState.addOperands(ctls); |
15407 | odsState.addAttribute(getOperandSegmentSizesAttrName(odsState.name), odsBuilder.getDenseI32ArrayAttr({static_cast<int32_t>(init.size()), static_cast<int32_t>(ctls.size())})); |
15408 | odsState.addAttribute(getParallelIterationsAttrName(odsState.name), odsBuilder.getIntegerAttr(odsBuilder.getIntegerType(64), parallel_iterations)); |
15409 | if (cond_attrs) { |
15410 | odsState.addAttribute(getCondAttrsAttrName(odsState.name), cond_attrs); |
15411 | } |
15412 | if (body_attrs) { |
15413 | odsState.addAttribute(getBodyAttrsAttrName(odsState.name), body_attrs); |
15414 | } |
15415 | if (cond_region_attrs) { |
15416 | odsState.addAttribute(getCondRegionAttrsAttrName(odsState.name), cond_region_attrs); |
15417 | } |
15418 | if (body_region_attrs) { |
15419 | odsState.addAttribute(getBodyRegionAttrsAttrName(odsState.name), body_region_attrs); |
15420 | } |
15421 | (void)odsState.addRegion(); |
15422 | (void)odsState.addRegion(); |
15423 | odsState.addTypes(outs); |
15424 | odsState.addTypes(ctl); |
15425 | } |
15426 | |
15427 | void WhileRegionOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange init, ::mlir::ValueRange ctls, uint64_t parallel_iterations, /*optional*/::mlir::DictionaryAttr cond_attrs, /*optional*/::mlir::DictionaryAttr body_attrs, /*optional*/::mlir::tfg::RegionAttr cond_region_attrs, /*optional*/::mlir::tfg::RegionAttr body_region_attrs) { |
15428 | odsState.addOperands(init); |
15429 | odsState.addOperands(ctls); |
15430 | odsState.addAttribute(getOperandSegmentSizesAttrName(odsState.name), odsBuilder.getDenseI32ArrayAttr({static_cast<int32_t>(init.size()), static_cast<int32_t>(ctls.size())})); |
15431 | odsState.addAttribute(getParallelIterationsAttrName(odsState.name), odsBuilder.getIntegerAttr(odsBuilder.getIntegerType(64), parallel_iterations)); |
15432 | if (cond_attrs) { |
15433 | odsState.addAttribute(getCondAttrsAttrName(odsState.name), cond_attrs); |
15434 | } |
15435 | if (body_attrs) { |
15436 | odsState.addAttribute(getBodyAttrsAttrName(odsState.name), body_attrs); |
15437 | } |
15438 | if (cond_region_attrs) { |
15439 | odsState.addAttribute(getCondRegionAttrsAttrName(odsState.name), cond_region_attrs); |
15440 | } |
15441 | if (body_region_attrs) { |
15442 | odsState.addAttribute(getBodyRegionAttrsAttrName(odsState.name), body_region_attrs); |
15443 | } |
15444 | (void)odsState.addRegion(); |
15445 | (void)odsState.addRegion(); |
15446 | assert(resultTypes.size() >= 1u && "mismatched number of results" ); |
15447 | odsState.addTypes(resultTypes); |
15448 | } |
15449 | |
15450 | void WhileRegionOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { |
15451 | odsState.addOperands(operands); |
15452 | odsState.addAttributes(attributes); |
15453 | for (unsigned i = 0; i != 2; ++i) |
15454 | (void)odsState.addRegion(); |
15455 | assert(resultTypes.size() >= 1u && "mismatched number of return types" ); |
15456 | odsState.addTypes(resultTypes); |
15457 | } |
15458 | |
15459 | ::mlir::LogicalResult WhileRegionOp::verifyInvariantsImpl() { |
15460 | auto namedAttrRange = (*this)->getAttrs(); |
15461 | auto namedAttrIt = namedAttrRange.begin(); |
15462 | ::mlir::Attribute tblgen_operand_segment_sizes; |
15463 | ::mlir::Attribute tblgen_body_attrs; |
15464 | ::mlir::Attribute tblgen_body_region_attrs; |
15465 | ::mlir::Attribute tblgen_cond_attrs; |
15466 | ::mlir::Attribute tblgen_cond_region_attrs; |
15467 | while (true) { |
15468 | if (namedAttrIt == namedAttrRange.end()) |
15469 | return emitOpError("requires attribute 'operand_segment_sizes'" ); |
15470 | if (namedAttrIt->getName() == getOperandSegmentSizesAttrName()) { |
15471 | tblgen_operand_segment_sizes = namedAttrIt->getValue(); |
15472 | break; |
15473 | } |
15474 | else if (namedAttrIt->getName() == getBodyAttrsAttrName()) { |
15475 | tblgen_body_attrs = namedAttrIt->getValue(); |
15476 | } |
15477 | else if (namedAttrIt->getName() == getBodyRegionAttrsAttrName()) { |
15478 | tblgen_body_region_attrs = namedAttrIt->getValue(); |
15479 | } |
15480 | else if (namedAttrIt->getName() == getCondAttrsAttrName()) { |
15481 | tblgen_cond_attrs = namedAttrIt->getValue(); |
15482 | } |
15483 | else if (namedAttrIt->getName() == getCondRegionAttrsAttrName()) { |
15484 | tblgen_cond_region_attrs = namedAttrIt->getValue(); |
15485 | } |
15486 | ++namedAttrIt; |
15487 | } |
15488 | ::mlir::Attribute tblgen_parallel_iterations; |
15489 | while (true) { |
15490 | if (namedAttrIt == namedAttrRange.end()) |
15491 | return emitOpError("requires attribute 'parallel_iterations'" ); |
15492 | if (namedAttrIt->getName() == getParallelIterationsAttrName()) { |
15493 | tblgen_parallel_iterations = namedAttrIt->getValue(); |
15494 | break; |
15495 | } |
15496 | ++namedAttrIt; |
15497 | } |
15498 | |
15499 | { |
15500 | auto sizeAttr = tblgen_operand_segment_sizes.cast<::mlir::DenseI32ArrayAttr>(); |
15501 | auto numElements = sizeAttr.asArrayRef().size(); |
15502 | if (numElements != 2) |
15503 | return emitOpError("'operand_segment_sizes' attribute for specifying operand segments must have 2 " |
15504 | "elements, but got " ) << numElements; |
15505 | } |
15506 | |
15507 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops18(*this, tblgen_parallel_iterations, "parallel_iterations" ))) |
15508 | return ::mlir::failure(); |
15509 | |
15510 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops6(*this, tblgen_cond_attrs, "cond_attrs" ))) |
15511 | return ::mlir::failure(); |
15512 | |
15513 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops6(*this, tblgen_body_attrs, "body_attrs" ))) |
15514 | return ::mlir::failure(); |
15515 | |
15516 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops7(*this, tblgen_cond_region_attrs, "cond_region_attrs" ))) |
15517 | return ::mlir::failure(); |
15518 | |
15519 | if (::mlir::failed(__mlir_ods_local_attr_constraint_ops7(*this, tblgen_body_region_attrs, "body_region_attrs" ))) |
15520 | return ::mlir::failure(); |
15521 | { |
15522 | unsigned index = 0; (void)index; |
15523 | auto valueGroup0 = getODSOperands(0); |
15524 | |
15525 | for (auto v : valueGroup0) { |
15526 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops2(*this, v.getType(), "operand" , index++))) |
15527 | return ::mlir::failure(); |
15528 | } |
15529 | auto valueGroup1 = getODSOperands(1); |
15530 | |
15531 | for (auto v : valueGroup1) { |
15532 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops3(*this, v.getType(), "operand" , index++))) |
15533 | return ::mlir::failure(); |
15534 | } |
15535 | } |
15536 | { |
15537 | unsigned index = 0; (void)index; |
15538 | auto valueGroup0 = getODSResults(0); |
15539 | |
15540 | for (auto v : valueGroup0) { |
15541 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops2(*this, v.getType(), "result" , index++))) |
15542 | return ::mlir::failure(); |
15543 | } |
15544 | auto valueGroup1 = getODSResults(1); |
15545 | |
15546 | for (auto v : valueGroup1) { |
15547 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops3(*this, v.getType(), "result" , index++))) |
15548 | return ::mlir::failure(); |
15549 | } |
15550 | } |
15551 | { |
15552 | unsigned index = 0; (void)index; |
15553 | |
15554 | for (auto ®ion : ::llvm::makeMutableArrayRef((*this)->getRegion(0))) |
15555 | if (::mlir::failed(__mlir_ods_local_region_constraint_ops0(*this, region, "cond_region" , index++))) |
15556 | return ::mlir::failure(); |
15557 | |
15558 | for (auto ®ion : ::llvm::makeMutableArrayRef((*this)->getRegion(1))) |
15559 | if (::mlir::failed(__mlir_ods_local_region_constraint_ops0(*this, region, "body_region" , index++))) |
15560 | return ::mlir::failure(); |
15561 | } |
15562 | return ::mlir::success(); |
15563 | } |
15564 | |
15565 | ::mlir::LogicalResult WhileRegionOp::verifyInvariants() { |
15566 | if(::mlir::succeeded(verifyInvariantsImpl()) && ::mlir::succeeded(verify())) |
15567 | return ::mlir::success(); |
15568 | return ::mlir::failure(); |
15569 | } |
15570 | |
15571 | ::mlir::ParseResult WhileRegionOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { |
15572 | ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> initOperands; |
15573 | ::llvm::SMLoc initOperandsLoc; |
15574 | (void)initOperandsLoc; |
15575 | ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> ctlsOperands; |
15576 | ::llvm::SMLoc ctlsOperandsLoc; |
15577 | (void)ctlsOperandsLoc; |
15578 | std::unique_ptr<::mlir::Region> cond_regionRegion = std::make_unique<::mlir::Region>(); |
15579 | std::unique_ptr<::mlir::Region> body_regionRegion = std::make_unique<::mlir::Region>(); |
15580 | ::llvm::ArrayRef<::mlir::Type> initTypes; |
15581 | ::llvm::ArrayRef<::mlir::Type> outsTypes; |
15582 | if (::mlir::succeeded(parser.parseOptionalLParen())) { |
15583 | |
15584 | initOperandsLoc = parser.getCurrentLocation(); |
15585 | if (parser.parseOperandList(initOperands)) |
15586 | return ::mlir::failure(); |
15587 | if (parser.parseRParen()) |
15588 | return ::mlir::failure(); |
15589 | } |
15590 | if (::mlir::succeeded(parser.parseOptionalLSquare())) { |
15591 | |
15592 | ctlsOperandsLoc = parser.getCurrentLocation(); |
15593 | if (parser.parseOperandList(ctlsOperands)) |
15594 | return ::mlir::failure(); |
15595 | if (parser.parseRSquare()) |
15596 | return ::mlir::failure(); |
15597 | } |
15598 | |
15599 | if (parser.parseRegion(*cond_regionRegion)) |
15600 | return ::mlir::failure(); |
15601 | |
15602 | if (cond_regionRegion->empty()) cond_regionRegion->emplaceBlock(); |
15603 | if (parser.parseKeyword("do" )) |
15604 | return ::mlir::failure(); |
15605 | |
15606 | if (parser.parseRegion(*body_regionRegion)) |
15607 | return ::mlir::failure(); |
15608 | |
15609 | if (body_regionRegion->empty()) body_regionRegion->emplaceBlock(); |
15610 | if (parser.parseOptionalAttrDict(result.attributes)) |
15611 | return ::mlir::failure(); |
15612 | if (::mlir::succeeded(parser.parseOptionalColon())) { |
15613 | |
15614 | ::mlir::FunctionType init__outs_functionType; |
15615 | if (parser.parseType(init__outs_functionType)) |
15616 | return ::mlir::failure(); |
15617 | initTypes = init__outs_functionType.getInputs(); |
15618 | outsTypes = init__outs_functionType.getResults(); |
15619 | } |
15620 | result.addRegion(std::move(cond_regionRegion)); |
15621 | result.addRegion(std::move(body_regionRegion)); |
15622 | result.addAttribute("operand_segment_sizes" , parser.getBuilder().getDenseI32ArrayAttr({static_cast<int32_t>(initOperands.size()), static_cast<int32_t>(ctlsOperands.size())})); |
15623 | ::mlir::Type odsBuildableType0 = parser.getBuilder().getType<::mlir::tf_type::ControlType>(); |
15624 | result.addTypes(outsTypes); |
15625 | result.addTypes(odsBuildableType0); |
15626 | if (parser.resolveOperands(initOperands, initTypes, initOperandsLoc, result.operands)) |
15627 | return ::mlir::failure(); |
15628 | if (parser.resolveOperands(ctlsOperands, odsBuildableType0, ctlsOperandsLoc, result.operands)) |
15629 | return ::mlir::failure(); |
15630 | return ::mlir::success(); |
15631 | } |
15632 | |
15633 | void WhileRegionOp::print(::mlir::OpAsmPrinter &_odsPrinter) { |
15634 | if (!getInit().empty()) { |
15635 | _odsPrinter << "(" ; |
15636 | _odsPrinter << getInit(); |
15637 | _odsPrinter << ")" ; |
15638 | } |
15639 | if (!getCtls().empty()) { |
15640 | _odsPrinter << ' ' << "[" ; |
15641 | _odsPrinter << getCtls(); |
15642 | _odsPrinter << "]" ; |
15643 | } |
15644 | _odsPrinter << ' '; |
15645 | _odsPrinter.printRegion(getCondRegion()); |
15646 | _odsPrinter << ' ' << "do" ; |
15647 | _odsPrinter << ' '; |
15648 | _odsPrinter.printRegion(getBodyRegion()); |
15649 | _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), /*elidedAttrs=*/{"operand_segment_sizes" , }); |
15650 | if (!getInit().empty()) { |
15651 | _odsPrinter << ' ' << ":" ; |
15652 | _odsPrinter << ' '; |
15653 | _odsPrinter.printFunctionalType(getInit().getTypes(), getOuts().getTypes()); |
15654 | } |
15655 | } |
15656 | |
15657 | StringRef WhileRegionOp::getDefaultDialect() { return "tfg" ; } |
15658 | void WhileRegionOp::getAsmResultNames(OpAsmSetValueNameFn setNameFn) { |
15659 | GenericGetAsmResultNames(*this, setNameFn); |
15660 | } |
15661 | |
15662 | ConditionOp WhileRegionOp::cond_condition() { |
15663 | return cast<ConditionOp>(cond_block().getTerminator()); |
15664 | } |
15665 | YieldOp WhileRegionOp::body_yield() { |
15666 | return cast<YieldOp>(body_block().getTerminator()); |
15667 | } |
15668 | |
15669 | OperandRange WhileRegionOp::getSuccessorEntryOperands( |
15670 | Optional<unsigned> index) { |
15671 | return init(); |
15672 | } |
15673 | void WhileRegionOp::getSuccessorRegions( |
15674 | Optional<unsigned> index, ArrayRef<Attribute> operands, |
15675 | SmallVectorImpl<RegionSuccessor> ®ions) { |
15676 | return GetWhileLikeRegionOpSuccessorRegions(*this, index, operands, |
15677 | regions); |
15678 | } |
15679 | |
15680 | LogicalResult WhileRegionOp::verify() { return VerifyWhileLikeRegionOp(*this); } |
15681 | |
15682 | BlockArgument WhileRegionOp::getDataValueOf(BlockArgument ctl) { |
15683 | return GetLoopRegionDataOf(ctl); |
15684 | } |
15685 | BlockArgument WhileRegionOp::getControlTokenOf(BlockArgument data) { |
15686 | return GetLoopRegionControlOf(data); |
15687 | } |
15688 | BlockArgument WhileRegionOp::getDataValue(Region ®ion, unsigned idx) { |
15689 | return GetLoopRegionDataArgs(region)[idx]; |
15690 | } |
15691 | BlockArgument WhileRegionOp::getControlToken(Region ®ion, unsigned idx) { |
15692 | return GetLoopRegionControlTokens(region)[idx]; |
15693 | } |
15694 | } // namespace tfg |
15695 | } // namespace mlir |
15696 | MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::tfg::WhileRegionOp) |
15697 | |
15698 | namespace mlir { |
15699 | namespace tfg { |
15700 | |
15701 | //===----------------------------------------------------------------------===// |
15702 | // ::mlir::tfg::YieldOp definitions |
15703 | //===----------------------------------------------------------------------===// |
15704 | |
15705 | YieldOpAdaptor::YieldOpAdaptor(::mlir::ValueRange values, ::mlir::DictionaryAttr attrs, ::mlir::RegionRange regions) : odsOperands(values), odsAttrs(attrs), odsRegions(regions) { if (odsAttrs) |
15706 | odsOpName.emplace("tfg.yield" , odsAttrs.getContext()); |
15707 | } |
15708 | |
15709 | YieldOpAdaptor::YieldOpAdaptor(YieldOp op) : odsOperands(op->getOperands()), odsAttrs(op->getAttrDictionary()), odsRegions(op->getRegions()), odsOpName(op->getName()) {} |
15710 | |
15711 | ::mlir::ValueRange YieldOpAdaptor::getOperands() { |
15712 | return odsOperands; |
15713 | } |
15714 | |
15715 | std::pair<unsigned, unsigned> YieldOpAdaptor::getODSOperandIndexAndLength(unsigned index) { |
15716 | assert(odsAttrs && "missing segment size attribute for op" ); |
15717 | auto sizeAttr = ::mlir::impl::getAttrFromSortedRange(odsAttrs.begin() + 0, odsAttrs.end() - 0, YieldOp::getOperandSegmentSizesAttrName(*odsOpName)).cast<::mlir::DenseI32ArrayAttr>(); |
15718 | |
15719 | unsigned start = 0; |
15720 | for (unsigned i = 0; i < index; ++i) |
15721 | start += sizeAttr[i]; |
15722 | return {start, sizeAttr[index]}; |
15723 | } |
15724 | |
15725 | ::mlir::ValueRange YieldOpAdaptor::getODSOperands(unsigned index) { |
15726 | auto valueRange = getODSOperandIndexAndLength(index); |
15727 | return {std::next(odsOperands.begin(), valueRange.first), |
15728 | std::next(odsOperands.begin(), valueRange.first + valueRange.second)}; |
15729 | } |
15730 | |
15731 | ::mlir::ValueRange YieldOpAdaptor::getArgs() { |
15732 | return getODSOperands(0); |
15733 | } |
15734 | |
15735 | ::mlir::ValueRange YieldOpAdaptor::args() { |
15736 | return getODSOperands(0); |
15737 | } |
15738 | |
15739 | ::mlir::ValueRange YieldOpAdaptor::getCtls() { |
15740 | return getODSOperands(1); |
15741 | } |
15742 | |
15743 | ::mlir::ValueRange YieldOpAdaptor::ctls() { |
15744 | return getODSOperands(1); |
15745 | } |
15746 | |
15747 | ::mlir::DictionaryAttr YieldOpAdaptor::getAttributes() { |
15748 | return odsAttrs; |
15749 | } |
15750 | |
15751 | ::mlir::LogicalResult YieldOpAdaptor::verify(::mlir::Location loc) { |
15752 | auto namedAttrRange = odsAttrs; |
15753 | auto namedAttrIt = namedAttrRange.begin(); |
15754 | ::mlir::Attribute tblgen_operand_segment_sizes; |
15755 | while (true) { |
15756 | if (namedAttrIt == namedAttrRange.end()) |
15757 | return emitError(loc, "'tfg.yield' op " "requires attribute 'operand_segment_sizes'" ); |
15758 | if (namedAttrIt->getName() == YieldOp::getOperandSegmentSizesAttrName(*odsOpName)) { |
15759 | tblgen_operand_segment_sizes = namedAttrIt->getValue(); |
15760 | break; |
15761 | } |
15762 | ++namedAttrIt; |
15763 | } |
15764 | |
15765 | { |
15766 | auto sizeAttr = tblgen_operand_segment_sizes.cast<::mlir::DenseI32ArrayAttr>(); |
15767 | auto numElements = sizeAttr.asArrayRef().size(); |
15768 | if (numElements != 2) |
15769 | return emitError(loc, "'tfg.yield' op " "'operand_segment_sizes' attribute for specifying operand segments must have 2 " |
15770 | "elements, but got " ) << numElements; |
15771 | } |
15772 | return ::mlir::success(); |
15773 | } |
15774 | |
15775 | std::pair<unsigned, unsigned> YieldOp::getODSOperandIndexAndLength(unsigned index) { |
15776 | auto sizeAttr = ::mlir::impl::getAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getOperandSegmentSizesAttrName()).cast<::mlir::DenseI32ArrayAttr>(); |
15777 | |
15778 | unsigned start = 0; |
15779 | for (unsigned i = 0; i < index; ++i) |
15780 | start += sizeAttr[i]; |
15781 | return {start, sizeAttr[index]}; |
15782 | } |
15783 | |
15784 | ::mlir::Operation::operand_range YieldOp::getODSOperands(unsigned index) { |
15785 | auto valueRange = getODSOperandIndexAndLength(index); |
15786 | return {std::next(getOperation()->operand_begin(), valueRange.first), |
15787 | std::next(getOperation()->operand_begin(), valueRange.first + valueRange.second)}; |
15788 | } |
15789 | |
15790 | ::mlir::Operation::operand_range YieldOp::getArgs() { |
15791 | return getODSOperands(0); |
15792 | } |
15793 | |
15794 | ::mlir::Operation::operand_range YieldOp::args() { |
15795 | return getODSOperands(0); |
15796 | } |
15797 | |
15798 | ::mlir::Operation::operand_range YieldOp::getCtls() { |
15799 | return getODSOperands(1); |
15800 | } |
15801 | |
15802 | ::mlir::Operation::operand_range YieldOp::ctls() { |
15803 | return getODSOperands(1); |
15804 | } |
15805 | |
15806 | ::mlir::MutableOperandRange YieldOp::getArgsMutable() { |
15807 | auto range = getODSOperandIndexAndLength(0); |
15808 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(0u, *::mlir::impl::getNamedAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getOperandSegmentSizesAttrName()))); |
15809 | return mutableRange; |
15810 | } |
15811 | |
15812 | ::mlir::MutableOperandRange YieldOp::argsMutable() { |
15813 | auto range = getODSOperandIndexAndLength(0); |
15814 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(0u, *::mlir::impl::getNamedAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getOperandSegmentSizesAttrName()))); |
15815 | return mutableRange; |
15816 | } |
15817 | |
15818 | ::mlir::MutableOperandRange YieldOp::getCtlsMutable() { |
15819 | auto range = getODSOperandIndexAndLength(1); |
15820 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(1u, *::mlir::impl::getNamedAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getOperandSegmentSizesAttrName()))); |
15821 | return mutableRange; |
15822 | } |
15823 | |
15824 | ::mlir::MutableOperandRange YieldOp::ctlsMutable() { |
15825 | auto range = getODSOperandIndexAndLength(1); |
15826 | auto mutableRange = ::mlir::MutableOperandRange(getOperation(), range.first, range.second, ::mlir::MutableOperandRange::OperandSegment(1u, *::mlir::impl::getNamedAttrFromSortedRange((*this)->getAttrs().begin() + 0, (*this)->getAttrs().end() - 0, getOperandSegmentSizesAttrName()))); |
15827 | return mutableRange; |
15828 | } |
15829 | |
15830 | std::pair<unsigned, unsigned> YieldOp::getODSResultIndexAndLength(unsigned index) { |
15831 | return {index, 1}; |
15832 | } |
15833 | |
15834 | ::mlir::Operation::result_range YieldOp::getODSResults(unsigned index) { |
15835 | auto valueRange = getODSResultIndexAndLength(index); |
15836 | return {std::next(getOperation()->result_begin(), valueRange.first), |
15837 | std::next(getOperation()->result_begin(), valueRange.first + valueRange.second)}; |
15838 | } |
15839 | |
15840 | void YieldOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::ValueRange args, ::mlir::ValueRange ctls) { |
15841 | odsState.addOperands(args); |
15842 | odsState.addOperands(ctls); |
15843 | odsState.addAttribute(getOperandSegmentSizesAttrName(odsState.name), odsBuilder.getDenseI32ArrayAttr({static_cast<int32_t>(args.size()), static_cast<int32_t>(ctls.size())})); |
15844 | } |
15845 | |
15846 | void YieldOp::build(::mlir::OpBuilder &odsBuilder, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange args, ::mlir::ValueRange ctls) { |
15847 | odsState.addOperands(args); |
15848 | odsState.addOperands(ctls); |
15849 | odsState.addAttribute(getOperandSegmentSizesAttrName(odsState.name), odsBuilder.getDenseI32ArrayAttr({static_cast<int32_t>(args.size()), static_cast<int32_t>(ctls.size())})); |
15850 | assert(resultTypes.size() == 0u && "mismatched number of results" ); |
15851 | odsState.addTypes(resultTypes); |
15852 | } |
15853 | |
15854 | void YieldOp::build(::mlir::OpBuilder &, ::mlir::OperationState &odsState, ::mlir::TypeRange resultTypes, ::mlir::ValueRange operands, ::llvm::ArrayRef<::mlir::NamedAttribute> attributes) { |
15855 | odsState.addOperands(operands); |
15856 | odsState.addAttributes(attributes); |
15857 | assert(resultTypes.size() == 0u && "mismatched number of return types" ); |
15858 | odsState.addTypes(resultTypes); |
15859 | } |
15860 | |
15861 | ::mlir::LogicalResult YieldOp::verifyInvariantsImpl() { |
15862 | auto namedAttrRange = (*this)->getAttrs(); |
15863 | auto namedAttrIt = namedAttrRange.begin(); |
15864 | ::mlir::Attribute tblgen_operand_segment_sizes; |
15865 | while (true) { |
15866 | if (namedAttrIt == namedAttrRange.end()) |
15867 | return emitOpError("requires attribute 'operand_segment_sizes'" ); |
15868 | if (namedAttrIt->getName() == getOperandSegmentSizesAttrName()) { |
15869 | tblgen_operand_segment_sizes = namedAttrIt->getValue(); |
15870 | break; |
15871 | } |
15872 | ++namedAttrIt; |
15873 | } |
15874 | |
15875 | { |
15876 | auto sizeAttr = tblgen_operand_segment_sizes.cast<::mlir::DenseI32ArrayAttr>(); |
15877 | auto numElements = sizeAttr.asArrayRef().size(); |
15878 | if (numElements != 2) |
15879 | return emitOpError("'operand_segment_sizes' attribute for specifying operand segments must have 2 " |
15880 | "elements, but got " ) << numElements; |
15881 | } |
15882 | { |
15883 | unsigned index = 0; (void)index; |
15884 | auto valueGroup0 = getODSOperands(0); |
15885 | |
15886 | for (auto v : valueGroup0) { |
15887 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops2(*this, v.getType(), "operand" , index++))) |
15888 | return ::mlir::failure(); |
15889 | } |
15890 | auto valueGroup1 = getODSOperands(1); |
15891 | |
15892 | for (auto v : valueGroup1) { |
15893 | if (::mlir::failed(__mlir_ods_local_type_constraint_ops3(*this, v.getType(), "operand" , index++))) |
15894 | return ::mlir::failure(); |
15895 | } |
15896 | } |
15897 | return ::mlir::success(); |
15898 | } |
15899 | |
15900 | ::mlir::LogicalResult YieldOp::verifyInvariants() { |
15901 | return verifyInvariantsImpl(); |
15902 | } |
15903 | |
15904 | ::mlir::ParseResult YieldOp::parse(::mlir::OpAsmParser &parser, ::mlir::OperationState &result) { |
15905 | ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> argsOperands; |
15906 | ::llvm::SMLoc argsOperandsLoc; |
15907 | (void)argsOperandsLoc; |
15908 | ::llvm::SmallVector<::mlir::OpAsmParser::UnresolvedOperand, 4> ctlsOperands; |
15909 | ::llvm::SMLoc ctlsOperandsLoc; |
15910 | (void)ctlsOperandsLoc; |
15911 | ::llvm::SmallVector<::mlir::Type, 1> argsTypes; |
15912 | if (::mlir::succeeded(parser.parseOptionalLParen())) { |
15913 | |
15914 | argsOperandsLoc = parser.getCurrentLocation(); |
15915 | if (parser.parseOperandList(argsOperands)) |
15916 | return ::mlir::failure(); |
15917 | if (parser.parseRParen()) |
15918 | return ::mlir::failure(); |
15919 | } |
15920 | if (::mlir::succeeded(parser.parseOptionalLSquare())) { |
15921 | |
15922 | ctlsOperandsLoc = parser.getCurrentLocation(); |
15923 | if (parser.parseOperandList(ctlsOperands)) |
15924 | return ::mlir::failure(); |
15925 | if (parser.parseRSquare()) |
15926 | return ::mlir::failure(); |
15927 | } |
15928 | if (parser.parseOptionalAttrDict(result.attributes)) |
15929 | return ::mlir::failure(); |
15930 | if (::mlir::succeeded(parser.parseOptionalColon())) { |
15931 | |
15932 | if (parser.parseTypeList(argsTypes)) |
15933 | return ::mlir::failure(); |
15934 | } |
15935 | result.addAttribute("operand_segment_sizes" , parser.getBuilder().getDenseI32ArrayAttr({static_cast<int32_t>(argsOperands.size()), static_cast<int32_t>(ctlsOperands.size())})); |
15936 | ::mlir::Type odsBuildableType0 = parser.getBuilder().getType<::mlir::tf_type::ControlType>(); |
15937 | if (parser.resolveOperands(argsOperands, argsTypes, argsOperandsLoc, result.operands)) |
15938 | return ::mlir::failure(); |
15939 | if (parser.resolveOperands(ctlsOperands, odsBuildableType0, ctlsOperandsLoc, result.operands)) |
15940 | return ::mlir::failure(); |
15941 | return ::mlir::success(); |
15942 | } |
15943 | |
15944 | void YieldOp::print(::mlir::OpAsmPrinter &_odsPrinter) { |
15945 | if (!getArgs().empty()) { |
15946 | _odsPrinter << "(" ; |
15947 | _odsPrinter << getArgs(); |
15948 | _odsPrinter << ")" ; |
15949 | } |
15950 | if (!getCtls().empty()) { |
15951 | _odsPrinter << ' ' << "[" ; |
15952 | _odsPrinter << getCtls(); |
15953 | _odsPrinter << "]" ; |
15954 | } |
15955 | _odsPrinter.printOptionalAttrDict((*this)->getAttrs(), /*elidedAttrs=*/{"operand_segment_sizes" , }); |
15956 | if (!getArgs().empty()) { |
15957 | _odsPrinter << ' ' << ":" ; |
15958 | _odsPrinter << ' '; |
15959 | _odsPrinter << getArgs().getTypes(); |
15960 | } |
15961 | } |
15962 | |
15963 | void YieldOp::getEffects(::llvm::SmallVectorImpl<::mlir::SideEffects::EffectInstance<::mlir::MemoryEffects::Effect>> &effects) { |
15964 | } |
15965 | |
15966 | } // namespace tfg |
15967 | } // namespace mlir |
15968 | MLIR_DEFINE_EXPLICIT_TYPE_ID(::mlir::tfg::YieldOp) |
15969 | |
15970 | |
15971 | #endif // GET_OP_CLASSES |
15972 | |
15973 | |