@@ -15,11 +15,25 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> {
15
15
explicit ComplexExprEmitter (CIRGenFunction &cgf)
16
16
: cgf(cgf), builder(cgf.getBuilder()) {}
17
17
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
+
18
31
// / Store the specified real/imag parts into the
19
32
// / specified value pointer.
20
33
void emitStoreOfComplex (mlir::Location loc, mlir::Value val, LValue lv,
21
34
bool isInit);
22
35
36
+ mlir::Value VisitCallExpr (const CallExpr *e);
23
37
mlir::Value VisitInitListExpr (InitListExpr *e);
24
38
};
25
39
@@ -32,6 +46,16 @@ static const ComplexType *getComplexType(QualType type) {
32
46
return cast<ComplexType>(cast<AtomicType>(type)->getValueType ());
33
47
}
34
48
49
+ mlir::Value ComplexExprEmitter::emitLoadOfLValue (LValue lv,
50
+ SourceLocation loc) {
51
+ assert (lv.isSimple () && " non-simple complex l-value?" );
52
+ if (lv.getType ()->isAtomicType ())
53
+ cgf.cgm .errorNYI (" emitLoadOfLValue with Atomic LV" );
54
+
55
+ const Address srcAddr = lv.getAddress ();
56
+ return builder.createLoad (cgf.getLoc (loc), srcAddr);
57
+ }
58
+
35
59
void ComplexExprEmitter::emitStoreOfComplex (mlir::Location loc, mlir::Value val,
36
60
LValue lv, bool isInit) {
37
61
if (lv.getType ()->isAtomicType () ||
@@ -44,6 +68,15 @@ void ComplexExprEmitter::emitStoreOfComplex(mlir::Location loc, mlir::Value val,
44
68
builder.createStore (loc, val, destAddr);
45
69
}
46
70
71
+ mlir::Value ComplexExprEmitter::VisitCallExpr (const CallExpr *e) {
72
+ if (e->getCallReturnType (cgf.getContext ())->isReferenceType ())
73
+ return emitLoadOfLValue (e);
74
+
75
+ mlir::Location loc = cgf.getLoc (e->getExprLoc ());
76
+ auto complex = cgf.emitCallExpr (e).getComplexVal ();
77
+ return builder.createComplexCreate (loc, complex.first , complex.second );
78
+ }
79
+
47
80
mlir::Value ComplexExprEmitter::VisitInitListExpr (InitListExpr *e) {
48
81
mlir::Location loc = cgf.getLoc (e->getExprLoc ());
49
82
if (e->getNumInits () == 2 ) {
0 commit comments