Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 1 | //===-- 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 Dunbar | 5cf8bfe | 2010-08-21 02:53:44 +0000 | [diff] [blame] | 18 | #include "clang/AST/ASTContext.h" |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 19 | #include "clang/AST/Type.h" |
| 20 | |
Daniel Dunbar | 46f45b9 | 2008-09-09 01:06:48 +0000 | [diff] [blame] | 21 | namespace llvm { |
| 22 | class Constant; |
| 23 | class Value; |
| 24 | } |
| 25 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 26 | namespace clang { |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 27 | class ObjCPropertyRefExpr; |
| 28 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 29 | namespace CodeGen { |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 30 | class CGBitFieldInfo; |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 31 | |
| 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. |
| 36 | class RValue { |
Benjamin Kramer | 81bf3b3 | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 37 | enum Flavor { Scalar, Complex, Aggregate }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 38 | |
Benjamin Kramer | 81bf3b3 | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 39 | // 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 Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 44 | public: |
Benjamin Kramer | 81bf3b3 | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 45 | bool isScalar() const { return V1.getInt() == Scalar; } |
| 46 | bool isComplex() const { return V1.getInt() == Complex; } |
| 47 | bool isAggregate() const { return V1.getInt() == Aggregate; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 48 | |
Benjamin Kramer | 81bf3b3 | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 49 | bool isVolatileQualified() const { return V2.getInt(); } |
Mike Stump | 8b3d93a | 2009-05-23 20:21:36 +0000 | [diff] [blame] | 50 | |
Mike Stump | 519202d | 2009-11-03 16:11:57 +0000 | [diff] [blame] | 51 | /// getScalarVal() - Return the Value* of this scalar value. |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 52 | llvm::Value *getScalarVal() const { |
| 53 | assert(isScalar() && "Not a scalar!"); |
Benjamin Kramer | 81bf3b3 | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 54 | return V1.getPointer(); |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | /// getComplexVal - Return the real/imag components of this complex value. |
| 58 | /// |
| 59 | std::pair<llvm::Value *, llvm::Value *> getComplexVal() const { |
Benjamin Kramer | 81bf3b3 | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 60 | return std::make_pair(V1.getPointer(), V2.getPointer()); |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 61 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 62 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 63 | /// getAggregateAddr() - Return the Value* of the address of the aggregate. |
| 64 | llvm::Value *getAggregateAddr() const { |
| 65 | assert(isAggregate() && "Not an aggregate!"); |
Benjamin Kramer | 81bf3b3 | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 66 | return V1.getPointer(); |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 67 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 68 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 69 | static RValue get(llvm::Value *V) { |
| 70 | RValue ER; |
Benjamin Kramer | 81bf3b3 | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 71 | ER.V1.setPointer(V); |
| 72 | ER.V1.setInt(Scalar); |
| 73 | ER.V2.setInt(false); |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 74 | return ER; |
| 75 | } |
| 76 | static RValue getComplex(llvm::Value *V1, llvm::Value *V2) { |
| 77 | RValue ER; |
Benjamin Kramer | 81bf3b3 | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 78 | ER.V1.setPointer(V1); |
| 79 | ER.V2.setPointer(V2); |
| 80 | ER.V1.setInt(Complex); |
| 81 | ER.V2.setInt(false); |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 82 | return ER; |
| 83 | } |
| 84 | static RValue getComplex(const std::pair<llvm::Value *, llvm::Value *> &C) { |
Benjamin Kramer | 81bf3b3 | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 85 | return getComplex(C.first, C.second); |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 86 | } |
Mike Stump | 8b3d93a | 2009-05-23 20:21:36 +0000 | [diff] [blame] | 87 | // 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 Kramer | 81bf3b3 | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 90 | static RValue getAggregate(llvm::Value *V, bool Volatile = false) { |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 91 | RValue ER; |
Benjamin Kramer | 81bf3b3 | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 92 | ER.V1.setPointer(V); |
| 93 | ER.V1.setInt(Aggregate); |
| 94 | ER.V2.setInt(Volatile); |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 95 | 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. |
| 103 | class LValue { |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 104 | 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*. |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 108 | ExtVectorElt, // This is an extended vector subset, use getExtVectorComp |
John McCall | 119a1c6 | 2010-12-04 02:32:38 +0000 | [diff] [blame] | 109 | PropertyRef // This is an Objective-C property reference, use |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 110 | // getPropertyRefExpr |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 111 | } LVType; |
Fariborz Jahanian | 5862650 | 2008-11-19 00:59:10 +0000 | [diff] [blame] | 112 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 113 | llvm::Value *V; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 114 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 115 | union { |
| 116 | // Index into a vector subscript: V[i] |
| 117 | llvm::Value *VectorIdx; |
| 118 | |
| 119 | // ExtVector element subset: V.xyx |
| 120 | llvm::Constant *VectorElts; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 121 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 122 | // BitField start bit and size |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 123 | const CGBitFieldInfo *BitFieldInfo; |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 124 | |
| 125 | // Obj-C property reference expression |
| 126 | const ObjCPropertyRefExpr *PropertyRefExpr; |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 127 | }; |
| 128 | |
John McCall | a07398e | 2011-06-16 04:16:24 +0000 | [diff] [blame] | 129 | QualType Type; |
| 130 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 131 | // 'const' is unused here |
| 132 | Qualifiers Quals; |
Fariborz Jahanian | 5862650 | 2008-11-19 00:59:10 +0000 | [diff] [blame] | 133 | |
Daniel Dunbar | 9f4f7cf | 2010-08-21 02:39:23 +0000 | [diff] [blame] | 134 | /// The alignment to use when accessing this lvalue. |
Daniel Dunbar | 77c0590 | 2010-08-26 06:02:12 +0000 | [diff] [blame] | 135 | unsigned short Alignment; |
Daniel Dunbar | 9f4f7cf | 2010-08-21 02:39:23 +0000 | [diff] [blame] | 136 | |
Fariborz Jahanian | d1cc804 | 2008-11-20 20:53:20 +0000 | [diff] [blame] | 137 | // objective-c's ivar |
| 138 | bool Ivar:1; |
Fariborz Jahanian | 1c1afc4 | 2009-09-18 00:04:00 +0000 | [diff] [blame] | 139 | |
| 140 | // objective-c's ivar is an array |
Fariborz Jahanian | fd02ed7 | 2009-09-21 18:54:29 +0000 | [diff] [blame] | 141 | bool ObjIsArray:1; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 142 | |
Fariborz Jahanian | 4f676ed | 2009-02-21 00:30:43 +0000 | [diff] [blame] | 143 | // LValue is non-gc'able for any reason, including being a parameter or local |
| 144 | // variable. |
| 145 | bool NonGC: 1; |
Fariborz Jahanian | d1cc804 | 2008-11-20 20:53:20 +0000 | [diff] [blame] | 146 | |
Fariborz Jahanian | bf63b87 | 2009-05-04 23:27:20 +0000 | [diff] [blame] | 147 | // Lvalue is a global reference of an objective-c object |
| 148 | bool GlobalObjCRef : 1; |
Fariborz Jahanian | 021a7a6 | 2010-07-20 20:30:03 +0000 | [diff] [blame] | 149 | |
| 150 | // Lvalue is a thread local reference |
| 151 | bool ThreadLocalRef : 1; |
Fariborz Jahanian | bf63b87 | 2009-05-04 23:27:20 +0000 | [diff] [blame] | 152 | |
Fariborz Jahanian | 6c7a1f3 | 2009-09-24 22:25:38 +0000 | [diff] [blame] | 153 | Expr *BaseIvarExp; |
Dan Gohman | 3d5aff5 | 2010-10-14 23:06:10 +0000 | [diff] [blame] | 154 | |
| 155 | /// TBAAInfo - TBAA information to attach to dereferences of this LValue. |
| 156 | llvm::MDNode *TBAAInfo; |
| 157 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 158 | private: |
John McCall | a07398e | 2011-06-16 04:16:24 +0000 | [diff] [blame] | 159 | void Initialize(QualType Type, Qualifiers Quals, unsigned Alignment = 0, |
Dan Gohman | 3d5aff5 | 2010-10-14 23:06:10 +0000 | [diff] [blame] | 160 | llvm::MDNode *TBAAInfo = 0) { |
John McCall | a07398e | 2011-06-16 04:16:24 +0000 | [diff] [blame] | 161 | this->Type = Type; |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 162 | this->Quals = Quals; |
Daniel Dunbar | 9f4f7cf | 2010-08-21 02:39:23 +0000 | [diff] [blame] | 163 | this->Alignment = Alignment; |
| 164 | assert(this->Alignment == Alignment && "Alignment exceeds allowed max!"); |
| 165 | |
| 166 | // Initialize Objective-C flags. |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 167 | this->Ivar = this->ObjIsArray = this->NonGC = this->GlobalObjCRef = false; |
Fariborz Jahanian | 021a7a6 | 2010-07-20 20:30:03 +0000 | [diff] [blame] | 168 | this->ThreadLocalRef = false; |
Fariborz Jahanian | 6c7a1f3 | 2009-09-24 22:25:38 +0000 | [diff] [blame] | 169 | this->BaseIvarExp = 0; |
Dan Gohman | 3d5aff5 | 2010-10-14 23:06:10 +0000 | [diff] [blame] | 170 | this->TBAAInfo = TBAAInfo; |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 171 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 172 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 173 | public: |
| 174 | bool isSimple() const { return LVType == Simple; } |
| 175 | bool isVectorElt() const { return LVType == VectorElt; } |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 176 | bool isBitField() const { return LVType == BitField; } |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 177 | bool isExtVectorElt() const { return LVType == ExtVectorElt; } |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 178 | bool isPropertyRef() const { return LVType == PropertyRef; } |
| 179 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 180 | bool isVolatileQualified() const { return Quals.hasVolatile(); } |
| 181 | bool isRestrictQualified() const { return Quals.hasRestrict(); } |
| 182 | unsigned getVRQualifiers() const { |
| 183 | return Quals.getCVRQualifiers() & ~Qualifiers::Const; |
Chris Lattner | 1bd885e | 2009-02-16 22:25:49 +0000 | [diff] [blame] | 184 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 185 | |
John McCall | a07398e | 2011-06-16 04:16:24 +0000 | [diff] [blame] | 186 | QualType getType() const { return Type; } |
| 187 | |
| 188 | Qualifiers::ObjCLifetime getObjCLifetime() const { |
| 189 | return Quals.getObjCLifetime(); |
| 190 | } |
| 191 | |
Fariborz Jahanian | d1cc804 | 2008-11-20 20:53:20 +0000 | [diff] [blame] | 192 | bool isObjCIvar() const { return Ivar; } |
Daniel Dunbar | 3491b3d | 2010-08-21 03:51:29 +0000 | [diff] [blame] | 193 | void setObjCIvar(bool Value) { Ivar = Value; } |
| 194 | |
Fariborz Jahanian | fd02ed7 | 2009-09-21 18:54:29 +0000 | [diff] [blame] | 195 | bool isObjCArray() const { return ObjIsArray; } |
Daniel Dunbar | 3491b3d | 2010-08-21 03:51:29 +0000 | [diff] [blame] | 196 | void setObjCArray(bool Value) { ObjIsArray = Value; } |
Daniel Dunbar | ea61917 | 2010-08-21 03:22:38 +0000 | [diff] [blame] | 197 | |
Fariborz Jahanian | 4f676ed | 2009-02-21 00:30:43 +0000 | [diff] [blame] | 198 | bool isNonGC () const { return NonGC; } |
Daniel Dunbar | ea61917 | 2010-08-21 03:22:38 +0000 | [diff] [blame] | 199 | void setNonGC(bool Value) { NonGC = Value; } |
| 200 | |
Fariborz Jahanian | bf63b87 | 2009-05-04 23:27:20 +0000 | [diff] [blame] | 201 | bool isGlobalObjCRef() const { return GlobalObjCRef; } |
Daniel Dunbar | 3491b3d | 2010-08-21 03:51:29 +0000 | [diff] [blame] | 202 | void setGlobalObjCRef(bool Value) { GlobalObjCRef = Value; } |
| 203 | |
Fariborz Jahanian | 021a7a6 | 2010-07-20 20:30:03 +0000 | [diff] [blame] | 204 | bool isThreadLocalRef() const { return ThreadLocalRef; } |
Daniel Dunbar | 3491b3d | 2010-08-21 03:51:29 +0000 | [diff] [blame] | 205 | 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 | } |
John McCall | a07398e | 2011-06-16 04:16:24 +0000 | [diff] [blame] | 213 | |
| 214 | bool isVolatile() const { |
| 215 | return Quals.hasVolatile(); |
| 216 | } |
Fariborz Jahanian | 6c7a1f3 | 2009-09-24 22:25:38 +0000 | [diff] [blame] | 217 | |
| 218 | Expr *getBaseIvarExp() const { return BaseIvarExp; } |
| 219 | void setBaseIvarExp(Expr *V) { BaseIvarExp = V; } |
Mon P Wang | c6a38a4 | 2009-07-22 03:08:17 +0000 | [diff] [blame] | 220 | |
Dan Gohman | 3d5aff5 | 2010-10-14 23:06:10 +0000 | [diff] [blame] | 221 | llvm::MDNode *getTBAAInfo() const { return TBAAInfo; } |
| 222 | void setTBAAInfo(llvm::MDNode *N) { TBAAInfo = N; } |
| 223 | |
Daniel Dunbar | 99ad7df | 2010-08-21 03:29:54 +0000 | [diff] [blame] | 224 | const Qualifiers &getQuals() const { return Quals; } |
| 225 | Qualifiers &getQuals() { return Quals; } |
| 226 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 227 | unsigned getAddressSpace() const { return Quals.getAddressSpace(); } |
Mon P Wang | c6a38a4 | 2009-07-22 03:08:17 +0000 | [diff] [blame] | 228 | |
Daniel Dunbar | 9f4f7cf | 2010-08-21 02:39:23 +0000 | [diff] [blame] | 229 | unsigned getAlignment() const { return Alignment; } |
| 230 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 231 | // simple lvalue |
| 232 | llvm::Value *getAddress() const { assert(isSimple()); return V; } |
John McCall | a07398e | 2011-06-16 04:16:24 +0000 | [diff] [blame] | 233 | void setAddress(llvm::Value *address) { |
| 234 | assert(isSimple()); |
| 235 | V = address; |
| 236 | } |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 237 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 238 | // vector elt lvalue |
| 239 | llvm::Value *getVectorAddr() const { assert(isVectorElt()); return V; } |
| 240 | llvm::Value *getVectorIdx() const { assert(isVectorElt()); return VectorIdx; } |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 241 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 242 | // extended vector elements. |
| 243 | llvm::Value *getExtVectorAddr() const { assert(isExtVectorElt()); return V; } |
| 244 | llvm::Constant *getExtVectorElts() const { |
| 245 | assert(isExtVectorElt()); |
| 246 | return VectorElts; |
| 247 | } |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 248 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 249 | // bitfield lvalue |
Daniel Dunbar | 7f28964 | 2010-04-08 02:59:45 +0000 | [diff] [blame] | 250 | llvm::Value *getBitFieldBaseAddr() const { |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 251 | assert(isBitField()); |
| 252 | return V; |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 253 | } |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 254 | const CGBitFieldInfo &getBitFieldInfo() const { |
| 255 | assert(isBitField()); |
| 256 | return *BitFieldInfo; |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 257 | } |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 258 | |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 259 | // property ref lvalue |
John McCall | 119a1c6 | 2010-12-04 02:32:38 +0000 | [diff] [blame] | 260 | llvm::Value *getPropertyRefBaseAddr() const { |
| 261 | assert(isPropertyRef()); |
| 262 | return V; |
| 263 | } |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 264 | const ObjCPropertyRefExpr *getPropertyRefExpr() const { |
| 265 | assert(isPropertyRef()); |
| 266 | return PropertyRefExpr; |
| 267 | } |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 268 | |
John McCall | a07398e | 2011-06-16 04:16:24 +0000 | [diff] [blame] | 269 | static LValue MakeAddr(llvm::Value *address, QualType type, |
| 270 | unsigned alignment, ASTContext &Context, |
Dan Gohman | 3d5aff5 | 2010-10-14 23:06:10 +0000 | [diff] [blame] | 271 | llvm::MDNode *TBAAInfo = 0) { |
John McCall | a07398e | 2011-06-16 04:16:24 +0000 | [diff] [blame] | 272 | Qualifiers qs = type.getQualifiers(); |
| 273 | qs.setObjCGCAttr(Context.getObjCGCAttrKind(type)); |
Daniel Dunbar | f1fbda3 | 2010-08-21 03:58:45 +0000 | [diff] [blame] | 274 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 275 | LValue R; |
| 276 | R.LVType = Simple; |
John McCall | a07398e | 2011-06-16 04:16:24 +0000 | [diff] [blame] | 277 | R.V = address; |
| 278 | R.Initialize(type, qs, alignment, TBAAInfo); |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 279 | return R; |
| 280 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 281 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 282 | static LValue MakeVectorElt(llvm::Value *Vec, llvm::Value *Idx, |
John McCall | a07398e | 2011-06-16 04:16:24 +0000 | [diff] [blame] | 283 | QualType type) { |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 284 | LValue R; |
| 285 | R.LVType = VectorElt; |
| 286 | R.V = Vec; |
| 287 | R.VectorIdx = Idx; |
John McCall | a07398e | 2011-06-16 04:16:24 +0000 | [diff] [blame] | 288 | R.Initialize(type, type.getQualifiers()); |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 289 | return R; |
| 290 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 291 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 292 | static LValue MakeExtVectorElt(llvm::Value *Vec, llvm::Constant *Elts, |
John McCall | a07398e | 2011-06-16 04:16:24 +0000 | [diff] [blame] | 293 | QualType type) { |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 294 | LValue R; |
| 295 | R.LVType = ExtVectorElt; |
| 296 | R.V = Vec; |
| 297 | R.VectorElts = Elts; |
John McCall | a07398e | 2011-06-16 04:16:24 +0000 | [diff] [blame] | 298 | R.Initialize(type, type.getQualifiers()); |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 299 | return R; |
| 300 | } |
| 301 | |
Daniel Dunbar | 7f28964 | 2010-04-08 02:59:45 +0000 | [diff] [blame] | 302 | /// \brief Create a new object to represent a bit-field access. |
| 303 | /// |
| 304 | /// \param BaseValue - The base address of the structure containing the |
| 305 | /// bit-field. |
| 306 | /// \param Info - The information describing how to perform the bit-field |
| 307 | /// access. |
John McCall | a07398e | 2011-06-16 04:16:24 +0000 | [diff] [blame] | 308 | static LValue MakeBitfield(llvm::Value *BaseValue, |
| 309 | const CGBitFieldInfo &Info, |
| 310 | QualType type) { |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 311 | LValue R; |
| 312 | R.LVType = BitField; |
Daniel Dunbar | 7f28964 | 2010-04-08 02:59:45 +0000 | [diff] [blame] | 313 | R.V = BaseValue; |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 314 | R.BitFieldInfo = &Info; |
John McCall | a07398e | 2011-06-16 04:16:24 +0000 | [diff] [blame] | 315 | R.Initialize(type, type.getQualifiers()); |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 316 | return R; |
| 317 | } |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 318 | |
Mike Stump | f5408fe | 2009-05-16 07:57:57 +0000 | [diff] [blame] | 319 | // FIXME: It is probably bad that we aren't emitting the target when we build |
| 320 | // the lvalue. However, this complicates the code a bit, and I haven't figured |
| 321 | // out how to make it go wrong yet. |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 322 | static LValue MakePropertyRef(const ObjCPropertyRefExpr *E, |
John McCall | 119a1c6 | 2010-12-04 02:32:38 +0000 | [diff] [blame] | 323 | llvm::Value *Base) { |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 324 | LValue R; |
| 325 | R.LVType = PropertyRef; |
John McCall | 119a1c6 | 2010-12-04 02:32:38 +0000 | [diff] [blame] | 326 | R.V = Base; |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 327 | R.PropertyRefExpr = E; |
John McCall | a07398e | 2011-06-16 04:16:24 +0000 | [diff] [blame] | 328 | R.Initialize(QualType(), Qualifiers()); |
Fariborz Jahanian | 43f4470 | 2008-11-22 22:30:21 +0000 | [diff] [blame] | 329 | return R; |
| 330 | } |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 331 | }; |
| 332 | |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 333 | /// An aggregate value slot. |
| 334 | class AggValueSlot { |
Fariborz Jahanian | 474e2fe | 2010-09-16 00:20:07 +0000 | [diff] [blame] | 335 | /// The address. |
John McCall | 6fa2916 | 2010-09-16 03:16:41 +0000 | [diff] [blame] | 336 | llvm::Value *Addr; |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 337 | |
| 338 | // Qualifiers |
| 339 | Qualifiers Quals; |
John McCall | 7c2349b | 2011-08-25 20:40:09 +0000 | [diff] [blame] | 340 | |
Fariborz Jahanian | 474e2fe | 2010-09-16 00:20:07 +0000 | [diff] [blame] | 341 | // Associated flags. |
Fariborz Jahanian | 474e2fe | 2010-09-16 00:20:07 +0000 | [diff] [blame] | 342 | bool LifetimeFlag : 1; |
| 343 | bool RequiresGCollection : 1; |
Chris Lattner | 1b72677 | 2010-12-02 07:07:26 +0000 | [diff] [blame] | 344 | |
John McCall | 7c2349b | 2011-08-25 20:40:09 +0000 | [diff] [blame] | 345 | /// ZeroedFlag - This is set to true if the destination is known to be zero |
Chris Lattner | 1b72677 | 2010-12-02 07:07:26 +0000 | [diff] [blame] | 346 | /// before the assignment into it. This means that zero fields don't need to |
| 347 | /// be set. |
John McCall | 7c2349b | 2011-08-25 20:40:09 +0000 | [diff] [blame] | 348 | bool ZeroedFlag : 1; |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 349 | |
| 350 | public: |
John McCall | 7c2349b | 2011-08-25 20:40:09 +0000 | [diff] [blame] | 351 | enum IsZeroed_t { IsNotZeroed, IsZeroed }; |
| 352 | enum IsDestructed_t { IsNotDestructed, IsDestructed }; |
| 353 | enum NeedsGCBarriers_t { DoesNotNeedGCBarriers, NeedsGCBarriers }; |
| 354 | |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 355 | /// ignored - Returns an aggregate value slot indicating that the |
| 356 | /// aggregate value is being ignored. |
| 357 | static AggValueSlot ignored() { |
| 358 | AggValueSlot AV; |
John McCall | 6fa2916 | 2010-09-16 03:16:41 +0000 | [diff] [blame] | 359 | AV.Addr = 0; |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 360 | AV.Quals = Qualifiers(); |
John McCall | 7c2349b | 2011-08-25 20:40:09 +0000 | [diff] [blame] | 361 | AV.LifetimeFlag = AV.RequiresGCollection = AV.ZeroedFlag = 0; |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 362 | return AV; |
| 363 | } |
| 364 | |
| 365 | /// forAddr - Make a slot for an aggregate value. |
| 366 | /// |
John McCall | 7c2349b | 2011-08-25 20:40:09 +0000 | [diff] [blame] | 367 | /// \param quals - The qualifiers that dictate how the slot should |
| 368 | /// be initialied. Only 'volatile' and the Objective-C lifetime |
| 369 | /// qualifiers matter. |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 370 | /// |
John McCall | 7c2349b | 2011-08-25 20:40:09 +0000 | [diff] [blame] | 371 | /// \param isDestructed - true if something else is responsible |
| 372 | /// for calling destructors on this object |
| 373 | /// \param needsGC - true if the slot is potentially located |
John McCall | d1a5f13 | 2010-09-16 03:13:23 +0000 | [diff] [blame] | 374 | /// somewhere that ObjC GC calls should be emitted for |
John McCall | 7c2349b | 2011-08-25 20:40:09 +0000 | [diff] [blame] | 375 | static AggValueSlot forAddr(llvm::Value *addr, Qualifiers quals, |
| 376 | IsDestructed_t isDestructed, |
| 377 | NeedsGCBarriers_t needsGC, |
| 378 | IsZeroed_t isZeroed = IsNotZeroed) { |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 379 | AggValueSlot AV; |
John McCall | 7c2349b | 2011-08-25 20:40:09 +0000 | [diff] [blame] | 380 | AV.Addr = addr; |
| 381 | AV.Quals = quals; |
| 382 | AV.LifetimeFlag = isDestructed; |
| 383 | AV.RequiresGCollection = needsGC; |
| 384 | AV.ZeroedFlag = isZeroed; |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 385 | return AV; |
| 386 | } |
| 387 | |
John McCall | 7c2349b | 2011-08-25 20:40:09 +0000 | [diff] [blame] | 388 | static AggValueSlot forLValue(LValue LV, IsDestructed_t isDestructed, |
| 389 | NeedsGCBarriers_t needsGC, |
| 390 | IsZeroed_t isZeroed = IsNotZeroed) { |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 391 | return forAddr(LV.getAddress(), LV.getQuals(), |
John McCall | 7c2349b | 2011-08-25 20:40:09 +0000 | [diff] [blame] | 392 | isDestructed, needsGC, isZeroed); |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 393 | } |
Fariborz Jahanian | 8a97005 | 2010-10-22 22:05:03 +0000 | [diff] [blame] | 394 | |
John McCall | 7c2349b | 2011-08-25 20:40:09 +0000 | [diff] [blame] | 395 | IsDestructed_t isLifetimeExternallyManaged() const { |
| 396 | return IsDestructed_t(LifetimeFlag); |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 397 | } |
John McCall | 74fb0ed | 2010-11-17 00:07:33 +0000 | [diff] [blame] | 398 | void setLifetimeExternallyManaged(bool Managed = true) { |
| 399 | LifetimeFlag = Managed; |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 400 | } |
| 401 | |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 402 | Qualifiers getQualifiers() const { return Quals; } |
| 403 | |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 404 | bool isVolatile() const { |
John McCall | f85e193 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 405 | return Quals.hasVolatile(); |
| 406 | } |
| 407 | |
| 408 | Qualifiers::ObjCLifetime getObjCLifetime() const { |
| 409 | return Quals.getObjCLifetime(); |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 410 | } |
| 411 | |
John McCall | 7c2349b | 2011-08-25 20:40:09 +0000 | [diff] [blame] | 412 | NeedsGCBarriers_t requiresGCollection() const { |
| 413 | return NeedsGCBarriers_t(RequiresGCollection); |
Fariborz Jahanian | 474e2fe | 2010-09-16 00:20:07 +0000 | [diff] [blame] | 414 | } |
Fariborz Jahanian | 474e2fe | 2010-09-16 00:20:07 +0000 | [diff] [blame] | 415 | |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 416 | llvm::Value *getAddr() const { |
John McCall | 6fa2916 | 2010-09-16 03:16:41 +0000 | [diff] [blame] | 417 | return Addr; |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | bool isIgnored() const { |
John McCall | 6fa2916 | 2010-09-16 03:16:41 +0000 | [diff] [blame] | 421 | return Addr == 0; |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 422 | } |
| 423 | |
| 424 | RValue asRValue() const { |
| 425 | return RValue::getAggregate(getAddr(), isVolatile()); |
| 426 | } |
| 427 | |
John McCall | 7c2349b | 2011-08-25 20:40:09 +0000 | [diff] [blame] | 428 | void setZeroed(bool V = true) { ZeroedFlag = V; } |
| 429 | IsZeroed_t isZeroed() const { |
| 430 | return IsZeroed_t(ZeroedFlag); |
Chris Lattner | 1b72677 | 2010-12-02 07:07:26 +0000 | [diff] [blame] | 431 | } |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 432 | }; |
| 433 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 434 | } // end namespace CodeGen |
| 435 | } // end namespace clang |
| 436 | |
| 437 | #endif |