21class ComplexExprEmitter :
public StmtVisitor<ComplexExprEmitter, mlir::Value> {
23 CIRGenBuilderTy &builder;
26 explicit ComplexExprEmitter(CIRGenFunction &cgf)
27 : cgf(cgf), builder(cgf.getBuilder()) {}
36 mlir::Value emitLoadOfLValue(
const Expr *e) {
37 return emitLoadOfLValue(cgf.emitLValue(e), e->
getExprLoc());
40 mlir::Value emitLoadOfLValue(LValue lv, SourceLocation loc);
44 void emitStoreOfComplex(mlir::Location loc, mlir::Value val, LValue lv,
48 mlir::Value emitComplexToComplexCast(mlir::Value value, QualType srcType,
49 QualType destType, SourceLocation loc);
52 mlir::Value emitScalarToComplexCast(mlir::Value value, QualType srcType,
53 QualType destType, SourceLocation loc);
59 mlir::Value Visit(Expr *e) {
60 return StmtVisitor<ComplexExprEmitter, mlir::Value>::Visit(e);
63 mlir::Value VisitStmt(Stmt *
s) {
64 s->dump(llvm::errs(), cgf.getContext());
65 llvm_unreachable(
"Stmt can't have complex result type!");
68 mlir::Value VisitExpr(Expr *e);
69 mlir::Value VisitConstantExpr(ConstantExpr *e) {
70 if (mlir::Attribute result = ConstantEmitter(cgf).tryEmitConstantExpr(e))
72 mlir::cast<mlir::TypedAttr>(result));
75 "ComplexExprEmitter VisitConstantExpr non constantexpr");
79 mlir::Value VisitParenExpr(ParenExpr *pe) {
return Visit(pe->
getSubExpr()); }
80 mlir::Value VisitGenericSelectionExpr(GenericSelectionExpr *ge) {
83 mlir::Value VisitImaginaryLiteral(
const ImaginaryLiteral *il);
85 VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *pe) {
88 mlir::Value VisitCoawaitExpr(CoawaitExpr *
s) {
89 cgf.cgm.errorNYI(
s->getExprLoc(),
"ComplexExprEmitter VisitCoawaitExpr");
92 mlir::Value VisitCoyieldExpr(CoyieldExpr *
s) {
93 cgf.cgm.errorNYI(
s->getExprLoc(),
"ComplexExprEmitter VisitCoyieldExpr");
96 mlir::Value VisitUnaryCoawait(
const UnaryOperator *e) {
97 cgf.cgm.errorNYI(e->
getExprLoc(),
"ComplexExprEmitter VisitUnaryCoawait");
101 mlir::Value emitConstant(
const CIRGenFunction::ConstantEmission &constant,
103 assert(constant &&
"not a constant");
108 mlir::TypedAttr valueAttr = constant.
getValue();
109 return builder.getConstant(cgf.getLoc(e->
getSourceRange()), valueAttr);
113 mlir::Value VisitDeclRefExpr(DeclRefExpr *e) {
114 if (CIRGenFunction::ConstantEmission constant = cgf.tryEmitAsConstant(e))
115 return emitConstant(constant, e);
116 return emitLoadOfLValue(e);
118 mlir::Value VisitObjCIvarRefExpr(ObjCIvarRefExpr *e) {
120 "ComplexExprEmitter VisitObjCIvarRefExpr");
123 mlir::Value VisitObjCMessageExpr(ObjCMessageExpr *e) {
125 "ComplexExprEmitter VisitObjCMessageExpr");
128 mlir::Value VisitArraySubscriptExpr(Expr *e) {
return emitLoadOfLValue(e); }
129 mlir::Value VisitMemberExpr(MemberExpr *me) {
130 if (CIRGenFunction::ConstantEmission constant = cgf.tryEmitAsConstant(me)) {
131 cgf.emitIgnoredExpr(me->
getBase());
132 return emitConstant(constant, me);
134 return emitLoadOfLValue(me);
136 mlir::Value VisitOpaqueValueExpr(OpaqueValueExpr *e) {
138 return emitLoadOfLValue(cgf.getOrCreateOpaqueLValueMapping(e),
140 return cgf.getOrCreateOpaqueRValueMapping(e).getComplexValue();
143 mlir::Value VisitPseudoObjectExpr(PseudoObjectExpr *e) {
145 "ComplexExprEmitter VisitPseudoObjectExpr");
149 mlir::Value emitCast(
CastKind ck, Expr *op, QualType destTy);
150 mlir::Value VisitImplicitCastExpr(ImplicitCastExpr *e) {
154 return emitLoadOfLValue(e);
157 mlir::Value VisitCastExpr(
CastExpr *e) {
158 if (
const auto *ece = dyn_cast<ExplicitCastExpr>(e)) {
160 if (ece->getType()->isVariablyModifiedType()) {
162 "VisitCastExpr Bind VLAs in the cast type");
168 return emitLoadOfLValue(e);
172 mlir::Value VisitCallExpr(
const CallExpr *e);
173 mlir::Value VisitStmtExpr(
const StmtExpr *e);
176 mlir::Value VisitPrePostIncDec(
const UnaryOperator *e) {
178 return cgf.emitComplexPrePostIncDec(e, lv);
180 mlir::Value VisitUnaryPostDec(
const UnaryOperator *e) {
181 return VisitPrePostIncDec(e);
183 mlir::Value VisitUnaryPostInc(
const UnaryOperator *e) {
184 return VisitPrePostIncDec(e);
186 mlir::Value VisitUnaryPreDec(
const UnaryOperator *e) {
187 return VisitPrePostIncDec(e);
189 mlir::Value VisitUnaryPreInc(
const UnaryOperator *e) {
190 return VisitPrePostIncDec(e);
192 mlir::Value VisitUnaryDeref(
const Expr *e) {
return emitLoadOfLValue(e); }
194 mlir::Value VisitUnaryPlus(
const UnaryOperator *e);
195 mlir::Value VisitUnaryPlus(
const UnaryOperator *e, QualType promotionType);
196 mlir::Value VisitUnaryMinus(
const UnaryOperator *e);
197 mlir::Value VisitUnaryMinus(
const UnaryOperator *e, QualType promotionType);
198 mlir::Value VisitUnaryNot(
const UnaryOperator *e);
200 mlir::Value VisitUnaryExtension(
const UnaryOperator *e) {
203 mlir::Value VisitCXXDefaultArgExpr(CXXDefaultArgExpr *dae) {
204 CIRGenFunction::CXXDefaultArgExprScope scope(cgf, dae);
207 mlir::Value VisitCXXDefaultInitExpr(CXXDefaultInitExpr *die) {
208 CIRGenFunction::CXXDefaultInitExprScope scope(cgf, die);
211 mlir::Value VisitExprWithCleanups(ExprWithCleanups *e) {
212 CIRGenFunction::RunCleanupsScope scope(cgf);
213 mlir::Value complexVal = Visit(e->
getSubExpr());
216 scope.forceCleanup({&complexVal});
219 mlir::Value VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *e) {
220 mlir::Location loc = cgf.getLoc(e->
getExprLoc());
221 mlir::Type complexTy = cgf.convertType(e->
getType());
222 return builder.getNullValue(complexTy, loc);
224 mlir::Value VisitImplicitValueInitExpr(ImplicitValueInitExpr *e) {
225 mlir::Location loc = cgf.getLoc(e->
getExprLoc());
226 mlir::Type complexTy = cgf.convertType(e->
getType());
227 return builder.getNullValue(complexTy, loc);
235 FPOptions fpFeatures{};
238 BinOpInfo emitBinOps(
const BinaryOperator *e,
239 QualType promotionTy = QualType());
241 mlir::Value emitPromoted(
const Expr *e, QualType promotionTy);
242 mlir::Value emitPromotedComplexOperand(
const Expr *e, QualType promotionTy);
243 LValue emitCompoundAssignLValue(
244 const CompoundAssignOperator *e,
245 mlir::Value (ComplexExprEmitter::*func)(
const BinOpInfo &),
247 mlir::Value emitCompoundAssign(
248 const CompoundAssignOperator *e,
249 mlir::Value (ComplexExprEmitter::*func)(
const BinOpInfo &));
251 mlir::Value emitBinAdd(
const BinOpInfo &op);
252 mlir::Value emitBinSub(
const BinOpInfo &op);
253 mlir::Value emitBinMul(
const BinOpInfo &op);
254 mlir::Value emitBinDiv(
const BinOpInfo &op);
256 QualType getPromotionType(QualType ty,
bool isDivOpCode =
false) {
257 if (
auto *complexTy = ty->
getAs<ComplexType>()) {
258 QualType elementTy = complexTy->getElementType();
260 return cgf.getContext().getComplexType(cgf.getContext().FloatTy);
264 return cgf.getContext().FloatTy;
268#define HANDLEBINOP(OP) \
269 mlir::Value VisitBin##OP(const BinaryOperator *e) { \
270 QualType promotionTy = getPromotionType( \
271 e->getType(), e->getOpcode() == BinaryOperatorKind::BO_Div); \
272 mlir::Value result = emitBin##OP(emitBinOps(e, promotionTy)); \
273 if (!promotionTy.isNull()) \
274 result = cgf.emitUnPromotedValue(result, e->getType()); \
286 "ComplexExprEmitter VisitCXXRewrittenBinaryOperator");
291 mlir::Value VisitBinAddAssign(
const CompoundAssignOperator *e) {
292 return emitCompoundAssign(e, &ComplexExprEmitter::emitBinAdd);
294 mlir::Value VisitBinSubAssign(
const CompoundAssignOperator *e) {
295 return emitCompoundAssign(e, &ComplexExprEmitter::emitBinSub);
297 mlir::Value VisitBinMulAssign(
const CompoundAssignOperator *e) {
298 return emitCompoundAssign(e, &ComplexExprEmitter::emitBinMul);
300 mlir::Value VisitBinDivAssign(
const CompoundAssignOperator *e) {
301 return emitCompoundAssign(e, &ComplexExprEmitter::emitBinDiv);
309 LValue emitBinAssignLValue(
const BinaryOperator *e, mlir::Value &val);
310 mlir::Value VisitBinAssign(
const BinaryOperator *e);
311 mlir::Value VisitBinComma(
const BinaryOperator *e);
314 VisitAbstractConditionalOperator(
const AbstractConditionalOperator *e);
315 mlir::Value VisitChooseExpr(ChooseExpr *e);
317 mlir::Value VisitInitListExpr(InitListExpr *e);
319 mlir::Value VisitCompoundLiteralExpr(CompoundLiteralExpr *e) {
320 return emitLoadOfLValue(e);
323 mlir::Value VisitVAArgExpr(VAArgExpr *e);
325 mlir::Value VisitAtomicExpr(AtomicExpr *e) {
326 return cgf.emitAtomicExpr(e).getComplexValue();
329 mlir::Value VisitPackIndexingExpr(PackIndexingExpr *e) {
341mlir::Value ComplexExprEmitter::emitLoadOfLValue(LValue lv,
343 assert(lv.isSimple() &&
"non-simple complex l-value?");
344 if (lv.getType()->isAtomicType())
345 cgf.
cgm.
errorNYI(loc,
"emitLoadOfLValue with Atomic LV");
347 const Address srcAddr = lv.getAddress();
348 return builder.
createLoad(cgf.
getLoc(loc), srcAddr, lv.isVolatileQualified());
353void ComplexExprEmitter::emitStoreOfComplex(mlir::Location loc, mlir::Value val,
354 LValue lv,
bool isInit) {
355 if (lv.getType()->isAtomicType() ||
357 cgf.
cgm.
errorNYI(loc,
"StoreOfComplex with Atomic LV");
361 const Address destAddr = lv.getAddress();
362 builder.
createStore(loc, val, destAddr, lv.isVolatileQualified());
369mlir::Value ComplexExprEmitter::VisitExpr(Expr *e) {
375ComplexExprEmitter::VisitImaginaryLiteral(
const ImaginaryLiteral *il) {
377 mlir::Type elementTy = ty.getElementType();
380 mlir::TypedAttr realValueAttr;
381 mlir::TypedAttr imagValueAttr;
383 if (mlir::isa<cir::IntType>(elementTy)) {
385 realValueAttr = cir::IntAttr::get(elementTy, 0);
386 imagValueAttr = cir::IntAttr::get(elementTy, imagValue);
388 assert(mlir::isa<cir::FPTypeInterface>(elementTy) &&
389 "Expected complex element type to be floating-point");
391 llvm::APFloat imagValue =
393 realValueAttr = cir::FPAttr::get(
394 elementTy, llvm::APFloat::getZero(imagValue.getSemantics()));
395 imagValueAttr = cir::FPAttr::get(elementTy, imagValue);
398 auto complexAttr = cir::ConstComplexAttr::get(realValueAttr, imagValueAttr);
399 return cir::ConstantOp::create(builder, loc, complexAttr);
402mlir::Value ComplexExprEmitter::VisitCallExpr(
const CallExpr *e) {
404 return emitLoadOfLValue(e);
408mlir::Value ComplexExprEmitter::VisitStmtExpr(
const StmtExpr *e) {
409 CIRGenFunction::StmtExprEvaluation eval(cgf);
413 assert(retAlloca.
isValid() &&
"Expected complex return value");
418mlir::Value ComplexExprEmitter::emitComplexToComplexCast(mlir::Value val,
421 SourceLocation loc) {
422 if (srcType == destType)
426 QualType srcElemTy = srcType->
castAs<ComplexType>()->getElementType();
427 QualType destElemTy = destType->
castAs<ComplexType>()->getElementType();
429 cir::CastKind castOpKind;
431 castOpKind = cir::CastKind::float_complex;
433 castOpKind = cir::CastKind::float_complex_to_int_complex;
435 castOpKind = cir::CastKind::int_complex_to_float_complex;
437 castOpKind = cir::CastKind::int_complex;
439 llvm_unreachable(
"unexpected src type or dest type");
445mlir::Value ComplexExprEmitter::emitScalarToComplexCast(mlir::Value val,
448 SourceLocation loc) {
449 cir::CastKind castOpKind;
451 castOpKind = cir::CastKind::float_to_complex;
453 castOpKind = cir::CastKind::int_to_complex;
455 llvm_unreachable(
"unexpected src type");
461mlir::Value ComplexExprEmitter::emitCast(
CastKind ck, Expr *op,
465 llvm_unreachable(
"dependent type must be resolved before the CIR codegen");
468 case CK_LValueToRValue:
469 case CK_UserDefinedConversion:
472 case CK_AtomicToNonAtomic:
473 case CK_NonAtomicToAtomic: {
474 cgf.
cgm.
errorNYI(
"ComplexExprEmitter::emitCast Atmoic");
478 case CK_LValueBitCast: {
481 origLV.getAddress().withElementType(builder, cgf.
convertType(destTy));
483 return emitLoadOfLValue(destLV, op->
getExprLoc());
486 case CK_LValueToRValueBitCast: {
488 Address addr = sourceLVal.getAddress().withElementType(
492 return emitLoadOfLValue(destLV, op->
getExprLoc());
496 case CK_BaseToDerived:
497 case CK_DerivedToBase:
498 case CK_UncheckedDerivedToBase:
501 case CK_ArrayToPointerDecay:
502 case CK_FunctionToPointerDecay:
503 case CK_NullToPointer:
504 case CK_NullToMemberPointer:
505 case CK_BaseToDerivedMemberPointer:
506 case CK_DerivedToBaseMemberPointer:
507 case CK_MemberPointerToBoolean:
508 case CK_ReinterpretMemberPointer:
509 case CK_ConstructorConversion:
510 case CK_IntegralToPointer:
511 case CK_PointerToIntegral:
512 case CK_PointerToBoolean:
515 case CK_IntegralCast:
516 case CK_BooleanToSignedIntegral:
517 case CK_IntegralToBoolean:
518 case CK_IntegralToFloating:
519 case CK_FloatingToIntegral:
520 case CK_FloatingToBoolean:
521 case CK_FloatingCast:
522 case CK_CPointerToObjCPointerCast:
523 case CK_BlockPointerToObjCPointerCast:
524 case CK_AnyPointerToBlockPointerCast:
525 case CK_ObjCObjectLValueCast:
526 case CK_FloatingComplexToReal:
527 case CK_FloatingComplexToBoolean:
528 case CK_IntegralComplexToReal:
529 case CK_IntegralComplexToBoolean:
530 case CK_ARCProduceObject:
531 case CK_ARCConsumeObject:
532 case CK_ARCReclaimReturnedObject:
533 case CK_ARCExtendBlockObject:
534 case CK_CopyAndAutoreleaseBlockObject:
535 case CK_BuiltinFnToFnPtr:
536 case CK_ZeroToOCLOpaqueType:
537 case CK_AddressSpaceConversion:
538 case CK_IntToOCLSampler:
539 case CK_FloatingToFixedPoint:
540 case CK_FixedPointToFloating:
541 case CK_FixedPointCast:
542 case CK_FixedPointToBoolean:
543 case CK_FixedPointToIntegral:
544 case CK_IntegralToFixedPoint:
546 case CK_HLSLVectorTruncation:
547 case CK_HLSLMatrixTruncation:
548 case CK_HLSLArrayRValue:
549 case CK_HLSLElementwiseCast:
550 case CK_HLSLAggregateSplatCast:
551 llvm_unreachable(
"invalid cast kind for complex value");
553 case CK_FloatingRealToComplex:
554 case CK_IntegralRealToComplex: {
555 CIRGenFunction::CIRGenFPOptionsRAII FPOptsRAII(cgf, op);
560 case CK_FloatingComplexCast:
561 case CK_FloatingComplexToIntegralComplex:
562 case CK_IntegralComplexCast:
563 case CK_IntegralComplexToFloatingComplex: {
564 CIRGenFunction::CIRGenFPOptionsRAII FPOptsRAII(cgf, op);
565 return emitComplexToComplexCast(Visit(op), op->
getType(), destTy,
570 llvm_unreachable(
"unknown cast resulting in complex value");
573mlir::Value ComplexExprEmitter::VisitUnaryPlus(
const UnaryOperator *e) {
575 mlir::Value result = VisitUnaryPlus(e, promotionTy);
576 if (!promotionTy.
isNull())
581mlir::Value ComplexExprEmitter::VisitUnaryPlus(
const UnaryOperator *e,
582 QualType promotionType) {
583 if (!promotionType.
isNull())
588mlir::Value ComplexExprEmitter::VisitUnaryMinus(
const UnaryOperator *e) {
590 mlir::Value result = VisitUnaryMinus(e, promotionTy);
591 if (!promotionTy.
isNull())
596mlir::Value ComplexExprEmitter::VisitUnaryMinus(
const UnaryOperator *e,
597 QualType promotionType) {
599 if (!promotionType.
isNull())
606mlir::Value ComplexExprEmitter::VisitUnaryNot(
const UnaryOperator *e) {
611mlir::Value ComplexExprEmitter::emitBinAdd(
const BinOpInfo &op) {
613 CIRGenFunction::CIRGenFPOptionsRAII FPOptsRAII(cgf, op.fpFeatures);
615 if (mlir::isa<cir::ComplexType>(op.lhs.getType()) &&
616 mlir::isa<cir::ComplexType>(op.rhs.getType()))
617 return cir::ComplexAddOp::create(builder, op.loc, op.lhs, op.rhs);
619 if (mlir::isa<cir::ComplexType>(op.lhs.getType())) {
622 mlir::Value newReal = builder.
createAdd(op.loc, real, op.rhs);
626 assert(mlir::isa<cir::ComplexType>(op.rhs.getType()));
629 mlir::Value newReal = builder.
createAdd(op.loc, op.lhs, real);
633mlir::Value ComplexExprEmitter::emitBinSub(
const BinOpInfo &op) {
635 CIRGenFunction::CIRGenFPOptionsRAII FPOptsRAII(cgf, op.fpFeatures);
637 if (mlir::isa<cir::ComplexType>(op.lhs.getType()) &&
638 mlir::isa<cir::ComplexType>(op.rhs.getType()))
639 return cir::ComplexSubOp::create(builder, op.loc, op.lhs, op.rhs);
641 if (mlir::isa<cir::ComplexType>(op.lhs.getType())) {
644 mlir::Value newReal = builder.
createSub(op.loc, real, op.rhs);
648 assert(mlir::isa<cir::ComplexType>(op.rhs.getType()));
651 mlir::Value newReal = builder.
createSub(op.loc, op.lhs, real);
655static cir::ComplexRangeKind
659 return cir::ComplexRangeKind::Full;
661 return cir::ComplexRangeKind::Improved;
663 return cir::ComplexRangeKind::Promoted;
665 return cir::ComplexRangeKind::Basic;
668 return cir::ComplexRangeKind::Full;
672mlir::Value ComplexExprEmitter::emitBinMul(
const BinOpInfo &op) {
674 CIRGenFunction::CIRGenFPOptionsRAII FPOptsRAII(cgf, op.fpFeatures);
676 if (mlir::isa<cir::ComplexType>(op.lhs.getType()) &&
677 mlir::isa<cir::ComplexType>(op.rhs.getType())) {
678 cir::ComplexRangeKind rangeKind =
680 return cir::ComplexMulOp::create(builder, op.loc, op.lhs, op.rhs,
684 if (mlir::isa<cir::ComplexType>(op.lhs.getType())) {
687 mlir::Value newReal = builder.
createMul(op.loc, real, op.rhs);
688 mlir::Value newImag = builder.
createMul(op.loc, imag, op.rhs);
692 assert(mlir::isa<cir::ComplexType>(op.rhs.getType()));
695 mlir::Value newReal = builder.
createMul(op.loc, op.lhs, real);
696 mlir::Value newImag = builder.
createMul(op.loc, op.lhs, imag);
700mlir::Value ComplexExprEmitter::emitBinDiv(
const BinOpInfo &op) {
702 CIRGenFunction::CIRGenFPOptionsRAII FPOptsRAII(cgf, op.fpFeatures);
708 if (mlir::isa<cir::ComplexType>(op.lhs.getType()) &&
709 mlir::isa<cir::ComplexType>(op.rhs.getType())) {
710 cir::ComplexRangeKind rangeKind =
712 return cir::ComplexDivOp::create(builder, op.loc, op.lhs, op.rhs,
718 if (mlir::isa<cir::ComplexType>(op.lhs.getType())) {
719 assert(mlir::cast<cir::ComplexType>(op.lhs.getType()).getElementType() ==
723 mlir::Value newReal = builder.
createFDiv(op.loc, real, op.rhs);
724 mlir::Value newImag = builder.
createFDiv(op.loc, imag, op.rhs);
728 assert(mlir::isa<cir::ComplexType>(op.rhs.getType()));
729 cir::ConstantOp nullValue = builder.
getNullValue(op.lhs.getType(), op.loc);
731 cir::ComplexRangeKind rangeKind =
733 return cir::ComplexDivOp::create(builder, op.loc, lhs, op.rhs, rangeKind);
738 assert(!mlir::cast<cir::ComplexType>(result.getType()).isIntegerComplex() &&
739 "integral complex will never be promoted");
740 return builder.createCast(cir::CastKind::float_complex, result,
746 assert(!mlir::cast<cir::ComplexType>(result.getType()).isIntegerComplex() &&
747 "integral complex will never be promoted");
748 return builder.createCast(cir::CastKind::float_complex, result,
752mlir::Value ComplexExprEmitter::emitPromoted(
const Expr *e,
755 if (
const auto *bo = dyn_cast<BinaryOperator>(e)) {
756 switch (bo->getOpcode()) {
757#define HANDLE_BINOP(OP) \
759 return emitBin##OP(emitBinOps(bo, promotionTy));
768 }
else if (
const auto *unaryOp = dyn_cast<UnaryOperator>(e)) {
769 switch (unaryOp->getOpcode()) {
771 return VisitUnaryPlus(unaryOp, promotionTy);
773 return VisitUnaryMinus(unaryOp, promotionTy);
779 mlir::Value result = Visit(
const_cast<Expr *
>(e));
780 if (!promotionTy.
isNull())
788 return ComplexExprEmitter(*this).emitPromoted(e, promotionType);
792ComplexExprEmitter::emitPromotedComplexOperand(
const Expr *e,
795 if (!promotionTy.
isNull())
797 return Visit(
const_cast<Expr *
>(e));
800 if (!promotionTy.
isNull()) {
808ComplexExprEmitter::BinOpInfo
809ComplexExprEmitter::emitBinOps(
const BinaryOperator *e, QualType promotionTy) {
811 binOpInfo.lhs = emitPromotedComplexOperand(e->
getLHS(), promotionTy);
812 binOpInfo.rhs = emitPromotedComplexOperand(e->
getRHS(), promotionTy);
813 binOpInfo.ty = promotionTy.
isNull() ? e->
getType() : promotionTy;
818LValue ComplexExprEmitter::emitCompoundAssignLValue(
819 const CompoundAssignOperator *e,
820 mlir::Value (ComplexExprEmitter::*func)(
const BinOpInfo &), RValue &value) {
824 mlir::Location loc = cgf.
getLoc(exprLoc);
826 if (lhsTy->
getAs<AtomicType>()) {
827 cgf.
cgm.
errorNYI(
"emitCompoundAssignLValue AtmoicType");
831 BinOpInfo opInfo{loc};
834 CIRGenFunction::CIRGenFPOptionsRAII FPOptsRAII(cgf, opInfo.fpFeatures);
843 QualType complexElementTy =
844 opInfo.ty->castAs<ComplexType>()->getElementType();
845 QualType promotionTypeRHS = getPromotionType(rhsTy);
849 if (!promotionTypeRHS.
isNull()) {
856 if (!promotionTypeRHS.
isNull()) {
860 opInfo.rhs = Visit(e->
getRHS());
869 mlir::Value lhsValue = emitLoadOfLValue(lhs, exprLoc);
870 QualType destTy = promotionTypeLHS.
isNull() ? opInfo.ty : promotionTypeLHS;
871 opInfo.lhs = emitComplexToComplexCast(lhsValue, lhsTy, destTy, exprLoc);
877 QualType promotedComplexElementTy;
878 if (!promotionTypeLHS.
isNull()) {
879 promotedComplexElementTy =
884 promotedComplexElementTy, exprLoc);
892 opInfo.lhs = emitScalarToComplexCast(lhsVal, lhsTy, opInfo.ty, exprLoc);
897 mlir::Value result = (this->*func)(opInfo);
901 mlir::Value resultValue =
902 emitComplexToComplexCast(result, opInfo.ty, lhsTy, exprLoc);
903 emitStoreOfComplex(loc, resultValue, lhs,
false);
906 mlir::Value resultValue =
915mlir::Value ComplexExprEmitter::emitCompoundAssign(
916 const CompoundAssignOperator *e,
917 mlir::Value (ComplexExprEmitter::*func)(
const BinOpInfo &)) {
919 LValue lv = emitCompoundAssignLValue(e, func, val);
926 if (!lv.isVolatileQualified())
932LValue ComplexExprEmitter::emitBinAssignLValue(
const BinaryOperator *e,
933 mlir::Value &value) {
936 "Invalid assignment");
939 value = Visit(e->
getRHS());
950mlir::Value ComplexExprEmitter::VisitBinAssign(
const BinaryOperator *e) {
952 LValue lv = emitBinAssignLValue(e, value);
960 if (!lv.isVolatile())
966mlir::Value ComplexExprEmitter::VisitBinComma(
const BinaryOperator *e) {
968 return Visit(e->
getRHS());
971mlir::Value ComplexExprEmitter::VisitAbstractConditionalOperator(
972 const AbstractConditionalOperator *e) {
976 CIRGenFunction::OpaqueValueMapping binding(cgf, e);
978 CIRGenFunction::ConditionalEvaluation eval(cgf);
983 return cir::TernaryOp::create(
984 builder, loc, condValue,
986 [&](mlir::OpBuilder &
b, mlir::Location loc) {
987 eval.beginEvaluation();
989 cir::YieldOp::create(
b, loc, trueValue);
990 eval.endEvaluation();
993 [&](mlir::OpBuilder &
b, mlir::Location loc) {
994 eval.beginEvaluation();
996 cir::YieldOp::create(
b, loc, falseValue);
997 eval.endEvaluation();
1002mlir::Value ComplexExprEmitter::VisitChooseExpr(ChooseExpr *e) {
1006mlir::Value ComplexExprEmitter::VisitInitListExpr(InitListExpr *e) {
1017 assert(e->
getNumInits() == 0 &&
"Unexpected number of inits");
1022mlir::Value ComplexExprEmitter::VisitVAArgExpr(VAArgExpr *e) {
1034 "Invalid complex expression to emit");
1036 return ComplexExprEmitter(*this).Visit(
const_cast<Expr *
>(e));
1042 "Invalid complex expression to emit");
1043 ComplexExprEmitter emitter(*
this);
1044 mlir::Value value = emitter.Visit(
const_cast<Expr *
>(e));
1050 LValue dest,
bool isInit) {
1051 ComplexExprEmitter(*this).emitStoreOfComplex(loc, v, dest, isInit);
1055 return ComplexExprEmitter(*this).emitLoadOfLValue(src, loc);
1059 assert(e->
getOpcode() == BO_Assign &&
"Expected assign op");
1062 LValue lvalue = ComplexExprEmitter(*this).emitBinAssignLValue(e, value);
1064 cgm.errorNYI(
"emitComplexAssignmentLValue OpenMP");
1070 mlir::Value (ComplexExprEmitter::*)(
const ComplexExprEmitter::BinOpInfo &);
1075 return &ComplexExprEmitter::emitBinMul;
1077 return &ComplexExprEmitter::emitBinDiv;
1079 return &ComplexExprEmitter::emitBinSub;
1081 return &ComplexExprEmitter::emitBinAdd;
1083 llvm_unreachable(
"unexpected complex compound assignment");
1091 return ComplexExprEmitter(*this).emitCompoundAssignLValue(e, op, val);
1098 mlir::Value incVal = e->
isIncrementOp() ? builder.createInc(loc, inVal)
1099 : builder.createDec(loc, inVal);
1105 cgm.errorNYI(loc,
"emitComplexPrePostIncDec OpenMP");
1109 return e->
isPrefix() ? incVal : inVal;
1118 LValue ret = ComplexExprEmitter(*this).emitCompoundAssignLValue(e, op, value);
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)
__device__ __2f16 float __ockl_bool s
mlir::Value createSub(mlir::Location loc, mlir::Value lhs, mlir::Value rhs, OverflowBehavior ob=OverflowBehavior::None)
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 createComplexImag(mlir::Location loc, mlir::Value operand)
mlir::Value createNot(mlir::Location loc, mlir::Value value)
mlir::Value createMul(mlir::Location loc, mlir::Value lhs, mlir::Value rhs, OverflowBehavior ob=OverflowBehavior::None)
mlir::Value createMinus(mlir::Location loc, mlir::Value input, bool nsw=false)
mlir::Value createComplexCreate(mlir::Location loc, mlir::Value real, mlir::Value imag)
mlir::Value createComplexReal(mlir::Location loc, mlir::Value operand)
static bool hasSameUnqualifiedType(QualType T1, QualType T2)
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 ?
Expr * getTrueExpr() const
getTrueExpr - Return the subexpression representing the value of the expression if the condition eval...
Expr * getFalseExpr() const
getFalseExpr - Return the subexpression representing the value of the expression if the condition eva...
A builtin binary operation expression such as "x + y" or "x <= y".
SourceLocation getExprLoc() const
FPOptions getFPFeaturesInEffect(const LangOptions &LO) const
Get the FP features status of this operator.
mlir::Value createFDiv(mlir::Location loc, mlir::Value lhs, mlir::Value rhs)
cir::StoreOp createStore(mlir::Location loc, mlir::Value val, Address dst, bool isVolatile=false, mlir::IntegerAttr align={}, cir::SyncScopeKindAttr scope={}, cir::MemOrderAttr order={})
cir::LoadOp createLoad(mlir::Location loc, Address addr, bool isVolatile=false)
LValue getReferenceLValue(CIRGenFunction &cgf, Expr *refExpr) const
mlir::TypedAttr getValue() 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,...
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 emitComplexPrePostIncDec(const UnaryOperator *e, LValue lv)
mlir::Value emitLoadOfComplex(LValue src, SourceLocation loc)
Load a complex number from the specified l-value.
void emitStoreOfScalar(mlir::Value value, Address addr, bool isVolatile, clang::QualType ty, LValueBaseInfo baseInfo, bool isInit=false, bool isNontemporal=false)
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, bool ignoreResultAssign=false)
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
mlir::LogicalResult emitCompoundStmt(const clang::CompoundStmt &s, Address *lastValue=nullptr, AggValueSlot slot=AggValueSlot::ignored())
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.
Address createMemTemp(QualType t, mlir::Location loc, const Twine &name="tmp", Address *alloca=nullptr, mlir::OpBuilder::InsertPoint ip={})
Create a temporary memory object of the given type, with appropriate alignmen and cast it to the defa...
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.
static RValue get(mlir::Value v)
static RValue getComplex(mlir::Value v)
mlir::Value getValue() const
Return the value of this scalar value.
mlir::Value getComplexValue() const
Return the value of this complex value.
Expr * getExpr()
Get the initialization expression that will be used.
A rewritten comparison expression that was originally written using operator syntax.
SourceLocation getExprLoc() const LLVM_READONLY
QualType getCallReturnType(const ASTContext &Ctx) const
getCallReturnType - Get the return type of the call expr.
CastKind getCastKind() const
bool changesVolatileQualification() const
Return.
Expr * getChosenSubExpr() const
getChosenSubExpr - Return the subexpression chosen according to the condition.
Complex values, per C99 6.2.5p11.
CompoundAssignOperator - For compound assignments (e.g.
QualType getComputationLHSType() const
QualType getComputationResultType() const
This represents one expression.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
const Expr * getSubExpr() const
Expr * getResultExpr()
Return the result expression of this controlling expression.
const Expr * getSubExpr() const
unsigned getNumInits() const
const Expr * getInit(unsigned Init) const
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...
SourceLocation getExprLoc() const LLVM_READONLY
Expr * getSelectedExpr() const
const Expr * getSubExpr() const
SourceLocation getExprLoc() const LLVM_READONLY
A (possibly-)qualified type.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
bool UseExcessPrecision(const ASTContext &Ctx)
Encodes a location in the source.
CompoundStmt * getSubStmt()
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...
Expr * getReplacement() const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
const T * castAs() const
Member-template castAs<specific type>.
bool isReferenceType() const
bool isAnyComplexType() const
bool isRealFloatingType() const
Floating point categories.
bool isFloatingType() const
const T * getAs() const
Member-template getAs<specific type>'.
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
SourceLocation getExprLoc() const
Expr * getSubExpr() const
static bool isIncrementOp(Opcode Op)
static bool isPrefix(Opcode Op)
isPrefix - Return true if this is a prefix operation, like –x.
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)
static bool fastMathFlags()