Chris Lattner | 566b6ce | 2007-08-24 02:22:53 +0000 | [diff] [blame] | 1 | //===--- CGExprComplex.cpp - Emit LLVM Code for Complex Exprs -------------===// |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 0bc735f | 2007-12-29 19:59:25 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This contains code to emit Expr nodes with complex types as LLVM code. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "CodeGenFunction.h" |
| 15 | #include "CodeGenModule.h" |
Daniel Dunbar | de7fb84 | 2008-08-11 05:00:27 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTContext.h" |
| 17 | #include "clang/AST/StmtVisitor.h" |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 18 | #include "llvm/Constants.h" |
| 19 | #include "llvm/Function.h" |
Chris Lattner | 6b5d0bf | 2007-08-26 22:47:40 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/SmallString.h" |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 21 | using namespace clang; |
| 22 | using namespace CodeGen; |
| 23 | |
| 24 | //===----------------------------------------------------------------------===// |
Chris Lattner | 05ba49c | 2007-08-21 05:54:53 +0000 | [diff] [blame] | 25 | // Complex Expression Emitter |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 26 | //===----------------------------------------------------------------------===// |
| 27 | |
Chris Lattner | 58dee10 | 2007-08-21 16:57:55 +0000 | [diff] [blame] | 28 | typedef CodeGenFunction::ComplexPairTy ComplexPairTy; |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 29 | |
| 30 | namespace { |
Benjamin Kramer | 85b4521 | 2009-11-28 19:45:26 +0000 | [diff] [blame] | 31 | class ComplexExprEmitter |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 32 | : public StmtVisitor<ComplexExprEmitter, ComplexPairTy> { |
| 33 | CodeGenFunction &CGF; |
Daniel Dunbar | 45d196b | 2008-11-01 01:53:16 +0000 | [diff] [blame] | 34 | CGBuilderTy &Builder; |
Mike Stump | 7f79f9b | 2009-05-29 15:46:01 +0000 | [diff] [blame] | 35 | // True is we should ignore the value of a |
| 36 | bool IgnoreReal; |
| 37 | bool IgnoreImag; |
| 38 | // True if we should ignore the value of a=b |
| 39 | bool IgnoreRealAssign; |
| 40 | bool IgnoreImagAssign; |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 41 | public: |
Mike Stump | 7f79f9b | 2009-05-29 15:46:01 +0000 | [diff] [blame] | 42 | ComplexExprEmitter(CodeGenFunction &cgf, bool ir=false, bool ii=false, |
| 43 | bool irn=false, bool iin=false) |
| 44 | : CGF(cgf), Builder(CGF.Builder), IgnoreReal(ir), IgnoreImag(ii), |
| 45 | IgnoreRealAssign(irn), IgnoreImagAssign(iin) { |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 46 | } |
| 47 | |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 48 | |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 49 | //===--------------------------------------------------------------------===// |
| 50 | // Utilities |
| 51 | //===--------------------------------------------------------------------===// |
| 52 | |
Mike Stump | 7f79f9b | 2009-05-29 15:46:01 +0000 | [diff] [blame] | 53 | bool TestAndClearIgnoreReal() { |
| 54 | bool I = IgnoreReal; |
| 55 | IgnoreReal = false; |
| 56 | return I; |
| 57 | } |
| 58 | bool TestAndClearIgnoreImag() { |
| 59 | bool I = IgnoreImag; |
| 60 | IgnoreImag = false; |
| 61 | return I; |
| 62 | } |
| 63 | bool TestAndClearIgnoreRealAssign() { |
| 64 | bool I = IgnoreRealAssign; |
| 65 | IgnoreRealAssign = false; |
| 66 | return I; |
| 67 | } |
| 68 | bool TestAndClearIgnoreImagAssign() { |
| 69 | bool I = IgnoreImagAssign; |
| 70 | IgnoreImagAssign = false; |
| 71 | return I; |
| 72 | } |
| 73 | |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 74 | /// EmitLoadOfLValue - Given an expression with complex type that represents a |
| 75 | /// value l-value, this method emits the address of the l-value, then loads |
| 76 | /// and returns the result. |
Chris Lattner | 46d7d9f | 2007-08-21 17:28:34 +0000 | [diff] [blame] | 77 | ComplexPairTy EmitLoadOfLValue(const Expr *E) { |
Chris Lattner | 76e8033 | 2007-08-21 18:02:02 +0000 | [diff] [blame] | 78 | LValue LV = CGF.EmitLValue(E); |
Daniel Dunbar | 42f963d | 2009-06-10 04:38:50 +0000 | [diff] [blame] | 79 | if (LV.isSimple()) |
| 80 | return EmitLoadOfComplex(LV.getAddress(), LV.isVolatileQualified()); |
| 81 | |
| 82 | if (LV.isPropertyRef()) |
| 83 | return CGF.EmitObjCPropertyGet(LV.getPropertyRefExpr()).getComplexVal(); |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 84 | |
Daniel Dunbar | 42f963d | 2009-06-10 04:38:50 +0000 | [diff] [blame] | 85 | assert(LV.isKVCRef() && "Unknown LValue type!"); |
| 86 | return CGF.EmitObjCPropertyGet(LV.getKVCRefExpr()).getComplexVal(); |
Chris Lattner | 46d7d9f | 2007-08-21 17:28:34 +0000 | [diff] [blame] | 87 | } |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 88 | |
Chris Lattner | 46d7d9f | 2007-08-21 17:28:34 +0000 | [diff] [blame] | 89 | /// EmitLoadOfComplex - Given a pointer to a complex value, emit code to load |
| 90 | /// the real and imaginary pieces. |
Chris Lattner | 76e8033 | 2007-08-21 18:02:02 +0000 | [diff] [blame] | 91 | ComplexPairTy EmitLoadOfComplex(llvm::Value *SrcPtr, bool isVolatile); |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 92 | |
Chris Lattner | 46d7d9f | 2007-08-21 17:28:34 +0000 | [diff] [blame] | 93 | /// EmitStoreOfComplex - Store the specified real/imag parts into the |
| 94 | /// specified value pointer. |
Chris Lattner | 76e8033 | 2007-08-21 18:02:02 +0000 | [diff] [blame] | 95 | void EmitStoreOfComplex(ComplexPairTy Val, llvm::Value *ResPtr, bool isVol); |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 96 | |
Chris Lattner | ab340c2 | 2007-08-26 22:09:01 +0000 | [diff] [blame] | 97 | /// EmitComplexToComplexCast - Emit a cast from complex value Val to DestType. |
| 98 | ComplexPairTy EmitComplexToComplexCast(ComplexPairTy Val, QualType SrcType, |
| 99 | QualType DestType); |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 100 | |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 101 | //===--------------------------------------------------------------------===// |
| 102 | // Visitor Methods |
| 103 | //===--------------------------------------------------------------------===// |
Chris Lattner | 776c649 | 2007-08-21 18:51:13 +0000 | [diff] [blame] | 104 | |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 105 | ComplexPairTy VisitStmt(Stmt *S) { |
Ted Kremenek | 7a9d49f | 2007-12-11 21:27:55 +0000 | [diff] [blame] | 106 | S->dump(CGF.getContext().getSourceManager()); |
Chris Lattner | 776c649 | 2007-08-21 18:51:13 +0000 | [diff] [blame] | 107 | assert(0 && "Stmt can't have complex result type!"); |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 108 | return ComplexPairTy(); |
| 109 | } |
Chris Lattner | 776c649 | 2007-08-21 18:51:13 +0000 | [diff] [blame] | 110 | ComplexPairTy VisitExpr(Expr *S); |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 111 | ComplexPairTy VisitParenExpr(ParenExpr *PE) { return Visit(PE->getSubExpr());} |
Chris Lattner | d272ff0 | 2007-08-26 05:57:57 +0000 | [diff] [blame] | 112 | ComplexPairTy VisitImaginaryLiteral(const ImaginaryLiteral *IL); |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 113 | |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 114 | // l-values. |
Chris Lattner | d272ff0 | 2007-08-26 05:57:57 +0000 | [diff] [blame] | 115 | ComplexPairTy VisitDeclRefExpr(const Expr *E) { return EmitLoadOfLValue(E); } |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 116 | ComplexPairTy VisitObjCIvarRefExpr(ObjCIvarRefExpr *E) { |
Daniel Dunbar | 42f963d | 2009-06-10 04:38:50 +0000 | [diff] [blame] | 117 | return EmitLoadOfLValue(E); |
| 118 | } |
| 119 | ComplexPairTy VisitObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { |
| 120 | return EmitLoadOfLValue(E); |
| 121 | } |
Fariborz Jahanian | 09105f5 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 122 | ComplexPairTy VisitObjCImplicitSetterGetterRefExpr( |
| 123 | ObjCImplicitSetterGetterRefExpr *E) { |
Daniel Dunbar | 42f963d | 2009-06-10 04:38:50 +0000 | [diff] [blame] | 124 | return EmitLoadOfLValue(E); |
| 125 | } |
| 126 | ComplexPairTy VisitObjCMessageExpr(ObjCMessageExpr *E) { |
| 127 | return CGF.EmitObjCMessageExpr(E).getComplexVal(); |
| 128 | } |
Chris Lattner | 8bcd723 | 2007-08-21 18:03:58 +0000 | [diff] [blame] | 129 | ComplexPairTy VisitArraySubscriptExpr(Expr *E) { return EmitLoadOfLValue(E); } |
Chris Lattner | d272ff0 | 2007-08-26 05:57:57 +0000 | [diff] [blame] | 130 | ComplexPairTy VisitMemberExpr(const Expr *E) { return EmitLoadOfLValue(E); } |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 131 | |
Chris Lattner | e73e8e2 | 2007-08-21 22:33:41 +0000 | [diff] [blame] | 132 | // FIXME: CompoundLiteralExpr |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 133 | |
Chris Lattner | d272ff0 | 2007-08-26 05:57:57 +0000 | [diff] [blame] | 134 | ComplexPairTy EmitCast(Expr *Op, QualType DestTy); |
| 135 | ComplexPairTy VisitImplicitCastExpr(ImplicitCastExpr *E) { |
| 136 | // Unlike for scalars, we don't have to worry about function->ptr demotion |
| 137 | // here. |
| 138 | return EmitCast(E->getSubExpr(), E->getType()); |
| 139 | } |
| 140 | ComplexPairTy VisitCastExpr(CastExpr *E) { |
| 141 | return EmitCast(E->getSubExpr(), E->getType()); |
| 142 | } |
Chris Lattner | 419d25e | 2007-08-23 21:38:16 +0000 | [diff] [blame] | 143 | ComplexPairTy VisitCallExpr(const CallExpr *E); |
Chris Lattner | 7e20d09 | 2007-08-31 22:51:38 +0000 | [diff] [blame] | 144 | ComplexPairTy VisitStmtExpr(const StmtExpr *E); |
| 145 | |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 146 | // Operators. |
Chris Lattner | 3070f98 | 2007-08-21 22:25:29 +0000 | [diff] [blame] | 147 | ComplexPairTy VisitPrePostIncDec(const UnaryOperator *E, |
Chris Lattner | dd36d32 | 2010-01-09 21:40:03 +0000 | [diff] [blame] | 148 | bool isInc, bool isPre) { |
| 149 | LValue LV = CGF.EmitLValue(E->getSubExpr()); |
| 150 | return CGF.EmitComplexPrePostIncDec(E, LV, isInc, isPre); |
| 151 | } |
Chris Lattner | 3070f98 | 2007-08-21 22:25:29 +0000 | [diff] [blame] | 152 | ComplexPairTy VisitUnaryPostDec(const UnaryOperator *E) { |
| 153 | return VisitPrePostIncDec(E, false, false); |
| 154 | } |
| 155 | ComplexPairTy VisitUnaryPostInc(const UnaryOperator *E) { |
| 156 | return VisitPrePostIncDec(E, true, false); |
| 157 | } |
| 158 | ComplexPairTy VisitUnaryPreDec(const UnaryOperator *E) { |
| 159 | return VisitPrePostIncDec(E, false, true); |
| 160 | } |
| 161 | ComplexPairTy VisitUnaryPreInc(const UnaryOperator *E) { |
| 162 | return VisitPrePostIncDec(E, true, true); |
| 163 | } |
| 164 | ComplexPairTy VisitUnaryDeref(const Expr *E) { return EmitLoadOfLValue(E); } |
Chris Lattner | fa2b9c9 | 2007-08-21 20:08:23 +0000 | [diff] [blame] | 165 | ComplexPairTy VisitUnaryPlus (const UnaryOperator *E) { |
Mike Stump | 7f79f9b | 2009-05-29 15:46:01 +0000 | [diff] [blame] | 166 | TestAndClearIgnoreReal(); |
| 167 | TestAndClearIgnoreImag(); |
| 168 | TestAndClearIgnoreRealAssign(); |
| 169 | TestAndClearIgnoreImagAssign(); |
Chris Lattner | fa2b9c9 | 2007-08-21 20:08:23 +0000 | [diff] [blame] | 170 | return Visit(E->getSubExpr()); |
| 171 | } |
| 172 | ComplexPairTy VisitUnaryMinus (const UnaryOperator *E); |
Chris Lattner | e98a11c | 2007-08-21 20:41:44 +0000 | [diff] [blame] | 173 | ComplexPairTy VisitUnaryNot (const UnaryOperator *E); |
Sebastian Redl | 0518999 | 2008-11-11 17:56:53 +0000 | [diff] [blame] | 174 | // LNot,Real,Imag never return complex. |
Chris Lattner | e98a11c | 2007-08-21 20:41:44 +0000 | [diff] [blame] | 175 | ComplexPairTy VisitUnaryExtension(const UnaryOperator *E) { |
| 176 | return Visit(E->getSubExpr()); |
| 177 | } |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 178 | ComplexPairTy VisitCXXDefaultArgExpr(CXXDefaultArgExpr *DAE) { |
| 179 | return Visit(DAE->getExpr()); |
| 180 | } |
Anders Carlsson | 4b76b4f | 2009-05-31 00:12:05 +0000 | [diff] [blame] | 181 | ComplexPairTy VisitCXXExprWithTemporaries(CXXExprWithTemporaries *E) { |
| 182 | return CGF.EmitCXXExprWithTemporaries(E).getComplexVal(); |
| 183 | } |
Argyrios Kyrtzidis | 7267f78 | 2008-08-23 19:35:47 +0000 | [diff] [blame] | 184 | ComplexPairTy VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) { |
| 185 | assert(E->getType()->isAnyComplexType() && "Expected complex type!"); |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 186 | QualType Elem = E->getType()->getAs<ComplexType>()->getElementType(); |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 187 | llvm::Constant *Null = llvm::Constant::getNullValue(CGF.ConvertType(Elem)); |
Argyrios Kyrtzidis | 7267f78 | 2008-08-23 19:35:47 +0000 | [diff] [blame] | 188 | return ComplexPairTy(Null, Null); |
| 189 | } |
Douglas Gregor | 3498bdb | 2009-01-29 17:44:32 +0000 | [diff] [blame] | 190 | ComplexPairTy VisitImplicitValueInitExpr(ImplicitValueInitExpr *E) { |
| 191 | assert(E->getType()->isAnyComplexType() && "Expected complex type!"); |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 192 | QualType Elem = E->getType()->getAs<ComplexType>()->getElementType(); |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 193 | llvm::Constant *Null = |
Owen Anderson | c9c88b4 | 2009-07-31 20:28:54 +0000 | [diff] [blame] | 194 | llvm::Constant::getNullValue(CGF.ConvertType(Elem)); |
Douglas Gregor | 3498bdb | 2009-01-29 17:44:32 +0000 | [diff] [blame] | 195 | return ComplexPairTy(Null, Null); |
| 196 | } |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 197 | |
Chris Lattner | ab340c2 | 2007-08-26 22:09:01 +0000 | [diff] [blame] | 198 | struct BinOpInfo { |
| 199 | ComplexPairTy LHS; |
| 200 | ComplexPairTy RHS; |
| 201 | QualType Ty; // Computation Type. |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 202 | }; |
| 203 | |
Chris Lattner | ab340c2 | 2007-08-26 22:09:01 +0000 | [diff] [blame] | 204 | BinOpInfo EmitBinOps(const BinaryOperator *E); |
| 205 | ComplexPairTy EmitCompoundAssign(const CompoundAssignOperator *E, |
| 206 | ComplexPairTy (ComplexExprEmitter::*Func) |
| 207 | (const BinOpInfo &)); |
| 208 | |
| 209 | ComplexPairTy EmitBinAdd(const BinOpInfo &Op); |
| 210 | ComplexPairTy EmitBinSub(const BinOpInfo &Op); |
| 211 | ComplexPairTy EmitBinMul(const BinOpInfo &Op); |
| 212 | ComplexPairTy EmitBinDiv(const BinOpInfo &Op); |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 213 | |
Chris Lattner | ab340c2 | 2007-08-26 22:09:01 +0000 | [diff] [blame] | 214 | ComplexPairTy VisitBinMul(const BinaryOperator *E) { |
| 215 | return EmitBinMul(EmitBinOps(E)); |
| 216 | } |
| 217 | ComplexPairTy VisitBinAdd(const BinaryOperator *E) { |
| 218 | return EmitBinAdd(EmitBinOps(E)); |
| 219 | } |
| 220 | ComplexPairTy VisitBinSub(const BinaryOperator *E) { |
| 221 | return EmitBinSub(EmitBinOps(E)); |
| 222 | } |
| 223 | ComplexPairTy VisitBinDiv(const BinaryOperator *E) { |
| 224 | return EmitBinDiv(EmitBinOps(E)); |
| 225 | } |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 226 | |
Chris Lattner | ab340c2 | 2007-08-26 22:09:01 +0000 | [diff] [blame] | 227 | // Compound assignments. |
| 228 | ComplexPairTy VisitBinAddAssign(const CompoundAssignOperator *E) { |
| 229 | return EmitCompoundAssign(E, &ComplexExprEmitter::EmitBinAdd); |
| 230 | } |
| 231 | ComplexPairTy VisitBinSubAssign(const CompoundAssignOperator *E) { |
| 232 | return EmitCompoundAssign(E, &ComplexExprEmitter::EmitBinSub); |
| 233 | } |
| 234 | ComplexPairTy VisitBinMulAssign(const CompoundAssignOperator *E) { |
| 235 | return EmitCompoundAssign(E, &ComplexExprEmitter::EmitBinMul); |
| 236 | } |
| 237 | ComplexPairTy VisitBinDivAssign(const CompoundAssignOperator *E) { |
| 238 | return EmitCompoundAssign(E, &ComplexExprEmitter::EmitBinDiv); |
| 239 | } |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 240 | |
Chris Lattner | 612c40c | 2007-08-26 21:27:07 +0000 | [diff] [blame] | 241 | // GCC rejects rem/and/or/xor for integer complex. |
Chris Lattner | 4034edb | 2007-08-21 17:12:50 +0000 | [diff] [blame] | 242 | // Logical and/or always return int, never complex. |
Chris Lattner | 58dee10 | 2007-08-21 16:57:55 +0000 | [diff] [blame] | 243 | |
| 244 | // No comparisons produce a complex result. |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 245 | ComplexPairTy VisitBinAssign (const BinaryOperator *E); |
Chris Lattner | 756a4d8 | 2007-08-21 17:15:50 +0000 | [diff] [blame] | 246 | ComplexPairTy VisitBinComma (const BinaryOperator *E); |
| 247 | |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 248 | |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 249 | ComplexPairTy VisitConditionalOperator(const ConditionalOperator *CO); |
Chris Lattner | d0b1203 | 2007-08-24 02:18:47 +0000 | [diff] [blame] | 250 | ComplexPairTy VisitChooseExpr(ChooseExpr *CE); |
Eli Friedman | c4777f1 | 2008-05-13 23:11:35 +0000 | [diff] [blame] | 251 | |
| 252 | ComplexPairTy VisitInitListExpr(InitListExpr *E); |
Daniel Dunbar | 4e484b8 | 2009-02-10 03:03:30 +0000 | [diff] [blame] | 253 | |
| 254 | ComplexPairTy VisitVAArgExpr(VAArgExpr *E); |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 255 | }; |
| 256 | } // end anonymous namespace. |
| 257 | |
| 258 | //===----------------------------------------------------------------------===// |
| 259 | // Utilities |
| 260 | //===----------------------------------------------------------------------===// |
| 261 | |
Chris Lattner | 46d7d9f | 2007-08-21 17:28:34 +0000 | [diff] [blame] | 262 | /// EmitLoadOfComplex - Given an RValue reference for a complex, emit code to |
| 263 | /// load the real and imaginary pieces, returning them as Real/Imag. |
Chris Lattner | 76e8033 | 2007-08-21 18:02:02 +0000 | [diff] [blame] | 264 | ComplexPairTy ComplexExprEmitter::EmitLoadOfComplex(llvm::Value *SrcPtr, |
| 265 | bool isVolatile) { |
Mike Stump | 7f79f9b | 2009-05-29 15:46:01 +0000 | [diff] [blame] | 266 | llvm::Value *Real=0, *Imag=0; |
Chris Lattner | 6b5d0bf | 2007-08-26 22:47:40 +0000 | [diff] [blame] | 267 | |
Mike Stump | 7f79f9b | 2009-05-29 15:46:01 +0000 | [diff] [blame] | 268 | if (!IgnoreReal) { |
Benjamin Kramer | 56a44f7 | 2009-11-29 19:51:45 +0000 | [diff] [blame] | 269 | llvm::Value *RealP = Builder.CreateStructGEP(SrcPtr, 0, |
| 270 | SrcPtr->getName() + ".realp"); |
| 271 | Real = Builder.CreateLoad(RealP, isVolatile, SrcPtr->getName() + ".real"); |
Mike Stump | 7f79f9b | 2009-05-29 15:46:01 +0000 | [diff] [blame] | 272 | } |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 273 | |
Mike Stump | 7f79f9b | 2009-05-29 15:46:01 +0000 | [diff] [blame] | 274 | if (!IgnoreImag) { |
Benjamin Kramer | 56a44f7 | 2009-11-29 19:51:45 +0000 | [diff] [blame] | 275 | llvm::Value *ImagP = Builder.CreateStructGEP(SrcPtr, 1, |
| 276 | SrcPtr->getName() + ".imagp"); |
| 277 | Imag = Builder.CreateLoad(ImagP, isVolatile, SrcPtr->getName() + ".imag"); |
Mike Stump | 7f79f9b | 2009-05-29 15:46:01 +0000 | [diff] [blame] | 278 | } |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 279 | return ComplexPairTy(Real, Imag); |
| 280 | } |
| 281 | |
Chris Lattner | 46d7d9f | 2007-08-21 17:28:34 +0000 | [diff] [blame] | 282 | /// EmitStoreOfComplex - Store the specified real/imag parts into the |
| 283 | /// specified value pointer. |
Chris Lattner | 76e8033 | 2007-08-21 18:02:02 +0000 | [diff] [blame] | 284 | void ComplexExprEmitter::EmitStoreOfComplex(ComplexPairTy Val, llvm::Value *Ptr, |
| 285 | bool isVolatile) { |
Chris Lattner | 36b6a0a | 2008-03-19 05:19:41 +0000 | [diff] [blame] | 286 | llvm::Value *RealPtr = Builder.CreateStructGEP(Ptr, 0, "real"); |
| 287 | llvm::Value *ImagPtr = Builder.CreateStructGEP(Ptr, 1, "imag"); |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 288 | |
Chris Lattner | 76e8033 | 2007-08-21 18:02:02 +0000 | [diff] [blame] | 289 | Builder.CreateStore(Val.first, RealPtr, isVolatile); |
| 290 | Builder.CreateStore(Val.second, ImagPtr, isVolatile); |
Chris Lattner | 46d7d9f | 2007-08-21 17:28:34 +0000 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | |
| 294 | |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 295 | //===----------------------------------------------------------------------===// |
| 296 | // Visitor Methods |
| 297 | //===----------------------------------------------------------------------===// |
| 298 | |
Chris Lattner | 776c649 | 2007-08-21 18:51:13 +0000 | [diff] [blame] | 299 | ComplexPairTy ComplexExprEmitter::VisitExpr(Expr *E) { |
Daniel Dunbar | 488e993 | 2008-08-16 00:56:44 +0000 | [diff] [blame] | 300 | CGF.ErrorUnsupported(E, "complex expression"); |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 301 | const llvm::Type *EltTy = |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 302 | CGF.ConvertType(E->getType()->getAs<ComplexType>()->getElementType()); |
Chris Lattner | 776c649 | 2007-08-21 18:51:13 +0000 | [diff] [blame] | 303 | llvm::Value *U = llvm::UndefValue::get(EltTy); |
| 304 | return ComplexPairTy(U, U); |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 305 | } |
| 306 | |
Chris Lattner | d272ff0 | 2007-08-26 05:57:57 +0000 | [diff] [blame] | 307 | ComplexPairTy ComplexExprEmitter:: |
| 308 | VisitImaginaryLiteral(const ImaginaryLiteral *IL) { |
Chris Lattner | db68f1b | 2007-08-26 03:51:12 +0000 | [diff] [blame] | 309 | llvm::Value *Imag = CGF.EmitScalarExpr(IL->getSubExpr()); |
Owen Anderson | 6924382 | 2009-07-13 04:10:07 +0000 | [diff] [blame] | 310 | return |
Owen Anderson | c9c88b4 | 2009-07-31 20:28:54 +0000 | [diff] [blame] | 311 | ComplexPairTy(llvm::Constant::getNullValue(Imag->getType()), Imag); |
Chris Lattner | db68f1b | 2007-08-26 03:51:12 +0000 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | |
Chris Lattner | 419d25e | 2007-08-23 21:38:16 +0000 | [diff] [blame] | 315 | ComplexPairTy ComplexExprEmitter::VisitCallExpr(const CallExpr *E) { |
Anders Carlsson | e9f2f45 | 2009-05-27 03:37:57 +0000 | [diff] [blame] | 316 | if (E->getCallReturnType()->isReferenceType()) |
| 317 | return EmitLoadOfLValue(E); |
| 318 | |
Chris Lattner | 9b65551 | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 319 | return CGF.EmitCallExpr(E).getComplexVal(); |
Chris Lattner | 419d25e | 2007-08-23 21:38:16 +0000 | [diff] [blame] | 320 | } |
| 321 | |
Chris Lattner | 7e20d09 | 2007-08-31 22:51:38 +0000 | [diff] [blame] | 322 | ComplexPairTy ComplexExprEmitter::VisitStmtExpr(const StmtExpr *E) { |
| 323 | return CGF.EmitCompoundStmt(*E->getSubStmt(), true).getComplexVal(); |
| 324 | } |
| 325 | |
Chris Lattner | ab340c2 | 2007-08-26 22:09:01 +0000 | [diff] [blame] | 326 | /// EmitComplexToComplexCast - Emit a cast from complex value Val to DestType. |
| 327 | ComplexPairTy ComplexExprEmitter::EmitComplexToComplexCast(ComplexPairTy Val, |
| 328 | QualType SrcType, |
| 329 | QualType DestType) { |
| 330 | // Get the src/dest element type. |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 331 | SrcType = SrcType->getAs<ComplexType>()->getElementType(); |
| 332 | DestType = DestType->getAs<ComplexType>()->getElementType(); |
Chris Lattner | d272ff0 | 2007-08-26 05:57:57 +0000 | [diff] [blame] | 333 | |
Daniel Dunbar | 56f0d16 | 2009-01-29 06:44:03 +0000 | [diff] [blame] | 334 | // C99 6.3.1.6: When a value of complex type is converted to another |
Daniel Dunbar | e12d8e3 | 2009-01-26 18:02:34 +0000 | [diff] [blame] | 335 | // complex type, both the real and imaginary parts follow the conversion |
Chris Lattner | ab340c2 | 2007-08-26 22:09:01 +0000 | [diff] [blame] | 336 | // rules for the corresponding real types. |
| 337 | Val.first = CGF.EmitScalarConversion(Val.first, SrcType, DestType); |
| 338 | Val.second = CGF.EmitScalarConversion(Val.second, SrcType, DestType); |
| 339 | return Val; |
| 340 | } |
| 341 | |
| 342 | ComplexPairTy ComplexExprEmitter::EmitCast(Expr *Op, QualType DestTy) { |
Chris Lattner | d272ff0 | 2007-08-26 05:57:57 +0000 | [diff] [blame] | 343 | // Two cases here: cast from (complex to complex) and (scalar to complex). |
Chris Lattner | 9b2dc28 | 2008-04-04 16:54:41 +0000 | [diff] [blame] | 344 | if (Op->getType()->isAnyComplexType()) |
Chris Lattner | ab340c2 | 2007-08-26 22:09:01 +0000 | [diff] [blame] | 345 | return EmitComplexToComplexCast(Visit(Op), Op->getType(), DestTy); |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 346 | |
Chris Lattner | d272ff0 | 2007-08-26 05:57:57 +0000 | [diff] [blame] | 347 | // C99 6.3.1.7: When a value of real type is converted to a complex type, the |
Eli Friedman | c110c54 | 2009-03-23 04:08:46 +0000 | [diff] [blame] | 348 | // real part of the complex result value is determined by the rules of |
Chris Lattner | d272ff0 | 2007-08-26 05:57:57 +0000 | [diff] [blame] | 349 | // conversion to the corresponding real type and the imaginary part of the |
| 350 | // complex result value is a positive zero or an unsigned zero. |
| 351 | llvm::Value *Elt = CGF.EmitScalarExpr(Op); |
| 352 | |
| 353 | // Convert the input element to the element type of the complex. |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 354 | DestTy = DestTy->getAs<ComplexType>()->getElementType(); |
Chris Lattner | 3707b25 | 2007-08-26 06:48:56 +0000 | [diff] [blame] | 355 | Elt = CGF.EmitScalarConversion(Elt, Op->getType(), DestTy); |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 356 | |
Chris Lattner | d272ff0 | 2007-08-26 05:57:57 +0000 | [diff] [blame] | 357 | // Return (realval, 0). |
Owen Anderson | c9c88b4 | 2009-07-31 20:28:54 +0000 | [diff] [blame] | 358 | return ComplexPairTy(Elt, llvm::Constant::getNullValue(Elt->getType())); |
Chris Lattner | d272ff0 | 2007-08-26 05:57:57 +0000 | [diff] [blame] | 359 | } |
| 360 | |
Chris Lattner | fa2b9c9 | 2007-08-21 20:08:23 +0000 | [diff] [blame] | 361 | ComplexPairTy ComplexExprEmitter::VisitUnaryMinus(const UnaryOperator *E) { |
Mike Stump | 7f79f9b | 2009-05-29 15:46:01 +0000 | [diff] [blame] | 362 | TestAndClearIgnoreReal(); |
| 363 | TestAndClearIgnoreImag(); |
| 364 | TestAndClearIgnoreRealAssign(); |
| 365 | TestAndClearIgnoreImagAssign(); |
Chris Lattner | fa2b9c9 | 2007-08-21 20:08:23 +0000 | [diff] [blame] | 366 | ComplexPairTy Op = Visit(E->getSubExpr()); |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 367 | |
Chris Lattner | 87415d2 | 2009-06-17 06:36:24 +0000 | [diff] [blame] | 368 | llvm::Value *ResR, *ResI; |
Duncan Sands | f177d9d | 2010-02-15 16:14:01 +0000 | [diff] [blame] | 369 | if (Op.first->getType()->isFloatingPointTy()) { |
Chris Lattner | 87415d2 | 2009-06-17 06:36:24 +0000 | [diff] [blame] | 370 | ResR = Builder.CreateFNeg(Op.first, "neg.r"); |
| 371 | ResI = Builder.CreateFNeg(Op.second, "neg.i"); |
| 372 | } else { |
| 373 | ResR = Builder.CreateNeg(Op.first, "neg.r"); |
| 374 | ResI = Builder.CreateNeg(Op.second, "neg.i"); |
| 375 | } |
Chris Lattner | fa2b9c9 | 2007-08-21 20:08:23 +0000 | [diff] [blame] | 376 | return ComplexPairTy(ResR, ResI); |
| 377 | } |
| 378 | |
Chris Lattner | e98a11c | 2007-08-21 20:41:44 +0000 | [diff] [blame] | 379 | ComplexPairTy ComplexExprEmitter::VisitUnaryNot(const UnaryOperator *E) { |
Mike Stump | 7f79f9b | 2009-05-29 15:46:01 +0000 | [diff] [blame] | 380 | TestAndClearIgnoreReal(); |
| 381 | TestAndClearIgnoreImag(); |
| 382 | TestAndClearIgnoreRealAssign(); |
| 383 | TestAndClearIgnoreImagAssign(); |
Chris Lattner | e98a11c | 2007-08-21 20:41:44 +0000 | [diff] [blame] | 384 | // ~(a+ib) = a + i*-b |
| 385 | ComplexPairTy Op = Visit(E->getSubExpr()); |
Chris Lattner | 87415d2 | 2009-06-17 06:36:24 +0000 | [diff] [blame] | 386 | llvm::Value *ResI; |
Duncan Sands | f177d9d | 2010-02-15 16:14:01 +0000 | [diff] [blame] | 387 | if (Op.second->getType()->isFloatingPointTy()) |
Chris Lattner | 87415d2 | 2009-06-17 06:36:24 +0000 | [diff] [blame] | 388 | ResI = Builder.CreateFNeg(Op.second, "conj.i"); |
| 389 | else |
| 390 | ResI = Builder.CreateNeg(Op.second, "conj.i"); |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 391 | |
Chris Lattner | e98a11c | 2007-08-21 20:41:44 +0000 | [diff] [blame] | 392 | return ComplexPairTy(Op.first, ResI); |
| 393 | } |
Chris Lattner | fa2b9c9 | 2007-08-21 20:08:23 +0000 | [diff] [blame] | 394 | |
Chris Lattner | ab340c2 | 2007-08-26 22:09:01 +0000 | [diff] [blame] | 395 | ComplexPairTy ComplexExprEmitter::EmitBinAdd(const BinOpInfo &Op) { |
Chris Lattner | 87415d2 | 2009-06-17 06:36:24 +0000 | [diff] [blame] | 396 | llvm::Value *ResR, *ResI; |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 397 | |
Duncan Sands | f177d9d | 2010-02-15 16:14:01 +0000 | [diff] [blame] | 398 | if (Op.LHS.first->getType()->isFloatingPointTy()) { |
Chris Lattner | 87415d2 | 2009-06-17 06:36:24 +0000 | [diff] [blame] | 399 | ResR = Builder.CreateFAdd(Op.LHS.first, Op.RHS.first, "add.r"); |
| 400 | ResI = Builder.CreateFAdd(Op.LHS.second, Op.RHS.second, "add.i"); |
| 401 | } else { |
| 402 | ResR = Builder.CreateAdd(Op.LHS.first, Op.RHS.first, "add.r"); |
| 403 | ResI = Builder.CreateAdd(Op.LHS.second, Op.RHS.second, "add.i"); |
| 404 | } |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 405 | return ComplexPairTy(ResR, ResI); |
| 406 | } |
| 407 | |
Chris Lattner | ab340c2 | 2007-08-26 22:09:01 +0000 | [diff] [blame] | 408 | ComplexPairTy ComplexExprEmitter::EmitBinSub(const BinOpInfo &Op) { |
Chris Lattner | 87415d2 | 2009-06-17 06:36:24 +0000 | [diff] [blame] | 409 | llvm::Value *ResR, *ResI; |
Duncan Sands | f177d9d | 2010-02-15 16:14:01 +0000 | [diff] [blame] | 410 | if (Op.LHS.first->getType()->isFloatingPointTy()) { |
Chris Lattner | 87415d2 | 2009-06-17 06:36:24 +0000 | [diff] [blame] | 411 | ResR = Builder.CreateFSub(Op.LHS.first, Op.RHS.first, "sub.r"); |
| 412 | ResI = Builder.CreateFSub(Op.LHS.second, Op.RHS.second, "sub.i"); |
| 413 | } else { |
| 414 | ResR = Builder.CreateSub(Op.LHS.first, Op.RHS.first, "sub.r"); |
| 415 | ResI = Builder.CreateSub(Op.LHS.second, Op.RHS.second, "sub.i"); |
| 416 | } |
Chris Lattner | 6bc1ade | 2007-08-23 23:46:33 +0000 | [diff] [blame] | 417 | return ComplexPairTy(ResR, ResI); |
| 418 | } |
| 419 | |
| 420 | |
Chris Lattner | ab340c2 | 2007-08-26 22:09:01 +0000 | [diff] [blame] | 421 | ComplexPairTy ComplexExprEmitter::EmitBinMul(const BinOpInfo &Op) { |
Chris Lattner | 87415d2 | 2009-06-17 06:36:24 +0000 | [diff] [blame] | 422 | using llvm::Value; |
| 423 | Value *ResR, *ResI; |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 424 | |
Duncan Sands | f177d9d | 2010-02-15 16:14:01 +0000 | [diff] [blame] | 425 | if (Op.LHS.first->getType()->isFloatingPointTy()) { |
Chris Lattner | 87415d2 | 2009-06-17 06:36:24 +0000 | [diff] [blame] | 426 | Value *ResRl = Builder.CreateFMul(Op.LHS.first, Op.RHS.first, "mul.rl"); |
| 427 | Value *ResRr = Builder.CreateFMul(Op.LHS.second, Op.RHS.second,"mul.rr"); |
| 428 | ResR = Builder.CreateFSub(ResRl, ResRr, "mul.r"); |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 429 | |
Chris Lattner | 87415d2 | 2009-06-17 06:36:24 +0000 | [diff] [blame] | 430 | Value *ResIl = Builder.CreateFMul(Op.LHS.second, Op.RHS.first, "mul.il"); |
| 431 | Value *ResIr = Builder.CreateFMul(Op.LHS.first, Op.RHS.second, "mul.ir"); |
| 432 | ResI = Builder.CreateFAdd(ResIl, ResIr, "mul.i"); |
| 433 | } else { |
| 434 | Value *ResRl = Builder.CreateMul(Op.LHS.first, Op.RHS.first, "mul.rl"); |
| 435 | Value *ResRr = Builder.CreateMul(Op.LHS.second, Op.RHS.second,"mul.rr"); |
| 436 | ResR = Builder.CreateSub(ResRl, ResRr, "mul.r"); |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 437 | |
Chris Lattner | 87415d2 | 2009-06-17 06:36:24 +0000 | [diff] [blame] | 438 | Value *ResIl = Builder.CreateMul(Op.LHS.second, Op.RHS.first, "mul.il"); |
| 439 | Value *ResIr = Builder.CreateMul(Op.LHS.first, Op.RHS.second, "mul.ir"); |
| 440 | ResI = Builder.CreateAdd(ResIl, ResIr, "mul.i"); |
| 441 | } |
Chris Lattner | 2823c19 | 2007-08-21 16:34:16 +0000 | [diff] [blame] | 442 | return ComplexPairTy(ResR, ResI); |
| 443 | } |
| 444 | |
Chris Lattner | ab340c2 | 2007-08-26 22:09:01 +0000 | [diff] [blame] | 445 | ComplexPairTy ComplexExprEmitter::EmitBinDiv(const BinOpInfo &Op) { |
| 446 | llvm::Value *LHSr = Op.LHS.first, *LHSi = Op.LHS.second; |
| 447 | llvm::Value *RHSr = Op.RHS.first, *RHSi = Op.RHS.second; |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 448 | |
Chris Lattner | 3219c5d | 2007-08-26 21:24:19 +0000 | [diff] [blame] | 449 | |
| 450 | llvm::Value *DSTr, *DSTi; |
Duncan Sands | f177d9d | 2010-02-15 16:14:01 +0000 | [diff] [blame] | 451 | if (Op.LHS.first->getType()->isFloatingPointTy()) { |
Chris Lattner | 87415d2 | 2009-06-17 06:36:24 +0000 | [diff] [blame] | 452 | // (a+ib) / (c+id) = ((ac+bd)/(cc+dd)) + i((bc-ad)/(cc+dd)) |
| 453 | llvm::Value *Tmp1 = Builder.CreateFMul(LHSr, RHSr, "tmp"); // a*c |
| 454 | llvm::Value *Tmp2 = Builder.CreateFMul(LHSi, RHSi, "tmp"); // b*d |
| 455 | llvm::Value *Tmp3 = Builder.CreateFAdd(Tmp1, Tmp2, "tmp"); // ac+bd |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 456 | |
Chris Lattner | 87415d2 | 2009-06-17 06:36:24 +0000 | [diff] [blame] | 457 | llvm::Value *Tmp4 = Builder.CreateFMul(RHSr, RHSr, "tmp"); // c*c |
| 458 | llvm::Value *Tmp5 = Builder.CreateFMul(RHSi, RHSi, "tmp"); // d*d |
| 459 | llvm::Value *Tmp6 = Builder.CreateFAdd(Tmp4, Tmp5, "tmp"); // cc+dd |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 460 | |
Chris Lattner | 87415d2 | 2009-06-17 06:36:24 +0000 | [diff] [blame] | 461 | llvm::Value *Tmp7 = Builder.CreateFMul(LHSi, RHSr, "tmp"); // b*c |
| 462 | llvm::Value *Tmp8 = Builder.CreateFMul(LHSr, RHSi, "tmp"); // a*d |
| 463 | llvm::Value *Tmp9 = Builder.CreateFSub(Tmp7, Tmp8, "tmp"); // bc-ad |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 464 | |
Chris Lattner | 3219c5d | 2007-08-26 21:24:19 +0000 | [diff] [blame] | 465 | DSTr = Builder.CreateFDiv(Tmp3, Tmp6, "tmp"); |
| 466 | DSTi = Builder.CreateFDiv(Tmp9, Tmp6, "tmp"); |
| 467 | } else { |
Chris Lattner | 87415d2 | 2009-06-17 06:36:24 +0000 | [diff] [blame] | 468 | // (a+ib) / (c+id) = ((ac+bd)/(cc+dd)) + i((bc-ad)/(cc+dd)) |
| 469 | llvm::Value *Tmp1 = Builder.CreateMul(LHSr, RHSr, "tmp"); // a*c |
| 470 | llvm::Value *Tmp2 = Builder.CreateMul(LHSi, RHSi, "tmp"); // b*d |
| 471 | llvm::Value *Tmp3 = Builder.CreateAdd(Tmp1, Tmp2, "tmp"); // ac+bd |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 472 | |
Chris Lattner | 87415d2 | 2009-06-17 06:36:24 +0000 | [diff] [blame] | 473 | llvm::Value *Tmp4 = Builder.CreateMul(RHSr, RHSr, "tmp"); // c*c |
| 474 | llvm::Value *Tmp5 = Builder.CreateMul(RHSi, RHSi, "tmp"); // d*d |
| 475 | llvm::Value *Tmp6 = Builder.CreateAdd(Tmp4, Tmp5, "tmp"); // cc+dd |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 476 | |
Chris Lattner | 87415d2 | 2009-06-17 06:36:24 +0000 | [diff] [blame] | 477 | llvm::Value *Tmp7 = Builder.CreateMul(LHSi, RHSr, "tmp"); // b*c |
| 478 | llvm::Value *Tmp8 = Builder.CreateMul(LHSr, RHSi, "tmp"); // a*d |
| 479 | llvm::Value *Tmp9 = Builder.CreateSub(Tmp7, Tmp8, "tmp"); // bc-ad |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 480 | |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 481 | if (Op.Ty->getAs<ComplexType>()->getElementType()->isUnsignedIntegerType()) { |
Chris Lattner | 3219c5d | 2007-08-26 21:24:19 +0000 | [diff] [blame] | 482 | DSTr = Builder.CreateUDiv(Tmp3, Tmp6, "tmp"); |
| 483 | DSTi = Builder.CreateUDiv(Tmp9, Tmp6, "tmp"); |
| 484 | } else { |
| 485 | DSTr = Builder.CreateSDiv(Tmp3, Tmp6, "tmp"); |
| 486 | DSTi = Builder.CreateSDiv(Tmp9, Tmp6, "tmp"); |
| 487 | } |
| 488 | } |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 489 | |
Chris Lattner | 3219c5d | 2007-08-26 21:24:19 +0000 | [diff] [blame] | 490 | return ComplexPairTy(DSTr, DSTi); |
| 491 | } |
| 492 | |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 493 | ComplexExprEmitter::BinOpInfo |
Chris Lattner | ab340c2 | 2007-08-26 22:09:01 +0000 | [diff] [blame] | 494 | ComplexExprEmitter::EmitBinOps(const BinaryOperator *E) { |
Mike Stump | 7f79f9b | 2009-05-29 15:46:01 +0000 | [diff] [blame] | 495 | TestAndClearIgnoreReal(); |
| 496 | TestAndClearIgnoreImag(); |
| 497 | TestAndClearIgnoreRealAssign(); |
| 498 | TestAndClearIgnoreImagAssign(); |
Chris Lattner | ab340c2 | 2007-08-26 22:09:01 +0000 | [diff] [blame] | 499 | BinOpInfo Ops; |
| 500 | Ops.LHS = Visit(E->getLHS()); |
| 501 | Ops.RHS = Visit(E->getRHS()); |
| 502 | Ops.Ty = E->getType(); |
| 503 | return Ops; |
| 504 | } |
| 505 | |
| 506 | |
| 507 | // Compound assignments. |
| 508 | ComplexPairTy ComplexExprEmitter:: |
| 509 | EmitCompoundAssign(const CompoundAssignOperator *E, |
| 510 | ComplexPairTy (ComplexExprEmitter::*Func)(const BinOpInfo&)){ |
Mike Stump | 7f79f9b | 2009-05-29 15:46:01 +0000 | [diff] [blame] | 511 | TestAndClearIgnoreReal(); |
| 512 | TestAndClearIgnoreImag(); |
| 513 | bool ignreal = TestAndClearIgnoreRealAssign(); |
| 514 | bool ignimag = TestAndClearIgnoreImagAssign(); |
Chris Lattner | ab340c2 | 2007-08-26 22:09:01 +0000 | [diff] [blame] | 515 | QualType LHSTy = E->getLHS()->getType(), RHSTy = E->getRHS()->getType(); |
Chris Lattner | ab340c2 | 2007-08-26 22:09:01 +0000 | [diff] [blame] | 516 | |
| 517 | BinOpInfo OpInfo; |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 518 | |
Mike Stump | 7f79f9b | 2009-05-29 15:46:01 +0000 | [diff] [blame] | 519 | // Load the RHS and LHS operands. |
| 520 | // __block variables need to have the rhs evaluated first, plus this should |
| 521 | // improve codegen a little. It is possible for the RHS to be complex or |
| 522 | // scalar. |
Eli Friedman | ab3a852 | 2009-03-28 01:22:36 +0000 | [diff] [blame] | 523 | OpInfo.Ty = E->getComputationResultType(); |
Chris Lattner | ab340c2 | 2007-08-26 22:09:01 +0000 | [diff] [blame] | 524 | OpInfo.RHS = EmitCast(E->getRHS(), OpInfo.Ty); |
Fariborz Jahanian | dfb1eb2 | 2010-03-23 18:08:50 +0000 | [diff] [blame] | 525 | |
Daniel Dunbar | 120bc77 | 2010-06-29 22:44:21 +0000 | [diff] [blame^] | 526 | LValue LHS = CGF.EmitLValue(E->getLHS()); |
Mike Stump | 7f79f9b | 2009-05-29 15:46:01 +0000 | [diff] [blame] | 527 | // We know the LHS is a complex lvalue. |
Fariborz Jahanian | dfb1eb2 | 2010-03-23 18:08:50 +0000 | [diff] [blame] | 528 | ComplexPairTy LHSComplexPair; |
Daniel Dunbar | 120bc77 | 2010-06-29 22:44:21 +0000 | [diff] [blame^] | 529 | if (LHS.isPropertyRef()) |
| 530 | LHSComplexPair = |
| 531 | CGF.EmitObjCPropertyGet(LHS.getPropertyRefExpr()).getComplexVal(); |
| 532 | else if (LHS.isKVCRef()) |
| 533 | LHSComplexPair = |
| 534 | CGF.EmitObjCPropertyGet(LHS.getKVCRefExpr()).getComplexVal(); |
Fariborz Jahanian | dfb1eb2 | 2010-03-23 18:08:50 +0000 | [diff] [blame] | 535 | else |
Daniel Dunbar | 120bc77 | 2010-06-29 22:44:21 +0000 | [diff] [blame^] | 536 | LHSComplexPair = EmitLoadOfComplex(LHS.getAddress(), |
| 537 | LHS.isVolatileQualified()); |
Fariborz Jahanian | dfb1eb2 | 2010-03-23 18:08:50 +0000 | [diff] [blame] | 538 | |
Daniel Dunbar | 120bc77 | 2010-06-29 22:44:21 +0000 | [diff] [blame^] | 539 | OpInfo.LHS = EmitComplexToComplexCast(LHSComplexPair, LHSTy, OpInfo.Ty); |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 540 | |
Chris Lattner | ab340c2 | 2007-08-26 22:09:01 +0000 | [diff] [blame] | 541 | // Expand the binary operator. |
| 542 | ComplexPairTy Result = (this->*Func)(OpInfo); |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 543 | |
Chris Lattner | ab340c2 | 2007-08-26 22:09:01 +0000 | [diff] [blame] | 544 | // Truncate the result back to the LHS type. |
| 545 | Result = EmitComplexToComplexCast(Result, OpInfo.Ty, LHSTy); |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 546 | |
Chris Lattner | ab340c2 | 2007-08-26 22:09:01 +0000 | [diff] [blame] | 547 | // Store the result value into the LHS lvalue. |
Daniel Dunbar | 120bc77 | 2010-06-29 22:44:21 +0000 | [diff] [blame^] | 548 | if (LHS.isPropertyRef()) |
| 549 | CGF.EmitObjCPropertySet(LHS.getPropertyRefExpr(), |
Fariborz Jahanian | dfb1eb2 | 2010-03-23 18:08:50 +0000 | [diff] [blame] | 550 | RValue::getComplex(Result)); |
Daniel Dunbar | 120bc77 | 2010-06-29 22:44:21 +0000 | [diff] [blame^] | 551 | else if (LHS.isKVCRef()) |
| 552 | CGF.EmitObjCPropertySet(LHS.getKVCRefExpr(), RValue::getComplex(Result)); |
Fariborz Jahanian | dfb1eb2 | 2010-03-23 18:08:50 +0000 | [diff] [blame] | 553 | else |
Daniel Dunbar | 120bc77 | 2010-06-29 22:44:21 +0000 | [diff] [blame^] | 554 | EmitStoreOfComplex(Result, LHS.getAddress(), LHS.isVolatileQualified()); |
| 555 | |
| 556 | // Restore the Ignore* flags. |
Mike Stump | 7f79f9b | 2009-05-29 15:46:01 +0000 | [diff] [blame] | 557 | IgnoreReal = ignreal; |
| 558 | IgnoreImag = ignimag; |
| 559 | IgnoreRealAssign = ignreal; |
| 560 | IgnoreImagAssign = ignimag; |
Daniel Dunbar | 120bc77 | 2010-06-29 22:44:21 +0000 | [diff] [blame^] | 561 | |
| 562 | // Objective-C property assignment never reloads the value following a store. |
| 563 | if (LHS.isPropertyRef() || LHS.isKVCRef()) |
| 564 | return Result; |
| 565 | |
| 566 | // Otherwise, reload the value. |
| 567 | return EmitLoadOfComplex(LHS.getAddress(), LHS.isVolatileQualified()); |
Chris Lattner | ab340c2 | 2007-08-26 22:09:01 +0000 | [diff] [blame] | 568 | } |
Chris Lattner | 3219c5d | 2007-08-26 21:24:19 +0000 | [diff] [blame] | 569 | |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 570 | ComplexPairTy ComplexExprEmitter::VisitBinAssign(const BinaryOperator *E) { |
Mike Stump | 7f79f9b | 2009-05-29 15:46:01 +0000 | [diff] [blame] | 571 | TestAndClearIgnoreReal(); |
| 572 | TestAndClearIgnoreImag(); |
| 573 | bool ignreal = TestAndClearIgnoreRealAssign(); |
| 574 | bool ignimag = TestAndClearIgnoreImagAssign(); |
Chris Lattner | 9619662 | 2008-07-26 22:37:01 +0000 | [diff] [blame] | 575 | assert(CGF.getContext().getCanonicalType(E->getLHS()->getType()) == |
| 576 | CGF.getContext().getCanonicalType(E->getRHS()->getType()) && |
| 577 | "Invalid assignment"); |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 578 | // Emit the RHS. |
| 579 | ComplexPairTy Val = Visit(E->getRHS()); |
| 580 | |
| 581 | // Compute the address to store into. |
| 582 | LValue LHS = CGF.EmitLValue(E->getLHS()); |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 583 | |
Daniel Dunbar | 120bc77 | 2010-06-29 22:44:21 +0000 | [diff] [blame^] | 584 | // Store the result value into the LHS lvalue. |
Daniel Dunbar | 42f963d | 2009-06-10 04:38:50 +0000 | [diff] [blame] | 585 | if (LHS.isPropertyRef()) |
| 586 | CGF.EmitObjCPropertySet(LHS.getPropertyRefExpr(), RValue::getComplex(Val)); |
Daniel Dunbar | 120bc77 | 2010-06-29 22:44:21 +0000 | [diff] [blame^] | 587 | else if (LHS.isKVCRef()) |
Daniel Dunbar | 42f963d | 2009-06-10 04:38:50 +0000 | [diff] [blame] | 588 | CGF.EmitObjCPropertySet(LHS.getKVCRefExpr(), RValue::getComplex(Val)); |
Daniel Dunbar | 120bc77 | 2010-06-29 22:44:21 +0000 | [diff] [blame^] | 589 | else |
| 590 | EmitStoreOfComplex(Val, LHS.getAddress(), LHS.isVolatileQualified()); |
Daniel Dunbar | 42f963d | 2009-06-10 04:38:50 +0000 | [diff] [blame] | 591 | |
Daniel Dunbar | 120bc77 | 2010-06-29 22:44:21 +0000 | [diff] [blame^] | 592 | // Restore the Ignore* flags. |
Mike Stump | 7f79f9b | 2009-05-29 15:46:01 +0000 | [diff] [blame] | 593 | IgnoreReal = ignreal; |
| 594 | IgnoreImag = ignimag; |
| 595 | IgnoreRealAssign = ignreal; |
| 596 | IgnoreImagAssign = ignimag; |
Daniel Dunbar | 120bc77 | 2010-06-29 22:44:21 +0000 | [diff] [blame^] | 597 | |
| 598 | // Objective-C property assignment never reloads the value following a store. |
| 599 | if (LHS.isPropertyRef() || LHS.isKVCRef()) |
| 600 | return Val; |
| 601 | |
| 602 | // Otherwise, reload the value. |
| 603 | return EmitLoadOfComplex(LHS.getAddress(), LHS.isVolatileQualified()); |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 604 | } |
| 605 | |
Chris Lattner | 756a4d8 | 2007-08-21 17:15:50 +0000 | [diff] [blame] | 606 | ComplexPairTy ComplexExprEmitter::VisitBinComma(const BinaryOperator *E) { |
| 607 | CGF.EmitStmt(E->getLHS()); |
Daniel Dunbar | a448fb2 | 2008-11-11 23:11:34 +0000 | [diff] [blame] | 608 | CGF.EnsureInsertPoint(); |
Chris Lattner | 756a4d8 | 2007-08-21 17:15:50 +0000 | [diff] [blame] | 609 | return Visit(E->getRHS()); |
| 610 | } |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 611 | |
| 612 | ComplexPairTy ComplexExprEmitter:: |
| 613 | VisitConditionalOperator(const ConditionalOperator *E) { |
Eli Friedman | 8e274bd | 2009-12-25 06:17:05 +0000 | [diff] [blame] | 614 | if (!E->getLHS()) { |
| 615 | CGF.ErrorUnsupported(E, "conditional operator with missing LHS"); |
| 616 | const llvm::Type *EltTy = |
| 617 | CGF.ConvertType(E->getType()->getAs<ComplexType>()->getElementType()); |
| 618 | llvm::Value *U = llvm::UndefValue::get(EltTy); |
| 619 | return ComplexPairTy(U, U); |
| 620 | } |
| 621 | |
Mike Stump | 7f79f9b | 2009-05-29 15:46:01 +0000 | [diff] [blame] | 622 | TestAndClearIgnoreReal(); |
| 623 | TestAndClearIgnoreImag(); |
| 624 | TestAndClearIgnoreRealAssign(); |
| 625 | TestAndClearIgnoreImagAssign(); |
Daniel Dunbar | 9615ecb | 2008-11-13 01:38:36 +0000 | [diff] [blame] | 626 | llvm::BasicBlock *LHSBlock = CGF.createBasicBlock("cond.true"); |
| 627 | llvm::BasicBlock *RHSBlock = CGF.createBasicBlock("cond.false"); |
| 628 | llvm::BasicBlock *ContBlock = CGF.createBasicBlock("cond.end"); |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 629 | |
Eli Friedman | 8e274bd | 2009-12-25 06:17:05 +0000 | [diff] [blame] | 630 | CGF.EmitBranchOnBoolExpr(E->getCond(), LHSBlock, RHSBlock); |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 631 | |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 632 | CGF.EmitBlock(LHSBlock); |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 633 | |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 634 | // Handle the GNU extension for missing LHS. |
Chris Lattner | 05ba49c | 2007-08-21 05:54:53 +0000 | [diff] [blame] | 635 | assert(E->getLHS() && "Must have LHS for complex value"); |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 636 | |
| 637 | ComplexPairTy LHS = Visit(E->getLHS()); |
Chris Lattner | 5083a53 | 2007-08-21 17:39:38 +0000 | [diff] [blame] | 638 | LHSBlock = Builder.GetInsertBlock(); |
Daniel Dunbar | d57a871 | 2008-11-11 09:41:28 +0000 | [diff] [blame] | 639 | CGF.EmitBranch(ContBlock); |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 640 | |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 641 | CGF.EmitBlock(RHSBlock); |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 642 | |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 643 | ComplexPairTy RHS = Visit(E->getRHS()); |
Chris Lattner | 5083a53 | 2007-08-21 17:39:38 +0000 | [diff] [blame] | 644 | RHSBlock = Builder.GetInsertBlock(); |
Daniel Dunbar | d57a871 | 2008-11-11 09:41:28 +0000 | [diff] [blame] | 645 | CGF.EmitBranch(ContBlock); |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 646 | |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 647 | CGF.EmitBlock(ContBlock); |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 648 | |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 649 | // Create a PHI node for the real part. |
Chris Lattner | 5083a53 | 2007-08-21 17:39:38 +0000 | [diff] [blame] | 650 | llvm::PHINode *RealPN = Builder.CreatePHI(LHS.first->getType(), "cond.r"); |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 651 | RealPN->reserveOperandSpace(2); |
| 652 | RealPN->addIncoming(LHS.first, LHSBlock); |
| 653 | RealPN->addIncoming(RHS.first, RHSBlock); |
| 654 | |
| 655 | // Create a PHI node for the imaginary part. |
Chris Lattner | 5083a53 | 2007-08-21 17:39:38 +0000 | [diff] [blame] | 656 | llvm::PHINode *ImagPN = Builder.CreatePHI(LHS.first->getType(), "cond.i"); |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 657 | ImagPN->reserveOperandSpace(2); |
| 658 | ImagPN->addIncoming(LHS.second, LHSBlock); |
| 659 | ImagPN->addIncoming(RHS.second, RHSBlock); |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 660 | |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 661 | return ComplexPairTy(RealPN, ImagPN); |
| 662 | } |
| 663 | |
Chris Lattner | d0b1203 | 2007-08-24 02:18:47 +0000 | [diff] [blame] | 664 | ComplexPairTy ComplexExprEmitter::VisitChooseExpr(ChooseExpr *E) { |
Eli Friedman | 7976932 | 2009-03-04 05:52:32 +0000 | [diff] [blame] | 665 | return Visit(E->getChosenSubExpr(CGF.getContext())); |
Chris Lattner | d0b1203 | 2007-08-24 02:18:47 +0000 | [diff] [blame] | 666 | } |
| 667 | |
Eli Friedman | c4777f1 | 2008-05-13 23:11:35 +0000 | [diff] [blame] | 668 | ComplexPairTy ComplexExprEmitter::VisitInitListExpr(InitListExpr *E) { |
Mike Stump | 7f79f9b | 2009-05-29 15:46:01 +0000 | [diff] [blame] | 669 | bool Ignore = TestAndClearIgnoreReal(); |
| 670 | (void)Ignore; |
| 671 | assert (Ignore == false && "init list ignored"); |
| 672 | Ignore = TestAndClearIgnoreImag(); |
| 673 | (void)Ignore; |
| 674 | assert (Ignore == false && "init list ignored"); |
Eli Friedman | c4777f1 | 2008-05-13 23:11:35 +0000 | [diff] [blame] | 675 | if (E->getNumInits()) |
| 676 | return Visit(E->getInit(0)); |
| 677 | |
| 678 | // Empty init list intializes to null |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 679 | QualType Ty = E->getType()->getAs<ComplexType>()->getElementType(); |
Eli Friedman | c4777f1 | 2008-05-13 23:11:35 +0000 | [diff] [blame] | 680 | const llvm::Type* LTy = CGF.ConvertType(Ty); |
Owen Anderson | c9c88b4 | 2009-07-31 20:28:54 +0000 | [diff] [blame] | 681 | llvm::Value* zeroConstant = llvm::Constant::getNullValue(LTy); |
Eli Friedman | c4777f1 | 2008-05-13 23:11:35 +0000 | [diff] [blame] | 682 | return ComplexPairTy(zeroConstant, zeroConstant); |
| 683 | } |
| 684 | |
Daniel Dunbar | 4e484b8 | 2009-02-10 03:03:30 +0000 | [diff] [blame] | 685 | ComplexPairTy ComplexExprEmitter::VisitVAArgExpr(VAArgExpr *E) { |
Daniel Dunbar | 0785570 | 2009-02-11 22:25:55 +0000 | [diff] [blame] | 686 | llvm::Value *ArgValue = CGF.EmitVAListRef(E->getSubExpr()); |
Daniel Dunbar | 4e484b8 | 2009-02-10 03:03:30 +0000 | [diff] [blame] | 687 | llvm::Value *ArgPtr = CGF.EmitVAArg(ArgValue, E->getType()); |
| 688 | |
| 689 | if (!ArgPtr) { |
| 690 | CGF.ErrorUnsupported(E, "complex va_arg expression"); |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 691 | const llvm::Type *EltTy = |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 692 | CGF.ConvertType(E->getType()->getAs<ComplexType>()->getElementType()); |
Daniel Dunbar | 4e484b8 | 2009-02-10 03:03:30 +0000 | [diff] [blame] | 693 | llvm::Value *U = llvm::UndefValue::get(EltTy); |
| 694 | return ComplexPairTy(U, U); |
| 695 | } |
| 696 | |
| 697 | // FIXME Volatility. |
| 698 | return EmitLoadOfComplex(ArgPtr, false); |
| 699 | } |
| 700 | |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 701 | //===----------------------------------------------------------------------===// |
| 702 | // Entry Point into this File |
| 703 | //===----------------------------------------------------------------------===// |
| 704 | |
| 705 | /// EmitComplexExpr - Emit the computation of the specified expression of |
| 706 | /// complex type, ignoring the result. |
Mike Stump | 7f79f9b | 2009-05-29 15:46:01 +0000 | [diff] [blame] | 707 | ComplexPairTy CodeGenFunction::EmitComplexExpr(const Expr *E, bool IgnoreReal, |
| 708 | bool IgnoreImag, bool IgnoreRealAssign, bool IgnoreImagAssign) { |
Chris Lattner | 9b2dc28 | 2008-04-04 16:54:41 +0000 | [diff] [blame] | 709 | assert(E && E->getType()->isAnyComplexType() && |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 710 | "Invalid complex expression to emit"); |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 711 | |
Mike Stump | 7f79f9b | 2009-05-29 15:46:01 +0000 | [diff] [blame] | 712 | return ComplexExprEmitter(*this, IgnoreReal, IgnoreImag, IgnoreRealAssign, |
| 713 | IgnoreImagAssign) |
| 714 | .Visit(const_cast<Expr*>(E)); |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 715 | } |
| 716 | |
Chris Lattner | 23b1cdb | 2007-08-23 23:43:33 +0000 | [diff] [blame] | 717 | /// EmitComplexExprIntoAddr - Emit the computation of the specified expression |
| 718 | /// of complex type, storing into the specified Value*. |
| 719 | void CodeGenFunction::EmitComplexExprIntoAddr(const Expr *E, |
Chris Lattner | 190dbe2 | 2007-08-26 16:22:13 +0000 | [diff] [blame] | 720 | llvm::Value *DestAddr, |
| 721 | bool DestIsVolatile) { |
Chris Lattner | 9b2dc28 | 2008-04-04 16:54:41 +0000 | [diff] [blame] | 722 | assert(E && E->getType()->isAnyComplexType() && |
Chris Lattner | 23b1cdb | 2007-08-23 23:43:33 +0000 | [diff] [blame] | 723 | "Invalid complex expression to emit"); |
| 724 | ComplexExprEmitter Emitter(*this); |
| 725 | ComplexPairTy Val = Emitter.Visit(const_cast<Expr*>(E)); |
Chris Lattner | 190dbe2 | 2007-08-26 16:22:13 +0000 | [diff] [blame] | 726 | Emitter.EmitStoreOfComplex(Val, DestAddr, DestIsVolatile); |
Chris Lattner | 23b1cdb | 2007-08-23 23:43:33 +0000 | [diff] [blame] | 727 | } |
Chris Lattner | 9b65551 | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 728 | |
Daniel Dunbar | 7f8ea5c | 2008-08-30 05:35:15 +0000 | [diff] [blame] | 729 | /// StoreComplexToAddr - Store a complex number into the specified address. |
| 730 | void CodeGenFunction::StoreComplexToAddr(ComplexPairTy V, |
| 731 | llvm::Value *DestAddr, |
| 732 | bool DestIsVolatile) { |
| 733 | ComplexExprEmitter(*this).EmitStoreOfComplex(V, DestAddr, DestIsVolatile); |
| 734 | } |
| 735 | |
Chris Lattner | 9b65551 | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 736 | /// LoadComplexFromAddr - Load a complex number from the specified address. |
Mike Stump | db52dcd | 2009-09-09 13:00:44 +0000 | [diff] [blame] | 737 | ComplexPairTy CodeGenFunction::LoadComplexFromAddr(llvm::Value *SrcAddr, |
Chris Lattner | 9b65551 | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 738 | bool SrcIsVolatile) { |
| 739 | return ComplexExprEmitter(*this).EmitLoadOfComplex(SrcAddr, SrcIsVolatile); |
| 740 | } |