Lines Matching +full:v +full:- +full:neg +full:- +full:supply
1 //===--- CGExprComplex.cpp - Emit LLVM Code for Complex Exprs -------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
11 //===----------------------------------------------------------------------===//
27 //===----------------------------------------------------------------------===//
29 //===----------------------------------------------------------------------===//
43 return cast<ComplexType>(cast<AtomicType>(type)->getValueType()); in getComplexType()
61 //===--------------------------------------------------------------------===//
63 //===--------------------------------------------------------------------===//
76 /// EmitLoadOfLValue - Given an expression with complex type that represents a
77 /// value l-value, this method emits the address of the l-value, then loads
80 return EmitLoadOfLValue(CGF.EmitLValue(E), E->getExprLoc()); in EmitLoadOfLValue()
85 /// EmitStoreOfComplex - Store the specified real/imag parts into the
96 //===--------------------------------------------------------------------===//
98 //===--------------------------------------------------------------------===//
106 S->dump(llvm::errs(), CGF.getContext()); in VisitStmt()
112 return ComplexPairTy(Result->getAggregateElement(0U), in VisitConstantExpr()
113 Result->getAggregateElement(1U)); in VisitConstantExpr()
114 return Visit(E->getSubExpr()); in VisitConstantExpr()
116 ComplexPairTy VisitParenExpr(ParenExpr *PE) { return Visit(PE->getSubExpr());} in VisitParenExpr()
118 return Visit(GE->getResultExpr()); in VisitGenericSelectionExpr()
123 return Visit(PE->getReplacement()); in VisitSubstNonTypeTemplateParmExpr()
132 return Visit(E->getSubExpr()); in VisitUnaryCoawait()
140 E->getExprLoc()); in emitConstant()
143 return ComplexPairTy(pair->getAggregateElement(0U), in emitConstant()
144 pair->getAggregateElement(1U)); in emitConstant()
147 // l-values.
163 CGF.EmitIgnoredExpr(ME->getBase()); in VisitMemberExpr()
169 if (E->isGLValue()) in VisitOpaqueValueExpr()
171 E->getExprLoc()); in VisitOpaqueValueExpr()
183 // Unlike for scalars, we don't have to worry about function->ptr demotion in VisitImplicitCastExpr()
185 if (E->changesVolatileQualification()) in VisitImplicitCastExpr()
187 return EmitCast(E->getCastKind(), E->getSubExpr(), E->getType()); in VisitImplicitCastExpr()
192 if (E->changesVolatileQualification()) in VisitCastExpr()
194 return EmitCast(E->getCastKind(), E->getSubExpr(), E->getType()); in VisitCastExpr()
202 LValue LV = CGF.EmitLValue(E->getSubExpr()); in VisitPrePostIncDec()
228 return Visit(E->getSubExpr()); in VisitUnaryExtension()
232 return Visit(DAE->getExpr()); in VisitCXXDefaultArgExpr()
236 return Visit(DIE->getExpr()); in VisitCXXDefaultInitExpr()
240 ComplexPairTy Vals = Visit(E->getSubExpr()); in VisitExprWithCleanups()
247 assert(E->getType()->isAnyComplexType() && "Expected complex type!"); in VisitCXXScalarValueInitExpr()
248 QualType Elem = E->getType()->castAs<ComplexType>()->getElementType(); in VisitCXXScalarValueInitExpr()
253 assert(E->getType()->isAnyComplexType() && "Expected complex type!"); in VisitImplicitValueInitExpr()
254 QualType Elem = E->getType()->castAs<ComplexType>()->getElementType(); in VisitImplicitValueInitExpr()
293 switch (CurrentBT->getKind()) { in GetHigherPrecisionFPType()
333 if (auto *CT = Ty->getAs<ComplexType>()) { in getPromotionType()
334 QualType ElementType = CT->getElementType(); in getPromotionType()
335 bool IsFloatingType = ElementType->isFloatingType(); in getPromotionType()
358 E->getStoredFPFeaturesOrDefault(), E->getType(), \
359 (E->getOpcode() == BinaryOperatorKind::BO_Div) ? true : false); \
362 result = CGF.EmitUnPromotedValue(result, E->getType()); \
373 return Visit(E->getSemanticForm()); in HANDLEBINOP()
418 return Visit(E->getSelectedExpr()); in VisitPackIndexingExpr()
423 //===----------------------------------------------------------------------===//
425 //===----------------------------------------------------------------------===//
437 /// EmitLoadOfLValue - Given an RValue reference for a complex, emit code to
441 assert(lvalue.isSimple() && "non-simple complex l-value?"); in EmitLoadOfLValue()
442 if (lvalue.getType()->isAtomicType()) in EmitLoadOfLValue()
463 /// EmitStoreOfComplex - Store the specified real/imag parts into the
467 if (lvalue.getType()->isAtomicType() || in EmitStoreOfComplex()
481 //===----------------------------------------------------------------------===//
483 //===----------------------------------------------------------------------===//
488 CGF.ConvertType(getComplexType(E->getType())->getElementType()); in VisitExpr()
495 llvm::Value *Imag = CGF.EmitScalarExpr(IL->getSubExpr()); in VisitImaginaryLiteral()
496 return ComplexPairTy(llvm::Constant::getNullValue(Imag->getType()), Imag); in VisitImaginaryLiteral()
501 if (E->getCallReturnType(CGF.getContext())->isReferenceType()) in VisitCallExpr()
509 Address RetAlloca = CGF.EmitCompoundStmt(*E->getSubStmt(), true); in VisitStmtExpr()
511 return EmitLoadOfLValue(CGF.MakeAddrLValue(RetAlloca, E->getType()), in VisitStmtExpr()
512 E->getExprLoc()); in VisitStmtExpr()
521 SrcType = SrcType->castAs<ComplexType>()->getElementType(); in EmitComplexToComplexCast()
522 DestType = DestType->castAs<ComplexType>()->getElementType(); in EmitComplexToComplexCast()
539 DestType = DestType->castAs<ComplexType>()->getElementType(); in EmitScalarToComplexCast()
543 return ComplexPairTy(Val, llvm::Constant::getNullValue(Val->getType())); in EmitScalarToComplexCast()
551 // Atomic to non-atomic casts may be more than a no-op for some platforms and in EmitCast()
562 Address V = origLV.getAddress().withElementType(CGF.ConvertType(DestTy)); in EmitCast() local
563 return EmitLoadOfLValue(CGF.MakeAddrLValue(V, DestTy), Op->getExprLoc()); in EmitCast()
572 return EmitLoadOfLValue(DestLV, Op->getExprLoc()); in EmitCast()
633 return EmitScalarToComplexCast(CGF.EmitScalarExpr(Op), Op->getType(), in EmitCast()
634 DestTy, Op->getExprLoc()); in EmitCast()
642 return EmitComplexToComplexCast(Visit(Op), Op->getType(), DestTy, in EmitCast()
643 Op->getExprLoc()); in EmitCast()
652 E->hasStoredFPFeatures(); in VisitUnaryPlus()
655 ? getPromotionType(E->getStoredFPFeaturesOrDefault(), in VisitUnaryPlus()
656 E->getSubExpr()->getType()) in VisitUnaryPlus()
660 return CGF.EmitUnPromotedValue(result, E->getSubExpr()->getType()); in VisitUnaryPlus()
669 return CGF.EmitPromotedComplexExpr(E->getSubExpr(), PromotionType); in VisitPlus()
670 return Visit(E->getSubExpr()); in VisitPlus()
677 ? getPromotionType(E->getStoredFPFeaturesOrDefault(), in VisitUnaryMinus()
678 E->getSubExpr()->getType()) in VisitUnaryMinus()
682 return CGF.EmitUnPromotedValue(result, E->getSubExpr()->getType()); in VisitUnaryMinus()
691 Op = CGF.EmitPromotedComplexExpr(E->getSubExpr(), PromotionType); in VisitMinus()
693 Op = Visit(E->getSubExpr()); in VisitMinus()
696 if (Op.first->getType()->isFloatingPointTy()) { in VisitMinus()
697 ResR = Builder.CreateFNeg(Op.first, "neg.r"); in VisitMinus()
698 ResI = Builder.CreateFNeg(Op.second, "neg.i"); in VisitMinus()
700 ResR = Builder.CreateNeg(Op.first, "neg.r"); in VisitMinus()
701 ResI = Builder.CreateNeg(Op.second, "neg.i"); in VisitMinus()
709 // ~(a+ib) = a + i*-b in VisitUnaryNot()
710 ComplexPairTy Op = Visit(E->getSubExpr()); in VisitUnaryNot()
712 if (Op.second->getType()->isFloatingPointTy()) in VisitUnaryNot()
723 if (Op.LHS.first->getType()->isFloatingPointTy()) { in EmitBinAdd()
742 if (Op.LHS.first->getType()->isFloatingPointTy()) { in EmitBinSub()
765 Op.Ty->castAs<ComplexType>()->getElementType()); in EmitComplexBinOpLibCall()
767 Op.Ty->castAs<ComplexType>()->getElementType()); in EmitComplexBinOpLibCall()
769 Op.Ty->castAs<ComplexType>()->getElementType()); in EmitComplexBinOpLibCall()
771 Op.Ty->castAs<ComplexType>()->getElementType()); in EmitComplexBinOpLibCall()
783 4, Op.Ty->castAs<ComplexType>()->getElementType()); in EmitComplexBinOpLibCall()
791 CGCallee Callee = CGCallee::forDirect(Func, FQTy->getAs<FunctionProtoType>()); in EmitComplexBinOpLibCall()
795 Call->setCallingConv(CGF.CGM.getRuntimeCC()); in EmitComplexBinOpLibCall()
802 switch (Ty->getTypeID()) { in getComplexMultiplyLibCallName()
827 if (Op.LHS.first->getType()->isFloatingPointTy()) { in EmitBinMul()
829 // (a + ib) * (c + id) = (a * c - b * d) + i(a * d + b * c) in EmitBinMul()
838 // to carefully re-compute the correct infinity representation if in EmitBinMul()
841 // This is good, because the libcall re-computes the core multiplication in EmitBinMul()
842 // exactly the same as we do here and re-tests for NaNs in order to be in EmitBinMul()
867 llvm::BasicBlock *OrigBB = Branch->getParent(); in EmitBinMul()
871 Branch->setMetadata(llvm::LLVMContext::MD_prof, BrWeight); in EmitBinMul()
878 Branch->setMetadata(llvm::LLVMContext::MD_prof, BrWeight); in EmitBinMul()
884 getComplexMultiplyLibCallName(Op.LHS.first->getType()), Op); in EmitBinMul()
887 // Finally continue execution by phi-ing together the different in EmitBinMul()
890 llvm::PHINode *RealPHI = Builder.CreatePHI(ResR->getType(), 3, "real_mul_phi"); in EmitBinMul()
891 RealPHI->addIncoming(ResR, OrigBB); in EmitBinMul()
892 RealPHI->addIncoming(ResR, INaNBB); in EmitBinMul()
893 RealPHI->addIncoming(LibCallR, LibCallBB); in EmitBinMul()
894 llvm::PHINode *ImagPHI = Builder.CreatePHI(ResI->getType(), 3, "imag_mul_phi"); in EmitBinMul()
895 ImagPHI->addIncoming(ResI, OrigBB); in EmitBinMul()
896 ImagPHI->addIncoming(ResI, INaNBB); in EmitBinMul()
897 ImagPHI->addIncoming(LibCallI, LibCallBB); in EmitBinMul()
929 // (a+ib) / (c+id) = ((ac+bd)/(cc+dd)) + i((bc-ad)/(cc+dd)) in EmitAlgebraicDiv()
942 llvm::Value *BCmAD = Builder.CreateFSub(BC, AD); // bc-ad in EmitAlgebraicDiv()
949 // EmitFAbs - Emit a call to @llvm.fabs.
952 CGF.CGM.getIntrinsic(llvm::Intrinsic::fabs, Value->getType()); in EmitllvmFAbs()
957 // EmitRangeReductionDiv - Implements Smith's algorithm for complex division.
984 // f = (b - ar)/tmp in EmitRangeReductionDiv()
995 llvm::Value *T6 = Builder.CreateFSub(LHSi, T5); // b-ar in EmitRangeReductionDiv()
996 llvm::Value *DSTTi = Builder.CreateFDiv(T6, CpRD); // (b-ar)/tmp in EmitRangeReductionDiv()
1004 // f = (br - a)/tmp in EmitRangeReductionDiv()
1015 llvm::Value *T10 = Builder.CreateFSub(T9, LHSr); // br-a in EmitRangeReductionDiv()
1016 llvm::Value *DSTFi = Builder.CreateFDiv(T10, DpRC); // (br-a)/tmp in EmitRangeReductionDiv()
1021 llvm::PHINode *VALr = Builder.CreatePHI(DSTTr->getType(), 2); in EmitRangeReductionDiv()
1022 VALr->addIncoming(DSTTr, TrueBB); in EmitRangeReductionDiv()
1023 VALr->addIncoming(DSTFr, FalseBB); in EmitRangeReductionDiv()
1024 llvm::PHINode *VALi = Builder.CreatePHI(DSTTi->getType(), 2); in EmitRangeReductionDiv()
1025 VALi->addIncoming(DSTTi, TrueBB); in EmitRangeReductionDiv()
1026 VALi->addIncoming(DSTFi, FalseBB); in EmitRangeReductionDiv()
1036 if (LHSr->getType()->isFloatingPointTy()) { in EmitBinDiv()
1039 assert(LHSi && "Can have at most one non-complex operand!"); in EmitBinDiv()
1047 LHSi = llvm::Constant::getNullValue(RHSi->getType()); in EmitBinDiv()
1055 // '-ffast-math' is used in the command line but followed by an in EmitBinDiv()
1056 // '-fno-cx-limited-range' or '-fcomplex-arithmetic=full'. in EmitBinDiv()
1064 // If LHS was a real, supply a null imaginary part. in EmitBinDiv()
1066 LibCallOp.LHS.second = llvm::Constant::getNullValue(LHSr->getType()); in EmitBinDiv()
1068 switch (LHSr->getType()->getTypeID()) { in EmitBinDiv()
1090 // (a+ib) / (c+id) = ((ac+bd)/(cc+dd)) + i((bc-ad)/(cc+dd)) in EmitBinDiv()
1101 llvm::Value *Tmp9 = Builder.CreateSub(Tmp7, Tmp8); // bc-ad in EmitBinDiv()
1103 if (Op.Ty->castAs<ComplexType>()->getElementType()->isUnsignedIntegerType()) { in EmitBinDiv()
1118 ConvertType(UnPromotionType->castAs<ComplexType>()->getElementType()); in EmitUnPromotedValue()
1131 ConvertType(PromotionType->castAs<ComplexType>()->getElementType()); in EmitPromotedValue()
1142 E = E->IgnoreParens(); in EmitPromoted()
1144 switch (BO->getOpcode()) { in EmitPromoted()
1157 switch (UO->getOpcode()) { in EmitPromoted()
1181 if (E->getType()->isAnyComplexType()) { in EmitPromotedComplexOperand()
1189 OverallPromotionType->castAs<ComplexType>()->getElementType(); in EmitPromotedComplexOperand()
1205 Ops.LHS = EmitPromotedComplexOperand(E->getLHS(), PromotionType); in EmitBinOps()
1206 Ops.RHS = EmitPromotedComplexOperand(E->getRHS(), PromotionType); in EmitBinOps()
1210 Ops.Ty = E->getType(); in EmitBinOps()
1211 Ops.FPFeatures = E->getFPFeaturesInEffect(CGF.getLangOpts()); in EmitBinOps()
1222 QualType LHSTy = E->getLHS()->getType(); in EmitCompoundAssignLValue()
1223 if (const AtomicType *AT = LHSTy->getAs<AtomicType>()) in EmitCompoundAssignLValue()
1224 LHSTy = AT->getValueType(); in EmitCompoundAssignLValue()
1227 OpInfo.FPFeatures = E->getFPFeaturesInEffect(CGF.getLangOpts()); in EmitCompoundAssignLValue()
1234 PromotionTypeCR = getPromotionType(E->getStoredFPFeaturesOrDefault(), in EmitCompoundAssignLValue()
1235 E->getComputationResultType()); in EmitCompoundAssignLValue()
1237 PromotionTypeCR = E->getComputationResultType(); in EmitCompoundAssignLValue()
1240 OpInfo.Ty->castAs<ComplexType>()->getElementType(); in EmitCompoundAssignLValue()
1242 E->getStoredFPFeaturesOrDefault(), E->getRHS()->getType()); in EmitCompoundAssignLValue()
1245 if (E->getRHS()->getType()->isRealFloatingType()) { in EmitCompoundAssignLValue()
1248 CGF.EmitPromotedScalarExpr(E->getRHS(), PromotionTypeRHS), nullptr); in EmitCompoundAssignLValue()
1251 E->getRHS()->getType())); in EmitCompoundAssignLValue()
1253 OpInfo.RHS = ComplexPairTy(CGF.EmitScalarExpr(E->getRHS()), nullptr); in EmitCompoundAssignLValue()
1258 CGF.EmitPromotedComplexExpr(E->getRHS(), PromotionTypeRHS)); in EmitCompoundAssignLValue()
1261 E->getRHS()->getType())); in EmitCompoundAssignLValue()
1262 OpInfo.RHS = Visit(E->getRHS()); in EmitCompoundAssignLValue()
1266 LValue LHS = CGF.EmitLValue(E->getLHS()); in EmitCompoundAssignLValue()
1268 // Load from the l-value and convert it. in EmitCompoundAssignLValue()
1269 SourceLocation Loc = E->getExprLoc(); in EmitCompoundAssignLValue()
1271 E->getStoredFPFeaturesOrDefault(), E->getComputationLHSType()); in EmitCompoundAssignLValue()
1272 if (LHSTy->isAnyComplexType()) { in EmitCompoundAssignLValue()
1283 if (LHSTy->isRealFloatingType()) { in EmitCompoundAssignLValue()
1287 cast<ComplexType>(PromotionTypeLHS)->getElementType(); in EmitCompoundAssignLValue()
1304 ComplexPairTy Result = (this->*Func)(OpInfo); in EmitCompoundAssignLValue()
1307 if (LHSTy->isAnyComplexType()) { in EmitCompoundAssignLValue()
1329 // The result of an assignment in C is the assigned r-value. in EmitCompoundAssign()
1333 // If the lvalue is non-volatile, return the computed value of the assignment. in EmitCompoundAssign()
1337 return EmitLoadOfLValue(LV, E->getExprLoc()); in EmitCompoundAssign()
1342 assert(CGF.getContext().hasSameUnqualifiedType(E->getLHS()->getType(), in EmitBinAssignLValue()
1343 E->getRHS()->getType()) && in EmitBinAssignLValue()
1349 Val = Visit(E->getRHS()); in EmitBinAssignLValue()
1352 LValue LHS = CGF.EmitLValue(E->getLHS()); in EmitBinAssignLValue()
1364 // The result of an assignment in C is the assigned r-value. in VisitBinAssign()
1368 // If the lvalue is non-volatile, return the computed value of the assignment. in VisitBinAssign()
1372 return EmitLoadOfLValue(LV, E->getExprLoc()); in VisitBinAssign()
1376 CGF.EmitIgnoredExpr(E->getLHS()); in VisitBinComma()
1377 return Visit(E->getRHS()); in VisitBinComma()
1393 CGF.EmitBranchOnBoolExpr(E->getCond(), LHSBlock, RHSBlock, in VisitAbstractConditionalOperator()
1399 CGF.incrementProfileCounter(E->getTrueExpr()); in VisitAbstractConditionalOperator()
1403 ComplexPairTy LHS = Visit(E->getTrueExpr()); in VisitAbstractConditionalOperator()
1411 CGF.incrementProfileCounter(E->getFalseExpr()); in VisitAbstractConditionalOperator()
1412 ComplexPairTy RHS = Visit(E->getFalseExpr()); in VisitAbstractConditionalOperator()
1420 llvm::PHINode *RealPN = Builder.CreatePHI(LHS.first->getType(), 2, "cond.r"); in VisitAbstractConditionalOperator()
1421 RealPN->addIncoming(LHS.first, LHSBlock); in VisitAbstractConditionalOperator()
1422 RealPN->addIncoming(RHS.first, RHSBlock); in VisitAbstractConditionalOperator()
1425 llvm::PHINode *ImagPN = Builder.CreatePHI(LHS.first->getType(), 2, "cond.i"); in VisitAbstractConditionalOperator()
1426 ImagPN->addIncoming(LHS.second, LHSBlock); in VisitAbstractConditionalOperator()
1427 ImagPN->addIncoming(RHS.second, RHSBlock); in VisitAbstractConditionalOperator()
1433 return Visit(E->getChosenSubExpr()); in VisitChooseExpr()
1444 if (E->getNumInits() == 2) { in VisitInitListExpr()
1445 llvm::Value *Real = CGF.EmitScalarExpr(E->getInit(0)); in VisitInitListExpr()
1446 llvm::Value *Imag = CGF.EmitScalarExpr(E->getInit(1)); in VisitInitListExpr()
1448 } else if (E->getNumInits() == 1) { in VisitInitListExpr()
1449 return Visit(E->getInit(0)); in VisitInitListExpr()
1453 assert(E->getNumInits() == 0 && "Unexpected number of inits"); in VisitInitListExpr()
1454 QualType Ty = E->getType()->castAs<ComplexType>()->getElementType(); in VisitInitListExpr()
1467 CGF.ConvertType(E->getType()->castAs<ComplexType>()->getElementType()); in VisitVAArgExpr()
1475 //===----------------------------------------------------------------------===//
1477 //===----------------------------------------------------------------------===//
1479 /// EmitComplexExpr - Emit the computation of the specified expression of
1483 assert(E && getComplexType(E->getType()) && in EmitComplexExpr()
1492 assert(E && getComplexType(E->getType()) && in EmitComplexExprIntoLValue()
1499 /// EmitStoreOfComplex - Store a complex number into the specified l-value.
1500 void CodeGenFunction::EmitStoreOfComplex(ComplexPairTy V, LValue dest, in EmitStoreOfComplex() argument
1502 ComplexExprEmitter(*this).EmitStoreOfComplex(V, dest, isInit); in EmitStoreOfComplex()
1505 /// EmitLoadOfComplex - Load a complex number from the specified address.
1512 assert(E->getOpcode() == BO_Assign); in EmitComplexAssignmentLValue()
1517 E->getLHS()); in EmitComplexAssignmentLValue()
1537 CompoundFunc Op = getComplexOp(E->getOpcode()); in EmitComplexCompoundAssignmentLValue()
1545 CompoundFunc Op = getComplexOp(E->getOpcode()); in EmitScalarCompoundAssignWithComplex()