@@ -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
mlir::Value VisitImaginaryLiteral (const ImaginaryLiteral *il);
@@ -34,6 +48,16 @@ static const ComplexType *getComplexType(QualType type) {
34
48
return cast<ComplexType>(cast<AtomicType>(type)->getValueType ());
35
49
}
36
50
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
+
37
61
void ComplexExprEmitter::emitStoreOfComplex (mlir::Location loc, mlir::Value val,
38
62
LValue lv, bool isInit) {
39
63
if (lv.getType ()->isAtomicType () ||
@@ -46,6 +70,15 @@ void ComplexExprEmitter::emitStoreOfComplex(mlir::Location loc, mlir::Value val,
46
70
builder.createStore (loc, val, destAddr);
47
71
}
48
72
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
+
49
82
mlir::Value ComplexExprEmitter::VisitInitListExpr (InitListExpr *e) {
50
83
mlir::Location loc = cgf.getLoc (e->getExprLoc ());
51
84
if (e->getNumInits () == 2 ) {
0 commit comments