@@ -34,11 +34,20 @@ class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> {
34
34
}
35
35
36
36
mlir::Value emitLoadOfLValue (LValue lv, SourceLocation loc);
37
+
37
38
// / Store the specified real/imag parts into the
38
39
// / specified value pointer.
39
40
void emitStoreOfComplex (mlir::Location loc, mlir::Value val, LValue lv,
40
41
bool isInit);
41
42
43
+ // / Emit a cast from complex value Val to DestType.
44
+ mlir::Value emitComplexToComplexCast (mlir::Value value, QualType srcType,
45
+ QualType destType, SourceLocation loc);
46
+
47
+ // / Emit a cast from scalar value Val to DestType.
48
+ mlir::Value emitScalarToComplexCast (mlir::Value value, QualType srcType,
49
+ QualType destType, SourceLocation loc);
50
+
42
51
mlir::Value
43
52
VisitAbstractConditionalOperator (const AbstractConditionalOperator *e);
44
53
mlir::Value VisitArraySubscriptExpr (Expr *e);
@@ -164,14 +173,106 @@ LValue ComplexExprEmitter::emitBinAssignLValue(const BinaryOperator *e,
164
173
mlir::Value ComplexExprEmitter::emitCast (CastKind ck, Expr *op,
165
174
QualType destTy) {
166
175
switch (ck) {
176
+ case CK_Dependent:
177
+ llvm_unreachable (" dependent type must be resolved before the CIR codegen" );
178
+
167
179
case CK_NoOp:
168
180
case CK_LValueToRValue:
169
181
return Visit (op);
170
- default :
171
- break ;
182
+
183
+ case CK_AtomicToNonAtomic:
184
+ case CK_NonAtomicToAtomic:
185
+ case CK_UserDefinedConversion: {
186
+ cgf.cgm .errorNYI (
187
+ " ComplexExprEmitter::emitCast Atmoic & UserDefinedConversion" );
188
+ return {};
172
189
}
173
- cgf.cgm .errorNYI (" ComplexType Cast" );
174
- return {};
190
+
191
+ case CK_LValueBitCast: {
192
+ cgf.cgm .errorNYI (" ComplexExprEmitter::emitCast CK_LValueBitCast" );
193
+ return {};
194
+ }
195
+
196
+ case CK_LValueToRValueBitCast: {
197
+ cgf.cgm .errorNYI (" ComplexExprEmitter::emitCast CK_LValueToRValueBitCast" );
198
+ return {};
199
+ }
200
+
201
+ case CK_BitCast:
202
+ case CK_BaseToDerived:
203
+ case CK_DerivedToBase:
204
+ case CK_UncheckedDerivedToBase:
205
+ case CK_Dynamic:
206
+ case CK_ToUnion:
207
+ case CK_ArrayToPointerDecay:
208
+ case CK_FunctionToPointerDecay:
209
+ case CK_NullToPointer:
210
+ case CK_NullToMemberPointer:
211
+ case CK_BaseToDerivedMemberPointer:
212
+ case CK_DerivedToBaseMemberPointer:
213
+ case CK_MemberPointerToBoolean:
214
+ case CK_ReinterpretMemberPointer:
215
+ case CK_ConstructorConversion:
216
+ case CK_IntegralToPointer:
217
+ case CK_PointerToIntegral:
218
+ case CK_PointerToBoolean:
219
+ case CK_ToVoid:
220
+ case CK_VectorSplat:
221
+ case CK_IntegralCast:
222
+ case CK_BooleanToSignedIntegral:
223
+ case CK_IntegralToBoolean:
224
+ case CK_IntegralToFloating:
225
+ case CK_FloatingToIntegral:
226
+ case CK_FloatingToBoolean:
227
+ case CK_FloatingCast:
228
+ case CK_CPointerToObjCPointerCast:
229
+ case CK_BlockPointerToObjCPointerCast:
230
+ case CK_AnyPointerToBlockPointerCast:
231
+ case CK_ObjCObjectLValueCast:
232
+ case CK_FloatingComplexToReal:
233
+ case CK_FloatingComplexToBoolean:
234
+ case CK_IntegralComplexToReal:
235
+ case CK_IntegralComplexToBoolean:
236
+ case CK_ARCProduceObject:
237
+ case CK_ARCConsumeObject:
238
+ case CK_ARCReclaimReturnedObject:
239
+ case CK_ARCExtendBlockObject:
240
+ case CK_CopyAndAutoreleaseBlockObject:
241
+ case CK_BuiltinFnToFnPtr:
242
+ case CK_ZeroToOCLOpaqueType:
243
+ case CK_AddressSpaceConversion:
244
+ case CK_IntToOCLSampler:
245
+ case CK_FloatingToFixedPoint:
246
+ case CK_FixedPointToFloating:
247
+ case CK_FixedPointCast:
248
+ case CK_FixedPointToBoolean:
249
+ case CK_FixedPointToIntegral:
250
+ case CK_IntegralToFixedPoint:
251
+ case CK_MatrixCast:
252
+ case CK_HLSLVectorTruncation:
253
+ case CK_HLSLArrayRValue:
254
+ case CK_HLSLElementwiseCast:
255
+ case CK_HLSLAggregateSplatCast:
256
+ llvm_unreachable (" invalid cast kind for complex value" );
257
+
258
+ case CK_FloatingRealToComplex:
259
+ case CK_IntegralRealToComplex: {
260
+ assert (!cir::MissingFeatures::cgFPOptionsRAII ());
261
+ return emitScalarToComplexCast (cgf.emitScalarExpr (op), op->getType (),
262
+ destTy, op->getExprLoc ());
263
+ }
264
+
265
+ case CK_FloatingComplexCast:
266
+ case CK_FloatingComplexToIntegralComplex:
267
+ case CK_IntegralComplexCast:
268
+ case CK_IntegralComplexToFloatingComplex: {
269
+ assert (!cir::MissingFeatures::cgFPOptionsRAII ());
270
+ return emitComplexToComplexCast (Visit (op), op->getType (), destTy,
271
+ op->getExprLoc ());
272
+ }
273
+ }
274
+
275
+ llvm_unreachable (" unknown cast resulting in complex value" );
175
276
}
176
277
177
278
mlir::Value ComplexExprEmitter::emitConstant (
@@ -207,6 +308,49 @@ void ComplexExprEmitter::emitStoreOfComplex(mlir::Location loc, mlir::Value val,
207
308
builder.createStore (loc, val, destAddr);
208
309
}
209
310
311
+ mlir::Value ComplexExprEmitter::emitComplexToComplexCast (mlir::Value val,
312
+ QualType srcType,
313
+ QualType destType,
314
+ SourceLocation loc) {
315
+ if (srcType == destType)
316
+ return val;
317
+
318
+ // Get the src/dest element type.
319
+ QualType srcElemTy = srcType->castAs <ComplexType>()->getElementType ();
320
+ QualType destElemTy = destType->castAs <ComplexType>()->getElementType ();
321
+
322
+ cir::CastKind castOpKind;
323
+ if (srcElemTy->isFloatingType () && destElemTy->isFloatingType ())
324
+ castOpKind = cir::CastKind::float_complex;
325
+ else if (srcElemTy->isFloatingType () && destElemTy->isIntegerType ())
326
+ castOpKind = cir::CastKind::float_complex_to_int_complex;
327
+ else if (srcElemTy->isIntegerType () && destElemTy->isFloatingType ())
328
+ castOpKind = cir::CastKind::int_complex_to_float_complex;
329
+ else if (srcElemTy->isIntegerType () && destElemTy->isIntegerType ())
330
+ castOpKind = cir::CastKind::int_complex;
331
+ else
332
+ llvm_unreachable (" unexpected src type or dest type" );
333
+
334
+ return builder.createCast (cgf.getLoc (loc), castOpKind, val,
335
+ cgf.convertType (destType));
336
+ }
337
+
338
+ mlir::Value ComplexExprEmitter::emitScalarToComplexCast (mlir::Value val,
339
+ QualType srcType,
340
+ QualType destType,
341
+ SourceLocation loc) {
342
+ cir::CastKind castOpKind;
343
+ if (srcType->isFloatingType ())
344
+ castOpKind = cir::CastKind::float_to_complex;
345
+ else if (srcType->isIntegerType ())
346
+ castOpKind = cir::CastKind::int_to_complex;
347
+ else
348
+ llvm_unreachable (" unexpected src type" );
349
+
350
+ return builder.createCast (cgf.getLoc (loc), castOpKind, val,
351
+ cgf.convertType (destType));
352
+ }
353
+
210
354
mlir::Value ComplexExprEmitter::VisitAbstractConditionalOperator (
211
355
const AbstractConditionalOperator *e) {
212
356
mlir::Value condValue = Visit (e->getCond ());
0 commit comments