blob: e507e718660c15d0831e927db95d375241a681b2 [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 {
27namespace CodeGen {
John McCall4b9c2d22011-11-06 09:01:30 +000028 class AggValueSlot;
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +000029 class CGBitFieldInfo;
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000030
31/// RValue - This trivial value class is used to represent the result of an
32/// expression that is evaluated. It can be one of three things: either a
33/// simple LLVM SSA value, a pair of SSA values for complex numbers, or the
34/// address of an aggregate value in memory.
35class RValue {
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000036 enum Flavor { Scalar, Complex, Aggregate };
Mike Stump1eb44332009-09-09 15:08:12 +000037
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000038 // Stores first value and flavor.
39 llvm::PointerIntPair<llvm::Value *, 2, Flavor> V1;
40 // Stores second value and volatility.
41 llvm::PointerIntPair<llvm::Value *, 1, bool> V2;
42
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000043public:
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000044 bool isScalar() const { return V1.getInt() == Scalar; }
45 bool isComplex() const { return V1.getInt() == Complex; }
46 bool isAggregate() const { return V1.getInt() == Aggregate; }
Mike Stump1eb44332009-09-09 15:08:12 +000047
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000048 bool isVolatileQualified() const { return V2.getInt(); }
Mike Stump8b3d93a2009-05-23 20:21:36 +000049
Mike Stump519202d2009-11-03 16:11:57 +000050 /// getScalarVal() - Return the Value* of this scalar value.
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000051 llvm::Value *getScalarVal() const {
52 assert(isScalar() && "Not a scalar!");
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000053 return V1.getPointer();
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000054 }
55
56 /// getComplexVal - Return the real/imag components of this complex value.
57 ///
58 std::pair<llvm::Value *, llvm::Value *> getComplexVal() const {
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000059 return std::make_pair(V1.getPointer(), V2.getPointer());
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000060 }
Mike Stump1eb44332009-09-09 15:08:12 +000061
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000062 /// getAggregateAddr() - Return the Value* of the address of the aggregate.
63 llvm::Value *getAggregateAddr() const {
64 assert(isAggregate() && "Not an aggregate!");
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000065 return V1.getPointer();
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000066 }
Mike Stump1eb44332009-09-09 15:08:12 +000067
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000068 static RValue get(llvm::Value *V) {
69 RValue ER;
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000070 ER.V1.setPointer(V);
71 ER.V1.setInt(Scalar);
72 ER.V2.setInt(false);
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000073 return ER;
74 }
75 static RValue getComplex(llvm::Value *V1, llvm::Value *V2) {
76 RValue ER;
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000077 ER.V1.setPointer(V1);
78 ER.V2.setPointer(V2);
79 ER.V1.setInt(Complex);
80 ER.V2.setInt(false);
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000081 return ER;
82 }
83 static RValue getComplex(const std::pair<llvm::Value *, llvm::Value *> &C) {
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000084 return getComplex(C.first, C.second);
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000085 }
Mike Stump8b3d93a2009-05-23 20:21:36 +000086 // FIXME: Aggregate rvalues need to retain information about whether they are
87 // volatile or not. Remove default to find all places that probably get this
88 // wrong.
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000089 static RValue getAggregate(llvm::Value *V, bool Volatile = false) {
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000090 RValue ER;
Benjamin Kramer81bf3b32010-05-02 14:59:10 +000091 ER.V1.setPointer(V);
92 ER.V1.setInt(Aggregate);
93 ER.V2.setInt(Volatile);
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000094 return ER;
95 }
96};
97
98
99/// LValue - This represents an lvalue references. Because C/C++ allow
100/// bitfields, this is not a simple LLVM pointer, it may be a pointer plus a
101/// bitrange.
102class LValue {
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000103 enum {
104 Simple, // This is a normal l-value, use getAddress().
105 VectorElt, // This is a vector element l-value (V[i]), use getVector*
106 BitField, // This is a bitfield l-value, use getBitfield*.
John McCalldb458062011-11-07 03:59:57 +0000107 ExtVectorElt // This is an extended vector subset, use getExtVectorComp
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000108 } LVType;
Fariborz Jahanian58626502008-11-19 00:59:10 +0000109
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000110 llvm::Value *V;
Mike Stump1eb44332009-09-09 15:08:12 +0000111
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000112 union {
113 // Index into a vector subscript: V[i]
114 llvm::Value *VectorIdx;
115
116 // ExtVector element subset: V.xyx
117 llvm::Constant *VectorElts;
Mike Stump1eb44332009-09-09 15:08:12 +0000118
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000119 // BitField start bit and size
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000120 const CGBitFieldInfo *BitFieldInfo;
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000121 };
122
John McCalla07398e2011-06-16 04:16:24 +0000123 QualType Type;
124
John McCall0953e762009-09-24 19:53:00 +0000125 // 'const' is unused here
126 Qualifiers Quals;
Fariborz Jahanian58626502008-11-19 00:59:10 +0000127
Daniel Dunbar9f4f7cf2010-08-21 02:39:23 +0000128 /// The alignment to use when accessing this lvalue.
Daniel Dunbar77c05902010-08-26 06:02:12 +0000129 unsigned short Alignment;
Daniel Dunbar9f4f7cf2010-08-21 02:39:23 +0000130
Fariborz Jahaniand1cc8042008-11-20 20:53:20 +0000131 // objective-c's ivar
132 bool Ivar:1;
Fariborz Jahanian1c1afc42009-09-18 00:04:00 +0000133
134 // objective-c's ivar is an array
Fariborz Jahanianfd02ed72009-09-21 18:54:29 +0000135 bool ObjIsArray:1;
Mike Stump1eb44332009-09-09 15:08:12 +0000136
Fariborz Jahanian4f676ed2009-02-21 00:30:43 +0000137 // LValue is non-gc'able for any reason, including being a parameter or local
138 // variable.
139 bool NonGC: 1;
Fariborz Jahaniand1cc8042008-11-20 20:53:20 +0000140
Fariborz Jahanianbf63b872009-05-04 23:27:20 +0000141 // Lvalue is a global reference of an objective-c object
142 bool GlobalObjCRef : 1;
Fariborz Jahanian021a7a62010-07-20 20:30:03 +0000143
144 // Lvalue is a thread local reference
145 bool ThreadLocalRef : 1;
Fariborz Jahanianbf63b872009-05-04 23:27:20 +0000146
Fariborz Jahanian6c7a1f32009-09-24 22:25:38 +0000147 Expr *BaseIvarExp;
Dan Gohman3d5aff52010-10-14 23:06:10 +0000148
149 /// TBAAInfo - TBAA information to attach to dereferences of this LValue.
150 llvm::MDNode *TBAAInfo;
151
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000152private:
John McCalla07398e2011-06-16 04:16:24 +0000153 void Initialize(QualType Type, Qualifiers Quals, unsigned Alignment = 0,
Dan Gohman3d5aff52010-10-14 23:06:10 +0000154 llvm::MDNode *TBAAInfo = 0) {
John McCalla07398e2011-06-16 04:16:24 +0000155 this->Type = Type;
John McCall0953e762009-09-24 19:53:00 +0000156 this->Quals = Quals;
Daniel Dunbar9f4f7cf2010-08-21 02:39:23 +0000157 this->Alignment = Alignment;
158 assert(this->Alignment == Alignment && "Alignment exceeds allowed max!");
159
160 // Initialize Objective-C flags.
John McCall0953e762009-09-24 19:53:00 +0000161 this->Ivar = this->ObjIsArray = this->NonGC = this->GlobalObjCRef = false;
Fariborz Jahanian021a7a62010-07-20 20:30:03 +0000162 this->ThreadLocalRef = false;
Fariborz Jahanian6c7a1f32009-09-24 22:25:38 +0000163 this->BaseIvarExp = 0;
Dan Gohman3d5aff52010-10-14 23:06:10 +0000164 this->TBAAInfo = TBAAInfo;
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000165 }
Mike Stump1eb44332009-09-09 15:08:12 +0000166
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000167public:
168 bool isSimple() const { return LVType == Simple; }
169 bool isVectorElt() const { return LVType == VectorElt; }
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000170 bool isBitField() const { return LVType == BitField; }
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000171 bool isExtVectorElt() const { return LVType == ExtVectorElt; }
Daniel Dunbar85c59ed2008-08-29 08:11:39 +0000172
John McCall0953e762009-09-24 19:53:00 +0000173 bool isVolatileQualified() const { return Quals.hasVolatile(); }
174 bool isRestrictQualified() const { return Quals.hasRestrict(); }
175 unsigned getVRQualifiers() const {
176 return Quals.getCVRQualifiers() & ~Qualifiers::Const;
Chris Lattner1bd885e2009-02-16 22:25:49 +0000177 }
Mike Stump1eb44332009-09-09 15:08:12 +0000178
John McCalla07398e2011-06-16 04:16:24 +0000179 QualType getType() const { return Type; }
180
181 Qualifiers::ObjCLifetime getObjCLifetime() const {
182 return Quals.getObjCLifetime();
183 }
184
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 }
John McCalla07398e2011-06-16 04:16:24 +0000206
207 bool isVolatile() const {
208 return Quals.hasVolatile();
209 }
Fariborz Jahanian6c7a1f32009-09-24 22:25:38 +0000210
211 Expr *getBaseIvarExp() const { return BaseIvarExp; }
212 void setBaseIvarExp(Expr *V) { BaseIvarExp = V; }
Mon P Wangc6a38a42009-07-22 03:08:17 +0000213
Dan Gohman3d5aff52010-10-14 23:06:10 +0000214 llvm::MDNode *getTBAAInfo() const { return TBAAInfo; }
215 void setTBAAInfo(llvm::MDNode *N) { TBAAInfo = N; }
216
Daniel Dunbar99ad7df2010-08-21 03:29:54 +0000217 const Qualifiers &getQuals() const { return Quals; }
218 Qualifiers &getQuals() { return Quals; }
219
John McCall0953e762009-09-24 19:53:00 +0000220 unsigned getAddressSpace() const { return Quals.getAddressSpace(); }
Mon P Wangc6a38a42009-07-22 03:08:17 +0000221
Daniel Dunbar9f4f7cf2010-08-21 02:39:23 +0000222 unsigned getAlignment() const { return Alignment; }
Eli Friedmanf3940782011-12-03 00:54:26 +0000223 void setAlignment(unsigned A) { Alignment = A; }
Daniel Dunbar9f4f7cf2010-08-21 02:39:23 +0000224
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000225 // simple lvalue
226 llvm::Value *getAddress() const { assert(isSimple()); return V; }
John McCalla07398e2011-06-16 04:16:24 +0000227 void setAddress(llvm::Value *address) {
228 assert(isSimple());
229 V = address;
230 }
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000231
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000232 // vector elt lvalue
233 llvm::Value *getVectorAddr() const { assert(isVectorElt()); return V; }
234 llvm::Value *getVectorIdx() const { assert(isVectorElt()); return VectorIdx; }
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000235
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000236 // extended vector elements.
237 llvm::Value *getExtVectorAddr() const { assert(isExtVectorElt()); return V; }
238 llvm::Constant *getExtVectorElts() const {
239 assert(isExtVectorElt());
240 return VectorElts;
241 }
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000242
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000243 // bitfield lvalue
Daniel Dunbar7f289642010-04-08 02:59:45 +0000244 llvm::Value *getBitFieldBaseAddr() const {
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000245 assert(isBitField());
246 return V;
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000247 }
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000248 const CGBitFieldInfo &getBitFieldInfo() const {
249 assert(isBitField());
250 return *BitFieldInfo;
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000251 }
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000252
John McCalla07398e2011-06-16 04:16:24 +0000253 static LValue MakeAddr(llvm::Value *address, QualType type,
254 unsigned alignment, ASTContext &Context,
Dan Gohman3d5aff52010-10-14 23:06:10 +0000255 llvm::MDNode *TBAAInfo = 0) {
John McCalla07398e2011-06-16 04:16:24 +0000256 Qualifiers qs = type.getQualifiers();
257 qs.setObjCGCAttr(Context.getObjCGCAttrKind(type));
Daniel Dunbarf1fbda32010-08-21 03:58:45 +0000258
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000259 LValue R;
260 R.LVType = Simple;
John McCalla07398e2011-06-16 04:16:24 +0000261 R.V = address;
262 R.Initialize(type, qs, alignment, TBAAInfo);
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000263 return R;
264 }
Mike Stump1eb44332009-09-09 15:08:12 +0000265
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000266 static LValue MakeVectorElt(llvm::Value *Vec, llvm::Value *Idx,
John McCalla07398e2011-06-16 04:16:24 +0000267 QualType type) {
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000268 LValue R;
269 R.LVType = VectorElt;
270 R.V = Vec;
271 R.VectorIdx = Idx;
John McCalla07398e2011-06-16 04:16:24 +0000272 R.Initialize(type, type.getQualifiers());
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 MakeExtVectorElt(llvm::Value *Vec, llvm::Constant *Elts,
John McCalla07398e2011-06-16 04:16:24 +0000277 QualType type) {
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000278 LValue R;
279 R.LVType = ExtVectorElt;
280 R.V = Vec;
281 R.VectorElts = Elts;
John McCalla07398e2011-06-16 04:16:24 +0000282 R.Initialize(type, type.getQualifiers());
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000283 return R;
284 }
285
Daniel Dunbar7f289642010-04-08 02:59:45 +0000286 /// \brief Create a new object to represent a bit-field access.
287 ///
288 /// \param BaseValue - The base address of the structure containing the
289 /// bit-field.
290 /// \param Info - The information describing how to perform the bit-field
291 /// access.
John McCalla07398e2011-06-16 04:16:24 +0000292 static LValue MakeBitfield(llvm::Value *BaseValue,
293 const CGBitFieldInfo &Info,
294 QualType type) {
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;
John McCalla07398e2011-06-16 04:16:24 +0000299 R.Initialize(type, type.getQualifiers());
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000300 return R;
301 }
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000302};
303
John McCall558d2ab2010-09-15 10:14:12 +0000304/// An aggregate value slot.
305class AggValueSlot {
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000306 /// The address.
John McCall6fa29162010-09-16 03:16:41 +0000307 llvm::Value *Addr;
John McCallf85e1932011-06-15 23:02:42 +0000308
309 // Qualifiers
310 Qualifiers Quals;
John McCall7c2349b2011-08-25 20:40:09 +0000311
Eli Friedmanf3940782011-12-03 00:54:26 +0000312 unsigned short Alignment;
313
John McCallfd71fb82011-08-26 08:02:37 +0000314 /// DestructedFlag - This is set to true if some external code is
315 /// responsible for setting up a destructor for the slot. Otherwise
316 /// the code which constructs it should push the appropriate cleanup.
317 bool DestructedFlag : 1;
318
319 /// ObjCGCFlag - This is set to true if writing to the memory in the
320 /// slot might require calling an appropriate Objective-C GC
321 /// barrier. The exact interaction here is unnecessarily mysterious.
322 bool ObjCGCFlag : 1;
Chris Lattner1b726772010-12-02 07:07:26 +0000323
John McCallfd71fb82011-08-26 08:02:37 +0000324 /// ZeroedFlag - This is set to true if the memory in the slot is
325 /// known to be zero before the assignment into it. This means that
326 /// zero fields don't need to be set.
John McCall7c2349b2011-08-25 20:40:09 +0000327 bool ZeroedFlag : 1;
John McCall558d2ab2010-09-15 10:14:12 +0000328
John McCallfd71fb82011-08-26 08:02:37 +0000329 /// AliasedFlag - This is set to true if the slot might be aliased
330 /// and it's not undefined behavior to access it through such an
331 /// alias. Note that it's always undefined behavior to access a C++
332 /// object that's under construction through an alias derived from
333 /// outside the construction process.
334 ///
335 /// This flag controls whether calls that produce the aggregate
336 /// value may be evaluated directly into the slot, or whether they
337 /// must be evaluated into an unaliased temporary and then memcpy'ed
338 /// over. Since it's invalid in general to memcpy a non-POD C++
339 /// object, it's important that this flag never be set when
340 /// evaluating an expression which constructs such an object.
John McCall410ffb22011-08-25 23:04:34 +0000341 bool AliasedFlag : 1;
342
John McCall558d2ab2010-09-15 10:14:12 +0000343public:
John McCall410ffb22011-08-25 23:04:34 +0000344 enum IsAliased_t { IsNotAliased, IsAliased };
John McCall7c2349b2011-08-25 20:40:09 +0000345 enum IsDestructed_t { IsNotDestructed, IsDestructed };
John McCall410ffb22011-08-25 23:04:34 +0000346 enum IsZeroed_t { IsNotZeroed, IsZeroed };
John McCall7c2349b2011-08-25 20:40:09 +0000347 enum NeedsGCBarriers_t { DoesNotNeedGCBarriers, NeedsGCBarriers };
348
John McCall558d2ab2010-09-15 10:14:12 +0000349 /// ignored - Returns an aggregate value slot indicating that the
350 /// aggregate value is being ignored.
351 static AggValueSlot ignored() {
352 AggValueSlot AV;
John McCall6fa29162010-09-16 03:16:41 +0000353 AV.Addr = 0;
John McCallf85e1932011-06-15 23:02:42 +0000354 AV.Quals = Qualifiers();
John McCallfd71fb82011-08-26 08:02:37 +0000355 AV.DestructedFlag = AV.ObjCGCFlag = AV.ZeroedFlag = AV.AliasedFlag = false;
John McCall558d2ab2010-09-15 10:14:12 +0000356 return AV;
357 }
358
359 /// forAddr - Make a slot for an aggregate value.
360 ///
John McCall7c2349b2011-08-25 20:40:09 +0000361 /// \param quals - The qualifiers that dictate how the slot should
362 /// be initialied. Only 'volatile' and the Objective-C lifetime
363 /// qualifiers matter.
John McCallf85e1932011-06-15 23:02:42 +0000364 ///
John McCall7c2349b2011-08-25 20:40:09 +0000365 /// \param isDestructed - true if something else is responsible
366 /// for calling destructors on this object
367 /// \param needsGC - true if the slot is potentially located
John McCalld1a5f132010-09-16 03:13:23 +0000368 /// somewhere that ObjC GC calls should be emitted for
Eli Friedmanf3940782011-12-03 00:54:26 +0000369 static AggValueSlot forAddr(llvm::Value *addr, unsigned align,
370 Qualifiers quals,
John McCall7c2349b2011-08-25 20:40:09 +0000371 IsDestructed_t isDestructed,
372 NeedsGCBarriers_t needsGC,
John McCall44184392011-08-26 07:31:35 +0000373 IsAliased_t isAliased,
John McCall7c2349b2011-08-25 20:40:09 +0000374 IsZeroed_t isZeroed = IsNotZeroed) {
John McCall558d2ab2010-09-15 10:14:12 +0000375 AggValueSlot AV;
John McCall7c2349b2011-08-25 20:40:09 +0000376 AV.Addr = addr;
Eli Friedmanf3940782011-12-03 00:54:26 +0000377 AV.Alignment = align;
John McCall7c2349b2011-08-25 20:40:09 +0000378 AV.Quals = quals;
John McCallfd71fb82011-08-26 08:02:37 +0000379 AV.DestructedFlag = isDestructed;
380 AV.ObjCGCFlag = needsGC;
John McCall7c2349b2011-08-25 20:40:09 +0000381 AV.ZeroedFlag = isZeroed;
John McCall410ffb22011-08-25 23:04:34 +0000382 AV.AliasedFlag = isAliased;
John McCall558d2ab2010-09-15 10:14:12 +0000383 return AV;
384 }
385
John McCall7c2349b2011-08-25 20:40:09 +0000386 static AggValueSlot forLValue(LValue LV, IsDestructed_t isDestructed,
387 NeedsGCBarriers_t needsGC,
John McCall44184392011-08-26 07:31:35 +0000388 IsAliased_t isAliased,
John McCall7c2349b2011-08-25 20:40:09 +0000389 IsZeroed_t isZeroed = IsNotZeroed) {
Eli Friedmanf3940782011-12-03 00:54:26 +0000390 return forAddr(LV.getAddress(), LV.getAlignment(), LV.getQuals(),
John McCall410ffb22011-08-25 23:04:34 +0000391 isDestructed, needsGC, isAliased, isZeroed);
John McCall558d2ab2010-09-15 10:14:12 +0000392 }
Fariborz Jahanian8a970052010-10-22 22:05:03 +0000393
John McCallfd71fb82011-08-26 08:02:37 +0000394 IsDestructed_t isExternallyDestructed() const {
395 return IsDestructed_t(DestructedFlag);
John McCall558d2ab2010-09-15 10:14:12 +0000396 }
John McCallfd71fb82011-08-26 08:02:37 +0000397 void setExternallyDestructed(bool destructed = true) {
398 DestructedFlag = destructed;
John McCall558d2ab2010-09-15 10:14:12 +0000399 }
400
John McCallf85e1932011-06-15 23:02:42 +0000401 Qualifiers getQualifiers() const { return Quals; }
402
John McCall558d2ab2010-09-15 10:14:12 +0000403 bool isVolatile() const {
John McCallf85e1932011-06-15 23:02:42 +0000404 return Quals.hasVolatile();
405 }
406
407 Qualifiers::ObjCLifetime getObjCLifetime() const {
408 return Quals.getObjCLifetime();
John McCall558d2ab2010-09-15 10:14:12 +0000409 }
410
John McCall7c2349b2011-08-25 20:40:09 +0000411 NeedsGCBarriers_t requiresGCollection() const {
John McCallfd71fb82011-08-26 08:02:37 +0000412 return NeedsGCBarriers_t(ObjCGCFlag);
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000413 }
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000414
John McCall558d2ab2010-09-15 10:14:12 +0000415 llvm::Value *getAddr() const {
John McCall6fa29162010-09-16 03:16:41 +0000416 return Addr;
John McCall558d2ab2010-09-15 10:14:12 +0000417 }
418
419 bool isIgnored() const {
John McCall6fa29162010-09-16 03:16:41 +0000420 return Addr == 0;
John McCall558d2ab2010-09-15 10:14:12 +0000421 }
422
Eli Friedmanf3940782011-12-03 00:54:26 +0000423 unsigned getAlignment() const {
424 return Alignment;
425 }
426
John McCall410ffb22011-08-25 23:04:34 +0000427 IsAliased_t isPotentiallyAliased() const {
428 return IsAliased_t(AliasedFlag);
429 }
430
Eli Friedmanf3940782011-12-03 00:54:26 +0000431 // FIXME: Alignment?
John McCall558d2ab2010-09-15 10:14:12 +0000432 RValue asRValue() const {
433 return RValue::getAggregate(getAddr(), isVolatile());
434 }
John McCall4b9c2d22011-11-06 09:01:30 +0000435
John McCall7c2349b2011-08-25 20:40:09 +0000436 void setZeroed(bool V = true) { ZeroedFlag = V; }
437 IsZeroed_t isZeroed() const {
438 return IsZeroed_t(ZeroedFlag);
Chris Lattner1b726772010-12-02 07:07:26 +0000439 }
John McCall558d2ab2010-09-15 10:14:12 +0000440};
441
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000442} // end namespace CodeGen
443} // end namespace clang
444
445#endif