clang  14.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  ComplexPairTy VisitUnaryPlus (const UnaryOperator *E) {
210  TestAndClearIgnoreReal();
211  TestAndClearIgnoreImag();
212  return Visit(E->getSubExpr());
213  }
214  ComplexPairTy VisitUnaryMinus (const UnaryOperator *E);
215  ComplexPairTy VisitUnaryNot (const UnaryOperator *E);
216  // LNot,Real,Imag never return complex.
217  ComplexPairTy VisitUnaryExtension(const UnaryOperator *E) {
218  return Visit(E->getSubExpr());
219  }
220  ComplexPairTy VisitCXXDefaultArgExpr(CXXDefaultArgExpr *DAE) {
222  return Visit(DAE->getExpr());
223  }
224  ComplexPairTy VisitCXXDefaultInitExpr(CXXDefaultInitExpr *DIE) {
226  return Visit(DIE->getExpr());
227  }
228  ComplexPairTy VisitExprWithCleanups(ExprWithCleanups *E) {
230  ComplexPairTy Vals = Visit(E->getSubExpr());
231  // Defend against dominance problems caused by jumps out of expression
232  // evaluation through the shared cleanup block.
233  Scope.ForceCleanup({&Vals.first, &Vals.second});
234  return Vals;
235  }
236  ComplexPairTy VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
237  assert(E->getType()->isAnyComplexType() && "Expected complex type!");
238  QualType Elem = E->getType()->castAs<ComplexType>()->getElementType();
239  llvm::Constant *Null = llvm::Constant::getNullValue(CGF.ConvertType(Elem));
240  return ComplexPairTy(Null, Null);
241  }
242  ComplexPairTy VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) {
243  assert(E->getType()->isAnyComplexType() && "Expected complex type!");
244  QualType Elem = E->getType()->castAs<ComplexType>()->getElementType();
245  llvm::Constant *Null =
246  llvm::Constant::getNullValue(CGF.ConvertType(Elem));
247  return ComplexPairTy(Null, Null);
248  }
249 
250  struct BinOpInfo {
251  ComplexPairTy LHS;
252  ComplexPairTy RHS;
253  QualType Ty; // Computation Type.
254  };
255 
256  BinOpInfo EmitBinOps(const BinaryOperator *E);
257  LValue EmitCompoundAssignLValue(const CompoundAssignOperator *E,
258  ComplexPairTy (ComplexExprEmitter::*Func)
259  (const BinOpInfo &),
260  RValue &Val);
261  ComplexPairTy EmitCompoundAssign(const CompoundAssignOperator *E,
262  ComplexPairTy (ComplexExprEmitter::*Func)
263  (const BinOpInfo &));
264 
265  ComplexPairTy EmitBinAdd(const BinOpInfo &Op);
266  ComplexPairTy EmitBinSub(const BinOpInfo &Op);
267  ComplexPairTy EmitBinMul(const BinOpInfo &Op);
268  ComplexPairTy EmitBinDiv(const BinOpInfo &Op);
269 
270  ComplexPairTy EmitComplexBinOpLibCall(StringRef LibCallName,
271  const BinOpInfo &Op);
272 
273  ComplexPairTy VisitBinAdd(const BinaryOperator *E) {
274  return EmitBinAdd(EmitBinOps(E));
275  }
276  ComplexPairTy VisitBinSub(const BinaryOperator *E) {
277  return EmitBinSub(EmitBinOps(E));
278  }
279  ComplexPairTy VisitBinMul(const BinaryOperator *E) {
280  return EmitBinMul(EmitBinOps(E));
281  }
282  ComplexPairTy VisitBinDiv(const BinaryOperator *E) {
283  return EmitBinDiv(EmitBinOps(E));
284  }
285 
286  ComplexPairTy VisitCXXRewrittenBinaryOperator(CXXRewrittenBinaryOperator *E) {
287  return Visit(E->getSemanticForm());
288  }
289 
290  // Compound assignments.
291  ComplexPairTy VisitBinAddAssign(const CompoundAssignOperator *E) {
292  return EmitCompoundAssign(E, &ComplexExprEmitter::EmitBinAdd);
293  }
294  ComplexPairTy VisitBinSubAssign(const CompoundAssignOperator *E) {
295  return EmitCompoundAssign(E, &ComplexExprEmitter::EmitBinSub);
296  }
297  ComplexPairTy VisitBinMulAssign(const CompoundAssignOperator *E) {
298  return EmitCompoundAssign(E, &ComplexExprEmitter::EmitBinMul);
299  }
300  ComplexPairTy VisitBinDivAssign(const CompoundAssignOperator *E) {
301  return EmitCompoundAssign(E, &ComplexExprEmitter::EmitBinDiv);
302  }
303 
304  // GCC rejects rem/and/or/xor for integer complex.
305  // Logical and/or always return int, never complex.
306 
307  // No comparisons produce a complex result.
308 
309  LValue EmitBinAssignLValue(const BinaryOperator *E,
310  ComplexPairTy &Val);
311  ComplexPairTy VisitBinAssign (const BinaryOperator *E);
312  ComplexPairTy VisitBinComma (const BinaryOperator *E);
313 
314 
316  VisitAbstractConditionalOperator(const AbstractConditionalOperator *CO);
317  ComplexPairTy VisitChooseExpr(ChooseExpr *CE);
318 
319  ComplexPairTy VisitInitListExpr(InitListExpr *E);
320 
321  ComplexPairTy VisitCompoundLiteralExpr(CompoundLiteralExpr *E) {
322  return EmitLoadOfLValue(E);
323  }
324 
325  ComplexPairTy VisitVAArgExpr(VAArgExpr *E);
326 
327  ComplexPairTy VisitAtomicExpr(AtomicExpr *E) {
328  return CGF.EmitAtomicExpr(E).getComplexVal();
329  }
330 };
331 } // end anonymous namespace.
332 
333 //===----------------------------------------------------------------------===//
334 // Utilities
335 //===----------------------------------------------------------------------===//
336 
339  return Builder.CreateStructGEP(addr, 0, addr.getName() + ".realp");
340 }
341 
344  return Builder.CreateStructGEP(addr, 1, addr.getName() + ".imagp");
345 }
346 
347 /// EmitLoadOfLValue - Given an RValue reference for a complex, emit code to
348 /// load the real and imaginary pieces, returning them as Real/Imag.
349 ComplexPairTy ComplexExprEmitter::EmitLoadOfLValue(LValue lvalue,
350  SourceLocation loc) {
351  assert(lvalue.isSimple() && "non-simple complex l-value?");
352  if (lvalue.getType()->isAtomicType())
353  return CGF.EmitAtomicLoad(lvalue, loc).getComplexVal();
354 
355  Address SrcPtr = lvalue.getAddress(CGF);
356  bool isVolatile = lvalue.isVolatileQualified();
357 
358  llvm::Value *Real = nullptr, *Imag = nullptr;
359 
360  if (!IgnoreReal || isVolatile) {
361  Address RealP = CGF.emitAddrOfRealComponent(SrcPtr, lvalue.getType());
362  Real = Builder.CreateLoad(RealP, isVolatile, SrcPtr.getName() + ".real");
363  }
364 
365  if (!IgnoreImag || isVolatile) {
366  Address ImagP = CGF.emitAddrOfImagComponent(SrcPtr, lvalue.getType());
367  Imag = Builder.CreateLoad(ImagP, isVolatile, SrcPtr.getName() + ".imag");
368  }
369 
370  return ComplexPairTy(Real, Imag);
371 }
372 
373 /// EmitStoreOfComplex - Store the specified real/imag parts into the
374 /// specified value pointer.
375 void ComplexExprEmitter::EmitStoreOfComplex(ComplexPairTy Val, LValue lvalue,
376  bool isInit) {
377  if (lvalue.getType()->isAtomicType() ||
378  (!isInit && CGF.LValueIsSuitableForInlineAtomic(lvalue)))
379  return CGF.EmitAtomicStore(RValue::getComplex(Val), lvalue, isInit);
380 
381  Address Ptr = lvalue.getAddress(CGF);
382  Address RealPtr = CGF.emitAddrOfRealComponent(Ptr, lvalue.getType());
383  Address ImagPtr = CGF.emitAddrOfImagComponent(Ptr, lvalue.getType());
384 
385  Builder.CreateStore(Val.first, RealPtr, lvalue.isVolatileQualified());
386  Builder.CreateStore(Val.second, ImagPtr, lvalue.isVolatileQualified());
387 }
388 
389 
390 
391 //===----------------------------------------------------------------------===//
392 // Visitor Methods
393 //===----------------------------------------------------------------------===//
394 
395 ComplexPairTy ComplexExprEmitter::VisitExpr(Expr *E) {
396  CGF.ErrorUnsupported(E, "complex expression");
397  llvm::Type *EltTy =
399  llvm::Value *U = llvm::UndefValue::get(EltTy);
400  return ComplexPairTy(U, U);
401 }
402 
403 ComplexPairTy ComplexExprEmitter::
404 VisitImaginaryLiteral(const ImaginaryLiteral *IL) {
405  llvm::Value *Imag = CGF.EmitScalarExpr(IL->getSubExpr());
406  return ComplexPairTy(llvm::Constant::getNullValue(Imag->getType()), Imag);
407 }
408 
409 
410 ComplexPairTy ComplexExprEmitter::VisitCallExpr(const CallExpr *E) {
412  return EmitLoadOfLValue(E);
413 
414  return CGF.EmitCallExpr(E).getComplexVal();
415 }
416 
417 ComplexPairTy ComplexExprEmitter::VisitStmtExpr(const StmtExpr *E) {
419  Address RetAlloca = CGF.EmitCompoundStmt(*E->getSubStmt(), true);
420  assert(RetAlloca.isValid() && "Expected complex return value");
421  return EmitLoadOfLValue(CGF.MakeAddrLValue(RetAlloca, E->getType()),
422  E->getExprLoc());
423 }
424 
425 /// Emit a cast from complex value Val to DestType.
426 ComplexPairTy ComplexExprEmitter::EmitComplexToComplexCast(ComplexPairTy Val,
427  QualType SrcType,
428  QualType DestType,
429  SourceLocation Loc) {
430  // Get the src/dest element type.
431  SrcType = SrcType->castAs<ComplexType>()->getElementType();
432  DestType = DestType->castAs<ComplexType>()->getElementType();
433 
434  // C99 6.3.1.6: When a value of complex type is converted to another
435  // complex type, both the real and imaginary parts follow the conversion
436  // rules for the corresponding real types.
437  if (Val.first)
438  Val.first = CGF.EmitScalarConversion(Val.first, SrcType, DestType, Loc);
439  if (Val.second)
440  Val.second = CGF.EmitScalarConversion(Val.second, SrcType, DestType, Loc);
441  return Val;
442 }
443 
444 ComplexPairTy ComplexExprEmitter::EmitScalarToComplexCast(llvm::Value *Val,
445  QualType SrcType,
446  QualType DestType,
447  SourceLocation Loc) {
448  // Convert the input element to the element type of the complex.
449  DestType = DestType->castAs<ComplexType>()->getElementType();
450  Val = CGF.EmitScalarConversion(Val, SrcType, DestType, Loc);
451 
452  // Return (realval, 0).
453  return ComplexPairTy(Val, llvm::Constant::getNullValue(Val->getType()));
454 }
455 
456 ComplexPairTy ComplexExprEmitter::EmitCast(CastKind CK, Expr *Op,
457  QualType DestTy) {
458  switch (CK) {
459  case CK_Dependent: llvm_unreachable("dependent cast kind in IR gen!");
460 
461  // Atomic to non-atomic casts may be more than a no-op for some platforms and
462  // for some types.
463  case CK_AtomicToNonAtomic:
464  case CK_NonAtomicToAtomic:
465  case CK_NoOp:
466  case CK_LValueToRValue:
467  case CK_UserDefinedConversion:
468  return Visit(Op);
469 
470  case CK_LValueBitCast: {
471  LValue origLV = CGF.EmitLValue(Op);
472  Address V = origLV.getAddress(CGF);
473  V = Builder.CreateElementBitCast(V, CGF.ConvertType(DestTy));
474  return EmitLoadOfLValue(CGF.MakeAddrLValue(V, DestTy), Op->getExprLoc());
475  }
476 
477  case CK_LValueToRValueBitCast: {
478  LValue SourceLVal = CGF.EmitLValue(Op);
479  Address Addr = Builder.CreateElementBitCast(SourceLVal.getAddress(CGF),
480  CGF.ConvertTypeForMem(DestTy));
481  LValue DestLV = CGF.MakeAddrLValue(Addr, DestTy);
483  return EmitLoadOfLValue(DestLV, Op->getExprLoc());
484  }
485 
486  case CK_BitCast:
487  case CK_BaseToDerived:
488  case CK_DerivedToBase:
489  case CK_UncheckedDerivedToBase:
490  case CK_Dynamic:
491  case CK_ToUnion:
492  case CK_ArrayToPointerDecay:
493  case CK_FunctionToPointerDecay:
494  case CK_NullToPointer:
495  case CK_NullToMemberPointer:
496  case CK_BaseToDerivedMemberPointer:
497  case CK_DerivedToBaseMemberPointer:
498  case CK_MemberPointerToBoolean:
499  case CK_ReinterpretMemberPointer:
500  case CK_ConstructorConversion:
501  case CK_IntegralToPointer:
502  case CK_PointerToIntegral:
503  case CK_PointerToBoolean:
504  case CK_ToVoid:
505  case CK_VectorSplat:
506  case CK_IntegralCast:
507  case CK_BooleanToSignedIntegral:
508  case CK_IntegralToBoolean:
509  case CK_IntegralToFloating:
510  case CK_FloatingToIntegral:
511  case CK_FloatingToBoolean:
512  case CK_FloatingCast:
513  case CK_CPointerToObjCPointerCast:
514  case CK_BlockPointerToObjCPointerCast:
515  case CK_AnyPointerToBlockPointerCast:
516  case CK_ObjCObjectLValueCast:
517  case CK_FloatingComplexToReal:
518  case CK_FloatingComplexToBoolean:
519  case CK_IntegralComplexToReal:
520  case CK_IntegralComplexToBoolean:
521  case CK_ARCProduceObject:
522  case CK_ARCConsumeObject:
523  case CK_ARCReclaimReturnedObject:
524  case CK_ARCExtendBlockObject:
525  case CK_CopyAndAutoreleaseBlockObject:
526  case CK_BuiltinFnToFnPtr:
527  case CK_ZeroToOCLOpaqueType:
528  case CK_AddressSpaceConversion:
529  case CK_IntToOCLSampler:
530  case CK_FloatingToFixedPoint:
531  case CK_FixedPointToFloating:
532  case CK_FixedPointCast:
533  case CK_FixedPointToBoolean:
534  case CK_FixedPointToIntegral:
535  case CK_IntegralToFixedPoint:
536  case CK_MatrixCast:
537  llvm_unreachable("invalid cast kind for complex value");
538 
539  case CK_FloatingRealToComplex:
540  case CK_IntegralRealToComplex: {
541  CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, Op);
542  return EmitScalarToComplexCast(CGF.EmitScalarExpr(Op), Op->getType(),
543  DestTy, Op->getExprLoc());
544  }
545 
546  case CK_FloatingComplexCast:
547  case CK_FloatingComplexToIntegralComplex:
548  case CK_IntegralComplexCast:
549  case CK_IntegralComplexToFloatingComplex: {
550  CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, Op);
551  return EmitComplexToComplexCast(Visit(Op), Op->getType(), DestTy,
552  Op->getExprLoc());
553  }
554  }
555 
556  llvm_unreachable("unknown cast resulting in complex value");
557 }
558 
559 ComplexPairTy ComplexExprEmitter::VisitUnaryMinus(const UnaryOperator *E) {
560  TestAndClearIgnoreReal();
561  TestAndClearIgnoreImag();
562  ComplexPairTy Op = Visit(E->getSubExpr());
563 
564  llvm::Value *ResR, *ResI;
565  if (Op.first->getType()->isFloatingPointTy()) {
566  ResR = Builder.CreateFNeg(Op.first, "neg.r");
567  ResI = Builder.CreateFNeg(Op.second, "neg.i");
568  } else {
569  ResR = Builder.CreateNeg(Op.first, "neg.r");
570  ResI = Builder.CreateNeg(Op.second, "neg.i");
571  }
572  return ComplexPairTy(ResR, ResI);
573 }
574 
575 ComplexPairTy ComplexExprEmitter::VisitUnaryNot(const UnaryOperator *E) {
576  TestAndClearIgnoreReal();
577  TestAndClearIgnoreImag();
578  // ~(a+ib) = a + i*-b
579  ComplexPairTy Op = Visit(E->getSubExpr());
580  llvm::Value *ResI;
581  if (Op.second->getType()->isFloatingPointTy())
582  ResI = Builder.CreateFNeg(Op.second, "conj.i");
583  else
584  ResI = Builder.CreateNeg(Op.second, "conj.i");
585 
586  return ComplexPairTy(Op.first, ResI);
587 }
588 
589 ComplexPairTy ComplexExprEmitter::EmitBinAdd(const BinOpInfo &Op) {
590  llvm::Value *ResR, *ResI;
591 
592  if (Op.LHS.first->getType()->isFloatingPointTy()) {
593  ResR = Builder.CreateFAdd(Op.LHS.first, Op.RHS.first, "add.r");
594  if (Op.LHS.second && Op.RHS.second)
595  ResI = Builder.CreateFAdd(Op.LHS.second, Op.RHS.second, "add.i");
596  else
597  ResI = Op.LHS.second ? Op.LHS.second : Op.RHS.second;
598  assert(ResI && "Only one operand may be real!");
599  } else {
600  ResR = Builder.CreateAdd(Op.LHS.first, Op.RHS.first, "add.r");
601  assert(Op.LHS.second && Op.RHS.second &&
602  "Both operands of integer complex operators must be complex!");
603  ResI = Builder.CreateAdd(Op.LHS.second, Op.RHS.second, "add.i");
604  }
605  return ComplexPairTy(ResR, ResI);
606 }
607 
608 ComplexPairTy ComplexExprEmitter::EmitBinSub(const BinOpInfo &Op) {
609  llvm::Value *ResR, *ResI;
610  if (Op.LHS.first->getType()->isFloatingPointTy()) {
611  ResR = Builder.CreateFSub(Op.LHS.first, Op.RHS.first, "sub.r");
612  if (Op.LHS.second && Op.RHS.second)
613  ResI = Builder.CreateFSub(Op.LHS.second, Op.RHS.second, "sub.i");
614  else
615  ResI = Op.LHS.second ? Op.LHS.second
616  : Builder.CreateFNeg(Op.RHS.second, "sub.i");
617  assert(ResI && "Only one operand may be real!");
618  } else {
619  ResR = Builder.CreateSub(Op.LHS.first, Op.RHS.first, "sub.r");
620  assert(Op.LHS.second && Op.RHS.second &&
621  "Both operands of integer complex operators must be complex!");
622  ResI = Builder.CreateSub(Op.LHS.second, Op.RHS.second, "sub.i");
623  }
624  return ComplexPairTy(ResR, ResI);
625 }
626 
627 /// Emit a libcall for a binary operation on complex types.
628 ComplexPairTy ComplexExprEmitter::EmitComplexBinOpLibCall(StringRef LibCallName,
629  const BinOpInfo &Op) {
630  CallArgList Args;
631  Args.add(RValue::get(Op.LHS.first),
632  Op.Ty->castAs<ComplexType>()->getElementType());
633  Args.add(RValue::get(Op.LHS.second),
634  Op.Ty->castAs<ComplexType>()->getElementType());
635  Args.add(RValue::get(Op.RHS.first),
636  Op.Ty->castAs<ComplexType>()->getElementType());
637  Args.add(RValue::get(Op.RHS.second),
638  Op.Ty->castAs<ComplexType>()->getElementType());
639 
640  // We *must* use the full CG function call building logic here because the
641  // complex type has special ABI handling. We also should not forget about
642  // special calling convention which may be used for compiler builtins.
643 
644  // We create a function qualified type to state that this call does not have
645  // any exceptions.
647  EPI = EPI.withExceptionSpec(
649  SmallVector<QualType, 4> ArgsQTys(
650  4, Op.Ty->castAs<ComplexType>()->getElementType());
651  QualType FQTy = CGF.getContext().getFunctionType(Op.Ty, ArgsQTys, EPI);
652  const CGFunctionInfo &FuncInfo = CGF.CGM.getTypes().arrangeFreeFunctionCall(
653  Args, cast<FunctionType>(FQTy.getTypePtr()), false);
654 
655  llvm::FunctionType *FTy = CGF.CGM.getTypes().GetFunctionType(FuncInfo);
656  llvm::FunctionCallee Func = CGF.CGM.CreateRuntimeFunction(
657  FTy, LibCallName, llvm::AttributeList(), true);
659 
660  llvm::CallBase *Call;
661  RValue Res = CGF.EmitCall(FuncInfo, Callee, ReturnValueSlot(), Args, &Call);
662  Call->setCallingConv(CGF.CGM.getRuntimeCC());
663  return Res.getComplexVal();
664 }
665 
666 /// Lookup the libcall name for a given floating point type complex
667 /// multiply.
668 static StringRef getComplexMultiplyLibCallName(llvm::Type *Ty) {
669  switch (Ty->getTypeID()) {
670  default:
671  llvm_unreachable("Unsupported floating point type!");
672  case llvm::Type::HalfTyID:
673  return "__mulhc3";
674  case llvm::Type::FloatTyID:
675  return "__mulsc3";
676  case llvm::Type::DoubleTyID:
677  return "__muldc3";
678  case llvm::Type::PPC_FP128TyID:
679  return "__multc3";
680  case llvm::Type::X86_FP80TyID:
681  return "__mulxc3";
682  case llvm::Type::FP128TyID:
683  return "__multc3";
684  }
685 }
686 
687 // See C11 Annex G.5.1 for the semantics of multiplicative operators on complex
688 // typed values.
689 ComplexPairTy ComplexExprEmitter::EmitBinMul(const BinOpInfo &Op) {
690  using llvm::Value;
691  Value *ResR, *ResI;
692  llvm::MDBuilder MDHelper(CGF.getLLVMContext());
693 
694  if (Op.LHS.first->getType()->isFloatingPointTy()) {
695  // The general formulation is:
696  // (a + ib) * (c + id) = (a * c - b * d) + i(a * d + b * c)
697  //
698  // But we can fold away components which would be zero due to a real
699  // operand according to C11 Annex G.5.1p2.
700  // FIXME: C11 also provides for imaginary types which would allow folding
701  // still more of this within the type system.
702 
703  if (Op.LHS.second && Op.RHS.second) {
704  // If both operands are complex, emit the core math directly, and then
705  // test for NaNs. If we find NaNs in the result, we delegate to a libcall
706  // to carefully re-compute the correct infinity representation if
707  // possible. The expectation is that the presence of NaNs here is
708  // *extremely* rare, and so the cost of the libcall is almost irrelevant.
709  // This is good, because the libcall re-computes the core multiplication
710  // exactly the same as we do here and re-tests for NaNs in order to be
711  // a generic complex*complex libcall.
712 
713  // First compute the four products.
714  Value *AC = Builder.CreateFMul(Op.LHS.first, Op.RHS.first, "mul_ac");
715  Value *BD = Builder.CreateFMul(Op.LHS.second, Op.RHS.second, "mul_bd");
716  Value *AD = Builder.CreateFMul(Op.LHS.first, Op.RHS.second, "mul_ad");
717  Value *BC = Builder.CreateFMul(Op.LHS.second, Op.RHS.first, "mul_bc");
718 
719  // The real part is the difference of the first two, the imaginary part is
720  // the sum of the second.
721  ResR = Builder.CreateFSub(AC, BD, "mul_r");
722  ResI = Builder.CreateFAdd(AD, BC, "mul_i");
723 
724  // Emit the test for the real part becoming NaN and create a branch to
725  // handle it. We test for NaN by comparing the number to itself.
726  Value *IsRNaN = Builder.CreateFCmpUNO(ResR, ResR, "isnan_cmp");
727  llvm::BasicBlock *ContBB = CGF.createBasicBlock("complex_mul_cont");
728  llvm::BasicBlock *INaNBB = CGF.createBasicBlock("complex_mul_imag_nan");
729  llvm::Instruction *Branch = Builder.CreateCondBr(IsRNaN, INaNBB, ContBB);
730  llvm::BasicBlock *OrigBB = Branch->getParent();
731 
732  // Give hint that we very much don't expect to see NaNs.
733  // Value chosen to match UR_NONTAKEN_WEIGHT, see BranchProbabilityInfo.cpp
734  llvm::MDNode *BrWeight = MDHelper.createBranchWeights(1, (1U << 20) - 1);
735  Branch->setMetadata(llvm::LLVMContext::MD_prof, BrWeight);
736 
737  // Now test the imaginary part and create its branch.
738  CGF.EmitBlock(INaNBB);
739  Value *IsINaN = Builder.CreateFCmpUNO(ResI, ResI, "isnan_cmp");
740  llvm::BasicBlock *LibCallBB = CGF.createBasicBlock("complex_mul_libcall");
741  Branch = Builder.CreateCondBr(IsINaN, LibCallBB, ContBB);
742  Branch->setMetadata(llvm::LLVMContext::MD_prof, BrWeight);
743 
744  // Now emit the libcall on this slowest of the slow paths.
745  CGF.EmitBlock(LibCallBB);
746  Value *LibCallR, *LibCallI;
747  std::tie(LibCallR, LibCallI) = EmitComplexBinOpLibCall(
748  getComplexMultiplyLibCallName(Op.LHS.first->getType()), Op);
749  Builder.CreateBr(ContBB);
750 
751  // Finally continue execution by phi-ing together the different
752  // computation paths.
753  CGF.EmitBlock(ContBB);
754  llvm::PHINode *RealPHI = Builder.CreatePHI(ResR->getType(), 3, "real_mul_phi");
755  RealPHI->addIncoming(ResR, OrigBB);
756  RealPHI->addIncoming(ResR, INaNBB);
757  RealPHI->addIncoming(LibCallR, LibCallBB);
758  llvm::PHINode *ImagPHI = Builder.CreatePHI(ResI->getType(), 3, "imag_mul_phi");
759  ImagPHI->addIncoming(ResI, OrigBB);
760  ImagPHI->addIncoming(ResI, INaNBB);
761  ImagPHI->addIncoming(LibCallI, LibCallBB);
762  return ComplexPairTy(RealPHI, ImagPHI);
763  }
764  assert((Op.LHS.second || Op.RHS.second) &&
765  "At least one operand must be complex!");
766 
767  // If either of the operands is a real rather than a complex, the
768  // imaginary component is ignored when computing the real component of the
769  // result.
770  ResR = Builder.CreateFMul(Op.LHS.first, Op.RHS.first, "mul.rl");
771 
772  ResI = Op.LHS.second
773  ? Builder.CreateFMul(Op.LHS.second, Op.RHS.first, "mul.il")
774  : Builder.CreateFMul(Op.LHS.first, Op.RHS.second, "mul.ir");
775  } else {
776  assert(Op.LHS.second && Op.RHS.second &&
777  "Both operands of integer complex operators must be complex!");
778  Value *ResRl = Builder.CreateMul(Op.LHS.first, Op.RHS.first, "mul.rl");
779  Value *ResRr = Builder.CreateMul(Op.LHS.second, Op.RHS.second, "mul.rr");
780  ResR = Builder.CreateSub(ResRl, ResRr, "mul.r");
781 
782  Value *ResIl = Builder.CreateMul(Op.LHS.second, Op.RHS.first, "mul.il");
783  Value *ResIr = Builder.CreateMul(Op.LHS.first, Op.RHS.second, "mul.ir");
784  ResI = Builder.CreateAdd(ResIl, ResIr, "mul.i");
785  }
786  return ComplexPairTy(ResR, ResI);
787 }
788 
789 // See C11 Annex G.5.1 for the semantics of multiplicative operators on complex
790 // typed values.
791 ComplexPairTy ComplexExprEmitter::EmitBinDiv(const BinOpInfo &Op) {
792  llvm::Value *LHSr = Op.LHS.first, *LHSi = Op.LHS.second;
793  llvm::Value *RHSr = Op.RHS.first, *RHSi = Op.RHS.second;
794 
795  llvm::Value *DSTr, *DSTi;
796  if (LHSr->getType()->isFloatingPointTy()) {
797  // If we have a complex operand on the RHS and FastMath is not allowed, we
798  // delegate to a libcall to handle all of the complexities and minimize
799  // underflow/overflow cases. When FastMath is allowed we construct the
800  // divide inline using the same algorithm as for integer operands.
801  //
802  // FIXME: We would be able to avoid the libcall in many places if we
803  // supported imaginary types in addition to complex types.
804  if (RHSi && !CGF.getLangOpts().FastMath) {
805  BinOpInfo LibCallOp = Op;
806  // If LHS was a real, supply a null imaginary part.
807  if (!LHSi)
808  LibCallOp.LHS.second = llvm::Constant::getNullValue(LHSr->getType());
809 
810  switch (LHSr->getType()->getTypeID()) {
811  default:
812  llvm_unreachable("Unsupported floating point type!");
813  case llvm::Type::HalfTyID:
814  return EmitComplexBinOpLibCall("__divhc3", LibCallOp);
815  case llvm::Type::FloatTyID:
816  return EmitComplexBinOpLibCall("__divsc3", LibCallOp);
817  case llvm::Type::DoubleTyID:
818  return EmitComplexBinOpLibCall("__divdc3", LibCallOp);
819  case llvm::Type::PPC_FP128TyID:
820  return EmitComplexBinOpLibCall("__divtc3", LibCallOp);
821  case llvm::Type::X86_FP80TyID:
822  return EmitComplexBinOpLibCall("__divxc3", LibCallOp);
823  case llvm::Type::FP128TyID:
824  return EmitComplexBinOpLibCall("__divtc3", LibCallOp);
825  }
826  } else if (RHSi) {
827  if (!LHSi)
828  LHSi = llvm::Constant::getNullValue(RHSi->getType());
829 
830  // (a+ib) / (c+id) = ((ac+bd)/(cc+dd)) + i((bc-ad)/(cc+dd))
831  llvm::Value *AC = Builder.CreateFMul(LHSr, RHSr); // a*c
832  llvm::Value *BD = Builder.CreateFMul(LHSi, RHSi); // b*d
833  llvm::Value *ACpBD = Builder.CreateFAdd(AC, BD); // ac+bd
834 
835  llvm::Value *CC = Builder.CreateFMul(RHSr, RHSr); // c*c
836  llvm::Value *DD = Builder.CreateFMul(RHSi, RHSi); // d*d
837  llvm::Value *CCpDD = Builder.CreateFAdd(CC, DD); // cc+dd
838 
839  llvm::Value *BC = Builder.CreateFMul(LHSi, RHSr); // b*c
840  llvm::Value *AD = Builder.CreateFMul(LHSr, RHSi); // a*d
841  llvm::Value *BCmAD = Builder.CreateFSub(BC, AD); // bc-ad
842 
843  DSTr = Builder.CreateFDiv(ACpBD, CCpDD);
844  DSTi = Builder.CreateFDiv(BCmAD, CCpDD);
845  } else {
846  assert(LHSi && "Can have at most one non-complex operand!");
847 
848  DSTr = Builder.CreateFDiv(LHSr, RHSr);
849  DSTi = Builder.CreateFDiv(LHSi, RHSr);
850  }
851  } else {
852  assert(Op.LHS.second && Op.RHS.second &&
853  "Both operands of integer complex operators must be complex!");
854  // (a+ib) / (c+id) = ((ac+bd)/(cc+dd)) + i((bc-ad)/(cc+dd))
855  llvm::Value *Tmp1 = Builder.CreateMul(LHSr, RHSr); // a*c
856  llvm::Value *Tmp2 = Builder.CreateMul(LHSi, RHSi); // b*d
857  llvm::Value *Tmp3 = Builder.CreateAdd(Tmp1, Tmp2); // ac+bd
858 
859  llvm::Value *Tmp4 = Builder.CreateMul(RHSr, RHSr); // c*c
860  llvm::Value *Tmp5 = Builder.CreateMul(RHSi, RHSi); // d*d
861  llvm::Value *Tmp6 = Builder.CreateAdd(Tmp4, Tmp5); // cc+dd
862 
863  llvm::Value *Tmp7 = Builder.CreateMul(LHSi, RHSr); // b*c
864  llvm::Value *Tmp8 = Builder.CreateMul(LHSr, RHSi); // a*d
865  llvm::Value *Tmp9 = Builder.CreateSub(Tmp7, Tmp8); // bc-ad
866 
867  if (Op.Ty->castAs<ComplexType>()->getElementType()->isUnsignedIntegerType()) {
868  DSTr = Builder.CreateUDiv(Tmp3, Tmp6);
869  DSTi = Builder.CreateUDiv(Tmp9, Tmp6);
870  } else {
871  DSTr = Builder.CreateSDiv(Tmp3, Tmp6);
872  DSTi = Builder.CreateSDiv(Tmp9, Tmp6);
873  }
874  }
875 
876  return ComplexPairTy(DSTr, DSTi);
877 }
878 
879 ComplexExprEmitter::BinOpInfo
880 ComplexExprEmitter::EmitBinOps(const BinaryOperator *E) {
881  TestAndClearIgnoreReal();
882  TestAndClearIgnoreImag();
883  BinOpInfo Ops;
884  if (E->getLHS()->getType()->isRealFloatingType())
885  Ops.LHS = ComplexPairTy(CGF.EmitScalarExpr(E->getLHS()), nullptr);
886  else
887  Ops.LHS = Visit(E->getLHS());
888  if (E->getRHS()->getType()->isRealFloatingType())
889  Ops.RHS = ComplexPairTy(CGF.EmitScalarExpr(E->getRHS()), nullptr);
890  else
891  Ops.RHS = Visit(E->getRHS());
892 
893  Ops.Ty = E->getType();
894  return Ops;
895 }
896 
897 
898 LValue ComplexExprEmitter::
899 EmitCompoundAssignLValue(const CompoundAssignOperator *E,
900  ComplexPairTy (ComplexExprEmitter::*Func)(const BinOpInfo&),
901  RValue &Val) {
902  TestAndClearIgnoreReal();
903  TestAndClearIgnoreImag();
904  QualType LHSTy = E->getLHS()->getType();
905  if (const AtomicType *AT = LHSTy->getAs<AtomicType>())
906  LHSTy = AT->getValueType();
907 
908  CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
909  BinOpInfo OpInfo;
910 
911  // Load the RHS and LHS operands.
912  // __block variables need to have the rhs evaluated first, plus this should
913  // improve codegen a little.
914  OpInfo.Ty = E->getComputationResultType();
915  QualType ComplexElementTy = cast<ComplexType>(OpInfo.Ty)->getElementType();
916 
917  // The RHS should have been converted to the computation type.
918  if (E->getRHS()->getType()->isRealFloatingType()) {
919  assert(
920  CGF.getContext()
921  .hasSameUnqualifiedType(ComplexElementTy, E->getRHS()->getType()));
922  OpInfo.RHS = ComplexPairTy(CGF.EmitScalarExpr(E->getRHS()), nullptr);
923  } else {
924  assert(CGF.getContext()
925  .hasSameUnqualifiedType(OpInfo.Ty, E->getRHS()->getType()));
926  OpInfo.RHS = Visit(E->getRHS());
927  }
928 
929  LValue LHS = CGF.EmitLValue(E->getLHS());
930 
931  // Load from the l-value and convert it.
932  SourceLocation Loc = E->getExprLoc();
933  if (LHSTy->isAnyComplexType()) {
934  ComplexPairTy LHSVal = EmitLoadOfLValue(LHS, Loc);
935  OpInfo.LHS = EmitComplexToComplexCast(LHSVal, LHSTy, OpInfo.Ty, Loc);
936  } else {
937  llvm::Value *LHSVal = CGF.EmitLoadOfScalar(LHS, Loc);
938  // For floating point real operands we can directly pass the scalar form
939  // to the binary operator emission and potentially get more efficient code.
940  if (LHSTy->isRealFloatingType()) {
941  if (!CGF.getContext().hasSameUnqualifiedType(ComplexElementTy, LHSTy))
942  LHSVal = CGF.EmitScalarConversion(LHSVal, LHSTy, ComplexElementTy, Loc);
943  OpInfo.LHS = ComplexPairTy(LHSVal, nullptr);
944  } else {
945  OpInfo.LHS = EmitScalarToComplexCast(LHSVal, LHSTy, OpInfo.Ty, Loc);
946  }
947  }
948 
949  // Expand the binary operator.
950  ComplexPairTy Result = (this->*Func)(OpInfo);
951 
952  // Truncate the result and store it into the LHS lvalue.
953  if (LHSTy->isAnyComplexType()) {
954  ComplexPairTy ResVal =
955  EmitComplexToComplexCast(Result, OpInfo.Ty, LHSTy, Loc);
956  EmitStoreOfComplex(ResVal, LHS, /*isInit*/ false);
957  Val = RValue::getComplex(ResVal);
958  } else {
959  llvm::Value *ResVal =
960  CGF.EmitComplexToScalarConversion(Result, OpInfo.Ty, LHSTy, Loc);
961  CGF.EmitStoreOfScalar(ResVal, LHS, /*isInit*/ false);
962  Val = RValue::get(ResVal);
963  }
964 
965  return LHS;
966 }
967 
968 // Compound assignments.
969 ComplexPairTy ComplexExprEmitter::
970 EmitCompoundAssign(const CompoundAssignOperator *E,
971  ComplexPairTy (ComplexExprEmitter::*Func)(const BinOpInfo&)){
972  RValue Val;
973  LValue LV = EmitCompoundAssignLValue(E, Func, Val);
974 
975  // The result of an assignment in C is the assigned r-value.
976  if (!CGF.getLangOpts().CPlusPlus)
977  return Val.getComplexVal();
978 
979  // If the lvalue is non-volatile, return the computed value of the assignment.
980  if (!LV.isVolatileQualified())
981  return Val.getComplexVal();
982 
983  return EmitLoadOfLValue(LV, E->getExprLoc());
984 }
985 
986 LValue ComplexExprEmitter::EmitBinAssignLValue(const BinaryOperator *E,
987  ComplexPairTy &Val) {
988  assert(CGF.getContext().hasSameUnqualifiedType(E->getLHS()->getType(),
989  E->getRHS()->getType()) &&
990  "Invalid assignment");
991  TestAndClearIgnoreReal();
992  TestAndClearIgnoreImag();
993 
994  // Emit the RHS. __block variables need the RHS evaluated first.
995  Val = Visit(E->getRHS());
996 
997  // Compute the address to store into.
998  LValue LHS = CGF.EmitLValue(E->getLHS());
999 
1000  // Store the result value into the LHS lvalue.
1001  EmitStoreOfComplex(Val, LHS, /*isInit*/ false);
1002 
1003  return LHS;
1004 }
1005 
1006 ComplexPairTy ComplexExprEmitter::VisitBinAssign(const BinaryOperator *E) {
1007  ComplexPairTy Val;
1008  LValue LV = EmitBinAssignLValue(E, Val);
1009 
1010  // The result of an assignment in C is the assigned r-value.
1011  if (!CGF.getLangOpts().CPlusPlus)
1012  return Val;
1013 
1014  // If the lvalue is non-volatile, return the computed value of the assignment.
1015  if (!LV.isVolatileQualified())
1016  return Val;
1017 
1018  return EmitLoadOfLValue(LV, E->getExprLoc());
1019 }
1020 
1021 ComplexPairTy ComplexExprEmitter::VisitBinComma(const BinaryOperator *E) {
1022  CGF.EmitIgnoredExpr(E->getLHS());
1023  return Visit(E->getRHS());
1024 }
1025 
1026 ComplexPairTy ComplexExprEmitter::
1027 VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) {
1028  TestAndClearIgnoreReal();
1029  TestAndClearIgnoreImag();
1030  llvm::BasicBlock *LHSBlock = CGF.createBasicBlock("cond.true");
1031  llvm::BasicBlock *RHSBlock = CGF.createBasicBlock("cond.false");
1032  llvm::BasicBlock *ContBlock = CGF.createBasicBlock("cond.end");
1033 
1034  // Bind the common expression if necessary.
1035  CodeGenFunction::OpaqueValueMapping binding(CGF, E);
1036 
1037 
1039  CGF.EmitBranchOnBoolExpr(E->getCond(), LHSBlock, RHSBlock,
1040  CGF.getProfileCount(E));
1041 
1042  eval.begin(CGF);
1043  CGF.EmitBlock(LHSBlock);
1044  CGF.incrementProfileCounter(E);
1045  ComplexPairTy LHS = Visit(E->getTrueExpr());
1046  LHSBlock = Builder.GetInsertBlock();
1047  CGF.EmitBranch(ContBlock);
1048  eval.end(CGF);
1049 
1050  eval.begin(CGF);
1051  CGF.EmitBlock(RHSBlock);
1052  ComplexPairTy RHS = Visit(E->getFalseExpr());
1053  RHSBlock = Builder.GetInsertBlock();
1054  CGF.EmitBlock(ContBlock);
1055  eval.end(CGF);
1056 
1057  // Create a PHI node for the real part.
1058  llvm::PHINode *RealPN = Builder.CreatePHI(LHS.first->getType(), 2, "cond.r");
1059  RealPN->addIncoming(LHS.first, LHSBlock);
1060  RealPN->addIncoming(RHS.first, RHSBlock);
1061 
1062  // Create a PHI node for the imaginary part.
1063  llvm::PHINode *ImagPN = Builder.CreatePHI(LHS.first->getType(), 2, "cond.i");
1064  ImagPN->addIncoming(LHS.second, LHSBlock);
1065  ImagPN->addIncoming(RHS.second, RHSBlock);
1066 
1067  return ComplexPairTy(RealPN, ImagPN);
1068 }
1069 
1070 ComplexPairTy ComplexExprEmitter::VisitChooseExpr(ChooseExpr *E) {
1071  return Visit(E->getChosenSubExpr());
1072 }
1073 
1074 ComplexPairTy ComplexExprEmitter::VisitInitListExpr(InitListExpr *E) {
1075  bool Ignore = TestAndClearIgnoreReal();
1076  (void)Ignore;
1077  assert (Ignore == false && "init list ignored");
1078  Ignore = TestAndClearIgnoreImag();
1079  (void)Ignore;
1080  assert (Ignore == false && "init list ignored");
1081 
1082  if (E->getNumInits() == 2) {
1083  llvm::Value *Real = CGF.EmitScalarExpr(E->getInit(0));
1084  llvm::Value *Imag = CGF.EmitScalarExpr(E->getInit(1));
1085  return ComplexPairTy(Real, Imag);
1086  } else if (E->getNumInits() == 1) {
1087  return Visit(E->getInit(0));
1088  }
1089 
1090  // Empty init list initializes to null
1091  assert(E->getNumInits() == 0 && "Unexpected number of inits");
1092  QualType Ty = E->getType()->castAs<ComplexType>()->getElementType();
1093  llvm::Type* LTy = CGF.ConvertType(Ty);
1094  llvm::Value* zeroConstant = llvm::Constant::getNullValue(LTy);
1095  return ComplexPairTy(zeroConstant, zeroConstant);
1096 }
1097 
1098 ComplexPairTy ComplexExprEmitter::VisitVAArgExpr(VAArgExpr *E) {
1099  Address ArgValue = Address::invalid();
1100  Address ArgPtr = CGF.EmitVAArg(E, ArgValue);
1101 
1102  if (!ArgPtr.isValid()) {
1103  CGF.ErrorUnsupported(E, "complex va_arg expression");
1104  llvm::Type *EltTy =
1106  llvm::Value *U = llvm::UndefValue::get(EltTy);
1107  return ComplexPairTy(U, U);
1108  }
1109 
1110  return EmitLoadOfLValue(CGF.MakeAddrLValue(ArgPtr, E->getType()),
1111  E->getExprLoc());
1112 }
1113 
1114 //===----------------------------------------------------------------------===//
1115 // Entry Point into this File
1116 //===----------------------------------------------------------------------===//
1117 
1118 /// EmitComplexExpr - Emit the computation of the specified expression of
1119 /// complex type, ignoring the result.
1121  bool IgnoreImag) {
1122  assert(E && getComplexType(E->getType()) &&
1123  "Invalid complex expression to emit");
1124 
1125  return ComplexExprEmitter(*this, IgnoreReal, IgnoreImag)
1126  .Visit(const_cast<Expr *>(E));
1127 }
1128 
1130  bool isInit) {
1131  assert(E && getComplexType(E->getType()) &&
1132  "Invalid complex expression to emit");
1133  ComplexExprEmitter Emitter(*this);
1134  ComplexPairTy Val = Emitter.Visit(const_cast<Expr*>(E));
1135  Emitter.EmitStoreOfComplex(Val, dest, isInit);
1136 }
1137 
1138 /// EmitStoreOfComplex - Store a complex number into the specified l-value.
1140  bool isInit) {
1141  ComplexExprEmitter(*this).EmitStoreOfComplex(V, dest, isInit);
1142 }
1143 
1144 /// EmitLoadOfComplex - Load a complex number from the specified address.
1146  SourceLocation loc) {
1147  return ComplexExprEmitter(*this).EmitLoadOfLValue(src, loc);
1148 }
1149 
1151  assert(E->getOpcode() == BO_Assign);
1152  ComplexPairTy Val; // ignored
1153  LValue LVal = ComplexExprEmitter(*this).EmitBinAssignLValue(E, Val);
1154  if (getLangOpts().OpenMP)
1156  E->getLHS());
1157  return LVal;
1158 }
1159 
1160 typedef ComplexPairTy (ComplexExprEmitter::*CompoundFunc)(
1161  const ComplexExprEmitter::BinOpInfo &);
1162 
1164  switch (Op) {
1165  case BO_MulAssign: return &ComplexExprEmitter::EmitBinMul;
1166  case BO_DivAssign: return &ComplexExprEmitter::EmitBinDiv;
1167  case BO_SubAssign: return &ComplexExprEmitter::EmitBinSub;
1168  case BO_AddAssign: return &ComplexExprEmitter::EmitBinAdd;
1169  default:
1170  llvm_unreachable("unexpected complex compound assignment");
1171  }
1172 }
1173 
1176  CompoundFunc Op = getComplexOp(E->getOpcode());
1177  RValue Val;
1178  return ComplexExprEmitter(*this).EmitCompoundAssignLValue(E, Op, Val);
1179 }
1180 
1183  llvm::Value *&Result) {
1184  CompoundFunc Op = getComplexOp(E->getOpcode());
1185  RValue Val;
1186  LValue Ret = ComplexExprEmitter(*this).EmitCompoundAssignLValue(E, Op, Val);
1187  Result = Val.getScalarVal();
1188  return Ret;
1189 }
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:207
clang::SubstNonTypeTemplateParmExpr
Represents a reference to a non-type template parameter that has been substituted with a template arg...
Definition: ExprCXX.h:4245
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:1129
clang::AtomicExpr
AtomicExpr - Variadic atomic builtins: __atomic_exchange, __atomic_fetch_*, __atomic_load,...
Definition: Expr.h:6229
clang::ImaginaryLiteral
ImaginaryLiteral - We support imaginary integer and floating point literals, like "1....
Definition: Expr.h:1712
clang::CodeGen::CodeGenFunction::getProfileCount
uint64_t getProfileCount(const Stmt *S)
Get the profiler's count for the given statement.
Definition: CodeGenFunction.h:1498
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:4858
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:3790
clang::CodeGen::CodeGenFunction::emitAddrOfImagComponent
Address emitAddrOfImagComponent(Address complex, QualType complexType)
Definition: CGExprComplex.cpp:342
type
clang::CXXDefaultArgExpr::getExpr
const Expr * getExpr() const
Definition: ExprCXX.h:1280
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:4616
Ret
static bool Ret(InterpState &S, CodePtr &PC, APValue &Result)
Definition: Interp.cpp:34
clang::CodeGen::CodeGenFunction::EmitScalarCompoundAssignWithComplex
LValue EmitScalarCompoundAssignWithComplex(const CompoundAssignOperator *E, llvm::Value *&Result)
Definition: CGExprComplex.cpp:1182
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:88
clang::AbstractConditionalOperator
AbstractConditionalOperator - An abstract base class for ConditionalOperator and BinaryConditionalOpe...
Definition: Expr.h:4103
clang::CodeGen::CodeGenFunction::EmitPseudoObjectRValue
RValue EmitPseudoObjectRValue(const PseudoObjectExpr *e, AggValueSlot slot=AggValueSlot::ignored())
Definition: CGExpr.cpp:5483
clang::CodeGen::LValue::getAddress
Address getAddress(CodeGenFunction &CGF) const
Definition: CGValue.h:329
clang::CodeGen::CodeGenFunction::CXXDefaultArgExprScope
Definition: CodeGenFunction.h:1605
clang::CodeGen::CodeGenFunction::EmitLoadOfComplex
ComplexPairTy EmitLoadOfComplex(LValue src, SourceLocation loc)
EmitLoadOfComplex - Load a complex number from the specified l-value.
Definition: CGExprComplex.cpp:1145
clang::CodeGen::CodeGenFunction::EmitAtomicStore
void EmitAtomicStore(RValue rvalue, LValue lvalue, bool isInit)
Definition: CGAtomic.cpp:1974
clang::CastExpr::getSubExpr
Expr * getSubExpr()
Definition: Expr.h:3524
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:673
clang::CodeGen::CodeGenFunction::EmitComplexCompoundAssignmentLValue
LValue EmitComplexCompoundAssignmentLValue(const CompoundAssignOperator *E)
Definition: CGExprComplex.cpp:1175
clang::AbstractConditionalOperator::getTrueExpr
Expr * getTrueExpr() const
Definition: Expr.h:4287
clang::CodeGen::Address::isValid
bool isValid() const
Definition: Address.h:35
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:1522
clang::BinaryOperator::getExprLoc
SourceLocation getExprLoc() const
Definition: Expr.h:3843
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:2394
clang::Type::isRealFloatingType
bool isRealFloatingType() const
Floating point categories.
Definition: Type.cpp:2113
clang::CodeGen::CodeGenFunction::OpaqueValueMapping
An RAII object to set (and then clear) a mapping for an OpaqueValueExpr.
Definition: CodeGenFunction.h:1292
clang::StmtExpr::getSubStmt
CompoundStmt * getSubStmt()
Definition: Expr.h:4362
clang::ComplexType::getElementType
QualType getElementType() const
Definition: Type.h:2597
clang::InitListExpr
Describes an C or C++ initializer list.
Definition: Expr.h:4786
clang::UnaryOperator
UnaryOperator - This represents the unary-expression's (except sizeof and alignof),...
Definition: Expr.h:2157
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:5531
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:3802
clang::index::SymbolRole::Call
@ Call
clang::BinaryOperator::getOpcode
Opcode getOpcode() const
Definition: Expr.h:3847
clang::CodeGen::CodeGenFunction::EmitObjCMessageExpr
RValue EmitObjCMessageExpr(const ObjCMessageExpr *E, ReturnValueSlot Return=ReturnValueSlot())
Definition: CGObjC.cpp:571
clang::CodeGen::CGBuilderTy
Definition: CGBuilder.h:43
clang::CodeGen::CGBuilderTy::CreateStructGEP
Address CreateStructGEP(Address Addr, unsigned Index, const llvm::Twine &Name="")
Definition: CGBuilder.h:188
ConstantEmitter.h
clang::Expr::isGLValue
bool isGLValue() const
Definition: Expr.h:273
clang::CodeGen::CallArgList::add
void add(RValue rvalue, QualType type)
Definition: CGCall.h:288
clang::CodeGen::CodeGenFunction::Builder
CGBuilderTy Builder
Definition: CodeGenFunction.h:274
clang::OpaqueValueExpr
OpaqueValueExpr - An expression referring to an opaque object of a fixed type and value class.
Definition: Expr.h:1129
clang::CodeGen::CodeGenFunction::CXXDefaultInitExprScope
The scope of a CXXDefaultInitExpr.
Definition: CodeGenFunction.h:1584
clang::CodeGen::CodeGenModule::getOpenMPRuntime
CGOpenMPRuntime & getOpenMPRuntime()
Return a reference to the configured OpenMP runtime.
Definition: CodeGenModule.h:616
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:3780
U
clang::CodeGen::CodeGenFunction::emitAddrOfRealComponent
Address emitAddrOfRealComponent(Address complex, QualType complexType)
Definition: CGExprComplex.cpp:337
clang::CodeGen::CodeGenFunction::ComplexPairTy
std::pair< llvm::Value *, llvm::Value * > ComplexPairTy
Definition: CodeGenFunction.h:272
clang::CodeGen::ReturnValueSlot
ReturnValueSlot - Contains the address where the return value of a function can be stored,...
Definition: CGCall.h:362
clang::Type::isReferenceType
bool isReferenceType() const
Definition: Type.h:6685
V
#define V(N, I)
Definition: ASTContext.h:3121
clang::CallExpr::getCallReturnType
QualType getCallReturnType(const ASTContext &Ctx) const
getCallReturnType - Get the return type of the call expr.
Definition: Expr.cpp:1513
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:838
clang::CXXRewrittenBinaryOperator
A rewritten comparison expression that was originally written using operator syntax.
Definition: ExprCXX.h:284
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:1150
clang::CodeGen::LValue::isVolatileQualified
bool isVolatileQualified() const
Definition: CGValue.h:260
clang::ParenExpr::getSubExpr
const Expr * getSubExpr() const
Definition: Expr.h:2121
clang::BinaryOperator
A builtin binary operation expression such as "x + y" or "x <= y".
Definition: Expr.h:3803
clang::FunctionProtoType::ExceptionSpecInfo
Holds information about the various types of exception specification.
Definition: Type.h:3942
clang::CodeGen::Address::getName
llvm::StringRef getName() const
Return the IR name of the pointer value.
Definition: Address.h:61
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:4277
CGOpenMPRuntime.h
getComplexOp
static CompoundFunc getComplexOp(BinaryOperatorKind Op)
Definition: CGExprComplex.cpp:1163
clang::Type::getAs
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7162
clang::CodeGen::CodeGenFunction::ConstantEmission::isReference
bool isReference() const
Definition: CodeGenFunction.h:3904
clang::CodeGen::CodeGenFunction::ConstantEmission
Definition: CodeGenFunction.h:3887
CompoundFunc
ComplexPairTy(ComplexExprEmitter::* CompoundFunc)(const ComplexExprEmitter::BinOpInfo &)
Definition: CGExprComplex.cpp:1160
getComplexMultiplyLibCallName
static StringRef getComplexMultiplyLibCallName(llvm::Type *Ty)
Lookup the libcall name for a given floating point type complex multiply.
Definition: CGExprComplex.cpp:668
clang::CodeGen::CodeGenFunction::EmitAtomicExpr
RValue EmitAtomicExpr(AtomicExpr *E)
Definition: CGAtomic.cpp:785
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:1632
clang::PseudoObjectExpr
PseudoObjectExpr - An expression which accesses a pseudo-object l-value.
Definition: Expr.h:6095
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:4868
clang::AbstractConditionalOperator::getFalseExpr
Expr * getFalseExpr() const
Definition: Expr.h:4293
clang::CodeGen::LValue::getType
QualType getType() const
Definition: CGValue.h:266
clang::ImplicitValueInitExpr
Represents an implicitly-generated value initialization of an object of a given type.
Definition: Expr.h:5505
clang::CodeGen::CodeGenFunction::EmitComplexPrePostIncDec
ComplexPairTy EmitComplexPrePostIncDec(const UnaryOperator *E, LValue LV, bool isInc, bool isPre)
Definition: CGExpr.cpp:1009
clang::CompoundAssignOperator::getComputationResultType
QualType getComputationResultType() const
Definition: Expr.h:4087
clang::CodeGen::CodeGenModule::getTypes
CodeGenTypes & getTypes()
Definition: CodeGenModule.h:726
clang::CodeGen::CodeGenFunction::EmitAtomicLoad
RValue EmitAtomicLoad(LValue LV, SourceLocation SL, AggValueSlot Slot=AggValueSlot::ignored())
Definition: CGAtomic.cpp:1555
clang::ExprWithCleanups
Represents an expression – generally a full-expression – that introduces cleanups to be run at the en...
Definition: ExprCXX.h:3342
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:443
clang::CodeGen::CodeGenFunction::getLLVMContext
llvm::LLVMContext & getLLVMContext()
Definition: CodeGenFunction.h:1990
clang::Type::isAnyComplexType
bool isAnyComplexType() const
Definition: Type.h:6771
clang::Type::isAtomicType
bool isAtomicType() const
Definition: Type.h:6808
clang::CodeGen::CodeGenFunction::getContext
ASTContext & getContext() const
Definition: CodeGenFunction.h:1947
clang::ImaginaryLiteral::getSubExpr
const Expr * getSubExpr() const
Definition: Expr.h:1724
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:1490
clang::CodeGen::Address
An aligned address.
Definition: Address.h:24
CodeGenModule.h
clang::CXXDefaultArgExpr
A default argument (C++ [dcl.fct.default]).
Definition: ExprCXX.h:1241
clang::CodeGen::CodeGenFunction::ConditionalEvaluation
An object to manage conditionally-evaluated expressions.
Definition: CodeGenFunction.h:1146
clang::ConstantExpr
ConstantExpr - An expression that occurs in a constant context and optionally the result of evaluatin...
Definition: Expr.h:1026
clang::ObjCMessageExpr
An expression that sends a message to the given Objective-C object or class.
Definition: ExprObjC.h:940
clang::CodeGen::CodeGenFunction::EmitCallExpr
RValue EmitCallExpr(const CallExpr *E, ReturnValueSlot ReturnValue=ReturnValueSlot())
Definition: CGExpr.cpp:4857
clang::CastExpr::getCastKind
CastKind getCastKind() const
Definition: Expr.h:3518
clang::CodeGen::CGCallee::forDirect
static CGCallee forDirect(llvm::Constant *functionPtr, const CGCalleeInfo &abstractInfo=CGCalleeInfo())
Definition: CGCall.h:135
clang::ChooseExpr
ChooseExpr - GNU builtin-in function __builtin_choose_expr.
Definition: Expr.h:4520
clang::interp::Null
bool Null(InterpState &S, CodePtr OpPC)
Definition: Interp.h:820
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:311
clang::FullExpr::getSubExpr
const Expr * getSubExpr() const
Definition: Expr.h:1011
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:1542
clang::FunctionProtoType::ExtProtoInfo::withExceptionSpec
ExtProtoInfo withExceptionSpec(const ExceptionSpecInfo &ESI)
Definition: Type.h:3983
clang::CodeGen::CodeGenTypes::GetFunctionType
llvm::FunctionType * GetFunctionType(const CGFunctionInfo &Info)
GetFunctionType - Get the LLVM function type for.
Definition: CGCall.cpp:1595
clang::Type::castAs
const T * castAs() const
Member-template castAs<specific type>.
Definition: Type.h:7227
clang::CompoundLiteralExpr
CompoundLiteralExpr - [C99 6.5.2.5].
Definition: Expr.h:3403
Emitter
clang::CodeGen::ApplyDebugLocation
A scoped helper to set the current debug location to the specified location or preferred location of ...
Definition: CGDebugInfo.h:778
clang::MemberExpr::getBase
Expr * getBase() const
Definition: Expr.h:3239
clang::CodeGen::LValue
LValue - This represents an lvalue references.
Definition: CGValue.h:167
clang::CodeGen::LValue::isSimple
bool isSimple() const
Definition: CGValue.h:253
clang::CodeGen::CodeGenFunction::StmtExprEvaluation
An RAII object to record that we're evaluating a statement expression.
Definition: CodeGenFunction.h:1185
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:12724
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:1044
clang::ChooseExpr::getChosenSubExpr
Expr * getChosenSubExpr() const
getChosenSubExpr - Return the subexpression chosen according to the condition.
Definition: Expr.h:4556
clang::CodeGen::CodeGenFunction
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
Definition: CodeGenFunction.h:235
clang::ComplexType
Complex values, per C99 6.2.5p11.
Definition: Type.h:2587
clang::CXXDefaultInitExpr::getExpr
const Expr * getExpr() const
Get the initialization expression that will be used.
Definition: ExprCXX.h:1346
clang::BinaryOperator::getLHS
Expr * getLHS() const
Definition: Expr.h:3852
clang::ParenExpr
ParenExpr - This represents a parethesized expression, e.g.
Definition: Expr.h:2106
clang::CoyieldExpr
Represents a 'co_yield' expression.
Definition: ExprCXX.h:4849
clang::FunctionProtoType
Represents a prototype with parameter type info, e.g.
Definition: Type.h:3885
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:229
clang::StmtExpr
StmtExpr - This is the GNU Statement Expression extension: ({int X=4; X;}).
Definition: Expr.h:4345
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:1120
Value
Value
Definition: UninitializedValues.cpp:102
clang::CodeGen::Address::invalid
static Address invalid()
Definition: Address.h:34
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:67
StmtVisitor.h
clang::ast_matchers::complexType
const AstTypeMatcher< ComplexType > complexType
Matches C99 complex types.
Definition: ASTMatchersInternal.cpp:1034
clang::OpaqueValueExpr::getExprLoc
SourceLocation getExprLoc() const LLVM_READONLY
Definition: Expr.h:1159
clang::CoawaitExpr
Represents a 'co_await' expression.
Definition: ExprCXX.h:4764
clang::CodeGen::CodeGenFunction::ConvertType
llvm::Type * ConvertType(QualType T)
Definition: CodeGenFunction.cpp:211
clang::CodeGen::CodeGenFunction::ConstantEmission::getValue
llvm::Constant * getValue() const
Definition: CodeGenFunction.h:3911
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:66
ComplexPairTy
CodeGenFunction::ComplexPairTy ComplexPairTy
Definition: CGExprComplex.cpp:31
clang::CompoundAssignOperator
CompoundAssignOperator - For compound assignments (e.g.
Definition: Expr.h:4050
clang::BinaryOperatorKind
BinaryOperatorKind
Definition: OperationKinds.h:25
clang::CodeGen::CodeGenFunction::MakeAddrLValue
LValue MakeAddrLValue(Address Addr, QualType T, AlignmentSource Source=AlignmentSource::Type)
Definition: CodeGenFunction.h:2456
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:1852
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:1472
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:4848
clang::CodeGen::CGFunctionInfo
CGFunctionInfo - Class to encapsulate the information about a function definition.
Definition: CGFunctionInfo.h:546
clang::CodeGen::CodeGenFunction::CGFPOptionsRAII
Definition: CodeGenFunction.h:680
clang::CodeGen::RValue::getComplex
static RValue getComplex(llvm::Value *V1, llvm::Value *V2)
Definition: CGValue.h:93
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:1139
clang::CodeGen::CodeGenFunction::CGM
CodeGenModule & CGM
Definition: CodeGenFunction.h:266
clang::AbstractConditionalOperator::getCond
Expr * getCond() const
Definition: Expr.h:4281
clang::FunctionProtoType::ExtProtoInfo
Extra information about a function prototype.
Definition: Type.h:3968
clang::UnaryOperator::getSubExpr
Expr * getSubExpr() const
Definition: Expr.h:2204
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:4802
clang
Definition: CalledOnceCheck.h:17
clang::CodeGen::RValue::get
static RValue get(llvm::Value *V)
Definition: CGValue.h:86
clang::interp::GE
bool GE(InterpState &S, CodePtr OpPC)
Definition: Interp.h:254
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:615
clang::Stmt
Stmt - This represents one statement.
Definition: Stmt.h:69
clang::EST_BasicNoexcept
@ EST_BasicNoexcept
noexcept
Definition: ExceptionSpecificationType.h:26
clang::BinaryOperator::getRHS
Expr * getRHS() const
Definition: Expr.h:3854
clang::GenericSelectionExpr
Represents a C11 generic selection.
Definition: Expr.h:5623
clang::CXXScalarValueInitExpr
An expression "T()" which creates a value-initialized rvalue of type T, which is a non-class type.
Definition: ExprCXX.h:2093
clang::CodeGen::CodeGenFunction::ConstantEmission::getReferenceLValue
LValue getReferenceLValue(CodeGenFunction &CGF, Expr *refExpr) const
Definition: CodeGenFunction.h:3905
clang::Expr::getType
QualType getType() const
Definition: Expr.h:141
clang::CodeGen::RValue::getScalarVal
llvm::Value * getScalarVal() const
getScalarVal() - Return the Value* of this scalar value.
Definition: CGValue.h:59
clang::CodeGen::TBAAAccessInfo::getMayAliasInfo
static TBAAAccessInfo getMayAliasInfo()
Definition: CodeGenTBAA.h:63
clang::ImplicitCastExpr
ImplicitCastExpr - Allows us to explicitly represent implicit type conversions, which have no direct ...
Definition: Expr.h:3618
clang::VAArgExpr
Represents a call to the builtin function __builtin_va_arg.
Definition: Expr.h:4629
clang::CodeGen::ConstantEmitter
Definition: ConstantEmitter.h:23
clang::MemberExpr
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
Definition: Expr.h:3162
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:1273
clang::QualType::getTypePtr
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
Definition: Type.h:6425
clang::InitListExpr::getInit
const Expr * getInit(unsigned Init) const
Definition: Expr.h:4834
clang::AtomicType
Definition: Type.h:6243
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:2508
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:1318
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:2053
clang::CastExpr
CastExpr - Base class for type casts, including both implicit casts (ImplicitCastExpr) and explicit c...
Definition: Expr.h:3473
clang::CodeGen::CallArgList
CallArgList - Type for representing both the value and type of arguments in a call.
Definition: CGCall.h:264
clang::DeclRefExpr
A reference to a declared variable, function, enum, etc.
Definition: Expr.h:1217
clang::CallExpr
CallExpr - Represents a function call (C99 6.5.2.2, C++ [expr.call]).
Definition: Expr.h:2795
clang::CodeGen::CodeGenFunction::EmitBlock
void EmitBlock(llvm::BasicBlock *BB, bool IsFinished=false)
EmitBlock - Emit the given block.
Definition: CGStmt.cpp:529
clang::InitListExpr::getNumInits
unsigned getNumInits() const
Definition: Expr.h:4816
clang::ObjCIvarRefExpr
ObjCIvarRefExpr - A reference to an ObjC instance variable.
Definition: ExprObjC.h:548
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:1960
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:4816
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:549