Skip to content

Commit 0aff1b6

Browse files
authored
[CIR][NFC] Replace bool by cir::UnaryOpKind in emitComplexPrePostIncDec (#149566)
Replace bool by cir::UnaryOpKind in emitComplexPrePostIncDec
1 parent 65bde89 commit 0aff1b6

File tree

4 files changed

+35
-29
lines changed

4 files changed

+35
-29
lines changed

clang/lib/CIR/CodeGen/CIRGenExpr.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,8 @@ LValue CIRGenFunction::emitUnaryOpLValue(const UnaryOperator *e) {
663663
}
664664
case UO_PreInc:
665665
case UO_PreDec: {
666-
bool isInc = e->isIncrementOp();
666+
cir::UnaryOpKind kind =
667+
e->isIncrementOp() ? cir::UnaryOpKind::Inc : cir::UnaryOpKind::Dec;
667668
LValue lv = emitLValue(e->getSubExpr());
668669

669670
assert(e->isPrefix() && "Prefix operator in unexpected state!");
@@ -672,7 +673,7 @@ LValue CIRGenFunction::emitUnaryOpLValue(const UnaryOperator *e) {
672673
cgm.errorNYI(e->getSourceRange(), "UnaryOp complex inc/dec");
673674
lv = LValue();
674675
} else {
675-
emitScalarPrePostIncDec(e, lv, isInc, /*isPre=*/true);
676+
emitScalarPrePostIncDec(e, lv, kind, /*isPre=*/true);
676677
}
677678

678679
return lv;

clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,23 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> {
6262
mlir::Value
6363
VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *e);
6464

65-
mlir::Value VisitPrePostIncDec(const UnaryOperator *e, bool isInc,
65+
mlir::Value VisitPrePostIncDec(const UnaryOperator *e, cir::UnaryOpKind op,
6666
bool isPre);
6767

6868
mlir::Value VisitUnaryPostDec(const UnaryOperator *e) {
69-
return VisitPrePostIncDec(e, false, false);
69+
return VisitPrePostIncDec(e, cir::UnaryOpKind::Dec, false);
7070
}
7171

7272
mlir::Value VisitUnaryPostInc(const UnaryOperator *e) {
73-
return VisitPrePostIncDec(e, true, false);
73+
return VisitPrePostIncDec(e, cir::UnaryOpKind::Inc, false);
7474
}
7575

7676
mlir::Value VisitUnaryPreDec(const UnaryOperator *e) {
77-
return VisitPrePostIncDec(e, false, true);
77+
return VisitPrePostIncDec(e, cir::UnaryOpKind::Dec, true);
7878
}
7979

8080
mlir::Value VisitUnaryPreInc(const UnaryOperator *e) {
81-
return VisitPrePostIncDec(e, true, true);
81+
return VisitPrePostIncDec(e, cir::UnaryOpKind::Inc, true);
8282
}
8383

8484
mlir::Value VisitUnaryDeref(const Expr *e);
@@ -360,9 +360,10 @@ mlir::Value ComplexExprEmitter::VisitSubstNonTypeTemplateParmExpr(
360360
}
361361

362362
mlir::Value ComplexExprEmitter::VisitPrePostIncDec(const UnaryOperator *e,
363-
bool isInc, bool isPre) {
363+
cir::UnaryOpKind op,
364+
bool isPre) {
364365
LValue lv = cgf.emitLValue(e->getSubExpr());
365-
return cgf.emitComplexPrePostIncDec(e, lv, isInc, isPre);
366+
return cgf.emitComplexPrePostIncDec(e, lv, op, isPre);
366367
}
367368

368369
mlir::Value ComplexExprEmitter::VisitUnaryDeref(const Expr *e) {
@@ -454,12 +455,15 @@ mlir::Value CIRGenFunction::emitComplexExpr(const Expr *e) {
454455
}
455456

456457
mlir::Value CIRGenFunction::emitComplexPrePostIncDec(const UnaryOperator *e,
457-
LValue lv, bool isInc,
458+
LValue lv,
459+
cir::UnaryOpKind op,
458460
bool isPre) {
461+
assert(op == cir::UnaryOpKind::Inc ||
462+
op == cir::UnaryOpKind::Dec && "Invalid UnaryOp kind for ComplexType");
463+
459464
mlir::Value inVal = emitLoadOfComplex(lv, e->getExprLoc());
460465
mlir::Location loc = getLoc(e->getExprLoc());
461-
auto opKind = isInc ? cir::UnaryOpKind::Inc : cir::UnaryOpKind::Dec;
462-
mlir::Value incVal = builder.createUnaryOp(loc, opKind, inVal);
466+
mlir::Value incVal = builder.createUnaryOp(loc, op, inVal);
463467

464468
// Store the updated result through the lvalue.
465469
emitStoreOfComplex(loc, incVal, lv, /*isInit=*/false);

clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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

21532153
mlir::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
}

clang/lib/CIR/CodeGen/CIRGenFunction.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ class CIRGenFunction : public CIRGenTypeCache {
917917
mlir::Value emitScalarExpr(const clang::Expr *e);
918918

919919
mlir::Value emitScalarPrePostIncDec(const UnaryOperator *e, LValue lv,
920-
bool isInc, bool isPre);
920+
cir::UnaryOpKind kind, bool isPre);
921921

922922
/// Build a debug stoppoint if we are emitting debug info.
923923
void emitStopPoint(const Stmt *s);
@@ -939,7 +939,7 @@ class CIRGenFunction : public CIRGenTypeCache {
939939
void emitComplexExprIntoLValue(const Expr *e, LValue dest, bool isInit);
940940

941941
mlir::Value emitComplexPrePostIncDec(const UnaryOperator *e, LValue lv,
942-
bool isInc, bool isPre);
942+
cir::UnaryOpKind op, bool isPre);
943943

944944
LValue emitComplexAssignmentLValue(const BinaryOperator *e);
945945

0 commit comments

Comments
 (0)