Skip to content

Commit 67f1eb5

Browse files
authored
[CIR] Comma Operator for ComplexType (#146204)
This change adds support for the comma operator for ComplexType #141365
1 parent b54e02a commit 67f1eb5

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

clang/lib/CIR/CodeGen/CIRGenExprComplex.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,15 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> {
4141

4242
mlir::Value VisitArraySubscriptExpr(Expr *e);
4343
mlir::Value VisitBinAssign(const BinaryOperator *e);
44+
mlir::Value VisitBinComma(const BinaryOperator *e);
4445
mlir::Value VisitCallExpr(const CallExpr *e);
4546
mlir::Value VisitChooseExpr(ChooseExpr *e);
4647
mlir::Value VisitDeclRefExpr(DeclRefExpr *e);
4748
mlir::Value VisitGenericSelectionExpr(GenericSelectionExpr *e);
4849
mlir::Value VisitImplicitCastExpr(ImplicitCastExpr *e);
4950
mlir::Value VisitInitListExpr(const InitListExpr *e);
5051
mlir::Value VisitImaginaryLiteral(const ImaginaryLiteral *il);
52+
mlir::Value VisitParenExpr(ParenExpr *e);
5153
};
5254
} // namespace
5355

@@ -140,6 +142,11 @@ mlir::Value ComplexExprEmitter::VisitBinAssign(const BinaryOperator *e) {
140142
return emitLoadOfLValue(lv, e->getExprLoc());
141143
}
142144

145+
mlir::Value ComplexExprEmitter::VisitBinComma(const BinaryOperator *e) {
146+
cgf.emitIgnoredExpr(e->getLHS());
147+
return Visit(e->getRHS());
148+
}
149+
143150
mlir::Value ComplexExprEmitter::VisitCallExpr(const CallExpr *e) {
144151
if (e->getCallReturnType(cgf.getContext())->isReferenceType())
145152
return emitLoadOfLValue(e);
@@ -220,6 +227,10 @@ ComplexExprEmitter::VisitImaginaryLiteral(const ImaginaryLiteral *il) {
220227
return builder.create<cir::ConstantOp>(loc, complexAttr);
221228
}
222229

230+
mlir::Value ComplexExprEmitter::VisitParenExpr(ParenExpr *e) {
231+
return Visit(e->getSubExpr());
232+
}
233+
223234
LValue CIRGenFunction::emitComplexAssignmentLValue(const BinaryOperator *e) {
224235
assert(e->getOpcode() == BO_Assign && "Expected assign op");
225236

clang/test/CIR/CodeGen/complex.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,34 @@ bool foo19(double _Complex a, double _Complex b) {
442442
// OGCG: %[[CMP_IMAG:.*]] = fcmp oeq double %[[A_IMAG]], %[[B_IMAG]]
443443
// OGCG: %[[RESULT:.*]] = and i1 %[[CMP_REAL]], %[[CMP_IMAG]]
444444

445+
void foo22(int _Complex a, int _Complex b) {
446+
int _Complex c = (a, b);
447+
}
448+
449+
// CIR: %[[COMPLEX_A:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["a", init]
450+
// CIR: %[[COMPLEX_B:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["b", init]
451+
// CIR: %[[RESULT:.*]] = cir.alloca !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>, ["c", init]
452+
// CIR: %[[TMP_B:.*]] = cir.load{{.*}} %[[COMPLEX_B]] : !cir.ptr<!cir.complex<!s32i>>, !cir.complex<!s32i>
453+
// CIR: cir.store{{.*}} %[[TMP_B]], %[[RESULT]] : !cir.complex<!s32i>, !cir.ptr<!cir.complex<!s32i>>
454+
455+
// LLVM: %[[COMPLEX_A:.*]] = alloca { i32, i32 }, i64 1, align 4
456+
// LLVM: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, i64 1, align 4
457+
// LLVM: %[[RESULT:.*]] = alloca { i32, i32 }, i64 1, align 4
458+
// LLVM: %[[TMP_B:.*]] = load { i32, i32 }, ptr %[[COMPLEX_B]], align 4
459+
// LLVM: store { i32, i32 } %[[TMP_B]], ptr %[[RESULT]], align 4
460+
461+
// OGCG: %[[COMPLEX_A:.*]] = alloca { i32, i32 }, align 4
462+
// OGCG: %[[COMPLEX_B:.*]] = alloca { i32, i32 }, align 4
463+
// OGCG: %[[RESULT:.*]] = alloca { i32, i32 }, align 4
464+
// OGCG: %[[B_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_B]], i32 0, i32 0
465+
// OGCG: %[[B_REAL:.*]] = load i32, ptr %[[B_REAL_PTR]], align 4
466+
// OGCG: %[[B_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[COMPLEX_B]], i32 0, i32 1
467+
// OGCG: %[[B_IMAG:.*]] = load i32, ptr %[[B_IMAG_PTR]], align 4
468+
// OGCG: %[[RESULT_REAL_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[RESULT]], i32 0, i32 0
469+
// OGCG: %[[RESULT_IMAG_PTR:.*]] = getelementptr inbounds nuw { i32, i32 }, ptr %[[RESULT]], i32 0, i32 1
470+
// OGCG: store i32 %[[B_REAL]], ptr %[[RESULT_REAL_PTR]], align 4
471+
// OGCG: store i32 %[[B_IMAG]], ptr %[[RESULT_IMAG_PTR]], align 4
472+
445473
void foo23(int _Complex a, int _Complex b) {
446474
float _Complex f;
447475
int _Complex c = _Generic(a, int _Complex: b, default: f);

0 commit comments

Comments
 (0)