clang  16.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"
17 #include "clang/AST/StmtVisitor.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>
24 using namespace clang;
25 using namespace CodeGen;
26 
27 //===----------------------------------------------------------------------===//
28 // Complex Expression Emitter
29 //===----------------------------------------------------------------------===//
30 
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 
43 namespace {
44 class ComplexExprEmitter
45  : public StmtVisitor<ComplexExprEmitter, ComplexPairTy> {
46  CodeGenFunction &CGF;
47  CGBuilderTy &Builder;
48  bool IgnoreReal;
49  bool IgnoreImag;
50 public:
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 
95  ComplexPairTy Visit(Expr *E) {
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) {
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) {
171  return CGF.EmitPseudoObjectRValue(E).getComplexVal();
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) {
223  return Visit(DAE->getExpr());
224  }
225  ComplexPairTy VisitCXXDefaultInitExpr(CXXDefaultInitExpr *DIE) {
227  return Visit(DIE->getExpr());
228  }
229  ComplexPairTy VisitExprWithCleanups(ExprWithCleanups *E) {
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  };
256 
257  BinOpInfo EmitBinOps(const BinaryOperator *E,
258  QualType PromotionTy = QualType());
259  ComplexPairTy EmitPromoted(const Expr *E, QualType PromotionTy);
260  ComplexPairTy EmitPromotedComplexOperand(const Expr *E, QualType PromotionTy);
261  LValue EmitCompoundAssignLValue(const CompoundAssignOperator *E,
262  ComplexPairTy (ComplexExprEmitter::*Func)
263  (const BinOpInfo &),
264  RValue &Val);
265  ComplexPairTy EmitCompoundAssign(const CompoundAssignOperator *E,
266  ComplexPairTy (ComplexExprEmitter::*Func)
267  (const BinOpInfo &));
268 
269  ComplexPairTy EmitBinAdd(const BinOpInfo &Op);
270  ComplexPairTy EmitBinSub(const BinOpInfo &Op);
271  ComplexPairTy EmitBinMul(const BinOpInfo &Op);
272  ComplexPairTy EmitBinDiv(const BinOpInfo &Op);
273 
274  ComplexPairTy EmitComplexBinOpLibCall(StringRef LibCallName,
275  const BinOpInfo &Op);
276 
277  QualType getPromotionType(QualType Ty) {
279  if (Ty->isRealFloatingType()) {
280  if (Ty->isFloat16Type())
281  return CGF.getContext().FloatTy;
282  } else {
283  assert(Ty->isAnyComplexType() &&
284  "Expecting to promote a complex type!");
285  QualType ElementType = Ty->castAs<ComplexType>()->getElementType();
286  if (ElementType->isFloat16Type())
287  return CGF.getContext().getComplexType(CGF.getContext().FloatTy);
288  }
289  }
290  return QualType();
291  }
292 
293 #define HANDLEBINOP(OP) \
294  ComplexPairTy VisitBin##OP(const BinaryOperator *E) { \
295  QualType promotionTy = getPromotionType(E->getType()); \
296  ComplexPairTy result = EmitBin##OP(EmitBinOps(E, promotionTy)); \
297  if (!promotionTy.isNull()) \
298  result = \
299  CGF.EmitUnPromotedValue(result, E->getType()); \
300  return result; \
301  }
302 
307 #undef HANDLEBINOP
308 
309  ComplexPairTy VisitCXXRewrittenBinaryOperator(CXXRewrittenBinaryOperator *E) {
310  return Visit(E->getSemanticForm());
311  }
312 
313  // Compound assignments.
314  ComplexPairTy VisitBinAddAssign(const CompoundAssignOperator *E) {
315  return EmitCompoundAssign(E, &ComplexExprEmitter::EmitBinAdd);
316  }
317  ComplexPairTy VisitBinSubAssign(const CompoundAssignOperator *E) {
318  return EmitCompoundAssign(E, &ComplexExprEmitter::EmitBinSub);
319  }
320  ComplexPairTy VisitBinMulAssign(const CompoundAssignOperator *E) {
321  return EmitCompoundAssign(E, &ComplexExprEmitter::EmitBinMul);
322  }
323  ComplexPairTy VisitBinDivAssign(const CompoundAssignOperator *E) {
324  return EmitCompoundAssign(E, &ComplexExprEmitter::EmitBinDiv);
325  }
326 
327  // GCC rejects rem/and/or/xor for integer complex.
328  // Logical and/or always return int, never complex.
329 
330  // No comparisons produce a complex result.
331 
332  LValue EmitBinAssignLValue(const BinaryOperator *E,
333  ComplexPairTy &Val);
334  ComplexPairTy VisitBinAssign (const BinaryOperator *E);
335  ComplexPairTy VisitBinComma (const BinaryOperator *E);
336 
337 
339  VisitAbstractConditionalOperator(const AbstractConditionalOperator *CO);
340  ComplexPairTy VisitChooseExpr(ChooseExpr *CE);
341 
342  ComplexPairTy VisitInitListExpr(InitListExpr *E);
343 
344  ComplexPairTy VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
345  return EmitLoadOfLValue(E);
346  }
347 
348  ComplexPairTy VisitVAArgExpr(VAArgExpr *E);
349 
350  ComplexPairTy VisitAtomicExpr(AtomicExpr *E) {
351  return CGF.EmitAtomicExpr(E).getComplexVal();
352  }
353 };
354 } // end anonymous namespace.
355 
356 //===----------------------------------------------------------------------===//
357 // Utilities
358 //===----------------------------------------------------------------------===//
359 
362  return Builder.CreateStructGEP(addr, 0, addr.getName() + ".realp");
363 }
364 
367  return Builder.CreateStructGEP(addr, 1, addr.getName() + ".imagp");
368 }
369 
370 /// EmitLoadOfLValue - Given an RValue reference for a complex, emit code to
371 /// load the real and imaginary pieces, returning them as Real/Imag.
372 ComplexPairTy ComplexExprEmitter::EmitLoadOfLValue(LValue lvalue,
373  SourceLocation loc) {
374  assert(lvalue.isSimple() && "non-simple complex l-value?");
375  if (lvalue.getType()->isAtomicType())
376  return CGF.EmitAtomicLoad(lvalue, loc).getComplexVal();
377 
378  Address SrcPtr = lvalue.getAddress(CGF);
379  bool isVolatile = lvalue.isVolatileQualified();
380 
381  llvm::Value *Real = nullptr, *Imag = nullptr;
382 
383  if (!IgnoreReal || isVolatile) {
384  Address RealP = CGF.emitAddrOfRealComponent(SrcPtr, lvalue.getType());
385  Real = Builder.CreateLoad(RealP, isVolatile, SrcPtr.getName() + ".real");
386  }
387 
388  if (!IgnoreImag || isVolatile) {
389  Address ImagP = CGF.emitAddrOfImagComponent(SrcPtr, lvalue.getType());
390  Imag = Builder.CreateLoad(ImagP, isVolatile, SrcPtr.getName() + ".imag");
391  }
392 
393  return ComplexPairTy(Real, Imag);
394 }
395 
396 /// EmitStoreOfComplex - Store the specified real/imag parts into the
397 /// specified value pointer.
398 void ComplexExprEmitter::EmitStoreOfComplex(ComplexPairTy Val, LValue lvalue,
399  bool isInit) {
400  if (lvalue.getType()->isAtomicType() ||
401  (!isInit && CGF.LValueIsSuitableForInlineAtomic(lvalue)))
402  return CGF.EmitAtomicStore(RValue::getComplex(Val), lvalue, isInit);
403 
404  Address Ptr = lvalue.getAddress(CGF);
405  Address RealPtr = CGF.emitAddrOfRealComponent(Ptr, lvalue.getType());
406  Address ImagPtr = CGF.emitAddrOfImagComponent(Ptr, lvalue.getType());
407 
408  Builder.CreateStore(Val.first, RealPtr, lvalue.isVolatileQualified());
409  Builder.CreateStore(Val.second, ImagPtr, lvalue.isVolatileQualified());
410 }
411 
412 
413 
414 //===----------------------------------------------------------------------===//
415 // Visitor Methods
416 //===----------------------------------------------------------------------===//
417 
418 ComplexPairTy ComplexExprEmitter::VisitExpr(Expr *E) {
419  CGF.ErrorUnsupported(E, "complex expression");
420  llvm::Type *EltTy =
422  llvm::Value *U = llvm::UndefValue::get(EltTy);
423  return ComplexPairTy(U, U);
424 }
425 
426 ComplexPairTy ComplexExprEmitter::
427 VisitImaginaryLiteral(const ImaginaryLiteral *IL) {
428  llvm::Value *Imag = CGF.EmitScalarExpr(IL->getSubExpr());
429  return ComplexPairTy(llvm::Constant::getNullValue(Imag->getType()), Imag);
430 }
431 
432 
433 ComplexPairTy ComplexExprEmitter::VisitCallExpr(const CallExpr *E) {
435  return EmitLoadOfLValue(E);
436 
437  return CGF.EmitCallExpr(E).getComplexVal();
438 }
439 
440 ComplexPairTy ComplexExprEmitter::VisitStmtExpr(const StmtExpr *E) {
442  Address RetAlloca = CGF.EmitCompoundStmt(*E->getSubStmt(), true);
443  assert(RetAlloca.isValid() && "Expected complex return value");
444  return EmitLoadOfLValue(CGF.MakeAddrLValue(RetAlloca, E->getType()),
445  E->getExprLoc());
446 }
447 
448 /// Emit a cast from complex value Val to DestType.
449 ComplexPairTy ComplexExprEmitter::EmitComplexToComplexCast(ComplexPairTy Val,
450  QualType SrcType,
451  QualType DestType,
452  SourceLocation Loc) {
453  // Get the src/dest element type.
454  SrcType = SrcType->castAs<ComplexType>()->getElementType();
455  DestType = DestType->castAs<ComplexType>()->getElementType();
456 
457  // C99 6.3.1.6: When a value of complex type is converted to another
458  // complex type, both the real and imaginary parts follow the conversion
459  // rules for the corresponding real types.
460  if (Val.first)
461  Val.first = CGF.EmitScalarConversion(Val.first, SrcType, DestType, Loc);
462  if (Val.second)
463  Val.second = CGF.EmitScalarConversion(Val.second, SrcType, DestType, Loc);
464  return Val;
465 }
466 
467 ComplexPairTy ComplexExprEmitter::EmitScalarToComplexCast(llvm::Value *Val,
468  QualType SrcType,
469  QualType DestType,
470  SourceLocation Loc) {
471  // Convert the input element to the element type of the complex.
472  DestType = DestType->castAs<ComplexType>()->getElementType();
473  Val = CGF.EmitScalarConversion(Val, SrcType, DestType, Loc);
474 
475  // Return (realval, 0).
476  return ComplexPairTy(Val, llvm::Constant::getNullValue(Val->getType()));
477 }
478 
479 ComplexPairTy ComplexExprEmitter::EmitCast(CastKind CK, Expr *Op,
480  QualType DestTy) {
481  switch (CK) {
482  case CK_Dependent: llvm_unreachable("dependent cast kind in IR gen!");
483 
484  // Atomic to non-atomic casts may be more than a no-op for some platforms and
485  // for some types.
486  case CK_AtomicToNonAtomic:
487  case CK_NonAtomicToAtomic:
488  case CK_NoOp:
489  case CK_LValueToRValue:
490  case CK_UserDefinedConversion:
491  return Visit(Op);
492 
493  case CK_LValueBitCast: {
494  LValue origLV = CGF.EmitLValue(Op);
495  Address V = origLV.getAddress(CGF);
496  V = Builder.CreateElementBitCast(V, CGF.ConvertType(DestTy));
497  return EmitLoadOfLValue(CGF.MakeAddrLValue(V, DestTy), Op->getExprLoc());
498  }
499 
500  case CK_LValueToRValueBitCast: {
501  LValue SourceLVal = CGF.EmitLValue(Op);
502  Address Addr = Builder.CreateElementBitCast(SourceLVal.getAddress(CGF),
503  CGF.ConvertTypeForMem(DestTy));
504  LValue DestLV = CGF.MakeAddrLValue(Addr, DestTy);
506  return EmitLoadOfLValue(DestLV, Op->getExprLoc());
507  }
508 
509  case CK_BitCast:
510  case CK_BaseToDerived:
511  case CK_DerivedToBase:
512  case CK_UncheckedDerivedToBase:
513  case CK_Dynamic:
514  case CK_ToUnion:
515  case CK_ArrayToPointerDecay:
516  case CK_FunctionToPointerDecay:
517  case CK_NullToPointer:
518  case CK_NullToMemberPointer:
519  case CK_BaseToDerivedMemberPointer:
520  case CK_DerivedToBaseMemberPointer:
521  case CK_MemberPointerToBoolean:
522  case CK_ReinterpretMemberPointer:
523  case CK_ConstructorConversion:
524  case CK_IntegralToPointer:
525  case CK_PointerToIntegral:
526  case CK_PointerToBoolean:
527  case CK_ToVoid:
528  case CK_VectorSplat:
529  case CK_IntegralCast:
530  case CK_BooleanToSignedIntegral:
531  case CK_IntegralToBoolean:
532  case CK_IntegralToFloating:
533  case CK_FloatingToIntegral:
534  case CK_FloatingToBoolean:
535  case CK_FloatingCast:
536  case CK_CPointerToObjCPointerCast:
537  case CK_BlockPointerToObjCPointerCast:
538  case CK_AnyPointerToBlockPointerCast:
539  case CK_ObjCObjectLValueCast:
540  case CK_FloatingComplexToReal:
541  case CK_FloatingComplexToBoolean:
542  case CK_IntegralComplexToReal:
543  case CK_IntegralComplexToBoolean:
544  case CK_ARCProduceObject:
545  case CK_ARCConsumeObject:
546  case CK_ARCReclaimReturnedObject:
547  case CK_ARCExtendBlockObject:
548  case CK_CopyAndAutoreleaseBlockObject:
549  case CK_BuiltinFnToFnPtr:
550  case CK_ZeroToOCLOpaqueType:
551  case CK_AddressSpaceConversion:
552  case CK_IntToOCLSampler:
553  case CK_FloatingToFixedPoint:
554  case CK_FixedPointToFloating:
555  case CK_FixedPointCast:
556  case CK_FixedPointToBoolean:
557  case CK_FixedPointToIntegral:
558  case CK_IntegralToFixedPoint:
559  case CK_MatrixCast:
560  llvm_unreachable("invalid cast kind for complex value");
561 
562  case CK_FloatingRealToComplex:
563  case CK_IntegralRealToComplex: {
564  CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, Op);
565  return EmitScalarToComplexCast(CGF.EmitScalarExpr(Op), Op->getType(),
566  DestTy, Op->getExprLoc());
567  }
568 
569  case CK_FloatingComplexCast:
570  case CK_FloatingComplexToIntegralComplex:
571  case CK_IntegralComplexCast:
572  case CK_IntegralComplexToFloatingComplex: {
573  CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, Op);
574  return EmitComplexToComplexCast(Visit(Op), Op->getType(), DestTy,
575  Op->getExprLoc());
576  }
577  }
578 
579  llvm_unreachable("unknown cast resulting in complex value");
580 }
581 
582 ComplexPairTy ComplexExprEmitter::VisitUnaryPlus(const UnaryOperator *E,
583  QualType PromotionType) {
584  QualType promotionTy = PromotionType.isNull()
585  ? getPromotionType(E->getSubExpr()->getType())
586  : PromotionType;
587  ComplexPairTy result = VisitPlus(E, promotionTy);
588  if (!promotionTy.isNull())
589  return CGF.EmitUnPromotedValue(result, E->getSubExpr()->getType());
590  return result;
591 }
592 
593 ComplexPairTy ComplexExprEmitter::VisitPlus(const UnaryOperator *E,
594  QualType PromotionType) {
595  TestAndClearIgnoreReal();
596  TestAndClearIgnoreImag();
597  if (!PromotionType.isNull())
598  return CGF.EmitPromotedComplexExpr(E->getSubExpr(), PromotionType);
599  return Visit(E->getSubExpr());
600 }
601 
602 ComplexPairTy ComplexExprEmitter::VisitUnaryMinus(const UnaryOperator *E,
603  QualType PromotionType) {
604  QualType promotionTy = PromotionType.isNull()
605  ? getPromotionType(E->getSubExpr()->getType())
606  : PromotionType;
607  ComplexPairTy result = VisitMinus(E, promotionTy);
608  if (!promotionTy.isNull())
609  return CGF.EmitUnPromotedValue(result, E->getSubExpr()->getType());
610  return result;
611 }
612 ComplexPairTy ComplexExprEmitter::VisitMinus(const UnaryOperator *E,
613  QualType PromotionType) {
614  TestAndClearIgnoreReal();
615  TestAndClearIgnoreImag();
616  ComplexPairTy Op;
617  if (!PromotionType.isNull())
618  Op = CGF.EmitPromotedComplexExpr(E->getSubExpr(), PromotionType);
619  else
620  Op = Visit(E->getSubExpr());
621 
622  llvm::Value *ResR, *ResI;
623  if (Op.first->getType()->isFloatingPointTy()) {
624  ResR = Builder.CreateFNeg(Op.first, "neg.r");
625  ResI = Builder.CreateFNeg(Op.second, "neg.i");
626  } else {
627  ResR = Builder.CreateNeg(Op.first, "neg.r");
628  ResI = Builder.CreateNeg(Op.second, "neg.i");
629  }
630  return ComplexPairTy(ResR, ResI);
631 }
632 
633 ComplexPairTy ComplexExprEmitter::VisitUnaryNot(const UnaryOperator *E) {
634  TestAndClearIgnoreReal();
635  TestAndClearIgnoreImag();
636  // ~(a+ib) = a + i*-b
637  ComplexPairTy Op = Visit(E->getSubExpr());
638  llvm::Value *ResI;
639  if (Op.second->getType()->isFloatingPointTy())
640  ResI = Builder.CreateFNeg(Op.second, "conj.i");
641  else
642  ResI = Builder.CreateNeg(Op.second, "conj.i");
643 
644  return ComplexPairTy(Op.first, ResI);
645 }
646 
647 ComplexPairTy ComplexExprEmitter::EmitBinAdd(const BinOpInfo &Op) {
648  llvm::Value *ResR, *ResI;
649 
650  if (Op.LHS.first->getType()->isFloatingPointTy()) {
651  ResR = Builder.CreateFAdd(Op.LHS.first, Op.RHS.first, "add.r");
652  if (Op.LHS.second && Op.RHS.second)
653  ResI = Builder.CreateFAdd(Op.LHS.second, Op.RHS.second, "add.i");
654  else
655  ResI = Op.LHS.second ? Op.LHS.second : Op.RHS.second;
656  assert(ResI && "Only one operand may be real!");
657  } else {
658  ResR = Builder.CreateAdd(Op.LHS.first, Op.RHS.first, "add.r");
659  assert(Op.LHS.second && Op.RHS.second &&
660  "Both operands of integer complex operators must be complex!");
661  ResI = Builder.CreateAdd(Op.LHS.second, Op.RHS.second, "add.i");
662  }
663  return ComplexPairTy(ResR, ResI);
664 }
665 
666 ComplexPairTy ComplexExprEmitter::EmitBinSub(const BinOpInfo &Op) {
667  llvm::Value *ResR, *ResI;
668  if (Op.LHS.first->getType()->isFloatingPointTy()) {
669  ResR = Builder.CreateFSub(Op.LHS.first, Op.RHS.first, "sub.r");
670  if (Op.LHS.second && Op.RHS.second)
671  ResI = Builder.CreateFSub(Op.LHS.second, Op.RHS.second, "sub.i");
672  else
673  ResI = Op.LHS.second ? Op.LHS.second
674  : Builder.CreateFNeg(Op.RHS.second, "sub.i");
675  assert(ResI && "Only one operand may be real!");
676  } else {
677  ResR = Builder.CreateSub(Op.LHS.first, Op.RHS.first, "sub.r");
678  assert(Op.LHS.second && Op.RHS.second &&
679  "Both operands of integer complex operators must be complex!");
680  ResI = Builder.CreateSub(Op.LHS.second, Op.RHS.second, "sub.i");
681  }
682  return ComplexPairTy(ResR, ResI);
683 }
684 
685 /// Emit a libcall for a binary operation on complex types.
686 ComplexPairTy ComplexExprEmitter::EmitComplexBinOpLibCall(StringRef LibCallName,
687  const BinOpInfo &Op) {
688  CallArgList Args;
689  Args.add(RValue::get(Op.LHS.first),
690  Op.Ty->castAs<ComplexType>()->getElementType());
691  Args.add(RValue::get(Op.LHS.second),
692  Op.Ty->castAs<ComplexType>()->getElementType());
693  Args.add(RValue::get(Op.RHS.first),
694  Op.Ty->castAs<ComplexType>()->getElementType());
695  Args.add(RValue::get(Op.RHS.second),
696  Op.Ty->castAs<ComplexType>()->getElementType());
697 
698  // We *must* use the full CG function call building logic here because the
699  // complex type has special ABI handling. We also should not forget about
700  // special calling convention which may be used for compiler builtins.
701 
702  // We create a function qualified type to state that this call does not have
703  // any exceptions.
705  EPI = EPI.withExceptionSpec(
707  SmallVector<QualType, 4> ArgsQTys(
708  4, Op.Ty->castAs<ComplexType>()->getElementType());
709  QualType FQTy = CGF.getContext().getFunctionType(Op.Ty, ArgsQTys, EPI);
710  const CGFunctionInfo &FuncInfo = CGF.CGM.getTypes().arrangeFreeFunctionCall(
711  Args, cast<FunctionType>(FQTy.getTypePtr()), false);
712 
713  llvm::FunctionType *FTy = CGF.CGM.getTypes().GetFunctionType(FuncInfo);
714  llvm::FunctionCallee Func = CGF.CGM.CreateRuntimeFunction(
715  FTy, LibCallName, llvm::AttributeList(), true);
717 
718  llvm::CallBase *Call;
719  RValue Res = CGF.EmitCall(FuncInfo, Callee, ReturnValueSlot(), Args, &Call);
720  Call->setCallingConv(CGF.CGM.getRuntimeCC());
721  return Res.getComplexVal();
722 }
723 
724 /// Lookup the libcall name for a given floating point type complex
725 /// multiply.
726 static StringRef getComplexMultiplyLibCallName(llvm::Type *Ty) {
727  switch (Ty->getTypeID()) {
728  default:
729  llvm_unreachable("Unsupported floating point type!");
730  case llvm::Type::HalfTyID:
731  return "__mulhc3";
732  case llvm::Type::FloatTyID:
733  return "__mulsc3";
734  case llvm::Type::DoubleTyID:
735  return "__muldc3";
736  case llvm::Type::PPC_FP128TyID:
737  return "__multc3";
738  case llvm::Type::X86_FP80TyID:
739  return "__mulxc3";
740  case llvm::Type::FP128TyID:
741  return "__multc3";
742  }
743 }
744 
745 // See C11 Annex G.5.1 for the semantics of multiplicative operators on complex
746 // typed values.
747 ComplexPairTy ComplexExprEmitter::EmitBinMul(const BinOpInfo &Op) {
748  using llvm::Value;
749  Value *ResR, *ResI;
750  llvm::MDBuilder MDHelper(CGF.getLLVMContext());
751 
752  if (Op.LHS.first->getType()->isFloatingPointTy()) {
753  // The general formulation is:
754  // (a + ib) * (c + id) = (a * c - b * d) + i(a * d + b * c)
755  //
756  // But we can fold away components which would be zero due to a real
757  // operand according to C11 Annex G.5.1p2.
758  // FIXME: C11 also provides for imaginary types which would allow folding
759  // still more of this within the type system.
760 
761  if (Op.LHS.second && Op.RHS.second) {
762  // If both operands are complex, emit the core math directly, and then
763  // test for NaNs. If we find NaNs in the result, we delegate to a libcall
764  // to carefully re-compute the correct infinity representation if
765  // possible. The expectation is that the presence of NaNs here is
766  // *extremely* rare, and so the cost of the libcall is almost irrelevant.
767  // This is good, because the libcall re-computes the core multiplication
768  // exactly the same as we do here and re-tests for NaNs in order to be
769  // a generic complex*complex libcall.
770 
771  // First compute the four products.
772  Value *AC = Builder.CreateFMul(Op.LHS.first, Op.RHS.first, "mul_ac");
773  Value *BD = Builder.CreateFMul(Op.LHS.second, Op.RHS.second, "mul_bd");
774  Value *AD = Builder.CreateFMul(Op.LHS.first, Op.RHS.second, "mul_ad");
775  Value *BC = Builder.CreateFMul(Op.LHS.second, Op.RHS.first, "mul_bc");
776 
777  // The real part is the difference of the first two, the imaginary part is
778  // the sum of the second.
779  ResR = Builder.CreateFSub(AC, BD, "mul_r");
780  ResI = Builder.CreateFAdd(AD, BC, "mul_i");
781 
782  // Emit the test for the real part becoming NaN and create a branch to
783  // handle it. We test for NaN by comparing the number to itself.
784  Value *IsRNaN = Builder.CreateFCmpUNO(ResR, ResR, "isnan_cmp");
785  llvm::BasicBlock *ContBB = CGF.createBasicBlock("complex_mul_cont");
786  llvm::BasicBlock *INaNBB = CGF.createBasicBlock("complex_mul_imag_nan");
787  llvm::Instruction *Branch = Builder.CreateCondBr(IsRNaN, INaNBB, ContBB);
788  llvm::BasicBlock *OrigBB = Branch->getParent();
789 
790  // Give hint that we very much don't expect to see NaNs.
791  // Value chosen to match UR_NONTAKEN_WEIGHT, see BranchProbabilityInfo.cpp
792  llvm::MDNode *BrWeight = MDHelper.createBranchWeights(1, (1U << 20) - 1);
793  Branch->setMetadata(llvm::LLVMContext::MD_prof, BrWeight);
794 
795  // Now test the imaginary part and create its branch.
796  CGF.EmitBlock(INaNBB);
797  Value *IsINaN = Builder.CreateFCmpUNO(ResI, ResI, "isnan_cmp");
798  llvm::BasicBlock *LibCallBB = CGF.createBasicBlock("complex_mul_libcall");
799  Branch = Builder.CreateCondBr(IsINaN, LibCallBB, ContBB);
800  Branch->setMetadata(llvm::LLVMContext::MD_prof, BrWeight);
801 
802  // Now emit the libcall on this slowest of the slow paths.
803  CGF.EmitBlock(LibCallBB);
804  Value *LibCallR, *LibCallI;
805  std::tie(LibCallR, LibCallI) = EmitComplexBinOpLibCall(
806  getComplexMultiplyLibCallName(Op.LHS.first->getType()), Op);
807  Builder.CreateBr(ContBB);
808 
809  // Finally continue execution by phi-ing together the different
810  // computation paths.
811  CGF.EmitBlock(ContBB);
812  llvm::PHINode *RealPHI = Builder.CreatePHI(ResR->getType(), 3, "real_mul_phi");
813  RealPHI->addIncoming(ResR, OrigBB);
814  RealPHI->addIncoming(ResR, INaNBB);
815  RealPHI->addIncoming(LibCallR, LibCallBB);
816  llvm::PHINode *ImagPHI = Builder.CreatePHI(ResI->getType(), 3, "imag_mul_phi");
817  ImagPHI->addIncoming(ResI, OrigBB);
818  ImagPHI->addIncoming(ResI, INaNBB);
819  ImagPHI->addIncoming(LibCallI, LibCallBB);
820  return ComplexPairTy(RealPHI, ImagPHI);
821  }
822  assert((Op.LHS.second || Op.RHS.second) &&
823  "At least one operand must be complex!");
824 
825  // If either of the operands is a real rather than a complex, the
826  // imaginary component is ignored when computing the real component of the
827  // result.
828  ResR = Builder.CreateFMul(Op.LHS.first, Op.RHS.first, "mul.rl");
829 
830  ResI = Op.LHS.second
831  ? Builder.CreateFMul(Op.LHS.second, Op.RHS.first, "mul.il")
832  : Builder.CreateFMul(Op.LHS.first, Op.RHS.second, "mul.ir");
833  } else {
834  assert(Op.LHS.second && Op.RHS.second &&
835  "Both operands of integer complex operators must be complex!");
836  Value *ResRl = Builder.CreateMul(Op.LHS.first, Op.RHS.first, "mul.rl");
837  Value *ResRr = Builder.CreateMul(Op.LHS.second, Op.RHS.second, "mul.rr");
838  ResR = Builder.CreateSub(ResRl, ResRr, "mul.r");
839 
840  Value *ResIl = Builder.CreateMul(Op.LHS.second, Op.RHS.first, "mul.il");
841  Value *ResIr = Builder.CreateMul(Op.LHS.first, Op.RHS.second, "mul.ir");
842  ResI = Builder.CreateAdd(ResIl, ResIr, "mul.i");
843  }
844  return ComplexPairTy(ResR, ResI);
845 }
846 
847 // See C11 Annex G.5.1 for the semantics of multiplicative operators on complex
848 // typed values.
849 ComplexPairTy ComplexExprEmitter::EmitBinDiv(const BinOpInfo &Op) {
850  llvm::Value *LHSr = Op.LHS.first, *LHSi = Op.LHS.second;
851  llvm::Value *RHSr = Op.RHS.first, *RHSi = Op.RHS.second;
852 
853  llvm::Value *DSTr, *DSTi;
854  if (LHSr->getType()->isFloatingPointTy()) {
855  // If we have a complex operand on the RHS and FastMath is not allowed, we
856  // delegate to a libcall to handle all of the complexities and minimize
857  // underflow/overflow cases. When FastMath is allowed we construct the
858  // divide inline using the same algorithm as for integer operands.
859  //
860  // FIXME: We would be able to avoid the libcall in many places if we
861  // supported imaginary types in addition to complex types.
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 
962 ComplexPairTy 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));
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 
1001 ComplexExprEmitter::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 
1020 ComplexExprEmitter::BinOpInfo
1021 ComplexExprEmitter::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  return Ops;
1034 }
1035 
1036 
1037 LValue ComplexExprEmitter::
1038 EmitCompoundAssignLValue(const CompoundAssignOperator *E,
1039  ComplexPairTy (ComplexExprEmitter::*Func)(const BinOpInfo&),
1040  RValue &Val) {
1041  TestAndClearIgnoreReal();
1042  TestAndClearIgnoreImag();
1043  QualType LHSTy = E->getLHS()->getType();
1044  if (const AtomicType *AT = LHSTy->getAs<AtomicType>())
1045  LHSTy = AT->getValueType();
1046 
1047  CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
1048  BinOpInfo OpInfo;
1049 
1050  // Load the RHS and LHS operands.
1051  // __block variables need to have the rhs evaluated first, plus this should
1052  // improve codegen a little.
1053  QualType PromotionTypeCR;
1054  PromotionTypeCR = getPromotionType(E->getComputationResultType());
1055  if (PromotionTypeCR.isNull())
1056  PromotionTypeCR = E->getComputationResultType();
1057  OpInfo.Ty = PromotionTypeCR;
1058  QualType ComplexElementTy =
1059  OpInfo.Ty->castAs<ComplexType>()->getElementType();
1060  QualType PromotionTypeRHS = getPromotionType(E->getRHS()->getType());
1061 
1062  // The RHS should have been converted to the computation type.
1063  if (E->getRHS()->getType()->isRealFloatingType()) {
1064  if (!PromotionTypeRHS.isNull())
1065  OpInfo.RHS = ComplexPairTy(
1066  CGF.EmitPromotedScalarExpr(E->getRHS(), PromotionTypeRHS), nullptr);
1067  else {
1068  assert(CGF.getContext().hasSameUnqualifiedType(ComplexElementTy,
1069  E->getRHS()->getType()));
1070 
1071  OpInfo.RHS = ComplexPairTy(CGF.EmitScalarExpr(E->getRHS()), nullptr);
1072  }
1073  } else {
1074  if (!PromotionTypeRHS.isNull()) {
1075  OpInfo.RHS = ComplexPairTy(
1076  CGF.EmitPromotedComplexExpr(E->getRHS(), PromotionTypeRHS));
1077  } else {
1078  assert(CGF.getContext().hasSameUnqualifiedType(OpInfo.Ty,
1079  E->getRHS()->getType()));
1080  OpInfo.RHS = Visit(E->getRHS());
1081  }
1082  }
1083 
1084  LValue LHS = CGF.EmitLValue(E->getLHS());
1085 
1086  // Load from the l-value and convert it.
1087  SourceLocation Loc = E->getExprLoc();
1088  QualType PromotionTypeLHS = getPromotionType(E->getComputationLHSType());
1089  if (LHSTy->isAnyComplexType()) {
1090  ComplexPairTy LHSVal = EmitLoadOfLValue(LHS, Loc);
1091  if (!PromotionTypeLHS.isNull())
1092  OpInfo.LHS =
1093  EmitComplexToComplexCast(LHSVal, LHSTy, PromotionTypeLHS, Loc);
1094  else
1095  OpInfo.LHS = EmitComplexToComplexCast(LHSVal, LHSTy, OpInfo.Ty, Loc);
1096  } else {
1097  llvm::Value *LHSVal = CGF.EmitLoadOfScalar(LHS, Loc);
1098  // For floating point real operands we can directly pass the scalar form
1099  // to the binary operator emission and potentially get more efficient code.
1100  if (LHSTy->isRealFloatingType()) {
1101  QualType PromotedComplexElementTy;
1102  if (!PromotionTypeLHS.isNull()) {
1103  PromotedComplexElementTy =
1104  cast<ComplexType>(PromotionTypeLHS)->getElementType();
1105  if (!CGF.getContext().hasSameUnqualifiedType(PromotedComplexElementTy,
1106  PromotionTypeLHS))
1107  LHSVal = CGF.EmitScalarConversion(LHSVal, LHSTy,
1108  PromotedComplexElementTy, Loc);
1109  } else {
1110  if (!CGF.getContext().hasSameUnqualifiedType(ComplexElementTy, LHSTy))
1111  LHSVal =
1112  CGF.EmitScalarConversion(LHSVal, LHSTy, ComplexElementTy, Loc);
1113  }
1114  OpInfo.LHS = ComplexPairTy(LHSVal, nullptr);
1115  } else {
1116  OpInfo.LHS = EmitScalarToComplexCast(LHSVal, LHSTy, OpInfo.Ty, Loc);
1117  }
1118  }
1119 
1120  // Expand the binary operator.
1121  ComplexPairTy Result = (this->*Func)(OpInfo);
1122 
1123  // Truncate the result and store it into the LHS lvalue.
1124  if (LHSTy->isAnyComplexType()) {
1125  ComplexPairTy ResVal =
1126  EmitComplexToComplexCast(Result, OpInfo.Ty, LHSTy, Loc);
1127  EmitStoreOfComplex(ResVal, LHS, /*isInit*/ false);
1128  Val = RValue::getComplex(ResVal);
1129  } else {
1130  llvm::Value *ResVal =
1131  CGF.EmitComplexToScalarConversion(Result, OpInfo.Ty, LHSTy, Loc);
1132  CGF.EmitStoreOfScalar(ResVal, LHS, /*isInit*/ false);
1133  Val = RValue::get(ResVal);
1134  }
1135 
1136  return LHS;
1137 }
1138 
1139 // Compound assignments.
1140 ComplexPairTy ComplexExprEmitter::
1141 EmitCompoundAssign(const CompoundAssignOperator *E,
1142  ComplexPairTy (ComplexExprEmitter::*Func)(const BinOpInfo&)){
1143  RValue Val;
1144  LValue LV = EmitCompoundAssignLValue(E, Func, Val);
1145 
1146  // The result of an assignment in C is the assigned r-value.
1147  if (!CGF.getLangOpts().CPlusPlus)
1148  return Val.getComplexVal();
1149 
1150  // If the lvalue is non-volatile, return the computed value of the assignment.
1151  if (!LV.isVolatileQualified())
1152  return Val.getComplexVal();
1153 
1154  return EmitLoadOfLValue(LV, E->getExprLoc());
1155 }
1156 
1157 LValue ComplexExprEmitter::EmitBinAssignLValue(const BinaryOperator *E,
1158  ComplexPairTy &Val) {
1159  assert(CGF.getContext().hasSameUnqualifiedType(E->getLHS()->getType(),
1160  E->getRHS()->getType()) &&
1161  "Invalid assignment");
1162  TestAndClearIgnoreReal();
1163  TestAndClearIgnoreImag();
1164 
1165  // Emit the RHS. __block variables need the RHS evaluated first.
1166  Val = Visit(E->getRHS());
1167 
1168  // Compute the address to store into.
1169  LValue LHS = CGF.EmitLValue(E->getLHS());
1170 
1171  // Store the result value into the LHS lvalue.
1172  EmitStoreOfComplex(Val, LHS, /*isInit*/ false);
1173 
1174  return LHS;
1175 }
1176 
1177 ComplexPairTy ComplexExprEmitter::VisitBinAssign(const BinaryOperator *E) {
1178  ComplexPairTy Val;
1179  LValue LV = EmitBinAssignLValue(E, Val);
1180 
1181  // The result of an assignment in C is the assigned r-value.
1182  if (!CGF.getLangOpts().CPlusPlus)
1183  return Val;
1184 
1185  // If the lvalue is non-volatile, return the computed value of the assignment.
1186  if (!LV.isVolatileQualified())
1187  return Val;
1188 
1189  return EmitLoadOfLValue(LV, E->getExprLoc());
1190 }
1191 
1192 ComplexPairTy ComplexExprEmitter::VisitBinComma(const BinaryOperator *E) {
1193  CGF.EmitIgnoredExpr(E->getLHS());
1194  return Visit(E->getRHS());
1195 }
1196 
1197 ComplexPairTy ComplexExprEmitter::
1198 VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) {
1199  TestAndClearIgnoreReal();
1200  TestAndClearIgnoreImag();
1201  llvm::BasicBlock *LHSBlock = CGF.createBasicBlock("cond.true");
1202  llvm::BasicBlock *RHSBlock = CGF.createBasicBlock("cond.false");
1203  llvm::BasicBlock *ContBlock = CGF.createBasicBlock("cond.end");
1204 
1205  // Bind the common expression if necessary.
1206  CodeGenFunction::OpaqueValueMapping binding(CGF, E);
1207 
1208 
1210  CGF.EmitBranchOnBoolExpr(E->getCond(), LHSBlock, RHSBlock,
1211  CGF.getProfileCount(E));
1212 
1213  eval.begin(CGF);
1214  CGF.EmitBlock(LHSBlock);
1215  CGF.incrementProfileCounter(E);
1216  ComplexPairTy LHS = Visit(E->getTrueExpr());
1217  LHSBlock = Builder.GetInsertBlock();
1218  CGF.EmitBranch(ContBlock);
1219  eval.end(CGF);
1220 
1221  eval.begin(CGF);
1222  CGF.EmitBlock(RHSBlock);
1223  ComplexPairTy RHS = Visit(E->getFalseExpr());
1224  RHSBlock = Builder.GetInsertBlock();
1225  CGF.EmitBlock(ContBlock);
1226  eval.end(CGF);
1227 
1228  // Create a PHI node for the real part.
1229  llvm::PHINode *RealPN = Builder.CreatePHI(LHS.first->getType(), 2, "cond.r");
1230  RealPN->addIncoming(LHS.first, LHSBlock);
1231  RealPN->addIncoming(RHS.first, RHSBlock);
1232 
1233  // Create a PHI node for the imaginary part.
1234  llvm::PHINode *ImagPN = Builder.CreatePHI(LHS.first->getType(), 2, "cond.i");
1235  ImagPN->addIncoming(LHS.second, LHSBlock);
1236  ImagPN->addIncoming(RHS.second, RHSBlock);
1237 
1238  return ComplexPairTy(RealPN, ImagPN);
1239 }
1240 
1241 ComplexPairTy ComplexExprEmitter::VisitChooseExpr(ChooseExpr *E) {
1242  return Visit(E->getChosenSubExpr());
1243 }
1244 
1245 ComplexPairTy ComplexExprEmitter::VisitInitListExpr(InitListExpr *E) {
1246  bool Ignore = TestAndClearIgnoreReal();
1247  (void)Ignore;
1248  assert (Ignore == false && "init list ignored");
1249  Ignore = TestAndClearIgnoreImag();
1250  (void)Ignore;
1251  assert (Ignore == false && "init list ignored");
1252 
1253  if (E->getNumInits() == 2) {
1254  llvm::Value *Real = CGF.EmitScalarExpr(E->getInit(0));
1255  llvm::Value *Imag = CGF.EmitScalarExpr(E->getInit(1));
1256  return ComplexPairTy(Real, Imag);
1257  } else if (E->getNumInits() == 1) {
1258  return Visit(E->getInit(0));
1259  }
1260 
1261  // Empty init list initializes to null
1262  assert(E->getNumInits() == 0 && "Unexpected number of inits");
1263  QualType Ty = E->getType()->castAs<ComplexType>()->getElementType();
1264  llvm::Type* LTy = CGF.ConvertType(Ty);
1265  llvm::Value* zeroConstant = llvm::Constant::getNullValue(LTy);
1266  return ComplexPairTy(zeroConstant, zeroConstant);
1267 }
1268 
1269 ComplexPairTy ComplexExprEmitter::VisitVAArgExpr(VAArgExpr *E) {
1270  Address ArgValue = Address::invalid();
1271  Address ArgPtr = CGF.EmitVAArg(E, ArgValue);
1272 
1273  if (!ArgPtr.isValid()) {
1274  CGF.ErrorUnsupported(E, "complex va_arg expression");
1275  llvm::Type *EltTy =
1277  llvm::Value *U = llvm::UndefValue::get(EltTy);
1278  return ComplexPairTy(U, U);
1279  }
1280 
1281  return EmitLoadOfLValue(CGF.MakeAddrLValue(ArgPtr, E->getType()),
1282  E->getExprLoc());
1283 }
1284 
1285 //===----------------------------------------------------------------------===//
1286 // Entry Point into this File
1287 //===----------------------------------------------------------------------===//
1288 
1289 /// EmitComplexExpr - Emit the computation of the specified expression of
1290 /// complex type, ignoring the result.
1292  bool IgnoreImag) {
1293  assert(E && getComplexType(E->getType()) &&
1294  "Invalid complex expression to emit");
1295 
1296  return ComplexExprEmitter(*this, IgnoreReal, IgnoreImag)
1297  .Visit(const_cast<Expr *>(E));
1298 }
1299 
1301  bool isInit) {
1302  assert(E && getComplexType(E->getType()) &&
1303  "Invalid complex expression to emit");
1304  ComplexExprEmitter Emitter(*this);
1305  ComplexPairTy Val = Emitter.Visit(const_cast<Expr*>(E));
1306  Emitter.EmitStoreOfComplex(Val, dest, isInit);
1307 }
1308 
1309 /// EmitStoreOfComplex - Store a complex number into the specified l-value.
1311  bool isInit) {
1312  ComplexExprEmitter(*this).EmitStoreOfComplex(V, dest, isInit);
1313 }
1314 
1315 /// EmitLoadOfComplex - Load a complex number from the specified address.
1317  SourceLocation loc) {
1318  return ComplexExprEmitter(*this).EmitLoadOfLValue(src, loc);
1319 }
1320 
1322  assert(E->getOpcode() == BO_Assign);
1323  ComplexPairTy Val; // ignored
1324  LValue LVal = ComplexExprEmitter(*this).EmitBinAssignLValue(E, Val);
1325  if (getLangOpts().OpenMP)
1327  E->getLHS());
1328  return LVal;
1329 }
1330 
1331 typedef ComplexPairTy (ComplexExprEmitter::*CompoundFunc)(
1332  const ComplexExprEmitter::BinOpInfo &);
1333 
1335  switch (Op) {
1336  case BO_MulAssign: return &ComplexExprEmitter::EmitBinMul;
1337  case BO_DivAssign: return &ComplexExprEmitter::EmitBinDiv;
1338  case BO_SubAssign: return &ComplexExprEmitter::EmitBinSub;
1339  case BO_AddAssign: return &ComplexExprEmitter::EmitBinAdd;
1340  default:
1341  llvm_unreachable("unexpected complex compound assignment");
1342  }
1343 }
1344 
1347  CompoundFunc Op = getComplexOp(E->getOpcode());
1348  RValue Val;
1349  return ComplexExprEmitter(*this).EmitCompoundAssignLValue(E, Op, Val);
1350 }
1351 
1354  llvm::Value *&Result) {
1355  CompoundFunc Op = getComplexOp(E->getOpcode());
1356  RValue Val;
1357  LValue Ret = ComplexExprEmitter(*this).EmitCompoundAssignLValue(E, Op, Val);
1358  Result = Val.getScalarVal();
1359  return Ret;
1360 }
clang::StmtVisitor
StmtVisitor - This class implements a simple visitor for Stmt subclasses.
Definition: StmtVisitor.h:183
clang::CodeGen::CodeGenFunction::ConvertTypeForMem
llvm::Type * ConvertTypeForMem(QualType T)
Definition: CodeGenFunction.cpp:210
clang::CompoundAssignOperator::getComputationLHSType
QualType getComputationLHSType() const
Definition: Expr.h:4093
clang::SubstNonTypeTemplateParmExpr
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition: ExprCXX.h:4269
clang::CodeGen::CodeGenFunction::EmitComplexExprIntoLValue
void EmitComplexExprIntoLValue(const Expr *E, LValue dest, bool isInit)
EmitComplexExprIntoLValue - Emit the given expression of complex type and place its result into the s...
Definition: CGExprComplex.cpp:1300
clang::AtomicExpr
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition: Expr.h:6239
clang::ImaginaryLiteral
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
Definition: Expr.h:1727
clang::CodeGen::CodeGenFunction::getProfileCount
uint64_t getProfileCount(const Stmt *S)
Get the profiler's count for the given statement.
Definition: CodeGenFunction.h:1537
clang::CodeGen::CodeGenFunction::EmitScalarConversion
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...
Definition: CGExprScalar.cpp:5051
clang::interp::Add
bool Add(InterpState &S, CodePtr OpPC)
Definition: Interp.h:155
clang::CodeGen::RValue
RValue - This trivial value class is used to represent the result of an expression that is evaluated.
Definition: CGValue.h:39
clang::CodeGen::CodeGenModule::CreateRuntimeFunction
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.
Definition: CodeGenModule.cpp:4215
clang::CodeGen::CodeGenFunction::emitAddrOfImagComponent
Address emitAddrOfImagComponent(Address complex, QualType complexType)
Definition: CGExprComplex.cpp:365
clang::CXXDefaultArgExpr::getExpr
const Expr * getExpr() const
Definition: ExprCXX.h:1287
clang::interp::Div
bool Div(InterpState &S, CodePtr OpPC)
1) Pops the RHS from the stack.
Definition: Interp.h:253
CodeGenFunction.h
clang::CodeGen::CodeGenFunction::EmitCall
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,...
Definition: CGCall.cpp:4728
Ret
static bool Ret(InterpState &S, CodePtr &PC, APValue &Result)
Definition: Interp.cpp:34
clang::Type::isFloat16Type
bool isFloat16Type() const
Definition: Type.h:7189
clang::CodeGen::CodeGenFunction::EmitScalarCompoundAssignWithComplex
LValue EmitScalarCompoundAssignWithComplex(const CompoundAssignOperator *E, llvm::Value *&Result)
Definition: CGExprComplex.cpp:1353
clang::CodeGen::CodeGenFunction::EmitCoyieldExpr
RValue EmitCoyieldExpr(const CoyieldExpr &E, AggValueSlot aggSlot=AggValueSlot::ignored(), bool ignoreResult=false)
Definition: CGCoroutine.cpp:268
llvm::SmallVector
Definition: LLVM.h:38
clang::SourceLocation
Encodes a location in the source.
Definition: SourceLocation.h:86
clang::AbstractConditionalOperator
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
Definition: Expr.h:4112
clang::CodeGen::CodeGenFunction::EmitPseudoObjectRValue
RValue EmitPseudoObjectRValue(const PseudoObjectExpr *e, AggValueSlot slot=AggValueSlot::ignored())
Definition: CGExpr.cpp:5629
clang::CodeGen::LValue::getAddress
Address getAddress(CodeGenFunction &CGF) const
Definition: CGValue.h:341
clang::CodeGen::CodeGenFunction::CXXDefaultArgExprScope
Definition: CodeGenFunction.h:1641
clang::CodeGen::CodeGenFunction::EmitLoadOfComplex
ComplexPairTy EmitLoadOfComplex(LValue src, SourceLocation loc)
EmitLoadOfComplex - Load a complex number from the specified l-value.
Definition: CGExprComplex.cpp:1316
clang::CodeGen::CodeGenFunction::EmitAtomicStore
void EmitAtomicStore(RValue rvalue, LValue lvalue, bool isInit)
Definition: CGAtomic.cpp:2028
clang::CastExpr::getSubExpr
Expr * getSubExpr()
Definition: Expr.h:3530
clang::CXXRewrittenBinaryOperator::getSemanticForm
Expr * getSemanticForm()
Get an equivalent semantic form for this expression.
Definition: ExprCXX.h:302
clang::QualType
A (possibly-)qualified type.
Definition: Type.h:737
clang::CodeGen::CodeGenFunction::EmitComplexCompoundAssignmentLValue
LValue EmitComplexCompoundAssignmentLValue(const CompoundAssignOperator *E)
Definition: CGExprComplex.cpp:1346
clang::AbstractConditionalOperator::getTrueExpr
Expr * getTrueExpr() const
Definition: Expr.h:4296
clang::CodeGen::Address::isValid
bool isValid() const
Definition: Address.h:91
clang::ast_matchers::type
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
Definition: ASTMatchersInternal.cpp:774
clang::CodeGen::CodeGenFunction::EmitCoawaitExpr
RValue EmitCoawaitExpr(const CoawaitExpr &E, AggValueSlot aggSlot=AggValueSlot::ignored(), bool ignoreResult=false)
Definition: CGCoroutine.cpp:261
clang::ASTContext::getFunctionType
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:1534
clang::BinaryOperator::getExprLoc
SourceLocation getExprLoc() const
Definition: Expr.h:3852
clang::CodeGen::CodeGenFunction::createBasicBlock
llvm::BasicBlock * createBasicBlock(const Twine &name="", llvm::Function *parent=nullptr, llvm::BasicBlock *before=nullptr)
createBasicBlock - Create an LLVM basic block.
Definition: CodeGenFunction.h:2428
clang::Type::isRealFloatingType
bool isRealFloatingType() const
Floating point categories.
Definition: Type.cpp:2138
clang::CodeGen::CodeGenFunction::OpaqueValueMapping
An RAII object to set (and then clear) a mapping for an OpaqueValueExpr.
Definition: CodeGenFunction.h:1330
clang::StmtExpr::getSubStmt
CompoundStmt * getSubStmt()
Definition: Expr.h:4371
clang::ComplexType::getElementType
QualType getElementType() const
Definition: Type.h:2726
clang::InitListExpr
Describes an C or C++ initializer list.
Definition: Expr.h:4796
clang::UnaryOperator
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition: Expr.h:2172
clang::CodeGen::CodeGenFunction::EmitVAArg
Address EmitVAArg(VAArgExpr *VE, Address &VAListAddr)
Generate code to get an argument from the passed in pointer and update it accordingly.
Definition: CGCall.cpp:5674
clang::CodeGen::CodeGenFunction::EmitStoreOfScalar
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...
Definition: CodeGenFunction.h:3851
clang::BinaryOperator::getOpcode
Opcode getOpcode() const
Definition: Expr.h:3856
clang::CodeGen::CodeGenFunction::EmitObjCMessageExpr
RValue EmitObjCMessageExpr(const ObjCMessageExpr *E, ReturnValueSlot Return=ReturnValueSlot())
Definition: CGObjC.cpp:574
clang::CodeGen::CGBuilderTy
Definition: CGBuilder.h:45
clang::CodeGen::CGBuilderTy::CreateStructGEP
Address CreateStructGEP(Address Addr, unsigned Index, const llvm::Twine &Name="")
Definition: CGBuilder.h:192
ConstantEmitter.h
clang::CodeGen::CodeGenFunction::EmitPromotedScalarExpr
llvm::Value * EmitPromotedScalarExpr(const Expr *E, QualType PromotionType)
Definition: CGExprScalar.cpp:5073
clang::Expr::isGLValue
bool isGLValue() const
Definition: Expr.h:273
clang::CodeGen::CallArgList::add
void add(RValue rvalue, QualType type)
Definition: CGCall.h:283
clang::CodeGen::CodeGenFunction::Builder
CGBuilderTy Builder
Definition: CodeGenFunction.h:269
clang::OpaqueValueExpr
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition: Expr.h:1144
clang::CodeGen::CodeGenFunction::CXXDefaultInitExprScope
The scope of a CXXDefaultInitExpr.
Definition: CodeGenFunction.h:1620
clang::CodeGen::CodeGenModule::getOpenMPRuntime
CGOpenMPRuntime & getOpenMPRuntime()
Return a reference to the configured OpenMP runtime.
Definition: CodeGenModule.h:635
HANDLE_BINOP
#define HANDLE_BINOP(OP)
clang::CodeGen::CodeGenFunction::EmitLoadOfScalar
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...
Definition: CodeGenFunction.h:3829
U
clang::CodeGen::CodeGenFunction::emitAddrOfRealComponent
Address emitAddrOfRealComponent(Address complex, QualType complexType)
Definition: CGExprComplex.cpp:360
clang::CodeGen::CodeGenFunction::ComplexPairTy
std::pair< llvm::Value *, llvm::Value * > ComplexPairTy
Definition: CodeGenFunction.h:267
clang::CodeGen::ReturnValueSlot
ReturnValueSlot - Contains the address where the return value of a function can be stored,...
Definition: CGCall.h:357
clang::CodeGen::CodeGenFunction::EmitPromotedValue
ComplexPairTy EmitPromotedValue(ComplexPairTy result, QualType PromotionType)
Definition: CGExprComplex.cpp:950
clang::Type::isReferenceType
bool isReferenceType() const
Definition: Type.h:6895
V
#define V(N, I)
Definition: ASTContext.h:3208
clang::CallExpr::getCallReturnType
QualType getCallReturnType(const ASTContext &Ctx) const
getCallReturnType - Get the return type of the call expr.
Definition: Expr.cpp:1575
clang::CodeGen::CodeGenFunction::RunCleanupsScope
Enters a new scope for capturing cleanups, all of which will be executed once the scope is exited.
Definition: CodeGenFunction.h:872
HANDLEBINOP
#define HANDLEBINOP(OP)
Definition: CGExprComplex.cpp:293
clang::CXXRewrittenBinaryOperator
A rewritten comparison expression that was originally written using operator syntax.
Definition: ExprCXX.h:284
clang::interp::Mul
bool Mul(InterpState &S, CodePtr OpPC)
Definition: Interp.h:171
clang::CodeGen::CodeGenFunction::EmitComplexAssignmentLValue
LValue EmitComplexAssignmentLValue(const BinaryOperator *E)
Emit an l-value for an assignment (simple or compound) of complex type.
Definition: CGExprComplex.cpp:1321
clang::CodeGen::LValue::isVolatileQualified
bool isVolatileQualified() const
Definition: CGValue.h:272
clang::ParenExpr::getSubExpr
const Expr * getSubExpr() const
Definition: Expr.h:2136
clang::BinaryOperator
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3812
clang::FunctionProtoType::ExceptionSpecInfo
Holds information about the various types of exception specification.
Definition: Type.h:4073
clang::CodeGen::Address::getName
llvm::StringRef getName() const
Return the IR name of the pointer value.
Definition: Address.h:115
clang::Scope
Scope - A scope is a transient data structure that is used while parsing the program.
Definition: Scope.h:40
clang::syntax::NodeRole::Callee
@ Callee
clang::SubstNonTypeTemplateParmExpr::getReplacement
Expr * getReplacement() const
Definition: ExprCXX.h:4307
CGOpenMPRuntime.h
getComplexOp
static CompoundFunc getComplexOp(BinaryOperatorKind Op)
Definition: CGExprComplex.cpp:1334
clang::Type::getAs
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7386
clang::CodeGen::CodeGenFunction::ConstantEmission::isReference
bool isReference() const
Definition: CodeGenFunction.h:3954
clang::CodeGen::CodeGenFunction::getTarget
const TargetInfo & getTarget() const
Definition: CodeGenFunction.h:2026
clang::CodeGen::CodeGenFunction::ConstantEmission
Definition: CodeGenFunction.h:3937
CompoundFunc
ComplexPairTy(ComplexExprEmitter::* CompoundFunc)(const ComplexExprEmitter::BinOpInfo &)
Definition: CGExprComplex.cpp:1331
getComplexMultiplyLibCallName
static StringRef getComplexMultiplyLibCallName(llvm::Type *Ty)
Lookup the libcall name for a given floating point type complex multiply.
Definition: CGExprComplex.cpp:726
clang::CodeGen::CodeGenFunction::EmitAtomicExpr
RValue EmitAtomicExpr(AtomicExpr *E)
Definition: CGAtomic.cpp:806
clang::StmtVisitorBase< std::add_pointer, ImplClass, void, ParamTys... >::Visit
void Visit(PTR(Stmt) S, ParamTys... P)
Definition: StmtVisitor.h:43
clang::CodeGen::CodeGenFunction::EmitBranchOnBoolExpr
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.
Definition: CodeGenFunction.cpp:1691
clang::PseudoObjectExpr
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition: Expr.h:6105
clang::CodeGen::CodeGenFunction::EmitComplexToScalarConversion
llvm::Value * EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy, QualType DstTy, SourceLocation Loc)
Emit a conversion from the specified complex type to the specified destination type,...
Definition: CGExprScalar.cpp:5061
clang::AbstractConditionalOperator::getFalseExpr
Expr * getFalseExpr() const
Definition: Expr.h:4302
clang::CodeGen::LValue::getType
QualType getType() const
Definition: CGValue.h:278
clang::ImplicitValueInitExpr
Represents an implicitly-generated value initialization of an object of a given type.
Definition: Expr.h:5515
clang::CodeGen::CodeGenFunction::EmitComplexPrePostIncDec
ComplexPairTy EmitComplexPrePostIncDec(const UnaryOperator *E, LValue LV, bool isInc, bool isPre)
Definition: CGExpr.cpp:988
clang::CompoundAssignOperator::getComputationResultType
QualType getComputationResultType() const
Definition: Expr.h:4096
clang::ASTContext::FloatTy
CanQualType FloatTy
Definition: ASTContext.h:1092
clang::CodeGen::CodeGenModule::getTypes
CodeGenTypes & getTypes()
Definition: CodeGenModule.h:755
clang::CodeGen::CodeGenFunction::EmitAtomicLoad
RValue EmitAtomicLoad(LValue LV, SourceLocation SL, AggValueSlot Slot=AggValueSlot::ignored())
Definition: CGAtomic.cpp:1609
clang::ExprWithCleanups
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition: ExprCXX.h:3366
clang::CodeGen::CodeGenFunction::EmitCompoundStmt
Address EmitCompoundStmt(const CompoundStmt &S, bool GetLast=false, AggValueSlot AVS=AggValueSlot::ignored())
EmitCompoundStmt - Emit a compound statement {..} node.
Definition: CGStmt.cpp:477
clang::CodeGen::CodeGenFunction::getLLVMContext
llvm::LLVMContext & getLLVMContext()
Definition: CodeGenFunction.h:2027
clang::Type::isAnyComplexType
bool isAnyComplexType() const
Definition: Type.h:6981
clang::Type::isAtomicType
bool isAtomicType() const
Definition: Type.h:7024
clang::ASTContext::getComplexType
QualType getComplexType(QualType T) const
Return the uniqued reference to the type for a complex number with the specified element type.
Definition: ASTContext.cpp:3314
clang::CodeGen::CodeGenFunction::getContext
ASTContext & getContext() const
Definition: CodeGenFunction.h:1984
clang::ImaginaryLiteral::getSubExpr
const Expr * getSubExpr() const
Definition: Expr.h:1739
clang::CodeGen::CodeGenFunction::incrementProfileCounter
void incrementProfileCounter(const Stmt *S, llvm::Value *StepV=nullptr)
Increment the profiler's counter for the given statement by StepV.
Definition: CodeGenFunction.h:1528
clang::CodeGen::Address
An aligned address.
Definition: Address.h:74
CodeGenModule.h
clang::CXXDefaultArgExpr
A default argument (C++ [dcl.fct.default]).
Definition: ExprCXX.h:1248
clang::CodeGen::CodeGenFunction::ConditionalEvaluation
An object to manage conditionally-evaluated expressions.
Definition: CodeGenFunction.h:1184
clang::ConstantExpr
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition: Expr.h:1041
clang::ObjCMessageExpr
An expression that sends a message to the given Objective-C object or class.
Definition: ExprObjC.h:941
clang::CodeGen::CodeGenFunction::EmitCallExpr
RValue EmitCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue=ReturnValueSlot())
Definition: CGExpr.cpp:4969
clang::CastExpr::getCastKind
CastKind getCastKind() const
Definition: Expr.h:3524
clang::CodeGen::CGCallee::forDirect
static CGCallee forDirect(llvm::Constant *functionPtr, const CGCalleeInfo &abstractInfo=CGCalleeInfo())
Definition: CGCall.h:130
clang::ChooseExpr
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Definition: Expr.h:4529
clang::interp::Null
bool Null(InterpState &S, CodePtr OpPC)
Definition: Interp.h:1128
clang::CodeGen::CodeGenFunction::EmitIgnoredExpr
void EmitIgnoredExpr(const Expr *E)
EmitIgnoredExpr - Emit an expression in a context which ignores the result.
Definition: CGExpr.cpp:190
clang::CodeGen::LValue::setTBAAInfo
void setTBAAInfo(TBAAAccessInfo Info)
Definition: CGValue.h:323
clang::FullExpr::getSubExpr
const Expr * getSubExpr() const
Definition: Expr.h:1026
clang::CodeGen::CodeGenFunction::LValueIsSuitableForInlineAtomic
bool LValueIsSuitableForInlineAtomic(LValue Src)
An LValue is a candidate for having its loads and stores be made atomic if we are operating under /vo...
Definition: CGAtomic.cpp:1596
clang::FunctionProtoType::ExtProtoInfo::withExceptionSpec
ExtProtoInfo withExceptionSpec(const ExceptionSpecInfo &ESI)
Definition: Type.h:4114
clang::CodeGen::CodeGenTypes::GetFunctionType
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.
Definition: CGCall.cpp:1617
clang::Type::castAs
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:7453
clang::CompoundLiteralExpr
CompoundLiteralExpr - [C99 6.5.2.5].
Definition: Expr.h:3410
Emitter
clang::CodeGen::ApplyDebugLocation
A scoped helper to set the current debug location to the specified location or preferred location of ...
Definition: CGDebugInfo.h:797
clang::MemberExpr::getBase
Expr * getBase() const
Definition: Expr.h:3246
clang::CodeGen::LValue
LValue - This represents an lvalue references.
Definition: CGValue.h:171
clang::CodeGen::LValue::isSimple
bool isSimple() const
Definition: CGValue.h:265
clang::CodeGen::CodeGenFunction::StmtExprEvaluation
An RAII object to record that we're evaluating a statement expression.
Definition: CodeGenFunction.h:1223
clang::CodeGen::CGOpenMPRuntime::checkAndEmitLastprivateConditional
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 ...
Definition: CGOpenMPRuntime.cpp:12226
clang::CodeGen::CodeGenModule::EmitExplicitCastExprType
void EmitExplicitCastExprType(const ExplicitCastExpr *E, CodeGenFunction *CGF=nullptr)
Emit type info if type of an expression is a variably modified type.
Definition: CGExpr.cpp:1023
clang::ChooseExpr::getChosenSubExpr
Expr * getChosenSubExpr() const
getChosenSubExpr - Return the subexpression chosen according to the condition.
Definition: Expr.h:4565
clang::CodeGen::CodeGenFunction
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
Definition: CodeGenFunction.h:231
clang::ComplexType
Complex values, per C99 6.2.5p11.
Definition: Type.h:2716
clang::CXXDefaultInitExpr::getExpr
const Expr * getExpr() const
Get the initialization expression that will be used.
Definition: ExprCXX.h:1353
clang::BinaryOperator::getLHS
Expr * getLHS() const
Definition: Expr.h:3861
clang::ParenExpr
ParenExpr - This represents a parethesized expression, e.g.
Definition: Expr.h:2121
clang::CoyieldExpr
Represents a 'co_yield' expression.
Definition: ExprCXX.h:4904
clang::FunctionProtoType
Represents a prototype with parameter type info, e.g.
Definition: Type.h:4016
clang::Expr::getExprLoc
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Definition: Expr.cpp:329
clang::QualType::isNull
bool isNull() const
Return true if this QualType doesn't point to a type yet.
Definition: Type.h:802
clang::StmtExpr
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition: Expr.h:4354
clang::CodeGen::CodeGenFunction::EmitComplexExpr
ComplexPairTy EmitComplexExpr(const Expr *E, bool IgnoreReal=false, bool IgnoreImag=false)
EmitComplexExpr - Emit the computation of the specified expression of complex type,...
Definition: CGExprComplex.cpp:1291
Value
Value
Definition: UninitializedValues.cpp:103
clang::TargetInfo::shouldEmitFloat16WithExcessPrecision
virtual bool shouldEmitFloat16WithExcessPrecision() const
Definition: TargetInfo.h:935
clang::CodeGen::Address::invalid
static Address invalid()
Definition: Address.h:90
clang::CodeGen::CodeGenTypeCache::getRuntimeCC
llvm::CallingConv::ID getRuntimeCC() const
Definition: CodeGenTypeCache.h:122
clang::CodeGen::CGCallee
All available information about a concrete callee.
Definition: CGCall.h:60
StmtVisitor.h
clang::ast_matchers::complexType
const AstTypeMatcher< ComplexType > complexType
Matches C99 complex types.
Definition: ASTMatchersInternal.cpp:1037
clang::OpaqueValueExpr::getExprLoc
SourceLocation getExprLoc() const LLVM_READONLY
Definition: Expr.h:1174
clang::CoawaitExpr
Represents a 'co_await' expression.
Definition: ExprCXX.h:4823
clang::CodeGen::CodeGenFunction::ConvertType
llvm::Type * ConvertType(QualType T)
Definition: CodeGenFunction.cpp:214
clang::CodeGen::CodeGenFunction::ConstantEmission::getValue
llvm::Constant * getValue() const
Definition: CodeGenFunction.h:3961
clang::CodeGen::RValue::getComplexVal
std::pair< llvm::Value *, llvm::Value * > getComplexVal() const
getComplexVal - Return the real/imag components of this complex value.
Definition: CGValue.h:68
ComplexPairTy
CodeGenFunction::ComplexPairTy ComplexPairTy
Definition: CGExprComplex.cpp:31
clang::CompoundAssignOperator
CompoundAssignOperator - For compound assignments (e.g.
Definition: Expr.h:4059
clang::BinaryOperatorKind
BinaryOperatorKind
Definition: OperationKinds.h:25
clang::CodeGen::CodeGenFunction::MakeAddrLValue
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
Definition: CodeGenFunction.h:2490
clang::CodeGen::CodeGenFunction::ErrorUnsupported
void ErrorUnsupported(const Stmt *S, const char *Type)
ErrorUnsupported - Print out an error that codegen doesn't support the specified stmt yet.
Definition: CodeGenFunction.cpp:1911
clang::CodeGen::CodeGenFunction::tryEmitAsConstant
ConstantEmission tryEmitAsConstant(DeclRefExpr *refExpr)
Try to emit a reference to the given value without producing it as an l-value.
Definition: CGExpr.cpp:1475
clang::CodeGen::CodeGenFunction::EmitScalarExpr
llvm::Value * EmitScalarExpr(const Expr *E, bool IgnoreResultAssign=false)
EmitScalarExpr - Emit the computation of the specified expression of LLVM scalar type,...
Definition: CGExprScalar.cpp:5041
clang::CodeGen::CGFunctionInfo
CGFunctionInfo - Class to encapsulate the information about a function definition.
Definition: CGFunctionInfo.h:546
clang::CodeGen::CodeGenFunction::CGFPOptionsRAII
Definition: CodeGenFunction.h:714
clang::CodeGen::RValue::getComplex
static RValue getComplex(llvm::Value *V1, llvm::Value *V2)
Definition: CGValue.h:96
clang::CodeGen::CodeGenFunction::EmitStoreOfComplex
void EmitStoreOfComplex(ComplexPairTy V, LValue dest, bool isInit)
EmitStoreOfComplex - Store a complex number into the specified l-value.
Definition: CGExprComplex.cpp:1310
clang::CodeGen::CodeGenFunction::CGM
CodeGenModule & CGM
Definition: CodeGenFunction.h:261
clang::AbstractConditionalOperator::getCond
Expr * getCond() const
Definition: Expr.h:4290
clang::FunctionProtoType::ExtProtoInfo
Extra information about a function prototype.
Definition: Type.h:4099
clang::UnaryOperator::getSubExpr
Expr * getSubExpr() const
Definition: Expr.h:2219
clang::CodeGen::CodeGenFunction::getOrCreateOpaqueLValueMapping
LValue getOrCreateOpaqueLValueMapping(const OpaqueValueExpr *e)
Given an opaque value expression, return its LValue mapping if it exists, otherwise create one.
Definition: CGExpr.cpp:4914
clang::Expr::IgnoreParens
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
Definition: Expr.cpp:3031
clang
Definition: CalledOnceCheck.h:17
clang::CodeGen::RValue::get
static RValue get(llvm::Value *V)
Definition: CGValue.h:89
clang::interp::GE
bool GE(InterpState &S, CodePtr OpPC)
Definition: Interp.h:519
clang::CodeGen::CodeGenTypes::arrangeFreeFunctionCall
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:628
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:71
clang::EST_BasicNoexcept
@ EST_BasicNoexcept
noexcept
Definition: ExceptionSpecificationType.h:26
clang::BinaryOperator::getRHS
Expr * getRHS() const
Definition: Expr.h:3863
clang::GenericSelectionExpr
Represents a C11 generic selection.
Definition: Expr.h:5633
clang::CXXScalarValueInitExpr
An expression "T()" which creates a value-initialized rvalue of type T, which is a non-class type.
Definition: ExprCXX.h:2100
clang::CodeGen::CodeGenFunction::ConstantEmission::getReferenceLValue
LValue getReferenceLValue(CodeGenFunction &CGF, Expr *refExpr) const
Definition: CodeGenFunction.h:3955
clang::Expr::getType
QualType getType() const
Definition: Expr.h:141
clang::CodeGen::CodeGenFunction::EmitUnPromotedValue
ComplexPairTy EmitUnPromotedValue(ComplexPairTy result, QualType PromotionType)
Definition: CGExprComplex.cpp:937
clang::CodeGen::RValue::getScalarVal
llvm::Value * getScalarVal() const
getScalarVal() - Return the Value* of this scalar value.
Definition: CGValue.h:61
clang::CodeGen::TBAAAccessInfo::getMayAliasInfo
static TBAAAccessInfo getMayAliasInfo()
Definition: CodeGenTBAA.h:62
clang::ImplicitCastExpr
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:3624
clang::VAArgExpr
Represents a call to the builtin function __builtin_va_arg.
Definition: Expr.h:4638
clang::CodeGen::ConstantEmitter
Definition: ConstantEmitter.h:23
clang::MemberExpr
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:3169
clang::CodeGen::CodeGenFunction::EmitLValue
LValue EmitLValue(const Expr *E)
EmitLValue - Emit code to compute a designator that specifies the location of the expression.
Definition: CGExpr.cpp:1272
clang::QualType::getTypePtr
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:6622
clang::InitListExpr::getInit
const Expr * getInit(unsigned Init) const
Definition: Expr.h:4844
clang::AtomicType
Definition: Type.h:6440
clang::interp::Call
bool Call(InterpState &S, CodePtr &PC, const Function *Func)
Definition: Interp.h:1246
clang::CastKind
CastKind
CastKind - The kind of operation required for a conversion.
Definition: OperationKinds.h:20
clang::ASTContext::hasSameUnqualifiedType
bool hasSameUnqualifiedType(QualType T1, QualType T2) const
Determine whether the given types are equivalent after cvr-qualifiers have been removed.
Definition: ASTContext.h:2544
clang::Expr
This represents one expression.
Definition: Expr.h:109
clang::CXXDefaultInitExpr
A use of a default initializer in a constructor or in aggregate initialization.
Definition: ExprCXX.h:1325
clang::Type::isUnsignedIntegerType
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:2069
clang::CastExpr
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition: Expr.h:3480
clang::CodeGen::CallArgList
CallArgList - Type for representing both the value and type of arguments in a call.
Definition: CGCall.h:259
clang::DeclRefExpr
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1232
clang::CallExpr
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2810
clang::CodeGen::CodeGenFunction::EmitBlock
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
Definition: CGStmt.cpp:563
clang::InitListExpr::getNumInits
unsigned getNumInits() const
Definition: Expr.h:4826
clang::interp::Sub
bool Sub(InterpState &S, CodePtr OpPC)
Definition: Interp.h:163
clang::ObjCIvarRefExpr
ObjCIvarRefExpr - A reference to an ObjC instance variable.
Definition: ExprObjC.h:549
getComplexType
static const ComplexType * getComplexType(QualType type)
Return the complex type that we are meant to emit.
Definition: CGExprComplex.cpp:34
clang::CodeGen::CodeGenFunction::getLangOpts
const LangOptions & getLangOpts() const
Definition: CodeGenFunction.h:1997
clang::CodeGen::CodeGenFunction::getOrCreateOpaqueRValueMapping
RValue getOrCreateOpaqueRValueMapping(const OpaqueValueExpr *e)
Given an opaque value expression, return its RValue mapping if it exists, otherwise create one.
Definition: CGExpr.cpp:4928
clang::CodeGen::CodeGenFunction::EmitBranch
void EmitBranch(llvm::BasicBlock *Block)
EmitBranch - Emit a branch to the specified basic block from the current insert block,...
Definition: CGStmt.cpp:583
clang::CodeGen::CodeGenFunction::EmitPromotedComplexExpr
ComplexPairTy EmitPromotedComplexExpr(const Expr *E, QualType PromotionType)
Definition: CGExprComplex.cpp:995