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 | #include "llvm/Support/Compiler.h" |
| 22 | using namespace clang; |
| 23 | using namespace CodeGen; |
| 24 | |
| 25 | //===----------------------------------------------------------------------===// |
Chris Lattner | 05ba49c | 2007-08-21 05:54:53 +0000 | [diff] [blame] | 26 | // Complex Expression Emitter |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 27 | //===----------------------------------------------------------------------===// |
| 28 | |
Chris Lattner | 58dee10 | 2007-08-21 16:57:55 +0000 | [diff] [blame] | 29 | typedef CodeGenFunction::ComplexPairTy ComplexPairTy; |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 30 | |
| 31 | namespace { |
| 32 | class VISIBILITY_HIDDEN ComplexExprEmitter |
| 33 | : public StmtVisitor<ComplexExprEmitter, ComplexPairTy> { |
| 34 | CodeGenFunction &CGF; |
Chris Lattner | 85e3568 | 2008-08-08 19:57:58 +0000 | [diff] [blame] | 35 | llvm::IRBuilder<> &Builder; |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 36 | public: |
Chris Lattner | 5083a53 | 2007-08-21 17:39:38 +0000 | [diff] [blame] | 37 | ComplexExprEmitter(CodeGenFunction &cgf) : CGF(cgf), Builder(CGF.Builder) { |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | |
| 41 | //===--------------------------------------------------------------------===// |
| 42 | // Utilities |
| 43 | //===--------------------------------------------------------------------===// |
| 44 | |
| 45 | /// EmitLoadOfLValue - Given an expression with complex type that represents a |
| 46 | /// value l-value, this method emits the address of the l-value, then loads |
| 47 | /// and returns the result. |
Chris Lattner | 46d7d9f | 2007-08-21 17:28:34 +0000 | [diff] [blame] | 48 | ComplexPairTy EmitLoadOfLValue(const Expr *E) { |
Chris Lattner | 76e8033 | 2007-08-21 18:02:02 +0000 | [diff] [blame] | 49 | LValue LV = CGF.EmitLValue(E); |
| 50 | // FIXME: Volatile |
| 51 | return EmitLoadOfComplex(LV.getAddress(), false); |
Chris Lattner | 46d7d9f | 2007-08-21 17:28:34 +0000 | [diff] [blame] | 52 | } |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 53 | |
Chris Lattner | 46d7d9f | 2007-08-21 17:28:34 +0000 | [diff] [blame] | 54 | /// EmitLoadOfComplex - Given a pointer to a complex value, emit code to load |
| 55 | /// the real and imaginary pieces. |
Chris Lattner | 76e8033 | 2007-08-21 18:02:02 +0000 | [diff] [blame] | 56 | ComplexPairTy EmitLoadOfComplex(llvm::Value *SrcPtr, bool isVolatile); |
Chris Lattner | 46d7d9f | 2007-08-21 17:28:34 +0000 | [diff] [blame] | 57 | |
| 58 | /// EmitStoreOfComplex - Store the specified real/imag parts into the |
| 59 | /// specified value pointer. |
Chris Lattner | 76e8033 | 2007-08-21 18:02:02 +0000 | [diff] [blame] | 60 | void EmitStoreOfComplex(ComplexPairTy Val, llvm::Value *ResPtr, bool isVol); |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 61 | |
Chris Lattner | ab340c2 | 2007-08-26 22:09:01 +0000 | [diff] [blame] | 62 | /// EmitComplexToComplexCast - Emit a cast from complex value Val to DestType. |
| 63 | ComplexPairTy EmitComplexToComplexCast(ComplexPairTy Val, QualType SrcType, |
| 64 | QualType DestType); |
| 65 | |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 66 | //===--------------------------------------------------------------------===// |
| 67 | // Visitor Methods |
| 68 | //===--------------------------------------------------------------------===// |
Chris Lattner | 776c649 | 2007-08-21 18:51:13 +0000 | [diff] [blame] | 69 | |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 70 | ComplexPairTy VisitStmt(Stmt *S) { |
Ted Kremenek | 7a9d49f | 2007-12-11 21:27:55 +0000 | [diff] [blame] | 71 | S->dump(CGF.getContext().getSourceManager()); |
Chris Lattner | 776c649 | 2007-08-21 18:51:13 +0000 | [diff] [blame] | 72 | assert(0 && "Stmt can't have complex result type!"); |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 73 | return ComplexPairTy(); |
| 74 | } |
Chris Lattner | 776c649 | 2007-08-21 18:51:13 +0000 | [diff] [blame] | 75 | ComplexPairTy VisitExpr(Expr *S); |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 76 | ComplexPairTy VisitParenExpr(ParenExpr *PE) { return Visit(PE->getSubExpr());} |
Chris Lattner | d272ff0 | 2007-08-26 05:57:57 +0000 | [diff] [blame] | 77 | ComplexPairTy VisitImaginaryLiteral(const ImaginaryLiteral *IL); |
Chris Lattner | db68f1b | 2007-08-26 03:51:12 +0000 | [diff] [blame] | 78 | |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 79 | // l-values. |
Chris Lattner | d272ff0 | 2007-08-26 05:57:57 +0000 | [diff] [blame] | 80 | ComplexPairTy VisitDeclRefExpr(const Expr *E) { return EmitLoadOfLValue(E); } |
Chris Lattner | 8bcd723 | 2007-08-21 18:03:58 +0000 | [diff] [blame] | 81 | ComplexPairTy VisitArraySubscriptExpr(Expr *E) { return EmitLoadOfLValue(E); } |
Chris Lattner | d272ff0 | 2007-08-26 05:57:57 +0000 | [diff] [blame] | 82 | ComplexPairTy VisitMemberExpr(const Expr *E) { return EmitLoadOfLValue(E); } |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 83 | |
Chris Lattner | e73e8e2 | 2007-08-21 22:33:41 +0000 | [diff] [blame] | 84 | // FIXME: CompoundLiteralExpr |
Chris Lattner | d272ff0 | 2007-08-26 05:57:57 +0000 | [diff] [blame] | 85 | |
| 86 | ComplexPairTy EmitCast(Expr *Op, QualType DestTy); |
| 87 | ComplexPairTy VisitImplicitCastExpr(ImplicitCastExpr *E) { |
| 88 | // Unlike for scalars, we don't have to worry about function->ptr demotion |
| 89 | // here. |
| 90 | return EmitCast(E->getSubExpr(), E->getType()); |
| 91 | } |
| 92 | ComplexPairTy VisitCastExpr(CastExpr *E) { |
| 93 | return EmitCast(E->getSubExpr(), E->getType()); |
| 94 | } |
Chris Lattner | 419d25e | 2007-08-23 21:38:16 +0000 | [diff] [blame] | 95 | ComplexPairTy VisitCallExpr(const CallExpr *E); |
Chris Lattner | 7e20d09 | 2007-08-31 22:51:38 +0000 | [diff] [blame] | 96 | ComplexPairTy VisitStmtExpr(const StmtExpr *E); |
Nate Begeman | 67295d0 | 2008-01-30 20:50:20 +0000 | [diff] [blame] | 97 | ComplexPairTy VisitOverloadExpr(const OverloadExpr *OE); |
Chris Lattner | 7e20d09 | 2007-08-31 22:51:38 +0000 | [diff] [blame] | 98 | |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 99 | // Operators. |
Chris Lattner | 3070f98 | 2007-08-21 22:25:29 +0000 | [diff] [blame] | 100 | ComplexPairTy VisitPrePostIncDec(const UnaryOperator *E, |
| 101 | bool isInc, bool isPre); |
| 102 | ComplexPairTy VisitUnaryPostDec(const UnaryOperator *E) { |
| 103 | return VisitPrePostIncDec(E, false, false); |
| 104 | } |
| 105 | ComplexPairTy VisitUnaryPostInc(const UnaryOperator *E) { |
| 106 | return VisitPrePostIncDec(E, true, false); |
| 107 | } |
| 108 | ComplexPairTy VisitUnaryPreDec(const UnaryOperator *E) { |
| 109 | return VisitPrePostIncDec(E, false, true); |
| 110 | } |
| 111 | ComplexPairTy VisitUnaryPreInc(const UnaryOperator *E) { |
| 112 | return VisitPrePostIncDec(E, true, true); |
| 113 | } |
| 114 | ComplexPairTy VisitUnaryDeref(const Expr *E) { return EmitLoadOfLValue(E); } |
Chris Lattner | fa2b9c9 | 2007-08-21 20:08:23 +0000 | [diff] [blame] | 115 | ComplexPairTy VisitUnaryPlus (const UnaryOperator *E) { |
| 116 | return Visit(E->getSubExpr()); |
| 117 | } |
| 118 | ComplexPairTy VisitUnaryMinus (const UnaryOperator *E); |
Chris Lattner | e98a11c | 2007-08-21 20:41:44 +0000 | [diff] [blame] | 119 | ComplexPairTy VisitUnaryNot (const UnaryOperator *E); |
| 120 | // LNot,SizeOf,AlignOf,Real,Imag never return complex. |
| 121 | ComplexPairTy VisitUnaryExtension(const UnaryOperator *E) { |
| 122 | return Visit(E->getSubExpr()); |
| 123 | } |
Chris Lattner | 0442108 | 2008-04-08 04:40:51 +0000 | [diff] [blame] | 124 | ComplexPairTy VisitCXXDefaultArgExpr(CXXDefaultArgExpr *DAE) { |
| 125 | return Visit(DAE->getExpr()); |
| 126 | } |
Argyrios Kyrtzidis | 7267f78 | 2008-08-23 19:35:47 +0000 | [diff] [blame] | 127 | ComplexPairTy VisitCXXZeroInitValueExpr(CXXZeroInitValueExpr *E) { |
| 128 | assert(E->getType()->isAnyComplexType() && "Expected complex type!"); |
| 129 | QualType Elem = E->getType()->getAsComplexType()->getElementType(); |
| 130 | llvm::Constant *Null = llvm::Constant::getNullValue(CGF.ConvertType(Elem)); |
| 131 | return ComplexPairTy(Null, Null); |
| 132 | } |
Chris Lattner | e98a11c | 2007-08-21 20:41:44 +0000 | [diff] [blame] | 133 | |
Chris Lattner | ab340c2 | 2007-08-26 22:09:01 +0000 | [diff] [blame] | 134 | struct BinOpInfo { |
| 135 | ComplexPairTy LHS; |
| 136 | ComplexPairTy RHS; |
| 137 | QualType Ty; // Computation Type. |
| 138 | }; |
| 139 | |
| 140 | BinOpInfo EmitBinOps(const BinaryOperator *E); |
| 141 | ComplexPairTy EmitCompoundAssign(const CompoundAssignOperator *E, |
| 142 | ComplexPairTy (ComplexExprEmitter::*Func) |
| 143 | (const BinOpInfo &)); |
| 144 | |
| 145 | ComplexPairTy EmitBinAdd(const BinOpInfo &Op); |
| 146 | ComplexPairTy EmitBinSub(const BinOpInfo &Op); |
| 147 | ComplexPairTy EmitBinMul(const BinOpInfo &Op); |
| 148 | ComplexPairTy EmitBinDiv(const BinOpInfo &Op); |
| 149 | |
| 150 | ComplexPairTy VisitBinMul(const BinaryOperator *E) { |
| 151 | return EmitBinMul(EmitBinOps(E)); |
| 152 | } |
| 153 | ComplexPairTy VisitBinAdd(const BinaryOperator *E) { |
| 154 | return EmitBinAdd(EmitBinOps(E)); |
| 155 | } |
| 156 | ComplexPairTy VisitBinSub(const BinaryOperator *E) { |
| 157 | return EmitBinSub(EmitBinOps(E)); |
| 158 | } |
| 159 | ComplexPairTy VisitBinDiv(const BinaryOperator *E) { |
| 160 | return EmitBinDiv(EmitBinOps(E)); |
| 161 | } |
| 162 | |
| 163 | // Compound assignments. |
| 164 | ComplexPairTy VisitBinAddAssign(const CompoundAssignOperator *E) { |
| 165 | return EmitCompoundAssign(E, &ComplexExprEmitter::EmitBinAdd); |
| 166 | } |
| 167 | ComplexPairTy VisitBinSubAssign(const CompoundAssignOperator *E) { |
| 168 | return EmitCompoundAssign(E, &ComplexExprEmitter::EmitBinSub); |
| 169 | } |
| 170 | ComplexPairTy VisitBinMulAssign(const CompoundAssignOperator *E) { |
| 171 | return EmitCompoundAssign(E, &ComplexExprEmitter::EmitBinMul); |
| 172 | } |
| 173 | ComplexPairTy VisitBinDivAssign(const CompoundAssignOperator *E) { |
| 174 | return EmitCompoundAssign(E, &ComplexExprEmitter::EmitBinDiv); |
| 175 | } |
| 176 | |
Chris Lattner | 612c40c | 2007-08-26 21:27:07 +0000 | [diff] [blame] | 177 | // GCC rejects rem/and/or/xor for integer complex. |
Chris Lattner | 4034edb | 2007-08-21 17:12:50 +0000 | [diff] [blame] | 178 | // Logical and/or always return int, never complex. |
Chris Lattner | 58dee10 | 2007-08-21 16:57:55 +0000 | [diff] [blame] | 179 | |
| 180 | // No comparisons produce a complex result. |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 181 | ComplexPairTy VisitBinAssign (const BinaryOperator *E); |
Chris Lattner | 756a4d8 | 2007-08-21 17:15:50 +0000 | [diff] [blame] | 182 | ComplexPairTy VisitBinComma (const BinaryOperator *E); |
| 183 | |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 184 | |
| 185 | ComplexPairTy VisitConditionalOperator(const ConditionalOperator *CO); |
Chris Lattner | d0b1203 | 2007-08-24 02:18:47 +0000 | [diff] [blame] | 186 | ComplexPairTy VisitChooseExpr(ChooseExpr *CE); |
Eli Friedman | c4777f1 | 2008-05-13 23:11:35 +0000 | [diff] [blame] | 187 | |
| 188 | ComplexPairTy VisitInitListExpr(InitListExpr *E); |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 189 | }; |
| 190 | } // end anonymous namespace. |
| 191 | |
| 192 | //===----------------------------------------------------------------------===// |
| 193 | // Utilities |
| 194 | //===----------------------------------------------------------------------===// |
| 195 | |
Chris Lattner | 46d7d9f | 2007-08-21 17:28:34 +0000 | [diff] [blame] | 196 | /// EmitLoadOfComplex - Given an RValue reference for a complex, emit code to |
| 197 | /// load the real and imaginary pieces, returning them as Real/Imag. |
Chris Lattner | 76e8033 | 2007-08-21 18:02:02 +0000 | [diff] [blame] | 198 | ComplexPairTy ComplexExprEmitter::EmitLoadOfComplex(llvm::Value *SrcPtr, |
| 199 | bool isVolatile) { |
Chris Lattner | 6b5d0bf | 2007-08-26 22:47:40 +0000 | [diff] [blame] | 200 | llvm::SmallString<64> Name(SrcPtr->getNameStart(), |
| 201 | SrcPtr->getNameStart()+SrcPtr->getNameLen()); |
| 202 | |
| 203 | Name += ".realp"; |
Chris Lattner | 36b6a0a | 2008-03-19 05:19:41 +0000 | [diff] [blame] | 204 | llvm::Value *RealPtr = Builder.CreateStructGEP(SrcPtr, 0, Name.c_str()); |
Chris Lattner | 6b5d0bf | 2007-08-26 22:47:40 +0000 | [diff] [blame] | 205 | |
| 206 | Name.pop_back(); // .realp -> .real |
| 207 | llvm::Value *Real = Builder.CreateLoad(RealPtr, isVolatile, Name.c_str()); |
| 208 | |
| 209 | Name.resize(Name.size()-4); // .real -> .imagp |
| 210 | Name += "imagp"; |
Ted Kremenek | d627889 | 2007-09-04 17:20:08 +0000 | [diff] [blame] | 211 | |
Chris Lattner | 36b6a0a | 2008-03-19 05:19:41 +0000 | [diff] [blame] | 212 | llvm::Value *ImagPtr = Builder.CreateStructGEP(SrcPtr, 1, Name.c_str()); |
Ted Kremenek | d627889 | 2007-09-04 17:20:08 +0000 | [diff] [blame] | 213 | |
Chris Lattner | 6b5d0bf | 2007-08-26 22:47:40 +0000 | [diff] [blame] | 214 | Name.pop_back(); // .imagp -> .imag |
| 215 | llvm::Value *Imag = Builder.CreateLoad(ImagPtr, isVolatile, Name.c_str()); |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 216 | return ComplexPairTy(Real, Imag); |
| 217 | } |
| 218 | |
Chris Lattner | 46d7d9f | 2007-08-21 17:28:34 +0000 | [diff] [blame] | 219 | /// EmitStoreOfComplex - Store the specified real/imag parts into the |
| 220 | /// specified value pointer. |
Chris Lattner | 76e8033 | 2007-08-21 18:02:02 +0000 | [diff] [blame] | 221 | void ComplexExprEmitter::EmitStoreOfComplex(ComplexPairTy Val, llvm::Value *Ptr, |
| 222 | bool isVolatile) { |
Chris Lattner | 36b6a0a | 2008-03-19 05:19:41 +0000 | [diff] [blame] | 223 | llvm::Value *RealPtr = Builder.CreateStructGEP(Ptr, 0, "real"); |
| 224 | llvm::Value *ImagPtr = Builder.CreateStructGEP(Ptr, 1, "imag"); |
Chris Lattner | 46d7d9f | 2007-08-21 17:28:34 +0000 | [diff] [blame] | 225 | |
Chris Lattner | 76e8033 | 2007-08-21 18:02:02 +0000 | [diff] [blame] | 226 | Builder.CreateStore(Val.first, RealPtr, isVolatile); |
| 227 | Builder.CreateStore(Val.second, ImagPtr, isVolatile); |
Chris Lattner | 46d7d9f | 2007-08-21 17:28:34 +0000 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | |
| 231 | |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 232 | //===----------------------------------------------------------------------===// |
| 233 | // Visitor Methods |
| 234 | //===----------------------------------------------------------------------===// |
| 235 | |
Chris Lattner | 776c649 | 2007-08-21 18:51:13 +0000 | [diff] [blame] | 236 | ComplexPairTy ComplexExprEmitter::VisitExpr(Expr *E) { |
Daniel Dunbar | 488e993 | 2008-08-16 00:56:44 +0000 | [diff] [blame] | 237 | CGF.ErrorUnsupported(E, "complex expression"); |
Chris Lattner | 776c649 | 2007-08-21 18:51:13 +0000 | [diff] [blame] | 238 | const llvm::Type *EltTy = |
| 239 | CGF.ConvertType(E->getType()->getAsComplexType()->getElementType()); |
| 240 | llvm::Value *U = llvm::UndefValue::get(EltTy); |
| 241 | return ComplexPairTy(U, U); |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 242 | } |
| 243 | |
Chris Lattner | d272ff0 | 2007-08-26 05:57:57 +0000 | [diff] [blame] | 244 | ComplexPairTy ComplexExprEmitter:: |
| 245 | VisitImaginaryLiteral(const ImaginaryLiteral *IL) { |
Chris Lattner | db68f1b | 2007-08-26 03:51:12 +0000 | [diff] [blame] | 246 | llvm::Value *Imag = CGF.EmitScalarExpr(IL->getSubExpr()); |
| 247 | return ComplexPairTy(llvm::Constant::getNullValue(Imag->getType()), Imag); |
| 248 | } |
| 249 | |
| 250 | |
Chris Lattner | 419d25e | 2007-08-23 21:38:16 +0000 | [diff] [blame] | 251 | ComplexPairTy ComplexExprEmitter::VisitCallExpr(const CallExpr *E) { |
Chris Lattner | 9b65551 | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 252 | return CGF.EmitCallExpr(E).getComplexVal(); |
Chris Lattner | 419d25e | 2007-08-23 21:38:16 +0000 | [diff] [blame] | 253 | } |
| 254 | |
Nate Begeman | 67295d0 | 2008-01-30 20:50:20 +0000 | [diff] [blame] | 255 | ComplexPairTy ComplexExprEmitter::VisitOverloadExpr(const OverloadExpr *E) { |
Ted Kremenek | 5549976 | 2008-06-17 02:43:46 +0000 | [diff] [blame] | 256 | return CGF.EmitCallExpr(E->getFn(), E->arg_begin(), |
| 257 | E->arg_end(CGF.getContext())).getComplexVal(); |
Nate Begeman | 67295d0 | 2008-01-30 20:50:20 +0000 | [diff] [blame] | 258 | } |
| 259 | |
Chris Lattner | 7e20d09 | 2007-08-31 22:51:38 +0000 | [diff] [blame] | 260 | ComplexPairTy ComplexExprEmitter::VisitStmtExpr(const StmtExpr *E) { |
| 261 | return CGF.EmitCompoundStmt(*E->getSubStmt(), true).getComplexVal(); |
| 262 | } |
| 263 | |
Chris Lattner | ab340c2 | 2007-08-26 22:09:01 +0000 | [diff] [blame] | 264 | /// EmitComplexToComplexCast - Emit a cast from complex value Val to DestType. |
| 265 | ComplexPairTy ComplexExprEmitter::EmitComplexToComplexCast(ComplexPairTy Val, |
| 266 | QualType SrcType, |
| 267 | QualType DestType) { |
| 268 | // Get the src/dest element type. |
Chris Lattner | 9619662 | 2008-07-26 22:37:01 +0000 | [diff] [blame] | 269 | SrcType = SrcType->getAsComplexType()->getElementType(); |
| 270 | DestType = DestType->getAsComplexType()->getElementType(); |
Chris Lattner | d272ff0 | 2007-08-26 05:57:57 +0000 | [diff] [blame] | 271 | |
Chris Lattner | ab340c2 | 2007-08-26 22:09:01 +0000 | [diff] [blame] | 272 | // C99 6.3.1.6: When a value of complextype is converted to another |
| 273 | // complex type, both the real and imaginary parts followthe conversion |
| 274 | // rules for the corresponding real types. |
| 275 | Val.first = CGF.EmitScalarConversion(Val.first, SrcType, DestType); |
| 276 | Val.second = CGF.EmitScalarConversion(Val.second, SrcType, DestType); |
| 277 | return Val; |
| 278 | } |
| 279 | |
| 280 | ComplexPairTy ComplexExprEmitter::EmitCast(Expr *Op, QualType DestTy) { |
Chris Lattner | d272ff0 | 2007-08-26 05:57:57 +0000 | [diff] [blame] | 281 | // Two cases here: cast from (complex to complex) and (scalar to complex). |
Chris Lattner | 9b2dc28 | 2008-04-04 16:54:41 +0000 | [diff] [blame] | 282 | if (Op->getType()->isAnyComplexType()) |
Chris Lattner | ab340c2 | 2007-08-26 22:09:01 +0000 | [diff] [blame] | 283 | return EmitComplexToComplexCast(Visit(Op), Op->getType(), DestTy); |
| 284 | |
Chris Lattner | d272ff0 | 2007-08-26 05:57:57 +0000 | [diff] [blame] | 285 | // C99 6.3.1.7: When a value of real type is converted to a complex type, the |
| 286 | // real part of the complex result value is determined by the rules of |
| 287 | // conversion to the corresponding real type and the imaginary part of the |
| 288 | // complex result value is a positive zero or an unsigned zero. |
| 289 | llvm::Value *Elt = CGF.EmitScalarExpr(Op); |
| 290 | |
| 291 | // Convert the input element to the element type of the complex. |
Chris Lattner | 9619662 | 2008-07-26 22:37:01 +0000 | [diff] [blame] | 292 | DestTy = DestTy->getAsComplexType()->getElementType(); |
Chris Lattner | 3707b25 | 2007-08-26 06:48:56 +0000 | [diff] [blame] | 293 | Elt = CGF.EmitScalarConversion(Elt, Op->getType(), DestTy); |
Chris Lattner | d272ff0 | 2007-08-26 05:57:57 +0000 | [diff] [blame] | 294 | |
| 295 | // Return (realval, 0). |
| 296 | return ComplexPairTy(Elt, llvm::Constant::getNullValue(Elt->getType())); |
| 297 | } |
| 298 | |
Chris Lattner | 3070f98 | 2007-08-21 22:25:29 +0000 | [diff] [blame] | 299 | ComplexPairTy ComplexExprEmitter::VisitPrePostIncDec(const UnaryOperator *E, |
| 300 | bool isInc, bool isPre) { |
| 301 | LValue LV = CGF.EmitLValue(E->getSubExpr()); |
| 302 | // FIXME: Handle volatile! |
| 303 | ComplexPairTy InVal = EmitLoadOfComplex(LV.getAddress(), false); |
| 304 | |
Hartmut Kaiser | 124dd7b | 2007-09-07 14:34:20 +0000 | [diff] [blame] | 305 | uint64_t AmountVal = isInc ? 1 : -1; |
Chris Lattner | 3070f98 | 2007-08-21 22:25:29 +0000 | [diff] [blame] | 306 | |
| 307 | llvm::Value *NextVal; |
| 308 | if (isa<llvm::IntegerType>(InVal.first->getType())) |
| 309 | NextVal = llvm::ConstantInt::get(InVal.first->getType(), AmountVal); |
Chris Lattner | ca2617c | 2007-09-13 06:19:18 +0000 | [diff] [blame] | 310 | else if (InVal.first->getType() == llvm::Type::FloatTy) |
| 311 | // FIXME: Handle long double. |
Devang Patel | e9b8c0a | 2007-10-30 20:59:40 +0000 | [diff] [blame] | 312 | NextVal = |
Chris Lattner | 2c62a1a | 2008-05-04 18:23:51 +0000 | [diff] [blame] | 313 | llvm::ConstantFP::get(llvm::APFloat(static_cast<float>(AmountVal))); |
Chris Lattner | ca2617c | 2007-09-13 06:19:18 +0000 | [diff] [blame] | 314 | else { |
| 315 | // FIXME: Handle long double. |
| 316 | assert(InVal.first->getType() == llvm::Type::DoubleTy); |
Devang Patel | e9b8c0a | 2007-10-30 20:59:40 +0000 | [diff] [blame] | 317 | NextVal = |
Chris Lattner | 2c62a1a | 2008-05-04 18:23:51 +0000 | [diff] [blame] | 318 | llvm::ConstantFP::get(llvm::APFloat(static_cast<double>(AmountVal))); |
Chris Lattner | ca2617c | 2007-09-13 06:19:18 +0000 | [diff] [blame] | 319 | } |
Chris Lattner | 3070f98 | 2007-08-21 22:25:29 +0000 | [diff] [blame] | 320 | |
| 321 | // Add the inc/dec to the real part. |
| 322 | NextVal = Builder.CreateAdd(InVal.first, NextVal, isInc ? "inc" : "dec"); |
| 323 | |
| 324 | ComplexPairTy IncVal(NextVal, InVal.second); |
| 325 | |
| 326 | // Store the updated result through the lvalue. |
| 327 | EmitStoreOfComplex(IncVal, LV.getAddress(), false); /* FIXME: Volatile */ |
| 328 | |
| 329 | // If this is a postinc, return the value read from memory, otherwise use the |
| 330 | // updated value. |
| 331 | return isPre ? IncVal : InVal; |
| 332 | } |
| 333 | |
Chris Lattner | fa2b9c9 | 2007-08-21 20:08:23 +0000 | [diff] [blame] | 334 | ComplexPairTy ComplexExprEmitter::VisitUnaryMinus(const UnaryOperator *E) { |
| 335 | ComplexPairTy Op = Visit(E->getSubExpr()); |
| 336 | llvm::Value *ResR = Builder.CreateNeg(Op.first, "neg.r"); |
| 337 | llvm::Value *ResI = Builder.CreateNeg(Op.second, "neg.i"); |
| 338 | return ComplexPairTy(ResR, ResI); |
| 339 | } |
| 340 | |
Chris Lattner | e98a11c | 2007-08-21 20:41:44 +0000 | [diff] [blame] | 341 | ComplexPairTy ComplexExprEmitter::VisitUnaryNot(const UnaryOperator *E) { |
| 342 | // ~(a+ib) = a + i*-b |
| 343 | ComplexPairTy Op = Visit(E->getSubExpr()); |
| 344 | llvm::Value *ResI = Builder.CreateNeg(Op.second, "conj.i"); |
| 345 | return ComplexPairTy(Op.first, ResI); |
| 346 | } |
Chris Lattner | fa2b9c9 | 2007-08-21 20:08:23 +0000 | [diff] [blame] | 347 | |
Chris Lattner | ab340c2 | 2007-08-26 22:09:01 +0000 | [diff] [blame] | 348 | ComplexPairTy ComplexExprEmitter::EmitBinAdd(const BinOpInfo &Op) { |
| 349 | llvm::Value *ResR = Builder.CreateAdd(Op.LHS.first, Op.RHS.first, "add.r"); |
| 350 | llvm::Value *ResI = Builder.CreateAdd(Op.LHS.second, Op.RHS.second, "add.i"); |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 351 | return ComplexPairTy(ResR, ResI); |
| 352 | } |
| 353 | |
Chris Lattner | ab340c2 | 2007-08-26 22:09:01 +0000 | [diff] [blame] | 354 | ComplexPairTy ComplexExprEmitter::EmitBinSub(const BinOpInfo &Op) { |
| 355 | llvm::Value *ResR = Builder.CreateSub(Op.LHS.first, Op.RHS.first, "sub.r"); |
| 356 | llvm::Value *ResI = Builder.CreateSub(Op.LHS.second, Op.RHS.second, "sub.i"); |
Chris Lattner | 6bc1ade | 2007-08-23 23:46:33 +0000 | [diff] [blame] | 357 | return ComplexPairTy(ResR, ResI); |
| 358 | } |
| 359 | |
| 360 | |
Chris Lattner | ab340c2 | 2007-08-26 22:09:01 +0000 | [diff] [blame] | 361 | ComplexPairTy ComplexExprEmitter::EmitBinMul(const BinOpInfo &Op) { |
| 362 | llvm::Value *ResRl = Builder.CreateMul(Op.LHS.first, Op.RHS.first, "mul.rl"); |
| 363 | llvm::Value *ResRr = Builder.CreateMul(Op.LHS.second, Op.RHS.second,"mul.rr"); |
Chris Lattner | 5083a53 | 2007-08-21 17:39:38 +0000 | [diff] [blame] | 364 | llvm::Value *ResR = Builder.CreateSub(ResRl, ResRr, "mul.r"); |
Chris Lattner | 2823c19 | 2007-08-21 16:34:16 +0000 | [diff] [blame] | 365 | |
Chris Lattner | ab340c2 | 2007-08-26 22:09:01 +0000 | [diff] [blame] | 366 | llvm::Value *ResIl = Builder.CreateMul(Op.LHS.second, Op.RHS.first, "mul.il"); |
| 367 | llvm::Value *ResIr = Builder.CreateMul(Op.LHS.first, Op.RHS.second, "mul.ir"); |
Chris Lattner | 5083a53 | 2007-08-21 17:39:38 +0000 | [diff] [blame] | 368 | llvm::Value *ResI = Builder.CreateAdd(ResIl, ResIr, "mul.i"); |
Chris Lattner | 2823c19 | 2007-08-21 16:34:16 +0000 | [diff] [blame] | 369 | return ComplexPairTy(ResR, ResI); |
| 370 | } |
| 371 | |
Chris Lattner | ab340c2 | 2007-08-26 22:09:01 +0000 | [diff] [blame] | 372 | ComplexPairTy ComplexExprEmitter::EmitBinDiv(const BinOpInfo &Op) { |
| 373 | llvm::Value *LHSr = Op.LHS.first, *LHSi = Op.LHS.second; |
| 374 | llvm::Value *RHSr = Op.RHS.first, *RHSi = Op.RHS.second; |
Chris Lattner | 3219c5d | 2007-08-26 21:24:19 +0000 | [diff] [blame] | 375 | |
| 376 | // (a+ib) / (c+id) = ((ac+bd)/(cc+dd)) + i((bc-ad)/(cc+dd)) |
| 377 | llvm::Value *Tmp1 = Builder.CreateMul(LHSr, RHSr, "tmp"); // a*c |
| 378 | llvm::Value *Tmp2 = Builder.CreateMul(LHSi, RHSi, "tmp"); // b*d |
| 379 | llvm::Value *Tmp3 = Builder.CreateAdd(Tmp1, Tmp2, "tmp"); // ac+bd |
| 380 | |
| 381 | llvm::Value *Tmp4 = Builder.CreateMul(RHSr, RHSr, "tmp"); // c*c |
| 382 | llvm::Value *Tmp5 = Builder.CreateMul(RHSi, RHSi, "tmp"); // d*d |
| 383 | llvm::Value *Tmp6 = Builder.CreateAdd(Tmp4, Tmp5, "tmp"); // cc+dd |
| 384 | |
| 385 | llvm::Value *Tmp7 = Builder.CreateMul(LHSi, RHSr, "tmp"); // b*c |
| 386 | llvm::Value *Tmp8 = Builder.CreateMul(LHSr, RHSi, "tmp"); // a*d |
| 387 | llvm::Value *Tmp9 = Builder.CreateSub(Tmp7, Tmp8, "tmp"); // bc-ad |
| 388 | |
| 389 | llvm::Value *DSTr, *DSTi; |
| 390 | if (Tmp3->getType()->isFloatingPoint()) { |
| 391 | DSTr = Builder.CreateFDiv(Tmp3, Tmp6, "tmp"); |
| 392 | DSTi = Builder.CreateFDiv(Tmp9, Tmp6, "tmp"); |
| 393 | } else { |
Chris Lattner | ab340c2 | 2007-08-26 22:09:01 +0000 | [diff] [blame] | 394 | if (Op.Ty->getAsComplexType()->getElementType()->isUnsignedIntegerType()) { |
Chris Lattner | 3219c5d | 2007-08-26 21:24:19 +0000 | [diff] [blame] | 395 | DSTr = Builder.CreateUDiv(Tmp3, Tmp6, "tmp"); |
| 396 | DSTi = Builder.CreateUDiv(Tmp9, Tmp6, "tmp"); |
| 397 | } else { |
| 398 | DSTr = Builder.CreateSDiv(Tmp3, Tmp6, "tmp"); |
| 399 | DSTi = Builder.CreateSDiv(Tmp9, Tmp6, "tmp"); |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | return ComplexPairTy(DSTr, DSTi); |
| 404 | } |
| 405 | |
Chris Lattner | ab340c2 | 2007-08-26 22:09:01 +0000 | [diff] [blame] | 406 | ComplexExprEmitter::BinOpInfo |
| 407 | ComplexExprEmitter::EmitBinOps(const BinaryOperator *E) { |
| 408 | BinOpInfo Ops; |
| 409 | Ops.LHS = Visit(E->getLHS()); |
| 410 | Ops.RHS = Visit(E->getRHS()); |
| 411 | Ops.Ty = E->getType(); |
| 412 | return Ops; |
| 413 | } |
| 414 | |
| 415 | |
| 416 | // Compound assignments. |
| 417 | ComplexPairTy ComplexExprEmitter:: |
| 418 | EmitCompoundAssign(const CompoundAssignOperator *E, |
| 419 | ComplexPairTy (ComplexExprEmitter::*Func)(const BinOpInfo&)){ |
| 420 | QualType LHSTy = E->getLHS()->getType(), RHSTy = E->getRHS()->getType(); |
| 421 | |
| 422 | // Load the LHS and RHS operands. |
| 423 | LValue LHSLV = CGF.EmitLValue(E->getLHS()); |
| 424 | |
| 425 | BinOpInfo OpInfo; |
| 426 | OpInfo.Ty = E->getComputationType(); |
| 427 | |
| 428 | // We know the LHS is a complex lvalue. |
| 429 | OpInfo.LHS = EmitLoadOfComplex(LHSLV.getAddress(), false);// FIXME: Volatile. |
| 430 | OpInfo.LHS = EmitComplexToComplexCast(OpInfo.LHS, LHSTy, OpInfo.Ty); |
| 431 | |
| 432 | // It is possible for the RHS to be complex or scalar. |
| 433 | OpInfo.RHS = EmitCast(E->getRHS(), OpInfo.Ty); |
| 434 | |
| 435 | // Expand the binary operator. |
| 436 | ComplexPairTy Result = (this->*Func)(OpInfo); |
| 437 | |
| 438 | // Truncate the result back to the LHS type. |
| 439 | Result = EmitComplexToComplexCast(Result, OpInfo.Ty, LHSTy); |
| 440 | |
| 441 | // Store the result value into the LHS lvalue. |
| 442 | EmitStoreOfComplex(Result, LHSLV.getAddress(), false); // FIXME: VOLATILE |
| 443 | return Result; |
| 444 | } |
Chris Lattner | 3219c5d | 2007-08-26 21:24:19 +0000 | [diff] [blame] | 445 | |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 446 | ComplexPairTy ComplexExprEmitter::VisitBinAssign(const BinaryOperator *E) { |
Chris Lattner | 9619662 | 2008-07-26 22:37:01 +0000 | [diff] [blame] | 447 | assert(CGF.getContext().getCanonicalType(E->getLHS()->getType()) == |
| 448 | CGF.getContext().getCanonicalType(E->getRHS()->getType()) && |
| 449 | "Invalid assignment"); |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 450 | // Emit the RHS. |
| 451 | ComplexPairTy Val = Visit(E->getRHS()); |
| 452 | |
| 453 | // Compute the address to store into. |
| 454 | LValue LHS = CGF.EmitLValue(E->getLHS()); |
| 455 | |
| 456 | // Store into it. |
| 457 | // FIXME: Volatility! |
Chris Lattner | 76e8033 | 2007-08-21 18:02:02 +0000 | [diff] [blame] | 458 | EmitStoreOfComplex(Val, LHS.getAddress(), false); |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 459 | return Val; |
| 460 | } |
| 461 | |
Chris Lattner | 756a4d8 | 2007-08-21 17:15:50 +0000 | [diff] [blame] | 462 | ComplexPairTy ComplexExprEmitter::VisitBinComma(const BinaryOperator *E) { |
| 463 | CGF.EmitStmt(E->getLHS()); |
| 464 | return Visit(E->getRHS()); |
| 465 | } |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 466 | |
| 467 | ComplexPairTy ComplexExprEmitter:: |
| 468 | VisitConditionalOperator(const ConditionalOperator *E) { |
Gabor Greif | 984d0b4 | 2008-04-06 20:42:52 +0000 | [diff] [blame] | 469 | llvm::BasicBlock *LHSBlock = llvm::BasicBlock::Create("cond.?"); |
| 470 | llvm::BasicBlock *RHSBlock = llvm::BasicBlock::Create("cond.:"); |
| 471 | llvm::BasicBlock *ContBlock = llvm::BasicBlock::Create("cond.cont"); |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 472 | |
| 473 | llvm::Value *Cond = CGF.EvaluateExprAsBool(E->getCond()); |
Chris Lattner | 5083a53 | 2007-08-21 17:39:38 +0000 | [diff] [blame] | 474 | Builder.CreateCondBr(Cond, LHSBlock, RHSBlock); |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 475 | |
| 476 | CGF.EmitBlock(LHSBlock); |
| 477 | |
| 478 | // Handle the GNU extension for missing LHS. |
Chris Lattner | 05ba49c | 2007-08-21 05:54:53 +0000 | [diff] [blame] | 479 | assert(E->getLHS() && "Must have LHS for complex value"); |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 480 | |
| 481 | ComplexPairTy LHS = Visit(E->getLHS()); |
Chris Lattner | 5083a53 | 2007-08-21 17:39:38 +0000 | [diff] [blame] | 482 | Builder.CreateBr(ContBlock); |
| 483 | LHSBlock = Builder.GetInsertBlock(); |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 484 | |
| 485 | CGF.EmitBlock(RHSBlock); |
| 486 | |
| 487 | ComplexPairTy RHS = Visit(E->getRHS()); |
Chris Lattner | 5083a53 | 2007-08-21 17:39:38 +0000 | [diff] [blame] | 488 | Builder.CreateBr(ContBlock); |
| 489 | RHSBlock = Builder.GetInsertBlock(); |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 490 | |
| 491 | CGF.EmitBlock(ContBlock); |
| 492 | |
| 493 | // Create a PHI node for the real part. |
Chris Lattner | 5083a53 | 2007-08-21 17:39:38 +0000 | [diff] [blame] | 494 | llvm::PHINode *RealPN = Builder.CreatePHI(LHS.first->getType(), "cond.r"); |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 495 | RealPN->reserveOperandSpace(2); |
| 496 | RealPN->addIncoming(LHS.first, LHSBlock); |
| 497 | RealPN->addIncoming(RHS.first, RHSBlock); |
| 498 | |
| 499 | // Create a PHI node for the imaginary part. |
Chris Lattner | 5083a53 | 2007-08-21 17:39:38 +0000 | [diff] [blame] | 500 | llvm::PHINode *ImagPN = Builder.CreatePHI(LHS.first->getType(), "cond.i"); |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 501 | ImagPN->reserveOperandSpace(2); |
| 502 | ImagPN->addIncoming(LHS.second, LHSBlock); |
| 503 | ImagPN->addIncoming(RHS.second, RHSBlock); |
| 504 | |
| 505 | return ComplexPairTy(RealPN, ImagPN); |
| 506 | } |
| 507 | |
Chris Lattner | d0b1203 | 2007-08-24 02:18:47 +0000 | [diff] [blame] | 508 | ComplexPairTy ComplexExprEmitter::VisitChooseExpr(ChooseExpr *E) { |
Chris Lattner | d0b1203 | 2007-08-24 02:18:47 +0000 | [diff] [blame] | 509 | // Emit the LHS or RHS as appropriate. |
Chris Lattner | 27437ca | 2007-10-25 00:29:32 +0000 | [diff] [blame] | 510 | return Visit(E->isConditionTrue(CGF.getContext()) ? E->getLHS() :E->getRHS()); |
Chris Lattner | d0b1203 | 2007-08-24 02:18:47 +0000 | [diff] [blame] | 511 | } |
| 512 | |
Eli Friedman | c4777f1 | 2008-05-13 23:11:35 +0000 | [diff] [blame] | 513 | ComplexPairTy ComplexExprEmitter::VisitInitListExpr(InitListExpr *E) { |
| 514 | if (E->getNumInits()) |
| 515 | return Visit(E->getInit(0)); |
| 516 | |
| 517 | // Empty init list intializes to null |
| 518 | QualType Ty = E->getType()->getAsComplexType()->getElementType(); |
| 519 | const llvm::Type* LTy = CGF.ConvertType(Ty); |
| 520 | llvm::Value* zeroConstant = llvm::Constant::getNullValue(LTy); |
| 521 | return ComplexPairTy(zeroConstant, zeroConstant); |
| 522 | } |
| 523 | |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 524 | //===----------------------------------------------------------------------===// |
| 525 | // Entry Point into this File |
| 526 | //===----------------------------------------------------------------------===// |
| 527 | |
| 528 | /// EmitComplexExpr - Emit the computation of the specified expression of |
| 529 | /// complex type, ignoring the result. |
Chris Lattner | 58dee10 | 2007-08-21 16:57:55 +0000 | [diff] [blame] | 530 | ComplexPairTy CodeGenFunction::EmitComplexExpr(const Expr *E) { |
Chris Lattner | 9b2dc28 | 2008-04-04 16:54:41 +0000 | [diff] [blame] | 531 | assert(E && E->getType()->isAnyComplexType() && |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 532 | "Invalid complex expression to emit"); |
| 533 | |
Chris Lattner | 58dee10 | 2007-08-21 16:57:55 +0000 | [diff] [blame] | 534 | return ComplexExprEmitter(*this).Visit(const_cast<Expr*>(E)); |
Chris Lattner | b6ef18a | 2007-08-21 05:54:00 +0000 | [diff] [blame] | 535 | } |
| 536 | |
Chris Lattner | 23b1cdb | 2007-08-23 23:43:33 +0000 | [diff] [blame] | 537 | /// EmitComplexExprIntoAddr - Emit the computation of the specified expression |
| 538 | /// of complex type, storing into the specified Value*. |
| 539 | void CodeGenFunction::EmitComplexExprIntoAddr(const Expr *E, |
Chris Lattner | 190dbe2 | 2007-08-26 16:22:13 +0000 | [diff] [blame] | 540 | llvm::Value *DestAddr, |
| 541 | bool DestIsVolatile) { |
Chris Lattner | 9b2dc28 | 2008-04-04 16:54:41 +0000 | [diff] [blame] | 542 | assert(E && E->getType()->isAnyComplexType() && |
Chris Lattner | 23b1cdb | 2007-08-23 23:43:33 +0000 | [diff] [blame] | 543 | "Invalid complex expression to emit"); |
| 544 | ComplexExprEmitter Emitter(*this); |
| 545 | ComplexPairTy Val = Emitter.Visit(const_cast<Expr*>(E)); |
Chris Lattner | 190dbe2 | 2007-08-26 16:22:13 +0000 | [diff] [blame] | 546 | Emitter.EmitStoreOfComplex(Val, DestAddr, DestIsVolatile); |
Chris Lattner | 23b1cdb | 2007-08-23 23:43:33 +0000 | [diff] [blame] | 547 | } |
Chris Lattner | 9b65551 | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 548 | |
Daniel Dunbar | 7f8ea5c | 2008-08-30 05:35:15 +0000 | [diff] [blame] | 549 | /// StoreComplexToAddr - Store a complex number into the specified address. |
| 550 | void CodeGenFunction::StoreComplexToAddr(ComplexPairTy V, |
| 551 | llvm::Value *DestAddr, |
| 552 | bool DestIsVolatile) { |
| 553 | ComplexExprEmitter(*this).EmitStoreOfComplex(V, DestAddr, DestIsVolatile); |
| 554 | } |
| 555 | |
Chris Lattner | 9b65551 | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 556 | /// LoadComplexFromAddr - Load a complex number from the specified address. |
| 557 | ComplexPairTy CodeGenFunction::LoadComplexFromAddr(llvm::Value *SrcAddr, |
| 558 | bool SrcIsVolatile) { |
| 559 | return ComplexExprEmitter(*this).EmitLoadOfComplex(SrcAddr, SrcIsVolatile); |
| 560 | } |