@@ -387,22 +387,22 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
387387 // Unary Operators.
388388 mlir::Value VisitUnaryPostDec (const UnaryOperator *e) {
389389 LValue lv = cgf.emitLValue (e->getSubExpr ());
390- return emitScalarPrePostIncDec (e, lv, false , false );
390+ return emitScalarPrePostIncDec (e, lv, cir::UnaryOpKind::Dec , false );
391391 }
392392 mlir::Value VisitUnaryPostInc (const UnaryOperator *e) {
393393 LValue lv = cgf.emitLValue (e->getSubExpr ());
394- return emitScalarPrePostIncDec (e, lv, true , false );
394+ return emitScalarPrePostIncDec (e, lv, cir::UnaryOpKind::Inc , false );
395395 }
396396 mlir::Value VisitUnaryPreDec (const UnaryOperator *e) {
397397 LValue lv = cgf.emitLValue (e->getSubExpr ());
398- return emitScalarPrePostIncDec (e, lv, false , true );
398+ return emitScalarPrePostIncDec (e, lv, cir::UnaryOpKind::Dec , true );
399399 }
400400 mlir::Value VisitUnaryPreInc (const UnaryOperator *e) {
401401 LValue lv = cgf.emitLValue (e->getSubExpr ());
402- return emitScalarPrePostIncDec (e, lv, true , true );
402+ return emitScalarPrePostIncDec (e, lv, cir::UnaryOpKind::Inc , true );
403403 }
404404 mlir::Value emitScalarPrePostIncDec (const UnaryOperator *e, LValue lv,
405- bool isInc , bool isPre) {
405+ cir::UnaryOpKind kind , bool isPre) {
406406 if (cgf.getLangOpts ().OpenMP )
407407 cgf.cgm .errorNYI (e->getSourceRange (), " inc/dec OpenMP" );
408408
@@ -431,7 +431,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
431431 // -> bool = ((int)bool + 1 != 0)
432432 // An interesting aspect of this is that increment is always true.
433433 // Decrement does not have this property.
434- if (isInc && type->isBooleanType ()) {
434+ if (kind == cir::UnaryOpKind::Inc && type->isBooleanType ()) {
435435 value = builder.getTrue (cgf.getLoc (e->getExprLoc ()));
436436 } else if (type->isIntegerType ()) {
437437 QualType promotedType;
@@ -462,7 +462,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
462462
463463 assert (!cir::MissingFeatures::sanitizers ());
464464 if (e->canOverflow () && type->isSignedIntegerOrEnumerationType ()) {
465- value = emitIncDecConsiderOverflowBehavior (e, value, isInc );
465+ value = emitIncDecConsiderOverflowBehavior (e, value, kind );
466466 } else {
467467 cir::UnaryOpKind kind =
468468 e->isIncrementOp () ? cir::UnaryOpKind::Inc : cir::UnaryOpKind::Dec;
@@ -484,7 +484,7 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
484484 // For everything else, we can just do a simple increment.
485485 mlir::Location loc = cgf.getLoc (e->getSourceRange ());
486486 CIRGenBuilderTy &builder = cgf.getBuilder ();
487- int amount = (isInc ? 1 : -1 ) ;
487+ int amount = kind == cir::UnaryOpKind::Inc ? 1 : -1 ;
488488 mlir::Value amt = builder.getSInt32 (amount, loc);
489489 assert (!cir::MissingFeatures::sanitizers ());
490490 value = builder.createPtrStride (loc, value, amt);
@@ -504,8 +504,8 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
504504 if (mlir::isa<cir::SingleType, cir::DoubleType>(value.getType ())) {
505505 // Create the inc/dec operation.
506506 // 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 " );
509509 value = emitUnaryOp (e, kind, value);
510510 } else {
511511 cgf.cgm .errorNYI (e->getSourceRange (), " Unary inc/dec other fp type" );
@@ -536,9 +536,9 @@ class ScalarExprEmitter : public StmtVisitor<ScalarExprEmitter, mlir::Value> {
536536
537537 mlir::Value emitIncDecConsiderOverflowBehavior (const UnaryOperator *e,
538538 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 " ) ;
542542 switch (cgf.getLangOpts ().getSignedOverflowBehavior ()) {
543543 case LangOptions::SOB_Defined:
544544 return emitUnaryOp (e, kind, inVal, /* nsw=*/ false );
@@ -2151,8 +2151,9 @@ mlir::Value ScalarExprEmitter::VisitAbstractConditionalOperator(
21512151}
21522152
21532153mlir::Value CIRGenFunction::emitScalarPrePostIncDec (const UnaryOperator *e,
2154- LValue lv, bool isInc,
2154+ LValue lv,
2155+ cir::UnaryOpKind kind,
21552156 bool isPre) {
21562157 return ScalarExprEmitter (*this , builder)
2157- .emitScalarPrePostIncDec (e, lv, isInc , isPre);
2158+ .emitScalarPrePostIncDec (e, lv, kind , isPre);
21582159}
0 commit comments