Bug Summary

File:build/source/build-llvm/tools/clang/stage2-bins/tools/mlir/include/mlir/Dialect/Tosa/IR/TosaAttributes.cpp.inc
Warning:line 294, column 5
Value stored to '_firstPrinted' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name TosaOps.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -analyzer-config-compatibility-mode=true -mrelocation-model pic -pic-level 2 -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -ffunction-sections -fdata-sections -fcoverage-compilation-dir=/build/source/build-llvm/tools/clang/stage2-bins -resource-dir /usr/lib/llvm-17/lib/clang/17 -D MLIR_CUDA_CONVERSIONS_ENABLED=1 -D MLIR_ROCM_CONVERSIONS_ENABLED=1 -D _DEBUG -D _GLIBCXX_ASSERTIONS -D _GNU_SOURCE -D _LIBCPP_ENABLE_ASSERTIONS -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I tools/mlir/lib/Dialect/Tosa -I /build/source/mlir/lib/Dialect/Tosa -I include -I /build/source/llvm/include -I /build/source/mlir/include -I tools/mlir/include -D _FORTIFY_SOURCE=2 -D NDEBUG -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/x86_64-linux-gnu/c++/10 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../include/c++/10/backward -internal-isystem /usr/lib/llvm-17/lib/clang/17/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fmacro-prefix-map=/build/source/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fmacro-prefix-map=/build/source/= -fcoverage-prefix-map=/build/source/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fcoverage-prefix-map=/build/source/= -source-date-epoch 1683717183 -O2 -Wno-unused-command-line-argument -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wno-comment -Wno-misleading-indentation -std=c++17 -fdeprecated-macro -fdebug-compilation-dir=/build/source/build-llvm/tools/clang/stage2-bins -fdebug-prefix-map=/build/source/build-llvm/tools/clang/stage2-bins=build-llvm/tools/clang/stage2-bins -fdebug-prefix-map=/build/source/= -ferror-limit 19 -fvisibility-inlines-hidden -stack-protector 2 -fgnuc-version=4.2.1 -fcolor-diagnostics -vectorize-loops -vectorize-slp -analyzer-output=html -analyzer-config stable-report-filename=true -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2023-05-10-133810-16478-1 -x c++ /build/source/mlir/lib/Dialect/Tosa/IR/TosaOps.cpp
1/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
2|* *|
3|* AttrDef Definitions *|
4|* *|
5|* Automatically generated file, do not edit! *|
6|* *|
7\*===----------------------------------------------------------------------===*/
8
9#ifdef GET_ATTRDEF_LIST
10#undef GET_ATTRDEF_LIST
11
12mlir::tosa::ConvOpQuantizationAttr,
13mlir::tosa::MatMulOpQuantizationAttr,
14mlir::tosa::PadOpQuantizationAttr,
15mlir::tosa::UnaryOpQuantizationAttr
16
17#endif // GET_ATTRDEF_LIST
18
19#ifdef GET_ATTRDEF_CLASSES
20#undef GET_ATTRDEF_CLASSES
21
22static ::mlir::OptionalParseResult generatedAttributeParser(::mlir::AsmParser &parser, ::llvm::StringRef *mnemonic, ::mlir::Type type, ::mlir::Attribute &value) {
23 return ::mlir::AsmParser::KeywordSwitch<::mlir::OptionalParseResult>(parser)
24 .Case(mlir::tosa::ConvOpQuantizationAttr::getMnemonic(), [&](llvm::StringRef, llvm::SMLoc) {
25 value = mlir::tosa::ConvOpQuantizationAttr::parse(parser, type);
26 return ::mlir::success(!!value);
27 })
28 .Case(mlir::tosa::MatMulOpQuantizationAttr::getMnemonic(), [&](llvm::StringRef, llvm::SMLoc) {
29 value = mlir::tosa::MatMulOpQuantizationAttr::parse(parser, type);
30 return ::mlir::success(!!value);
31 })
32 .Case(mlir::tosa::PadOpQuantizationAttr::getMnemonic(), [&](llvm::StringRef, llvm::SMLoc) {
33 value = mlir::tosa::PadOpQuantizationAttr::parse(parser, type);
34 return ::mlir::success(!!value);
35 })
36 .Case(mlir::tosa::UnaryOpQuantizationAttr::getMnemonic(), [&](llvm::StringRef, llvm::SMLoc) {
37 value = mlir::tosa::UnaryOpQuantizationAttr::parse(parser, type);
38 return ::mlir::success(!!value);
39 })
40 .Default([&](llvm::StringRef keyword, llvm::SMLoc) {
41 *mnemonic = keyword;
42 return std::nullopt;
43 });
44}
45
46static ::mlir::LogicalResult generatedAttributePrinter(::mlir::Attribute def, ::mlir::AsmPrinter &printer) {
47 return ::llvm::TypeSwitch<::mlir::Attribute, ::mlir::LogicalResult>(def) .Case<mlir::tosa::ConvOpQuantizationAttr>([&](auto t) {
48 printer << mlir::tosa::ConvOpQuantizationAttr::getMnemonic();
49t.print(printer);
50 return ::mlir::success();
51 })
52 .Case<mlir::tosa::MatMulOpQuantizationAttr>([&](auto t) {
53 printer << mlir::tosa::MatMulOpQuantizationAttr::getMnemonic();
54t.print(printer);
55 return ::mlir::success();
56 })
57 .Case<mlir::tosa::PadOpQuantizationAttr>([&](auto t) {
58 printer << mlir::tosa::PadOpQuantizationAttr::getMnemonic();
59t.print(printer);
60 return ::mlir::success();
61 })
62 .Case<mlir::tosa::UnaryOpQuantizationAttr>([&](auto t) {
63 printer << mlir::tosa::UnaryOpQuantizationAttr::getMnemonic();
64t.print(printer);
65 return ::mlir::success();
66 })
67 .Default([](auto) { return ::mlir::failure(); });
68}
69
70namespace mlir {
71namespace tosa {
72namespace detail {
73struct ConvOpQuantizationAttrStorage : public ::mlir::AttributeStorage {
74 using KeyTy = std::tuple<int64_t, int64_t>;
75 ConvOpQuantizationAttrStorage(int64_t input_zp, int64_t weight_zp) : input_zp(input_zp), weight_zp(weight_zp) {}
76
77 KeyTy getAsKey() const {
78 return KeyTy(input_zp, weight_zp);
79 }
80
81 bool operator==(const KeyTy &tblgenKey) const {
82 return (input_zp == std::get<0>(tblgenKey)) && (weight_zp == std::get<1>(tblgenKey));
83 }
84
85 static ::llvm::hash_code hashKey(const KeyTy &tblgenKey) {
86 return ::llvm::hash_combine(std::get<0>(tblgenKey), std::get<1>(tblgenKey));
87 }
88
89 static ConvOpQuantizationAttrStorage *construct(::mlir::AttributeStorageAllocator &allocator, const KeyTy &tblgenKey) {
90 auto input_zp = std::get<0>(tblgenKey);
91 auto weight_zp = std::get<1>(tblgenKey);
92 return new (allocator.allocate<ConvOpQuantizationAttrStorage>()) ConvOpQuantizationAttrStorage(input_zp, weight_zp);
93 }
94
95 int64_t input_zp;
96 int64_t weight_zp;
97};
98} // namespace detail
99ConvOpQuantizationAttr ConvOpQuantizationAttr::get(::mlir::MLIRContext *context, int64_t input_zp, int64_t weight_zp) {
100 return Base::get(context, input_zp, weight_zp);
101}
102
103::mlir::Attribute ConvOpQuantizationAttr::parse(::mlir::AsmParser &odsParser, ::mlir::Type odsType) {
104 ::mlir::Builder odsBuilder(odsParser.getContext());
105 ::llvm::SMLoc odsLoc = odsParser.getCurrentLocation();
106 (void) odsLoc;
107 ::mlir::FailureOr<int64_t> _result_input_zp;
108 ::mlir::FailureOr<int64_t> _result_weight_zp;
109 // Parse literal '<'
110 if (odsParser.parseLess()) return {};
111 // Parse parameter struct
112 bool _seen_input_zp = false;
113 bool _seen_weight_zp = false;
114 {
115 const auto _loop_body = [&](::llvm::StringRef _paramKey) -> bool {
116 // Parse literal '='
117 if (odsParser.parseEqual()) return {};
118 if (!_seen_input_zp && _paramKey == "input_zp") {
119 _seen_input_zp = true;
120
121 // Parse variable 'input_zp'
122 _result_input_zp = ::mlir::FieldParser<int64_t>::parse(odsParser);
123 if (::mlir::failed(_result_input_zp)) {
124 odsParser.emitError(odsParser.getCurrentLocation(), "failed to parse Tosa_ConvOpQuantizationAttr parameter 'input_zp' which is to be a `int64_t`");
125 return {};
126 }
127 } else if (!_seen_weight_zp && _paramKey == "weight_zp") {
128 _seen_weight_zp = true;
129
130 // Parse variable 'weight_zp'
131 _result_weight_zp = ::mlir::FieldParser<int64_t>::parse(odsParser);
132 if (::mlir::failed(_result_weight_zp)) {
133 odsParser.emitError(odsParser.getCurrentLocation(), "failed to parse Tosa_ConvOpQuantizationAttr parameter 'weight_zp' which is to be a `int64_t`");
134 return {};
135 }
136 } else {
137 odsParser.emitError(odsParser.getCurrentLocation(), "duplicate or unknown struct parameter name: ") << _paramKey;
138 return {};
139 }
140 return true;
141 };
142 for (unsigned odsStructIndex = 0; odsStructIndex < 2; ++odsStructIndex) {
143 ::llvm::StringRef _paramKey;
144 if (odsParser.parseKeyword(&_paramKey)) {
145 odsParser.emitError(odsParser.getCurrentLocation(),
146 "expected a parameter name in struct");
147 return {};
148 }
149 if (!_loop_body(_paramKey)) return {};
150 if ((odsStructIndex != 2 - 1) && odsParser.parseComma())
151 return {};
152 }
153 }
154 // Parse literal '>'
155 if (odsParser.parseGreater()) return {};
156 assert(::mlir::succeeded(_result_input_zp))(static_cast <bool> (::mlir::succeeded(_result_input_zp
)) ? void (0) : __assert_fail ("::mlir::succeeded(_result_input_zp)"
, "tools/mlir/include/mlir/Dialect/Tosa/IR/TosaAttributes.cpp.inc"
, 156, __extension__ __PRETTY_FUNCTION__))
;
157 assert(::mlir::succeeded(_result_weight_zp))(static_cast <bool> (::mlir::succeeded(_result_weight_zp
)) ? void (0) : __assert_fail ("::mlir::succeeded(_result_weight_zp)"
, "tools/mlir/include/mlir/Dialect/Tosa/IR/TosaAttributes.cpp.inc"
, 157, __extension__ __PRETTY_FUNCTION__))
;
158 return ConvOpQuantizationAttr::get(odsParser.getContext(),
159 int64_t((*_result_input_zp)),
160 int64_t((*_result_weight_zp)));
161}
162
163void ConvOpQuantizationAttr::print(::mlir::AsmPrinter &odsPrinter) const {
164 ::mlir::Builder odsBuilder(getContext());
165 odsPrinter << "<";
166 {
167 bool _firstPrinted = true;
168 if (!_firstPrinted) odsPrinter << ", ";
169 _firstPrinted = false;
170 odsPrinter << "input_zp = ";
171 odsPrinter.printStrippedAttrOrType(getInputZp());
172 if (!_firstPrinted) odsPrinter << ", ";
173 _firstPrinted = false;
174 odsPrinter << "weight_zp = ";
175 odsPrinter.printStrippedAttrOrType(getWeightZp());
176 }
177 odsPrinter << ">";
178}
179
180int64_t ConvOpQuantizationAttr::getInputZp() const {
181 return getImpl()->input_zp;
182}
183
184int64_t ConvOpQuantizationAttr::getWeightZp() const {
185 return getImpl()->weight_zp;
186}
187
188} // namespace tosa
189} // namespace mlir
190MLIR_DEFINE_EXPLICIT_TYPE_ID(mlir::tosa::ConvOpQuantizationAttr)namespace mlir { namespace detail { SelfOwningTypeID TypeIDResolver
<mlir::tosa::ConvOpQuantizationAttr>::id = {}; } }
191namespace mlir {
192namespace tosa {
193namespace detail {
194struct MatMulOpQuantizationAttrStorage : public ::mlir::AttributeStorage {
195 using KeyTy = std::tuple<int64_t, int64_t>;
196 MatMulOpQuantizationAttrStorage(int64_t a_zp, int64_t b_zp) : a_zp(a_zp), b_zp(b_zp) {}
197
198 KeyTy getAsKey() const {
199 return KeyTy(a_zp, b_zp);
200 }
201
202 bool operator==(const KeyTy &tblgenKey) const {
203 return (a_zp == std::get<0>(tblgenKey)) && (b_zp == std::get<1>(tblgenKey));
204 }
205
206 static ::llvm::hash_code hashKey(const KeyTy &tblgenKey) {
207 return ::llvm::hash_combine(std::get<0>(tblgenKey), std::get<1>(tblgenKey));
208 }
209
210 static MatMulOpQuantizationAttrStorage *construct(::mlir::AttributeStorageAllocator &allocator, const KeyTy &tblgenKey) {
211 auto a_zp = std::get<0>(tblgenKey);
212 auto b_zp = std::get<1>(tblgenKey);
213 return new (allocator.allocate<MatMulOpQuantizationAttrStorage>()) MatMulOpQuantizationAttrStorage(a_zp, b_zp);
214 }
215
216 int64_t a_zp;
217 int64_t b_zp;
218};
219} // namespace detail
220MatMulOpQuantizationAttr MatMulOpQuantizationAttr::get(::mlir::MLIRContext *context, int64_t a_zp, int64_t b_zp) {
221 return Base::get(context, a_zp, b_zp);
222}
223
224::mlir::Attribute MatMulOpQuantizationAttr::parse(::mlir::AsmParser &odsParser, ::mlir::Type odsType) {
225 ::mlir::Builder odsBuilder(odsParser.getContext());
226 ::llvm::SMLoc odsLoc = odsParser.getCurrentLocation();
227 (void) odsLoc;
228 ::mlir::FailureOr<int64_t> _result_a_zp;
229 ::mlir::FailureOr<int64_t> _result_b_zp;
230 // Parse literal '<'
231 if (odsParser.parseLess()) return {};
232 // Parse parameter struct
233 bool _seen_a_zp = false;
234 bool _seen_b_zp = false;
235 {
236 const auto _loop_body = [&](::llvm::StringRef _paramKey) -> bool {
237 // Parse literal '='
238 if (odsParser.parseEqual()) return {};
239 if (!_seen_a_zp && _paramKey == "a_zp") {
240 _seen_a_zp = true;
241
242 // Parse variable 'a_zp'
243 _result_a_zp = ::mlir::FieldParser<int64_t>::parse(odsParser);
244 if (::mlir::failed(_result_a_zp)) {
245 odsParser.emitError(odsParser.getCurrentLocation(), "failed to parse Tosa_MatMulOpQuantizationAttr parameter 'a_zp' which is to be a `int64_t`");
246 return {};
247 }
248 } else if (!_seen_b_zp && _paramKey == "b_zp") {
249 _seen_b_zp = true;
250
251 // Parse variable 'b_zp'
252 _result_b_zp = ::mlir::FieldParser<int64_t>::parse(odsParser);
253 if (::mlir::failed(_result_b_zp)) {
254 odsParser.emitError(odsParser.getCurrentLocation(), "failed to parse Tosa_MatMulOpQuantizationAttr parameter 'b_zp' which is to be a `int64_t`");
255 return {};
256 }
257 } else {
258 odsParser.emitError(odsParser.getCurrentLocation(), "duplicate or unknown struct parameter name: ") << _paramKey;
259 return {};
260 }
261 return true;
262 };
263 for (unsigned odsStructIndex = 0; odsStructIndex < 2; ++odsStructIndex) {
264 ::llvm::StringRef _paramKey;
265 if (odsParser.parseKeyword(&_paramKey)) {
266 odsParser.emitError(odsParser.getCurrentLocation(),
267 "expected a parameter name in struct");
268 return {};
269 }
270 if (!_loop_body(_paramKey)) return {};
271 if ((odsStructIndex != 2 - 1) && odsParser.parseComma())
272 return {};
273 }
274 }
275 // Parse literal '>'
276 if (odsParser.parseGreater()) return {};
277 assert(::mlir::succeeded(_result_a_zp))(static_cast <bool> (::mlir::succeeded(_result_a_zp)) ?
void (0) : __assert_fail ("::mlir::succeeded(_result_a_zp)",
"tools/mlir/include/mlir/Dialect/Tosa/IR/TosaAttributes.cpp.inc"
, 277, __extension__ __PRETTY_FUNCTION__))
;
278 assert(::mlir::succeeded(_result_b_zp))(static_cast <bool> (::mlir::succeeded(_result_b_zp)) ?
void (0) : __assert_fail ("::mlir::succeeded(_result_b_zp)",
"tools/mlir/include/mlir/Dialect/Tosa/IR/TosaAttributes.cpp.inc"
, 278, __extension__ __PRETTY_FUNCTION__))
;
279 return MatMulOpQuantizationAttr::get(odsParser.getContext(),
280 int64_t((*_result_a_zp)),
281 int64_t((*_result_b_zp)));
282}
283
284void MatMulOpQuantizationAttr::print(::mlir::AsmPrinter &odsPrinter) const {
285 ::mlir::Builder odsBuilder(getContext());
286 odsPrinter << "<";
287 {
288 bool _firstPrinted = true;
289 if (!_firstPrinted) odsPrinter << ", ";
290 _firstPrinted = false;
291 odsPrinter << "a_zp = ";
292 odsPrinter.printStrippedAttrOrType(getAZp());
293 if (!_firstPrinted) odsPrinter << ", ";
294 _firstPrinted = false;
Value stored to '_firstPrinted' is never read
295 odsPrinter << "b_zp = ";
296 odsPrinter.printStrippedAttrOrType(getBZp());
297 }
298 odsPrinter << ">";
299}
300
301int64_t MatMulOpQuantizationAttr::getAZp() const {
302 return getImpl()->a_zp;
303}
304
305int64_t MatMulOpQuantizationAttr::getBZp() const {
306 return getImpl()->b_zp;
307}
308
309} // namespace tosa
310} // namespace mlir
311MLIR_DEFINE_EXPLICIT_TYPE_ID(mlir::tosa::MatMulOpQuantizationAttr)namespace mlir { namespace detail { SelfOwningTypeID TypeIDResolver
<mlir::tosa::MatMulOpQuantizationAttr>::id = {}; } }
312namespace mlir {
313namespace tosa {
314namespace detail {
315struct PadOpQuantizationAttrStorage : public ::mlir::AttributeStorage {
316 using KeyTy = std::tuple<int64_t>;
317 PadOpQuantizationAttrStorage(int64_t input_zp) : input_zp(input_zp) {}
318
319 KeyTy getAsKey() const {
320 return KeyTy(input_zp);
321 }
322
323 bool operator==(const KeyTy &tblgenKey) const {
324 return (input_zp == std::get<0>(tblgenKey));
325 }
326
327 static ::llvm::hash_code hashKey(const KeyTy &tblgenKey) {
328 return ::llvm::hash_combine(std::get<0>(tblgenKey));
329 }
330
331 static PadOpQuantizationAttrStorage *construct(::mlir::AttributeStorageAllocator &allocator, const KeyTy &tblgenKey) {
332 auto input_zp = std::get<0>(tblgenKey);
333 return new (allocator.allocate<PadOpQuantizationAttrStorage>()) PadOpQuantizationAttrStorage(input_zp);
334 }
335
336 int64_t input_zp;
337};
338} // namespace detail
339PadOpQuantizationAttr PadOpQuantizationAttr::get(::mlir::MLIRContext *context, int64_t input_zp) {
340 return Base::get(context, input_zp);
341}
342
343::mlir::Attribute PadOpQuantizationAttr::parse(::mlir::AsmParser &odsParser, ::mlir::Type odsType) {
344 ::mlir::Builder odsBuilder(odsParser.getContext());
345 ::llvm::SMLoc odsLoc = odsParser.getCurrentLocation();
346 (void) odsLoc;
347 ::mlir::FailureOr<int64_t> _result_input_zp;
348 // Parse literal '<'
349 if (odsParser.parseLess()) return {};
350 // Parse parameter struct
351 bool _seen_input_zp = false;
352 {
353 const auto _loop_body = [&](::llvm::StringRef _paramKey) -> bool {
354 // Parse literal '='
355 if (odsParser.parseEqual()) return {};
356 if (!_seen_input_zp && _paramKey == "input_zp") {
357 _seen_input_zp = true;
358
359 // Parse variable 'input_zp'
360 _result_input_zp = ::mlir::FieldParser<int64_t>::parse(odsParser);
361 if (::mlir::failed(_result_input_zp)) {
362 odsParser.emitError(odsParser.getCurrentLocation(), "failed to parse Tosa_PadOpQuantizationAttr parameter 'input_zp' which is to be a `int64_t`");
363 return {};
364 }
365 } else {
366 odsParser.emitError(odsParser.getCurrentLocation(), "duplicate or unknown struct parameter name: ") << _paramKey;
367 return {};
368 }
369 return true;
370 };
371 for (unsigned odsStructIndex = 0; odsStructIndex < 1; ++odsStructIndex) {
372 ::llvm::StringRef _paramKey;
373 if (odsParser.parseKeyword(&_paramKey)) {
374 odsParser.emitError(odsParser.getCurrentLocation(),
375 "expected a parameter name in struct");
376 return {};
377 }
378 if (!_loop_body(_paramKey)) return {};
379 if ((odsStructIndex != 1 - 1) && odsParser.parseComma())
380 return {};
381 }
382 }
383 // Parse literal '>'
384 if (odsParser.parseGreater()) return {};
385 assert(::mlir::succeeded(_result_input_zp))(static_cast <bool> (::mlir::succeeded(_result_input_zp
)) ? void (0) : __assert_fail ("::mlir::succeeded(_result_input_zp)"
, "tools/mlir/include/mlir/Dialect/Tosa/IR/TosaAttributes.cpp.inc"
, 385, __extension__ __PRETTY_FUNCTION__))
;
386 return PadOpQuantizationAttr::get(odsParser.getContext(),
387 int64_t((*_result_input_zp)));
388}
389
390void PadOpQuantizationAttr::print(::mlir::AsmPrinter &odsPrinter) const {
391 ::mlir::Builder odsBuilder(getContext());
392 odsPrinter << "<";
393 {
394 bool _firstPrinted = true;
395 if (!_firstPrinted) odsPrinter << ", ";
396 _firstPrinted = false;
397 odsPrinter << "input_zp = ";
398 odsPrinter.printStrippedAttrOrType(getInputZp());
399 }
400 odsPrinter << ">";
401}
402
403int64_t PadOpQuantizationAttr::getInputZp() const {
404 return getImpl()->input_zp;
405}
406
407} // namespace tosa
408} // namespace mlir
409MLIR_DEFINE_EXPLICIT_TYPE_ID(mlir::tosa::PadOpQuantizationAttr)namespace mlir { namespace detail { SelfOwningTypeID TypeIDResolver
<mlir::tosa::PadOpQuantizationAttr>::id = {}; } }
410namespace mlir {
411namespace tosa {
412namespace detail {
413struct UnaryOpQuantizationAttrStorage : public ::mlir::AttributeStorage {
414 using KeyTy = std::tuple<int64_t, int64_t>;
415 UnaryOpQuantizationAttrStorage(int64_t input_zp, int64_t output_zp) : input_zp(input_zp), output_zp(output_zp) {}
416
417 KeyTy getAsKey() const {
418 return KeyTy(input_zp, output_zp);
419 }
420
421 bool operator==(const KeyTy &tblgenKey) const {
422 return (input_zp == std::get<0>(tblgenKey)) && (output_zp == std::get<1>(tblgenKey));
423 }
424
425 static ::llvm::hash_code hashKey(const KeyTy &tblgenKey) {
426 return ::llvm::hash_combine(std::get<0>(tblgenKey), std::get<1>(tblgenKey));
427 }
428
429 static UnaryOpQuantizationAttrStorage *construct(::mlir::AttributeStorageAllocator &allocator, const KeyTy &tblgenKey) {
430 auto input_zp = std::get<0>(tblgenKey);
431 auto output_zp = std::get<1>(tblgenKey);
432 return new (allocator.allocate<UnaryOpQuantizationAttrStorage>()) UnaryOpQuantizationAttrStorage(input_zp, output_zp);
433 }
434
435 int64_t input_zp;
436 int64_t output_zp;
437};
438} // namespace detail
439UnaryOpQuantizationAttr UnaryOpQuantizationAttr::get(::mlir::MLIRContext *context, int64_t input_zp, int64_t output_zp) {
440 return Base::get(context, input_zp, output_zp);
441}
442
443::mlir::Attribute UnaryOpQuantizationAttr::parse(::mlir::AsmParser &odsParser, ::mlir::Type odsType) {
444 ::mlir::Builder odsBuilder(odsParser.getContext());
445 ::llvm::SMLoc odsLoc = odsParser.getCurrentLocation();
446 (void) odsLoc;
447 ::mlir::FailureOr<int64_t> _result_input_zp;
448 ::mlir::FailureOr<int64_t> _result_output_zp;
449 // Parse literal '<'
450 if (odsParser.parseLess()) return {};
451 // Parse parameter struct
452 bool _seen_input_zp = false;
453 bool _seen_output_zp = false;
454 {
455 const auto _loop_body = [&](::llvm::StringRef _paramKey) -> bool {
456 // Parse literal '='
457 if (odsParser.parseEqual()) return {};
458 if (!_seen_input_zp && _paramKey == "input_zp") {
459 _seen_input_zp = true;
460
461 // Parse variable 'input_zp'
462 _result_input_zp = ::mlir::FieldParser<int64_t>::parse(odsParser);
463 if (::mlir::failed(_result_input_zp)) {
464 odsParser.emitError(odsParser.getCurrentLocation(), "failed to parse Tosa_UnaryOpQuantizationAttr parameter 'input_zp' which is to be a `int64_t`");
465 return {};
466 }
467 } else if (!_seen_output_zp && _paramKey == "output_zp") {
468 _seen_output_zp = true;
469
470 // Parse variable 'output_zp'
471 _result_output_zp = ::mlir::FieldParser<int64_t>::parse(odsParser);
472 if (::mlir::failed(_result_output_zp)) {
473 odsParser.emitError(odsParser.getCurrentLocation(), "failed to parse Tosa_UnaryOpQuantizationAttr parameter 'output_zp' which is to be a `int64_t`");
474 return {};
475 }
476 } else {
477 odsParser.emitError(odsParser.getCurrentLocation(), "duplicate or unknown struct parameter name: ") << _paramKey;
478 return {};
479 }
480 return true;
481 };
482 for (unsigned odsStructIndex = 0; odsStructIndex < 2; ++odsStructIndex) {
483 ::llvm::StringRef _paramKey;
484 if (odsParser.parseKeyword(&_paramKey)) {
485 odsParser.emitError(odsParser.getCurrentLocation(),
486 "expected a parameter name in struct");
487 return {};
488 }
489 if (!_loop_body(_paramKey)) return {};
490 if ((odsStructIndex != 2 - 1) && odsParser.parseComma())
491 return {};
492 }
493 }
494 // Parse literal '>'
495 if (odsParser.parseGreater()) return {};
496 assert(::mlir::succeeded(_result_input_zp))(static_cast <bool> (::mlir::succeeded(_result_input_zp
)) ? void (0) : __assert_fail ("::mlir::succeeded(_result_input_zp)"
, "tools/mlir/include/mlir/Dialect/Tosa/IR/TosaAttributes.cpp.inc"
, 496, __extension__ __PRETTY_FUNCTION__))
;
497 assert(::mlir::succeeded(_result_output_zp))(static_cast <bool> (::mlir::succeeded(_result_output_zp
)) ? void (0) : __assert_fail ("::mlir::succeeded(_result_output_zp)"
, "tools/mlir/include/mlir/Dialect/Tosa/IR/TosaAttributes.cpp.inc"
, 497, __extension__ __PRETTY_FUNCTION__))
;
498 return UnaryOpQuantizationAttr::get(odsParser.getContext(),
499 int64_t((*_result_input_zp)),
500 int64_t((*_result_output_zp)));
501}
502
503void UnaryOpQuantizationAttr::print(::mlir::AsmPrinter &odsPrinter) const {
504 ::mlir::Builder odsBuilder(getContext());
505 odsPrinter << "<";
506 {
507 bool _firstPrinted = true;
508 if (!_firstPrinted) odsPrinter << ", ";
509 _firstPrinted = false;
510 odsPrinter << "input_zp = ";
511 odsPrinter.printStrippedAttrOrType(getInputZp());
512 if (!_firstPrinted) odsPrinter << ", ";
513 _firstPrinted = false;
514 odsPrinter << "output_zp = ";
515 odsPrinter.printStrippedAttrOrType(getOutputZp());
516 }
517 odsPrinter << ">";
518}
519
520int64_t UnaryOpQuantizationAttr::getInputZp() const {
521 return getImpl()->input_zp;
522}
523
524int64_t UnaryOpQuantizationAttr::getOutputZp() const {
525 return getImpl()->output_zp;
526}
527
528} // namespace tosa
529} // namespace mlir
530MLIR_DEFINE_EXPLICIT_TYPE_ID(mlir::tosa::UnaryOpQuantizationAttr)namespace mlir { namespace detail { SelfOwningTypeID TypeIDResolver
<mlir::tosa::UnaryOpQuantizationAttr>::id = {}; } }
531namespace mlir {
532namespace tosa {
533
534/// Parse an attribute registered to this dialect.
535::mlir::Attribute TosaDialect::parseAttribute(::mlir::DialectAsmParser &parser,
536 ::mlir::Type type) const {
537 ::llvm::SMLoc typeLoc = parser.getCurrentLocation();
538 ::llvm::StringRef attrTag;
539 {
540 ::mlir::Attribute attr;
541 auto parseResult = generatedAttributeParser(parser, &attrTag, type, attr);
542 if (parseResult.has_value())
543 return attr;
544 }
545
546 parser.emitError(typeLoc) << "unknown attribute `"
547 << attrTag << "` in dialect `" << getNamespace() << "`";
548 return {};
549}
550/// Print an attribute registered to this dialect.
551void TosaDialect::printAttribute(::mlir::Attribute attr,
552 ::mlir::DialectAsmPrinter &printer) const {
553 if (::mlir::succeeded(generatedAttributePrinter(attr, printer)))
554 return;
555
556}
557} // namespace tosa
558} // namespace mlir
559
560#endif // GET_ATTRDEF_CLASSES
561