@@ -56,6 +56,26 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> {
5656 mlir::Value VisitParenExpr (ParenExpr *e);
5757 mlir::Value
5858 VisitSubstNonTypeTemplateParmExpr (SubstNonTypeTemplateParmExpr *e);
59+
60+ mlir::Value VisitPrePostIncDec (const UnaryOperator *e, bool isInc,
61+ bool isPre);
62+
63+ mlir::Value VisitUnaryPostDec (const UnaryOperator *e) {
64+ return VisitPrePostIncDec (e, false , false );
65+ }
66+
67+ mlir::Value VisitUnaryPostInc (const UnaryOperator *e) {
68+ return VisitPrePostIncDec (e, true , false );
69+ }
70+
71+ mlir::Value VisitUnaryPreDec (const UnaryOperator *e) {
72+ return VisitPrePostIncDec (e, false , true );
73+ }
74+
75+ mlir::Value VisitUnaryPreInc (const UnaryOperator *e) {
76+ return VisitPrePostIncDec (e, true , true );
77+ }
78+
5979 mlir::Value VisitUnaryDeref (const Expr *e);
6080 mlir::Value VisitUnaryNot (const UnaryOperator *e);
6181
@@ -334,6 +354,12 @@ mlir::Value ComplexExprEmitter::VisitSubstNonTypeTemplateParmExpr(
334354 return Visit (e->getReplacement ());
335355}
336356
357+ mlir::Value ComplexExprEmitter::VisitPrePostIncDec (const UnaryOperator *e,
358+ bool isInc, bool isPre) {
359+ LValue lv = cgf.emitLValue (e->getSubExpr ());
360+ return cgf.emitComplexPrePostIncDec (e, lv, isInc, isPre);
361+ }
362+
337363mlir::Value ComplexExprEmitter::VisitUnaryDeref (const Expr *e) {
338364 return emitLoadOfLValue (e);
339365}
@@ -422,6 +448,29 @@ mlir::Value CIRGenFunction::emitComplexExpr(const Expr *e) {
422448 return ComplexExprEmitter (*this ).Visit (const_cast <Expr *>(e));
423449}
424450
451+ mlir::Value CIRGenFunction::emitComplexPrePostIncDec (const UnaryOperator *e,
452+ LValue lv, bool isInc,
453+ bool isPre) {
454+ mlir::Value inVal = emitLoadOfComplex (lv, e->getExprLoc ());
455+ mlir::Location loc = getLoc (e->getExprLoc ());
456+ auto opKind = isInc ? cir::UnaryOpKind::Inc : cir::UnaryOpKind::Dec;
457+ mlir::Value incVal = builder.createUnaryOp (loc, opKind, inVal);
458+
459+ // Store the updated result through the lvalue.
460+ emitStoreOfComplex (loc, incVal, lv, /* isInit=*/ false );
461+
462+ if (getLangOpts ().OpenMP )
463+ cgm.errorNYI (loc, " emitComplexPrePostIncDec OpenMP" );
464+
465+ // If this is a postinc, return the value read from memory, otherwise use the
466+ // updated value.
467+ return isPre ? incVal : inVal;
468+ }
469+
470+ mlir::Value CIRGenFunction::emitLoadOfComplex (LValue src, SourceLocation loc) {
471+ return ComplexExprEmitter (*this ).emitLoadOfLValue (src, loc);
472+ }
473+
425474void CIRGenFunction::emitStoreOfComplex (mlir::Location loc, mlir::Value v,
426475 LValue dest, bool isInit) {
427476 ComplexExprEmitter (*this ).emitStoreOfComplex (loc, v, dest, isInit);
0 commit comments