Skip to content

[CIR][NFC] Replace bool by cir::UnaryOpKind in emitComplexPrePostIncDec #149566

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 19, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,23 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> {
mlir::Value
VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *e);

mlir::Value VisitPrePostIncDec(const UnaryOperator *e, bool isInc,
mlir::Value VisitPrePostIncDec(const UnaryOperator *e, cir::UnaryOpKind op,
bool isPre);

mlir::Value VisitUnaryPostDec(const UnaryOperator *e) {
return VisitPrePostIncDec(e, false, false);
return VisitPrePostIncDec(e, cir::UnaryOpKind::Dec, false);
}

mlir::Value VisitUnaryPostInc(const UnaryOperator *e) {
return VisitPrePostIncDec(e, true, false);
return VisitPrePostIncDec(e, cir::UnaryOpKind::Inc, false);
}

mlir::Value VisitUnaryPreDec(const UnaryOperator *e) {
return VisitPrePostIncDec(e, false, true);
return VisitPrePostIncDec(e, cir::UnaryOpKind::Dec, true);
}

mlir::Value VisitUnaryPreInc(const UnaryOperator *e) {
return VisitPrePostIncDec(e, true, true);
return VisitPrePostIncDec(e, cir::UnaryOpKind::Inc, true);
}

mlir::Value VisitUnaryDeref(const Expr *e);
Expand Down Expand Up @@ -355,9 +355,10 @@ mlir::Value ComplexExprEmitter::VisitSubstNonTypeTemplateParmExpr(
}

mlir::Value ComplexExprEmitter::VisitPrePostIncDec(const UnaryOperator *e,
bool isInc, bool isPre) {
cir::UnaryOpKind op,
bool isPre) {
LValue lv = cgf.emitLValue(e->getSubExpr());
return cgf.emitComplexPrePostIncDec(e, lv, isInc, isPre);
return cgf.emitComplexPrePostIncDec(e, lv, op, isPre);
}

mlir::Value ComplexExprEmitter::VisitUnaryDeref(const Expr *e) {
Expand Down Expand Up @@ -449,12 +450,15 @@ mlir::Value CIRGenFunction::emitComplexExpr(const Expr *e) {
}

mlir::Value CIRGenFunction::emitComplexPrePostIncDec(const UnaryOperator *e,
LValue lv, bool isInc,
LValue lv,
cir::UnaryOpKind op,
bool isPre) {
assert(op == cir::UnaryOpKind::Inc ||
op == cir::UnaryOpKind::Dec && "Invalid UnaryOp kind for ComplexType");

mlir::Value inVal = emitLoadOfComplex(lv, e->getExprLoc());
mlir::Location loc = getLoc(e->getExprLoc());
auto opKind = isInc ? cir::UnaryOpKind::Inc : cir::UnaryOpKind::Dec;
mlir::Value incVal = builder.createUnaryOp(loc, opKind, inVal);
mlir::Value incVal = builder.createUnaryOp(loc, op, inVal);

// Store the updated result through the lvalue.
emitStoreOfComplex(loc, incVal, lv, /*isInit=*/false);
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CIR/CodeGen/CIRGenFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ class CIRGenFunction : public CIRGenTypeCache {
mlir::Value emitComplexExpr(const Expr *e);

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

LValue emitComplexAssignmentLValue(const BinaryOperator *e);

Expand Down
Loading