@@ -137,33 +137,25 @@ static ParseResult parseRecordMembers(mlir::AsmParser &parser,
137
137
return mlir::success ();
138
138
}
139
139
140
- LogicalResult ConstRecordAttr::verify (
141
- ::llvm:: function_ref<::mlir:: InFlightDiagnostic()> emitError,
142
- mlir::Type type, ArrayAttr members) {
140
+ LogicalResult
141
+ ConstRecordAttr::verify ( function_ref<InFlightDiagnostic()> emitError,
142
+ mlir::Type type, ArrayAttr members) {
143
143
auto sTy = mlir::dyn_cast_if_present<cir::RecordType>(type);
144
- if (!sTy ) {
145
- emitError () << " expected !cir.record type" ;
146
- return failure ();
147
- }
144
+ if (!sTy )
145
+ return emitError () << " expected !cir.record type" ;
148
146
149
- if (sTy .getMembers ().size () != members.size ()) {
150
- emitError () << " number of elements must match" ;
151
- return failure ();
152
- }
147
+ if (sTy .getMembers ().size () != members.size ())
148
+ return emitError () << " number of elements must match" ;
153
149
154
150
unsigned attrIdx = 0 ;
155
151
for (auto &member : sTy .getMembers ()) {
156
152
auto m = mlir::dyn_cast_or_null<mlir::TypedAttr>(members[attrIdx]);
157
- if (!m) {
158
- emitError () << " expected mlir::TypedAttr attribute" ;
159
- return failure ();
160
- }
161
- if (member != m.getType ()) {
162
- emitError () << " element at index " << attrIdx << " has type "
163
- << m.getType () << " but return type for this element is "
164
- << member;
165
- return failure ();
166
- }
153
+ if (!m)
154
+ return emitError () << " expected mlir::TypedAttr attribute" ;
155
+ if (member != m.getType ())
156
+ return emitError () << " element at index " << attrIdx << " has type "
157
+ << m.getType ()
158
+ << " but return type for this element is " << member;
167
159
attrIdx++;
168
160
}
169
161
@@ -176,14 +168,12 @@ LogicalResult ConstRecordAttr::verify(
176
168
177
169
LogicalResult OptInfoAttr::verify (function_ref<InFlightDiagnostic()> emitError,
178
170
unsigned level, unsigned size) {
179
- if (level > 3 ) {
180
- emitError () << " optimization level must be between 0 and 3 inclusive" ;
181
- return failure ();
182
- }
183
- if (size > 2 ) {
184
- emitError () << " size optimization level must be between 0 and 2 inclusive" ;
185
- return failure ();
186
- }
171
+ if (level > 3 )
172
+ return emitError ()
173
+ << " optimization level must be between 0 and 3 inclusive" ;
174
+ if (size > 2 )
175
+ return emitError ()
176
+ << " size optimization level must be between 0 and 2 inclusive" ;
187
177
return success ();
188
178
}
189
179
@@ -266,17 +256,13 @@ void IntAttr::print(AsmPrinter &printer) const {
266
256
267
257
LogicalResult IntAttr::verify (function_ref<InFlightDiagnostic()> emitError,
268
258
Type type, APInt value) {
269
- if (!mlir::isa<IntType>(type)) {
270
- emitError () << " expected 'simple.int' type" ;
271
- return failure ();
272
- }
259
+ if (!mlir::isa<IntType>(type))
260
+ return emitError () << " expected 'simple.int' type" ;
273
261
274
262
auto intType = mlir::cast<IntType>(type);
275
- if (value.getBitWidth () != intType.getWidth ()) {
276
- emitError () << " type and value bitwidth mismatch: " << intType.getWidth ()
277
- << " != " << value.getBitWidth ();
278
- return failure ();
279
- }
263
+ if (value.getBitWidth () != intType.getWidth ())
264
+ return emitError () << " type and value bitwidth mismatch: "
265
+ << intType.getWidth () << " != " << value.getBitWidth ();
280
266
281
267
return success ();
282
268
}
@@ -310,10 +296,8 @@ cir::FPAttr cir::FPAttr::getZero(mlir::Type type) {
310
296
LogicalResult FPAttr::verify (function_ref<InFlightDiagnostic()> emitError,
311
297
CIRFPTypeInterface fpType, APFloat value) {
312
298
if (APFloat::SemanticsToEnum (fpType.getFloatSemantics ()) !=
313
- APFloat::SemanticsToEnum (value.getSemantics ())) {
314
- emitError () << " floating-point semantics mismatch" ;
315
- return failure ();
316
- }
299
+ APFloat::SemanticsToEnum (value.getSemantics ()))
300
+ return emitError () << " floating-point semantics mismatch" ;
317
301
318
302
return success ();
319
303
}
@@ -326,14 +310,13 @@ LogicalResult ComplexAttr::verify(function_ref<InFlightDiagnostic()> emitError,
326
310
cir::ComplexType type, mlir::TypedAttr real,
327
311
mlir::TypedAttr imag) {
328
312
auto elemType = type.getElementType ();
329
- if (real.getType () != elemType) {
330
- emitError () << " type of the real part does not match the complex type" ;
331
- return failure ();
332
- }
333
- if (imag.getType () != elemType) {
334
- emitError () << " type of the imaginary part does not match the complex type" ;
335
- return failure ();
336
- }
313
+ if (real.getType () != elemType)
314
+ return emitError ()
315
+ << " type of the real part does not match the complex type" ;
316
+
317
+ if (imag.getType () != elemType)
318
+ return emitError ()
319
+ << " type of the imaginary part does not match the complex type" ;
337
320
338
321
return success ();
339
322
}
@@ -378,14 +361,11 @@ CmpThreeWayInfoAttr::verify(function_ref<InFlightDiagnostic()> emitError,
378
361
CmpOrdering ordering, int64_t lt, int64_t eq,
379
362
int64_t gt, std::optional<int64_t> unordered) {
380
363
// The presense of unordered must match the value of ordering.
381
- if (ordering == CmpOrdering::Strong && unordered) {
382
- emitError () << " strong ordering does not include unordered ordering" ;
383
- return failure ();
384
- }
385
- if (ordering == CmpOrdering::Partial && !unordered) {
386
- emitError () << " partial ordering lacks unordered ordering" ;
387
- return failure ();
388
- }
364
+ if (ordering == CmpOrdering::Strong && unordered)
365
+ return emitError () << " strong ordering does not include unordered ordering" ;
366
+
367
+ if (ordering == CmpOrdering::Partial && !unordered)
368
+ return emitError () << " partial ordering lacks unordered ordering" ;
389
369
390
370
return success ();
391
371
}
@@ -404,25 +384,21 @@ DataMemberAttr::verify(function_ref<InFlightDiagnostic()> emitError,
404
384
}
405
385
406
386
auto clsRecordTy = ty.getClsTy ();
407
- if (clsRecordTy.isIncomplete ()) {
408
- emitError () << " incomplete 'cir.record' cannot be used to build a non-null "
409
- " data member pointer" ;
410
- return failure ();
411
- }
387
+ if (clsRecordTy.isIncomplete ())
388
+ return emitError ()
389
+ << " incomplete 'cir.record' cannot be used to build a non-null "
390
+ " data member pointer" ;
412
391
413
392
auto memberIndexValue = memberIndex.value ();
414
- if (memberIndexValue >= clsRecordTy.getNumElements ()) {
415
- emitError ()
416
- << " member index of a #cir.data_member attribute is out of range" ;
417
- return failure ();
418
- }
393
+ if (memberIndexValue >= clsRecordTy.getNumElements ())
394
+ return emitError ()
395
+ << " member index of a #cir.data_member attribute is out of range" ;
419
396
420
397
auto memberTy = clsRecordTy.getMembers ()[memberIndexValue];
421
- if (memberTy != ty.getMemberTy ()) {
422
- emitError () << " member type of a #cir.data_member attribute must match the "
423
- " attribute type" ;
424
- return failure ();
425
- }
398
+ if (memberTy != ty.getMemberTy ())
399
+ return emitError ()
400
+ << " member type of a #cir.data_member attribute must match the "
401
+ " attribute type" ;
426
402
427
403
return success ();
428
404
}
@@ -431,16 +407,14 @@ DataMemberAttr::verify(function_ref<InFlightDiagnostic()> emitError,
431
407
// MethodAttr definitions
432
408
// ===----------------------------------------------------------------------===//
433
409
434
- LogicalResult
435
- MethodAttr::verify (function_ref<::mlir::InFlightDiagnostic()> emitError,
436
- cir::MethodType type,
437
- std::optional<FlatSymbolRefAttr> symbol,
438
- std::optional<uint64_t> vtable_offset) {
439
- if (symbol.has_value () && vtable_offset.has_value ()) {
440
- emitError () << " at most one of symbol and vtable_offset can be present "
441
- " in #cir.method" ;
442
- return failure ();
443
- }
410
+ LogicalResult MethodAttr::verify (function_ref<InFlightDiagnostic()> emitError,
411
+ cir::MethodType type,
412
+ std::optional<FlatSymbolRefAttr> symbol,
413
+ std::optional<uint64_t> vtable_offset) {
414
+ if (symbol.has_value () && vtable_offset.has_value ())
415
+ return emitError ()
416
+ << " at most one of symbol and vtable_offset can be present "
417
+ " in #cir.method" ;
444
418
445
419
return success ();
446
420
}
@@ -504,38 +478,35 @@ void MethodAttr::print(AsmPrinter &printer) const {
504
478
// GlobalAnnotationValuesAttr definitions
505
479
// ===----------------------------------------------------------------------===//
506
480
507
- LogicalResult GlobalAnnotationValuesAttr::verify (
508
- function_ref<::mlir::InFlightDiagnostic()> emitError,
509
- mlir::ArrayAttr annotations) {
510
- if (annotations.empty ()) {
511
- emitError ()
512
- << " GlobalAnnotationValuesAttr should at least have one annotation" ;
513
- return failure ();
514
- }
481
+ LogicalResult
482
+ GlobalAnnotationValuesAttr::verify (function_ref<InFlightDiagnostic()> emitError,
483
+ mlir::ArrayAttr annotations) {
484
+ if (annotations.empty ())
485
+ return emitError ()
486
+ << " GlobalAnnotationValuesAttr should at least have one annotation" ;
487
+
515
488
for (auto &entry : annotations) {
516
489
auto annoEntry = ::mlir::dyn_cast<mlir::ArrayAttr>(entry);
517
- if (!annoEntry) {
518
- emitError () << " Element of GlobalAnnotationValuesAttr annotations array"
519
- " must be an array" ;
520
- return failure ();
521
- } else if (annoEntry.size () != 2 ) {
522
- emitError () << " Element of GlobalAnnotationValuesAttr annotations array"
523
- << " must be a 2-element array and you have "
524
- << annoEntry.size ();
525
- return failure ();
526
- } else if (!::mlir::isa<mlir::StringAttr>(annoEntry[0 ])) {
527
- emitError () << " Element of GlobalAnnotationValuesAttr annotations"
528
- " array must start with a string, which is the name of "
529
- " global op or func it annotates" ;
530
- return failure ();
531
- }
532
- auto annoPart = ::mlir::dyn_cast<cir::AnnotationAttr>(annoEntry[1 ]);
533
- if (!annoPart) {
534
- emitError () << " The second element of GlobalAnnotationValuesAttr"
535
- " annotations array element must be of "
536
- " type AnnotationValueAttr" ;
537
- return failure ();
538
- }
490
+ if (!annoEntry)
491
+ return emitError ()
492
+ << " Element of GlobalAnnotationValuesAttr annotations array"
493
+ " must be an array" ;
494
+
495
+ if (annoEntry.size () != 2 )
496
+ return emitError ()
497
+ << " Element of GlobalAnnotationValuesAttr annotations array"
498
+ << " must be a 2-element array and you have " << annoEntry.size ();
499
+
500
+ if (!mlir::isa<mlir::StringAttr>(annoEntry[0 ]))
501
+ return emitError ()
502
+ << " Element of GlobalAnnotationValuesAttr annotations"
503
+ " array must start with a string, which is the name of "
504
+ " global op or func it annotates" ;
505
+
506
+ if (!mlir::isa<cir::AnnotationAttr>(annoEntry[1 ]))
507
+ return emitError () << " The second element of GlobalAnnotationValuesAttr"
508
+ " annotations array element must be of "
509
+ " type AnnotationValueAttr" ;
539
510
}
540
511
return success ();
541
512
}
@@ -574,15 +545,11 @@ LogicalResult DynamicCastInfoAttr::verify(
574
545
return pointeeIntTy.isUnsigned () && pointeeIntTy.getWidth () == 8 ;
575
546
};
576
547
577
- if (!isRttiPtr (srcRtti.getType ())) {
578
- emitError () << " srcRtti must be an RTTI pointer" ;
579
- return failure ();
580
- }
548
+ if (!isRttiPtr (srcRtti.getType ()))
549
+ return emitError () << " srcRtti must be an RTTI pointer" ;
581
550
582
- if (!isRttiPtr (destRtti.getType ())) {
583
- emitError () << " destRtti must be an RTTI pointer" ;
584
- return failure ();
585
- }
551
+ if (!isRttiPtr (destRtti.getType ()))
552
+ return emitError () << " destRtti must be an RTTI pointer" ;
586
553
587
554
return success ();
588
555
}
0 commit comments