@@ -56,6 +56,26 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> {
56
56
mlir::Value VisitParenExpr (ParenExpr *e);
57
57
mlir::Value
58
58
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
+
59
79
mlir::Value VisitUnaryDeref (const Expr *e);
60
80
mlir::Value VisitUnaryNot (const UnaryOperator *e);
61
81
@@ -334,6 +354,12 @@ mlir::Value ComplexExprEmitter::VisitSubstNonTypeTemplateParmExpr(
334
354
return Visit (e->getReplacement ());
335
355
}
336
356
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
+
337
363
mlir::Value ComplexExprEmitter::VisitUnaryDeref (const Expr *e) {
338
364
return emitLoadOfLValue (e);
339
365
}
@@ -422,6 +448,29 @@ mlir::Value CIRGenFunction::emitComplexExpr(const Expr *e) {
422
448
return ComplexExprEmitter (*this ).Visit (const_cast <Expr *>(e));
423
449
}
424
450
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
+
425
474
void CIRGenFunction::emitStoreOfComplex (mlir::Location loc, mlir::Value v,
426
475
LValue dest, bool isInit) {
427
476
ComplexExprEmitter (*this ).emitStoreOfComplex (loc, v, dest, isInit);
0 commit comments