Skip to content

Commit 4aad518

Browse files
author
git apple-llvm automerger
committed
Merge commit 'b84f72a7f51e' from llvm.org/main into next
2 parents 1bfea59 + b84f72a commit 4aad518

File tree

4 files changed

+290
-38
lines changed

4 files changed

+290
-38
lines changed

clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
337363
mlir::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+
425474
void CIRGenFunction::emitStoreOfComplex(mlir::Location loc, mlir::Value v,
426475
LValue dest, bool isInit) {
427476
ComplexExprEmitter(*this).emitStoreOfComplex(loc, v, dest, isInit);

clang/lib/CIR/CodeGen/CIRGenFunction.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,9 @@ class CIRGenFunction : public CIRGenTypeCache {
930930
/// returning the result.
931931
mlir::Value emitComplexExpr(const Expr *e);
932932

933+
mlir::Value emitComplexPrePostIncDec(const UnaryOperator *e, LValue lv,
934+
bool isInc, bool isPre);
935+
933936
LValue emitComplexAssignmentLValue(const BinaryOperator *e);
934937

935938
void emitCompoundStmt(const clang::CompoundStmt &s);
@@ -980,6 +983,9 @@ class CIRGenFunction : public CIRGenTypeCache {
980983

981984
RValue emitLoadOfBitfieldLValue(LValue lv, SourceLocation loc);
982985

986+
/// Load a complex number from the specified l-value.
987+
mlir::Value emitLoadOfComplex(LValue src, SourceLocation loc);
988+
983989
/// Given an expression that represents a value lvalue, this method emits
984990
/// the address of the lvalue, then loads the result as an rvalue,
985991
/// returning the rvalue.

clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ void LoweringPreparePass::lowerUnaryOp(cir::UnaryOp op) {
5050
switch (opKind) {
5151
case cir::UnaryOpKind::Inc:
5252
case cir::UnaryOpKind::Dec:
53-
llvm_unreachable("Complex unary Inc/Dec NYI");
53+
resultReal = builder.createUnaryOp(loc, opKind, operandReal);
54+
resultImag = operandImag;
5455
break;
5556

5657
case cir::UnaryOpKind::Plus:

0 commit comments

Comments
 (0)