clang 17.0.0git
CGExprComplex.cpp
Go to the documentation of this file.
1//===--- CGExprComplex.cpp - Emit LLVM Code for Complex Exprs -------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This contains code to emit Expr nodes with complex types as LLVM code.
10//
11//===----------------------------------------------------------------------===//
12
13#include "CGOpenMPRuntime.h"
14#include "CodeGenFunction.h"
15#include "CodeGenModule.h"
16#include "ConstantEmitter.h"
18#include "llvm/ADT/STLExtras.h"
19#include "llvm/IR/Constants.h"
20#include "llvm/IR/Instructions.h"
21#include "llvm/IR/MDBuilder.h"
22#include "llvm/IR/Metadata.h"
23#include <algorithm>
24using namespace clang;
25using namespace CodeGen;
26
27//===----------------------------------------------------------------------===//
28// Complex Expression Emitter
29//===----------------------------------------------------------------------===//
30
31typedef CodeGenFunction::ComplexPairTy ComplexPairTy;
32
33/// Return the complex type that we are meant to emit.
35 type = type.getCanonicalType();
36 if (const ComplexType *comp = dyn_cast<ComplexType>(type)) {
37 return comp;
38 } else {
39 return cast<ComplexType>(cast<AtomicType>(type)->getValueType());
40 }
41}
42
43namespace {
44class ComplexExprEmitter
45 : public StmtVisitor<ComplexExprEmitter, ComplexPairTy> {
46 CodeGenFunction &CGF;
47 CGBuilderTy &Builder;
48 bool IgnoreReal;
49 bool IgnoreImag;
50public:
51 ComplexExprEmitter(CodeGenFunction &cgf, bool ir=false, bool ii=false)
52 : CGF(cgf), Builder(CGF.Builder), IgnoreReal(ir), IgnoreImag(ii) {
53 }
54
55
56 //===--------------------------------------------------------------------===//
57 // Utilities
58 //===--------------------------------------------------------------------===//
59
60 bool TestAndClearIgnoreReal() {
61 bool I = IgnoreReal;
62 IgnoreReal = false;
63 return I;
64 }
65 bool TestAndClearIgnoreImag() {
66 bool I = IgnoreImag;
67 IgnoreImag = false;
68 return I;
69 }
70
71 /// EmitLoadOfLValue - Given an expression with complex type that represents a
72 /// value l-value, this method emits the address of the l-value, then loads
73 /// and returns the result.
74 ComplexPairTy EmitLoadOfLValue(const Expr *E) {
75 return EmitLoadOfLValue(CGF.EmitLValue(E), E->getExprLoc());
76 }
77
78 ComplexPairTy EmitLoadOfLValue(LValue LV, SourceLocation Loc);
79
80 /// EmitStoreOfComplex - Store the specified real/imag parts into the
81 /// specified value pointer.
82 void EmitStoreOfComplex(ComplexPairTy Val, LValue LV, bool isInit);
83
84 /// Emit a cast from complex value Val to DestType.
85 ComplexPairTy EmitComplexToComplexCast(ComplexPairTy Val, QualType SrcType,
86 QualType DestType, SourceLocation Loc);
87 /// Emit a cast from scalar value Val to DestType.
88 ComplexPairTy EmitScalarToComplexCast(llvm::Value *Val, QualType SrcType,
89 QualType DestType, SourceLocation Loc);
90
91 //===--------------------------------------------------------------------===//
92 // Visitor Methods
93 //===--------------------------------------------------------------------===//
94
96 ApplyDebugLocation DL(CGF, E);
98 }
99
100 ComplexPairTy VisitStmt(Stmt *S) {
101 S->dump(llvm::errs(), CGF.getContext());
102 llvm_unreachable("Stmt can't have complex result type!");
103 }
104 ComplexPairTy VisitExpr(Expr *S);
105 ComplexPairTy VisitConstantExpr(ConstantExpr *E) {
106 if (llvm::Constant *Result = ConstantEmitter(CGF).tryEmitConstantExpr(E))
107 return ComplexPairTy(Result->getAggregateElement(0U),
108 Result->getAggregateElement(1U));
109 return Visit(E->getSubExpr());
110 }
111 ComplexPairTy VisitParenExpr(ParenExpr *PE) { return Visit(PE->getSubExpr());}
112 ComplexPairTy VisitGenericSelectionExpr(GenericSelectionExpr *GE) {
113 return Visit(GE->getResultExpr());
114 }
115 ComplexPairTy VisitImaginaryLiteral(const ImaginaryLiteral *IL);
117 VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *PE) {
118 return Visit(PE->getReplacement());
119 }
120 ComplexPairTy VisitCoawaitExpr(CoawaitExpr *S) {
121 return CGF.EmitCoawaitExpr(*S).getComplexVal();
122 }
123 ComplexPairTy VisitCoyieldExpr(CoyieldExpr *S) {
124 return CGF.EmitCoyieldExpr(*S).getComplexVal();
125 }
126 ComplexPairTy VisitUnaryCoawait(const UnaryOperator *E) {
127 return Visit(E->getSubExpr());
128 }
129
130 ComplexPairTy emitConstant(const CodeGenFunction::ConstantEmission &Constant,
131 Expr *E) {
132 assert(Constant && "not a constant");
133 if (Constant.isReference())
134 return EmitLoadOfLValue(Constant.getReferenceLValue(CGF, E),
135 E->getExprLoc());
136
137 llvm::Constant *pair = Constant.getValue();
138 return ComplexPairTy(pair->getAggregateElement(0U),
139 pair->getAggregateElement(1U));
140 }
141
142 // l-values.
143 ComplexPairTy VisitDeclRefExpr(DeclRefExpr *E) {
144 if (CodeGenFunction::ConstantEmission Constant = CGF.tryEmitAsConstant(E))
145 return emitConstant(Constant, E);
146 return EmitLoadOfLValue(E);
147 }
148 ComplexPairTy VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) {
149 return EmitLoadOfLValue(E);
150 }
151 ComplexPairTy VisitObjCMessageExpr(ObjCMessageExpr *E) {
152 return CGF.EmitObjCMessageExpr(E).getComplexVal();
153 }
154 ComplexPairTy VisitArraySubscriptExpr(Expr *E) { return EmitLoadOfLValue(E); }
155 ComplexPairTy VisitMemberExpr(MemberExpr *ME) {
156 if (CodeGenFunction::ConstantEmission Constant =
157 CGF.tryEmitAsConstant(ME)) {
158 CGF.EmitIgnoredExpr(ME->getBase());
159 return emitConstant(Constant, ME);
160 }
161 return EmitLoadOfLValue(ME);
162 }
163 ComplexPairTy VisitOpaqueValueExpr(OpaqueValueExpr *E) {
164 if (E->isGLValue())
165 return EmitLoadOfLValue(CGF.getOrCreateOpaqueLValueMapping(E),
166 E->getExprLoc());
168 }
169
170 ComplexPairTy VisitPseudoObjectExpr(PseudoObjectExpr *E) {
172 }
173
174 // FIXME: CompoundLiteralExpr
175
176 ComplexPairTy EmitCast(CastKind CK, Expr *Op, QualType DestTy);
177 ComplexPairTy VisitImplicitCastExpr(ImplicitCastExpr *E) {
178 // Unlike for scalars, we don't have to worry about function->ptr demotion
179 // here.
180 return EmitCast(E->getCastKind(), E->getSubExpr(), E->getType());
181 }
182 ComplexPairTy VisitCastExpr(CastExpr *E) {
183 if (const auto *ECE = dyn_cast<ExplicitCastExpr>(E))
184 CGF.CGM.EmitExplicitCastExprType(ECE, &CGF);
185 return EmitCast(E->getCastKind(), E->getSubExpr(), E->getType());
186 }
187 ComplexPairTy VisitCallExpr(const CallExpr *E);
188 ComplexPairTy VisitStmtExpr(const StmtExpr *E);
189
190 // Operators.
191 ComplexPairTy VisitPrePostIncDec(const UnaryOperator *E,
192 bool isInc, bool isPre) {
193 LValue LV = CGF.EmitLValue(E->getSubExpr());
194 return CGF.EmitComplexPrePostIncDec(E, LV, isInc, isPre);
195 }
196 ComplexPairTy VisitUnaryPostDec(const UnaryOperator *E) {
197 return VisitPrePostIncDec(E, false, false);
198 }
199 ComplexPairTy VisitUnaryPostInc(const UnaryOperator *E) {
200 return VisitPrePostIncDec(E, true, false);
201 }
202 ComplexPairTy VisitUnaryPreDec(const UnaryOperator *E) {
203 return VisitPrePostIncDec(E, false, true);
204 }
205 ComplexPairTy VisitUnaryPreInc(const UnaryOperator *E) {
206 return VisitPrePostIncDec(E, true, true);
207 }
208 ComplexPairTy VisitUnaryDeref(const Expr *E) { return EmitLoadOfLValue(E); }
209
210 ComplexPairTy VisitUnaryPlus(const UnaryOperator *E,
211 QualType PromotionType = QualType());
212 ComplexPairTy VisitPlus(const UnaryOperator *E, QualType PromotionType);
213 ComplexPairTy VisitUnaryMinus(const UnaryOperator *E,
214 QualType PromotionType = QualType());
215 ComplexPairTy VisitMinus(const UnaryOperator *E, QualType PromotionType);
216 ComplexPairTy VisitUnaryNot (const UnaryOperator *E);
217 // LNot,Real,Imag never return complex.
218 ComplexPairTy VisitUnaryExtension(const UnaryOperator *E) {
219 return Visit(E->getSubExpr());
220 }
221 ComplexPairTy VisitCXXDefaultArgExpr(CXXDefaultArgExpr *DAE) {
222 CodeGenFunction::CXXDefaultArgExprScope Scope(CGF, DAE);
223 return Visit(DAE->getExpr());
224 }
225 ComplexPairTy VisitCXXDefaultInitExpr(CXXDefaultInitExpr *DIE) {
226 CodeGenFunction::CXXDefaultInitExprScope Scope(CGF, DIE);
227 return Visit(DIE->getExpr());
228 }
229 ComplexPairTy VisitExprWithCleanups(ExprWithCleanups *E) {
230 CodeGenFunction::RunCleanupsScope Scope(CGF);
231 ComplexPairTy Vals = Visit(E->getSubExpr());
232 // Defend against dominance problems caused by jumps out of expression
233 // evaluation through the shared cleanup block.
234 Scope.ForceCleanup({&Vals.first, &Vals.second});
235 return Vals;
236 }
237 ComplexPairTy VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
238 assert(E->getType()->isAnyComplexType() && "Expected complex type!");
239 QualType Elem = E->getType()->castAs<ComplexType>()->getElementType();
240 llvm::Constant *Null = llvm::Constant::getNullValue(CGF.ConvertType(Elem));
241 return ComplexPairTy(Null, Null);
242 }
243 ComplexPairTy VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
244 assert(E->getType()->isAnyComplexType() && "Expected complex type!");
245 QualType Elem = E->getType()->castAs<ComplexType>()->getElementType();
246 llvm::Constant *Null =
247 llvm::Constant::getNullValue(CGF.ConvertType(Elem));
248 return ComplexPairTy(Null, Null);
249 }
250
251 struct BinOpInfo {
252 ComplexPairTy LHS;
253 ComplexPairTy RHS;
254 QualType Ty; // Computation Type.
255 FPOptions FPFeatures;
256 };
257
258 BinOpInfo EmitBinOps(const BinaryOperator *E,
259 QualType PromotionTy = QualType());
260 ComplexPairTy EmitPromoted(const Expr *E, QualType PromotionTy);
261 ComplexPairTy EmitPromotedComplexOperand(const Expr *E, QualType PromotionTy);
262 LValue EmitCompoundAssignLValue(const CompoundAssignOperator *E,
263 ComplexPairTy (ComplexExprEmitter::*Func)
264 (const BinOpInfo &),
265 RValue &Val);
266 ComplexPairTy EmitCompoundAssign(const CompoundAssignOperator *E,
267 ComplexPairTy (ComplexExprEmitter::*Func)
268 (const BinOpInfo &));
269
270 ComplexPairTy EmitBinAdd(const BinOpInfo &Op);
271 ComplexPairTy EmitBinSub(const BinOpInfo &Op);
272 ComplexPairTy EmitBinMul(const BinOpInfo &Op);
273 ComplexPairTy EmitBinDiv(const BinOpInfo &Op);
274
275 ComplexPairTy EmitComplexBinOpLibCall(StringRef LibCallName,
276 const BinOpInfo &Op);
277
278 QualType getPromotionType(QualType Ty) {
279 if (auto *CT = Ty->getAs<ComplexType>()) {
280 QualType ElementType = CT->getElementType();
281 if (ElementType.UseExcessPrecision(CGF.getContext()))
282 return CGF.getContext().getComplexType(CGF.getContext().FloatTy);
283 }
284 if (Ty.UseExcessPrecision(CGF.getContext()))
285 return CGF.getContext().FloatTy;
286 return QualType();
287 }
288
289#define HANDLEBINOP(OP) \
290 ComplexPairTy VisitBin##OP(const BinaryOperator *E) { \
291 QualType promotionTy = getPromotionType(E->getType()); \
292 ComplexPairTy result = EmitBin##OP(EmitBinOps(E, promotionTy)); \
293 if (!promotionTy.isNull()) \
294 result = \
295 CGF.EmitUnPromotedValue(result, E->getType()); \
296 return result; \
297 }
298
299 HANDLEBINOP(Mul)
300 HANDLEBINOP(Div)
301 HANDLEBINOP(Add)
302 HANDLEBINOP(Sub)
303#undef HANDLEBINOP
304
305 ComplexPairTy VisitCXXRewrittenBinaryOperator(CXXRewrittenBinaryOperator *E) {
306 return Visit(E->getSemanticForm());
307 }
308
309 // Compound assignments.
310 ComplexPairTy VisitBinAddAssign(const CompoundAssignOperator *E) {
311 return EmitCompoundAssign(E, &ComplexExprEmitter::EmitBinAdd);
312 }
313 ComplexPairTy VisitBinSubAssign(const CompoundAssignOperator *E) {
314 return EmitCompoundAssign(E, &ComplexExprEmitter::EmitBinSub);
315 }
316 ComplexPairTy VisitBinMulAssign(const CompoundAssignOperator *E) {
317 return EmitCompoundAssign(E, &ComplexExprEmitter::EmitBinMul);
318 }
319 ComplexPairTy VisitBinDivAssign(const CompoundAssignOperator *E) {
320 return EmitCompoundAssign(E, &ComplexExprEmitter::EmitBinDiv);
321 }
322
323 // GCC rejects rem/and/or/xor for integer complex.
324 // Logical and/or always return int, never complex.
325
326 // No comparisons produce a complex result.
327
328 LValue EmitBinAssignLValue(const BinaryOperator *E,
329 ComplexPairTy &Val);
330 ComplexPairTy VisitBinAssign (const BinaryOperator *E);
331 ComplexPairTy VisitBinComma (const BinaryOperator *E);
332
333
335 VisitAbstractConditionalOperator(const AbstractConditionalOperator *CO);
336 ComplexPairTy VisitChooseExpr(ChooseExpr *CE);
337
338 ComplexPairTy VisitInitListExpr(InitListExpr *E);
339
340 ComplexPairTy VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
341 return EmitLoadOfLValue(E);
342 }
343
344 ComplexPairTy VisitVAArgExpr(VAArgExpr *E);
345
346 ComplexPairTy VisitAtomicExpr(AtomicExpr *E) {
347 return CGF.EmitAtomicExpr(E).getComplexVal();
348 }
349};
350} // end anonymous namespace.
351
352//===----------------------------------------------------------------------===//
353// Utilities
354//===----------------------------------------------------------------------===//
355
356Address CodeGenFunction::emitAddrOfRealComponent(Address addr,
358 return Builder.CreateStructGEP(addr, 0, addr.getName() + ".realp");
359}
360
363 return Builder.CreateStructGEP(addr, 1, addr.getName() + ".imagp");
364}
365
366/// EmitLoadOfLValue - Given an RValue reference for a complex, emit code to
367/// load the real and imaginary pieces, returning them as Real/Imag.
368ComplexPairTy ComplexExprEmitter::EmitLoadOfLValue(LValue lvalue,
369 SourceLocation loc) {
370 assert(lvalue.isSimple() && "non-simple complex l-value?");
371 if (lvalue.getType()->isAtomicType())
372 return CGF.EmitAtomicLoad(lvalue, loc).getComplexVal();
373
374 Address SrcPtr = lvalue.getAddress(CGF);
375 bool isVolatile = lvalue.isVolatileQualified();
376
377 llvm::Value *Real = nullptr, *Imag = nullptr;
378
379 if (!IgnoreReal || isVolatile) {
380 Address RealP = CGF.emitAddrOfRealComponent(SrcPtr, lvalue.getType());
381 Real = Builder.CreateLoad(RealP, isVolatile, SrcPtr.getName() + ".real");
382 }
383
384 if (!IgnoreImag || isVolatile) {
385 Address ImagP = CGF.emitAddrOfImagComponent(SrcPtr, lvalue.getType());
386 Imag = Builder.CreateLoad(ImagP, isVolatile, SrcPtr.getName() + ".imag");
387 }
388
389 return ComplexPairTy(Real, Imag);
390}
391
392/// EmitStoreOfComplex - Store the specified real/imag parts into the
393/// specified value pointer.
394void ComplexExprEmitter::EmitStoreOfComplex(ComplexPairTy Val, LValue lvalue,
395 bool isInit) {
396 if (lvalue.getType()->isAtomicType() ||
397 (!isInit && CGF.LValueIsSuitableForInlineAtomic(lvalue)))
398 return CGF.EmitAtomicStore(RValue::getComplex(Val), lvalue, isInit);
399
400 Address Ptr = lvalue.getAddress(CGF);
401 Address RealPtr = CGF.emitAddrOfRealComponent(Ptr, lvalue.getType());
402 Address ImagPtr = CGF.emitAddrOfImagComponent(Ptr, lvalue.getType());
403
404 Builder.CreateStore(Val.first, RealPtr, lvalue.isVolatileQualified());
405 Builder.CreateStore(Val.second, ImagPtr, lvalue.isVolatileQualified());
406}
407
408
409
410//===----------------------------------------------------------------------===//
411// Visitor Methods
412//===----------------------------------------------------------------------===//
413
414ComplexPairTy ComplexExprEmitter::VisitExpr(Expr *E) {
415 CGF.ErrorUnsupported(E, "complex expression");
416 llvm::Type *EltTy =
418 llvm::Value *U = llvm::UndefValue::get(EltTy);
419 return ComplexPairTy(U, U);
420}
421
422ComplexPairTy ComplexExprEmitter::
423VisitImaginaryLiteral(const ImaginaryLiteral *IL) {
424 llvm::Value *Imag = CGF.EmitScalarExpr(IL->getSubExpr());
425 return ComplexPairTy(llvm::Constant::getNullValue(Imag->getType()), Imag);
426}
427
428
429ComplexPairTy ComplexExprEmitter::VisitCallExpr(const CallExpr *E) {
431 return EmitLoadOfLValue(E);
432
433 return CGF.EmitCallExpr(E).getComplexVal();
434}
435
436ComplexPairTy ComplexExprEmitter::VisitStmtExpr(const StmtExpr *E) {
437 CodeGenFunction::StmtExprEvaluation eval(CGF);
438 Address RetAlloca = CGF.EmitCompoundStmt(*E->getSubStmt(), true);
439 assert(RetAlloca.isValid() && "Expected complex return value");
440 return EmitLoadOfLValue(CGF.MakeAddrLValue(RetAlloca, E->getType()),
441 E->getExprLoc());
442}
443
444/// Emit a cast from complex value Val to DestType.
445ComplexPairTy ComplexExprEmitter::EmitComplexToComplexCast(ComplexPairTy Val,
446 QualType SrcType,
447 QualType DestType,
448 SourceLocation Loc) {
449 // Get the src/dest element type.
450 SrcType = SrcType->castAs<ComplexType>()->getElementType();
451 DestType = DestType->castAs<ComplexType>()->getElementType();
452
453 // C99 6.3.1.6: When a value of complex type is converted to another
454 // complex type, both the real and imaginary parts follow the conversion
455 // rules for the corresponding real types.
456 if (Val.first)
457 Val.first = CGF.EmitScalarConversion(Val.first, SrcType, DestType, Loc);
458 if (Val.second)
459 Val.second = CGF.EmitScalarConversion(Val.second, SrcType, DestType, Loc);
460 return Val;
461}
462
463ComplexPairTy ComplexExprEmitter::EmitScalarToComplexCast(llvm::Value *Val,
464 QualType SrcType,
465 QualType DestType,
466 SourceLocation Loc) {
467 // Convert the input element to the element type of the complex.
468 DestType = DestType->castAs<ComplexType>()->getElementType();
469 Val = CGF.EmitScalarConversion(Val, SrcType, DestType, Loc);
470
471 // Return (realval, 0).
472 return ComplexPairTy(Val, llvm::Constant::getNullValue(Val->getType()));
473}
474
475ComplexPairTy ComplexExprEmitter::EmitCast(CastKind CK, Expr *Op,
476 QualType DestTy) {
477 switch (CK) {
478 case CK_Dependent: llvm_unreachable("dependent cast kind in IR gen!");
479
480 // Atomic to non-atomic casts may be more than a no-op for some platforms and
481 // for some types.
482 case CK_AtomicToNonAtomic:
483 case CK_NonAtomicToAtomic:
484 case CK_NoOp:
485 case CK_LValueToRValue:
486 case CK_UserDefinedConversion:
487 return Visit(Op);
488
489 case CK_LValueBitCast: {
490 LValue origLV = CGF.EmitLValue(Op);
491 Address V = origLV.getAddress(CGF);
492 V = Builder.CreateElementBitCast(V, CGF.ConvertType(DestTy));
493 return EmitLoadOfLValue(CGF.MakeAddrLValue(V, DestTy), Op->getExprLoc());
494 }
495
496 case CK_LValueToRValueBitCast: {
497 LValue SourceLVal = CGF.EmitLValue(Op);
498 Address Addr = Builder.CreateElementBitCast(SourceLVal.getAddress(CGF),
499 CGF.ConvertTypeForMem(DestTy));
500 LValue DestLV = CGF.MakeAddrLValue(Addr, DestTy);
502 return EmitLoadOfLValue(DestLV, Op->getExprLoc());
503 }
504
505 case CK_BitCast:
506 case CK_BaseToDerived:
507 case CK_DerivedToBase:
508 case CK_UncheckedDerivedToBase:
509 case CK_Dynamic:
510 case CK_ToUnion:
511 case CK_ArrayToPointerDecay:
512 case CK_FunctionToPointerDecay:
513 case CK_NullToPointer:
514 case CK_NullToMemberPointer:
515 case CK_BaseToDerivedMemberPointer:
516 case CK_DerivedToBaseMemberPointer:
517 case CK_MemberPointerToBoolean:
518 case CK_ReinterpretMemberPointer:
519 case CK_ConstructorConversion:
520 case CK_IntegralToPointer:
521 case CK_PointerToIntegral:
522 case CK_PointerToBoolean:
523 case CK_ToVoid:
524 case CK_VectorSplat:
525 case CK_IntegralCast:
526 case CK_BooleanToSignedIntegral:
527 case CK_IntegralToBoolean:
528 case CK_IntegralToFloating:
529 case CK_FloatingToIntegral:
530 case CK_FloatingToBoolean:
531 case CK_FloatingCast:
532 case CK_CPointerToObjCPointerCast:
533 case CK_BlockPointerToObjCPointerCast:
534 case CK_AnyPointerToBlockPointerCast:
535 case CK_ObjCObjectLValueCast:
536 case CK_FloatingComplexToReal:
537 case CK_FloatingComplexToBoolean:
538 case CK_IntegralComplexToReal:
539 case CK_IntegralComplexToBoolean:
540 case CK_ARCProduceObject:
541 case CK_ARCConsumeObject:
542 case CK_ARCReclaimReturnedObject:
543 case CK_ARCExtendBlockObject:
544 case CK_CopyAndAutoreleaseBlockObject:
545 case CK_BuiltinFnToFnPtr:
546 case CK_ZeroToOCLOpaqueType:
547 case CK_AddressSpaceConversion:
548 case CK_IntToOCLSampler:
549 case CK_FloatingToFixedPoint:
550 case CK_FixedPointToFloating:
551 case CK_FixedPointCast:
552 case CK_FixedPointToBoolean:
553 case CK_FixedPointToIntegral:
554 case CK_IntegralToFixedPoint:
555 case CK_MatrixCast:
556 llvm_unreachable("invalid cast kind for complex value");
557
558 case CK_FloatingRealToComplex:
559 case CK_IntegralRealToComplex: {
560 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, Op);
561 return EmitScalarToComplexCast(CGF.EmitScalarExpr(Op), Op->getType(),
562 DestTy, Op->getExprLoc());
563 }
564
565 case CK_FloatingComplexCast:
566 case CK_FloatingComplexToIntegralComplex:
567 case CK_IntegralComplexCast:
568 case CK_IntegralComplexToFloatingComplex: {
569 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, Op);
570 return EmitComplexToComplexCast(Visit(Op), Op->getType(), DestTy,
571 Op->getExprLoc());
572 }
573 }
574
575 llvm_unreachable("unknown cast resulting in complex value");
576}
577
578ComplexPairTy ComplexExprEmitter::VisitUnaryPlus(const UnaryOperator *E,
579 QualType PromotionType) {
580 QualType promotionTy = PromotionType.isNull()
581 ? getPromotionType(E->getSubExpr()->getType())
582 : PromotionType;
583 ComplexPairTy result = VisitPlus(E, promotionTy);
584 if (!promotionTy.isNull())
585 return CGF.EmitUnPromotedValue(result, E->getSubExpr()->getType());
586 return result;
587}
588
589ComplexPairTy ComplexExprEmitter::VisitPlus(const UnaryOperator *E,
590 QualType PromotionType) {
591 TestAndClearIgnoreReal();
592 TestAndClearIgnoreImag();
593 if (!PromotionType.isNull())
594 return CGF.EmitPromotedComplexExpr(E->getSubExpr(), PromotionType);
595 return Visit(E->getSubExpr());
596}
597
598ComplexPairTy ComplexExprEmitter::VisitUnaryMinus(const UnaryOperator *E,
599 QualType PromotionType) {
600 QualType promotionTy = PromotionType.isNull()
601 ? getPromotionType(E->getSubExpr()->getType())
602 : PromotionType;
603 ComplexPairTy result = VisitMinus(E, promotionTy);
604 if (!promotionTy.isNull())
605 return CGF.EmitUnPromotedValue(result, E->getSubExpr()->getType());
606 return result;
607}
608ComplexPairTy ComplexExprEmitter::VisitMinus(const UnaryOperator *E,
609 QualType PromotionType) {
610 TestAndClearIgnoreReal();
611 TestAndClearIgnoreImag();
612 ComplexPairTy Op;
613 if (!PromotionType.isNull())
614 Op = CGF.EmitPromotedComplexExpr(E->getSubExpr(), PromotionType);
615 else
616 Op = Visit(E->getSubExpr());
617
618 llvm::Value *ResR, *ResI;
619 if (Op.first->getType()->isFloatingPointTy()) {
620 ResR = Builder.CreateFNeg(Op.first, "neg.r");
621 ResI = Builder.CreateFNeg(Op.second, "neg.i");
622 } else {
623 ResR = Builder.CreateNeg(Op.first, "neg.r");
624 ResI = Builder.CreateNeg(Op.second, "neg.i");
625 }
626 return ComplexPairTy(ResR, ResI);
627}
628
629ComplexPairTy ComplexExprEmitter::VisitUnaryNot(const UnaryOperator *E) {
630 TestAndClearIgnoreReal();
631 TestAndClearIgnoreImag();
632 // ~(a+ib) = a + i*-b
633 ComplexPairTy Op = Visit(E->getSubExpr());
634 llvm::Value *ResI;
635 if (Op.second->getType()->isFloatingPointTy())
636 ResI = Builder.CreateFNeg(Op.second, "conj.i");
637 else
638 ResI = Builder.CreateNeg(Op.second, "conj.i");
639
640 return ComplexPairTy(Op.first, ResI);
641}
642
643ComplexPairTy ComplexExprEmitter::EmitBinAdd(const BinOpInfo &Op) {
644 llvm::Value *ResR, *ResI;
645
646 if (Op.LHS.first->getType()->isFloatingPointTy()) {
647 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, Op.FPFeatures);
648 ResR = Builder.CreateFAdd(Op.LHS.first, Op.RHS.first, "add.r");
649 if (Op.LHS.second && Op.RHS.second)
650 ResI = Builder.CreateFAdd(Op.LHS.second, Op.RHS.second, "add.i");
651 else
652 ResI = Op.LHS.second ? Op.LHS.second : Op.RHS.second;
653 assert(ResI && "Only one operand may be real!");
654 } else {
655 ResR = Builder.CreateAdd(Op.LHS.first, Op.RHS.first, "add.r");
656 assert(Op.LHS.second && Op.RHS.second &&
657 "Both operands of integer complex operators must be complex!");
658 ResI = Builder.CreateAdd(Op.LHS.second, Op.RHS.second, "add.i");
659 }
660 return ComplexPairTy(ResR, ResI);
661}
662
663ComplexPairTy ComplexExprEmitter::EmitBinSub(const BinOpInfo &Op) {
664 llvm::Value *ResR, *ResI;
665 if (Op.LHS.first->getType()->isFloatingPointTy()) {
666 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, Op.FPFeatures);
667 ResR = Builder.CreateFSub(Op.LHS.first, Op.RHS.first, "sub.r");
668 if (Op.LHS.second && Op.RHS.second)
669 ResI = Builder.CreateFSub(Op.LHS.second, Op.RHS.second, "sub.i");
670 else
671 ResI = Op.LHS.second ? Op.LHS.second
672 : Builder.CreateFNeg(Op.RHS.second, "sub.i");
673 assert(ResI && "Only one operand may be real!");
674 } else {
675 ResR = Builder.CreateSub(Op.LHS.first, Op.RHS.first, "sub.r");
676 assert(Op.LHS.second && Op.RHS.second &&
677 "Both operands of integer complex operators must be complex!");
678 ResI = Builder.CreateSub(Op.LHS.second, Op.RHS.second, "sub.i");
679 }
680 return ComplexPairTy(ResR, ResI);
681}
682
683/// Emit a libcall for a binary operation on complex types.
684ComplexPairTy ComplexExprEmitter::EmitComplexBinOpLibCall(StringRef LibCallName,
685 const BinOpInfo &Op) {
686 CallArgList Args;
687 Args.add(RValue::get(Op.LHS.first),
688 Op.Ty->castAs<ComplexType>()->getElementType());
689 Args.add(RValue::get(Op.LHS.second),
690 Op.Ty->castAs<ComplexType>()->getElementType());
691 Args.add(RValue::get(Op.RHS.first),
692 Op.Ty->castAs<ComplexType>()->getElementType());
693 Args.add(RValue::get(Op.RHS.second),
694 Op.Ty->castAs<ComplexType>()->getElementType());
695
696 // We *must* use the full CG function call building logic here because the
697 // complex type has special ABI handling. We also should not forget about
698 // special calling convention which may be used for compiler builtins.
699
700 // We create a function qualified type to state that this call does not have
701 // any exceptions.
703 EPI = EPI.withExceptionSpec(
706 4, Op.Ty->castAs<ComplexType>()->getElementType());
707 QualType FQTy = CGF.getContext().getFunctionType(Op.Ty, ArgsQTys, EPI);
708 const CGFunctionInfo &FuncInfo = CGF.CGM.getTypes().arrangeFreeFunctionCall(
709 Args, cast<FunctionType>(FQTy.getTypePtr()), false);
710
711 llvm::FunctionType *FTy = CGF.CGM.getTypes().GetFunctionType(FuncInfo);
712 llvm::FunctionCallee Func = CGF.CGM.CreateRuntimeFunction(
713 FTy, LibCallName, llvm::AttributeList(), true);
715
716 llvm::CallBase *Call;
717 RValue Res = CGF.EmitCall(FuncInfo, Callee, ReturnValueSlot(), Args, &Call);
718 Call->setCallingConv(CGF.CGM.getRuntimeCC());
719 return Res.getComplexVal();
720}
721
722/// Lookup the libcall name for a given floating point type complex
723/// multiply.
724static StringRef getComplexMultiplyLibCallName(llvm::Type *Ty) {
725 switch (Ty->getTypeID()) {
726 default:
727 llvm_unreachable("Unsupported floating point type!");
728 case llvm::Type::HalfTyID:
729 return "__mulhc3";
730 case llvm::Type::FloatTyID:
731 return "__mulsc3";
732 case llvm::Type::DoubleTyID:
733 return "__muldc3";
734 case llvm::Type::PPC_FP128TyID:
735 return "__multc3";
736 case llvm::Type::X86_FP80TyID:
737 return "__mulxc3";
738 case llvm::Type::FP128TyID:
739 return "__multc3";
740 }
741}
742
743// See C11 Annex G.5.1 for the semantics of multiplicative operators on complex
744// typed values.
745ComplexPairTy ComplexExprEmitter::EmitBinMul(const BinOpInfo &Op) {
746 using llvm::Value;
747 Value *ResR, *ResI;
748 llvm::MDBuilder MDHelper(CGF.getLLVMContext());
749
750 if (Op.LHS.first->getType()->isFloatingPointTy()) {
751 // The general formulation is:
752 // (a + ib) * (c + id) = (a * c - b * d) + i(a * d + b * c)
753 //
754 // But we can fold away components which would be zero due to a real
755 // operand according to C11 Annex G.5.1p2.
756 // FIXME: C11 also provides for imaginary types which would allow folding
757 // still more of this within the type system.
758
759 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, Op.FPFeatures);
760 if (Op.LHS.second && Op.RHS.second) {
761 // If both operands are complex, emit the core math directly, and then
762 // test for NaNs. If we find NaNs in the result, we delegate to a libcall
763 // to carefully re-compute the correct infinity representation if
764 // possible. The expectation is that the presence of NaNs here is
765 // *extremely* rare, and so the cost of the libcall is almost irrelevant.
766 // This is good, because the libcall re-computes the core multiplication
767 // exactly the same as we do here and re-tests for NaNs in order to be
768 // a generic complex*complex libcall.
769
770 // First compute the four products.
771 Value *AC = Builder.CreateFMul(Op.LHS.first, Op.RHS.first, "mul_ac");
772 Value *BD = Builder.CreateFMul(Op.LHS.second, Op.RHS.second, "mul_bd");
773 Value *AD = Builder.CreateFMul(Op.LHS.first, Op.RHS.second, "mul_ad");
774 Value *BC = Builder.CreateFMul(Op.LHS.second, Op.RHS.first, "mul_bc");
775
776 // The real part is the difference of the first two, the imaginary part is
777 // the sum of the second.
778 ResR = Builder.CreateFSub(AC, BD, "mul_r");
779 ResI = Builder.CreateFAdd(AD, BC, "mul_i");
780
781 // Emit the test for the real part becoming NaN and create a branch to
782 // handle it. We test for NaN by comparing the number to itself.
783 Value *IsRNaN = Builder.CreateFCmpUNO(ResR, ResR, "isnan_cmp");
784 llvm::BasicBlock *ContBB = CGF.createBasicBlock("complex_mul_cont");
785 llvm::BasicBlock *INaNBB = CGF.createBasicBlock("complex_mul_imag_nan");
786 llvm::Instruction *Branch = Builder.CreateCondBr(IsRNaN, INaNBB, ContBB);
787 llvm::BasicBlock *OrigBB = Branch->getParent();
788
789 // Give hint that we very much don't expect to see NaNs.
790 // Value chosen to match UR_NONTAKEN_WEIGHT, see BranchProbabilityInfo.cpp
791 llvm::MDNode *BrWeight = MDHelper.createBranchWeights(1, (1U << 20) - 1);
792 Branch->setMetadata(llvm::LLVMContext::MD_prof, BrWeight);
793
794 // Now test the imaginary part and create its branch.
795 CGF.EmitBlock(INaNBB);
796 Value *IsINaN = Builder.CreateFCmpUNO(ResI, ResI, "isnan_cmp");
797 llvm::BasicBlock *LibCallBB = CGF.createBasicBlock("complex_mul_libcall");
798 Branch = Builder.CreateCondBr(IsINaN, LibCallBB, ContBB);
799 Branch->setMetadata(llvm::LLVMContext::MD_prof, BrWeight);
800
801 // Now emit the libcall on this slowest of the slow paths.
802 CGF.EmitBlock(LibCallBB);
803 Value *LibCallR, *LibCallI;
804 std::tie(LibCallR, LibCallI) = EmitComplexBinOpLibCall(
805 getComplexMultiplyLibCallName(Op.LHS.first->getType()), Op);
806 Builder.CreateBr(ContBB);
807
808 // Finally continue execution by phi-ing together the different
809 // computation paths.
810 CGF.EmitBlock(ContBB);
811 llvm::PHINode *RealPHI = Builder.CreatePHI(ResR->getType(), 3, "real_mul_phi");
812 RealPHI->addIncoming(ResR, OrigBB);
813 RealPHI->addIncoming(ResR, INaNBB);
814 RealPHI->addIncoming(LibCallR, LibCallBB);
815 llvm::PHINode *ImagPHI = Builder.CreatePHI(ResI->getType(), 3, "imag_mul_phi");
816 ImagPHI->addIncoming(ResI, OrigBB);
817 ImagPHI->addIncoming(ResI, INaNBB);
818 ImagPHI->addIncoming(LibCallI, LibCallBB);
819 return ComplexPairTy(RealPHI, ImagPHI);
820 }
821 assert((Op.LHS.second || Op.RHS.second) &&
822 "At least one operand must be complex!");
823
824 // If either of the operands is a real rather than a complex, the
825 // imaginary component is ignored when computing the real component of the
826 // result.
827 ResR = Builder.CreateFMul(Op.LHS.first, Op.RHS.first, "mul.rl");
828
829 ResI = Op.LHS.second
830 ? Builder.CreateFMul(Op.LHS.second, Op.RHS.first, "mul.il")
831 : Builder.CreateFMul(Op.LHS.first, Op.RHS.second, "mul.ir");
832 } else {
833 assert(Op.LHS.second && Op.RHS.second &&
834 "Both operands of integer complex operators must be complex!");
835 Value *ResRl = Builder.CreateMul(Op.LHS.first, Op.RHS.first, "mul.rl");
836 Value *ResRr = Builder.CreateMul(Op.LHS.second, Op.RHS.second, "mul.rr");
837 ResR = Builder.CreateSub(ResRl, ResRr, "mul.r");
838
839 Value *ResIl = Builder.CreateMul(Op.LHS.second, Op.RHS.first, "mul.il");
840 Value *ResIr = Builder.CreateMul(Op.LHS.first, Op.RHS.second, "mul.ir");
841 ResI = Builder.CreateAdd(ResIl, ResIr, "mul.i");
842 }
843 return ComplexPairTy(ResR, ResI);
844}
845
846// See C11 Annex G.5.1 for the semantics of multiplicative operators on complex
847// typed values.
848ComplexPairTy ComplexExprEmitter::EmitBinDiv(const BinOpInfo &Op) {
849 llvm::Value *LHSr = Op.LHS.first, *LHSi = Op.LHS.second;
850 llvm::Value *RHSr = Op.RHS.first, *RHSi = Op.RHS.second;
851
852 llvm::Value *DSTr, *DSTi;
853 if (LHSr->getType()->isFloatingPointTy()) {
854 // If we have a complex operand on the RHS and FastMath is not allowed, we
855 // delegate to a libcall to handle all of the complexities and minimize
856 // underflow/overflow cases. When FastMath is allowed we construct the
857 // divide inline using the same algorithm as for integer operands.
858 //
859 // FIXME: We would be able to avoid the libcall in many places if we
860 // supported imaginary types in addition to complex types.
861 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, Op.FPFeatures);
862 if (RHSi && !CGF.getLangOpts().FastMath) {
863 BinOpInfo LibCallOp = Op;
864 // If LHS was a real, supply a null imaginary part.
865 if (!LHSi)
866 LibCallOp.LHS.second = llvm::Constant::getNullValue(LHSr->getType());
867
868 switch (LHSr->getType()->getTypeID()) {
869 default:
870 llvm_unreachable("Unsupported floating point type!");
871 case llvm::Type::HalfTyID:
872 return EmitComplexBinOpLibCall("__divhc3", LibCallOp);
873 case llvm::Type::FloatTyID:
874 return EmitComplexBinOpLibCall("__divsc3", LibCallOp);
875 case llvm::Type::DoubleTyID:
876 return EmitComplexBinOpLibCall("__divdc3", LibCallOp);
877 case llvm::Type::PPC_FP128TyID:
878 return EmitComplexBinOpLibCall("__divtc3", LibCallOp);
879 case llvm::Type::X86_FP80TyID:
880 return EmitComplexBinOpLibCall("__divxc3", LibCallOp);
881 case llvm::Type::FP128TyID:
882 return EmitComplexBinOpLibCall("__divtc3", LibCallOp);
883 }
884 } else if (RHSi) {
885 if (!LHSi)
886 LHSi = llvm::Constant::getNullValue(RHSi->getType());
887
888 // (a+ib) / (c+id) = ((ac+bd)/(cc+dd)) + i((bc-ad)/(cc+dd))
889 llvm::Value *AC = Builder.CreateFMul(LHSr, RHSr); // a*c
890 llvm::Value *BD = Builder.CreateFMul(LHSi, RHSi); // b*d
891 llvm::Value *ACpBD = Builder.CreateFAdd(AC, BD); // ac+bd
892
893 llvm::Value *CC = Builder.CreateFMul(RHSr, RHSr); // c*c
894 llvm::Value *DD = Builder.CreateFMul(RHSi, RHSi); // d*d
895 llvm::Value *CCpDD = Builder.CreateFAdd(CC, DD); // cc+dd
896
897 llvm::Value *BC = Builder.CreateFMul(LHSi, RHSr); // b*c
898 llvm::Value *AD = Builder.CreateFMul(LHSr, RHSi); // a*d
899 llvm::Value *BCmAD = Builder.CreateFSub(BC, AD); // bc-ad
900
901 DSTr = Builder.CreateFDiv(ACpBD, CCpDD);
902 DSTi = Builder.CreateFDiv(BCmAD, CCpDD);
903 } else {
904 assert(LHSi && "Can have at most one non-complex operand!");
905
906 DSTr = Builder.CreateFDiv(LHSr, RHSr);
907 DSTi = Builder.CreateFDiv(LHSi, RHSr);
908 }
909 } else {
910 assert(Op.LHS.second && Op.RHS.second &&
911 "Both operands of integer complex operators must be complex!");
912 // (a+ib) / (c+id) = ((ac+bd)/(cc+dd)) + i((bc-ad)/(cc+dd))
913 llvm::Value *Tmp1 = Builder.CreateMul(LHSr, RHSr); // a*c
914 llvm::Value *Tmp2 = Builder.CreateMul(LHSi, RHSi); // b*d
915 llvm::Value *Tmp3 = Builder.CreateAdd(Tmp1, Tmp2); // ac+bd
916
917 llvm::Value *Tmp4 = Builder.CreateMul(RHSr, RHSr); // c*c
918 llvm::Value *Tmp5 = Builder.CreateMul(RHSi, RHSi); // d*d
919 llvm::Value *Tmp6 = Builder.CreateAdd(Tmp4, Tmp5); // cc+dd
920
921 llvm::Value *Tmp7 = Builder.CreateMul(LHSi, RHSr); // b*c
922 llvm::Value *Tmp8 = Builder.CreateMul(LHSr, RHSi); // a*d
923 llvm::Value *Tmp9 = Builder.CreateSub(Tmp7, Tmp8); // bc-ad
924
925 if (Op.Ty->castAs<ComplexType>()->getElementType()->isUnsignedIntegerType()) {
926 DSTr = Builder.CreateUDiv(Tmp3, Tmp6);
927 DSTi = Builder.CreateUDiv(Tmp9, Tmp6);
928 } else {
929 DSTr = Builder.CreateSDiv(Tmp3, Tmp6);
930 DSTi = Builder.CreateSDiv(Tmp9, Tmp6);
931 }
932 }
933
934 return ComplexPairTy(DSTr, DSTi);
935}
936
938 QualType UnPromotionType) {
939 llvm::Type *ComplexElementTy =
940 ConvertType(UnPromotionType->castAs<ComplexType>()->getElementType());
941 if (result.first)
942 result.first =
943 Builder.CreateFPTrunc(result.first, ComplexElementTy, "unpromotion");
944 if (result.second)
945 result.second =
946 Builder.CreateFPTrunc(result.second, ComplexElementTy, "unpromotion");
947 return result;
948}
949
951 QualType PromotionType) {
952 llvm::Type *ComplexElementTy =
953 ConvertType(PromotionType->castAs<ComplexType>()->getElementType());
954 if (result.first)
955 result.first = Builder.CreateFPExt(result.first, ComplexElementTy, "ext");
956 if (result.second)
957 result.second = Builder.CreateFPExt(result.second, ComplexElementTy, "ext");
958
959 return result;
960}
961
962ComplexPairTy ComplexExprEmitter::EmitPromoted(const Expr *E,
963 QualType PromotionType) {
964 E = E->IgnoreParens();
965 if (auto BO = dyn_cast<BinaryOperator>(E)) {
966 switch (BO->getOpcode()) {
967#define HANDLE_BINOP(OP) \
968 case BO_##OP: \
969 return EmitBin##OP(EmitBinOps(BO, PromotionType));
970 HANDLE_BINOP(Add)
971 HANDLE_BINOP(Sub)
972 HANDLE_BINOP(Mul)
973 HANDLE_BINOP(Div)
974#undef HANDLE_BINOP
975 default:
976 break;
977 }
978 } else if (auto UO = dyn_cast<UnaryOperator>(E)) {
979 switch (UO->getOpcode()) {
980 case UO_Minus:
981 return VisitMinus(UO, PromotionType);
982 case UO_Plus:
983 return VisitPlus(UO, PromotionType);
984 default:
985 break;
986 }
987 }
988 auto result = Visit(const_cast<Expr *>(E));
989 if (!PromotionType.isNull())
990 return CGF.EmitPromotedValue(result, PromotionType);
991 else
992 return result;
993}
994
996 QualType DstTy) {
997 return ComplexExprEmitter(*this).EmitPromoted(E, DstTy);
998}
999
1001ComplexExprEmitter::EmitPromotedComplexOperand(const Expr *E,
1002 QualType OverallPromotionType) {
1003 if (E->getType()->isAnyComplexType()) {
1004 if (!OverallPromotionType.isNull())
1005 return CGF.EmitPromotedComplexExpr(E, OverallPromotionType);
1006 else
1007 return Visit(const_cast<Expr *>(E));
1008 } else {
1009 if (!OverallPromotionType.isNull()) {
1010 QualType ComplexElementTy =
1011 OverallPromotionType->castAs<ComplexType>()->getElementType();
1012 return ComplexPairTy(CGF.EmitPromotedScalarExpr(E, ComplexElementTy),
1013 nullptr);
1014 } else {
1015 return ComplexPairTy(CGF.EmitScalarExpr(E), nullptr);
1016 }
1017 }
1018}
1019
1020ComplexExprEmitter::BinOpInfo
1021ComplexExprEmitter::EmitBinOps(const BinaryOperator *E,
1022 QualType PromotionType) {
1023 TestAndClearIgnoreReal();
1024 TestAndClearIgnoreImag();
1025 BinOpInfo Ops;
1026
1027 Ops.LHS = EmitPromotedComplexOperand(E->getLHS(), PromotionType);
1028 Ops.RHS = EmitPromotedComplexOperand(E->getRHS(), PromotionType);
1029 if (!PromotionType.isNull())
1030 Ops.Ty = PromotionType;
1031 else
1032 Ops.Ty = E->getType();
1033 Ops.FPFeatures = E->getFPFeaturesInEffect(CGF.getLangOpts());
1034 return Ops;
1035}
1036
1037
1038LValue ComplexExprEmitter::
1039EmitCompoundAssignLValue(const CompoundAssignOperator *E,
1040 ComplexPairTy (ComplexExprEmitter::*Func)(const BinOpInfo&),
1041 RValue &Val) {
1042 TestAndClearIgnoreReal();
1043 TestAndClearIgnoreImag();
1044 QualType LHSTy = E->getLHS()->getType();
1045 if (const AtomicType *AT = LHSTy->getAs<AtomicType>())
1046 LHSTy = AT->getValueType();
1047
1048 BinOpInfo OpInfo;
1049 OpInfo.FPFeatures = E->getFPFeaturesInEffect(CGF.getLangOpts());
1050 CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, OpInfo.FPFeatures);
1051
1052 // Load the RHS and LHS operands.
1053 // __block variables need to have the rhs evaluated first, plus this should
1054 // improve codegen a little.
1055 QualType PromotionTypeCR;
1056 PromotionTypeCR = getPromotionType(E->getComputationResultType());
1057 if (PromotionTypeCR.isNull())
1058 PromotionTypeCR = E->getComputationResultType();
1059 OpInfo.Ty = PromotionTypeCR;
1060 QualType ComplexElementTy =
1061 OpInfo.Ty->castAs<ComplexType>()->getElementType();
1062 QualType PromotionTypeRHS = getPromotionType(E->getRHS()->getType());
1063
1064 // The RHS should have been converted to the computation type.
1065 if (E->getRHS()->getType()->isRealFloatingType()) {
1066 if (!PromotionTypeRHS.isNull())
1067 OpInfo.RHS = ComplexPairTy(
1068 CGF.EmitPromotedScalarExpr(E->getRHS(), PromotionTypeRHS), nullptr);
1069 else {
1070 assert(CGF.getContext().hasSameUnqualifiedType(ComplexElementTy,
1071 E->getRHS()->getType()));
1072
1073 OpInfo.RHS = ComplexPairTy(CGF.EmitScalarExpr(E->getRHS()), nullptr);
1074 }
1075 } else {
1076 if (!PromotionTypeRHS.isNull()) {
1077 OpInfo.RHS = ComplexPairTy(
1078 CGF.EmitPromotedComplexExpr(E->getRHS(), PromotionTypeRHS));
1079 } else {
1080 assert(CGF.getContext().hasSameUnqualifiedType(OpInfo.Ty,
1081 E->getRHS()->getType()));
1082 OpInfo.RHS = Visit(E->getRHS());
1083 }
1084 }
1085
1086 LValue LHS = CGF.EmitLValue(E->getLHS());
1087
1088 // Load from the l-value and convert it.
1089 SourceLocation Loc = E->getExprLoc();
1090 QualType PromotionTypeLHS = getPromotionType(E->getComputationLHSType());
1091 if (LHSTy->isAnyComplexType()) {
1092 ComplexPairTy LHSVal = EmitLoadOfLValue(LHS, Loc);
1093 if (!PromotionTypeLHS.isNull())
1094 OpInfo.LHS =
1095 EmitComplexToComplexCast(LHSVal, LHSTy, PromotionTypeLHS, Loc);
1096 else
1097 OpInfo.LHS = EmitComplexToComplexCast(LHSVal, LHSTy, OpInfo.Ty, Loc);
1098 } else {
1099 llvm::Value *LHSVal = CGF.EmitLoadOfScalar(LHS, Loc);
1100 // For floating point real operands we can directly pass the scalar form
1101 // to the binary operator emission and potentially get more efficient code.
1102 if (LHSTy->isRealFloatingType()) {
1103 QualType PromotedComplexElementTy;
1104 if (!PromotionTypeLHS.isNull()) {
1105 PromotedComplexElementTy =
1106 cast<ComplexType>(PromotionTypeLHS)->getElementType();
1107 if (!CGF.getContext().hasSameUnqualifiedType(PromotedComplexElementTy,
1108 PromotionTypeLHS))
1109 LHSVal = CGF.EmitScalarConversion(LHSVal, LHSTy,
1110 PromotedComplexElementTy, Loc);
1111 } else {
1112 if (!CGF.getContext().hasSameUnqualifiedType(ComplexElementTy, LHSTy))
1113 LHSVal =
1114 CGF.EmitScalarConversion(LHSVal, LHSTy, ComplexElementTy, Loc);
1115 }
1116 OpInfo.LHS = ComplexPairTy(LHSVal, nullptr);
1117 } else {
1118 OpInfo.LHS = EmitScalarToComplexCast(LHSVal, LHSTy, OpInfo.Ty, Loc);
1119 }
1120 }
1121
1122 // Expand the binary operator.
1123 ComplexPairTy Result = (this->*Func)(OpInfo);
1124
1125 // Truncate the result and store it into the LHS lvalue.
1126 if (LHSTy->isAnyComplexType()) {
1127 ComplexPairTy ResVal =
1128 EmitComplexToComplexCast(Result, OpInfo.Ty, LHSTy, Loc);
1129 EmitStoreOfComplex(ResVal, LHS, /*isInit*/ false);
1130 Val = RValue::getComplex(ResVal);
1131 } else {
1132 llvm::Value *ResVal =
1133 CGF.EmitComplexToScalarConversion(Result, OpInfo.Ty, LHSTy, Loc);
1134 CGF.EmitStoreOfScalar(ResVal, LHS, /*isInit*/ false);
1135 Val = RValue::get(ResVal);
1136 }
1137
1138 return LHS;
1139}
1140
1141// Compound assignments.
1142ComplexPairTy ComplexExprEmitter::
1143EmitCompoundAssign(const CompoundAssignOperator *E,
1144 ComplexPairTy (ComplexExprEmitter::*Func)(const BinOpInfo&)){
1145 RValue Val;
1146 LValue LV = EmitCompoundAssignLValue(E, Func, Val);
1147
1148 // The result of an assignment in C is the assigned r-value.
1149 if (!CGF.getLangOpts().CPlusPlus)
1150 return Val.getComplexVal();
1151
1152 // If the lvalue is non-volatile, return the computed value of the assignment.
1153 if (!LV.isVolatileQualified())
1154 return Val.getComplexVal();
1155
1156 return EmitLoadOfLValue(LV, E->getExprLoc());
1157}
1158
1159LValue ComplexExprEmitter::EmitBinAssignLValue(const BinaryOperator *E,
1160 ComplexPairTy &Val) {
1161 assert(CGF.getContext().hasSameUnqualifiedType(E->getLHS()->getType(),
1162 E->getRHS()->getType()) &&
1163 "Invalid assignment");
1164 TestAndClearIgnoreReal();
1165 TestAndClearIgnoreImag();
1166
1167 // Emit the RHS. __block variables need the RHS evaluated first.
1168 Val = Visit(E->getRHS());
1169
1170 // Compute the address to store into.
1171 LValue LHS = CGF.EmitLValue(E->getLHS());
1172
1173 // Store the result value into the LHS lvalue.
1174 EmitStoreOfComplex(Val, LHS, /*isInit*/ false);
1175
1176 return LHS;
1177}
1178
1179ComplexPairTy ComplexExprEmitter::VisitBinAssign(const BinaryOperator *E) {
1180 ComplexPairTy Val;
1181 LValue LV = EmitBinAssignLValue(E, Val);
1182
1183 // The result of an assignment in C is the assigned r-value.
1184 if (!CGF.getLangOpts().CPlusPlus)
1185 return Val;
1186
1187 // If the lvalue is non-volatile, return the computed value of the assignment.
1188 if (!LV.isVolatileQualified())
1189 return Val;
1190
1191 return EmitLoadOfLValue(LV, E->getExprLoc());
1192}
1193
1194ComplexPairTy ComplexExprEmitter::VisitBinComma(const BinaryOperator *E) {
1195 CGF.EmitIgnoredExpr(E->getLHS());
1196 return Visit(E->getRHS());
1197}
1198
1199ComplexPairTy ComplexExprEmitter::
1200VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) {
1201 TestAndClearIgnoreReal();
1202 TestAndClearIgnoreImag();
1203 llvm::BasicBlock *LHSBlock = CGF.createBasicBlock("cond.true");
1204 llvm::BasicBlock *RHSBlock = CGF.createBasicBlock("cond.false");
1205 llvm::BasicBlock *ContBlock = CGF.createBasicBlock("cond.end");
1206
1207 // Bind the common expression if necessary.
1208 CodeGenFunction::OpaqueValueMapping binding(CGF, E);
1209
1210
1211 CodeGenFunction::ConditionalEvaluation eval(CGF);
1212 CGF.EmitBranchOnBoolExpr(E->getCond(), LHSBlock, RHSBlock,
1213 CGF.getProfileCount(E));
1214
1215 eval.begin(CGF);
1216 CGF.EmitBlock(LHSBlock);
1218 ComplexPairTy LHS = Visit(E->getTrueExpr());
1219 LHSBlock = Builder.GetInsertBlock();
1220 CGF.EmitBranch(ContBlock);
1221 eval.end(CGF);
1222
1223 eval.begin(CGF);
1224 CGF.EmitBlock(RHSBlock);
1225 ComplexPairTy RHS = Visit(E->getFalseExpr());
1226 RHSBlock = Builder.GetInsertBlock();
1227 CGF.EmitBlock(ContBlock);
1228 eval.end(CGF);
1229
1230 // Create a PHI node for the real part.
1231 llvm::PHINode *RealPN = Builder.CreatePHI(LHS.first->getType(), 2, "cond.r");
1232 RealPN->addIncoming(LHS.first, LHSBlock);
1233 RealPN->addIncoming(RHS.first, RHSBlock);
1234
1235 // Create a PHI node for the imaginary part.
1236 llvm::PHINode *ImagPN = Builder.CreatePHI(LHS.first->getType(), 2, "cond.i");
1237 ImagPN->addIncoming(LHS.second, LHSBlock);
1238 ImagPN->addIncoming(RHS.second, RHSBlock);
1239
1240 return ComplexPairTy(RealPN, ImagPN);
1241}
1242
1243ComplexPairTy ComplexExprEmitter::VisitChooseExpr(ChooseExpr *E) {
1244 return Visit(E->getChosenSubExpr());
1245}
1246
1247ComplexPairTy ComplexExprEmitter::VisitInitListExpr(InitListExpr *E) {
1248 bool Ignore = TestAndClearIgnoreReal();
1249 (void)Ignore;
1250 assert (Ignore == false && "init list ignored");
1251 Ignore = TestAndClearIgnoreImag();
1252 (void)Ignore;
1253 assert (Ignore == false && "init list ignored");
1254
1255 if (E->getNumInits() == 2) {
1256 llvm::Value *Real = CGF.EmitScalarExpr(E->getInit(0));
1257 llvm::Value *Imag = CGF.EmitScalarExpr(E->getInit(1));
1258 return ComplexPairTy(Real, Imag);
1259 } else if (E->getNumInits() == 1) {
1260 return Visit(E->getInit(0));
1261 }
1262
1263 // Empty init list initializes to null
1264 assert(E->getNumInits() == 0 && "Unexpected number of inits");
1265 QualType Ty = E->getType()->castAs<ComplexType>()->getElementType();
1266 llvm::Type* LTy = CGF.ConvertType(Ty);
1267 llvm::Value* zeroConstant = llvm::Constant::getNullValue(LTy);
1268 return ComplexPairTy(zeroConstant, zeroConstant);
1269}
1270
1271ComplexPairTy ComplexExprEmitter::VisitVAArgExpr(VAArgExpr *E) {
1272 Address ArgValue = Address::invalid();
1273 Address ArgPtr = CGF.EmitVAArg(E, ArgValue);
1274
1275 if (!ArgPtr.isValid()) {
1276 CGF.ErrorUnsupported(E, "complex va_arg expression");
1277 llvm::Type *EltTy =
1279 llvm::Value *U = llvm::UndefValue::get(EltTy);
1280 return ComplexPairTy(U, U);
1281 }
1282
1283 return EmitLoadOfLValue(CGF.MakeAddrLValue(ArgPtr, E->getType()),
1284 E->getExprLoc());
1285}
1286
1287//===----------------------------------------------------------------------===//
1288// Entry Point into this File
1289//===----------------------------------------------------------------------===//
1290
1291/// EmitComplexExpr - Emit the computation of the specified expression of
1292/// complex type, ignoring the result.
1293ComplexPairTy CodeGenFunction::EmitComplexExpr(const Expr *E, bool IgnoreReal,
1294 bool IgnoreImag) {
1295 assert(E && getComplexType(E->getType()) &&
1296 "Invalid complex expression to emit");
1297
1298 return ComplexExprEmitter(*this, IgnoreReal, IgnoreImag)
1299 .Visit(const_cast<Expr *>(E));
1300}
1301
1303 bool isInit) {
1304 assert(E && getComplexType(E->getType()) &&
1305 "Invalid complex expression to emit");
1306 ComplexExprEmitter Emitter(*this);
1307 ComplexPairTy Val = Emitter.Visit(const_cast<Expr*>(E));
1308 Emitter.EmitStoreOfComplex(Val, dest, isInit);
1309}
1310
1311/// EmitStoreOfComplex - Store a complex number into the specified l-value.
1313 bool isInit) {
1314 ComplexExprEmitter(*this).EmitStoreOfComplex(V, dest, isInit);
1315}
1316
1317/// EmitLoadOfComplex - Load a complex number from the specified address.
1319 SourceLocation loc) {
1320 return ComplexExprEmitter(*this).EmitLoadOfLValue(src, loc);
1321}
1322
1324 assert(E->getOpcode() == BO_Assign);
1325 ComplexPairTy Val; // ignored
1326 LValue LVal = ComplexExprEmitter(*this).EmitBinAssignLValue(E, Val);
1327 if (getLangOpts().OpenMP)
1329 E->getLHS());
1330 return LVal;
1331}
1332
1333typedef ComplexPairTy (ComplexExprEmitter::*CompoundFunc)(
1334 const ComplexExprEmitter::BinOpInfo &);
1335
1337 switch (Op) {
1338 case BO_MulAssign: return &ComplexExprEmitter::EmitBinMul;
1339 case BO_DivAssign: return &ComplexExprEmitter::EmitBinDiv;
1340 case BO_SubAssign: return &ComplexExprEmitter::EmitBinSub;
1341 case BO_AddAssign: return &ComplexExprEmitter::EmitBinAdd;
1342 default:
1343 llvm_unreachable("unexpected complex compound assignment");
1344 }
1345}
1346
1350 RValue Val;
1351 return ComplexExprEmitter(*this).EmitCompoundAssignLValue(E, Op, Val);
1352}
1353
1356 llvm::Value *&Result) {
1358 RValue Val;
1359 LValue Ret = ComplexExprEmitter(*this).EmitCompoundAssignLValue(E, Op, Val);
1360 Result = Val.getScalarVal();
1361 return Ret;
1362}
#define V(N, I)
Definition: ASTContext.h:3217
#define HANDLEBINOP(OP)
ComplexPairTy(ComplexExprEmitter::* CompoundFunc)(const ComplexExprEmitter::BinOpInfo &)
static const ComplexType * getComplexType(QualType type)
Return the complex type that we are meant to emit.
CodeGenFunction::ComplexPairTy ComplexPairTy
#define HANDLE_BINOP(OP)
static StringRef getComplexMultiplyLibCallName(llvm::Type *Ty)
Lookup the libcall name for a given floating point type complex multiply.
static CompoundFunc getComplexOp(BinaryOperatorKind Op)
CanQualType FloatTy
Definition: ASTContext.h:1090
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
Definition: ASTContext.h:2548
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
Definition: ASTContext.h:1537
QualType getComplexType(QualType T) const
Return the uniqued reference to the type for a complex number with the specified element type.
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
Definition: Expr.h:4114
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition: Expr.h:6239
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3814
Expr * getLHS() const
Definition: Expr.h:3863
SourceLocation getExprLoc() const
Definition: Expr.h:3854
Expr * getRHS() const
Definition: Expr.h:3865
FPOptions getFPFeaturesInEffect(const LangOptions &LO) const
Definition: Expr.h:4012
Opcode getOpcode() const
Definition: Expr.h:3858
A default argument (C++ [dcl.fct.default]).
Definition: ExprCXX.h:1249
A use of a default initializer in a constructor or in aggregate initialization.
Definition: ExprCXX.h:1356
Expr * getExpr()
Get the initialization expression that will be used.
Definition: ExprCXX.cpp:1026
A rewritten comparison expression that was originally written using operator syntax.
Definition: ExprCXX.h:283
Expr * getSemanticForm()
Get an equivalent semantic form for this expression.
Definition: ExprCXX.h:301
An expression "T()" which creates a value-initialized rvalue of type T, which is a non-class type.
Definition: ExprCXX.h:2151
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2812
QualType getCallReturnType(const ASTContext &Ctx) const
getCallReturnType - Get the return type of the call expr.
Definition: Expr.cpp:1576
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition: Expr.h:3482
CastKind getCastKind() const
Definition: Expr.h:3526
Expr * getSubExpr()
Definition: Expr.h:3532
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Definition: Expr.h:4531
Expr * getChosenSubExpr() const
getChosenSubExpr - Return the subexpression chosen according to the condition.
Definition: Expr.h:4567
Represents a 'co_await' expression.
Definition: ExprCXX.h:5006
An aligned address.
Definition: Address.h:29
static Address invalid()
Definition: Address.h:49
llvm::StringRef getName() const
Return the IR name of the pointer value.
Definition: Address.h:76
bool isValid() const
Definition: Address.h:50
A scoped helper to set the current debug location to the specified location or preferred location of ...
Definition: CGDebugInfo.h:804
Address CreateStructGEP(Address Addr, unsigned Index, const llvm::Twine &Name="")
Definition: CGBuilder.h:193
All available information about a concrete callee.
Definition: CGCall.h:60
static CGCallee forDirect(llvm::Constant *functionPtr, const CGCalleeInfo &abstractInfo=CGCalleeInfo())
Definition: CGCall.h:130
CGFunctionInfo - Class to encapsulate the information about a function definition.
virtual void checkAndEmitLastprivateConditional(CodeGenFunction &CGF, const Expr *LHS)
Checks if the provided LVal is lastprivate conditional and emits the code to update the value of the ...
CallArgList - Type for representing both the value and type of arguments in a call.
Definition: CGCall.h:259
void add(RValue rvalue, QualType type)
Definition: CGCall.h:283
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
LValue getOrCreateOpaqueLValueMapping(const OpaqueValueExpr *e)
Given an opaque value expression, return its LValue mapping if it exists, otherwise create one.
LValue EmitScalarCompoundAssignWithComplex(const CompoundAssignOperator *E, llvm::Value *&Result)
LValue EmitLValue(const Expr *E, KnownNonNull_t IsKnownNonNull=NotKnownNonNull)
EmitLValue - Emit code to compute a designator that specifies the location of the expression.
RValue EmitAtomicLoad(LValue LV, SourceLocation SL, AggValueSlot Slot=AggValueSlot::ignored())
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
const LangOptions & getLangOpts() const
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
ComplexPairTy EmitComplexExpr(const Expr *E, bool IgnoreReal=false, bool IgnoreImag=false)
EmitComplexExpr - Emit the computation of the specified expression of complex type,...
RValue EmitObjCMessageExpr(const ObjCMessageExpr *E, ReturnValueSlot Return=ReturnValueSlot())
void EmitIgnoredExpr(const Expr *E)
EmitIgnoredExpr - Emit an expression in a context which ignores the result.
RValue EmitCall(const CGFunctionInfo &CallInfo, const CGCallee &Callee, ReturnValueSlot ReturnValue, const CallArgList &Args, llvm::CallBase **callOrInvoke, bool IsMustTail, SourceLocation Loc)
EmitCall - Generate a call of the given function, expecting the given result type,...
llvm::Type * ConvertTypeForMem(QualType T)
void EmitBranchOnBoolExpr(const Expr *Cond, llvm::BasicBlock *TrueBlock, llvm::BasicBlock *FalseBlock, uint64_t TrueCount, Stmt::Likelihood LH=Stmt::LH_None)
EmitBranchOnBoolExpr - Emit a branch on a boolean condition (e.g.
ConstantEmission tryEmitAsConstant(DeclRefExpr *refExpr)
void EmitComplexExprIntoLValue(const Expr *E, LValue dest, bool isInit)
EmitComplexExprIntoLValue - Emit the given expression of complex type and place its result into the s...
ComplexPairTy EmitPromotedComplexExpr(const Expr *E, QualType PromotionType)
ComplexPairTy EmitComplexPrePostIncDec(const UnaryOperator *E, LValue LV, bool isInc, bool isPre)
RValue EmitCoyieldExpr(const CoyieldExpr &E, AggValueSlot aggSlot=AggValueSlot::ignored(), bool ignoreResult=false)
ComplexPairTy EmitLoadOfComplex(LValue src, SourceLocation loc)
EmitLoadOfComplex - Load a complex number from the specified l-value.
llvm::Value * EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy, QualType DstTy, SourceLocation Loc)
Emit a conversion from the specified complex type to the specified destination type,...
LValue EmitComplexAssignmentLValue(const BinaryOperator *E)
Emit an l-value for an assignment (simple or compound) of complex type.
void ErrorUnsupported(const Stmt *S, const char *Type)
ErrorUnsupported - Print out an error that codegen doesn't support the specified stmt yet.
Address emitAddrOfImagComponent(Address complex, QualType complexType)
void EmitBranch(llvm::BasicBlock *Block)
EmitBranch - Emit a branch to the specified basic block from the current insert block,...
Address EmitCompoundStmt(const CompoundStmt &S, bool GetLast=false, AggValueSlot AVS=AggValueSlot::ignored())
RValue EmitPseudoObjectRValue(const PseudoObjectExpr *e, AggValueSlot slot=AggValueSlot::ignored())
llvm::Value * EmitLoadOfScalar(Address Addr, bool Volatile, QualType Ty, SourceLocation Loc, AlignmentSource Source=AlignmentSource::Type, bool isNontemporal=false)
EmitLoadOfScalar - Load a scalar value from an address, taking care to appropriately convert from the...
ComplexPairTy EmitUnPromotedValue(ComplexPairTy result, QualType PromotionType)
ComplexPairTy EmitPromotedValue(ComplexPairTy result, QualType PromotionType)
llvm::Value * EmitPromotedScalarExpr(const Expr *E, QualType PromotionType)
llvm::Type * ConvertType(QualType T)
Address EmitVAArg(VAArgExpr *VE, Address &VAListAddr)
Generate code to get an argument from the passed in pointer and update it accordingly.
RValue EmitCoawaitExpr(const CoawaitExpr &E, AggValueSlot aggSlot=AggValueSlot::ignored(), bool ignoreResult=false)
uint64_t getProfileCount(const Stmt *S)
Get the profiler's count for the given statement.
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
void EmitStoreOfComplex(ComplexPairTy V, LValue dest, bool isInit)
EmitStoreOfComplex - Store a complex number into the specified l-value.
void EmitAtomicStore(RValue rvalue, LValue lvalue, bool isInit)
llvm::Value * EmitScalarConversion(llvm::Value *Src, QualType SrcTy, QualType DstTy, SourceLocation Loc)
Emit a conversion from the specified type to the specified destination type, both of which are LLVM s...
RValue getOrCreateOpaqueRValueMapping(const OpaqueValueExpr *e)
Given an opaque value expression, return its RValue mapping if it exists, otherwise create one.
RValue EmitCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue=ReturnValueSlot())
llvm::LLVMContext & getLLVMContext()
llvm::Value * EmitScalarExpr(const Expr *E, bool IgnoreResultAssign=false)
EmitScalarExpr - Emit the computation of the specified expression of LLVM scalar type,...
bool LValueIsSuitableForInlineAtomic(LValue Src)
void incrementProfileCounter(const Stmt *S, llvm::Value *StepV=nullptr)
Increment the profiler's counter for the given statement by StepV.
Address emitAddrOfRealComponent(Address complex, QualType complexType)
LValue EmitComplexCompoundAssignmentLValue(const CompoundAssignOperator *E)
void EmitStoreOfScalar(llvm::Value *Value, Address Addr, bool Volatile, QualType Ty, AlignmentSource Source=AlignmentSource::Type, bool isInit=false, bool isNontemporal=false)
EmitStoreOfScalar - Store a scalar value to an address, taking care to appropriately convert from the...
RValue EmitAtomicExpr(AtomicExpr *E)
void EmitExplicitCastExprType(const ExplicitCastExpr *E, CodeGenFunction *CGF=nullptr)
Emit type info if type of an expression is a variably modified type.
Definition: CGExpr.cpp:1028
llvm::FunctionCallee CreateRuntimeFunction(llvm::FunctionType *Ty, StringRef Name, llvm::AttributeList ExtraAttrs=llvm::AttributeList(), bool Local=false, bool AssumeConvergent=false)
Create or return a runtime function declaration with the specified type and name.
CGOpenMPRuntime & getOpenMPRuntime()
Return a reference to the configured OpenMP runtime.
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.
Definition: CGCall.cpp:1618
const CGFunctionInfo & arrangeFreeFunctionCall(const CallArgList &Args, const FunctionType *Ty, bool ChainCall)
Figure out the rules for calling a function with the given formal type using the given arguments.
Definition: CGCall.cpp:629
LValue - This represents an lvalue references.
Definition: CGValue.h:171
bool isSimple() const
Definition: CGValue.h:268
bool isVolatileQualified() const
Definition: CGValue.h:275
void setTBAAInfo(TBAAAccessInfo Info)
Definition: CGValue.h:326
Address getAddress(CodeGenFunction &CGF) const
Definition: CGValue.h:352
QualType getType() const
Definition: CGValue.h:281
RValue - This trivial value class is used to represent the result of an expression that is evaluated.
Definition: CGValue.h:39
static RValue get(llvm::Value *V)
Definition: CGValue.h:89
static RValue getComplex(llvm::Value *V1, llvm::Value *V2)
Definition: CGValue.h:96
llvm::Value * getScalarVal() const
getScalarVal() - Return the Value* of this scalar value.
Definition: CGValue.h:61
std::pair< llvm::Value *, llvm::Value * > getComplexVal() const
getComplexVal - Return the real/imag components of this complex value.
Definition: CGValue.h:68
ReturnValueSlot - Contains the address where the return value of a function can be stored,...
Definition: CGCall.h:357
Complex values, per C99 6.2.5p11.
Definition: Type.h:2735
QualType getElementType() const
Definition: Type.h:2745
CompoundAssignOperator - For compound assignments (e.g.
Definition: Expr.h:4061
QualType getComputationLHSType() const
Definition: Expr.h:4095
QualType getComputationResultType() const
Definition: Expr.h:4098
CompoundLiteralExpr - [C99 6.5.2.5].
Definition: Expr.h:3412
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition: Expr.h:1045
Represents a 'co_yield' expression.
Definition: ExprCXX.h:5087
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1238
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition: ExprCXX.h:3420
This represents one expression.
Definition: Expr.h:110
bool isGLValue() const
Definition: Expr.h:274
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
Definition: Expr.cpp:3042
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:330
QualType getType() const
Definition: Expr.h:142
const Expr * getSubExpr() const
Definition: Expr.h:1028
Represents a prototype with parameter type info, e.g.
Definition: Type.h:4041
Represents a C11 generic selection.
Definition: Expr.h:5636
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
Definition: Expr.h:1729
const Expr * getSubExpr() const
Definition: Expr.h:1741
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:3629
Represents an implicitly-generated value initialization of an object of a given type.
Definition: Expr.h:5517
Describes an C or C++ initializer list.
Definition: Expr.h:4800
unsigned getNumInits() const
Definition: Expr.h:4830
const Expr * getInit(unsigned Init) const
Definition: Expr.h:4846
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:3175
Expr * getBase() const
Definition: Expr.h:3248
ObjCIvarRefExpr - A reference to an ObjC instance variable.
Definition: ExprObjC.h:548
An expression that sends a message to the given Objective-C object or class.
Definition: ExprObjC.h:942
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition: Expr.h:1146
SourceLocation getExprLoc() const LLVM_READONLY
Definition: Expr.h:1176
ParenExpr - This represents a parethesized expression, e.g.
Definition: Expr.h:2123
const Expr * getSubExpr() const
Definition: Expr.h:2138
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition: Expr.h:6107
A (possibly-)qualified type.
Definition: Type.h:736
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:803
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:6649
bool UseExcessPrecision(const ASTContext &Ctx)
Definition: Type.cpp:1487
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:41
Encodes a location in the source.
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition: Expr.h:4356
CompoundStmt * getSubStmt()
Definition: Expr.h:4373
RetTy Visit(PTR(Stmt) S, ParamTys... P)
Definition: StmtVisitor.h:43
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
Definition: StmtVisitor.h:184
Stmt - This represents one statement.
Definition: Stmt.h:72
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition: ExprCXX.h:4318
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:7491
bool isReferenceType() const
Definition: Type.h:6922
bool isAnyComplexType() const
Definition: Type.h:7008
bool isAtomicType() const
Definition: Type.h:7051
bool isRealFloatingType() const
Floating point categories.
Definition: Type.cpp:2162
bool isUnsignedIntegerType() const
Return true if this is an integer type that is unsigned, according to C99 6.2.5p6 [which returns true...
Definition: Type.cpp:2092
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7424
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition: Expr.h:2176
Expr * getSubExpr() const
Definition: Expr.h:2221
Represents a call to the builtin function __builtin_va_arg.
Definition: Expr.h:4640
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const AstTypeMatcher< ComplexType > complexType
Matches C99 complex types.
bool Ret(InterpState &S, CodePtr &PC, APValue &Result)
Definition: Interp.h:159
bool Null(InterpState &S, CodePtr OpPC)
Definition: Interp.h:1363
bool Call(InterpState &S, CodePtr &PC, const Function *Func)
Definition: Interp.h:1493
bool GE(InterpState &S, CodePtr OpPC)
Definition: Interp.h:643
BinaryOperatorKind
@ Result
The result type of a method or function.
CastKind
CastKind - The kind of operation required for a conversion.
@ EST_BasicNoexcept
noexcept
llvm::CallingConv::ID getRuntimeCC() const
static TBAAAccessInfo getMayAliasInfo()
Definition: CodeGenTBAA.h:62
Holds information about the various types of exception specification.
Definition: Type.h:4092
Extra information about a function prototype.
Definition: Type.h:4118
ExtProtoInfo withExceptionSpec(const ExceptionSpecInfo &ESI)
Definition: Type.h:4133