@@ -15,11 +15,25 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> {
1515 explicit ComplexExprEmitter (CIRGenFunction &cgf)
1616 : cgf(cgf), builder(cgf.getBuilder()) {}
1717
18+ // ===--------------------------------------------------------------------===//
19+ // Utilities
20+ // ===--------------------------------------------------------------------===//
21+
22+ // / Given an expression with complex type that represents a value l-value,
23+ // / this method emits the address of the l-value, then loads and returns the
24+ // / result.
25+ mlir::Value emitLoadOfLValue (const Expr *e) {
26+ return emitLoadOfLValue (cgf.emitLValue (e), e->getExprLoc ());
27+ }
28+
29+ mlir::Value emitLoadOfLValue (LValue lv, SourceLocation loc);
30+
1831 // / Store the specified real/imag parts into the
1932 // / specified value pointer.
2033 void emitStoreOfComplex (mlir::Location loc, mlir::Value val, LValue lv,
2134 bool isInit);
2235
36+ mlir::Value VisitCallExpr (const CallExpr *e);
2337 mlir::Value VisitInitListExpr (InitListExpr *e);
2438
2539 mlir::Value VisitImaginaryLiteral (const ImaginaryLiteral *il);
@@ -34,6 +48,16 @@ static const ComplexType *getComplexType(QualType type) {
3448 return cast<ComplexType>(cast<AtomicType>(type)->getValueType ());
3549}
3650
51+ mlir::Value ComplexExprEmitter::emitLoadOfLValue (LValue lv,
52+ SourceLocation loc) {
53+ assert (lv.isSimple () && " non-simple complex l-value?" );
54+ if (lv.getType ()->isAtomicType ())
55+ cgf.cgm .errorNYI (" emitLoadOfLValue with Atomic LV" );
56+
57+ const Address srcAddr = lv.getAddress ();
58+ return builder.createLoad (cgf.getLoc (loc), srcAddr);
59+ }
60+
3761void ComplexExprEmitter::emitStoreOfComplex (mlir::Location loc, mlir::Value val,
3862 LValue lv, bool isInit) {
3963 if (lv.getType ()->isAtomicType () ||
@@ -46,6 +70,15 @@ void ComplexExprEmitter::emitStoreOfComplex(mlir::Location loc, mlir::Value val,
4670 builder.createStore (loc, val, destAddr);
4771}
4872
73+ mlir::Value ComplexExprEmitter::VisitCallExpr (const CallExpr *e) {
74+ if (e->getCallReturnType (cgf.getContext ())->isReferenceType ())
75+ return emitLoadOfLValue (e);
76+
77+ mlir::Location loc = cgf.getLoc (e->getExprLoc ());
78+ auto complex = cgf.emitCallExpr (e).getComplexVal ();
79+ return builder.createComplexCreate (loc, complex .first , complex .second );
80+ }
81+
4982mlir::Value ComplexExprEmitter::VisitInitListExpr (InitListExpr *e) {
5083 mlir::Location loc = cgf.getLoc (e->getExprLoc ());
5184 if (e->getNumInits () == 2 ) {
0 commit comments