blob: fd82be75580b690cf3f8882b6920ec4f8d298224 [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;
Fariborz Jahanian07ed93f2010-10-22 21:01:02 +000029 class CXXConstructExpr;
Daniel Dunbar85c59ed2008-08-29 08:11:39 +000030
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000031namespace CodeGen {
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +000032 class CGBitFieldInfo;
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000033
34/// RValue - This trivial value class is used to represent the result of an
35/// expression that is evaluated. It can be one of three things: either a
36/// simple LLVM SSA value, a pair of SSA values for complex numbers, or the
37/// address of an aggregate value in memory.
38class RValue {
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000039 enum Flavor { Scalar, Complex, Aggregate };
Mike Stump1eb44332009-09-09 15:08:12 +000040
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000041 // Stores first value and flavor.
42 llvm::PointerIntPair<llvm::Value *, 2, Flavor> V1;
43 // Stores second value and volatility.
44 llvm::PointerIntPair<llvm::Value *, 1, bool> V2;
45
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000046public:
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000047 bool isScalar() const { return V1.getInt() == Scalar; }
48 bool isComplex() const { return V1.getInt() == Complex; }
49 bool isAggregate() const { return V1.getInt() == Aggregate; }
Mike Stump1eb44332009-09-09 15:08:12 +000050
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000051 bool isVolatileQualified() const { return V2.getInt(); }
Mike Stump8b3d93a2009-05-23 20:21:36 +000052
Mike Stump519202d2009-11-03 16:11:57 +000053 /// getScalarVal() - Return the Value* of this scalar value.
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000054 llvm::Value *getScalarVal() const {
55 assert(isScalar() && "Not a scalar!");
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000056 return V1.getPointer();
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000057 }
58
59 /// getComplexVal - Return the real/imag components of this complex value.
60 ///
61 std::pair<llvm::Value *, llvm::Value *> getComplexVal() const {
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000062 return std::make_pair(V1.getPointer(), V2.getPointer());
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000063 }
Mike Stump1eb44332009-09-09 15:08:12 +000064
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000065 /// getAggregateAddr() - Return the Value* of the address of the aggregate.
66 llvm::Value *getAggregateAddr() const {
67 assert(isAggregate() && "Not an aggregate!");
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000068 return V1.getPointer();
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000069 }
Mike Stump1eb44332009-09-09 15:08:12 +000070
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000071 static RValue get(llvm::Value *V) {
72 RValue ER;
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000073 ER.V1.setPointer(V);
74 ER.V1.setInt(Scalar);
75 ER.V2.setInt(false);
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000076 return ER;
77 }
78 static RValue getComplex(llvm::Value *V1, llvm::Value *V2) {
79 RValue ER;
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000080 ER.V1.setPointer(V1);
81 ER.V2.setPointer(V2);
82 ER.V1.setInt(Complex);
83 ER.V2.setInt(false);
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000084 return ER;
85 }
86 static RValue getComplex(const std::pair<llvm::Value *, llvm::Value *> &C) {
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000087 return getComplex(C.first, C.second);
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000088 }
Mike Stump8b3d93a2009-05-23 20:21:36 +000089 // FIXME: Aggregate rvalues need to retain information about whether they are
90 // volatile or not. Remove default to find all places that probably get this
91 // wrong.
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000092 static RValue getAggregate(llvm::Value *V, bool Volatile = false) {
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000093 RValue ER;
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000094 ER.V1.setPointer(V);
95 ER.V1.setInt(Aggregate);
96 ER.V2.setInt(Volatile);
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000097 return ER;
98 }
99};
100
101
102/// LValue - This represents an lvalue references. Because C/C++ allow
103/// bitfields, this is not a simple LLVM pointer, it may be a pointer plus a
104/// bitrange.
105class LValue {
106 // FIXME: alignment?
Mike Stump1eb44332009-09-09 15:08:12 +0000107
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000108 enum {
109 Simple, // This is a normal l-value, use getAddress().
110 VectorElt, // This is a vector element l-value (V[i]), use getVector*
111 BitField, // This is a bitfield l-value, use getBitfield*.
Daniel Dunbar85c59ed2008-08-29 08:11:39 +0000112 ExtVectorElt, // This is an extended vector subset, use getExtVectorComp
Fariborz Jahanian43f44702008-11-22 22:30:21 +0000113 PropertyRef, // This is an Objective-C property reference, use
Daniel Dunbar85c59ed2008-08-29 08:11:39 +0000114 // getPropertyRefExpr
Fariborz Jahanian43f44702008-11-22 22:30:21 +0000115 KVCRef // This is an objective-c 'implicit' property ref,
116 // use getKVCRefExpr
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000117 } LVType;
Fariborz Jahanian58626502008-11-19 00:59:10 +0000118
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000119 llvm::Value *V;
Mike Stump1eb44332009-09-09 15:08:12 +0000120
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000121 union {
122 // Index into a vector subscript: V[i]
123 llvm::Value *VectorIdx;
124
125 // ExtVector element subset: V.xyx
126 llvm::Constant *VectorElts;
Mike Stump1eb44332009-09-09 15:08:12 +0000127
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000128 // BitField start bit and size
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000129 const CGBitFieldInfo *BitFieldInfo;
Daniel Dunbar85c59ed2008-08-29 08:11:39 +0000130
131 // Obj-C property reference expression
132 const ObjCPropertyRefExpr *PropertyRefExpr;
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000133
Fariborz Jahanian43f44702008-11-22 22:30:21 +0000134 // ObjC 'implicit' property reference expression
Fariborz Jahanian09105f52009-08-20 17:02:02 +0000135 const ObjCImplicitSetterGetterRefExpr *KVCRefExpr;
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000136 };
137
John McCall0953e762009-09-24 19:53:00 +0000138 // 'const' is unused here
139 Qualifiers Quals;
Fariborz Jahanian58626502008-11-19 00:59:10 +0000140
Daniel Dunbar9f4f7cf2010-08-21 02:39:23 +0000141 /// The alignment to use when accessing this lvalue.
Daniel Dunbar77c05902010-08-26 06:02:12 +0000142 unsigned short Alignment;
Daniel Dunbar9f4f7cf2010-08-21 02:39:23 +0000143
Fariborz Jahaniand1cc8042008-11-20 20:53:20 +0000144 // objective-c's ivar
145 bool Ivar:1;
Fariborz Jahanian1c1afc42009-09-18 00:04:00 +0000146
147 // objective-c's ivar is an array
Fariborz Jahanianfd02ed72009-09-21 18:54:29 +0000148 bool ObjIsArray:1;
Mike Stump1eb44332009-09-09 15:08:12 +0000149
Fariborz Jahanian4f676ed2009-02-21 00:30:43 +0000150 // LValue is non-gc'able for any reason, including being a parameter or local
151 // variable.
152 bool NonGC: 1;
Fariborz Jahaniand1cc8042008-11-20 20:53:20 +0000153
Fariborz Jahanianbf63b872009-05-04 23:27:20 +0000154 // Lvalue is a global reference of an objective-c object
155 bool GlobalObjCRef : 1;
Fariborz Jahanian021a7a62010-07-20 20:30:03 +0000156
157 // Lvalue is a thread local reference
158 bool ThreadLocalRef : 1;
Fariborz Jahanianbf63b872009-05-04 23:27:20 +0000159
Fariborz Jahanian6c7a1f32009-09-24 22:25:38 +0000160 Expr *BaseIvarExp;
Dan Gohman3d5aff52010-10-14 23:06:10 +0000161
162 /// TBAAInfo - TBAA information to attach to dereferences of this LValue.
163 llvm::MDNode *TBAAInfo;
164
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000165private:
Dan Gohman3d5aff52010-10-14 23:06:10 +0000166 void Initialize(Qualifiers Quals, unsigned Alignment = 0,
167 llvm::MDNode *TBAAInfo = 0) {
John McCall0953e762009-09-24 19:53:00 +0000168 this->Quals = Quals;
Daniel Dunbar9f4f7cf2010-08-21 02:39:23 +0000169 this->Alignment = Alignment;
170 assert(this->Alignment == Alignment && "Alignment exceeds allowed max!");
171
172 // Initialize Objective-C flags.
John McCall0953e762009-09-24 19:53:00 +0000173 this->Ivar = this->ObjIsArray = this->NonGC = this->GlobalObjCRef = false;
Fariborz Jahanian021a7a62010-07-20 20:30:03 +0000174 this->ThreadLocalRef = false;
Fariborz Jahanian6c7a1f32009-09-24 22:25:38 +0000175 this->BaseIvarExp = 0;
Dan Gohman3d5aff52010-10-14 23:06:10 +0000176 this->TBAAInfo = TBAAInfo;
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000177 }
Mike Stump1eb44332009-09-09 15:08:12 +0000178
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000179public:
180 bool isSimple() const { return LVType == Simple; }
181 bool isVectorElt() const { return LVType == VectorElt; }
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000182 bool isBitField() const { return LVType == BitField; }
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000183 bool isExtVectorElt() const { return LVType == ExtVectorElt; }
Daniel Dunbar85c59ed2008-08-29 08:11:39 +0000184 bool isPropertyRef() const { return LVType == PropertyRef; }
Fariborz Jahanian43f44702008-11-22 22:30:21 +0000185 bool isKVCRef() const { return LVType == KVCRef; }
Daniel Dunbar85c59ed2008-08-29 08:11:39 +0000186
John McCall0953e762009-09-24 19:53:00 +0000187 bool isVolatileQualified() const { return Quals.hasVolatile(); }
188 bool isRestrictQualified() const { return Quals.hasRestrict(); }
189 unsigned getVRQualifiers() const {
190 return Quals.getCVRQualifiers() & ~Qualifiers::Const;
Chris Lattner1bd885e2009-02-16 22:25:49 +0000191 }
Mike Stump1eb44332009-09-09 15:08:12 +0000192
Fariborz Jahaniand1cc8042008-11-20 20:53:20 +0000193 bool isObjCIvar() const { return Ivar; }
Daniel Dunbar3491b3d2010-08-21 03:51:29 +0000194 void setObjCIvar(bool Value) { Ivar = Value; }
195
Fariborz Jahanianfd02ed72009-09-21 18:54:29 +0000196 bool isObjCArray() const { return ObjIsArray; }
Daniel Dunbar3491b3d2010-08-21 03:51:29 +0000197 void setObjCArray(bool Value) { ObjIsArray = Value; }
Daniel Dunbarea619172010-08-21 03:22:38 +0000198
Fariborz Jahanian4f676ed2009-02-21 00:30:43 +0000199 bool isNonGC () const { return NonGC; }
Daniel Dunbarea619172010-08-21 03:22:38 +0000200 void setNonGC(bool Value) { NonGC = Value; }
201
Fariborz Jahanianbf63b872009-05-04 23:27:20 +0000202 bool isGlobalObjCRef() const { return GlobalObjCRef; }
Daniel Dunbar3491b3d2010-08-21 03:51:29 +0000203 void setGlobalObjCRef(bool Value) { GlobalObjCRef = Value; }
204
Fariborz Jahanian021a7a62010-07-20 20:30:03 +0000205 bool isThreadLocalRef() const { return ThreadLocalRef; }
Daniel Dunbar3491b3d2010-08-21 03:51:29 +0000206 void setThreadLocalRef(bool Value) { ThreadLocalRef = Value;}
207
208 bool isObjCWeak() const {
209 return Quals.getObjCGCAttr() == Qualifiers::Weak;
210 }
211 bool isObjCStrong() const {
212 return Quals.getObjCGCAttr() == Qualifiers::Strong;
213 }
Fariborz Jahanian6c7a1f32009-09-24 22:25:38 +0000214
215 Expr *getBaseIvarExp() const { return BaseIvarExp; }
216 void setBaseIvarExp(Expr *V) { BaseIvarExp = V; }
Mon P Wangc6a38a42009-07-22 03:08:17 +0000217
Dan Gohman3d5aff52010-10-14 23:06:10 +0000218 llvm::MDNode *getTBAAInfo() const { return TBAAInfo; }
219 void setTBAAInfo(llvm::MDNode *N) { TBAAInfo = N; }
220
Daniel Dunbar99ad7df2010-08-21 03:29:54 +0000221 const Qualifiers &getQuals() const { return Quals; }
222 Qualifiers &getQuals() { return Quals; }
223
John McCall0953e762009-09-24 19:53:00 +0000224 unsigned getAddressSpace() const { return Quals.getAddressSpace(); }
Mon P Wangc6a38a42009-07-22 03:08:17 +0000225
Daniel Dunbar9f4f7cf2010-08-21 02:39:23 +0000226 unsigned getAlignment() const { return Alignment; }
227
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000228 // simple lvalue
229 llvm::Value *getAddress() const { assert(isSimple()); return V; }
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000230
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000231 // vector elt lvalue
232 llvm::Value *getVectorAddr() const { assert(isVectorElt()); return V; }
233 llvm::Value *getVectorIdx() const { assert(isVectorElt()); return VectorIdx; }
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000234
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000235 // extended vector elements.
236 llvm::Value *getExtVectorAddr() const { assert(isExtVectorElt()); return V; }
237 llvm::Constant *getExtVectorElts() const {
238 assert(isExtVectorElt());
239 return VectorElts;
240 }
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000241
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000242 // bitfield lvalue
Daniel Dunbar7f289642010-04-08 02:59:45 +0000243 llvm::Value *getBitFieldBaseAddr() const {
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000244 assert(isBitField());
245 return V;
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000246 }
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000247 const CGBitFieldInfo &getBitFieldInfo() const {
248 assert(isBitField());
249 return *BitFieldInfo;
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000250 }
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000251
Daniel Dunbar85c59ed2008-08-29 08:11:39 +0000252 // property ref lvalue
253 const ObjCPropertyRefExpr *getPropertyRefExpr() const {
254 assert(isPropertyRef());
255 return PropertyRefExpr;
256 }
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000257
Fariborz Jahanian43f44702008-11-22 22:30:21 +0000258 // 'implicit' property ref lvalue
Fariborz Jahanian09105f52009-08-20 17:02:02 +0000259 const ObjCImplicitSetterGetterRefExpr *getKVCRefExpr() const {
Fariborz Jahanian43f44702008-11-22 22:30:21 +0000260 assert(isKVCRef());
261 return KVCRefExpr;
262 }
263
Daniel Dunbarf1fbda32010-08-21 03:58:45 +0000264 static LValue MakeAddr(llvm::Value *V, QualType T, unsigned Alignment,
Dan Gohman3d5aff52010-10-14 23:06:10 +0000265 ASTContext &Context,
266 llvm::MDNode *TBAAInfo = 0) {
Daniel Dunbarf1fbda32010-08-21 03:58:45 +0000267 Qualifiers Quals = Context.getCanonicalType(T).getQualifiers();
268 Quals.setObjCGCAttr(Context.getObjCGCAttrKind(T));
269
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000270 LValue R;
271 R.LVType = Simple;
272 R.V = V;
Dan Gohman3d5aff52010-10-14 23:06:10 +0000273 R.Initialize(Quals, Alignment, TBAAInfo);
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 MakeVectorElt(llvm::Value *Vec, llvm::Value *Idx,
John McCall0953e762009-09-24 19:53:00 +0000278 unsigned CVR) {
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000279 LValue R;
280 R.LVType = VectorElt;
281 R.V = Vec;
282 R.VectorIdx = Idx;
Daniel Dunbarde988812010-08-21 02:31:58 +0000283 R.Initialize(Qualifiers::fromCVRMask(CVR));
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000284 return R;
285 }
Mike Stump1eb44332009-09-09 15:08:12 +0000286
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000287 static LValue MakeExtVectorElt(llvm::Value *Vec, llvm::Constant *Elts,
John McCall0953e762009-09-24 19:53:00 +0000288 unsigned CVR) {
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000289 LValue R;
290 R.LVType = ExtVectorElt;
291 R.V = Vec;
292 R.VectorElts = Elts;
Daniel Dunbarde988812010-08-21 02:31:58 +0000293 R.Initialize(Qualifiers::fromCVRMask(CVR));
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000294 return R;
295 }
296
Daniel Dunbar7f289642010-04-08 02:59:45 +0000297 /// \brief Create a new object to represent a bit-field access.
298 ///
299 /// \param BaseValue - The base address of the structure containing the
300 /// bit-field.
301 /// \param Info - The information describing how to perform the bit-field
302 /// access.
303 static LValue MakeBitfield(llvm::Value *BaseValue, const CGBitFieldInfo &Info,
Daniel Dunbarefbf4872010-04-06 01:07:44 +0000304 unsigned CVR) {
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000305 LValue R;
306 R.LVType = BitField;
Daniel Dunbar7f289642010-04-08 02:59:45 +0000307 R.V = BaseValue;
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000308 R.BitFieldInfo = &Info;
Daniel Dunbarde988812010-08-21 02:31:58 +0000309 R.Initialize(Qualifiers::fromCVRMask(CVR));
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000310 return R;
311 }
Daniel Dunbar85c59ed2008-08-29 08:11:39 +0000312
Mike Stumpf5408fe2009-05-16 07:57:57 +0000313 // FIXME: It is probably bad that we aren't emitting the target when we build
314 // the lvalue. However, this complicates the code a bit, and I haven't figured
315 // out how to make it go wrong yet.
Daniel Dunbar85c59ed2008-08-29 08:11:39 +0000316 static LValue MakePropertyRef(const ObjCPropertyRefExpr *E,
John McCall0953e762009-09-24 19:53:00 +0000317 unsigned CVR) {
Daniel Dunbar85c59ed2008-08-29 08:11:39 +0000318 LValue R;
319 R.LVType = PropertyRef;
320 R.PropertyRefExpr = E;
Daniel Dunbarde988812010-08-21 02:31:58 +0000321 R.Initialize(Qualifiers::fromCVRMask(CVR));
Daniel Dunbar85c59ed2008-08-29 08:11:39 +0000322 return R;
323 }
Mike Stump1eb44332009-09-09 15:08:12 +0000324
325 static LValue MakeKVCRef(const ObjCImplicitSetterGetterRefExpr *E,
John McCall0953e762009-09-24 19:53:00 +0000326 unsigned CVR) {
Fariborz Jahanian43f44702008-11-22 22:30:21 +0000327 LValue R;
328 R.LVType = KVCRef;
329 R.KVCRefExpr = E;
Daniel Dunbarde988812010-08-21 02:31:58 +0000330 R.Initialize(Qualifiers::fromCVRMask(CVR));
Fariborz Jahanian43f44702008-11-22 22:30:21 +0000331 return R;
332 }
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000333};
334
John McCall558d2ab2010-09-15 10:14:12 +0000335/// An aggregate value slot.
336class AggValueSlot {
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000337 /// The address.
John McCall6fa29162010-09-16 03:16:41 +0000338 llvm::Value *Addr;
Fariborz Jahanian07ed93f2010-10-22 21:01:02 +0000339 CXXConstructExpr *CtorExpr;
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000340
341 // Associated flags.
342 bool VolatileFlag : 1;
343 bool LifetimeFlag : 1;
344 bool RequiresGCollection : 1;
John McCall558d2ab2010-09-15 10:14:12 +0000345
346public:
347 /// ignored - Returns an aggregate value slot indicating that the
348 /// aggregate value is being ignored.
349 static AggValueSlot ignored() {
350 AggValueSlot AV;
John McCall6fa29162010-09-16 03:16:41 +0000351 AV.Addr = 0;
Fariborz Jahanian07ed93f2010-10-22 21:01:02 +0000352 AV.CtorExpr = 0;
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000353 AV.VolatileFlag = AV.LifetimeFlag = AV.RequiresGCollection = 0;
John McCall558d2ab2010-09-15 10:14:12 +0000354 return AV;
355 }
356
357 /// forAddr - Make a slot for an aggregate value.
358 ///
359 /// \param Volatile - true if the slot should be volatile-initialized
360 /// \param LifetimeExternallyManaged - true if the slot's lifetime
361 /// is being externally managed; false if a destructor should be
362 /// registered for any temporaries evaluated into the slot
John McCalld1a5f132010-09-16 03:13:23 +0000363 /// \param RequiresGCollection - true if the slot is located
364 /// somewhere that ObjC GC calls should be emitted for
John McCall558d2ab2010-09-15 10:14:12 +0000365 static AggValueSlot forAddr(llvm::Value *Addr, bool Volatile,
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000366 bool LifetimeExternallyManaged,
367 bool RequiresGCollection=false) {
John McCall558d2ab2010-09-15 10:14:12 +0000368 AggValueSlot AV;
John McCall6fa29162010-09-16 03:16:41 +0000369 AV.Addr = Addr;
Fariborz Jahanian07ed93f2010-10-22 21:01:02 +0000370 AV.CtorExpr = 0;
John McCalld1a5f132010-09-16 03:13:23 +0000371 AV.VolatileFlag = Volatile;
372 AV.LifetimeFlag = LifetimeExternallyManaged;
373 AV.RequiresGCollection = RequiresGCollection;
John McCall558d2ab2010-09-15 10:14:12 +0000374 return AV;
375 }
376
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000377 static AggValueSlot forLValue(LValue LV, bool LifetimeExternallyManaged,
378 bool RequiresGCollection=false) {
John McCall558d2ab2010-09-15 10:14:12 +0000379 return forAddr(LV.getAddress(), LV.isVolatileQualified(),
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000380 LifetimeExternallyManaged, RequiresGCollection);
John McCall558d2ab2010-09-15 10:14:12 +0000381 }
Fariborz Jahanian07ed93f2010-10-22 21:01:02 +0000382
383 void setCtorExpr(CXXConstructExpr *E) { CtorExpr = E; }
384 CXXConstructExpr *getCtorExpr() const { return CtorExpr; }
385
John McCall558d2ab2010-09-15 10:14:12 +0000386 bool isLifetimeExternallyManaged() const {
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000387 return LifetimeFlag;
John McCall558d2ab2010-09-15 10:14:12 +0000388 }
389 void setLifetimeExternallyManaged() {
John McCalld1a5f132010-09-16 03:13:23 +0000390 LifetimeFlag = true;
John McCall558d2ab2010-09-15 10:14:12 +0000391 }
392
393 bool isVolatile() const {
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000394 return VolatileFlag;
John McCall558d2ab2010-09-15 10:14:12 +0000395 }
396
John McCalld1a5f132010-09-16 03:13:23 +0000397 bool requiresGCollection() const {
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000398 return RequiresGCollection;
399 }
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000400
John McCall558d2ab2010-09-15 10:14:12 +0000401 llvm::Value *getAddr() const {
John McCall6fa29162010-09-16 03:16:41 +0000402 return Addr;
John McCall558d2ab2010-09-15 10:14:12 +0000403 }
404
405 bool isIgnored() const {
John McCall6fa29162010-09-16 03:16:41 +0000406 return Addr == 0;
John McCall558d2ab2010-09-15 10:14:12 +0000407 }
408
409 RValue asRValue() const {
410 return RValue::getAggregate(getAddr(), isVolatile());
411 }
412
413};
414
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000415} // end namespace CodeGen
416} // end namespace clang
417
418#endif