@@ -21,6 +21,8 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> {
2121 bool isInit);
2222
2323 mlir::Value VisitInitListExpr (InitListExpr *e);
24+
25+ mlir::Value VisitImaginaryLiteral (const ImaginaryLiteral *il);
2426};
2527
2628} // namespace
@@ -66,6 +68,34 @@ mlir::Value ComplexExprEmitter::VisitInitListExpr(InitListExpr *e) {
6668 return builder.create <cir::ConstantOp>(loc, complexAttr);
6769}
6870
71+ mlir::Value
72+ ComplexExprEmitter::VisitImaginaryLiteral (const ImaginaryLiteral *il) {
73+ auto ty = mlir::cast<cir::ComplexType>(cgf.convertType (il->getType ()));
74+ mlir::Type elementTy = ty.getElementType ();
75+ mlir::Location loc = cgf.getLoc (il->getExprLoc ());
76+
77+ mlir::TypedAttr realValueAttr;
78+ mlir::TypedAttr imagValueAttr;
79+
80+ if (mlir::isa<cir::IntType>(elementTy)) {
81+ llvm::APInt imagValue = cast<IntegerLiteral>(il->getSubExpr ())->getValue ();
82+ realValueAttr = cir::IntAttr::get (elementTy, 0 );
83+ imagValueAttr = cir::IntAttr::get (elementTy, imagValue);
84+ } else {
85+ assert (mlir::isa<cir::CIRFPTypeInterface>(elementTy) &&
86+ " Expected complex element type to be floating-point" );
87+
88+ llvm::APFloat imagValue =
89+ cast<FloatingLiteral>(il->getSubExpr ())->getValue ();
90+ realValueAttr = cir::FPAttr::get (
91+ elementTy, llvm::APFloat::getZero (imagValue.getSemantics ()));
92+ imagValueAttr = cir::FPAttr::get (elementTy, imagValue);
93+ }
94+
95+ auto complexAttr = cir::ConstComplexAttr::get (realValueAttr, imagValueAttr);
96+ return builder.create <cir::ConstantOp>(loc, complexAttr);
97+ }
98+
6999mlir::Value CIRGenFunction::emitComplexExpr (const Expr *e) {
70100 assert (e && getComplexType (e->getType ()) &&
71101 " Invalid complex expression to emit" );
0 commit comments