clang 22.0.0git
CIRGenExprComplex.cpp
Go to the documentation of this file.
1#include "CIRGenBuilder.h"
2#include "CIRGenFunction.h"
3
5
6using namespace clang;
7using namespace clang::CIRGen;
8
9#ifndef NDEBUG
10/// Return the complex type that we are meant to emit.
12 type = type.getCanonicalType();
13 if (const ComplexType *comp = dyn_cast<ComplexType>(type))
14 return comp;
15 return cast<ComplexType>(cast<AtomicType>(type)->getValueType());
16}
17#endif // NDEBUG
18
19namespace {
20class ComplexExprEmitter : public StmtVisitor<ComplexExprEmitter, mlir::Value> {
21 CIRGenFunction &cgf;
22 CIRGenBuilderTy &builder;
23
24public:
25 explicit ComplexExprEmitter(CIRGenFunction &cgf)
26 : cgf(cgf), builder(cgf.getBuilder()) {}
27
28 //===--------------------------------------------------------------------===//
29 // Utilities
30 //===--------------------------------------------------------------------===//
31
32 /// Given an expression with complex type that represents a value l-value,
33 /// this method emits the address of the l-value, then loads and returns the
34 /// result.
35 mlir::Value emitLoadOfLValue(const Expr *e) {
36 return emitLoadOfLValue(cgf.emitLValue(e), e->getExprLoc());
37 }
38
39 mlir::Value emitLoadOfLValue(LValue lv, SourceLocation loc);
40
41 /// Store the specified real/imag parts into the
42 /// specified value pointer.
43 void emitStoreOfComplex(mlir::Location loc, mlir::Value val, LValue lv,
44 bool isInit);
45
46 /// Emit a cast from complex value Val to DestType.
47 mlir::Value emitComplexToComplexCast(mlir::Value value, QualType srcType,
48 QualType destType, SourceLocation loc);
49
50 /// Emit a cast from scalar value Val to DestType.
51 mlir::Value emitScalarToComplexCast(mlir::Value value, QualType srcType,
52 QualType destType, SourceLocation loc);
53
54 //===--------------------------------------------------------------------===//
55 // Visitor Methods
56 //===--------------------------------------------------------------------===//
57
58 mlir::Value Visit(Expr *e) {
59 return StmtVisitor<ComplexExprEmitter, mlir::Value>::Visit(e);
60 }
61
62 mlir::Value VisitStmt(Stmt *s) {
63 cgf.cgm.errorNYI(s->getBeginLoc(), "ComplexExprEmitter VisitStmt");
64 return {};
65 }
66
67 mlir::Value VisitExpr(Expr *e);
68 mlir::Value VisitConstantExpr(ConstantExpr *e) {
69 cgf.cgm.errorNYI(e->getExprLoc(), "ComplexExprEmitter VisitConstantExpr");
70 return {};
71 }
72
73 mlir::Value VisitParenExpr(ParenExpr *pe) { return Visit(pe->getSubExpr()); }
74 mlir::Value VisitGenericSelectionExpr(GenericSelectionExpr *ge) {
75 return Visit(ge->getResultExpr());
76 }
77 mlir::Value VisitImaginaryLiteral(const ImaginaryLiteral *il);
78 mlir::Value
79 VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *pe) {
80 return Visit(pe->getReplacement());
81 }
82 mlir::Value VisitCoawaitExpr(CoawaitExpr *s) {
83 cgf.cgm.errorNYI(s->getExprLoc(), "ComplexExprEmitter VisitCoawaitExpr");
84 return {};
85 }
86 mlir::Value VisitCoyieldExpr(CoyieldExpr *s) {
87 cgf.cgm.errorNYI(s->getExprLoc(), "ComplexExprEmitter VisitCoyieldExpr");
88 return {};
89 }
90 mlir::Value VisitUnaryCoawait(const UnaryOperator *e) {
91 cgf.cgm.errorNYI(e->getExprLoc(), "ComplexExprEmitter VisitUnaryCoawait");
92 return {};
93 }
94
95 mlir::Value emitConstant(const CIRGenFunction::ConstantEmission &constant,
96 Expr *e) {
97 assert(constant && "not a constant");
98 if (constant.isReference())
99 return emitLoadOfLValue(constant.getReferenceLValue(cgf, e),
100 e->getExprLoc());
101
102 mlir::TypedAttr valueAttr = constant.getValue();
103 return builder.getConstant(cgf.getLoc(e->getSourceRange()), valueAttr);
104 }
105
106 // l-values.
107 mlir::Value VisitDeclRefExpr(DeclRefExpr *e) {
108 if (CIRGenFunction::ConstantEmission constant = cgf.tryEmitAsConstant(e))
109 return emitConstant(constant, e);
110 return emitLoadOfLValue(e);
111 }
112 mlir::Value VisitObjCIvarRefExpr(ObjCIvarRefExpr *e) {
113 cgf.cgm.errorNYI(e->getExprLoc(),
114 "ComplexExprEmitter VisitObjCIvarRefExpr");
115 return {};
116 }
117 mlir::Value VisitObjCMessageExpr(ObjCMessageExpr *e) {
118 cgf.cgm.errorNYI(e->getExprLoc(),
119 "ComplexExprEmitter VisitObjCMessageExpr");
120 return {};
121 }
122 mlir::Value VisitArraySubscriptExpr(Expr *e) { return emitLoadOfLValue(e); }
123 mlir::Value VisitMemberExpr(MemberExpr *me) {
124 if (CIRGenFunction::ConstantEmission constant = cgf.tryEmitAsConstant(me)) {
125 cgf.emitIgnoredExpr(me->getBase());
126 return emitConstant(constant, me);
127 }
128 return emitLoadOfLValue(me);
129 }
130 mlir::Value VisitOpaqueValueExpr(OpaqueValueExpr *e) {
131 if (e->isGLValue())
132 return emitLoadOfLValue(cgf.getOrCreateOpaqueLValueMapping(e),
133 e->getExprLoc());
134 return cgf.getOrCreateOpaqueRValueMapping(e).getComplexValue();
135 }
136
137 mlir::Value VisitPseudoObjectExpr(PseudoObjectExpr *e) {
138 cgf.cgm.errorNYI(e->getExprLoc(),
139 "ComplexExprEmitter VisitPseudoObjectExpr");
140 return {};
141 }
142
143 mlir::Value emitCast(CastKind ck, Expr *op, QualType destTy);
144 mlir::Value VisitImplicitCastExpr(ImplicitCastExpr *e) {
145 // Unlike for scalars, we don't have to worry about function->ptr demotion
146 // here.
148 return emitLoadOfLValue(e);
149 return emitCast(e->getCastKind(), e->getSubExpr(), e->getType());
150 }
151 mlir::Value VisitCastExpr(CastExpr *e) {
152 if (const auto *ece = dyn_cast<ExplicitCastExpr>(e)) {
153 // Bind VLAs in the cast type.
154 if (ece->getType()->isVariablyModifiedType()) {
155 cgf.cgm.errorNYI(e->getExprLoc(),
156 "VisitCastExpr Bind VLAs in the cast type");
157 return {};
158 }
159 }
160
162 return emitLoadOfLValue(e);
163
164 return emitCast(e->getCastKind(), e->getSubExpr(), e->getType());
165 }
166 mlir::Value VisitCallExpr(const CallExpr *e);
167 mlir::Value VisitStmtExpr(const StmtExpr *e);
168
169 // Operators.
170 mlir::Value VisitPrePostIncDec(const UnaryOperator *e, cir::UnaryOpKind op,
171 bool isPre) {
172 LValue lv = cgf.emitLValue(e->getSubExpr());
173 return cgf.emitComplexPrePostIncDec(e, lv, op, isPre);
174 }
175 mlir::Value VisitUnaryPostDec(const UnaryOperator *e) {
176 return VisitPrePostIncDec(e, cir::UnaryOpKind::Dec, false);
177 }
178 mlir::Value VisitUnaryPostInc(const UnaryOperator *e) {
179 return VisitPrePostIncDec(e, cir::UnaryOpKind::Inc, false);
180 }
181 mlir::Value VisitUnaryPreDec(const UnaryOperator *e) {
182 return VisitPrePostIncDec(e, cir::UnaryOpKind::Dec, true);
183 }
184 mlir::Value VisitUnaryPreInc(const UnaryOperator *e) {
185 return VisitPrePostIncDec(e, cir::UnaryOpKind::Inc, true);
186 }
187 mlir::Value VisitUnaryDeref(const Expr *e) { return emitLoadOfLValue(e); }
188
189 mlir::Value VisitUnaryPlus(const UnaryOperator *e);
190 mlir::Value VisitUnaryMinus(const UnaryOperator *e);
191 mlir::Value VisitPlusMinus(const UnaryOperator *e, cir::UnaryOpKind kind,
192 QualType promotionType);
193 mlir::Value VisitUnaryNot(const UnaryOperator *e);
194 // LNot,Real,Imag never return complex.
195 mlir::Value VisitUnaryExtension(const UnaryOperator *e) {
196 return Visit(e->getSubExpr());
197 }
198 mlir::Value VisitCXXDefaultArgExpr(CXXDefaultArgExpr *dae) {
199 cgf.cgm.errorNYI(dae->getExprLoc(),
200 "ComplexExprEmitter VisitCXXDefaultArgExpr");
201 return {};
202 }
203 mlir::Value VisitCXXDefaultInitExpr(CXXDefaultInitExpr *die) {
204 CIRGenFunction::CXXDefaultInitExprScope scope(cgf, die);
205 return Visit(die->getExpr());
206 }
207 mlir::Value VisitExprWithCleanups(ExprWithCleanups *e) {
208 cgf.cgm.errorNYI(e->getExprLoc(),
209 "ComplexExprEmitter VisitExprWithCleanups");
210 return {};
211 }
212 mlir::Value VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *e) {
213 mlir::Location loc = cgf.getLoc(e->getExprLoc());
214 mlir::Type complexTy = cgf.convertType(e->getType());
215 return builder.getNullValue(complexTy, loc);
216 }
217 mlir::Value VisitImplicitValueInitExpr(ImplicitValueInitExpr *e) {
218 cgf.cgm.errorNYI(e->getExprLoc(),
219 "ComplexExprEmitter VisitImplicitValueInitExpr");
220 return {};
221 }
222
223 struct BinOpInfo {
224 mlir::Location loc;
225 mlir::Value lhs{};
226 mlir::Value rhs{};
227 QualType ty{}; // Computation Type.
228 FPOptions fpFeatures{};
229 };
230
231 BinOpInfo emitBinOps(const BinaryOperator *e,
232 QualType promotionTy = QualType());
233
234 mlir::Value emitPromoted(const Expr *e, QualType promotionTy);
235 mlir::Value emitPromotedComplexOperand(const Expr *e, QualType promotionTy);
236 LValue emitCompoundAssignLValue(
237 const CompoundAssignOperator *e,
238 mlir::Value (ComplexExprEmitter::*func)(const BinOpInfo &),
239 RValue &value);
240 mlir::Value emitCompoundAssign(
241 const CompoundAssignOperator *e,
242 mlir::Value (ComplexExprEmitter::*func)(const BinOpInfo &));
243
244 mlir::Value emitBinAdd(const BinOpInfo &op);
245 mlir::Value emitBinSub(const BinOpInfo &op);
246 mlir::Value emitBinMul(const BinOpInfo &op);
247 mlir::Value emitBinDiv(const BinOpInfo &op);
248
249 QualType getPromotionType(QualType ty, bool isDivOpCode = false) {
250 if (auto *complexTy = ty->getAs<ComplexType>()) {
251 QualType elementTy = complexTy->getElementType();
252 if (elementTy.UseExcessPrecision(cgf.getContext()))
253 return cgf.getContext().getComplexType(cgf.getContext().FloatTy);
254 }
255
256 if (ty.UseExcessPrecision(cgf.getContext()))
257 return cgf.getContext().FloatTy;
258 return QualType();
259 }
260
261#define HANDLEBINOP(OP) \
262 mlir::Value VisitBin##OP(const BinaryOperator *e) { \
263 QualType promotionTy = getPromotionType( \
264 e->getType(), e->getOpcode() == BinaryOperatorKind::BO_Div); \
265 mlir::Value result = emitBin##OP(emitBinOps(e, promotionTy)); \
266 if (!promotionTy.isNull()) \
267 result = cgf.emitUnPromotedValue(result, e->getType()); \
268 return result; \
269 }
270
271 HANDLEBINOP(Add)
272 HANDLEBINOP(Sub)
273 HANDLEBINOP(Mul)
274 HANDLEBINOP(Div)
275#undef HANDLEBINOP
276
277 mlir::Value VisitCXXRewrittenBinaryOperator(CXXRewrittenBinaryOperator *e) {
278 cgf.cgm.errorNYI(e->getExprLoc(),
279 "ComplexExprEmitter VisitCXXRewrittenBinaryOperator");
280 return {};
281 }
282
283 // Compound assignments.
284 mlir::Value VisitBinAddAssign(const CompoundAssignOperator *e) {
285 return emitCompoundAssign(e, &ComplexExprEmitter::emitBinAdd);
286 }
287 mlir::Value VisitBinSubAssign(const CompoundAssignOperator *e) {
288 return emitCompoundAssign(e, &ComplexExprEmitter::emitBinSub);
289 }
290 mlir::Value VisitBinMulAssign(const CompoundAssignOperator *e) {
291 return emitCompoundAssign(e, &ComplexExprEmitter::emitBinMul);
292 }
293 mlir::Value VisitBinDivAssign(const CompoundAssignOperator *e) {
294 return emitCompoundAssign(e, &ComplexExprEmitter::emitBinDiv);
295 }
296
297 // GCC rejects rem/and/or/xor for integer complex.
298 // Logical and/or always return int, never complex.
299
300 // No comparisons produce a complex result.
301
302 LValue emitBinAssignLValue(const BinaryOperator *e, mlir::Value &val);
303 mlir::Value VisitBinAssign(const BinaryOperator *e);
304 mlir::Value VisitBinComma(const BinaryOperator *e);
305
306 mlir::Value
307 VisitAbstractConditionalOperator(const AbstractConditionalOperator *e);
308 mlir::Value VisitChooseExpr(ChooseExpr *e);
309
310 mlir::Value VisitInitListExpr(InitListExpr *e);
311
312 mlir::Value VisitCompoundLiteralExpr(CompoundLiteralExpr *e) {
313 return emitLoadOfLValue(e);
314 }
315
316 mlir::Value VisitVAArgExpr(VAArgExpr *e);
317
318 mlir::Value VisitAtomicExpr(AtomicExpr *e) {
319 cgf.cgm.errorNYI(e->getExprLoc(), "ComplexExprEmitter VisitAtomicExpr");
320 return {};
321 }
322
323 mlir::Value VisitPackIndexingExpr(PackIndexingExpr *e) {
324 cgf.cgm.errorNYI(e->getExprLoc(),
325 "ComplexExprEmitter VisitPackIndexingExpr");
326 return {};
327 }
328};
329} // namespace
330
331//===----------------------------------------------------------------------===//
332// Utilities
333//===----------------------------------------------------------------------===//
334
335/// EmitLoadOfLValue - Given an RValue reference for a complex, emit code to
336/// load the real and imaginary pieces, returning them as Real/Imag.
337mlir::Value ComplexExprEmitter::emitLoadOfLValue(LValue lv,
338 SourceLocation loc) {
339 assert(lv.isSimple() && "non-simple complex l-value?");
340 if (lv.getType()->isAtomicType())
341 cgf.cgm.errorNYI(loc, "emitLoadOfLValue with Atomic LV");
342
343 const Address srcAddr = lv.getAddress();
344 return builder.createLoad(cgf.getLoc(loc), srcAddr);
345}
346
347/// EmitStoreOfComplex - Store the specified real/imag parts into the
348/// specified value pointer.
349void ComplexExprEmitter::emitStoreOfComplex(mlir::Location loc, mlir::Value val,
350 LValue lv, bool isInit) {
351 if (lv.getType()->isAtomicType() ||
352 (!isInit && cgf.isLValueSuitableForInlineAtomic(lv))) {
353 cgf.cgm.errorNYI(loc, "StoreOfComplex with Atomic LV");
354 return;
355 }
356
357 const Address destAddr = lv.getAddress();
358 builder.createStore(loc, val, destAddr);
359}
360
361//===----------------------------------------------------------------------===//
362// Visitor Methods
363//===----------------------------------------------------------------------===//
364
365mlir::Value ComplexExprEmitter::VisitExpr(Expr *e) {
366 cgf.cgm.errorNYI(e->getExprLoc(), "ComplexExprEmitter VisitExpr");
367 return {};
368}
369
370mlir::Value
371ComplexExprEmitter::VisitImaginaryLiteral(const ImaginaryLiteral *il) {
372 auto ty = mlir::cast<cir::ComplexType>(cgf.convertType(il->getType()));
373 mlir::Type elementTy = ty.getElementType();
374 mlir::Location loc = cgf.getLoc(il->getExprLoc());
375
376 mlir::TypedAttr realValueAttr;
377 mlir::TypedAttr imagValueAttr;
378
379 if (mlir::isa<cir::IntType>(elementTy)) {
380 llvm::APInt imagValue = cast<IntegerLiteral>(il->getSubExpr())->getValue();
381 realValueAttr = cir::IntAttr::get(elementTy, 0);
382 imagValueAttr = cir::IntAttr::get(elementTy, imagValue);
383 } else {
384 assert(mlir::isa<cir::FPTypeInterface>(elementTy) &&
385 "Expected complex element type to be floating-point");
386
387 llvm::APFloat imagValue =
388 cast<FloatingLiteral>(il->getSubExpr())->getValue();
389 realValueAttr = cir::FPAttr::get(
390 elementTy, llvm::APFloat::getZero(imagValue.getSemantics()));
391 imagValueAttr = cir::FPAttr::get(elementTy, imagValue);
392 }
393
394 auto complexAttr = cir::ConstComplexAttr::get(realValueAttr, imagValueAttr);
395 return builder.create<cir::ConstantOp>(loc, complexAttr);
396}
397
398mlir::Value ComplexExprEmitter::VisitCallExpr(const CallExpr *e) {
400 return emitLoadOfLValue(e);
401 return cgf.emitCallExpr(e).getComplexValue();
402}
403
404mlir::Value ComplexExprEmitter::VisitStmtExpr(const StmtExpr *e) {
405 cgf.cgm.errorNYI(e->getExprLoc(), "ComplexExprEmitter VisitExpr");
406 return {};
407}
408
409mlir::Value ComplexExprEmitter::emitComplexToComplexCast(mlir::Value val,
410 QualType srcType,
411 QualType destType,
412 SourceLocation loc) {
413 if (srcType == destType)
414 return val;
415
416 // Get the src/dest element type.
417 QualType srcElemTy = srcType->castAs<ComplexType>()->getElementType();
418 QualType destElemTy = destType->castAs<ComplexType>()->getElementType();
419
420 cir::CastKind castOpKind;
421 if (srcElemTy->isFloatingType() && destElemTy->isFloatingType())
422 castOpKind = cir::CastKind::float_complex;
423 else if (srcElemTy->isFloatingType() && destElemTy->isIntegerType())
424 castOpKind = cir::CastKind::float_complex_to_int_complex;
425 else if (srcElemTy->isIntegerType() && destElemTy->isFloatingType())
426 castOpKind = cir::CastKind::int_complex_to_float_complex;
427 else if (srcElemTy->isIntegerType() && destElemTy->isIntegerType())
428 castOpKind = cir::CastKind::int_complex;
429 else
430 llvm_unreachable("unexpected src type or dest type");
431
432 return builder.createCast(cgf.getLoc(loc), castOpKind, val,
433 cgf.convertType(destType));
434}
435
436mlir::Value ComplexExprEmitter::emitScalarToComplexCast(mlir::Value val,
437 QualType srcType,
438 QualType destType,
439 SourceLocation loc) {
440 cir::CastKind castOpKind;
441 if (srcType->isFloatingType())
442 castOpKind = cir::CastKind::float_to_complex;
443 else if (srcType->isIntegerType())
444 castOpKind = cir::CastKind::int_to_complex;
445 else
446 llvm_unreachable("unexpected src type");
447
448 return builder.createCast(cgf.getLoc(loc), castOpKind, val,
449 cgf.convertType(destType));
450}
451
452mlir::Value ComplexExprEmitter::emitCast(CastKind ck, Expr *op,
453 QualType destTy) {
454 switch (ck) {
455 case CK_Dependent:
456 llvm_unreachable("dependent type must be resolved before the CIR codegen");
457
458 case CK_NoOp:
459 case CK_LValueToRValue:
460 return Visit(op);
461
462 case CK_AtomicToNonAtomic:
463 case CK_NonAtomicToAtomic:
464 case CK_UserDefinedConversion: {
465 cgf.cgm.errorNYI(
466 "ComplexExprEmitter::emitCast Atmoic & UserDefinedConversion");
467 return {};
468 }
469
470 case CK_LValueBitCast: {
471 LValue origLV = cgf.emitLValue(op);
472 Address addr =
473 origLV.getAddress().withElementType(builder, cgf.convertType(destTy));
474 LValue destLV = cgf.makeAddrLValue(addr, destTy);
475 return emitLoadOfLValue(destLV, op->getExprLoc());
476 }
477
478 case CK_LValueToRValueBitCast: {
479 LValue sourceLVal = cgf.emitLValue(op);
480 Address addr = sourceLVal.getAddress().withElementType(
481 builder, cgf.convertTypeForMem(destTy));
482 LValue destLV = cgf.makeAddrLValue(addr, destTy);
484 return emitLoadOfLValue(destLV, op->getExprLoc());
485 }
486
487 case CK_BitCast:
488 case CK_BaseToDerived:
489 case CK_DerivedToBase:
490 case CK_UncheckedDerivedToBase:
491 case CK_Dynamic:
492 case CK_ToUnion:
493 case CK_ArrayToPointerDecay:
494 case CK_FunctionToPointerDecay:
495 case CK_NullToPointer:
496 case CK_NullToMemberPointer:
497 case CK_BaseToDerivedMemberPointer:
498 case CK_DerivedToBaseMemberPointer:
499 case CK_MemberPointerToBoolean:
500 case CK_ReinterpretMemberPointer:
501 case CK_ConstructorConversion:
502 case CK_IntegralToPointer:
503 case CK_PointerToIntegral:
504 case CK_PointerToBoolean:
505 case CK_ToVoid:
506 case CK_VectorSplat:
507 case CK_IntegralCast:
508 case CK_BooleanToSignedIntegral:
509 case CK_IntegralToBoolean:
510 case CK_IntegralToFloating:
511 case CK_FloatingToIntegral:
512 case CK_FloatingToBoolean:
513 case CK_FloatingCast:
514 case CK_CPointerToObjCPointerCast:
515 case CK_BlockPointerToObjCPointerCast:
516 case CK_AnyPointerToBlockPointerCast:
517 case CK_ObjCObjectLValueCast:
518 case CK_FloatingComplexToReal:
519 case CK_FloatingComplexToBoolean:
520 case CK_IntegralComplexToReal:
521 case CK_IntegralComplexToBoolean:
522 case CK_ARCProduceObject:
523 case CK_ARCConsumeObject:
524 case CK_ARCReclaimReturnedObject:
525 case CK_ARCExtendBlockObject:
526 case CK_CopyAndAutoreleaseBlockObject:
527 case CK_BuiltinFnToFnPtr:
528 case CK_ZeroToOCLOpaqueType:
529 case CK_AddressSpaceConversion:
530 case CK_IntToOCLSampler:
531 case CK_FloatingToFixedPoint:
532 case CK_FixedPointToFloating:
533 case CK_FixedPointCast:
534 case CK_FixedPointToBoolean:
535 case CK_FixedPointToIntegral:
536 case CK_IntegralToFixedPoint:
537 case CK_MatrixCast:
538 case CK_HLSLVectorTruncation:
539 case CK_HLSLArrayRValue:
540 case CK_HLSLElementwiseCast:
541 case CK_HLSLAggregateSplatCast:
542 llvm_unreachable("invalid cast kind for complex value");
543
544 case CK_FloatingRealToComplex:
545 case CK_IntegralRealToComplex: {
547 return emitScalarToComplexCast(cgf.emitScalarExpr(op), op->getType(),
548 destTy, op->getExprLoc());
549 }
550
551 case CK_FloatingComplexCast:
552 case CK_FloatingComplexToIntegralComplex:
553 case CK_IntegralComplexCast:
554 case CK_IntegralComplexToFloatingComplex: {
556 return emitComplexToComplexCast(Visit(op), op->getType(), destTy,
557 op->getExprLoc());
558 }
559 }
560
561 llvm_unreachable("unknown cast resulting in complex value");
562}
563
564mlir::Value ComplexExprEmitter::VisitUnaryPlus(const UnaryOperator *e) {
565 QualType promotionTy = getPromotionType(e->getSubExpr()->getType());
566 mlir::Value result = VisitPlusMinus(e, cir::UnaryOpKind::Plus, promotionTy);
567 if (!promotionTy.isNull())
568 return cgf.emitUnPromotedValue(result, e->getSubExpr()->getType());
569 return result;
570}
571
572mlir::Value ComplexExprEmitter::VisitUnaryMinus(const UnaryOperator *e) {
573 QualType promotionTy = getPromotionType(e->getSubExpr()->getType());
574 mlir::Value result = VisitPlusMinus(e, cir::UnaryOpKind::Minus, promotionTy);
575 if (!promotionTy.isNull())
576 return cgf.emitUnPromotedValue(result, e->getSubExpr()->getType());
577 return result;
578}
579
580mlir::Value ComplexExprEmitter::VisitPlusMinus(const UnaryOperator *e,
581 cir::UnaryOpKind kind,
582 QualType promotionType) {
583 assert(kind == cir::UnaryOpKind::Plus ||
584 kind == cir::UnaryOpKind::Minus &&
585 "Invalid UnaryOp kind for ComplexType Plus or Minus");
586
587 mlir::Value op;
588 if (!promotionType.isNull())
589 op = cgf.emitPromotedComplexExpr(e->getSubExpr(), promotionType);
590 else
591 op = Visit(e->getSubExpr());
592 return builder.createUnaryOp(cgf.getLoc(e->getExprLoc()), kind, op);
593}
594
595mlir::Value ComplexExprEmitter::VisitUnaryNot(const UnaryOperator *e) {
596 mlir::Value op = Visit(e->getSubExpr());
597 return builder.createNot(op);
598}
599
600mlir::Value ComplexExprEmitter::emitBinAdd(const BinOpInfo &op) {
603
604 if (mlir::isa<cir::ComplexType>(op.lhs.getType()) &&
605 mlir::isa<cir::ComplexType>(op.rhs.getType()))
606 return builder.create<cir::ComplexAddOp>(op.loc, op.lhs, op.rhs);
607
608 if (mlir::isa<cir::ComplexType>(op.lhs.getType())) {
609 mlir::Value real = builder.createComplexReal(op.loc, op.lhs);
610 mlir::Value imag = builder.createComplexImag(op.loc, op.lhs);
611 mlir::Value newReal = builder.createAdd(op.loc, real, op.rhs);
612 return builder.createComplexCreate(op.loc, newReal, imag);
613 }
614
615 assert(mlir::isa<cir::ComplexType>(op.rhs.getType()));
616 mlir::Value real = builder.createComplexReal(op.loc, op.rhs);
617 mlir::Value imag = builder.createComplexImag(op.loc, op.rhs);
618 mlir::Value newReal = builder.createAdd(op.loc, op.lhs, real);
619 return builder.createComplexCreate(op.loc, newReal, imag);
620}
621
622mlir::Value ComplexExprEmitter::emitBinSub(const BinOpInfo &op) {
625
626 if (mlir::isa<cir::ComplexType>(op.lhs.getType()) &&
627 mlir::isa<cir::ComplexType>(op.rhs.getType()))
628 return builder.create<cir::ComplexSubOp>(op.loc, op.lhs, op.rhs);
629
630 if (mlir::isa<cir::ComplexType>(op.lhs.getType())) {
631 mlir::Value real = builder.createComplexReal(op.loc, op.lhs);
632 mlir::Value imag = builder.createComplexImag(op.loc, op.lhs);
633 mlir::Value newReal = builder.createSub(op.loc, real, op.rhs);
634 return builder.createComplexCreate(op.loc, newReal, imag);
635 }
636
637 assert(mlir::isa<cir::ComplexType>(op.rhs.getType()));
638 mlir::Value real = builder.createComplexReal(op.loc, op.rhs);
639 mlir::Value imag = builder.createComplexImag(op.loc, op.rhs);
640 mlir::Value newReal = builder.createSub(op.loc, op.lhs, real);
641 return builder.createComplexCreate(op.loc, newReal, imag);
642}
643
644static cir::ComplexRangeKind
646 switch (range) {
648 return cir::ComplexRangeKind::Full;
650 return cir::ComplexRangeKind::Improved;
652 return cir::ComplexRangeKind::Promoted;
654 return cir::ComplexRangeKind::Basic;
656 // The default value for ComplexRangeKind is Full if no option is selected
657 return cir::ComplexRangeKind::Full;
658 }
659}
660
661mlir::Value ComplexExprEmitter::emitBinMul(const BinOpInfo &op) {
664
665 if (mlir::isa<cir::ComplexType>(op.lhs.getType()) &&
666 mlir::isa<cir::ComplexType>(op.rhs.getType())) {
667 cir::ComplexRangeKind rangeKind =
668 getComplexRangeAttr(op.fpFeatures.getComplexRange());
669 return builder.create<cir::ComplexMulOp>(op.loc, op.lhs, op.rhs, rangeKind);
670 }
671
672 if (mlir::isa<cir::ComplexType>(op.lhs.getType())) {
673 mlir::Value real = builder.createComplexReal(op.loc, op.lhs);
674 mlir::Value imag = builder.createComplexImag(op.loc, op.lhs);
675 mlir::Value newReal = builder.createMul(op.loc, real, op.rhs);
676 mlir::Value newImag = builder.createMul(op.loc, imag, op.rhs);
677 return builder.createComplexCreate(op.loc, newReal, newImag);
678 }
679
680 assert(mlir::isa<cir::ComplexType>(op.rhs.getType()));
681 mlir::Value real = builder.createComplexReal(op.loc, op.rhs);
682 mlir::Value imag = builder.createComplexImag(op.loc, op.rhs);
683 mlir::Value newReal = builder.createMul(op.loc, op.lhs, real);
684 mlir::Value newImag = builder.createMul(op.loc, op.lhs, imag);
685 return builder.createComplexCreate(op.loc, newReal, newImag);
686}
687
688mlir::Value ComplexExprEmitter::emitBinDiv(const BinOpInfo &op) {
691
692 // Handle division between two complex values. In the case of complex integer
693 // types mixed with scalar integers, the scalar integer type will always be
694 // promoted to a complex integer value with a zero imaginary component when
695 // the AST is formed.
696 if (mlir::isa<cir::ComplexType>(op.lhs.getType()) &&
697 mlir::isa<cir::ComplexType>(op.rhs.getType())) {
698 cir::ComplexRangeKind rangeKind =
699 getComplexRangeAttr(op.fpFeatures.getComplexRange());
700 return cir::ComplexDivOp::create(builder, op.loc, op.lhs, op.rhs,
701 rangeKind);
702 }
703
704 // The C99 standard (G.5.1) defines division of a complex value by a real
705 // value in the following simplified form.
706 if (mlir::isa<cir::ComplexType>(op.lhs.getType())) {
707 assert(mlir::cast<cir::ComplexType>(op.lhs.getType()).getElementType() ==
708 op.rhs.getType());
709 mlir::Value real = builder.createComplexReal(op.loc, op.lhs);
710 mlir::Value imag = builder.createComplexImag(op.loc, op.lhs);
711 mlir::Value newReal = builder.createFDiv(op.loc, real, op.rhs);
712 mlir::Value newImag = builder.createFDiv(op.loc, imag, op.rhs);
713 return builder.createComplexCreate(op.loc, newReal, newImag);
714 }
715
716 assert(mlir::isa<cir::ComplexType>(op.rhs.getType()));
717 cir::ConstantOp nullValue = builder.getNullValue(op.lhs.getType(), op.loc);
718 mlir::Value lhs = builder.createComplexCreate(op.loc, op.lhs, nullValue);
719 cir::ComplexRangeKind rangeKind =
720 getComplexRangeAttr(op.fpFeatures.getComplexRange());
721 return cir::ComplexDivOp::create(builder, op.loc, lhs, op.rhs, rangeKind);
722}
723
724mlir::Value CIRGenFunction::emitUnPromotedValue(mlir::Value result,
725 QualType unPromotionType) {
726 assert(!mlir::cast<cir::ComplexType>(result.getType()).isIntegerComplex() &&
727 "integral complex will never be promoted");
728 return builder.createCast(cir::CastKind::float_complex, result,
729 convertType(unPromotionType));
730}
731
732mlir::Value CIRGenFunction::emitPromotedValue(mlir::Value result,
733 QualType promotionType) {
734 assert(!mlir::cast<cir::ComplexType>(result.getType()).isIntegerComplex() &&
735 "integral complex will never be promoted");
736 return builder.createCast(cir::CastKind::float_complex, result,
737 convertType(promotionType));
738}
739
740mlir::Value ComplexExprEmitter::emitPromoted(const Expr *e,
741 QualType promotionTy) {
742 e = e->IgnoreParens();
743 if (const auto *bo = dyn_cast<BinaryOperator>(e)) {
744 switch (bo->getOpcode()) {
745#define HANDLE_BINOP(OP) \
746 case BO_##OP: \
747 return emitBin##OP(emitBinOps(bo, promotionTy));
748 HANDLE_BINOP(Add)
749 HANDLE_BINOP(Sub)
750 HANDLE_BINOP(Mul)
751 HANDLE_BINOP(Div)
752#undef HANDLE_BINOP
753 default:
754 break;
755 }
756 } else if (const auto *unaryOp = dyn_cast<UnaryOperator>(e)) {
757 switch (unaryOp->getOpcode()) {
758 case UO_Minus:
759 case UO_Plus: {
760 auto kind = unaryOp->getOpcode() == UO_Plus ? cir::UnaryOpKind::Plus
761 : cir::UnaryOpKind::Minus;
762 return VisitPlusMinus(unaryOp, kind, promotionTy);
763 }
764 default:
765 break;
766 }
767 }
768
769 mlir::Value result = Visit(const_cast<Expr *>(e));
770 if (!promotionTy.isNull())
771 return cgf.emitPromotedValue(result, promotionTy);
772
773 return result;
774}
775
777 QualType promotionType) {
778 return ComplexExprEmitter(*this).emitPromoted(e, promotionType);
779}
780
781mlir::Value
782ComplexExprEmitter::emitPromotedComplexOperand(const Expr *e,
783 QualType promotionTy) {
784 if (e->getType()->isAnyComplexType()) {
785 if (!promotionTy.isNull())
786 return cgf.emitPromotedComplexExpr(e, promotionTy);
787 return Visit(const_cast<Expr *>(e));
788 }
789
790 if (!promotionTy.isNull()) {
791 QualType complexElementTy =
792 promotionTy->castAs<ComplexType>()->getElementType();
793 return cgf.emitPromotedScalarExpr(e, complexElementTy);
794 }
795 return cgf.emitScalarExpr(e);
796}
797
798ComplexExprEmitter::BinOpInfo
799ComplexExprEmitter::emitBinOps(const BinaryOperator *e, QualType promotionTy) {
800 BinOpInfo binOpInfo{cgf.getLoc(e->getExprLoc())};
801 binOpInfo.lhs = emitPromotedComplexOperand(e->getLHS(), promotionTy);
802 binOpInfo.rhs = emitPromotedComplexOperand(e->getRHS(), promotionTy);
803 binOpInfo.ty = promotionTy.isNull() ? e->getType() : promotionTy;
804 binOpInfo.fpFeatures = e->getFPFeaturesInEffect(cgf.getLangOpts());
805 return binOpInfo;
806}
807
808LValue ComplexExprEmitter::emitCompoundAssignLValue(
809 const CompoundAssignOperator *e,
810 mlir::Value (ComplexExprEmitter::*func)(const BinOpInfo &), RValue &value) {
811 QualType lhsTy = e->getLHS()->getType();
812 QualType rhsTy = e->getRHS()->getType();
813 SourceLocation exprLoc = e->getExprLoc();
814 mlir::Location loc = cgf.getLoc(exprLoc);
815
816 if (lhsTy->getAs<AtomicType>()) {
817 cgf.cgm.errorNYI("emitCompoundAssignLValue AtmoicType");
818 return {};
819 }
820
821 BinOpInfo opInfo{loc};
822 opInfo.fpFeatures = e->getFPFeaturesInEffect(cgf.getLangOpts());
823
825
826 // Load the RHS and LHS operands.
827 // __block variables need to have the rhs evaluated first, plus this should
828 // improve codegen a little.
829 QualType promotionTypeCR = getPromotionType(e->getComputationResultType());
830 opInfo.ty = promotionTypeCR.isNull() ? e->getComputationResultType()
831 : promotionTypeCR;
832
833 QualType complexElementTy =
834 opInfo.ty->castAs<ComplexType>()->getElementType();
835 QualType promotionTypeRHS = getPromotionType(rhsTy);
836
837 // The RHS should have been converted to the computation type.
838 if (e->getRHS()->getType()->isRealFloatingType()) {
839 if (!promotionTypeRHS.isNull()) {
840 opInfo.rhs = cgf.emitPromotedScalarExpr(e->getRHS(), promotionTypeRHS);
841 } else {
842 assert(cgf.getContext().hasSameUnqualifiedType(complexElementTy, rhsTy));
843 opInfo.rhs = cgf.emitScalarExpr(e->getRHS());
844 }
845 } else {
846 if (!promotionTypeRHS.isNull()) {
847 opInfo.rhs = cgf.emitPromotedComplexExpr(e->getRHS(), promotionTypeRHS);
848 } else {
849 assert(cgf.getContext().hasSameUnqualifiedType(opInfo.ty, rhsTy));
850 opInfo.rhs = Visit(e->getRHS());
851 }
852 }
853
854 LValue lhs = cgf.emitLValue(e->getLHS());
855
856 // Load from the l-value and convert it.
857 QualType promotionTypeLHS = getPromotionType(e->getComputationLHSType());
858 if (lhsTy->isAnyComplexType()) {
859 mlir::Value lhsValue = emitLoadOfLValue(lhs, exprLoc);
860 QualType destTy = promotionTypeLHS.isNull() ? opInfo.ty : promotionTypeLHS;
861 opInfo.lhs = emitComplexToComplexCast(lhsValue, lhsTy, destTy, exprLoc);
862 } else {
863 mlir::Value lhsVal = cgf.emitLoadOfScalar(lhs, exprLoc);
864 // For floating point real operands we can directly pass the scalar form
865 // to the binary operator emission and potentially get more efficient code.
866 if (lhsTy->isRealFloatingType()) {
867 QualType promotedComplexElementTy;
868 if (!promotionTypeLHS.isNull()) {
869 promotedComplexElementTy =
870 cast<ComplexType>(promotionTypeLHS)->getElementType();
871 if (!cgf.getContext().hasSameUnqualifiedType(promotedComplexElementTy,
872 promotionTypeLHS))
873 lhsVal = cgf.emitScalarConversion(lhsVal, lhsTy,
874 promotedComplexElementTy, exprLoc);
875 } else {
876 if (!cgf.getContext().hasSameUnqualifiedType(complexElementTy, lhsTy))
877 lhsVal = cgf.emitScalarConversion(lhsVal, lhsTy, complexElementTy,
878 exprLoc);
879 }
880 opInfo.lhs = lhsVal;
881 } else {
882 opInfo.lhs = emitScalarToComplexCast(lhsVal, lhsTy, opInfo.ty, exprLoc);
883 }
884 }
885
886 // Expand the binary operator.
887 mlir::Value result = (this->*func)(opInfo);
888
889 // Truncate the result and store it into the LHS lvalue.
890 if (lhsTy->isAnyComplexType()) {
891 mlir::Value resultValue =
892 emitComplexToComplexCast(result, opInfo.ty, lhsTy, exprLoc);
893 emitStoreOfComplex(loc, resultValue, lhs, /*isInit*/ false);
894 value = RValue::getComplex(resultValue);
895 } else {
896 mlir::Value resultValue =
897 cgf.emitComplexToScalarConversion(result, opInfo.ty, lhsTy, exprLoc);
898 cgf.emitStoreOfScalar(resultValue, lhs, /*isInit*/ false);
899 value = RValue::get(resultValue);
900 }
901
902 return lhs;
903}
904
905mlir::Value ComplexExprEmitter::emitCompoundAssign(
906 const CompoundAssignOperator *e,
907 mlir::Value (ComplexExprEmitter::*func)(const BinOpInfo &)) {
908 RValue val;
909 LValue lv = emitCompoundAssignLValue(e, func, val);
910
911 // The result of an assignment in C is the assigned r-value.
912 if (!cgf.getLangOpts().CPlusPlus)
913 return val.getComplexValue();
914
915 // If the lvalue is non-volatile, return the computed value of the assignment.
916 if (!lv.isVolatileQualified())
917 return val.getComplexValue();
918
919 return emitLoadOfLValue(lv, e->getExprLoc());
920}
921
922LValue ComplexExprEmitter::emitBinAssignLValue(const BinaryOperator *e,
923 mlir::Value &value) {
924 assert(cgf.getContext().hasSameUnqualifiedType(e->getLHS()->getType(),
925 e->getRHS()->getType()) &&
926 "Invalid assignment");
927
928 // Emit the RHS. __block variables need the RHS evaluated first.
929 value = Visit(e->getRHS());
930
931 // Compute the address to store into.
932 LValue lhs = cgf.emitLValue(e->getLHS());
933
934 // Store the result value into the LHS lvalue.
935 emitStoreOfComplex(cgf.getLoc(e->getExprLoc()), value, lhs,
936 /*isInit*/ false);
937 return lhs;
938}
939
940mlir::Value ComplexExprEmitter::VisitBinAssign(const BinaryOperator *e) {
941 mlir::Value value;
942 LValue lv = emitBinAssignLValue(e, value);
943
944 // The result of an assignment in C is the assigned r-value.
945 if (!cgf.getLangOpts().CPlusPlus)
946 return value;
947
948 // If the lvalue is non-volatile, return the computed value of the
949 // assignment.
950 if (!lv.isVolatile())
951 return value;
952
953 return emitLoadOfLValue(lv, e->getExprLoc());
954}
955
956mlir::Value ComplexExprEmitter::VisitBinComma(const BinaryOperator *e) {
957 cgf.emitIgnoredExpr(e->getLHS());
958 return Visit(e->getRHS());
959}
960
961mlir::Value ComplexExprEmitter::VisitAbstractConditionalOperator(
962 const AbstractConditionalOperator *e) {
963 mlir::Location loc = cgf.getLoc(e->getSourceRange());
964
965 // Bind the common expression if necessary.
966 CIRGenFunction::OpaqueValueMapping binding(cgf, e);
967
968 CIRGenFunction::ConditionalEvaluation eval(cgf);
969
970 Expr *cond = e->getCond()->IgnoreParens();
971 mlir::Value condValue = cgf.evaluateExprAsBool(cond);
972
973 return builder
974 .create<cir::TernaryOp>(
975 loc, condValue,
976 /*thenBuilder=*/
977 [&](mlir::OpBuilder &b, mlir::Location loc) {
978 eval.beginEvaluation();
979 mlir::Value trueValue = Visit(e->getTrueExpr());
980 b.create<cir::YieldOp>(loc, trueValue);
981 eval.endEvaluation();
982 },
983 /*elseBuilder=*/
984 [&](mlir::OpBuilder &b, mlir::Location loc) {
985 eval.beginEvaluation();
986 mlir::Value falseValue = Visit(e->getFalseExpr());
987 b.create<cir::YieldOp>(loc, falseValue);
988 eval.endEvaluation();
989 })
990 .getResult();
991}
992
993mlir::Value ComplexExprEmitter::VisitChooseExpr(ChooseExpr *e) {
994 return Visit(e->getChosenSubExpr());
995}
996
997mlir::Value ComplexExprEmitter::VisitInitListExpr(InitListExpr *e) {
998 mlir::Location loc = cgf.getLoc(e->getExprLoc());
999 if (e->getNumInits() == 2) {
1000 mlir::Value real = cgf.emitScalarExpr(e->getInit(0));
1001 mlir::Value imag = cgf.emitScalarExpr(e->getInit(1));
1002 return builder.createComplexCreate(loc, real, imag);
1003 }
1004
1005 if (e->getNumInits() == 1)
1006 return Visit(e->getInit(0));
1007
1008 assert(e->getNumInits() == 0 && "Unexpected number of inits");
1009 mlir::Type complexTy = cgf.convertType(e->getType());
1010 return builder.getNullValue(complexTy, loc);
1011}
1012
1013mlir::Value ComplexExprEmitter::VisitVAArgExpr(VAArgExpr *e) {
1014 return cgf.emitVAArg(e);
1015}
1016
1017//===----------------------------------------------------------------------===//
1018// Entry Point into this File
1019//===----------------------------------------------------------------------===//
1020
1021/// EmitComplexExpr - Emit the computation of the specified expression of
1022/// complex type, ignoring the result.
1024 assert(e && getComplexType(e->getType()) &&
1025 "Invalid complex expression to emit");
1026
1027 return ComplexExprEmitter(*this).Visit(const_cast<Expr *>(e));
1028}
1029
1031 bool isInit) {
1032 assert(e && getComplexType(e->getType()) &&
1033 "Invalid complex expression to emit");
1034 ComplexExprEmitter emitter(*this);
1035 mlir::Value value = emitter.Visit(const_cast<Expr *>(e));
1036 emitter.emitStoreOfComplex(getLoc(e->getExprLoc()), value, dest, isInit);
1037}
1038
1039/// EmitStoreOfComplex - Store a complex number into the specified l-value.
1040void CIRGenFunction::emitStoreOfComplex(mlir::Location loc, mlir::Value v,
1041 LValue dest, bool isInit) {
1042 ComplexExprEmitter(*this).emitStoreOfComplex(loc, v, dest, isInit);
1043}
1044
1046 return ComplexExprEmitter(*this).emitLoadOfLValue(src, loc);
1047}
1048
1050 assert(e->getOpcode() == BO_Assign && "Expected assign op");
1051
1052 mlir::Value value; // ignored
1053 LValue lvalue = ComplexExprEmitter(*this).emitBinAssignLValue(e, value);
1054 if (getLangOpts().OpenMP)
1055 cgm.errorNYI("emitComplexAssignmentLValue OpenMP");
1056
1057 return lvalue;
1058}
1059
1061 mlir::Value (ComplexExprEmitter::*)(const ComplexExprEmitter::BinOpInfo &);
1062
1064 switch (op) {
1065 case BO_MulAssign:
1066 return &ComplexExprEmitter::emitBinMul;
1067 case BO_DivAssign:
1068 return &ComplexExprEmitter::emitBinDiv;
1069 case BO_SubAssign:
1070 return &ComplexExprEmitter::emitBinSub;
1071 case BO_AddAssign:
1072 return &ComplexExprEmitter::emitBinAdd;
1073 default:
1074 llvm_unreachable("unexpected complex compound assignment");
1075 }
1076}
1077
1079 const CompoundAssignOperator *e) {
1081 RValue val;
1082 return ComplexExprEmitter(*this).emitCompoundAssignLValue(e, op, val);
1083}
1084
1086 LValue lv,
1087 cir::UnaryOpKind op,
1088 bool isPre) {
1089 assert(op == cir::UnaryOpKind::Inc ||
1090 op == cir::UnaryOpKind::Dec && "Invalid UnaryOp kind for ComplexType");
1091
1092 mlir::Value inVal = emitLoadOfComplex(lv, e->getExprLoc());
1093 mlir::Location loc = getLoc(e->getExprLoc());
1094 mlir::Value incVal = builder.createUnaryOp(loc, op, inVal);
1095
1096 // Store the updated result through the lvalue.
1097 emitStoreOfComplex(loc, incVal, lv, /*isInit=*/false);
1098
1099 if (getLangOpts().OpenMP)
1100 cgm.errorNYI(loc, "emitComplexPrePostIncDec OpenMP");
1101
1102 // If this is a postinc, return the value read from memory, otherwise use the
1103 // updated value.
1104 return isPre ? incVal : inVal;
1105}
1106
1108 const CompoundAssignOperator *e, mlir::Value &result) {
1109 // Key Instructions: Don't need to create an atom group here; one will already
1110 // be active through scalar handling code.
1112 RValue value;
1113 LValue ret = ComplexExprEmitter(*this).emitCompoundAssignLValue(e, op, value);
1114 result = value.getValue();
1115 return ret;
1116}
#define HANDLEBINOP(OP)
static CompoundFunc getComplexOp(BinaryOperatorKind op)
static const ComplexType * getComplexType(QualType type)
Return the complex type that we are meant to emit.
mlir::Value(ComplexExprEmitter::*)(const ComplexExprEmitter::BinOpInfo &) CompoundFunc
static cir::ComplexRangeKind getComplexRangeAttr(LangOptions::ComplexRangeKind range)
#define HANDLE_BINOP(OP)
__device__ __2f16 b
__device__ __2f16 float __ockl_bool s
cir::ConstantOp getNullValue(mlir::Type ty, mlir::Location loc)
mlir::Value createCast(mlir::Location loc, cir::CastKind kind, mlir::Value src, mlir::Type newTy)
mlir::Value createAdd(mlir::Location loc, mlir::Value lhs, mlir::Value rhs, OverflowBehavior ob=OverflowBehavior::None)
mlir::Value createNot(mlir::Value value)
mlir::Value createComplexImag(mlir::Location loc, mlir::Value operand)
mlir::Value createSub(mlir::Location loc, mlir::Value lhs, mlir::Value rhs, OverflowBehavior ob=OverflowBehavior::Saturated)
mlir::Value createMul(mlir::Location loc, mlir::Value lhs, mlir::Value rhs, OverflowBehavior ob=OverflowBehavior::None)
mlir::Value createComplexCreate(mlir::Location loc, mlir::Value real, mlir::Value imag)
mlir::Value createUnaryOp(mlir::Location loc, cir::UnaryOpKind kind, mlir::Value operand)
mlir::Value createComplexReal(mlir::Location loc, mlir::Value operand)
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
Expr * getCond() const
getCond - Return the expression representing the condition for the ?
Definition Expr.h:4465
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression representing the value of the expression if the condition eval...
Definition Expr.h:4471
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression representing the value of the expression if the condition eva...
Definition Expr.h:4477
A builtin binary operation expression such as "x + y" or "x <= y".
Definition Expr.h:3972
Expr * getLHS() const
Definition Expr.h:4022
SourceLocation getExprLoc() const
Definition Expr.h:4013
Expr * getRHS() const
Definition Expr.h:4024
FPOptions getFPFeaturesInEffect(const LangOptions &LO) const
Get the FP features status of this operator.
Definition Expr.h:4185
Opcode getOpcode() const
Definition Expr.h:4017
mlir::Value createFDiv(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
cir::LoadOp createLoad(mlir::Location loc, Address addr, bool isVolatile=false)
cir::StoreOp createStore(mlir::Location loc, mlir::Value val, Address dst, bool isVolatile=false, mlir::IntegerAttr align={}, cir::MemOrderAttr order={})
LValue getReferenceLValue(CIRGenFunction &cgf, Expr *refExpr) const
mlir::Value emitComplexToScalarConversion(mlir::Value src, QualType srcTy, QualType dstTy, SourceLocation loc)
Emit a conversion from the specified complex type to the specified destination type,...
mlir::Type convertType(clang::QualType t)
mlir::Value emitPromotedValue(mlir::Value result, QualType promotionType)
const clang::LangOptions & getLangOpts() const
LValue emitScalarCompoundAssignWithComplex(const CompoundAssignOperator *e, mlir::Value &result)
mlir::Value emitComplexExpr(const Expr *e)
Emit the computation of the specified expression of complex type, returning the result.
RValue emitCallExpr(const clang::CallExpr *e, ReturnValueSlot returnValue=ReturnValueSlot())
LValue emitLValue(const clang::Expr *e)
Emit code to compute a designator that specifies the location of the expression.
mlir::Value evaluateExprAsBool(const clang::Expr *e)
Perform the usual unary conversions on the specified expression and compare the result against zero,...
void emitStoreOfScalar(mlir::Value value, Address addr, bool isVolatile, clang::QualType ty, bool isInit=false, bool isNontemporal=false)
LValue emitComplexCompoundAssignmentLValue(const CompoundAssignOperator *e)
mlir::Location getLoc(clang::SourceLocation srcLoc)
Helpers to convert Clang's SourceLocation to a MLIR Location.
mlir::Value emitScalarConversion(mlir::Value src, clang::QualType srcType, clang::QualType dstType, clang::SourceLocation loc)
Emit a conversion from the specified type to the specified destination type, both of which are CIR sc...
mlir::Value emitPromotedComplexExpr(const Expr *e, QualType promotionType)
mlir::Value emitUnPromotedValue(mlir::Value result, QualType unPromotionType)
mlir::Type convertTypeForMem(QualType t)
mlir::Value emitLoadOfComplex(LValue src, SourceLocation loc)
Load a complex number from the specified l-value.
mlir::Value emitComplexPrePostIncDec(const UnaryOperator *e, LValue lv, cir::UnaryOpKind op, bool isPre)
void emitStoreOfComplex(mlir::Location loc, mlir::Value v, LValue dest, bool isInit)
EmitStoreOfComplex - Store a complex number into the specified l-value.
LValue emitComplexAssignmentLValue(const BinaryOperator *e)
mlir::Value emitScalarExpr(const clang::Expr *e)
Emit the computation of the specified expression of scalar type.
mlir::Value emitPromotedScalarExpr(const Expr *e, QualType promotionType)
mlir::Value emitLoadOfScalar(LValue lvalue, SourceLocation loc)
EmitLoadOfScalar - Load a scalar value from an address, taking care to appropriately convert from the...
void emitComplexExprIntoLValue(const Expr *e, LValue dest, bool isInit)
LValue makeAddrLValue(Address addr, QualType ty, AlignmentSource source=AlignmentSource::Type)
clang::ASTContext & getContext() const
bool isLValueSuitableForInlineAtomic(LValue lv)
An LValue is a candidate for having its loads and stores be made atomic if we are operating under /vo...
void emitIgnoredExpr(const clang::Expr *e)
Emit code to compute the specified expression, ignoring the result.
mlir::Value emitVAArg(VAArgExpr *ve)
Generate code to get an argument from the passed in pointer and update it accordingly.
DiagnosticBuilder errorNYI(SourceLocation, llvm::StringRef)
Helpers to emit "not yet implemented" error diagnostics.
This trivial value class is used to represent the result of an expression that is evaluated.
Definition CIRGenValue.h:33
static RValue get(mlir::Value v)
Definition CIRGenValue.h:82
static RValue getComplex(mlir::Value v)
Definition CIRGenValue.h:90
mlir::Value getValue() const
Return the value of this scalar value.
Definition CIRGenValue.h:56
mlir::Value getComplexValue() const
Return the value of this complex value.
Definition CIRGenValue.h:62
SourceLocation getExprLoc() const
Definition ExprCXX.h:1352
Expr * getExpr()
Get the initialization expression that will be used.
Definition ExprCXX.cpp:1105
A rewritten comparison expression that was originally written using operator syntax.
Definition ExprCXX.h:286
SourceLocation getExprLoc() const LLVM_READONLY
Definition ExprCXX.h:341
QualType getCallReturnType(const ASTContext &Ctx) const
getCallReturnType - Get the return type of the call expr.
Definition Expr.cpp:1599
CastKind getCastKind() const
Definition Expr.h:3654
bool changesVolatileQualification() const
Return.
Definition Expr.h:3744
Expr * getSubExpr()
Definition Expr.h:3660
Expr * getChosenSubExpr() const
getChosenSubExpr - Return the subexpression chosen according to the condition.
Definition Expr.h:4818
Complex values, per C99 6.2.5p11.
Definition TypeBase.h:3275
CompoundAssignOperator - For compound assignments (e.g.
Definition Expr.h:4234
QualType getComputationLHSType() const
Definition Expr.h:4268
QualType getComputationResultType() const
Definition Expr.h:4271
This represents one expression.
Definition Expr.h:112
bool isGLValue() const
Definition Expr.h:287
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
Definition Expr.cpp:3081
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition Expr.cpp:273
QualType getType() const
Definition Expr.h:144
Expr * getResultExpr()
Return the result expression of this controlling expression.
Definition Expr.h:6396
const Expr * getSubExpr() const
Definition Expr.h:1743
unsigned getNumInits() const
Definition Expr.h:5263
const Expr * getInit(unsigned Init) const
Definition Expr.h:5287
ComplexRangeKind
Controls the various implementations for complex multiplication and.
@ CX_Full
Implementation of complex division and multiplication using a call to runtime library functions(gener...
@ CX_Basic
Implementation of complex division and multiplication using algebraic formulas at source precision.
@ CX_Promoted
Implementation of complex division using algebraic formulas at higher precision.
@ CX_None
No range rule is enabled.
@ CX_Improved
Implementation of complex division offering an improved handling for overflow in intermediate calcula...
Expr * getBase() const
Definition Expr.h:3375
SourceLocation getExprLoc() const LLVM_READONLY
Definition Expr.h:1208
const Expr * getSubExpr() const
Definition Expr.h:2199
SourceLocation getExprLoc() const LLVM_READONLY
Definition Expr.h:6776
A (possibly-)qualified type.
Definition TypeBase.h:937
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition TypeBase.h:1004
bool UseExcessPrecision(const ASTContext &Ctx)
Definition Type.cpp:1612
Encodes a location in the source.
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
SourceRange getSourceRange() const LLVM_READONLY
SourceLocation tokens are not useful in isolation - they are low level value objects created/interpre...
Definition Stmt.cpp:334
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
Definition TypeBase.h:8922
const T * castAs() const
Member-template castAs<specific type>.
Definition TypeBase.h:9165
bool isReferenceType() const
Definition TypeBase.h:8546
bool isAnyComplexType() const
Definition TypeBase.h:8657
bool isRealFloatingType() const
Floating point categories.
Definition Type.cpp:2320
bool isFloatingType() const
Definition Type.cpp:2304
const T * getAs() const
Member-template getAs<specific type>'.
Definition TypeBase.h:9098
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition Expr.h:2244
SourceLocation getExprLoc() const
Definition Expr.h:2368
Expr * getSubExpr() const
Definition Expr.h:2285
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
The JSON file list parser is used to communicate input to InstallAPI.
CastKind
CastKind - The kind of operation required for a conversion.
U cast(CodeGen::Address addr)
Definition Address.h:327
static bool cgFPOptionsRAII()
static bool fastMathFlags()