20class ComplexExprEmitter :
public StmtVisitor<ComplexExprEmitter, mlir::Value> {
22 CIRGenBuilderTy &builder;
25 explicit ComplexExprEmitter(CIRGenFunction &cgf)
26 : cgf(cgf), builder(cgf.getBuilder()) {}
35 mlir::Value emitLoadOfLValue(
const Expr *e) {
36 return emitLoadOfLValue(cgf.emitLValue(e), e->
getExprLoc());
39 mlir::Value emitLoadOfLValue(LValue lv, SourceLocation loc);
43 void emitStoreOfComplex(mlir::Location loc, mlir::Value val, LValue lv,
47 mlir::Value emitComplexToComplexCast(mlir::Value value, QualType srcType,
48 QualType destType, SourceLocation loc);
51 mlir::Value emitScalarToComplexCast(mlir::Value value, QualType srcType,
52 QualType destType, SourceLocation loc);
58 mlir::Value Visit(Expr *e) {
59 return StmtVisitor<ComplexExprEmitter, mlir::Value>::Visit(e);
62 mlir::Value VisitStmt(Stmt *
s) {
63 cgf.cgm.errorNYI(
s->getBeginLoc(),
"ComplexExprEmitter VisitStmt");
67 mlir::Value VisitExpr(Expr *e);
68 mlir::Value VisitConstantExpr(ConstantExpr *e) {
69 cgf.cgm.errorNYI(e->
getExprLoc(),
"ComplexExprEmitter VisitConstantExpr");
73 mlir::Value VisitParenExpr(ParenExpr *pe) {
return Visit(pe->
getSubExpr()); }
74 mlir::Value VisitGenericSelectionExpr(GenericSelectionExpr *ge) {
77 mlir::Value VisitImaginaryLiteral(
const ImaginaryLiteral *il);
79 VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *pe) {
82 mlir::Value VisitCoawaitExpr(CoawaitExpr *
s) {
83 cgf.cgm.errorNYI(
s->getExprLoc(),
"ComplexExprEmitter VisitCoawaitExpr");
86 mlir::Value VisitCoyieldExpr(CoyieldExpr *
s) {
87 cgf.cgm.errorNYI(
s->getExprLoc(),
"ComplexExprEmitter VisitCoyieldExpr");
90 mlir::Value VisitUnaryCoawait(
const UnaryOperator *e) {
91 cgf.cgm.errorNYI(e->
getExprLoc(),
"ComplexExprEmitter VisitUnaryCoawait");
95 mlir::Value emitConstant(
const CIRGenFunction::ConstantEmission &constant,
97 assert(constant &&
"not a constant");
102 mlir::TypedAttr valueAttr = constant.
getValue();
103 return builder.getConstant(cgf.getLoc(e->
getSourceRange()), valueAttr);
107 mlir::Value VisitDeclRefExpr(DeclRefExpr *e) {
108 if (CIRGenFunction::ConstantEmission constant = cgf.tryEmitAsConstant(e))
109 return emitConstant(constant, e);
110 return emitLoadOfLValue(e);
112 mlir::Value VisitObjCIvarRefExpr(ObjCIvarRefExpr *e) {
114 "ComplexExprEmitter VisitObjCIvarRefExpr");
117 mlir::Value VisitObjCMessageExpr(ObjCMessageExpr *e) {
119 "ComplexExprEmitter VisitObjCMessageExpr");
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);
128 return emitLoadOfLValue(me);
130 mlir::Value VisitOpaqueValueExpr(OpaqueValueExpr *e) {
132 return emitLoadOfLValue(cgf.getOrCreateOpaqueLValueMapping(e),
134 return cgf.getOrCreateOpaqueRValueMapping(e).getComplexValue();
137 mlir::Value VisitPseudoObjectExpr(PseudoObjectExpr *e) {
139 "ComplexExprEmitter VisitPseudoObjectExpr");
143 mlir::Value emitCast(
CastKind ck, Expr *op, QualType destTy);
144 mlir::Value VisitImplicitCastExpr(ImplicitCastExpr *e) {
148 return emitLoadOfLValue(e);
151 mlir::Value VisitCastExpr(
CastExpr *e) {
152 if (
const auto *ece = dyn_cast<ExplicitCastExpr>(e)) {
154 if (ece->getType()->isVariablyModifiedType()) {
156 "VisitCastExpr Bind VLAs in the cast type");
162 return emitLoadOfLValue(e);
166 mlir::Value VisitCallExpr(
const CallExpr *e);
167 mlir::Value VisitStmtExpr(
const StmtExpr *e);
170 mlir::Value VisitPrePostIncDec(
const UnaryOperator *e, cir::UnaryOpKind op,
173 return cgf.emitComplexPrePostIncDec(e, lv, op, isPre);
175 mlir::Value VisitUnaryPostDec(
const UnaryOperator *e) {
176 return VisitPrePostIncDec(e, cir::UnaryOpKind::Dec,
false);
178 mlir::Value VisitUnaryPostInc(
const UnaryOperator *e) {
179 return VisitPrePostIncDec(e, cir::UnaryOpKind::Inc,
false);
181 mlir::Value VisitUnaryPreDec(
const UnaryOperator *e) {
182 return VisitPrePostIncDec(e, cir::UnaryOpKind::Dec,
true);
184 mlir::Value VisitUnaryPreInc(
const UnaryOperator *e) {
185 return VisitPrePostIncDec(e, cir::UnaryOpKind::Inc,
true);
187 mlir::Value VisitUnaryDeref(
const Expr *e) {
return emitLoadOfLValue(e); }
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);
195 mlir::Value VisitUnaryExtension(
const UnaryOperator *e) {
198 mlir::Value VisitCXXDefaultArgExpr(CXXDefaultArgExpr *dae) {
200 "ComplexExprEmitter VisitCXXDefaultArgExpr");
203 mlir::Value VisitCXXDefaultInitExpr(CXXDefaultInitExpr *die) {
204 CIRGenFunction::CXXDefaultInitExprScope scope(cgf, die);
207 mlir::Value VisitExprWithCleanups(ExprWithCleanups *e) {
209 "ComplexExprEmitter VisitExprWithCleanups");
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);
217 mlir::Value VisitImplicitValueInitExpr(ImplicitValueInitExpr *e) {
219 "ComplexExprEmitter VisitImplicitValueInitExpr");
228 FPOptions fpFeatures{};
231 BinOpInfo emitBinOps(
const BinaryOperator *e,
232 QualType promotionTy = QualType());
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 &),
240 mlir::Value emitCompoundAssign(
241 const CompoundAssignOperator *e,
242 mlir::Value (ComplexExprEmitter::*func)(
const BinOpInfo &));
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);
249 QualType getPromotionType(QualType ty,
bool isDivOpCode =
false) {
250 if (
auto *complexTy = ty->
getAs<ComplexType>()) {
251 QualType elementTy = complexTy->getElementType();
253 return cgf.getContext().getComplexType(cgf.getContext().FloatTy);
257 return cgf.getContext().FloatTy;
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()); \
279 "ComplexExprEmitter VisitCXXRewrittenBinaryOperator");
284 mlir::Value VisitBinAddAssign(
const CompoundAssignOperator *e) {
285 return emitCompoundAssign(e, &ComplexExprEmitter::emitBinAdd);
287 mlir::Value VisitBinSubAssign(
const CompoundAssignOperator *e) {
288 return emitCompoundAssign(e, &ComplexExprEmitter::emitBinSub);
290 mlir::Value VisitBinMulAssign(
const CompoundAssignOperator *e) {
291 return emitCompoundAssign(e, &ComplexExprEmitter::emitBinMul);
293 mlir::Value VisitBinDivAssign(
const CompoundAssignOperator *e) {
294 return emitCompoundAssign(e, &ComplexExprEmitter::emitBinDiv);
302 LValue emitBinAssignLValue(
const BinaryOperator *e, mlir::Value &val);
303 mlir::Value VisitBinAssign(
const BinaryOperator *e);
304 mlir::Value VisitBinComma(
const BinaryOperator *e);
307 VisitAbstractConditionalOperator(
const AbstractConditionalOperator *e);
308 mlir::Value VisitChooseExpr(ChooseExpr *e);
310 mlir::Value VisitInitListExpr(InitListExpr *e);
312 mlir::Value VisitCompoundLiteralExpr(CompoundLiteralExpr *e) {
313 return emitLoadOfLValue(e);
316 mlir::Value VisitVAArgExpr(VAArgExpr *e);
318 mlir::Value VisitAtomicExpr(AtomicExpr *e) {
319 return cgf.emitAtomicExpr(e).getComplexValue();
322 mlir::Value VisitPackIndexingExpr(PackIndexingExpr *e) {
324 "ComplexExprEmitter VisitPackIndexingExpr");
336mlir::Value ComplexExprEmitter::emitLoadOfLValue(LValue lv,
338 assert(lv.isSimple() &&
"non-simple complex l-value?");
339 if (lv.getType()->isAtomicType())
340 cgf.
cgm.
errorNYI(loc,
"emitLoadOfLValue with Atomic LV");
342 const Address srcAddr = lv.getAddress();
348void ComplexExprEmitter::emitStoreOfComplex(mlir::Location loc, mlir::Value val,
349 LValue lv,
bool isInit) {
350 if (lv.getType()->isAtomicType() ||
352 cgf.
cgm.
errorNYI(loc,
"StoreOfComplex with Atomic LV");
356 const Address destAddr = lv.getAddress();
364mlir::Value ComplexExprEmitter::VisitExpr(Expr *e) {
370ComplexExprEmitter::VisitImaginaryLiteral(
const ImaginaryLiteral *il) {
372 mlir::Type elementTy = ty.getElementType();
375 mlir::TypedAttr realValueAttr;
376 mlir::TypedAttr imagValueAttr;
378 if (mlir::isa<cir::IntType>(elementTy)) {
380 realValueAttr = cir::IntAttr::get(elementTy, 0);
381 imagValueAttr = cir::IntAttr::get(elementTy, imagValue);
383 assert(mlir::isa<cir::FPTypeInterface>(elementTy) &&
384 "Expected complex element type to be floating-point");
386 llvm::APFloat imagValue =
388 realValueAttr = cir::FPAttr::get(
389 elementTy, llvm::APFloat::getZero(imagValue.getSemantics()));
390 imagValueAttr = cir::FPAttr::get(elementTy, imagValue);
393 auto complexAttr = cir::ConstComplexAttr::get(realValueAttr, imagValueAttr);
394 return builder.create<cir::ConstantOp>(loc, complexAttr);
397mlir::Value ComplexExprEmitter::VisitCallExpr(
const CallExpr *e) {
399 return emitLoadOfLValue(e);
403mlir::Value ComplexExprEmitter::VisitStmtExpr(
const StmtExpr *e) {
408mlir::Value ComplexExprEmitter::emitComplexToComplexCast(mlir::Value val,
411 SourceLocation loc) {
412 if (srcType == destType)
416 QualType srcElemTy = srcType->
castAs<ComplexType>()->getElementType();
417 QualType destElemTy = destType->
castAs<ComplexType>()->getElementType();
419 cir::CastKind castOpKind;
421 castOpKind = cir::CastKind::float_complex;
423 castOpKind = cir::CastKind::float_complex_to_int_complex;
425 castOpKind = cir::CastKind::int_complex_to_float_complex;
427 castOpKind = cir::CastKind::int_complex;
429 llvm_unreachable(
"unexpected src type or dest type");
435mlir::Value ComplexExprEmitter::emitScalarToComplexCast(mlir::Value val,
438 SourceLocation loc) {
439 cir::CastKind castOpKind;
441 castOpKind = cir::CastKind::float_to_complex;
443 castOpKind = cir::CastKind::int_to_complex;
445 llvm_unreachable(
"unexpected src type");
451mlir::Value ComplexExprEmitter::emitCast(
CastKind ck, Expr *op,
455 llvm_unreachable(
"dependent type must be resolved before the CIR codegen");
458 case CK_LValueToRValue:
461 case CK_AtomicToNonAtomic:
462 case CK_NonAtomicToAtomic:
463 case CK_UserDefinedConversion: {
465 "ComplexExprEmitter::emitCast Atmoic & UserDefinedConversion");
469 case CK_LValueBitCast: {
472 origLV.getAddress().withElementType(builder, cgf.
convertType(destTy));
474 return emitLoadOfLValue(destLV, op->
getExprLoc());
477 case CK_LValueToRValueBitCast: {
479 Address addr = sourceLVal.getAddress().withElementType(
483 return emitLoadOfLValue(destLV, op->
getExprLoc());
487 case CK_BaseToDerived:
488 case CK_DerivedToBase:
489 case CK_UncheckedDerivedToBase:
492 case CK_ArrayToPointerDecay:
493 case CK_FunctionToPointerDecay:
494 case CK_NullToPointer:
495 case CK_NullToMemberPointer:
496 case CK_BaseToDerivedMemberPointer:
497 case CK_DerivedToBaseMemberPointer:
498 case CK_MemberPointerToBoolean:
499 case CK_ReinterpretMemberPointer:
500 case CK_ConstructorConversion:
501 case CK_IntegralToPointer:
502 case CK_PointerToIntegral:
503 case CK_PointerToBoolean:
506 case CK_IntegralCast:
507 case CK_BooleanToSignedIntegral:
508 case CK_IntegralToBoolean:
509 case CK_IntegralToFloating:
510 case CK_FloatingToIntegral:
511 case CK_FloatingToBoolean:
512 case CK_FloatingCast:
513 case CK_CPointerToObjCPointerCast:
514 case CK_BlockPointerToObjCPointerCast:
515 case CK_AnyPointerToBlockPointerCast:
516 case CK_ObjCObjectLValueCast:
517 case CK_FloatingComplexToReal:
518 case CK_FloatingComplexToBoolean:
519 case CK_IntegralComplexToReal:
520 case CK_IntegralComplexToBoolean:
521 case CK_ARCProduceObject:
522 case CK_ARCConsumeObject:
523 case CK_ARCReclaimReturnedObject:
524 case CK_ARCExtendBlockObject:
525 case CK_CopyAndAutoreleaseBlockObject:
526 case CK_BuiltinFnToFnPtr:
527 case CK_ZeroToOCLOpaqueType:
528 case CK_AddressSpaceConversion:
529 case CK_IntToOCLSampler:
530 case CK_FloatingToFixedPoint:
531 case CK_FixedPointToFloating:
532 case CK_FixedPointCast:
533 case CK_FixedPointToBoolean:
534 case CK_FixedPointToIntegral:
535 case CK_IntegralToFixedPoint:
537 case CK_HLSLVectorTruncation:
538 case CK_HLSLArrayRValue:
539 case CK_HLSLElementwiseCast:
540 case CK_HLSLAggregateSplatCast:
541 llvm_unreachable(
"invalid cast kind for complex value");
543 case CK_FloatingRealToComplex:
544 case CK_IntegralRealToComplex: {
550 case CK_FloatingComplexCast:
551 case CK_FloatingComplexToIntegralComplex:
552 case CK_IntegralComplexCast:
553 case CK_IntegralComplexToFloatingComplex: {
555 return emitComplexToComplexCast(Visit(op), op->
getType(), destTy,
560 llvm_unreachable(
"unknown cast resulting in complex value");
563mlir::Value ComplexExprEmitter::VisitUnaryPlus(
const UnaryOperator *e) {
565 mlir::Value result = VisitPlusMinus(e, cir::UnaryOpKind::Plus, promotionTy);
566 if (!promotionTy.
isNull())
571mlir::Value ComplexExprEmitter::VisitUnaryMinus(
const UnaryOperator *e) {
573 mlir::Value result = VisitPlusMinus(e, cir::UnaryOpKind::Minus, promotionTy);
574 if (!promotionTy.
isNull())
579mlir::Value ComplexExprEmitter::VisitPlusMinus(
const UnaryOperator *e,
580 cir::UnaryOpKind kind,
581 QualType promotionType) {
582 assert(kind == cir::UnaryOpKind::Plus ||
583 kind == cir::UnaryOpKind::Minus &&
584 "Invalid UnaryOp kind for ComplexType Plus or Minus");
587 if (!promotionType.
isNull())
594mlir::Value ComplexExprEmitter::VisitUnaryNot(
const UnaryOperator *e) {
599mlir::Value ComplexExprEmitter::emitBinAdd(
const BinOpInfo &op) {
603 if (mlir::isa<cir::ComplexType>(op.lhs.getType()) &&
604 mlir::isa<cir::ComplexType>(op.rhs.getType()))
605 return builder.create<cir::ComplexAddOp>(op.loc, op.lhs, op.rhs);
607 if (mlir::isa<cir::ComplexType>(op.lhs.getType())) {
610 mlir::Value newReal = builder.
createAdd(op.loc, real, op.rhs);
614 assert(mlir::isa<cir::ComplexType>(op.rhs.getType()));
617 mlir::Value newReal = builder.
createAdd(op.loc, op.lhs, real);
621mlir::Value ComplexExprEmitter::emitBinSub(
const BinOpInfo &op) {
625 if (mlir::isa<cir::ComplexType>(op.lhs.getType()) &&
626 mlir::isa<cir::ComplexType>(op.rhs.getType()))
627 return builder.create<cir::ComplexSubOp>(op.loc, op.lhs, op.rhs);
629 if (mlir::isa<cir::ComplexType>(op.lhs.getType())) {
632 mlir::Value newReal = builder.
createSub(op.loc, real, op.rhs);
636 assert(mlir::isa<cir::ComplexType>(op.rhs.getType()));
639 mlir::Value newReal = builder.
createSub(op.loc, op.lhs, real);
643static cir::ComplexRangeKind
647 return cir::ComplexRangeKind::Full;
649 return cir::ComplexRangeKind::Improved;
651 return cir::ComplexRangeKind::Promoted;
653 return cir::ComplexRangeKind::Basic;
656 return cir::ComplexRangeKind::Full;
660mlir::Value ComplexExprEmitter::emitBinMul(
const BinOpInfo &op) {
664 if (mlir::isa<cir::ComplexType>(op.lhs.getType()) &&
665 mlir::isa<cir::ComplexType>(op.rhs.getType())) {
666 cir::ComplexRangeKind rangeKind =
668 return builder.create<cir::ComplexMulOp>(op.loc, op.lhs, op.rhs, rangeKind);
671 if (mlir::isa<cir::ComplexType>(op.lhs.getType())) {
674 mlir::Value newReal = builder.
createMul(op.loc, real, op.rhs);
675 mlir::Value newImag = builder.
createMul(op.loc, imag, op.rhs);
679 assert(mlir::isa<cir::ComplexType>(op.rhs.getType()));
682 mlir::Value newReal = builder.
createMul(op.loc, op.lhs, real);
683 mlir::Value newImag = builder.
createMul(op.loc, op.lhs, imag);
687mlir::Value ComplexExprEmitter::emitBinDiv(
const BinOpInfo &op) {
695 if (mlir::isa<cir::ComplexType>(op.lhs.getType()) &&
696 mlir::isa<cir::ComplexType>(op.rhs.getType())) {
697 cir::ComplexRangeKind rangeKind =
699 return cir::ComplexDivOp::create(builder, op.loc, op.lhs, op.rhs,
705 if (mlir::isa<cir::ComplexType>(op.lhs.getType())) {
706 assert(mlir::cast<cir::ComplexType>(op.lhs.getType()).getElementType() ==
710 mlir::Value newReal = builder.
createFDiv(op.loc, real, op.rhs);
711 mlir::Value newImag = builder.
createFDiv(op.loc, imag, op.rhs);
715 assert(mlir::isa<cir::ComplexType>(op.rhs.getType()));
716 cir::ConstantOp nullValue = builder.
getNullValue(op.lhs.getType(), op.loc);
718 cir::ComplexRangeKind rangeKind =
720 return cir::ComplexDivOp::create(builder, op.loc, lhs, op.rhs, rangeKind);
725 assert(!mlir::cast<cir::ComplexType>(result.getType()).isIntegerComplex() &&
726 "integral complex will never be promoted");
727 return builder.createCast(cir::CastKind::float_complex, result,
733 assert(!mlir::cast<cir::ComplexType>(result.getType()).isIntegerComplex() &&
734 "integral complex will never be promoted");
735 return builder.createCast(cir::CastKind::float_complex, result,
739mlir::Value ComplexExprEmitter::emitPromoted(
const Expr *e,
742 if (
const auto *bo = dyn_cast<BinaryOperator>(e)) {
743 switch (bo->getOpcode()) {
744#define HANDLE_BINOP(OP) \
746 return emitBin##OP(emitBinOps(bo, promotionTy));
755 }
else if (
const auto *unaryOp = dyn_cast<UnaryOperator>(e)) {
756 switch (unaryOp->getOpcode()) {
759 auto kind = unaryOp->getOpcode() == UO_Plus ? cir::UnaryOpKind::Plus
760 : cir::UnaryOpKind::Minus;
761 return VisitPlusMinus(unaryOp, kind, promotionTy);
768 mlir::Value result = Visit(
const_cast<Expr *
>(e));
769 if (!promotionTy.
isNull())
777 return ComplexExprEmitter(*this).emitPromoted(e, promotionType);
781ComplexExprEmitter::emitPromotedComplexOperand(
const Expr *e,
784 if (!promotionTy.
isNull())
786 return Visit(
const_cast<Expr *
>(e));
789 if (!promotionTy.
isNull()) {
797ComplexExprEmitter::BinOpInfo
798ComplexExprEmitter::emitBinOps(
const BinaryOperator *e, QualType promotionTy) {
800 binOpInfo.lhs = emitPromotedComplexOperand(e->
getLHS(), promotionTy);
801 binOpInfo.rhs = emitPromotedComplexOperand(e->
getRHS(), promotionTy);
802 binOpInfo.ty = promotionTy.
isNull() ? e->
getType() : promotionTy;
807LValue ComplexExprEmitter::emitCompoundAssignLValue(
808 const CompoundAssignOperator *e,
809 mlir::Value (ComplexExprEmitter::*func)(
const BinOpInfo &), RValue &value) {
813 mlir::Location loc = cgf.
getLoc(exprLoc);
815 if (lhsTy->
getAs<AtomicType>()) {
816 cgf.
cgm.
errorNYI(
"emitCompoundAssignLValue AtmoicType");
820 BinOpInfo opInfo{loc};
832 QualType complexElementTy =
833 opInfo.ty->castAs<ComplexType>()->getElementType();
834 QualType promotionTypeRHS = getPromotionType(rhsTy);
838 if (!promotionTypeRHS.
isNull()) {
845 if (!promotionTypeRHS.
isNull()) {
849 opInfo.rhs = Visit(e->
getRHS());
858 mlir::Value lhsValue = emitLoadOfLValue(lhs, exprLoc);
859 QualType destTy = promotionTypeLHS.
isNull() ? opInfo.ty : promotionTypeLHS;
860 opInfo.lhs = emitComplexToComplexCast(lhsValue, lhsTy, destTy, exprLoc);
866 QualType promotedComplexElementTy;
867 if (!promotionTypeLHS.
isNull()) {
868 promotedComplexElementTy =
873 promotedComplexElementTy, exprLoc);
881 opInfo.lhs = emitScalarToComplexCast(lhsVal, lhsTy, opInfo.ty, exprLoc);
886 mlir::Value result = (this->*func)(opInfo);
890 mlir::Value resultValue =
891 emitComplexToComplexCast(result, opInfo.ty, lhsTy, exprLoc);
892 emitStoreOfComplex(loc, resultValue, lhs,
false);
895 mlir::Value resultValue =
904mlir::Value ComplexExprEmitter::emitCompoundAssign(
905 const CompoundAssignOperator *e,
906 mlir::Value (ComplexExprEmitter::*func)(
const BinOpInfo &)) {
908 LValue lv = emitCompoundAssignLValue(e, func, val);
915 if (!lv.isVolatileQualified())
921LValue ComplexExprEmitter::emitBinAssignLValue(
const BinaryOperator *e,
922 mlir::Value &value) {
925 "Invalid assignment");
928 value = Visit(e->
getRHS());
939mlir::Value ComplexExprEmitter::VisitBinAssign(
const BinaryOperator *e) {
941 LValue lv = emitBinAssignLValue(e, value);
949 if (!lv.isVolatile())
955mlir::Value ComplexExprEmitter::VisitBinComma(
const BinaryOperator *e) {
957 return Visit(e->
getRHS());
960mlir::Value ComplexExprEmitter::VisitAbstractConditionalOperator(
961 const AbstractConditionalOperator *e) {
965 CIRGenFunction::OpaqueValueMapping binding(cgf, e);
967 CIRGenFunction::ConditionalEvaluation eval(cgf);
973 .create<cir::TernaryOp>(
976 [&](mlir::OpBuilder &
b, mlir::Location loc) {
977 eval.beginEvaluation();
979 b.create<cir::YieldOp>(loc, trueValue);
980 eval.endEvaluation();
983 [&](mlir::OpBuilder &
b, mlir::Location loc) {
984 eval.beginEvaluation();
986 b.create<cir::YieldOp>(loc, falseValue);
987 eval.endEvaluation();
992mlir::Value ComplexExprEmitter::VisitChooseExpr(ChooseExpr *e) {
996mlir::Value ComplexExprEmitter::VisitInitListExpr(InitListExpr *e) {
1007 assert(e->
getNumInits() == 0 &&
"Unexpected number of inits");
1012mlir::Value ComplexExprEmitter::VisitVAArgExpr(VAArgExpr *e) {
1024 "Invalid complex expression to emit");
1026 return ComplexExprEmitter(*this).Visit(
const_cast<Expr *
>(e));
1032 "Invalid complex expression to emit");
1033 ComplexExprEmitter emitter(*
this);
1034 mlir::Value value = emitter.Visit(
const_cast<Expr *
>(e));
1040 LValue dest,
bool isInit) {
1041 ComplexExprEmitter(*this).emitStoreOfComplex(loc, v, dest, isInit);
1045 return ComplexExprEmitter(*this).emitLoadOfLValue(src, loc);
1049 assert(e->
getOpcode() == BO_Assign &&
"Expected assign op");
1052 LValue lvalue = ComplexExprEmitter(*this).emitBinAssignLValue(e, value);
1054 cgm.errorNYI(
"emitComplexAssignmentLValue OpenMP");
1060 mlir::Value (ComplexExprEmitter::*)(
const ComplexExprEmitter::BinOpInfo &);
1065 return &ComplexExprEmitter::emitBinMul;
1067 return &ComplexExprEmitter::emitBinDiv;
1069 return &ComplexExprEmitter::emitBinSub;
1071 return &ComplexExprEmitter::emitBinAdd;
1073 llvm_unreachable(
"unexpected complex compound assignment");
1081 return ComplexExprEmitter(*this).emitCompoundAssignLValue(e, op, val);
1086 cir::UnaryOpKind op,
1088 assert(op == cir::UnaryOpKind::Inc ||
1089 op == cir::UnaryOpKind::Dec &&
"Invalid UnaryOp kind for ComplexType");
1093 mlir::Value incVal = builder.createUnaryOp(loc, op, inVal);
1099 cgm.errorNYI(loc,
"emitComplexPrePostIncDec OpenMP");
1103 return isPre ? incVal : inVal;
1112 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
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 ?
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::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::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,...
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.
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.
SourceLocation getExprLoc() const
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...
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
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.
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
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 cgFPOptionsRAII()
static bool fastMathFlags()