blob: 744a6e02f9c898800a0e1061205071fc2bc803f9 [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"
Eli Friedmand7722d92011-12-03 02:13:40 +000019#include "clang/AST/CharUnits.h"
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000020#include "clang/AST/Type.h"
21
Daniel Dunbar46f45b92008-09-09 01:06:48 +000022namespace llvm {
23 class Constant;
24 class Value;
25}
26
Daniel Dunbar2eecaab2008-08-23 03:10:25 +000027namespace clang {
28namespace CodeGen {
John McCall4b9c2d22011-11-06 09:01:30 +000029 class AggValueSlot;
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 {
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000104 enum {
105 Simple, // This is a normal l-value, use getAddress().
106 VectorElt, // This is a vector element l-value (V[i]), use getVector*
107 BitField, // This is a bitfield l-value, use getBitfield*.
John McCalldb458062011-11-07 03:59:57 +0000108 ExtVectorElt // This is an extended vector subset, use getExtVectorComp
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000109 } LVType;
Fariborz Jahanian58626502008-11-19 00:59:10 +0000110
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000111 llvm::Value *V;
Mike Stump1eb44332009-09-09 15:08:12 +0000112
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000113 union {
114 // Index into a vector subscript: V[i]
115 llvm::Value *VectorIdx;
116
117 // ExtVector element subset: V.xyx
118 llvm::Constant *VectorElts;
Mike Stump1eb44332009-09-09 15:08:12 +0000119
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000120 // BitField start bit and size
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000121 const CGBitFieldInfo *BitFieldInfo;
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000122 };
123
John McCalla07398e2011-06-16 04:16:24 +0000124 QualType Type;
125
John McCall0953e762009-09-24 19:53:00 +0000126 // 'const' is unused here
127 Qualifiers Quals;
Fariborz Jahanian58626502008-11-19 00:59:10 +0000128
Daniel Dunbar9f4f7cf2010-08-21 02:39:23 +0000129 /// The alignment to use when accessing this lvalue.
Daniel Dunbar77c05902010-08-26 06:02:12 +0000130 unsigned short Alignment;
Daniel Dunbar9f4f7cf2010-08-21 02:39:23 +0000131
Fariborz Jahaniand1cc8042008-11-20 20:53:20 +0000132 // objective-c's ivar
133 bool Ivar:1;
Fariborz Jahanian1c1afc42009-09-18 00:04:00 +0000134
135 // objective-c's ivar is an array
Fariborz Jahanianfd02ed72009-09-21 18:54:29 +0000136 bool ObjIsArray:1;
Mike Stump1eb44332009-09-09 15:08:12 +0000137
Fariborz Jahanian4f676ed2009-02-21 00:30:43 +0000138 // LValue is non-gc'able for any reason, including being a parameter or local
139 // variable.
140 bool NonGC: 1;
Fariborz Jahaniand1cc8042008-11-20 20:53:20 +0000141
Fariborz Jahanianbf63b872009-05-04 23:27:20 +0000142 // Lvalue is a global reference of an objective-c object
143 bool GlobalObjCRef : 1;
Fariborz Jahanian021a7a62010-07-20 20:30:03 +0000144
145 // Lvalue is a thread local reference
146 bool ThreadLocalRef : 1;
Fariborz Jahanianbf63b872009-05-04 23:27:20 +0000147
Fariborz Jahanian6c7a1f32009-09-24 22:25:38 +0000148 Expr *BaseIvarExp;
Dan Gohman3d5aff52010-10-14 23:06:10 +0000149
150 /// TBAAInfo - TBAA information to attach to dereferences of this LValue.
151 llvm::MDNode *TBAAInfo;
152
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000153private:
Eli Friedman6da2c712011-12-03 04:14:32 +0000154 void Initialize(QualType Type, Qualifiers Quals,
155 CharUnits Alignment = CharUnits(),
Dan Gohman3d5aff52010-10-14 23:06:10 +0000156 llvm::MDNode *TBAAInfo = 0) {
John McCalla07398e2011-06-16 04:16:24 +0000157 this->Type = Type;
John McCall0953e762009-09-24 19:53:00 +0000158 this->Quals = Quals;
Eli Friedman6da2c712011-12-03 04:14:32 +0000159 this->Alignment = Alignment.getQuantity();
160 assert(this->Alignment == Alignment.getQuantity() &&
161 "Alignment exceeds allowed max!");
Daniel Dunbar9f4f7cf2010-08-21 02:39:23 +0000162
163 // Initialize Objective-C flags.
John McCall0953e762009-09-24 19:53:00 +0000164 this->Ivar = this->ObjIsArray = this->NonGC = this->GlobalObjCRef = false;
Fariborz Jahanian021a7a62010-07-20 20:30:03 +0000165 this->ThreadLocalRef = false;
Fariborz Jahanian6c7a1f32009-09-24 22:25:38 +0000166 this->BaseIvarExp = 0;
Dan Gohman3d5aff52010-10-14 23:06:10 +0000167 this->TBAAInfo = TBAAInfo;
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000168 }
Mike Stump1eb44332009-09-09 15:08:12 +0000169
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000170public:
171 bool isSimple() const { return LVType == Simple; }
172 bool isVectorElt() const { return LVType == VectorElt; }
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000173 bool isBitField() const { return LVType == BitField; }
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000174 bool isExtVectorElt() const { return LVType == ExtVectorElt; }
Daniel Dunbar85c59ed2008-08-29 08:11:39 +0000175
John McCall0953e762009-09-24 19:53:00 +0000176 bool isVolatileQualified() const { return Quals.hasVolatile(); }
177 bool isRestrictQualified() const { return Quals.hasRestrict(); }
178 unsigned getVRQualifiers() const {
179 return Quals.getCVRQualifiers() & ~Qualifiers::Const;
Chris Lattner1bd885e2009-02-16 22:25:49 +0000180 }
Mike Stump1eb44332009-09-09 15:08:12 +0000181
John McCalla07398e2011-06-16 04:16:24 +0000182 QualType getType() const { return Type; }
183
184 Qualifiers::ObjCLifetime getObjCLifetime() const {
185 return Quals.getObjCLifetime();
186 }
187
Fariborz Jahaniand1cc8042008-11-20 20:53:20 +0000188 bool isObjCIvar() const { return Ivar; }
Daniel Dunbar3491b3d2010-08-21 03:51:29 +0000189 void setObjCIvar(bool Value) { Ivar = Value; }
190
Fariborz Jahanianfd02ed72009-09-21 18:54:29 +0000191 bool isObjCArray() const { return ObjIsArray; }
Daniel Dunbar3491b3d2010-08-21 03:51:29 +0000192 void setObjCArray(bool Value) { ObjIsArray = Value; }
Daniel Dunbarea619172010-08-21 03:22:38 +0000193
Fariborz Jahanian4f676ed2009-02-21 00:30:43 +0000194 bool isNonGC () const { return NonGC; }
Daniel Dunbarea619172010-08-21 03:22:38 +0000195 void setNonGC(bool Value) { NonGC = Value; }
196
Fariborz Jahanianbf63b872009-05-04 23:27:20 +0000197 bool isGlobalObjCRef() const { return GlobalObjCRef; }
Daniel Dunbar3491b3d2010-08-21 03:51:29 +0000198 void setGlobalObjCRef(bool Value) { GlobalObjCRef = Value; }
199
Fariborz Jahanian021a7a62010-07-20 20:30:03 +0000200 bool isThreadLocalRef() const { return ThreadLocalRef; }
Daniel Dunbar3491b3d2010-08-21 03:51:29 +0000201 void setThreadLocalRef(bool Value) { ThreadLocalRef = Value;}
202
203 bool isObjCWeak() const {
204 return Quals.getObjCGCAttr() == Qualifiers::Weak;
205 }
206 bool isObjCStrong() const {
207 return Quals.getObjCGCAttr() == Qualifiers::Strong;
208 }
John McCalla07398e2011-06-16 04:16:24 +0000209
210 bool isVolatile() const {
211 return Quals.hasVolatile();
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
Eli Friedman6da2c712011-12-03 04:14:32 +0000225 CharUnits getAlignment() const { return CharUnits::fromQuantity(Alignment); }
226 void setAlignment(CharUnits A) { Alignment = A.getQuantity(); }
Daniel Dunbar9f4f7cf2010-08-21 02:39:23 +0000227
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000228 // simple lvalue
229 llvm::Value *getAddress() const { assert(isSimple()); return V; }
John McCalla07398e2011-06-16 04:16:24 +0000230 void setAddress(llvm::Value *address) {
231 assert(isSimple());
232 V = address;
233 }
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000234
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000235 // vector elt lvalue
236 llvm::Value *getVectorAddr() const { assert(isVectorElt()); return V; }
237 llvm::Value *getVectorIdx() const { assert(isVectorElt()); return VectorIdx; }
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000238
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000239 // extended vector elements.
240 llvm::Value *getExtVectorAddr() const { assert(isExtVectorElt()); return V; }
241 llvm::Constant *getExtVectorElts() const {
242 assert(isExtVectorElt());
243 return VectorElts;
244 }
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000245
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000246 // bitfield lvalue
Daniel Dunbar7f289642010-04-08 02:59:45 +0000247 llvm::Value *getBitFieldBaseAddr() const {
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000248 assert(isBitField());
249 return V;
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000250 }
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000251 const CGBitFieldInfo &getBitFieldInfo() const {
252 assert(isBitField());
253 return *BitFieldInfo;
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000254 }
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000255
John McCalla07398e2011-06-16 04:16:24 +0000256 static LValue MakeAddr(llvm::Value *address, QualType type,
Eli Friedman6da2c712011-12-03 04:14:32 +0000257 CharUnits alignment, ASTContext &Context,
Dan Gohman3d5aff52010-10-14 23:06:10 +0000258 llvm::MDNode *TBAAInfo = 0) {
John McCalla07398e2011-06-16 04:16:24 +0000259 Qualifiers qs = type.getQualifiers();
260 qs.setObjCGCAttr(Context.getObjCGCAttrKind(type));
Daniel Dunbarf1fbda32010-08-21 03:58:45 +0000261
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000262 LValue R;
263 R.LVType = Simple;
John McCalla07398e2011-06-16 04:16:24 +0000264 R.V = address;
265 R.Initialize(type, qs, alignment, TBAAInfo);
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000266 return R;
267 }
Mike Stump1eb44332009-09-09 15:08:12 +0000268
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000269 static LValue MakeVectorElt(llvm::Value *Vec, llvm::Value *Idx,
John McCalla07398e2011-06-16 04:16:24 +0000270 QualType type) {
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000271 LValue R;
272 R.LVType = VectorElt;
273 R.V = Vec;
274 R.VectorIdx = Idx;
John McCalla07398e2011-06-16 04:16:24 +0000275 R.Initialize(type, type.getQualifiers());
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000276 return R;
277 }
Mike Stump1eb44332009-09-09 15:08:12 +0000278
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000279 static LValue MakeExtVectorElt(llvm::Value *Vec, llvm::Constant *Elts,
John McCalla07398e2011-06-16 04:16:24 +0000280 QualType type) {
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000281 LValue R;
282 R.LVType = ExtVectorElt;
283 R.V = Vec;
284 R.VectorElts = Elts;
John McCalla07398e2011-06-16 04:16:24 +0000285 R.Initialize(type, type.getQualifiers());
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000286 return R;
287 }
288
Daniel Dunbar7f289642010-04-08 02:59:45 +0000289 /// \brief Create a new object to represent a bit-field access.
290 ///
291 /// \param BaseValue - The base address of the structure containing the
292 /// bit-field.
293 /// \param Info - The information describing how to perform the bit-field
294 /// access.
John McCalla07398e2011-06-16 04:16:24 +0000295 static LValue MakeBitfield(llvm::Value *BaseValue,
296 const CGBitFieldInfo &Info,
297 QualType type) {
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000298 LValue R;
299 R.LVType = BitField;
Daniel Dunbar7f289642010-04-08 02:59:45 +0000300 R.V = BaseValue;
Daniel Dunbarf0fe5bc2010-04-05 21:36:35 +0000301 R.BitFieldInfo = &Info;
John McCalla07398e2011-06-16 04:16:24 +0000302 R.Initialize(type, type.getQualifiers());
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000303 return R;
304 }
Eli Friedman51f51202011-12-03 03:08:40 +0000305
306 RValue asAggregateRValue() const {
307 // FIMXE: Alignment
308 return RValue::getAggregate(getAddress(), isVolatileQualified());
309 }
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000310};
311
John McCall558d2ab2010-09-15 10:14:12 +0000312/// An aggregate value slot.
313class AggValueSlot {
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000314 /// The address.
John McCall6fa29162010-09-16 03:16:41 +0000315 llvm::Value *Addr;
John McCallf85e1932011-06-15 23:02:42 +0000316
317 // Qualifiers
318 Qualifiers Quals;
John McCall7c2349b2011-08-25 20:40:09 +0000319
Eli Friedmanf3940782011-12-03 00:54:26 +0000320 unsigned short Alignment;
321
John McCallfd71fb82011-08-26 08:02:37 +0000322 /// DestructedFlag - This is set to true if some external code is
323 /// responsible for setting up a destructor for the slot. Otherwise
324 /// the code which constructs it should push the appropriate cleanup.
325 bool DestructedFlag : 1;
326
327 /// ObjCGCFlag - This is set to true if writing to the memory in the
328 /// slot might require calling an appropriate Objective-C GC
329 /// barrier. The exact interaction here is unnecessarily mysterious.
330 bool ObjCGCFlag : 1;
Chris Lattner1b726772010-12-02 07:07:26 +0000331
John McCallfd71fb82011-08-26 08:02:37 +0000332 /// ZeroedFlag - This is set to true if the memory in the slot is
333 /// known to be zero before the assignment into it. This means that
334 /// zero fields don't need to be set.
John McCall7c2349b2011-08-25 20:40:09 +0000335 bool ZeroedFlag : 1;
John McCall558d2ab2010-09-15 10:14:12 +0000336
John McCallfd71fb82011-08-26 08:02:37 +0000337 /// AliasedFlag - This is set to true if the slot might be aliased
338 /// and it's not undefined behavior to access it through such an
339 /// alias. Note that it's always undefined behavior to access a C++
340 /// object that's under construction through an alias derived from
341 /// outside the construction process.
342 ///
343 /// This flag controls whether calls that produce the aggregate
344 /// value may be evaluated directly into the slot, or whether they
345 /// must be evaluated into an unaliased temporary and then memcpy'ed
346 /// over. Since it's invalid in general to memcpy a non-POD C++
347 /// object, it's important that this flag never be set when
348 /// evaluating an expression which constructs such an object.
John McCall410ffb22011-08-25 23:04:34 +0000349 bool AliasedFlag : 1;
350
John McCall558d2ab2010-09-15 10:14:12 +0000351public:
John McCall410ffb22011-08-25 23:04:34 +0000352 enum IsAliased_t { IsNotAliased, IsAliased };
John McCall7c2349b2011-08-25 20:40:09 +0000353 enum IsDestructed_t { IsNotDestructed, IsDestructed };
John McCall410ffb22011-08-25 23:04:34 +0000354 enum IsZeroed_t { IsNotZeroed, IsZeroed };
John McCall7c2349b2011-08-25 20:40:09 +0000355 enum NeedsGCBarriers_t { DoesNotNeedGCBarriers, NeedsGCBarriers };
356
John McCall558d2ab2010-09-15 10:14:12 +0000357 /// ignored - Returns an aggregate value slot indicating that the
358 /// aggregate value is being ignored.
359 static AggValueSlot ignored() {
Benjamin Kramer9f32a922011-12-11 16:34:24 +0000360 return forAddr(0, CharUnits(), Qualifiers(), IsNotDestructed,
361 DoesNotNeedGCBarriers, IsNotAliased);
John McCall558d2ab2010-09-15 10:14:12 +0000362 }
363
364 /// forAddr - Make a slot for an aggregate value.
365 ///
John McCall7c2349b2011-08-25 20:40:09 +0000366 /// \param quals - The qualifiers that dictate how the slot should
367 /// be initialied. Only 'volatile' and the Objective-C lifetime
368 /// qualifiers matter.
John McCallf85e1932011-06-15 23:02:42 +0000369 ///
John McCall7c2349b2011-08-25 20:40:09 +0000370 /// \param isDestructed - true if something else is responsible
371 /// for calling destructors on this object
372 /// \param needsGC - true if the slot is potentially located
John McCalld1a5f132010-09-16 03:13:23 +0000373 /// somewhere that ObjC GC calls should be emitted for
Eli Friedmand7722d92011-12-03 02:13:40 +0000374 static AggValueSlot forAddr(llvm::Value *addr, CharUnits align,
Eli Friedmanf3940782011-12-03 00:54:26 +0000375 Qualifiers quals,
John McCall7c2349b2011-08-25 20:40:09 +0000376 IsDestructed_t isDestructed,
377 NeedsGCBarriers_t needsGC,
John McCall44184392011-08-26 07:31:35 +0000378 IsAliased_t isAliased,
John McCall7c2349b2011-08-25 20:40:09 +0000379 IsZeroed_t isZeroed = IsNotZeroed) {
John McCall558d2ab2010-09-15 10:14:12 +0000380 AggValueSlot AV;
John McCall7c2349b2011-08-25 20:40:09 +0000381 AV.Addr = addr;
Eli Friedmand7722d92011-12-03 02:13:40 +0000382 AV.Alignment = align.getQuantity();
John McCall7c2349b2011-08-25 20:40:09 +0000383 AV.Quals = quals;
John McCallfd71fb82011-08-26 08:02:37 +0000384 AV.DestructedFlag = isDestructed;
385 AV.ObjCGCFlag = needsGC;
John McCall7c2349b2011-08-25 20:40:09 +0000386 AV.ZeroedFlag = isZeroed;
John McCall410ffb22011-08-25 23:04:34 +0000387 AV.AliasedFlag = isAliased;
John McCall558d2ab2010-09-15 10:14:12 +0000388 return AV;
389 }
390
John McCall7c2349b2011-08-25 20:40:09 +0000391 static AggValueSlot forLValue(LValue LV, IsDestructed_t isDestructed,
392 NeedsGCBarriers_t needsGC,
John McCall44184392011-08-26 07:31:35 +0000393 IsAliased_t isAliased,
John McCall7c2349b2011-08-25 20:40:09 +0000394 IsZeroed_t isZeroed = IsNotZeroed) {
Eli Friedman6da2c712011-12-03 04:14:32 +0000395 return forAddr(LV.getAddress(), LV.getAlignment(),
Eli Friedmand7722d92011-12-03 02:13:40 +0000396 LV.getQuals(), isDestructed, needsGC, isAliased, isZeroed);
John McCall558d2ab2010-09-15 10:14:12 +0000397 }
Fariborz Jahanian8a970052010-10-22 22:05:03 +0000398
John McCallfd71fb82011-08-26 08:02:37 +0000399 IsDestructed_t isExternallyDestructed() const {
400 return IsDestructed_t(DestructedFlag);
John McCall558d2ab2010-09-15 10:14:12 +0000401 }
John McCallfd71fb82011-08-26 08:02:37 +0000402 void setExternallyDestructed(bool destructed = true) {
403 DestructedFlag = destructed;
John McCall558d2ab2010-09-15 10:14:12 +0000404 }
405
John McCallf85e1932011-06-15 23:02:42 +0000406 Qualifiers getQualifiers() const { return Quals; }
407
John McCall558d2ab2010-09-15 10:14:12 +0000408 bool isVolatile() const {
John McCallf85e1932011-06-15 23:02:42 +0000409 return Quals.hasVolatile();
410 }
411
412 Qualifiers::ObjCLifetime getObjCLifetime() const {
413 return Quals.getObjCLifetime();
John McCall558d2ab2010-09-15 10:14:12 +0000414 }
415
John McCall7c2349b2011-08-25 20:40:09 +0000416 NeedsGCBarriers_t requiresGCollection() const {
John McCallfd71fb82011-08-26 08:02:37 +0000417 return NeedsGCBarriers_t(ObjCGCFlag);
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000418 }
Fariborz Jahanian474e2fe2010-09-16 00:20:07 +0000419
John McCall558d2ab2010-09-15 10:14:12 +0000420 llvm::Value *getAddr() const {
John McCall6fa29162010-09-16 03:16:41 +0000421 return Addr;
John McCall558d2ab2010-09-15 10:14:12 +0000422 }
423
424 bool isIgnored() const {
John McCall6fa29162010-09-16 03:16:41 +0000425 return Addr == 0;
John McCall558d2ab2010-09-15 10:14:12 +0000426 }
427
Eli Friedmand7722d92011-12-03 02:13:40 +0000428 CharUnits getAlignment() const {
429 return CharUnits::fromQuantity(Alignment);
Eli Friedmanf3940782011-12-03 00:54:26 +0000430 }
431
John McCall410ffb22011-08-25 23:04:34 +0000432 IsAliased_t isPotentiallyAliased() const {
433 return IsAliased_t(AliasedFlag);
434 }
435
Eli Friedmanf3940782011-12-03 00:54:26 +0000436 // FIXME: Alignment?
John McCall558d2ab2010-09-15 10:14:12 +0000437 RValue asRValue() const {
438 return RValue::getAggregate(getAddr(), isVolatile());
439 }
John McCall4b9c2d22011-11-06 09:01:30 +0000440
John McCall7c2349b2011-08-25 20:40:09 +0000441 void setZeroed(bool V = true) { ZeroedFlag = V; }
442 IsZeroed_t isZeroed() const {
443 return IsZeroed_t(ZeroedFlag);
Chris Lattner1b726772010-12-02 07:07:26 +0000444 }
John McCall558d2ab2010-09-15 10:14:12 +0000445};
446
Daniel Dunbar2eecaab2008-08-23 03:10:25 +0000447} // end namespace CodeGen
448} // end namespace clang
449
450#endif