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; |
Fariborz Jahanian | 09105f5 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 28 | class ObjCImplicitSetterGetterRefExpr; |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 29 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 30 | namespace CodeGen { |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 31 | class CGBitFieldInfo; |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 32 | |
| 33 | /// RValue - This trivial value class is used to represent the result of an |
| 34 | /// expression that is evaluated. It can be one of three things: either a |
| 35 | /// simple LLVM SSA value, a pair of SSA values for complex numbers, or the |
| 36 | /// address of an aggregate value in memory. |
| 37 | class RValue { |
Benjamin Kramer | 81bf3b3 | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 38 | enum Flavor { Scalar, Complex, Aggregate }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 39 | |
Benjamin Kramer | 81bf3b3 | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 40 | // Stores first value and flavor. |
| 41 | llvm::PointerIntPair<llvm::Value *, 2, Flavor> V1; |
| 42 | // Stores second value and volatility. |
| 43 | llvm::PointerIntPair<llvm::Value *, 1, bool> V2; |
| 44 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 45 | public: |
Benjamin Kramer | 81bf3b3 | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 46 | bool isScalar() const { return V1.getInt() == Scalar; } |
| 47 | bool isComplex() const { return V1.getInt() == Complex; } |
| 48 | bool isAggregate() const { return V1.getInt() == Aggregate; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 49 | |
Benjamin Kramer | 81bf3b3 | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 50 | bool isVolatileQualified() const { return V2.getInt(); } |
Mike Stump | 8b3d93a | 2009-05-23 20:21:36 +0000 | [diff] [blame] | 51 | |
Mike Stump | 519202d | 2009-11-03 16:11:57 +0000 | [diff] [blame] | 52 | /// getScalarVal() - Return the Value* of this scalar value. |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 53 | llvm::Value *getScalarVal() const { |
| 54 | assert(isScalar() && "Not a scalar!"); |
Benjamin Kramer | 81bf3b3 | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 55 | return V1.getPointer(); |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | /// getComplexVal - Return the real/imag components of this complex value. |
| 59 | /// |
| 60 | std::pair<llvm::Value *, llvm::Value *> getComplexVal() const { |
Benjamin Kramer | 81bf3b3 | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 61 | return std::make_pair(V1.getPointer(), V2.getPointer()); |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 62 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 63 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 64 | /// getAggregateAddr() - Return the Value* of the address of the aggregate. |
| 65 | llvm::Value *getAggregateAddr() const { |
| 66 | assert(isAggregate() && "Not an aggregate!"); |
Benjamin Kramer | 81bf3b3 | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 67 | return V1.getPointer(); |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 68 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 69 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 70 | static RValue get(llvm::Value *V) { |
| 71 | RValue ER; |
Benjamin Kramer | 81bf3b3 | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 72 | ER.V1.setPointer(V); |
| 73 | ER.V1.setInt(Scalar); |
| 74 | ER.V2.setInt(false); |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 75 | return ER; |
| 76 | } |
| 77 | static RValue getComplex(llvm::Value *V1, llvm::Value *V2) { |
| 78 | RValue ER; |
Benjamin Kramer | 81bf3b3 | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 79 | ER.V1.setPointer(V1); |
| 80 | ER.V2.setPointer(V2); |
| 81 | ER.V1.setInt(Complex); |
| 82 | ER.V2.setInt(false); |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 83 | return ER; |
| 84 | } |
| 85 | static RValue getComplex(const std::pair<llvm::Value *, llvm::Value *> &C) { |
Benjamin Kramer | 81bf3b3 | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 86 | return getComplex(C.first, C.second); |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 87 | } |
Mike Stump | 8b3d93a | 2009-05-23 20:21:36 +0000 | [diff] [blame] | 88 | // FIXME: Aggregate rvalues need to retain information about whether they are |
| 89 | // volatile or not. Remove default to find all places that probably get this |
| 90 | // wrong. |
Benjamin Kramer | 81bf3b3 | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 91 | static RValue getAggregate(llvm::Value *V, bool Volatile = false) { |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 92 | RValue ER; |
Benjamin Kramer | 81bf3b3 | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 93 | ER.V1.setPointer(V); |
| 94 | ER.V1.setInt(Aggregate); |
| 95 | ER.V2.setInt(Volatile); |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 96 | return ER; |
| 97 | } |
| 98 | }; |
| 99 | |
| 100 | |
| 101 | /// LValue - This represents an lvalue references. Because C/C++ allow |
| 102 | /// bitfields, this is not a simple LLVM pointer, it may be a pointer plus a |
| 103 | /// bitrange. |
| 104 | class LValue { |
| 105 | // FIXME: alignment? |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 106 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 107 | enum { |
| 108 | Simple, // This is a normal l-value, use getAddress(). |
| 109 | VectorElt, // This is a vector element l-value (V[i]), use getVector* |
| 110 | BitField, // This is a bitfield l-value, use getBitfield*. |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 111 | ExtVectorElt, // This is an extended vector subset, use getExtVectorComp |
Fariborz Jahanian | 43f4470 | 2008-11-22 22:30:21 +0000 | [diff] [blame] | 112 | PropertyRef, // This is an Objective-C property reference, use |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 113 | // getPropertyRefExpr |
Fariborz Jahanian | 43f4470 | 2008-11-22 22:30:21 +0000 | [diff] [blame] | 114 | KVCRef // This is an objective-c 'implicit' property ref, |
| 115 | // use getKVCRefExpr |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 116 | } LVType; |
Fariborz Jahanian | 5862650 | 2008-11-19 00:59:10 +0000 | [diff] [blame] | 117 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 118 | llvm::Value *V; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 119 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 120 | union { |
| 121 | // Index into a vector subscript: V[i] |
| 122 | llvm::Value *VectorIdx; |
| 123 | |
| 124 | // ExtVector element subset: V.xyx |
| 125 | llvm::Constant *VectorElts; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 126 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 127 | // BitField start bit and size |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 128 | const CGBitFieldInfo *BitFieldInfo; |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 129 | |
| 130 | // Obj-C property reference expression |
| 131 | const ObjCPropertyRefExpr *PropertyRefExpr; |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 132 | |
Fariborz Jahanian | 43f4470 | 2008-11-22 22:30:21 +0000 | [diff] [blame] | 133 | // ObjC 'implicit' property reference expression |
Fariborz Jahanian | 09105f5 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 134 | const ObjCImplicitSetterGetterRefExpr *KVCRefExpr; |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 135 | }; |
| 136 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 137 | // 'const' is unused here |
| 138 | Qualifiers Quals; |
Fariborz Jahanian | 5862650 | 2008-11-19 00:59:10 +0000 | [diff] [blame] | 139 | |
Daniel Dunbar | 9f4f7cf | 2010-08-21 02:39:23 +0000 | [diff] [blame] | 140 | /// The alignment to use when accessing this lvalue. |
Daniel Dunbar | 77c0590 | 2010-08-26 06:02:12 +0000 | [diff] [blame] | 141 | unsigned short Alignment; |
Daniel Dunbar | 9f4f7cf | 2010-08-21 02:39:23 +0000 | [diff] [blame] | 142 | |
Fariborz Jahanian | d1cc804 | 2008-11-20 20:53:20 +0000 | [diff] [blame] | 143 | // objective-c's ivar |
| 144 | bool Ivar:1; |
Fariborz Jahanian | 1c1afc4 | 2009-09-18 00:04:00 +0000 | [diff] [blame] | 145 | |
| 146 | // objective-c's ivar is an array |
Fariborz Jahanian | fd02ed7 | 2009-09-21 18:54:29 +0000 | [diff] [blame] | 147 | bool ObjIsArray:1; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 148 | |
Fariborz Jahanian | 4f676ed | 2009-02-21 00:30:43 +0000 | [diff] [blame] | 149 | // LValue is non-gc'able for any reason, including being a parameter or local |
| 150 | // variable. |
| 151 | bool NonGC: 1; |
Fariborz Jahanian | d1cc804 | 2008-11-20 20:53:20 +0000 | [diff] [blame] | 152 | |
Fariborz Jahanian | bf63b87 | 2009-05-04 23:27:20 +0000 | [diff] [blame] | 153 | // Lvalue is a global reference of an objective-c object |
| 154 | bool GlobalObjCRef : 1; |
Fariborz Jahanian | 021a7a6 | 2010-07-20 20:30:03 +0000 | [diff] [blame] | 155 | |
| 156 | // Lvalue is a thread local reference |
| 157 | bool ThreadLocalRef : 1; |
Fariborz Jahanian | bf63b87 | 2009-05-04 23:27:20 +0000 | [diff] [blame] | 158 | |
Fariborz Jahanian | 6c7a1f3 | 2009-09-24 22:25:38 +0000 | [diff] [blame] | 159 | Expr *BaseIvarExp; |
Dan Gohman | 3d5aff5 | 2010-10-14 23:06:10 +0000 | [diff] [blame] | 160 | |
| 161 | /// TBAAInfo - TBAA information to attach to dereferences of this LValue. |
| 162 | llvm::MDNode *TBAAInfo; |
| 163 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 164 | private: |
Dan Gohman | 3d5aff5 | 2010-10-14 23:06:10 +0000 | [diff] [blame] | 165 | void Initialize(Qualifiers Quals, unsigned Alignment = 0, |
| 166 | llvm::MDNode *TBAAInfo = 0) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 167 | this->Quals = Quals; |
Daniel Dunbar | 9f4f7cf | 2010-08-21 02:39:23 +0000 | [diff] [blame] | 168 | this->Alignment = Alignment; |
| 169 | assert(this->Alignment == Alignment && "Alignment exceeds allowed max!"); |
| 170 | |
| 171 | // Initialize Objective-C flags. |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 172 | this->Ivar = this->ObjIsArray = this->NonGC = this->GlobalObjCRef = false; |
Fariborz Jahanian | 021a7a6 | 2010-07-20 20:30:03 +0000 | [diff] [blame] | 173 | this->ThreadLocalRef = false; |
Fariborz Jahanian | 6c7a1f3 | 2009-09-24 22:25:38 +0000 | [diff] [blame] | 174 | this->BaseIvarExp = 0; |
Dan Gohman | 3d5aff5 | 2010-10-14 23:06:10 +0000 | [diff] [blame] | 175 | this->TBAAInfo = TBAAInfo; |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 176 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 177 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 178 | public: |
| 179 | bool isSimple() const { return LVType == Simple; } |
| 180 | bool isVectorElt() const { return LVType == VectorElt; } |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 181 | bool isBitField() const { return LVType == BitField; } |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 182 | bool isExtVectorElt() const { return LVType == ExtVectorElt; } |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 183 | bool isPropertyRef() const { return LVType == PropertyRef; } |
Fariborz Jahanian | 43f4470 | 2008-11-22 22:30:21 +0000 | [diff] [blame] | 184 | bool isKVCRef() const { return LVType == KVCRef; } |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 185 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 186 | bool isVolatileQualified() const { return Quals.hasVolatile(); } |
| 187 | bool isRestrictQualified() const { return Quals.hasRestrict(); } |
| 188 | unsigned getVRQualifiers() const { |
| 189 | return Quals.getCVRQualifiers() & ~Qualifiers::Const; |
Chris Lattner | 1bd885e | 2009-02-16 22:25:49 +0000 | [diff] [blame] | 190 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 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 | } |
Fariborz Jahanian | 6c7a1f3 | 2009-09-24 22:25:38 +0000 | [diff] [blame] | 213 | |
| 214 | Expr *getBaseIvarExp() const { return BaseIvarExp; } |
| 215 | void setBaseIvarExp(Expr *V) { BaseIvarExp = V; } |
Mon P Wang | c6a38a4 | 2009-07-22 03:08:17 +0000 | [diff] [blame] | 216 | |
Dan Gohman | 3d5aff5 | 2010-10-14 23:06:10 +0000 | [diff] [blame] | 217 | llvm::MDNode *getTBAAInfo() const { return TBAAInfo; } |
| 218 | void setTBAAInfo(llvm::MDNode *N) { TBAAInfo = N; } |
| 219 | |
Daniel Dunbar | 99ad7df | 2010-08-21 03:29:54 +0000 | [diff] [blame] | 220 | const Qualifiers &getQuals() const { return Quals; } |
| 221 | Qualifiers &getQuals() { return Quals; } |
| 222 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 223 | unsigned getAddressSpace() const { return Quals.getAddressSpace(); } |
Mon P Wang | c6a38a4 | 2009-07-22 03:08:17 +0000 | [diff] [blame] | 224 | |
Daniel Dunbar | 9f4f7cf | 2010-08-21 02:39:23 +0000 | [diff] [blame] | 225 | unsigned getAlignment() const { return Alignment; } |
| 226 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 227 | // simple lvalue |
| 228 | llvm::Value *getAddress() const { assert(isSimple()); return V; } |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 229 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 230 | // vector elt lvalue |
| 231 | llvm::Value *getVectorAddr() const { assert(isVectorElt()); return V; } |
| 232 | llvm::Value *getVectorIdx() const { assert(isVectorElt()); return VectorIdx; } |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 233 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 234 | // extended vector elements. |
| 235 | llvm::Value *getExtVectorAddr() const { assert(isExtVectorElt()); return V; } |
| 236 | llvm::Constant *getExtVectorElts() const { |
| 237 | assert(isExtVectorElt()); |
| 238 | return VectorElts; |
| 239 | } |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 240 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 241 | // bitfield lvalue |
Daniel Dunbar | 7f28964 | 2010-04-08 02:59:45 +0000 | [diff] [blame] | 242 | llvm::Value *getBitFieldBaseAddr() const { |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 243 | assert(isBitField()); |
| 244 | return V; |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 245 | } |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 246 | const CGBitFieldInfo &getBitFieldInfo() const { |
| 247 | assert(isBitField()); |
| 248 | return *BitFieldInfo; |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 249 | } |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 250 | |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 251 | // property ref lvalue |
| 252 | const ObjCPropertyRefExpr *getPropertyRefExpr() const { |
| 253 | assert(isPropertyRef()); |
| 254 | return PropertyRefExpr; |
| 255 | } |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 256 | |
Fariborz Jahanian | 43f4470 | 2008-11-22 22:30:21 +0000 | [diff] [blame] | 257 | // 'implicit' property ref lvalue |
Fariborz Jahanian | 09105f5 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 258 | const ObjCImplicitSetterGetterRefExpr *getKVCRefExpr() const { |
Fariborz Jahanian | 43f4470 | 2008-11-22 22:30:21 +0000 | [diff] [blame] | 259 | assert(isKVCRef()); |
| 260 | return KVCRefExpr; |
| 261 | } |
| 262 | |
Daniel Dunbar | f1fbda3 | 2010-08-21 03:58:45 +0000 | [diff] [blame] | 263 | static LValue MakeAddr(llvm::Value *V, QualType T, unsigned Alignment, |
Dan Gohman | 3d5aff5 | 2010-10-14 23:06:10 +0000 | [diff] [blame] | 264 | ASTContext &Context, |
| 265 | llvm::MDNode *TBAAInfo = 0) { |
Daniel Dunbar | f1fbda3 | 2010-08-21 03:58:45 +0000 | [diff] [blame] | 266 | Qualifiers Quals = Context.getCanonicalType(T).getQualifiers(); |
| 267 | Quals.setObjCGCAttr(Context.getObjCGCAttrKind(T)); |
| 268 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 269 | LValue R; |
| 270 | R.LVType = Simple; |
| 271 | R.V = V; |
Dan Gohman | 3d5aff5 | 2010-10-14 23:06:10 +0000 | [diff] [blame] | 272 | R.Initialize(Quals, Alignment, TBAAInfo); |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 273 | return R; |
| 274 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 275 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 276 | static LValue MakeVectorElt(llvm::Value *Vec, llvm::Value *Idx, |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 277 | unsigned CVR) { |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 278 | LValue R; |
| 279 | R.LVType = VectorElt; |
| 280 | R.V = Vec; |
| 281 | R.VectorIdx = Idx; |
Daniel Dunbar | de98881 | 2010-08-21 02:31:58 +0000 | [diff] [blame] | 282 | R.Initialize(Qualifiers::fromCVRMask(CVR)); |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 283 | return R; |
| 284 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 285 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 286 | static LValue MakeExtVectorElt(llvm::Value *Vec, llvm::Constant *Elts, |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 287 | unsigned CVR) { |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 288 | LValue R; |
| 289 | R.LVType = ExtVectorElt; |
| 290 | R.V = Vec; |
| 291 | R.VectorElts = Elts; |
Daniel Dunbar | de98881 | 2010-08-21 02:31:58 +0000 | [diff] [blame] | 292 | R.Initialize(Qualifiers::fromCVRMask(CVR)); |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 293 | return R; |
| 294 | } |
| 295 | |
Daniel Dunbar | 7f28964 | 2010-04-08 02:59:45 +0000 | [diff] [blame] | 296 | /// \brief Create a new object to represent a bit-field access. |
| 297 | /// |
| 298 | /// \param BaseValue - The base address of the structure containing the |
| 299 | /// bit-field. |
| 300 | /// \param Info - The information describing how to perform the bit-field |
| 301 | /// access. |
| 302 | static LValue MakeBitfield(llvm::Value *BaseValue, const CGBitFieldInfo &Info, |
Daniel Dunbar | efbf487 | 2010-04-06 01:07:44 +0000 | [diff] [blame] | 303 | unsigned CVR) { |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 304 | LValue R; |
| 305 | R.LVType = BitField; |
Daniel Dunbar | 7f28964 | 2010-04-08 02:59:45 +0000 | [diff] [blame] | 306 | R.V = BaseValue; |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 307 | R.BitFieldInfo = &Info; |
Daniel Dunbar | de98881 | 2010-08-21 02:31:58 +0000 | [diff] [blame] | 308 | R.Initialize(Qualifiers::fromCVRMask(CVR)); |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 309 | return R; |
| 310 | } |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 311 | |
Mike Stump | f5408fe | 2009-05-16 07:57:57 +0000 | [diff] [blame] | 312 | // FIXME: It is probably bad that we aren't emitting the target when we build |
| 313 | // the lvalue. However, this complicates the code a bit, and I haven't figured |
| 314 | // out how to make it go wrong yet. |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 315 | static LValue MakePropertyRef(const ObjCPropertyRefExpr *E, |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 316 | unsigned CVR) { |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 317 | LValue R; |
| 318 | R.LVType = PropertyRef; |
| 319 | R.PropertyRefExpr = E; |
Daniel Dunbar | de98881 | 2010-08-21 02:31:58 +0000 | [diff] [blame] | 320 | R.Initialize(Qualifiers::fromCVRMask(CVR)); |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 321 | return R; |
| 322 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 323 | |
| 324 | static LValue MakeKVCRef(const ObjCImplicitSetterGetterRefExpr *E, |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 325 | unsigned CVR) { |
Fariborz Jahanian | 43f4470 | 2008-11-22 22:30:21 +0000 | [diff] [blame] | 326 | LValue R; |
| 327 | R.LVType = KVCRef; |
| 328 | R.KVCRefExpr = E; |
Daniel Dunbar | de98881 | 2010-08-21 02:31:58 +0000 | [diff] [blame] | 329 | R.Initialize(Qualifiers::fromCVRMask(CVR)); |
Fariborz Jahanian | 43f4470 | 2008-11-22 22:30:21 +0000 | [diff] [blame] | 330 | return R; |
| 331 | } |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 332 | }; |
| 333 | |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 334 | /// An aggregate value slot. |
| 335 | class AggValueSlot { |
Fariborz Jahanian | 474e2fe | 2010-09-16 00:20:07 +0000 | [diff] [blame] | 336 | /// The address. |
John McCall | 6fa2916 | 2010-09-16 03:16:41 +0000 | [diff] [blame] | 337 | llvm::Value *Addr; |
Fariborz Jahanian | 474e2fe | 2010-09-16 00:20:07 +0000 | [diff] [blame] | 338 | |
| 339 | // Associated flags. |
| 340 | bool VolatileFlag : 1; |
| 341 | bool LifetimeFlag : 1; |
| 342 | bool RequiresGCollection : 1; |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 343 | |
| 344 | public: |
| 345 | /// ignored - Returns an aggregate value slot indicating that the |
| 346 | /// aggregate value is being ignored. |
| 347 | static AggValueSlot ignored() { |
| 348 | AggValueSlot AV; |
John McCall | 6fa2916 | 2010-09-16 03:16:41 +0000 | [diff] [blame] | 349 | AV.Addr = 0; |
Fariborz Jahanian | 474e2fe | 2010-09-16 00:20:07 +0000 | [diff] [blame] | 350 | AV.VolatileFlag = AV.LifetimeFlag = AV.RequiresGCollection = 0; |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 351 | return AV; |
| 352 | } |
| 353 | |
| 354 | /// forAddr - Make a slot for an aggregate value. |
| 355 | /// |
| 356 | /// \param Volatile - true if the slot should be volatile-initialized |
| 357 | /// \param LifetimeExternallyManaged - true if the slot's lifetime |
| 358 | /// is being externally managed; false if a destructor should be |
| 359 | /// registered for any temporaries evaluated into the slot |
John McCall | d1a5f13 | 2010-09-16 03:13:23 +0000 | [diff] [blame] | 360 | /// \param RequiresGCollection - true if the slot is located |
| 361 | /// somewhere that ObjC GC calls should be emitted for |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 362 | static AggValueSlot forAddr(llvm::Value *Addr, bool Volatile, |
Fariborz Jahanian | 474e2fe | 2010-09-16 00:20:07 +0000 | [diff] [blame] | 363 | bool LifetimeExternallyManaged, |
| 364 | bool RequiresGCollection=false) { |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 365 | AggValueSlot AV; |
John McCall | 6fa2916 | 2010-09-16 03:16:41 +0000 | [diff] [blame] | 366 | AV.Addr = Addr; |
John McCall | d1a5f13 | 2010-09-16 03:13:23 +0000 | [diff] [blame] | 367 | AV.VolatileFlag = Volatile; |
| 368 | AV.LifetimeFlag = LifetimeExternallyManaged; |
| 369 | AV.RequiresGCollection = RequiresGCollection; |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 370 | return AV; |
| 371 | } |
| 372 | |
Fariborz Jahanian | 474e2fe | 2010-09-16 00:20:07 +0000 | [diff] [blame] | 373 | static AggValueSlot forLValue(LValue LV, bool LifetimeExternallyManaged, |
| 374 | bool RequiresGCollection=false) { |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 375 | return forAddr(LV.getAddress(), LV.isVolatileQualified(), |
Fariborz Jahanian | 474e2fe | 2010-09-16 00:20:07 +0000 | [diff] [blame] | 376 | LifetimeExternallyManaged, RequiresGCollection); |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 377 | } |
Fariborz Jahanian | 8a97005 | 2010-10-22 22:05:03 +0000 | [diff] [blame^] | 378 | |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 379 | bool isLifetimeExternallyManaged() const { |
Fariborz Jahanian | 474e2fe | 2010-09-16 00:20:07 +0000 | [diff] [blame] | 380 | return LifetimeFlag; |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 381 | } |
| 382 | void setLifetimeExternallyManaged() { |
John McCall | d1a5f13 | 2010-09-16 03:13:23 +0000 | [diff] [blame] | 383 | LifetimeFlag = true; |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | bool isVolatile() const { |
Fariborz Jahanian | 474e2fe | 2010-09-16 00:20:07 +0000 | [diff] [blame] | 387 | return VolatileFlag; |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 388 | } |
| 389 | |
John McCall | d1a5f13 | 2010-09-16 03:13:23 +0000 | [diff] [blame] | 390 | bool requiresGCollection() const { |
Fariborz Jahanian | 474e2fe | 2010-09-16 00:20:07 +0000 | [diff] [blame] | 391 | return RequiresGCollection; |
| 392 | } |
Fariborz Jahanian | 474e2fe | 2010-09-16 00:20:07 +0000 | [diff] [blame] | 393 | |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 394 | llvm::Value *getAddr() const { |
John McCall | 6fa2916 | 2010-09-16 03:16:41 +0000 | [diff] [blame] | 395 | return Addr; |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | bool isIgnored() const { |
John McCall | 6fa2916 | 2010-09-16 03:16:41 +0000 | [diff] [blame] | 399 | return Addr == 0; |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | RValue asRValue() const { |
| 403 | return RValue::getAggregate(getAddr(), isVolatile()); |
| 404 | } |
| 405 | |
| 406 | }; |
| 407 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 408 | } // end namespace CodeGen |
| 409 | } // end namespace clang |
| 410 | |
| 411 | #endif |