@@ -387,22 +387,22 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
387
387
// Unary Operators.
388
388
mlir::Value VisitUnaryPostDec (const UnaryOperator *e) {
389
389
LValue lv = cgf.emitLValue (e->getSubExpr ());
390
- return emitScalarPrePostIncDec (e, lv, false , false );
390
+ return emitScalarPrePostIncDec (e, lv, cir::UnaryOpKind::Dec , false );
391
391
}
392
392
mlir::Value VisitUnaryPostInc (const UnaryOperator *e) {
393
393
LValue lv = cgf.emitLValue (e->getSubExpr ());
394
- return emitScalarPrePostIncDec (e, lv, true , false );
394
+ return emitScalarPrePostIncDec (e, lv, cir::UnaryOpKind::Inc , false );
395
395
}
396
396
mlir::Value VisitUnaryPreDec (const UnaryOperator *e) {
397
397
LValue lv = cgf.emitLValue (e->getSubExpr ());
398
- return emitScalarPrePostIncDec (e, lv, false , true );
398
+ return emitScalarPrePostIncDec (e, lv, cir::UnaryOpKind::Dec , true );
399
399
}
400
400
mlir::Value VisitUnaryPreInc (const UnaryOperator *e) {
401
401
LValue lv = cgf.emitLValue (e->getSubExpr ());
402
- return emitScalarPrePostIncDec (e, lv, true , true );
402
+ return emitScalarPrePostIncDec (e, lv, cir::UnaryOpKind::Inc , true );
403
403
}
404
404
mlir::Value emitScalarPrePostIncDec (const UnaryOperator *e, LValue lv,
405
- bool isInc , bool isPre) {
405
+ cir::UnaryOpKind kind , bool isPre) {
406
406
if (cgf.getLangOpts ().OpenMP )
407
407
cgf.cgm .errorNYI (e->getSourceRange (), " inc/dec OpenMP" );
408
408
@@ -431,7 +431,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
431
431
// -> bool = ((int)bool + 1 != 0)
432
432
// An interesting aspect of this is that increment is always true.
433
433
// Decrement does not have this property.
434
- if (isInc && type->isBooleanType ()) {
434
+ if (kind == cir::UnaryOpKind::Inc && type->isBooleanType ()) {
435
435
value = builder.getTrue (cgf.getLoc (e->getExprLoc ()));
436
436
} else if (type->isIntegerType ()) {
437
437
QualType promotedType;
@@ -462,7 +462,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
462
462
463
463
assert (!cir::MissingFeatures::sanitizers ());
464
464
if (e->canOverflow () && type->isSignedIntegerOrEnumerationType ()) {
465
- value = emitIncDecConsiderOverflowBehavior (e, value, isInc );
465
+ value = emitIncDecConsiderOverflowBehavior (e, value, kind );
466
466
} else {
467
467
cir::UnaryOpKind kind =
468
468
e->isIncrementOp () ? cir::UnaryOpKind::Inc : cir::UnaryOpKind::Dec;
@@ -484,7 +484,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
484
484
// For everything else, we can just do a simple increment.
485
485
mlir::Location loc = cgf.getLoc (e->getSourceRange ());
486
486
CIRGenBuilderTy &builder = cgf.getBuilder ();
487
- int amount = (isInc ? 1 : -1 ) ;
487
+ int amount = kind == cir::UnaryOpKind::Inc ? 1 : -1 ;
488
488
mlir::Value amt = builder.getSInt32 (amount, loc);
489
489
assert (!cir::MissingFeatures::sanitizers ());
490
490
value = builder.createPtrStride (loc, value, amt);
@@ -504,8 +504,8 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
504
504
if (mlir::isa<cir::SingleType, cir::DoubleType>(value.getType ())) {
505
505
// Create the inc/dec operation.
506
506
// NOTE(CIR): clang calls CreateAdd but folds this to a unary op
507
- cir::UnaryOpKind kind =
508
- (isInc ? cir::UnaryOpKind::Inc : cir::UnaryOpKind::Dec);
507
+ assert (kind == cir::UnaryOpKind::Inc ||
508
+ kind == cir::UnaryOpKind::Dec && " Invalid UnaryOp kind " );
509
509
value = emitUnaryOp (e, kind, value);
510
510
} else {
511
511
cgf.cgm .errorNYI (e->getSourceRange (), " Unary inc/dec other fp type" );
@@ -536,9 +536,9 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
536
536
537
537
mlir::Value emitIncDecConsiderOverflowBehavior (const UnaryOperator *e,
538
538
mlir::Value inVal,
539
- bool isInc ) {
540
- cir::UnaryOpKind kind =
541
- e-> isIncrementOp () ? cir::UnaryOpKind::Inc : cir::UnaryOpKind::Dec;
539
+ cir::UnaryOpKind kind ) {
540
+ assert (kind == cir::UnaryOpKind::Inc ||
541
+ kind == cir::UnaryOpKind::Dec && " Invalid UnaryOp kind " ) ;
542
542
switch (cgf.getLangOpts ().getSignedOverflowBehavior ()) {
543
543
case LangOptions::SOB_Defined:
544
544
return emitUnaryOp (e, kind, inVal, /* nsw=*/ false );
@@ -2151,8 +2151,9 @@ mlir::Value ScalarExprEmitter::VisitAbstractConditionalOperator(
2151
2151
}
2152
2152
2153
2153
mlir::Value CIRGenFunction::emitScalarPrePostIncDec (const UnaryOperator *e,
2154
- LValue lv, bool isInc,
2154
+ LValue lv,
2155
+ cir::UnaryOpKind kind,
2155
2156
bool isPre) {
2156
2157
return ScalarExprEmitter (*this , builder)
2157
- .emitScalarPrePostIncDec (e, lv, isInc , isPre);
2158
+ .emitScalarPrePostIncDec (e, lv, kind , isPre);
2158
2159
}
0 commit comments