blob: a000b223311ea31f74a45f01285dfe2aeeb56eb4 [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;
Fariborz Jahanian09105f52009-08-20 17:02:02 +000028 class ObjCImplicitSetterGetterRefExpr;
Daniel Dunbar85c59ed2008-08-29 08:11:39 +000029
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000030namespace CodeGen {
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +000031 class CGBitFieldInfo;
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000032
33/// RValue - This trivial value class is used to represent the result of an
34/// expression that is evaluated. It can be one of three things: either a
35/// simple LLVM SSA value, a pair of SSA values for complex numbers, or the
36/// address of an aggregate value in memory.
37class RValue {
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000038 enum Flavor { Scalar, Complex, Aggregate };
Mike Stump1eb44332009-09-09 15:08:12 +000039
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000040 // Stores first value and flavor.
41 llvm::PointerIntPair<llvm::Value *, 2, Flavor> V1;
42 // Stores second value and volatility.
43 llvm::PointerIntPair<llvm::Value *, 1, bool> V2;
44
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000045public:
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000046 bool isScalar() const { return V1.getInt() == Scalar; }
47 bool isComplex() const { return V1.getInt() == Complex; }
48 bool isAggregate() const { return V1.getInt() == Aggregate; }
Mike Stump1eb44332009-09-09 15:08:12 +000049
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000050 bool isVolatileQualified() const { return V2.getInt(); }
Mike Stump8b3d93a2009-05-23 20:21:36 +000051
Mike Stump519202d2009-11-03 16:11:57 +000052 /// getScalarVal() - Return the Value* of this scalar value.
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000053 llvm::Value *getScalarVal() const {
54 assert(isScalar() && "Not a scalar!");
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000055 return V1.getPointer();
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000056 }
57
58 /// getComplexVal - Return the real/imag components of this complex value.
59 ///
60 std::pair<llvm::Value *, llvm::Value *> getComplexVal() const {
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000061 return std::make_pair(V1.getPointer(), V2.getPointer());
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000062 }
Mike Stump1eb44332009-09-09 15:08:12 +000063
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000064 /// getAggregateAddr() - Return the Value* of the address of the aggregate.
65 llvm::Value *getAggregateAddr() const {
66 assert(isAggregate() && "Not an aggregate!");
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000067 return V1.getPointer();
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000068 }
Mike Stump1eb44332009-09-09 15:08:12 +000069
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000070 static RValue get(llvm::Value *V) {
71 RValue ER;
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000072 ER.V1.setPointer(V);
73 ER.V1.setInt(Scalar);
74 ER.V2.setInt(false);
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000075 return ER;
76 }
77 static RValue getComplex(llvm::Value *V1, llvm::Value *V2) {
78 RValue ER;
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000079 ER.V1.setPointer(V1);
80 ER.V2.setPointer(V2);
81 ER.V1.setInt(Complex);
82 ER.V2.setInt(false);
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000083 return ER;
84 }
85 static RValue getComplex(const std::pair<llvm::Value *, llvm::Value *> &C) {
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000086 return getComplex(C.first, C.second);
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000087 }
Mike Stump8b3d93a2009-05-23 20:21:36 +000088 // FIXME: Aggregate rvalues need to retain information about whether they are
89 // volatile or not. Remove default to find all places that probably get this
90 // wrong.
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000091 static RValue getAggregate(llvm::Value *V, bool Volatile = false) {
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000092 RValue ER;
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000093 ER.V1.setPointer(V);
94 ER.V1.setInt(Aggregate);
95 ER.V2.setInt(Volatile);
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000096 return ER;
97 }
98};
99
100
101/// LValue - This represents an lvalue references. Because C/C++ allow
102/// bitfields, this is not a simple LLVM pointer, it may be a pointer plus a
103/// bitrange.
104class LValue {
105 // FIXME: alignment?
Mike Stump1eb44332009-09-09 15:08:12 +0000106
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000107 enum {
108 Simple, // This is a normal l-value, use getAddress().
109 VectorElt, // This is a vector element l-value (V[i]), use getVector*
110 BitField, // This is a bitfield l-value, use getBitfield*.
Daniel Dunbar85c59ed2008-08-29 08:11:39 +0000111 ExtVectorElt, // This is an extended vector subset, use getExtVectorComp
Fariborz Jahanian43f44702008-11-22 22:30:21 +0000112 PropertyRef, // This is an Objective-C property reference, use
Daniel Dunbar85c59ed2008-08-29 08:11:39 +0000113 // getPropertyRefExpr
Fariborz Jahanian43f44702008-11-22 22:30:21 +0000114 KVCRef // This is an objective-c 'implicit' property ref,
115 // use getKVCRefExpr
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000116 } LVType;
Fariborz Jahanian58626502008-11-19 00:59:10 +0000117
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000118 llvm::Value *V;
Mike Stump1eb44332009-09-09 15:08:12 +0000119
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000120 union {
121 // Index into a vector subscript: V[i]
122 llvm::Value *VectorIdx;
123
124 // ExtVector element subset: V.xyx
125 llvm::Constant *VectorElts;
Mike Stump1eb44332009-09-09 15:08:12 +0000126
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000127 // BitField start bit and size
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000128 const CGBitFieldInfo *BitFieldInfo;
Daniel Dunbar85c59ed2008-08-29 08:11:39 +0000129
130 // Obj-C property reference expression
131 const ObjCPropertyRefExpr *PropertyRefExpr;
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000132
Fariborz Jahanian43f44702008-11-22 22:30:21 +0000133 // ObjC 'implicit' property reference expression
Fariborz Jahanian09105f52009-08-20 17:02:02 +0000134 const ObjCImplicitSetterGetterRefExpr *KVCRefExpr;
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000135 };
136
John McCall0953e762009-09-24 19:53:00 +0000137 // 'const' is unused here
138 Qualifiers Quals;
Fariborz Jahanian58626502008-11-19 00:59:10 +0000139
Daniel Dunbar9f4f7cf2010-08-21 02:39:23 +0000140 /// The alignment to use when accessing this lvalue.
Daniel Dunbar77c05902010-08-26 06:02:12 +0000141 unsigned short Alignment;
Daniel Dunbar9f4f7cf2010-08-21 02:39:23 +0000142
Fariborz Jahaniand1cc8042008-11-20 20:53:20 +0000143 // objective-c's ivar
144 bool Ivar:1;
Fariborz Jahanian1c1afc42009-09-18 00:04:00 +0000145
146 // objective-c's ivar is an array
Fariborz Jahanianfd02ed72009-09-21 18:54:29 +0000147 bool ObjIsArray:1;
Mike Stump1eb44332009-09-09 15:08:12 +0000148
Fariborz Jahanian4f676ed2009-02-21 00:30:43 +0000149 // LValue is non-gc'able for any reason, including being a parameter or local
150 // variable.
151 bool NonGC: 1;
Fariborz Jahaniand1cc8042008-11-20 20:53:20 +0000152
Fariborz Jahanianbf63b872009-05-04 23:27:20 +0000153 // Lvalue is a global reference of an objective-c object
154 bool GlobalObjCRef : 1;
Fariborz Jahanian021a7a62010-07-20 20:30:03 +0000155
156 // Lvalue is a thread local reference
157 bool ThreadLocalRef : 1;
Fariborz Jahanianbf63b872009-05-04 23:27:20 +0000158
Fariborz Jahanian6c7a1f32009-09-24 22:25:38 +0000159 Expr *BaseIvarExp;
Dan Gohman3d5aff52010-10-14 23:06:10 +0000160
161 /// TBAAInfo - TBAA information to attach to dereferences of this LValue.
162 llvm::MDNode *TBAAInfo;
163
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000164private:
Dan Gohman3d5aff52010-10-14 23:06:10 +0000165 void Initialize(Qualifiers Quals, unsigned Alignment = 0,
166 llvm::MDNode *TBAAInfo = 0) {
John McCall0953e762009-09-24 19:53:00 +0000167 this->Quals = Quals;
Daniel Dunbar9f4f7cf2010-08-21 02:39:23 +0000168 this->Alignment = Alignment;
169 assert(this->Alignment == Alignment && "Alignment exceeds allowed max!");
170
171 // Initialize Objective-C flags.
John McCall0953e762009-09-24 19:53:00 +0000172 this->Ivar = this->ObjIsArray = this->NonGC = this->GlobalObjCRef = false;
Fariborz Jahanian021a7a62010-07-20 20:30:03 +0000173 this->ThreadLocalRef = false;
Fariborz Jahanian6c7a1f32009-09-24 22:25:38 +0000174 this->BaseIvarExp = 0;
Dan Gohman3d5aff52010-10-14 23:06:10 +0000175 this->TBAAInfo = TBAAInfo;
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000176 }
Mike Stump1eb44332009-09-09 15:08:12 +0000177
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000178public:
179 bool isSimple() const { return LVType == Simple; }
180 bool isVectorElt() const { return LVType == VectorElt; }
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000181 bool isBitField() const { return LVType == BitField; }
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000182 bool isExtVectorElt() const { return LVType == ExtVectorElt; }
Daniel Dunbar85c59ed2008-08-29 08:11:39 +0000183 bool isPropertyRef() const { return LVType == PropertyRef; }
Fariborz Jahanian43f44702008-11-22 22:30:21 +0000184 bool isKVCRef() const { return LVType == KVCRef; }
Daniel Dunbar85c59ed2008-08-29 08:11:39 +0000185
John McCall0953e762009-09-24 19:53:00 +0000186 bool isVolatileQualified() const { return Quals.hasVolatile(); }
187 bool isRestrictQualified() const { return Quals.hasRestrict(); }
188 unsigned getVRQualifiers() const {
189 return Quals.getCVRQualifiers() & ~Qualifiers::Const;
Chris Lattner1bd885e2009-02-16 22:25:49 +0000190 }
Mike Stump1eb44332009-09-09 15:08:12 +0000191
Fariborz Jahaniand1cc8042008-11-20 20:53:20 +0000192 bool isObjCIvar() const { return Ivar; }
Daniel Dunbar3491b3d2010-08-21 03:51:29 +0000193 void setObjCIvar(bool Value) { Ivar = Value; }
194
Fariborz Jahanianfd02ed72009-09-21 18:54:29 +0000195 bool isObjCArray() const { return ObjIsArray; }
Daniel Dunbar3491b3d2010-08-21 03:51:29 +0000196 void setObjCArray(bool Value) { ObjIsArray = Value; }
Daniel Dunbarea619172010-08-21 03:22:38 +0000197
Fariborz Jahanian4f676ed2009-02-21 00:30:43 +0000198 bool isNonGC () const { return NonGC; }
Daniel Dunbarea619172010-08-21 03:22:38 +0000199 void setNonGC(bool Value) { NonGC = Value; }
200
Fariborz Jahanianbf63b872009-05-04 23:27:20 +0000201 bool isGlobalObjCRef() const { return GlobalObjCRef; }
Daniel Dunbar3491b3d2010-08-21 03:51:29 +0000202 void setGlobalObjCRef(bool Value) { GlobalObjCRef = Value; }
203
Fariborz Jahanian021a7a62010-07-20 20:30:03 +0000204 bool isThreadLocalRef() const { return ThreadLocalRef; }
Daniel Dunbar3491b3d2010-08-21 03:51:29 +0000205 void setThreadLocalRef(bool Value) { ThreadLocalRef = Value;}
206
207 bool isObjCWeak() const {
208 return Quals.getObjCGCAttr() == Qualifiers::Weak;
209 }
210 bool isObjCStrong() const {
211 return Quals.getObjCGCAttr() == Qualifiers::Strong;
212 }
Fariborz Jahanian6c7a1f32009-09-24 22:25:38 +0000213
214 Expr *getBaseIvarExp() const { return BaseIvarExp; }
215 void setBaseIvarExp(Expr *V) { BaseIvarExp = V; }
Mon P Wangc6a38a42009-07-22 03:08:17 +0000216
Dan Gohman3d5aff52010-10-14 23:06:10 +0000217 llvm::MDNode *getTBAAInfo() const { return TBAAInfo; }
218 void setTBAAInfo(llvm::MDNode *N) { TBAAInfo = N; }
219
Daniel Dunbar99ad7df2010-08-21 03:29:54 +0000220 const Qualifiers &getQuals() const { return Quals; }
221 Qualifiers &getQuals() { return Quals; }
222
John McCall0953e762009-09-24 19:53:00 +0000223 unsigned getAddressSpace() const { return Quals.getAddressSpace(); }
Mon P Wangc6a38a42009-07-22 03:08:17 +0000224
Daniel Dunbar9f4f7cf2010-08-21 02:39:23 +0000225 unsigned getAlignment() const { return Alignment; }
226
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000227 // simple lvalue
228 llvm::Value *getAddress() const { assert(isSimple()); return V; }
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000229
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000230 // vector elt lvalue
231 llvm::Value *getVectorAddr() const { assert(isVectorElt()); return V; }
232 llvm::Value *getVectorIdx() const { assert(isVectorElt()); return VectorIdx; }
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000233
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000234 // extended vector elements.
235 llvm::Value *getExtVectorAddr() const { assert(isExtVectorElt()); return V; }
236 llvm::Constant *getExtVectorElts() const {
237 assert(isExtVectorElt());
238 return VectorElts;
239 }
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000240
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000241 // bitfield lvalue
Daniel Dunbar7f289642010-04-08 02:59:45 +0000242 llvm::Value *getBitFieldBaseAddr() const {
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000243 assert(isBitField());
244 return V;
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000245 }
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000246 const CGBitFieldInfo &getBitFieldInfo() const {
247 assert(isBitField());
248 return *BitFieldInfo;
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000249 }
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000250
Daniel Dunbar85c59ed2008-08-29 08:11:39 +0000251 // property ref lvalue
252 const ObjCPropertyRefExpr *getPropertyRefExpr() const {
253 assert(isPropertyRef());
254 return PropertyRefExpr;
255 }
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000256
Fariborz Jahanian43f44702008-11-22 22:30:21 +0000257 // 'implicit' property ref lvalue
Fariborz Jahanian09105f52009-08-20 17:02:02 +0000258 const ObjCImplicitSetterGetterRefExpr *getKVCRefExpr() const {
Fariborz Jahanian43f44702008-11-22 22:30:21 +0000259 assert(isKVCRef());
260 return KVCRefExpr;
261 }
262
Daniel Dunbarf1fbda32010-08-21 03:58:45 +0000263 static LValue MakeAddr(llvm::Value *V, QualType T, unsigned Alignment,
Dan Gohman3d5aff52010-10-14 23:06:10 +0000264 ASTContext &Context,
265 llvm::MDNode *TBAAInfo = 0) {
Daniel Dunbarf1fbda32010-08-21 03:58:45 +0000266 Qualifiers Quals = Context.getCanonicalType(T).getQualifiers();
267 Quals.setObjCGCAttr(Context.getObjCGCAttrKind(T));
268
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000269 LValue R;
270 R.LVType = Simple;
271 R.V = V;
Dan Gohman3d5aff52010-10-14 23:06:10 +0000272 R.Initialize(Quals, Alignment, TBAAInfo);
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000273 return R;
274 }
Mike Stump1eb44332009-09-09 15:08:12 +0000275
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000276 static LValue MakeVectorElt(llvm::Value *Vec, llvm::Value *Idx,
John McCall0953e762009-09-24 19:53:00 +0000277 unsigned CVR) {
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000278 LValue R;
279 R.LVType = VectorElt;
280 R.V = Vec;
281 R.VectorIdx = Idx;
Daniel Dunbarde988812010-08-21 02:31:58 +0000282 R.Initialize(Qualifiers::fromCVRMask(CVR));
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000283 return R;
284 }
Mike Stump1eb44332009-09-09 15:08:12 +0000285
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000286 static LValue MakeExtVectorElt(llvm::Value *Vec, llvm::Constant *Elts,
John McCall0953e762009-09-24 19:53:00 +0000287 unsigned CVR) {
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000288 LValue R;
289 R.LVType = ExtVectorElt;
290 R.V = Vec;
291 R.VectorElts = Elts;
Daniel Dunbarde988812010-08-21 02:31:58 +0000292 R.Initialize(Qualifiers::fromCVRMask(CVR));
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000293 return R;
294 }
295
Daniel Dunbar7f289642010-04-08 02:59:45 +0000296 /// \brief Create a new object to represent a bit-field access.
297 ///
298 /// \param BaseValue - The base address of the structure containing the
299 /// bit-field.
300 /// \param Info - The information describing how to perform the bit-field
301 /// access.
302 static LValue MakeBitfield(llvm::Value *BaseValue, const CGBitFieldInfo &Info,
Daniel Dunbarefbf4872010-04-06 01:07:44 +0000303 unsigned CVR) {
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000304 LValue R;
305 R.LVType = BitField;
Daniel Dunbar7f289642010-04-08 02:59:45 +0000306 R.V = BaseValue;
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000307 R.BitFieldInfo = &Info;
Daniel Dunbarde988812010-08-21 02:31:58 +0000308 R.Initialize(Qualifiers::fromCVRMask(CVR));
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000309 return R;
310 }
Daniel Dunbar85c59ed2008-08-29 08:11:39 +0000311
Mike Stumpf5408fe2009-05-16 07:57:57 +0000312 // FIXME: It is probably bad that we aren't emitting the target when we build
313 // the lvalue. However, this complicates the code a bit, and I haven't figured
314 // out how to make it go wrong yet.
Daniel Dunbar85c59ed2008-08-29 08:11:39 +0000315 static LValue MakePropertyRef(const ObjCPropertyRefExpr *E,
John McCall0953e762009-09-24 19:53:00 +0000316 unsigned CVR) {
Daniel Dunbar85c59ed2008-08-29 08:11:39 +0000317 LValue R;
318 R.LVType = PropertyRef;
319 R.PropertyRefExpr = E;
Daniel Dunbarde988812010-08-21 02:31:58 +0000320 R.Initialize(Qualifiers::fromCVRMask(CVR));
Daniel Dunbar85c59ed2008-08-29 08:11:39 +0000321 return R;
322 }
Mike Stump1eb44332009-09-09 15:08:12 +0000323
324 static LValue MakeKVCRef(const ObjCImplicitSetterGetterRefExpr *E,
John McCall0953e762009-09-24 19:53:00 +0000325 unsigned CVR) {
Fariborz Jahanian43f44702008-11-22 22:30:21 +0000326 LValue R;
327 R.LVType = KVCRef;
328 R.KVCRefExpr = E;
Daniel Dunbarde988812010-08-21 02:31:58 +0000329 R.Initialize(Qualifiers::fromCVRMask(CVR));
Fariborz Jahanian43f44702008-11-22 22:30:21 +0000330 return R;
331 }
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000332};
333
John McCall558d2ab2010-09-15 10:14:12 +0000334/// An aggregate value slot.
335class AggValueSlot {
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000336 /// The address.
John McCall6fa29162010-09-16 03:16:41 +0000337 llvm::Value *Addr;
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000338
339 // Associated flags.
340 bool VolatileFlag : 1;
341 bool LifetimeFlag : 1;
342 bool RequiresGCollection : 1;
John McCall558d2ab2010-09-15 10:14:12 +0000343
344public:
345 /// ignored - Returns an aggregate value slot indicating that the
346 /// aggregate value is being ignored.
347 static AggValueSlot ignored() {
348 AggValueSlot AV;
John McCall6fa29162010-09-16 03:16:41 +0000349 AV.Addr = 0;
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000350 AV.VolatileFlag = AV.LifetimeFlag = AV.RequiresGCollection = 0;
John McCall558d2ab2010-09-15 10:14:12 +0000351 return AV;
352 }
353
354 /// forAddr - Make a slot for an aggregate value.
355 ///
356 /// \param Volatile - true if the slot should be volatile-initialized
357 /// \param LifetimeExternallyManaged - true if the slot's lifetime
358 /// is being externally managed; false if a destructor should be
359 /// registered for any temporaries evaluated into the slot
John McCalld1a5f132010-09-16 03:13:23 +0000360 /// \param RequiresGCollection - true if the slot is located
361 /// somewhere that ObjC GC calls should be emitted for
John McCall558d2ab2010-09-15 10:14:12 +0000362 static AggValueSlot forAddr(llvm::Value *Addr, bool Volatile,
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000363 bool LifetimeExternallyManaged,
364 bool RequiresGCollection=false) {
John McCall558d2ab2010-09-15 10:14:12 +0000365 AggValueSlot AV;
John McCall6fa29162010-09-16 03:16:41 +0000366 AV.Addr = Addr;
John McCalld1a5f132010-09-16 03:13:23 +0000367 AV.VolatileFlag = Volatile;
368 AV.LifetimeFlag = LifetimeExternallyManaged;
369 AV.RequiresGCollection = RequiresGCollection;
John McCall558d2ab2010-09-15 10:14:12 +0000370 return AV;
371 }
372
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000373 static AggValueSlot forLValue(LValue LV, bool LifetimeExternallyManaged,
374 bool RequiresGCollection=false) {
John McCall558d2ab2010-09-15 10:14:12 +0000375 return forAddr(LV.getAddress(), LV.isVolatileQualified(),
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000376 LifetimeExternallyManaged, RequiresGCollection);
John McCall558d2ab2010-09-15 10:14:12 +0000377 }
Fariborz Jahanian8a970052010-10-22 22:05:03 +0000378
John McCall558d2ab2010-09-15 10:14:12 +0000379 bool isLifetimeExternallyManaged() const {
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000380 return LifetimeFlag;
John McCall558d2ab2010-09-15 10:14:12 +0000381 }
382 void setLifetimeExternallyManaged() {
John McCalld1a5f132010-09-16 03:13:23 +0000383 LifetimeFlag = true;
John McCall558d2ab2010-09-15 10:14:12 +0000384 }
385
386 bool isVolatile() const {
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000387 return VolatileFlag;
John McCall558d2ab2010-09-15 10:14:12 +0000388 }
389
John McCalld1a5f132010-09-16 03:13:23 +0000390 bool requiresGCollection() const {
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000391 return RequiresGCollection;
392 }
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000393
John McCall558d2ab2010-09-15 10:14:12 +0000394 llvm::Value *getAddr() const {
John McCall6fa29162010-09-16 03:16:41 +0000395 return Addr;
John McCall558d2ab2010-09-15 10:14:12 +0000396 }
397
398 bool isIgnored() const {
John McCall6fa29162010-09-16 03:16:41 +0000399 return Addr == 0;
John McCall558d2ab2010-09-15 10:14:12 +0000400 }
401
402 RValue asRValue() const {
403 return RValue::getAggregate(getAddr(), isVolatile());
404 }
405
406};
407
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000408} // end namespace CodeGen
409} // end namespace clang
410
411#endif