blob: 7f77d552032ac1cabf43287e31b88ad1029b939b [file] [log] [blame]
Daniel Dunbar2eecaab2008-08-23 03:10:25 +00001//===-- CGValue.h - LLVM CodeGen wrappers for llvm::Value* ------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// These classes implement wrappers around llvm::Value in order to
11// fully represent the range of values for C L- and R- values.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef CLANG_CODEGEN_CGVALUE_H
16#define CLANG_CODEGEN_CGVALUE_H
17
Daniel Dunbar5cf8bfe2010-08-21 02:53:44 +000018#include "clang/AST/ASTContext.h"
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000019#include "clang/AST/Type.h"
20
Daniel Dunbar46f45b92008-09-09 01:06:48 +000021namespace llvm {
22 class Constant;
23 class Value;
24}
25
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000026namespace clang {
Daniel Dunbar85c59ed2008-08-29 08:11:39 +000027 class ObjCPropertyRefExpr;
28
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000029namespace CodeGen {
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +000030 class CGBitFieldInfo;
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000031
32/// RValue - This trivial value class is used to represent the result of an
33/// expression that is evaluated. It can be one of three things: either a
34/// simple LLVM SSA value, a pair of SSA values for complex numbers, or the
35/// address of an aggregate value in memory.
36class RValue {
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000037 enum Flavor { Scalar, Complex, Aggregate };
Mike Stump1eb44332009-09-09 15:08:12 +000038
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000039 // Stores first value and flavor.
40 llvm::PointerIntPair<llvm::Value *, 2, Flavor> V1;
41 // Stores second value and volatility.
42 llvm::PointerIntPair<llvm::Value *, 1, bool> V2;
43
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000044public:
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000045 bool isScalar() const { return V1.getInt() == Scalar; }
46 bool isComplex() const { return V1.getInt() == Complex; }
47 bool isAggregate() const { return V1.getInt() == Aggregate; }
Mike Stump1eb44332009-09-09 15:08:12 +000048
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000049 bool isVolatileQualified() const { return V2.getInt(); }
Mike Stump8b3d93a2009-05-23 20:21:36 +000050
Mike Stump519202d2009-11-03 16:11:57 +000051 /// getScalarVal() - Return the Value* of this scalar value.
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000052 llvm::Value *getScalarVal() const {
53 assert(isScalar() && "Not a scalar!");
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000054 return V1.getPointer();
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000055 }
56
57 /// getComplexVal - Return the real/imag components of this complex value.
58 ///
59 std::pair<llvm::Value *, llvm::Value *> getComplexVal() const {
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000060 return std::make_pair(V1.getPointer(), V2.getPointer());
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000061 }
Mike Stump1eb44332009-09-09 15:08:12 +000062
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000063 /// getAggregateAddr() - Return the Value* of the address of the aggregate.
64 llvm::Value *getAggregateAddr() const {
65 assert(isAggregate() && "Not an aggregate!");
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000066 return V1.getPointer();
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000067 }
Mike Stump1eb44332009-09-09 15:08:12 +000068
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000069 static RValue get(llvm::Value *V) {
70 RValue ER;
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000071 ER.V1.setPointer(V);
72 ER.V1.setInt(Scalar);
73 ER.V2.setInt(false);
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000074 return ER;
75 }
76 static RValue getComplex(llvm::Value *V1, llvm::Value *V2) {
77 RValue ER;
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000078 ER.V1.setPointer(V1);
79 ER.V2.setPointer(V2);
80 ER.V1.setInt(Complex);
81 ER.V2.setInt(false);
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000082 return ER;
83 }
84 static RValue getComplex(const std::pair<llvm::Value *, llvm::Value *> &C) {
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000085 return getComplex(C.first, C.second);
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000086 }
Mike Stump8b3d93a2009-05-23 20:21:36 +000087 // FIXME: Aggregate rvalues need to retain information about whether they are
88 // volatile or not. Remove default to find all places that probably get this
89 // wrong.
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000090 static RValue getAggregate(llvm::Value *V, bool Volatile = false) {
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000091 RValue ER;
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000092 ER.V1.setPointer(V);
93 ER.V1.setInt(Aggregate);
94 ER.V2.setInt(Volatile);
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000095 return ER;
96 }
97};
98
99
100/// LValue - This represents an lvalue references. Because C/C++ allow
101/// bitfields, this is not a simple LLVM pointer, it may be a pointer plus a
102/// bitrange.
103class LValue {
104 // FIXME: alignment?
Mike Stump1eb44332009-09-09 15:08:12 +0000105
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000106 enum {
107 Simple, // This is a normal l-value, use getAddress().
108 VectorElt, // This is a vector element l-value (V[i]), use getVector*
109 BitField, // This is a bitfield l-value, use getBitfield*.
Daniel Dunbar85c59ed2008-08-29 08:11:39 +0000110 ExtVectorElt, // This is an extended vector subset, use getExtVectorComp
John McCall119a1c62010-12-04 02:32:38 +0000111 PropertyRef // This is an Objective-C property reference, use
Daniel Dunbar85c59ed2008-08-29 08:11:39 +0000112 // getPropertyRefExpr
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000113 } LVType;
Fariborz Jahanian58626502008-11-19 00:59:10 +0000114
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000115 llvm::Value *V;
Mike Stump1eb44332009-09-09 15:08:12 +0000116
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000117 union {
118 // Index into a vector subscript: V[i]
119 llvm::Value *VectorIdx;
120
121 // ExtVector element subset: V.xyx
122 llvm::Constant *VectorElts;
Mike Stump1eb44332009-09-09 15:08:12 +0000123
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000124 // BitField start bit and size
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000125 const CGBitFieldInfo *BitFieldInfo;
Daniel Dunbar85c59ed2008-08-29 08:11:39 +0000126
127 // Obj-C property reference expression
128 const ObjCPropertyRefExpr *PropertyRefExpr;
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000129 };
130
John McCall0953e762009-09-24 19:53:00 +0000131 // 'const' is unused here
132 Qualifiers Quals;
Fariborz Jahanian58626502008-11-19 00:59:10 +0000133
Daniel Dunbar9f4f7cf2010-08-21 02:39:23 +0000134 /// The alignment to use when accessing this lvalue.
Daniel Dunbar77c05902010-08-26 06:02:12 +0000135 unsigned short Alignment;
Daniel Dunbar9f4f7cf2010-08-21 02:39:23 +0000136
Fariborz Jahaniand1cc8042008-11-20 20:53:20 +0000137 // objective-c's ivar
138 bool Ivar:1;
Fariborz Jahanian1c1afc42009-09-18 00:04:00 +0000139
140 // objective-c's ivar is an array
Fariborz Jahanianfd02ed72009-09-21 18:54:29 +0000141 bool ObjIsArray:1;
Mike Stump1eb44332009-09-09 15:08:12 +0000142
Fariborz Jahanian4f676ed2009-02-21 00:30:43 +0000143 // LValue is non-gc'able for any reason, including being a parameter or local
144 // variable.
145 bool NonGC: 1;
Fariborz Jahaniand1cc8042008-11-20 20:53:20 +0000146
Fariborz Jahanianbf63b872009-05-04 23:27:20 +0000147 // Lvalue is a global reference of an objective-c object
148 bool GlobalObjCRef : 1;
Fariborz Jahanian021a7a62010-07-20 20:30:03 +0000149
150 // Lvalue is a thread local reference
151 bool ThreadLocalRef : 1;
Fariborz Jahanianbf63b872009-05-04 23:27:20 +0000152
Fariborz Jahanian6c7a1f32009-09-24 22:25:38 +0000153 Expr *BaseIvarExp;
Dan Gohman3d5aff52010-10-14 23:06:10 +0000154
155 /// TBAAInfo - TBAA information to attach to dereferences of this LValue.
156 llvm::MDNode *TBAAInfo;
157
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000158private:
Dan Gohman3d5aff52010-10-14 23:06:10 +0000159 void Initialize(Qualifiers Quals, unsigned Alignment = 0,
160 llvm::MDNode *TBAAInfo = 0) {
John McCall0953e762009-09-24 19:53:00 +0000161 this->Quals = Quals;
Daniel Dunbar9f4f7cf2010-08-21 02:39:23 +0000162 this->Alignment = Alignment;
163 assert(this->Alignment == Alignment && "Alignment exceeds allowed max!");
164
165 // Initialize Objective-C flags.
John McCall0953e762009-09-24 19:53:00 +0000166 this->Ivar = this->ObjIsArray = this->NonGC = this->GlobalObjCRef = false;
Fariborz Jahanian021a7a62010-07-20 20:30:03 +0000167 this->ThreadLocalRef = false;
Fariborz Jahanian6c7a1f32009-09-24 22:25:38 +0000168 this->BaseIvarExp = 0;
Dan Gohman3d5aff52010-10-14 23:06:10 +0000169 this->TBAAInfo = TBAAInfo;
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000170 }
Mike Stump1eb44332009-09-09 15:08:12 +0000171
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000172public:
173 bool isSimple() const { return LVType == Simple; }
174 bool isVectorElt() const { return LVType == VectorElt; }
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000175 bool isBitField() const { return LVType == BitField; }
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000176 bool isExtVectorElt() const { return LVType == ExtVectorElt; }
Daniel Dunbar85c59ed2008-08-29 08:11:39 +0000177 bool isPropertyRef() const { return LVType == PropertyRef; }
178
John McCall0953e762009-09-24 19:53:00 +0000179 bool isVolatileQualified() const { return Quals.hasVolatile(); }
180 bool isRestrictQualified() const { return Quals.hasRestrict(); }
181 unsigned getVRQualifiers() const {
182 return Quals.getCVRQualifiers() & ~Qualifiers::Const;
Chris Lattner1bd885e2009-02-16 22:25:49 +0000183 }
Mike Stump1eb44332009-09-09 15:08:12 +0000184
Fariborz Jahaniand1cc8042008-11-20 20:53:20 +0000185 bool isObjCIvar() const { return Ivar; }
Daniel Dunbar3491b3d2010-08-21 03:51:29 +0000186 void setObjCIvar(bool Value) { Ivar = Value; }
187
Fariborz Jahanianfd02ed72009-09-21 18:54:29 +0000188 bool isObjCArray() const { return ObjIsArray; }
Daniel Dunbar3491b3d2010-08-21 03:51:29 +0000189 void setObjCArray(bool Value) { ObjIsArray = Value; }
Daniel Dunbarea619172010-08-21 03:22:38 +0000190
Fariborz Jahanian4f676ed2009-02-21 00:30:43 +0000191 bool isNonGC () const { return NonGC; }
Daniel Dunbarea619172010-08-21 03:22:38 +0000192 void setNonGC(bool Value) { NonGC = Value; }
193
Fariborz Jahanianbf63b872009-05-04 23:27:20 +0000194 bool isGlobalObjCRef() const { return GlobalObjCRef; }
Daniel Dunbar3491b3d2010-08-21 03:51:29 +0000195 void setGlobalObjCRef(bool Value) { GlobalObjCRef = Value; }
196
Fariborz Jahanian021a7a62010-07-20 20:30:03 +0000197 bool isThreadLocalRef() const { return ThreadLocalRef; }
Daniel Dunbar3491b3d2010-08-21 03:51:29 +0000198 void setThreadLocalRef(bool Value) { ThreadLocalRef = Value;}
199
200 bool isObjCWeak() const {
201 return Quals.getObjCGCAttr() == Qualifiers::Weak;
202 }
203 bool isObjCStrong() const {
204 return Quals.getObjCGCAttr() == Qualifiers::Strong;
205 }
Fariborz Jahanian6c7a1f32009-09-24 22:25:38 +0000206
207 Expr *getBaseIvarExp() const { return BaseIvarExp; }
208 void setBaseIvarExp(Expr *V) { BaseIvarExp = V; }
Mon P Wangc6a38a42009-07-22 03:08:17 +0000209
Dan Gohman3d5aff52010-10-14 23:06:10 +0000210 llvm::MDNode *getTBAAInfo() const { return TBAAInfo; }
211 void setTBAAInfo(llvm::MDNode *N) { TBAAInfo = N; }
212
Daniel Dunbar99ad7df2010-08-21 03:29:54 +0000213 const Qualifiers &getQuals() const { return Quals; }
214 Qualifiers &getQuals() { return Quals; }
215
John McCall0953e762009-09-24 19:53:00 +0000216 unsigned getAddressSpace() const { return Quals.getAddressSpace(); }
Mon P Wangc6a38a42009-07-22 03:08:17 +0000217
Daniel Dunbar9f4f7cf2010-08-21 02:39:23 +0000218 unsigned getAlignment() const { return Alignment; }
219
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000220 // simple lvalue
221 llvm::Value *getAddress() const { assert(isSimple()); return V; }
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000222
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000223 // vector elt lvalue
224 llvm::Value *getVectorAddr() const { assert(isVectorElt()); return V; }
225 llvm::Value *getVectorIdx() const { assert(isVectorElt()); return VectorIdx; }
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000226
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000227 // extended vector elements.
228 llvm::Value *getExtVectorAddr() const { assert(isExtVectorElt()); return V; }
229 llvm::Constant *getExtVectorElts() const {
230 assert(isExtVectorElt());
231 return VectorElts;
232 }
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000233
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000234 // bitfield lvalue
Daniel Dunbar7f289642010-04-08 02:59:45 +0000235 llvm::Value *getBitFieldBaseAddr() const {
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000236 assert(isBitField());
237 return V;
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000238 }
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000239 const CGBitFieldInfo &getBitFieldInfo() const {
240 assert(isBitField());
241 return *BitFieldInfo;
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000242 }
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000243
Daniel Dunbar85c59ed2008-08-29 08:11:39 +0000244 // property ref lvalue
John McCall119a1c62010-12-04 02:32:38 +0000245 llvm::Value *getPropertyRefBaseAddr() const {
246 assert(isPropertyRef());
247 return V;
248 }
Daniel Dunbar85c59ed2008-08-29 08:11:39 +0000249 const ObjCPropertyRefExpr *getPropertyRefExpr() const {
250 assert(isPropertyRef());
251 return PropertyRefExpr;
252 }
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000253
Daniel Dunbarf1fbda32010-08-21 03:58:45 +0000254 static LValue MakeAddr(llvm::Value *V, QualType T, unsigned Alignment,
Dan Gohman3d5aff52010-10-14 23:06:10 +0000255 ASTContext &Context,
256 llvm::MDNode *TBAAInfo = 0) {
John McCall5808ce42011-02-03 08:15:49 +0000257 Qualifiers Quals = T.getQualifiers();
Daniel Dunbarf1fbda32010-08-21 03:58:45 +0000258 Quals.setObjCGCAttr(Context.getObjCGCAttrKind(T));
259
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000260 LValue R;
261 R.LVType = Simple;
262 R.V = V;
Dan Gohman3d5aff52010-10-14 23:06:10 +0000263 R.Initialize(Quals, Alignment, TBAAInfo);
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000264 return R;
265 }
Mike Stump1eb44332009-09-09 15:08:12 +0000266
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000267 static LValue MakeVectorElt(llvm::Value *Vec, llvm::Value *Idx,
John McCall0953e762009-09-24 19:53:00 +0000268 unsigned CVR) {
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000269 LValue R;
270 R.LVType = VectorElt;
271 R.V = Vec;
272 R.VectorIdx = Idx;
Daniel Dunbarde988812010-08-21 02:31:58 +0000273 R.Initialize(Qualifiers::fromCVRMask(CVR));
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000274 return R;
275 }
Mike Stump1eb44332009-09-09 15:08:12 +0000276
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000277 static LValue MakeExtVectorElt(llvm::Value *Vec, llvm::Constant *Elts,
John McCall0953e762009-09-24 19:53:00 +0000278 unsigned CVR) {
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000279 LValue R;
280 R.LVType = ExtVectorElt;
281 R.V = Vec;
282 R.VectorElts = Elts;
Daniel Dunbarde988812010-08-21 02:31:58 +0000283 R.Initialize(Qualifiers::fromCVRMask(CVR));
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000284 return R;
285 }
286
Daniel Dunbar7f289642010-04-08 02:59:45 +0000287 /// \brief Create a new object to represent a bit-field access.
288 ///
289 /// \param BaseValue - The base address of the structure containing the
290 /// bit-field.
291 /// \param Info - The information describing how to perform the bit-field
292 /// access.
293 static LValue MakeBitfield(llvm::Value *BaseValue, const CGBitFieldInfo &Info,
Daniel Dunbarefbf4872010-04-06 01:07:44 +0000294 unsigned CVR) {
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000295 LValue R;
296 R.LVType = BitField;
Daniel Dunbar7f289642010-04-08 02:59:45 +0000297 R.V = BaseValue;
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000298 R.BitFieldInfo = &Info;
Daniel Dunbarde988812010-08-21 02:31:58 +0000299 R.Initialize(Qualifiers::fromCVRMask(CVR));
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000300 return R;
301 }
Daniel Dunbar85c59ed2008-08-29 08:11:39 +0000302
Mike Stumpf5408fe2009-05-16 07:57:57 +0000303 // FIXME: It is probably bad that we aren't emitting the target when we build
304 // the lvalue. However, this complicates the code a bit, and I haven't figured
305 // out how to make it go wrong yet.
Daniel Dunbar85c59ed2008-08-29 08:11:39 +0000306 static LValue MakePropertyRef(const ObjCPropertyRefExpr *E,
John McCall119a1c62010-12-04 02:32:38 +0000307 llvm::Value *Base) {
Daniel Dunbar85c59ed2008-08-29 08:11:39 +0000308 LValue R;
309 R.LVType = PropertyRef;
John McCall119a1c62010-12-04 02:32:38 +0000310 R.V = Base;
Daniel Dunbar85c59ed2008-08-29 08:11:39 +0000311 R.PropertyRefExpr = E;
John McCall119a1c62010-12-04 02:32:38 +0000312 R.Initialize(Qualifiers());
Fariborz Jahanian43f44702008-11-22 22:30:21 +0000313 return R;
314 }
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000315};
316
John McCall558d2ab2010-09-15 10:14:12 +0000317/// An aggregate value slot.
318class AggValueSlot {
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000319 /// The address.
John McCall6fa29162010-09-16 03:16:41 +0000320 llvm::Value *Addr;
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000321
322 // Associated flags.
323 bool VolatileFlag : 1;
324 bool LifetimeFlag : 1;
325 bool RequiresGCollection : 1;
Chris Lattner1b726772010-12-02 07:07:26 +0000326
327 /// IsZeroed - This is set to true if the destination is known to be zero
328 /// before the assignment into it. This means that zero fields don't need to
329 /// be set.
330 bool IsZeroed : 1;
John McCall558d2ab2010-09-15 10:14:12 +0000331
332public:
333 /// ignored - Returns an aggregate value slot indicating that the
334 /// aggregate value is being ignored.
335 static AggValueSlot ignored() {
336 AggValueSlot AV;
John McCall6fa29162010-09-16 03:16:41 +0000337 AV.Addr = 0;
Chris Lattner1b726772010-12-02 07:07:26 +0000338 AV.VolatileFlag = AV.LifetimeFlag = AV.RequiresGCollection = AV.IsZeroed =0;
John McCall558d2ab2010-09-15 10:14:12 +0000339 return AV;
340 }
341
342 /// forAddr - Make a slot for an aggregate value.
343 ///
344 /// \param Volatile - true if the slot should be volatile-initialized
345 /// \param LifetimeExternallyManaged - true if the slot's lifetime
346 /// is being externally managed; false if a destructor should be
347 /// registered for any temporaries evaluated into the slot
John McCalld1a5f132010-09-16 03:13:23 +0000348 /// \param RequiresGCollection - true if the slot is located
349 /// somewhere that ObjC GC calls should be emitted for
John McCall558d2ab2010-09-15 10:14:12 +0000350 static AggValueSlot forAddr(llvm::Value *Addr, bool Volatile,
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000351 bool LifetimeExternallyManaged,
Chris Lattner1b726772010-12-02 07:07:26 +0000352 bool RequiresGCollection = false,
353 bool IsZeroed = false) {
John McCall558d2ab2010-09-15 10:14:12 +0000354 AggValueSlot AV;
John McCall6fa29162010-09-16 03:16:41 +0000355 AV.Addr = Addr;
John McCalld1a5f132010-09-16 03:13:23 +0000356 AV.VolatileFlag = Volatile;
357 AV.LifetimeFlag = LifetimeExternallyManaged;
358 AV.RequiresGCollection = RequiresGCollection;
Chris Lattner1b726772010-12-02 07:07:26 +0000359 AV.IsZeroed = IsZeroed;
John McCall558d2ab2010-09-15 10:14:12 +0000360 return AV;
361 }
362
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000363 static AggValueSlot forLValue(LValue LV, bool LifetimeExternallyManaged,
Chris Lattner1b726772010-12-02 07:07:26 +0000364 bool RequiresGCollection = false) {
John McCall558d2ab2010-09-15 10:14:12 +0000365 return forAddr(LV.getAddress(), LV.isVolatileQualified(),
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000366 LifetimeExternallyManaged, RequiresGCollection);
John McCall558d2ab2010-09-15 10:14:12 +0000367 }
Fariborz Jahanian8a970052010-10-22 22:05:03 +0000368
John McCall558d2ab2010-09-15 10:14:12 +0000369 bool isLifetimeExternallyManaged() const {
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000370 return LifetimeFlag;
John McCall558d2ab2010-09-15 10:14:12 +0000371 }
John McCall74fb0ed2010-11-17 00:07:33 +0000372 void setLifetimeExternallyManaged(bool Managed = true) {
373 LifetimeFlag = Managed;
John McCall558d2ab2010-09-15 10:14:12 +0000374 }
375
376 bool isVolatile() const {
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000377 return VolatileFlag;
John McCall558d2ab2010-09-15 10:14:12 +0000378 }
379
John McCalld1a5f132010-09-16 03:13:23 +0000380 bool requiresGCollection() const {
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000381 return RequiresGCollection;
382 }
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000383
John McCall558d2ab2010-09-15 10:14:12 +0000384 llvm::Value *getAddr() const {
John McCall6fa29162010-09-16 03:16:41 +0000385 return Addr;
John McCall558d2ab2010-09-15 10:14:12 +0000386 }
387
388 bool isIgnored() const {
John McCall6fa29162010-09-16 03:16:41 +0000389 return Addr == 0;
John McCall558d2ab2010-09-15 10:14:12 +0000390 }
391
392 RValue asRValue() const {
393 return RValue::getAggregate(getAddr(), isVolatile());
394 }
395
Chris Lattner1b726772010-12-02 07:07:26 +0000396 void setZeroed(bool V = true) { IsZeroed = V; }
397 bool isZeroed() const {
398 return IsZeroed;
399 }
John McCall558d2ab2010-09-15 10:14:12 +0000400};
401
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000402} // end namespace CodeGen
403} // end namespace clang
404
405#endif