Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 1 | //===--- CGExpr.cpp - Emit LLVM Code from Expressions ---------------------===// |
| 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. |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This contains code to emit Expr nodes as LLVM code. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "CodeGenFunction.h" |
| 15 | #include "CodeGenModule.h" |
| 16 | #include "clang/AST/AST.h" |
Eli Friedman | 316bb1b | 2008-05-17 20:03:47 +0000 | [diff] [blame] | 17 | #include "clang/Basic/TargetInfo.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 18 | #include "llvm/Constants.h" |
| 19 | #include "llvm/DerivedTypes.h" |
| 20 | #include "llvm/Function.h" |
| 21 | #include "llvm/GlobalVariable.h" |
Chris Lattner | 99e0d79 | 2007-07-16 05:43:05 +0000 | [diff] [blame] | 22 | #include "llvm/Support/MathExtras.h" |
Eli Friedman | 316bb1b | 2008-05-17 20:03:47 +0000 | [diff] [blame] | 23 | #include "llvm/Target/TargetData.h" |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 24 | using namespace clang; |
| 25 | using namespace CodeGen; |
| 26 | |
| 27 | //===--------------------------------------------------------------------===// |
| 28 | // Miscellaneous Helper Methods |
| 29 | //===--------------------------------------------------------------------===// |
| 30 | |
| 31 | /// CreateTempAlloca - This creates a alloca and inserts it into the entry |
| 32 | /// block. |
| 33 | llvm::AllocaInst *CodeGenFunction::CreateTempAlloca(const llvm::Type *Ty, |
| 34 | const char *Name) { |
| 35 | return new llvm::AllocaInst(Ty, 0, Name, AllocaInsertPt); |
| 36 | } |
| 37 | |
| 38 | /// EvaluateExprAsBool - Perform the usual unary conversions on the specified |
| 39 | /// expression and compare the result against zero, returning an Int1Ty value. |
| 40 | llvm::Value *CodeGenFunction::EvaluateExprAsBool(const Expr *E) { |
Chris Lattner | 9069fa2 | 2007-08-26 16:46:58 +0000 | [diff] [blame] | 41 | QualType BoolTy = getContext().BoolTy; |
Chris Lattner | 9b2dc28 | 2008-04-04 16:54:41 +0000 | [diff] [blame] | 42 | if (!E->getType()->isAnyComplexType()) |
Chris Lattner | 9069fa2 | 2007-08-26 16:46:58 +0000 | [diff] [blame] | 43 | return EmitScalarConversion(EmitScalarExpr(E), E->getType(), BoolTy); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 44 | |
Chris Lattner | 9069fa2 | 2007-08-26 16:46:58 +0000 | [diff] [blame] | 45 | return EmitComplexToScalarConversion(EmitComplexExpr(E), E->getType(),BoolTy); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 46 | } |
| 47 | |
Chris Lattner | 9b65551 | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 48 | /// EmitAnyExpr - Emit code to compute the specified expression which can have |
| 49 | /// any type. The result is returned as an RValue struct. If this is an |
| 50 | /// aggregate expression, the aggloc/agglocvolatile arguments indicate where |
| 51 | /// the result should be returned. |
| 52 | RValue CodeGenFunction::EmitAnyExpr(const Expr *E, llvm::Value *AggLoc, |
| 53 | bool isAggLocVolatile) { |
| 54 | if (!hasAggregateLLVMType(E->getType())) |
| 55 | return RValue::get(EmitScalarExpr(E)); |
Chris Lattner | 9b2dc28 | 2008-04-04 16:54:41 +0000 | [diff] [blame] | 56 | else if (E->getType()->isAnyComplexType()) |
Chris Lattner | 9b65551 | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 57 | return RValue::getComplex(EmitComplexExpr(E)); |
| 58 | |
| 59 | EmitAggExpr(E, AggLoc, isAggLocVolatile); |
| 60 | return RValue::getAggregate(AggLoc); |
| 61 | } |
| 62 | |
Dan Gohman | 4f8d123 | 2008-05-22 00:50:06 +0000 | [diff] [blame] | 63 | /// getAccessedFieldNo - Given an encoded value and a result number, return |
| 64 | /// the input field number being accessed. |
| 65 | unsigned CodeGenFunction::getAccessedFieldNo(unsigned Idx, |
| 66 | const llvm::Constant *Elts) { |
| 67 | if (isa<llvm::ConstantAggregateZero>(Elts)) |
| 68 | return 0; |
| 69 | |
| 70 | return cast<llvm::ConstantInt>(Elts->getOperand(Idx))->getZExtValue(); |
| 71 | } |
| 72 | |
Chris Lattner | 9b65551 | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 73 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 74 | //===----------------------------------------------------------------------===// |
| 75 | // LValue Expression Emission |
| 76 | //===----------------------------------------------------------------------===// |
| 77 | |
| 78 | /// EmitLValue - Emit code to compute a designator that specifies the location |
| 79 | /// of the expression. |
| 80 | /// |
| 81 | /// This can return one of two things: a simple address or a bitfield |
| 82 | /// reference. In either case, the LLVM Value* in the LValue structure is |
| 83 | /// guaranteed to be an LLVM pointer type. |
| 84 | /// |
| 85 | /// If this returns a bitfield reference, nothing about the pointee type of |
| 86 | /// the LLVM value is known: For example, it may not be a pointer to an |
| 87 | /// integer. |
| 88 | /// |
| 89 | /// If this returns a normal address, and if the lvalue's C type is fixed |
| 90 | /// size, this method guarantees that the returned pointer type will point to |
| 91 | /// an LLVM type of the same size of the lvalue's type. If the lvalue has a |
| 92 | /// variable length type, this is not possible. |
| 93 | /// |
| 94 | LValue CodeGenFunction::EmitLValue(const Expr *E) { |
| 95 | switch (E->getStmtClass()) { |
Chris Lattner | 7013c8c | 2007-08-26 05:06:40 +0000 | [diff] [blame] | 96 | default: { |
Chris Lattner | ce5605e | 2008-03-30 23:25:33 +0000 | [diff] [blame] | 97 | printf("Statement class: %d\n", E->getStmtClass()); |
Chris Lattner | dc4d280 | 2007-12-02 01:49:16 +0000 | [diff] [blame] | 98 | WarnUnsupported(E, "l-value expression"); |
Christopher Lamb | ddc23f3 | 2007-12-17 01:11:20 +0000 | [diff] [blame] | 99 | llvm::Type *Ty = llvm::PointerType::getUnqual(ConvertType(E->getType())); |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 100 | return LValue::MakeAddr(llvm::UndefValue::get(Ty), |
| 101 | E->getType().getCVRQualifiers()); |
Chris Lattner | 7013c8c | 2007-08-26 05:06:40 +0000 | [diff] [blame] | 102 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 103 | |
Christopher Lamb | 22c940e | 2007-12-29 05:02:41 +0000 | [diff] [blame] | 104 | case Expr::CallExprClass: return EmitCallExprLValue(cast<CallExpr>(E)); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 105 | case Expr::DeclRefExprClass: return EmitDeclRefLValue(cast<DeclRefExpr>(E)); |
| 106 | case Expr::ParenExprClass:return EmitLValue(cast<ParenExpr>(E)->getSubExpr()); |
Anders Carlsson | 2274266 | 2007-07-21 05:21:51 +0000 | [diff] [blame] | 107 | case Expr::PreDefinedExprClass: |
| 108 | return EmitPreDefinedLValue(cast<PreDefinedExpr>(E)); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 109 | case Expr::StringLiteralClass: |
| 110 | return EmitStringLiteralLValue(cast<StringLiteral>(E)); |
Chris Lattner | 391d77a | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 111 | |
| 112 | case Expr::ObjCIvarRefExprClass: |
| 113 | return EmitObjCIvarRefLValue(cast<ObjCIvarRefExpr>(E)); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 114 | |
| 115 | case Expr::UnaryOperatorClass: |
| 116 | return EmitUnaryOpLValue(cast<UnaryOperator>(E)); |
| 117 | case Expr::ArraySubscriptExprClass: |
| 118 | return EmitArraySubscriptExpr(cast<ArraySubscriptExpr>(E)); |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 119 | case Expr::ExtVectorElementExprClass: |
| 120 | return EmitExtVectorElementExpr(cast<ExtVectorElementExpr>(E)); |
Devang Patel | b9b00ad | 2007-10-23 20:28:39 +0000 | [diff] [blame] | 121 | case Expr::MemberExprClass: return EmitMemberExpr(cast<MemberExpr>(E)); |
Eli Friedman | 06e863f | 2008-05-13 23:18:27 +0000 | [diff] [blame] | 122 | case Expr::CompoundLiteralExprClass: |
| 123 | return EmitCompoundLiteralLValue(cast<CompoundLiteralExpr>(E)); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 124 | } |
| 125 | } |
| 126 | |
| 127 | /// EmitLoadOfLValue - Given an expression that represents a value lvalue, |
| 128 | /// this method emits the address of the lvalue, then loads the result as an |
| 129 | /// rvalue, returning the rvalue. |
| 130 | RValue CodeGenFunction::EmitLoadOfLValue(LValue LV, QualType ExprType) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 131 | if (LV.isSimple()) { |
| 132 | llvm::Value *Ptr = LV.getAddress(); |
| 133 | const llvm::Type *EltTy = |
| 134 | cast<llvm::PointerType>(Ptr->getType())->getElementType(); |
| 135 | |
| 136 | // Simple scalar l-value. |
Dan Gohman | d79a726 | 2008-05-22 22:12:56 +0000 | [diff] [blame] | 137 | if (EltTy->isSingleValueType()) { |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 138 | llvm::Value *V = Builder.CreateLoad(Ptr, LV.isVolatileQualified(),"tmp"); |
Chris Lattner | 01e3c9e | 2008-01-30 07:01:17 +0000 | [diff] [blame] | 139 | |
| 140 | // Bool can have different representation in memory than in registers. |
| 141 | if (ExprType->isBooleanType()) { |
| 142 | if (V->getType() != llvm::Type::Int1Ty) |
| 143 | V = Builder.CreateTrunc(V, llvm::Type::Int1Ty, "tobool"); |
| 144 | } |
| 145 | |
| 146 | return RValue::get(V); |
| 147 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 148 | |
Chris Lattner | 883f6a7 | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 149 | assert(ExprType->isFunctionType() && "Unknown scalar value"); |
| 150 | return RValue::get(Ptr); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | if (LV.isVectorElt()) { |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 154 | llvm::Value *Vec = Builder.CreateLoad(LV.getVectorAddr(), |
| 155 | LV.isVolatileQualified(), "tmp"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 156 | return RValue::get(Builder.CreateExtractElement(Vec, LV.getVectorIdx(), |
| 157 | "vecext")); |
| 158 | } |
Chris Lattner | 46ea8eb | 2007-08-03 00:16:29 +0000 | [diff] [blame] | 159 | |
| 160 | // If this is a reference to a subset of the elements of a vector, either |
| 161 | // shuffle the input or extract/insert them as appropriate. |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 162 | if (LV.isExtVectorElt()) |
| 163 | return EmitLoadOfExtVectorElementLValue(LV, ExprType); |
Lauro Ramos Venancio | 3b8c22d | 2008-01-22 20:17:04 +0000 | [diff] [blame] | 164 | |
| 165 | if (LV.isBitfield()) |
| 166 | return EmitLoadOfBitfieldLValue(LV, ExprType); |
| 167 | |
| 168 | assert(0 && "Unknown LValue type!"); |
Chris Lattner | b1776cb | 2007-09-16 19:23:47 +0000 | [diff] [blame] | 169 | //an invalid RValue, but the assert will |
| 170 | //ensure that this point is never reached |
| 171 | return RValue(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 172 | } |
| 173 | |
Lauro Ramos Venancio | 3b8c22d | 2008-01-22 20:17:04 +0000 | [diff] [blame] | 174 | RValue CodeGenFunction::EmitLoadOfBitfieldLValue(LValue LV, |
| 175 | QualType ExprType) { |
| 176 | llvm::Value *Ptr = LV.getBitfieldAddr(); |
| 177 | const llvm::Type *EltTy = |
| 178 | cast<llvm::PointerType>(Ptr->getType())->getElementType(); |
| 179 | unsigned EltTySize = EltTy->getPrimitiveSizeInBits(); |
| 180 | unsigned short BitfieldSize = LV.getBitfieldSize(); |
| 181 | unsigned short EndBit = LV.getBitfieldStartBit() + BitfieldSize; |
| 182 | |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 183 | llvm::Value *V = Builder.CreateLoad(Ptr, LV.isVolatileQualified(), "tmp"); |
Lauro Ramos Venancio | 3b8c22d | 2008-01-22 20:17:04 +0000 | [diff] [blame] | 184 | |
| 185 | llvm::Value *ShAmt = llvm::ConstantInt::get(EltTy, EltTySize - EndBit); |
| 186 | V = Builder.CreateShl(V, ShAmt, "tmp"); |
| 187 | |
| 188 | ShAmt = llvm::ConstantInt::get(EltTy, EltTySize - BitfieldSize); |
| 189 | V = LV.isBitfieldSigned() ? |
| 190 | Builder.CreateAShr(V, ShAmt, "tmp") : |
| 191 | Builder.CreateLShr(V, ShAmt, "tmp"); |
Eli Friedman | 316bb1b | 2008-05-17 20:03:47 +0000 | [diff] [blame] | 192 | |
| 193 | // The bitfield type and the normal type differ when the storage sizes |
| 194 | // differ (currently just _Bool). |
| 195 | V = Builder.CreateIntCast(V, ConvertType(ExprType), false, "tmp"); |
| 196 | |
Lauro Ramos Venancio | 3b8c22d | 2008-01-22 20:17:04 +0000 | [diff] [blame] | 197 | return RValue::get(V); |
| 198 | } |
| 199 | |
Chris Lattner | 34cdc86 | 2007-08-03 16:18:34 +0000 | [diff] [blame] | 200 | // If this is a reference to a subset of the elements of a vector, either |
| 201 | // shuffle the input or extract/insert them as appropriate. |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 202 | RValue CodeGenFunction::EmitLoadOfExtVectorElementLValue(LValue LV, |
| 203 | QualType ExprType) { |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 204 | llvm::Value *Vec = Builder.CreateLoad(LV.getExtVectorAddr(), |
| 205 | LV.isVolatileQualified(), "tmp"); |
Chris Lattner | 34cdc86 | 2007-08-03 16:18:34 +0000 | [diff] [blame] | 206 | |
Nate Begeman | 8a99764 | 2008-05-09 06:41:27 +0000 | [diff] [blame] | 207 | const llvm::Constant *Elts = LV.getExtVectorElts(); |
Chris Lattner | 34cdc86 | 2007-08-03 16:18:34 +0000 | [diff] [blame] | 208 | |
| 209 | // If the result of the expression is a non-vector type, we must be |
| 210 | // extracting a single element. Just codegen as an extractelement. |
Chris Lattner | cf60cd2 | 2007-08-10 17:10:08 +0000 | [diff] [blame] | 211 | const VectorType *ExprVT = ExprType->getAsVectorType(); |
| 212 | if (!ExprVT) { |
Dan Gohman | 4f8d123 | 2008-05-22 00:50:06 +0000 | [diff] [blame] | 213 | unsigned InIdx = getAccessedFieldNo(0, Elts); |
Chris Lattner | 34cdc86 | 2007-08-03 16:18:34 +0000 | [diff] [blame] | 214 | llvm::Value *Elt = llvm::ConstantInt::get(llvm::Type::Int32Ty, InIdx); |
| 215 | return RValue::get(Builder.CreateExtractElement(Vec, Elt, "tmp")); |
| 216 | } |
| 217 | |
| 218 | // If the source and destination have the same number of elements, use a |
| 219 | // vector shuffle instead of insert/extracts. |
Chris Lattner | cf60cd2 | 2007-08-10 17:10:08 +0000 | [diff] [blame] | 220 | unsigned NumResultElts = ExprVT->getNumElements(); |
Chris Lattner | 34cdc86 | 2007-08-03 16:18:34 +0000 | [diff] [blame] | 221 | unsigned NumSourceElts = |
| 222 | cast<llvm::VectorType>(Vec->getType())->getNumElements(); |
| 223 | |
| 224 | if (NumResultElts == NumSourceElts) { |
| 225 | llvm::SmallVector<llvm::Constant*, 4> Mask; |
| 226 | for (unsigned i = 0; i != NumResultElts; ++i) { |
Dan Gohman | 4f8d123 | 2008-05-22 00:50:06 +0000 | [diff] [blame] | 227 | unsigned InIdx = getAccessedFieldNo(i, Elts); |
Chris Lattner | 34cdc86 | 2007-08-03 16:18:34 +0000 | [diff] [blame] | 228 | Mask.push_back(llvm::ConstantInt::get(llvm::Type::Int32Ty, InIdx)); |
| 229 | } |
| 230 | |
| 231 | llvm::Value *MaskV = llvm::ConstantVector::get(&Mask[0], Mask.size()); |
| 232 | Vec = Builder.CreateShuffleVector(Vec, |
| 233 | llvm::UndefValue::get(Vec->getType()), |
| 234 | MaskV, "tmp"); |
| 235 | return RValue::get(Vec); |
| 236 | } |
| 237 | |
| 238 | // Start out with an undef of the result type. |
| 239 | llvm::Value *Result = llvm::UndefValue::get(ConvertType(ExprType)); |
| 240 | |
| 241 | // Extract/Insert each element of the result. |
| 242 | for (unsigned i = 0; i != NumResultElts; ++i) { |
Dan Gohman | 4f8d123 | 2008-05-22 00:50:06 +0000 | [diff] [blame] | 243 | unsigned InIdx = getAccessedFieldNo(i, Elts); |
Chris Lattner | 34cdc86 | 2007-08-03 16:18:34 +0000 | [diff] [blame] | 244 | llvm::Value *Elt = llvm::ConstantInt::get(llvm::Type::Int32Ty, InIdx); |
| 245 | Elt = Builder.CreateExtractElement(Vec, Elt, "tmp"); |
| 246 | |
| 247 | llvm::Value *OutIdx = llvm::ConstantInt::get(llvm::Type::Int32Ty, i); |
| 248 | Result = Builder.CreateInsertElement(Result, Elt, OutIdx, "tmp"); |
| 249 | } |
| 250 | |
| 251 | return RValue::get(Result); |
| 252 | } |
| 253 | |
| 254 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 255 | |
| 256 | /// EmitStoreThroughLValue - Store the specified rvalue into the specified |
| 257 | /// lvalue, where both are guaranteed to the have the same type, and that type |
| 258 | /// is 'Ty'. |
| 259 | void CodeGenFunction::EmitStoreThroughLValue(RValue Src, LValue Dst, |
| 260 | QualType Ty) { |
Chris Lattner | 017d6aa | 2007-08-03 16:28:33 +0000 | [diff] [blame] | 261 | if (!Dst.isSimple()) { |
| 262 | if (Dst.isVectorElt()) { |
| 263 | // Read/modify/write the vector, inserting the new element. |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 264 | llvm::Value *Vec = Builder.CreateLoad(Dst.getVectorAddr(), |
| 265 | Dst.isVolatileQualified(), "tmp"); |
Chris Lattner | 9b65551 | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 266 | Vec = Builder.CreateInsertElement(Vec, Src.getScalarVal(), |
Chris Lattner | 017d6aa | 2007-08-03 16:28:33 +0000 | [diff] [blame] | 267 | Dst.getVectorIdx(), "vecins"); |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 268 | Builder.CreateStore(Vec, Dst.getVectorAddr(),Dst.isVolatileQualified()); |
Chris Lattner | 017d6aa | 2007-08-03 16:28:33 +0000 | [diff] [blame] | 269 | return; |
| 270 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 271 | |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 272 | // If this is an update of extended vector elements, insert them as |
| 273 | // appropriate. |
| 274 | if (Dst.isExtVectorElt()) |
| 275 | return EmitStoreThroughExtVectorComponentLValue(Src, Dst, Ty); |
Lauro Ramos Venancio | a0c5d0e | 2008-01-22 22:36:45 +0000 | [diff] [blame] | 276 | |
| 277 | if (Dst.isBitfield()) |
| 278 | return EmitStoreThroughBitfieldLValue(Src, Dst, Ty); |
| 279 | |
Lauro Ramos Venancio | 6553982 | 2008-01-22 22:38:35 +0000 | [diff] [blame] | 280 | assert(0 && "Unknown LValue type"); |
Chris Lattner | 017d6aa | 2007-08-03 16:28:33 +0000 | [diff] [blame] | 281 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 282 | |
| 283 | llvm::Value *DstAddr = Dst.getAddress(); |
Chris Lattner | 883f6a7 | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 284 | assert(Src.isScalar() && "Can't emit an agg store with this method"); |
| 285 | // FIXME: Handle volatility etc. |
Chris Lattner | 9b65551 | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 286 | const llvm::Type *SrcTy = Src.getScalarVal()->getType(); |
Christopher Lamb | ddc23f3 | 2007-12-17 01:11:20 +0000 | [diff] [blame] | 287 | const llvm::PointerType *DstPtr = cast<llvm::PointerType>(DstAddr->getType()); |
| 288 | const llvm::Type *AddrTy = DstPtr->getElementType(); |
| 289 | unsigned AS = DstPtr->getAddressSpace(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 290 | |
Chris Lattner | 883f6a7 | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 291 | if (AddrTy != SrcTy) |
Christopher Lamb | ddc23f3 | 2007-12-17 01:11:20 +0000 | [diff] [blame] | 292 | DstAddr = Builder.CreateBitCast(DstAddr, |
| 293 | llvm::PointerType::get(SrcTy, AS), |
Chris Lattner | 883f6a7 | 2007-08-11 00:04:45 +0000 | [diff] [blame] | 294 | "storetmp"); |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 295 | Builder.CreateStore(Src.getScalarVal(), DstAddr, Dst.isVolatileQualified()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 296 | } |
| 297 | |
Lauro Ramos Venancio | a0c5d0e | 2008-01-22 22:36:45 +0000 | [diff] [blame] | 298 | void CodeGenFunction::EmitStoreThroughBitfieldLValue(RValue Src, LValue Dst, |
| 299 | QualType Ty) { |
| 300 | unsigned short StartBit = Dst.getBitfieldStartBit(); |
| 301 | unsigned short BitfieldSize = Dst.getBitfieldSize(); |
| 302 | llvm::Value *Ptr = Dst.getBitfieldAddr(); |
Lauro Ramos Venancio | a0c5d0e | 2008-01-22 22:36:45 +0000 | [diff] [blame] | 303 | |
| 304 | llvm::Value *NewVal = Src.getScalarVal(); |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 305 | llvm::Value *OldVal = Builder.CreateLoad(Ptr, Dst.isVolatileQualified(), |
| 306 | "tmp"); |
Lauro Ramos Venancio | a0c5d0e | 2008-01-22 22:36:45 +0000 | [diff] [blame] | 307 | |
Eli Friedman | 316bb1b | 2008-05-17 20:03:47 +0000 | [diff] [blame] | 308 | // The bitfield type and the normal type differ when the storage sizes |
| 309 | // differ (currently just _Bool). |
| 310 | const llvm::Type *EltTy = OldVal->getType(); |
| 311 | unsigned EltTySize = CGM.getTargetData().getABITypeSizeInBits(EltTy); |
| 312 | |
| 313 | NewVal = Builder.CreateIntCast(NewVal, EltTy, false, "tmp"); |
| 314 | |
| 315 | // Move the bits into the appropriate location |
Lauro Ramos Venancio | a0c5d0e | 2008-01-22 22:36:45 +0000 | [diff] [blame] | 316 | llvm::Value *ShAmt = llvm::ConstantInt::get(EltTy, StartBit); |
| 317 | NewVal = Builder.CreateShl(NewVal, ShAmt, "tmp"); |
| 318 | |
| 319 | llvm::Constant *Mask = llvm::ConstantInt::get( |
| 320 | llvm::APInt::getBitsSet(EltTySize, StartBit, |
Dan Gohman | d254f00 | 2008-02-12 21:49:34 +0000 | [diff] [blame] | 321 | StartBit + BitfieldSize)); |
Lauro Ramos Venancio | a0c5d0e | 2008-01-22 22:36:45 +0000 | [diff] [blame] | 322 | |
| 323 | // Mask out any bits that shouldn't be set in the result. |
| 324 | NewVal = Builder.CreateAnd(NewVal, Mask, "tmp"); |
| 325 | |
| 326 | // Next, mask out the bits this bit-field should include from the old value. |
| 327 | Mask = llvm::ConstantExpr::getNot(Mask); |
| 328 | OldVal = Builder.CreateAnd(OldVal, Mask, "tmp"); |
| 329 | |
| 330 | // Finally, merge the two together and store it. |
| 331 | NewVal = Builder.CreateOr(OldVal, NewVal, "tmp"); |
| 332 | |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 333 | Builder.CreateStore(NewVal, Ptr, Dst.isVolatileQualified()); |
Lauro Ramos Venancio | a0c5d0e | 2008-01-22 22:36:45 +0000 | [diff] [blame] | 334 | } |
| 335 | |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 336 | void CodeGenFunction::EmitStoreThroughExtVectorComponentLValue(RValue Src, |
| 337 | LValue Dst, |
| 338 | QualType Ty) { |
Chris Lattner | 017d6aa | 2007-08-03 16:28:33 +0000 | [diff] [blame] | 339 | // This access turns into a read/modify/write of the vector. Load the input |
| 340 | // value now. |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 341 | llvm::Value *Vec = Builder.CreateLoad(Dst.getExtVectorAddr(), |
| 342 | Dst.isVolatileQualified(), "tmp"); |
Nate Begeman | 8a99764 | 2008-05-09 06:41:27 +0000 | [diff] [blame] | 343 | const llvm::Constant *Elts = Dst.getExtVectorElts(); |
Chris Lattner | 017d6aa | 2007-08-03 16:28:33 +0000 | [diff] [blame] | 344 | |
Chris Lattner | 9b65551 | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 345 | llvm::Value *SrcVal = Src.getScalarVal(); |
Chris Lattner | 017d6aa | 2007-08-03 16:28:33 +0000 | [diff] [blame] | 346 | |
Chris Lattner | 7e6b51b | 2007-08-03 16:37:04 +0000 | [diff] [blame] | 347 | if (const VectorType *VTy = Ty->getAsVectorType()) { |
| 348 | unsigned NumSrcElts = VTy->getNumElements(); |
| 349 | |
| 350 | // Extract/Insert each element. |
| 351 | for (unsigned i = 0; i != NumSrcElts; ++i) { |
| 352 | llvm::Value *Elt = llvm::ConstantInt::get(llvm::Type::Int32Ty, i); |
| 353 | Elt = Builder.CreateExtractElement(SrcVal, Elt, "tmp"); |
| 354 | |
Dan Gohman | 4f8d123 | 2008-05-22 00:50:06 +0000 | [diff] [blame] | 355 | unsigned Idx = getAccessedFieldNo(i, Elts); |
Chris Lattner | 7e6b51b | 2007-08-03 16:37:04 +0000 | [diff] [blame] | 356 | llvm::Value *OutIdx = llvm::ConstantInt::get(llvm::Type::Int32Ty, Idx); |
| 357 | Vec = Builder.CreateInsertElement(Vec, Elt, OutIdx, "tmp"); |
| 358 | } |
| 359 | } else { |
| 360 | // If the Src is a scalar (not a vector) it must be updating one element. |
Dan Gohman | 4f8d123 | 2008-05-22 00:50:06 +0000 | [diff] [blame] | 361 | unsigned InIdx = getAccessedFieldNo(0, Elts); |
Chris Lattner | 017d6aa | 2007-08-03 16:28:33 +0000 | [diff] [blame] | 362 | llvm::Value *Elt = llvm::ConstantInt::get(llvm::Type::Int32Ty, InIdx); |
| 363 | Vec = Builder.CreateInsertElement(Vec, SrcVal, Elt, "tmp"); |
Chris Lattner | 017d6aa | 2007-08-03 16:28:33 +0000 | [diff] [blame] | 364 | } |
| 365 | |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 366 | Builder.CreateStore(Vec, Dst.getExtVectorAddr(), Dst.isVolatileQualified()); |
Chris Lattner | 017d6aa | 2007-08-03 16:28:33 +0000 | [diff] [blame] | 367 | } |
| 368 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 369 | |
| 370 | LValue CodeGenFunction::EmitDeclRefLValue(const DeclRefExpr *E) { |
Steve Naroff | 248a753 | 2008-04-15 22:42:06 +0000 | [diff] [blame] | 371 | const VarDecl *VD = dyn_cast<VarDecl>(E->getDecl()); |
| 372 | |
| 373 | if (VD && (VD->isBlockVarDecl() || isa<ParmVarDecl>(VD))) { |
Lauro Ramos Venancio | fea90b8 | 2008-02-16 22:30:38 +0000 | [diff] [blame] | 374 | if (VD->getStorageClass() == VarDecl::Extern) |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 375 | return LValue::MakeAddr(CGM.GetAddrOfGlobalVar(VD, false), |
| 376 | E->getType().getCVRQualifiers()); |
Lauro Ramos Venancio | fea90b8 | 2008-02-16 22:30:38 +0000 | [diff] [blame] | 377 | else { |
Steve Naroff | 248a753 | 2008-04-15 22:42:06 +0000 | [diff] [blame] | 378 | llvm::Value *V = LocalDeclMap[VD]; |
Lauro Ramos Venancio | fea90b8 | 2008-02-16 22:30:38 +0000 | [diff] [blame] | 379 | assert(V && "BlockVarDecl not entered in LocalDeclMap?"); |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 380 | return LValue::MakeAddr(V, E->getType().getCVRQualifiers()); |
Lauro Ramos Venancio | fea90b8 | 2008-02-16 22:30:38 +0000 | [diff] [blame] | 381 | } |
Steve Naroff | 248a753 | 2008-04-15 22:42:06 +0000 | [diff] [blame] | 382 | } else if (VD && VD->isFileVarDecl()) { |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 383 | return LValue::MakeAddr(CGM.GetAddrOfGlobalVar(VD, false), |
| 384 | E->getType().getCVRQualifiers()); |
Steve Naroff | 248a753 | 2008-04-15 22:42:06 +0000 | [diff] [blame] | 385 | } else if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(E->getDecl())) { |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 386 | return LValue::MakeAddr(CGM.GetAddrOfFunctionDecl(FD, false), |
| 387 | E->getType().getCVRQualifiers()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 388 | } |
| 389 | assert(0 && "Unimp declref"); |
Chris Lattner | b1776cb | 2007-09-16 19:23:47 +0000 | [diff] [blame] | 390 | //an invalid LValue, but the assert will |
| 391 | //ensure that this point is never reached. |
| 392 | return LValue(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | LValue CodeGenFunction::EmitUnaryOpLValue(const UnaryOperator *E) { |
| 396 | // __extension__ doesn't affect lvalue-ness. |
| 397 | if (E->getOpcode() == UnaryOperator::Extension) |
| 398 | return EmitLValue(E->getSubExpr()); |
| 399 | |
Chris Lattner | 7da36f6 | 2007-10-30 22:53:42 +0000 | [diff] [blame] | 400 | switch (E->getOpcode()) { |
| 401 | default: assert(0 && "Unknown unary operator lvalue!"); |
| 402 | case UnaryOperator::Deref: |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 403 | return LValue::MakeAddr(EmitScalarExpr(E->getSubExpr()), |
| 404 | E->getSubExpr()->getType().getCanonicalType()->getAsPointerType() |
| 405 | ->getPointeeType().getCVRQualifiers()); |
Chris Lattner | 7da36f6 | 2007-10-30 22:53:42 +0000 | [diff] [blame] | 406 | case UnaryOperator::Real: |
| 407 | case UnaryOperator::Imag: |
| 408 | LValue LV = EmitLValue(E->getSubExpr()); |
Chris Lattner | 36b6a0a | 2008-03-19 05:19:41 +0000 | [diff] [blame] | 409 | unsigned Idx = E->getOpcode() == UnaryOperator::Imag; |
| 410 | return LValue::MakeAddr(Builder.CreateStructGEP(LV.getAddress(), |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 411 | Idx, "idx"),E->getSubExpr()->getType().getCVRQualifiers()); |
Chris Lattner | 7da36f6 | 2007-10-30 22:53:42 +0000 | [diff] [blame] | 412 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | LValue CodeGenFunction::EmitStringLiteralLValue(const StringLiteral *E) { |
| 416 | assert(!E->isWide() && "FIXME: Wide strings not supported yet!"); |
Eli Friedman | 922696f | 2008-05-19 17:51:16 +0000 | [diff] [blame] | 417 | // Get the string data |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 418 | const char *StrData = E->getStrData(); |
| 419 | unsigned Len = E->getByteLength(); |
Chris Lattner | 45e8cbd | 2007-11-28 05:34:05 +0000 | [diff] [blame] | 420 | std::string StringLiteral(StrData, StrData+Len); |
Eli Friedman | 922696f | 2008-05-19 17:51:16 +0000 | [diff] [blame] | 421 | |
| 422 | // Resize the string to the right size |
| 423 | const ConstantArrayType *CAT = E->getType()->getAsConstantArrayType(); |
| 424 | uint64_t RealLen = CAT->getSize().getZExtValue(); |
| 425 | StringLiteral.resize(RealLen, '\0'); |
| 426 | |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 427 | return LValue::MakeAddr(CGM.GetAddrOfConstantString(StringLiteral),0); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 428 | } |
| 429 | |
Anders Carlsson | 2274266 | 2007-07-21 05:21:51 +0000 | [diff] [blame] | 430 | LValue CodeGenFunction::EmitPreDefinedLValue(const PreDefinedExpr *E) { |
Chris Lattner | c8aa5f1 | 2008-04-04 04:07:35 +0000 | [diff] [blame] | 431 | std::string FunctionName; |
| 432 | if(const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurFuncDecl)) { |
| 433 | FunctionName = FD->getName(); |
| 434 | } |
| 435 | else { |
| 436 | assert(0 && "Attempting to load predefined constant for invalid decl type"); |
| 437 | } |
Anders Carlsson | 2274266 | 2007-07-21 05:21:51 +0000 | [diff] [blame] | 438 | std::string GlobalVarName; |
| 439 | |
| 440 | switch (E->getIdentType()) { |
| 441 | default: |
| 442 | assert(0 && "unknown pre-defined ident type"); |
| 443 | case PreDefinedExpr::Func: |
| 444 | GlobalVarName = "__func__."; |
| 445 | break; |
| 446 | case PreDefinedExpr::Function: |
| 447 | GlobalVarName = "__FUNCTION__."; |
| 448 | break; |
| 449 | case PreDefinedExpr::PrettyFunction: |
| 450 | // FIXME:: Demangle C++ method names |
| 451 | GlobalVarName = "__PRETTY_FUNCTION__."; |
| 452 | break; |
| 453 | } |
| 454 | |
Chris Lattner | c8aa5f1 | 2008-04-04 04:07:35 +0000 | [diff] [blame] | 455 | GlobalVarName += FunctionName; |
Anders Carlsson | 2274266 | 2007-07-21 05:21:51 +0000 | [diff] [blame] | 456 | |
| 457 | // FIXME: Can cache/reuse these within the module. |
| 458 | llvm::Constant *C=llvm::ConstantArray::get(FunctionName); |
| 459 | |
| 460 | // Create a global variable for this. |
| 461 | C = new llvm::GlobalVariable(C->getType(), true, |
| 462 | llvm::GlobalValue::InternalLinkage, |
| 463 | C, GlobalVarName, CurFn->getParent()); |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 464 | return LValue::MakeAddr(C,0); |
Anders Carlsson | 2274266 | 2007-07-21 05:21:51 +0000 | [diff] [blame] | 465 | } |
| 466 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 467 | LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) { |
Ted Kremenek | 2324512 | 2007-08-20 16:18:38 +0000 | [diff] [blame] | 468 | // The index must always be an integer, which is not an aggregate. Emit it. |
Chris Lattner | 7f02f72 | 2007-08-24 05:35:26 +0000 | [diff] [blame] | 469 | llvm::Value *Idx = EmitScalarExpr(E->getIdx()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 470 | |
| 471 | // If the base is a vector type, then we are forming a vector element lvalue |
| 472 | // with this subscript. |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 473 | if (E->getBase()->getType()->isVectorType()) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 474 | // Emit the vector as an lvalue to get its address. |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 475 | LValue LHS = EmitLValue(E->getBase()); |
Ted Kremenek | 2324512 | 2007-08-20 16:18:38 +0000 | [diff] [blame] | 476 | assert(LHS.isSimple() && "Can only subscript lvalue vectors here!"); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 477 | // FIXME: This should properly sign/zero/extend or truncate Idx to i32. |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 478 | return LValue::MakeVectorElt(LHS.getAddress(), Idx, |
| 479 | E->getBase()->getType().getCVRQualifiers()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 480 | } |
| 481 | |
Ted Kremenek | 2324512 | 2007-08-20 16:18:38 +0000 | [diff] [blame] | 482 | // The base must be a pointer, which is not an aggregate. Emit it. |
Chris Lattner | 7f02f72 | 2007-08-24 05:35:26 +0000 | [diff] [blame] | 483 | llvm::Value *Base = EmitScalarExpr(E->getBase()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 484 | |
Ted Kremenek | 2324512 | 2007-08-20 16:18:38 +0000 | [diff] [blame] | 485 | // Extend or truncate the index type to 32 or 64-bits. |
Chris Lattner | d4f0802 | 2007-08-08 17:43:05 +0000 | [diff] [blame] | 486 | QualType IdxTy = E->getIdx()->getType(); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 487 | bool IdxSigned = IdxTy->isSignedIntegerType(); |
| 488 | unsigned IdxBitwidth = cast<llvm::IntegerType>(Idx->getType())->getBitWidth(); |
| 489 | if (IdxBitwidth != LLVMPointerWidth) |
| 490 | Idx = Builder.CreateIntCast(Idx, llvm::IntegerType::get(LLVMPointerWidth), |
| 491 | IdxSigned, "idxprom"); |
| 492 | |
| 493 | // We know that the pointer points to a type of the correct size, unless the |
| 494 | // size is a VLA. |
Eli Friedman | 3c2b317 | 2008-02-15 12:20:59 +0000 | [diff] [blame] | 495 | if (!E->getType()->isConstantSizeType()) |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 496 | assert(0 && "VLA idx not implemented"); |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 497 | return LValue::MakeAddr(Builder.CreateGEP(Base, Idx, "arrayidx"), |
| 498 | E->getBase()->getType().getCanonicalType()->getAsPointerType() |
| 499 | ->getPointeeType().getCVRQualifiers()); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 500 | } |
| 501 | |
Nate Begeman | 3b8d116 | 2008-05-13 21:03:02 +0000 | [diff] [blame] | 502 | static |
| 503 | llvm::Constant *GenerateConstantVector(llvm::SmallVector<unsigned, 4> &Elts) { |
| 504 | llvm::SmallVector<llvm::Constant *, 4> CElts; |
| 505 | |
| 506 | for (unsigned i = 0, e = Elts.size(); i != e; ++i) |
| 507 | CElts.push_back(llvm::ConstantInt::get(llvm::Type::Int32Ty, Elts[i])); |
| 508 | |
| 509 | return llvm::ConstantVector::get(&CElts[0], CElts.size()); |
| 510 | } |
| 511 | |
Chris Lattner | 349aaec | 2007-08-02 23:37:31 +0000 | [diff] [blame] | 512 | LValue CodeGenFunction:: |
Nate Begeman | 213541a | 2008-04-18 23:10:10 +0000 | [diff] [blame] | 513 | EmitExtVectorElementExpr(const ExtVectorElementExpr *E) { |
Chris Lattner | 349aaec | 2007-08-02 23:37:31 +0000 | [diff] [blame] | 514 | // Emit the base vector as an l-value. |
| 515 | LValue Base = EmitLValue(E->getBase()); |
Chris Lattner | 349aaec | 2007-08-02 23:37:31 +0000 | [diff] [blame] | 516 | |
Nate Begeman | 3b8d116 | 2008-05-13 21:03:02 +0000 | [diff] [blame] | 517 | // Encode the element access list into a vector of unsigned indices. |
| 518 | llvm::SmallVector<unsigned, 4> Indices; |
| 519 | E->getEncodedElementAccess(Indices); |
| 520 | |
| 521 | if (Base.isSimple()) { |
| 522 | llvm::Constant *CV = GenerateConstantVector(Indices); |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 523 | return LValue::MakeExtVectorElt(Base.getAddress(), CV, |
| 524 | E->getBase()->getType().getCVRQualifiers()); |
Nate Begeman | 3b8d116 | 2008-05-13 21:03:02 +0000 | [diff] [blame] | 525 | } |
| 526 | assert(Base.isExtVectorElt() && "Can only subscript lvalue vec elts here!"); |
| 527 | |
| 528 | llvm::Constant *BaseElts = Base.getExtVectorElts(); |
| 529 | llvm::SmallVector<llvm::Constant *, 4> CElts; |
| 530 | |
| 531 | for (unsigned i = 0, e = Indices.size(); i != e; ++i) { |
| 532 | if (isa<llvm::ConstantAggregateZero>(BaseElts)) |
| 533 | CElts.push_back(llvm::ConstantInt::get(llvm::Type::Int32Ty, 0)); |
| 534 | else |
| 535 | CElts.push_back(BaseElts->getOperand(Indices[i])); |
| 536 | } |
| 537 | llvm::Constant *CV = llvm::ConstantVector::get(&CElts[0], CElts.size()); |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 538 | return LValue::MakeExtVectorElt(Base.getExtVectorAddr(), CV, |
| 539 | E->getBase()->getType().getCVRQualifiers()); |
Chris Lattner | 349aaec | 2007-08-02 23:37:31 +0000 | [diff] [blame] | 540 | } |
| 541 | |
Devang Patel | b9b00ad | 2007-10-23 20:28:39 +0000 | [diff] [blame] | 542 | LValue CodeGenFunction::EmitMemberExpr(const MemberExpr *E) { |
Devang Patel | fe2419a | 2007-12-11 21:33:16 +0000 | [diff] [blame] | 543 | bool isUnion = false; |
Devang Patel | 126a856 | 2007-10-24 22:26:28 +0000 | [diff] [blame] | 544 | Expr *BaseExpr = E->getBase(); |
Devang Patel | 126a856 | 2007-10-24 22:26:28 +0000 | [diff] [blame] | 545 | llvm::Value *BaseValue = NULL; |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 546 | unsigned CVRQualifiers=0; |
| 547 | |
Chris Lattner | 12f65f6 | 2007-12-02 18:52:07 +0000 | [diff] [blame] | 548 | // If this is s.x, emit s as an lvalue. If it is s->x, emit s as a scalar. |
Devang Patel | fe2419a | 2007-12-11 21:33:16 +0000 | [diff] [blame] | 549 | if (E->isArrow()) { |
Devang Patel | 0a96118 | 2007-10-26 18:15:21 +0000 | [diff] [blame] | 550 | BaseValue = EmitScalarExpr(BaseExpr); |
Devang Patel | fe2419a | 2007-12-11 21:33:16 +0000 | [diff] [blame] | 551 | const PointerType *PTy = |
| 552 | cast<PointerType>(BaseExpr->getType().getCanonicalType()); |
| 553 | if (PTy->getPointeeType()->isUnionType()) |
| 554 | isUnion = true; |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 555 | CVRQualifiers = PTy->getPointeeType().getCVRQualifiers(); |
Devang Patel | fe2419a | 2007-12-11 21:33:16 +0000 | [diff] [blame] | 556 | } |
Chris Lattner | 12f65f6 | 2007-12-02 18:52:07 +0000 | [diff] [blame] | 557 | else { |
| 558 | LValue BaseLV = EmitLValue(BaseExpr); |
| 559 | // FIXME: this isn't right for bitfields. |
| 560 | BaseValue = BaseLV.getAddress(); |
Devang Patel | fe2419a | 2007-12-11 21:33:16 +0000 | [diff] [blame] | 561 | if (BaseExpr->getType()->isUnionType()) |
| 562 | isUnion = true; |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 563 | CVRQualifiers = BaseExpr->getType().getCVRQualifiers(); |
Chris Lattner | 12f65f6 | 2007-12-02 18:52:07 +0000 | [diff] [blame] | 564 | } |
Devang Patel | b9b00ad | 2007-10-23 20:28:39 +0000 | [diff] [blame] | 565 | |
| 566 | FieldDecl *Field = E->getMemberDecl(); |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 567 | return EmitLValueForField(BaseValue, Field, isUnion, CVRQualifiers); |
Eli Friedman | 472778e | 2008-02-09 08:50:58 +0000 | [diff] [blame] | 568 | } |
Devang Patel | b9b00ad | 2007-10-23 20:28:39 +0000 | [diff] [blame] | 569 | |
Eli Friedman | 472778e | 2008-02-09 08:50:58 +0000 | [diff] [blame] | 570 | LValue CodeGenFunction::EmitLValueForField(llvm::Value* BaseValue, |
| 571 | FieldDecl* Field, |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 572 | bool isUnion, |
| 573 | unsigned CVRQualifiers) |
Eli Friedman | 472778e | 2008-02-09 08:50:58 +0000 | [diff] [blame] | 574 | { |
| 575 | llvm::Value *V; |
| 576 | unsigned idx = CGM.getTypes().getLLVMFieldNo(Field); |
Lauro Ramos Venancio | d957aa0 | 2008-02-07 19:29:53 +0000 | [diff] [blame] | 577 | |
Eli Friedman | 1e86b34 | 2008-05-29 11:33:25 +0000 | [diff] [blame] | 578 | if (Field->isBitField()) { |
Eli Friedman | 316bb1b | 2008-05-17 20:03:47 +0000 | [diff] [blame] | 579 | // FIXME: CodeGenTypes should expose a method to get the appropriate |
| 580 | // type for FieldTy (the appropriate type is ABI-dependent). |
Eli Friedman | bfe08e0 | 2008-06-01 15:16:01 +0000 | [diff] [blame] | 581 | const llvm::Type *FieldTy = CGM.getTypes().ConvertTypeForMem(Field->getType()); |
Chris Lattner | 36b6a0a | 2008-03-19 05:19:41 +0000 | [diff] [blame] | 582 | const llvm::PointerType *BaseTy = |
Lauro Ramos Venancio | d957aa0 | 2008-02-07 19:29:53 +0000 | [diff] [blame] | 583 | cast<llvm::PointerType>(BaseValue->getType()); |
| 584 | unsigned AS = BaseTy->getAddressSpace(); |
| 585 | BaseValue = Builder.CreateBitCast(BaseValue, |
| 586 | llvm::PointerType::get(FieldTy, AS), |
| 587 | "tmp"); |
| 588 | V = Builder.CreateGEP(BaseValue, |
| 589 | llvm::ConstantInt::get(llvm::Type::Int32Ty, idx), |
| 590 | "tmp"); |
Eli Friedman | 1e86b34 | 2008-05-29 11:33:25 +0000 | [diff] [blame] | 591 | |
| 592 | CodeGenTypes::BitFieldInfo bitFieldInfo = |
| 593 | CGM.getTypes().getBitFieldInfo(Field); |
| 594 | return LValue::MakeBitfield(V, bitFieldInfo.Begin, bitFieldInfo.Size, |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 595 | Field->getType()->isSignedIntegerType(), |
| 596 | Field->getType().getCVRQualifiers()|CVRQualifiers); |
Lauro Ramos Venancio | d957aa0 | 2008-02-07 19:29:53 +0000 | [diff] [blame] | 597 | } |
Eli Friedman | bfe08e0 | 2008-06-01 15:16:01 +0000 | [diff] [blame] | 598 | |
Eli Friedman | 1e86b34 | 2008-05-29 11:33:25 +0000 | [diff] [blame] | 599 | V = Builder.CreateStructGEP(BaseValue, idx, "tmp"); |
| 600 | |
Devang Patel | abad06c | 2007-10-26 19:42:18 +0000 | [diff] [blame] | 601 | // Match union field type. |
Lauro Ramos Venancio | d957aa0 | 2008-02-07 19:29:53 +0000 | [diff] [blame] | 602 | if (isUnion) { |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 603 | const llvm::Type *FieldTy = |
| 604 | CGM.getTypes().ConvertTypeForMem(Field->getType()); |
Devang Patel | e9b8c0a | 2007-10-30 20:59:40 +0000 | [diff] [blame] | 605 | const llvm::PointerType * BaseTy = |
| 606 | cast<llvm::PointerType>(BaseValue->getType()); |
Eli Friedman | 788d571 | 2008-05-21 13:24:44 +0000 | [diff] [blame] | 607 | unsigned AS = BaseTy->getAddressSpace(); |
| 608 | V = Builder.CreateBitCast(V, |
| 609 | llvm::PointerType::get(FieldTy, AS), |
| 610 | "tmp"); |
Devang Patel | abad06c | 2007-10-26 19:42:18 +0000 | [diff] [blame] | 611 | } |
Lauro Ramos Venancio | 3b8c22d | 2008-01-22 20:17:04 +0000 | [diff] [blame] | 612 | |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 613 | return LValue::MakeAddr(V, |
| 614 | Field->getType().getCVRQualifiers()|CVRQualifiers); |
Devang Patel | b9b00ad | 2007-10-23 20:28:39 +0000 | [diff] [blame] | 615 | } |
| 616 | |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 617 | LValue CodeGenFunction::EmitCompoundLiteralLValue(const CompoundLiteralExpr* E) |
| 618 | { |
Eli Friedman | 06e863f | 2008-05-13 23:18:27 +0000 | [diff] [blame] | 619 | const llvm::Type *LTy = ConvertType(E->getType()); |
| 620 | llvm::Value *DeclPtr = CreateTempAlloca(LTy, ".compoundliteral"); |
| 621 | |
| 622 | const Expr* InitExpr = E->getInitializer(); |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 623 | LValue Result = LValue::MakeAddr(DeclPtr, E->getType().getCVRQualifiers()); |
Eli Friedman | 06e863f | 2008-05-13 23:18:27 +0000 | [diff] [blame] | 624 | |
| 625 | if (E->getType()->isComplexType()) { |
| 626 | EmitComplexExprIntoAddr(InitExpr, DeclPtr, false); |
| 627 | } else if (hasAggregateLLVMType(E->getType())) { |
| 628 | EmitAnyExpr(InitExpr, DeclPtr, false); |
| 629 | } else { |
| 630 | EmitStoreThroughLValue(EmitAnyExpr(InitExpr), Result, E->getType()); |
| 631 | } |
| 632 | |
| 633 | return Result; |
| 634 | } |
| 635 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 636 | //===--------------------------------------------------------------------===// |
| 637 | // Expression Emission |
| 638 | //===--------------------------------------------------------------------===// |
| 639 | |
Chris Lattner | 7016a70 | 2007-08-20 22:37:10 +0000 | [diff] [blame] | 640 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 641 | RValue CodeGenFunction::EmitCallExpr(const CallExpr *E) { |
Anders Carlsson | 022012e | 2007-08-20 18:05:56 +0000 | [diff] [blame] | 642 | if (const ImplicitCastExpr *IcExpr = |
| 643 | dyn_cast<const ImplicitCastExpr>(E->getCallee())) |
| 644 | if (const DeclRefExpr *DRExpr = |
| 645 | dyn_cast<const DeclRefExpr>(IcExpr->getSubExpr())) |
| 646 | if (const FunctionDecl *FDecl = |
| 647 | dyn_cast<const FunctionDecl>(DRExpr->getDecl())) |
| 648 | if (unsigned builtinID = FDecl->getIdentifier()->getBuiltinID()) |
| 649 | return EmitBuiltinExpr(builtinID, E); |
| 650 | |
Chris Lattner | 7f02f72 | 2007-08-24 05:35:26 +0000 | [diff] [blame] | 651 | llvm::Value *Callee = EmitScalarExpr(E->getCallee()); |
Eli Friedman | 5193b8a | 2008-01-30 01:32:06 +0000 | [diff] [blame] | 652 | return EmitCallExpr(Callee, E->getCallee()->getType(), |
| 653 | E->arg_begin(), E->getNumArgs()); |
Nate Begeman | e2ce1d9 | 2008-01-17 17:46:27 +0000 | [diff] [blame] | 654 | } |
| 655 | |
Eli Friedman | 5193b8a | 2008-01-30 01:32:06 +0000 | [diff] [blame] | 656 | RValue CodeGenFunction::EmitCallExpr(Expr *FnExpr, Expr *const *Args, |
| 657 | unsigned NumArgs) { |
Nate Begeman | e2ce1d9 | 2008-01-17 17:46:27 +0000 | [diff] [blame] | 658 | llvm::Value *Callee = EmitScalarExpr(FnExpr); |
Eli Friedman | 5193b8a | 2008-01-30 01:32:06 +0000 | [diff] [blame] | 659 | return EmitCallExpr(Callee, FnExpr->getType(), Args, NumArgs); |
Chris Lattner | c5e940f | 2007-08-31 04:44:06 +0000 | [diff] [blame] | 660 | } |
| 661 | |
Christopher Lamb | 22c940e | 2007-12-29 05:02:41 +0000 | [diff] [blame] | 662 | LValue CodeGenFunction::EmitCallExprLValue(const CallExpr *E) { |
| 663 | // Can only get l-value for call expression returning aggregate type |
| 664 | RValue RV = EmitCallExpr(E); |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 665 | // FIXME: can this be volatile? |
| 666 | return LValue::MakeAddr(RV.getAggregateAddr(), |
| 667 | E->getType().getCVRQualifiers()); |
Christopher Lamb | 22c940e | 2007-12-29 05:02:41 +0000 | [diff] [blame] | 668 | } |
| 669 | |
Chris Lattner | 391d77a | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 670 | LValue CodeGenFunction::EmitObjCIvarRefLValue(const ObjCIvarRefExpr *E) { |
| 671 | // Objective-C objects are traditionally C structures with their layout |
| 672 | // defined at compile-time. In some implementations, their layout is not |
| 673 | // defined until run time in order to allow instance variables to be added to |
| 674 | // a class without recompiling all of the subclasses. If this is the case |
| 675 | // then the CGObjCRuntime subclass must return true to LateBoundIvars and |
| 676 | // implement the lookup itself. |
Chris Lattner | ce5605e | 2008-03-30 23:25:33 +0000 | [diff] [blame] | 677 | if (CGM.getObjCRuntime()->LateBoundIVars()) { |
Chris Lattner | 391d77a | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 678 | assert(0 && "FIXME: Implement support for late-bound instance variables"); |
| 679 | return LValue(); // Not reached. |
| 680 | } |
Chris Lattner | ce5605e | 2008-03-30 23:25:33 +0000 | [diff] [blame] | 681 | |
| 682 | // Get a structure type for the object |
| 683 | QualType ExprTy = E->getBase()->getType(); |
| 684 | const llvm::Type *ObjectType = ConvertType(ExprTy); |
| 685 | // TODO: Add a special case for isa (index 0) |
| 686 | // Work out which index the ivar is |
| 687 | const ObjCIvarDecl *Decl = E->getDecl(); |
| 688 | unsigned Index = CGM.getTypes().getLLVMFieldNo(Decl); |
Chris Lattner | 391d77a | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 689 | |
Chris Lattner | ce5605e | 2008-03-30 23:25:33 +0000 | [diff] [blame] | 690 | // Get object pointer and coerce object pointer to correct type. |
| 691 | llvm::Value *Object = EmitLValue(E->getBase()).getAddress(); |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 692 | // FIXME: Volatility |
Chris Lattner | c8aa5f1 | 2008-04-04 04:07:35 +0000 | [diff] [blame] | 693 | Object = Builder.CreateLoad(Object, E->getDecl()->getName()); |
Chris Lattner | ce5605e | 2008-03-30 23:25:33 +0000 | [diff] [blame] | 694 | if (Object->getType() != ObjectType) |
| 695 | Object = Builder.CreateBitCast(Object, ObjectType); |
Chris Lattner | c8aa5f1 | 2008-04-04 04:07:35 +0000 | [diff] [blame] | 696 | |
Chris Lattner | ce5605e | 2008-03-30 23:25:33 +0000 | [diff] [blame] | 697 | |
| 698 | // Return a pointer to the right element. |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 699 | // FIXME: volatile |
Chris Lattner | ce5605e | 2008-03-30 23:25:33 +0000 | [diff] [blame] | 700 | return LValue::MakeAddr(Builder.CreateStructGEP(Object, Index, |
Eli Friedman | 1e692ac | 2008-06-13 23:01:12 +0000 | [diff] [blame^] | 701 | Decl->getName()),0); |
Chris Lattner | 391d77a | 2008-03-30 23:03:07 +0000 | [diff] [blame] | 702 | } |
| 703 | |
Nate Begeman | e2ce1d9 | 2008-01-17 17:46:27 +0000 | [diff] [blame] | 704 | RValue CodeGenFunction::EmitCallExpr(llvm::Value *Callee, QualType FnType, |
Eli Friedman | 5193b8a | 2008-01-30 01:32:06 +0000 | [diff] [blame] | 705 | Expr *const *ArgExprs, unsigned NumArgs) { |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 706 | // The callee type will always be a pointer to function type, get the function |
| 707 | // type. |
Nate Begeman | e2ce1d9 | 2008-01-17 17:46:27 +0000 | [diff] [blame] | 708 | FnType = cast<PointerType>(FnType.getCanonicalType())->getPointeeType(); |
| 709 | QualType ResultType = cast<FunctionType>(FnType)->getResultType(); |
Eli Friedman | 5193b8a | 2008-01-30 01:32:06 +0000 | [diff] [blame] | 710 | |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 711 | llvm::SmallVector<llvm::Value*, 16> Args; |
| 712 | |
Chris Lattner | cc666af | 2007-08-10 17:02:28 +0000 | [diff] [blame] | 713 | // Handle struct-return functions by passing a pointer to the location that |
| 714 | // we would like to return into. |
Nate Begeman | e2ce1d9 | 2008-01-17 17:46:27 +0000 | [diff] [blame] | 715 | if (hasAggregateLLVMType(ResultType)) { |
Chris Lattner | cc666af | 2007-08-10 17:02:28 +0000 | [diff] [blame] | 716 | // Create a temporary alloca to hold the result of the call. :( |
Nate Begeman | e2ce1d9 | 2008-01-17 17:46:27 +0000 | [diff] [blame] | 717 | Args.push_back(CreateTempAlloca(ConvertType(ResultType))); |
Chris Lattner | cc666af | 2007-08-10 17:02:28 +0000 | [diff] [blame] | 718 | // FIXME: set the stret attribute on the argument. |
| 719 | } |
| 720 | |
Nate Begeman | e2ce1d9 | 2008-01-17 17:46:27 +0000 | [diff] [blame] | 721 | for (unsigned i = 0, e = NumArgs; i != e; ++i) { |
| 722 | QualType ArgTy = ArgExprs[i]->getType(); |
Eli Friedman | 472778e | 2008-02-09 08:50:58 +0000 | [diff] [blame] | 723 | |
Chris Lattner | 660ac12 | 2007-08-26 22:55:13 +0000 | [diff] [blame] | 724 | if (!hasAggregateLLVMType(ArgTy)) { |
| 725 | // Scalar argument is passed by-value. |
Nate Begeman | e2ce1d9 | 2008-01-17 17:46:27 +0000 | [diff] [blame] | 726 | Args.push_back(EmitScalarExpr(ArgExprs[i])); |
Chris Lattner | 9b2dc28 | 2008-04-04 16:54:41 +0000 | [diff] [blame] | 727 | } else if (ArgTy->isAnyComplexType()) { |
Chris Lattner | 660ac12 | 2007-08-26 22:55:13 +0000 | [diff] [blame] | 728 | // Make a temporary alloca to pass the argument. |
| 729 | llvm::Value *DestMem = CreateTempAlloca(ConvertType(ArgTy)); |
Nate Begeman | e2ce1d9 | 2008-01-17 17:46:27 +0000 | [diff] [blame] | 730 | EmitComplexExprIntoAddr(ArgExprs[i], DestMem, false); |
Chris Lattner | 660ac12 | 2007-08-26 22:55:13 +0000 | [diff] [blame] | 731 | Args.push_back(DestMem); |
| 732 | } else { |
| 733 | llvm::Value *DestMem = CreateTempAlloca(ConvertType(ArgTy)); |
Nate Begeman | e2ce1d9 | 2008-01-17 17:46:27 +0000 | [diff] [blame] | 734 | EmitAggExpr(ArgExprs[i], DestMem, false); |
Chris Lattner | 660ac12 | 2007-08-26 22:55:13 +0000 | [diff] [blame] | 735 | Args.push_back(DestMem); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 736 | } |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 737 | } |
| 738 | |
Nate Begeman | ec9426c | 2008-03-09 03:09:36 +0000 | [diff] [blame] | 739 | llvm::CallInst *CI = Builder.CreateCall(Callee,&Args[0],&Args[0]+Args.size()); |
Eli Friedman | ff4a2d9 | 2008-06-01 15:54:49 +0000 | [diff] [blame] | 740 | |
| 741 | // Note that there is parallel code in SetFunctionAttributes in CodeGenModule |
| 742 | llvm::SmallVector<llvm::ParamAttrsWithIndex, 8> ParamAttrList; |
| 743 | if (hasAggregateLLVMType(ResultType)) |
| 744 | ParamAttrList.push_back( |
| 745 | llvm::ParamAttrsWithIndex::get(1, llvm::ParamAttr::StructRet)); |
| 746 | unsigned increment = hasAggregateLLVMType(ResultType) ? 2 : 1; |
| 747 | for (unsigned i = 0; i < NumArgs; i++) { |
| 748 | QualType ParamType = ArgExprs[i]->getType(); |
| 749 | unsigned ParamAttrs = 0; |
| 750 | if (ParamType->isRecordType()) |
| 751 | ParamAttrs |= llvm::ParamAttr::ByVal; |
| 752 | if (ParamType->isSignedIntegerType() && ParamType->isPromotableIntegerType()) |
| 753 | ParamAttrs |= llvm::ParamAttr::SExt; |
| 754 | if (ParamType->isUnsignedIntegerType() && ParamType->isPromotableIntegerType()) |
| 755 | ParamAttrs |= llvm::ParamAttr::ZExt; |
| 756 | if (ParamAttrs) |
| 757 | ParamAttrList.push_back(llvm::ParamAttrsWithIndex::get(i + increment, |
| 758 | ParamAttrs)); |
| 759 | } |
| 760 | CI->setParamAttrs(llvm::PAListPtr::get(ParamAttrList.begin(), |
| 761 | ParamAttrList.size())); |
| 762 | |
Nate Begeman | ec9426c | 2008-03-09 03:09:36 +0000 | [diff] [blame] | 763 | if (const llvm::Function *F = dyn_cast<llvm::Function>(Callee)) |
| 764 | CI->setCallingConv(F->getCallingConv()); |
| 765 | if (CI->getType() != llvm::Type::VoidTy) |
| 766 | CI->setName("call"); |
Chris Lattner | 9b2dc28 | 2008-04-04 16:54:41 +0000 | [diff] [blame] | 767 | else if (ResultType->isAnyComplexType()) |
Chris Lattner | 9b65551 | 2007-08-31 22:49:20 +0000 | [diff] [blame] | 768 | return RValue::getComplex(LoadComplexFromAddr(Args[0], false)); |
Nate Begeman | e2ce1d9 | 2008-01-17 17:46:27 +0000 | [diff] [blame] | 769 | else if (hasAggregateLLVMType(ResultType)) |
Chris Lattner | cc666af | 2007-08-10 17:02:28 +0000 | [diff] [blame] | 770 | // Struct return. |
| 771 | return RValue::getAggregate(Args[0]); |
Chris Lattner | 2202bce | 2007-11-30 17:56:23 +0000 | [diff] [blame] | 772 | else { |
| 773 | // void return. |
Nate Begeman | e2ce1d9 | 2008-01-17 17:46:27 +0000 | [diff] [blame] | 774 | assert(ResultType->isVoidType() && "Should only have a void expr here"); |
Nate Begeman | ec9426c | 2008-03-09 03:09:36 +0000 | [diff] [blame] | 775 | CI = 0; |
Chris Lattner | 2202bce | 2007-11-30 17:56:23 +0000 | [diff] [blame] | 776 | } |
Chris Lattner | cc666af | 2007-08-10 17:02:28 +0000 | [diff] [blame] | 777 | |
Nate Begeman | ec9426c | 2008-03-09 03:09:36 +0000 | [diff] [blame] | 778 | return RValue::get(CI); |
Reid Spencer | 5f016e2 | 2007-07-11 17:01:13 +0000 | [diff] [blame] | 779 | } |