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 { |
| 104 | // FIXME: alignment? |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 105 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 106 | enum { |
| 107 | Simple, // This is a normal l-value, use getAddress(). |
| 108 | VectorElt, // This is a vector element l-value (V[i]), use getVector* |
| 109 | BitField, // This is a bitfield l-value, use getBitfield*. |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 110 | ExtVectorElt, // This is an extended vector subset, use getExtVectorComp |
John McCall | 119a1c6 | 2010-12-04 02:32:38 +0000 | [diff] [blame] | 111 | PropertyRef // This is an Objective-C property reference, use |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 112 | // getPropertyRefExpr |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 113 | } LVType; |
Fariborz Jahanian | 5862650 | 2008-11-19 00:59:10 +0000 | [diff] [blame] | 114 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 115 | llvm::Value *V; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 116 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 117 | union { |
| 118 | // Index into a vector subscript: V[i] |
| 119 | llvm::Value *VectorIdx; |
| 120 | |
| 121 | // ExtVector element subset: V.xyx |
| 122 | llvm::Constant *VectorElts; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 123 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 124 | // BitField start bit and size |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 125 | const CGBitFieldInfo *BitFieldInfo; |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 126 | |
| 127 | // Obj-C property reference expression |
| 128 | const ObjCPropertyRefExpr *PropertyRefExpr; |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 129 | }; |
| 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: |
Dan Gohman | 3d5aff5 | 2010-10-14 23:06:10 +0000 | [diff] [blame] | 159 | void Initialize(Qualifiers Quals, unsigned Alignment = 0, |
| 160 | llvm::MDNode *TBAAInfo = 0) { |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 161 | this->Quals = Quals; |
Daniel Dunbar | 9f4f7cf | 2010-08-21 02:39:23 +0000 | [diff] [blame] | 162 | this->Alignment = Alignment; |
| 163 | assert(this->Alignment == Alignment && "Alignment exceeds allowed max!"); |
| 164 | |
| 165 | // Initialize Objective-C flags. |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 166 | this->Ivar = this->ObjIsArray = this->NonGC = this->GlobalObjCRef = false; |
Fariborz Jahanian | 021a7a6 | 2010-07-20 20:30:03 +0000 | [diff] [blame] | 167 | this->ThreadLocalRef = false; |
Fariborz Jahanian | 6c7a1f3 | 2009-09-24 22:25:38 +0000 | [diff] [blame] | 168 | this->BaseIvarExp = 0; |
Dan Gohman | 3d5aff5 | 2010-10-14 23:06:10 +0000 | [diff] [blame] | 169 | this->TBAAInfo = TBAAInfo; |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 170 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 171 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 172 | public: |
| 173 | bool isSimple() const { return LVType == Simple; } |
| 174 | bool isVectorElt() const { return LVType == VectorElt; } |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 175 | bool isBitField() const { return LVType == BitField; } |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 176 | bool isExtVectorElt() const { return LVType == ExtVectorElt; } |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 177 | bool isPropertyRef() const { return LVType == PropertyRef; } |
| 178 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 179 | bool isVolatileQualified() const { return Quals.hasVolatile(); } |
| 180 | bool isRestrictQualified() const { return Quals.hasRestrict(); } |
| 181 | unsigned getVRQualifiers() const { |
| 182 | return Quals.getCVRQualifiers() & ~Qualifiers::Const; |
Chris Lattner | 1bd885e | 2009-02-16 22:25:49 +0000 | [diff] [blame] | 183 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 184 | |
Fariborz Jahanian | d1cc804 | 2008-11-20 20:53:20 +0000 | [diff] [blame] | 185 | bool isObjCIvar() const { return Ivar; } |
Daniel Dunbar | 3491b3d | 2010-08-21 03:51:29 +0000 | [diff] [blame] | 186 | void setObjCIvar(bool Value) { Ivar = Value; } |
| 187 | |
Fariborz Jahanian | fd02ed7 | 2009-09-21 18:54:29 +0000 | [diff] [blame] | 188 | bool isObjCArray() const { return ObjIsArray; } |
Daniel Dunbar | 3491b3d | 2010-08-21 03:51:29 +0000 | [diff] [blame] | 189 | void setObjCArray(bool Value) { ObjIsArray = Value; } |
Daniel Dunbar | ea61917 | 2010-08-21 03:22:38 +0000 | [diff] [blame] | 190 | |
Fariborz Jahanian | 4f676ed | 2009-02-21 00:30:43 +0000 | [diff] [blame] | 191 | bool isNonGC () const { return NonGC; } |
Daniel Dunbar | ea61917 | 2010-08-21 03:22:38 +0000 | [diff] [blame] | 192 | void setNonGC(bool Value) { NonGC = Value; } |
| 193 | |
Fariborz Jahanian | bf63b87 | 2009-05-04 23:27:20 +0000 | [diff] [blame] | 194 | bool isGlobalObjCRef() const { return GlobalObjCRef; } |
Daniel Dunbar | 3491b3d | 2010-08-21 03:51:29 +0000 | [diff] [blame] | 195 | void setGlobalObjCRef(bool Value) { GlobalObjCRef = Value; } |
| 196 | |
Fariborz Jahanian | 021a7a6 | 2010-07-20 20:30:03 +0000 | [diff] [blame] | 197 | bool isThreadLocalRef() const { return ThreadLocalRef; } |
Daniel Dunbar | 3491b3d | 2010-08-21 03:51:29 +0000 | [diff] [blame] | 198 | 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 | } |
Fariborz Jahanian | 6c7a1f3 | 2009-09-24 22:25:38 +0000 | [diff] [blame] | 206 | |
| 207 | Expr *getBaseIvarExp() const { return BaseIvarExp; } |
| 208 | void setBaseIvarExp(Expr *V) { BaseIvarExp = V; } |
Mon P Wang | c6a38a4 | 2009-07-22 03:08:17 +0000 | [diff] [blame] | 209 | |
Dan Gohman | 3d5aff5 | 2010-10-14 23:06:10 +0000 | [diff] [blame] | 210 | llvm::MDNode *getTBAAInfo() const { return TBAAInfo; } |
| 211 | void setTBAAInfo(llvm::MDNode *N) { TBAAInfo = N; } |
| 212 | |
Daniel Dunbar | 99ad7df | 2010-08-21 03:29:54 +0000 | [diff] [blame] | 213 | const Qualifiers &getQuals() const { return Quals; } |
| 214 | Qualifiers &getQuals() { return Quals; } |
| 215 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 216 | unsigned getAddressSpace() const { return Quals.getAddressSpace(); } |
Mon P Wang | c6a38a4 | 2009-07-22 03:08:17 +0000 | [diff] [blame] | 217 | |
Daniel Dunbar | 9f4f7cf | 2010-08-21 02:39:23 +0000 | [diff] [blame] | 218 | unsigned getAlignment() const { return Alignment; } |
| 219 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 220 | // simple lvalue |
| 221 | llvm::Value *getAddress() const { assert(isSimple()); return V; } |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 222 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 223 | // vector elt lvalue |
| 224 | llvm::Value *getVectorAddr() const { assert(isVectorElt()); return V; } |
| 225 | llvm::Value *getVectorIdx() const { assert(isVectorElt()); return VectorIdx; } |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 226 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 227 | // extended vector elements. |
| 228 | llvm::Value *getExtVectorAddr() const { assert(isExtVectorElt()); return V; } |
| 229 | llvm::Constant *getExtVectorElts() const { |
| 230 | assert(isExtVectorElt()); |
| 231 | return VectorElts; |
| 232 | } |
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 | // bitfield lvalue |
Daniel Dunbar | 7f28964 | 2010-04-08 02:59:45 +0000 | [diff] [blame] | 235 | llvm::Value *getBitFieldBaseAddr() const { |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 236 | assert(isBitField()); |
| 237 | return V; |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 238 | } |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 239 | const CGBitFieldInfo &getBitFieldInfo() const { |
| 240 | assert(isBitField()); |
| 241 | return *BitFieldInfo; |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 242 | } |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 243 | |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 244 | // property ref lvalue |
John McCall | 119a1c6 | 2010-12-04 02:32:38 +0000 | [diff] [blame] | 245 | llvm::Value *getPropertyRefBaseAddr() const { |
| 246 | assert(isPropertyRef()); |
| 247 | return V; |
| 248 | } |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 249 | const ObjCPropertyRefExpr *getPropertyRefExpr() const { |
| 250 | assert(isPropertyRef()); |
| 251 | return PropertyRefExpr; |
| 252 | } |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 253 | |
Daniel Dunbar | f1fbda3 | 2010-08-21 03:58:45 +0000 | [diff] [blame] | 254 | static LValue MakeAddr(llvm::Value *V, QualType T, unsigned Alignment, |
Dan Gohman | 3d5aff5 | 2010-10-14 23:06:10 +0000 | [diff] [blame] | 255 | ASTContext &Context, |
| 256 | llvm::MDNode *TBAAInfo = 0) { |
John McCall | 5808ce4 | 2011-02-03 08:15:49 +0000 | [diff] [blame] | 257 | Qualifiers Quals = T.getQualifiers(); |
Daniel Dunbar | f1fbda3 | 2010-08-21 03:58:45 +0000 | [diff] [blame] | 258 | Quals.setObjCGCAttr(Context.getObjCGCAttrKind(T)); |
| 259 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 260 | LValue R; |
| 261 | R.LVType = Simple; |
| 262 | R.V = V; |
Dan Gohman | 3d5aff5 | 2010-10-14 23:06:10 +0000 | [diff] [blame] | 263 | R.Initialize(Quals, Alignment, TBAAInfo); |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 264 | return R; |
| 265 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 266 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 267 | static LValue MakeVectorElt(llvm::Value *Vec, llvm::Value *Idx, |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 268 | unsigned CVR) { |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 269 | LValue R; |
| 270 | R.LVType = VectorElt; |
| 271 | R.V = Vec; |
| 272 | R.VectorIdx = Idx; |
Daniel Dunbar | de98881 | 2010-08-21 02:31:58 +0000 | [diff] [blame] | 273 | R.Initialize(Qualifiers::fromCVRMask(CVR)); |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 274 | return R; |
| 275 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 276 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 277 | static LValue MakeExtVectorElt(llvm::Value *Vec, llvm::Constant *Elts, |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 278 | unsigned CVR) { |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 279 | LValue R; |
| 280 | R.LVType = ExtVectorElt; |
| 281 | R.V = Vec; |
| 282 | R.VectorElts = Elts; |
Daniel Dunbar | de98881 | 2010-08-21 02:31:58 +0000 | [diff] [blame] | 283 | R.Initialize(Qualifiers::fromCVRMask(CVR)); |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 284 | return R; |
| 285 | } |
| 286 | |
Daniel Dunbar | 7f28964 | 2010-04-08 02:59:45 +0000 | [diff] [blame] | 287 | /// \brief Create a new object to represent a bit-field access. |
| 288 | /// |
| 289 | /// \param BaseValue - The base address of the structure containing the |
| 290 | /// bit-field. |
| 291 | /// \param Info - The information describing how to perform the bit-field |
| 292 | /// access. |
| 293 | static LValue MakeBitfield(llvm::Value *BaseValue, const CGBitFieldInfo &Info, |
Daniel Dunbar | efbf487 | 2010-04-06 01:07:44 +0000 | [diff] [blame] | 294 | unsigned CVR) { |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 295 | LValue R; |
| 296 | R.LVType = BitField; |
Daniel Dunbar | 7f28964 | 2010-04-08 02:59:45 +0000 | [diff] [blame] | 297 | R.V = BaseValue; |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 298 | R.BitFieldInfo = &Info; |
Daniel Dunbar | de98881 | 2010-08-21 02:31:58 +0000 | [diff] [blame] | 299 | R.Initialize(Qualifiers::fromCVRMask(CVR)); |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 300 | return R; |
| 301 | } |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 302 | |
Mike Stump | f5408fe | 2009-05-16 07:57:57 +0000 | [diff] [blame] | 303 | // FIXME: It is probably bad that we aren't emitting the target when we build |
| 304 | // the lvalue. However, this complicates the code a bit, and I haven't figured |
| 305 | // out how to make it go wrong yet. |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 306 | static LValue MakePropertyRef(const ObjCPropertyRefExpr *E, |
John McCall | 119a1c6 | 2010-12-04 02:32:38 +0000 | [diff] [blame] | 307 | llvm::Value *Base) { |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 308 | LValue R; |
| 309 | R.LVType = PropertyRef; |
John McCall | 119a1c6 | 2010-12-04 02:32:38 +0000 | [diff] [blame] | 310 | R.V = Base; |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 311 | R.PropertyRefExpr = E; |
John McCall | 119a1c6 | 2010-12-04 02:32:38 +0000 | [diff] [blame] | 312 | R.Initialize(Qualifiers()); |
Fariborz Jahanian | 43f4470 | 2008-11-22 22:30:21 +0000 | [diff] [blame] | 313 | return R; |
| 314 | } |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 315 | }; |
| 316 | |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 317 | /// An aggregate value slot. |
| 318 | class AggValueSlot { |
Fariborz Jahanian | 474e2fe | 2010-09-16 00:20:07 +0000 | [diff] [blame] | 319 | /// The address. |
John McCall | 6fa2916 | 2010-09-16 03:16:41 +0000 | [diff] [blame] | 320 | llvm::Value *Addr; |
Fariborz Jahanian | 474e2fe | 2010-09-16 00:20:07 +0000 | [diff] [blame] | 321 | |
| 322 | // Associated flags. |
| 323 | bool VolatileFlag : 1; |
| 324 | bool LifetimeFlag : 1; |
| 325 | bool RequiresGCollection : 1; |
Chris Lattner | 1b72677 | 2010-12-02 07:07:26 +0000 | [diff] [blame] | 326 | |
| 327 | /// IsZeroed - This is set to true if the destination is known to be zero |
| 328 | /// before the assignment into it. This means that zero fields don't need to |
| 329 | /// be set. |
| 330 | bool IsZeroed : 1; |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 331 | |
| 332 | public: |
| 333 | /// ignored - Returns an aggregate value slot indicating that the |
| 334 | /// aggregate value is being ignored. |
| 335 | static AggValueSlot ignored() { |
| 336 | AggValueSlot AV; |
John McCall | 6fa2916 | 2010-09-16 03:16:41 +0000 | [diff] [blame] | 337 | AV.Addr = 0; |
Chris Lattner | 1b72677 | 2010-12-02 07:07:26 +0000 | [diff] [blame] | 338 | AV.VolatileFlag = AV.LifetimeFlag = AV.RequiresGCollection = AV.IsZeroed =0; |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 339 | return AV; |
| 340 | } |
| 341 | |
| 342 | /// forAddr - Make a slot for an aggregate value. |
| 343 | /// |
| 344 | /// \param Volatile - true if the slot should be volatile-initialized |
| 345 | /// \param LifetimeExternallyManaged - true if the slot's lifetime |
| 346 | /// is being externally managed; false if a destructor should be |
| 347 | /// registered for any temporaries evaluated into the slot |
John McCall | d1a5f13 | 2010-09-16 03:13:23 +0000 | [diff] [blame] | 348 | /// \param RequiresGCollection - true if the slot is located |
| 349 | /// somewhere that ObjC GC calls should be emitted for |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 350 | static AggValueSlot forAddr(llvm::Value *Addr, bool Volatile, |
Fariborz Jahanian | 474e2fe | 2010-09-16 00:20:07 +0000 | [diff] [blame] | 351 | bool LifetimeExternallyManaged, |
Chris Lattner | 1b72677 | 2010-12-02 07:07:26 +0000 | [diff] [blame] | 352 | bool RequiresGCollection = false, |
| 353 | bool IsZeroed = false) { |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 354 | AggValueSlot AV; |
John McCall | 6fa2916 | 2010-09-16 03:16:41 +0000 | [diff] [blame] | 355 | AV.Addr = Addr; |
John McCall | d1a5f13 | 2010-09-16 03:13:23 +0000 | [diff] [blame] | 356 | AV.VolatileFlag = Volatile; |
| 357 | AV.LifetimeFlag = LifetimeExternallyManaged; |
| 358 | AV.RequiresGCollection = RequiresGCollection; |
Chris Lattner | 1b72677 | 2010-12-02 07:07:26 +0000 | [diff] [blame] | 359 | AV.IsZeroed = IsZeroed; |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 360 | return AV; |
| 361 | } |
| 362 | |
Fariborz Jahanian | 474e2fe | 2010-09-16 00:20:07 +0000 | [diff] [blame] | 363 | static AggValueSlot forLValue(LValue LV, bool LifetimeExternallyManaged, |
Chris Lattner | 1b72677 | 2010-12-02 07:07:26 +0000 | [diff] [blame] | 364 | bool RequiresGCollection = false) { |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 365 | return forAddr(LV.getAddress(), LV.isVolatileQualified(), |
Fariborz Jahanian | 474e2fe | 2010-09-16 00:20:07 +0000 | [diff] [blame] | 366 | LifetimeExternallyManaged, RequiresGCollection); |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 367 | } |
Fariborz Jahanian | 8a97005 | 2010-10-22 22:05:03 +0000 | [diff] [blame] | 368 | |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 369 | bool isLifetimeExternallyManaged() const { |
Fariborz Jahanian | 474e2fe | 2010-09-16 00:20:07 +0000 | [diff] [blame] | 370 | return LifetimeFlag; |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 371 | } |
John McCall | 74fb0ed | 2010-11-17 00:07:33 +0000 | [diff] [blame] | 372 | void setLifetimeExternallyManaged(bool Managed = true) { |
| 373 | LifetimeFlag = Managed; |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | bool isVolatile() const { |
Fariborz Jahanian | 474e2fe | 2010-09-16 00:20:07 +0000 | [diff] [blame] | 377 | return VolatileFlag; |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 378 | } |
| 379 | |
John McCall | d1a5f13 | 2010-09-16 03:13:23 +0000 | [diff] [blame] | 380 | bool requiresGCollection() const { |
Fariborz Jahanian | 474e2fe | 2010-09-16 00:20:07 +0000 | [diff] [blame] | 381 | return RequiresGCollection; |
| 382 | } |
Fariborz Jahanian | 474e2fe | 2010-09-16 00:20:07 +0000 | [diff] [blame] | 383 | |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 384 | llvm::Value *getAddr() const { |
John McCall | 6fa2916 | 2010-09-16 03:16:41 +0000 | [diff] [blame] | 385 | return Addr; |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | bool isIgnored() const { |
John McCall | 6fa2916 | 2010-09-16 03:16:41 +0000 | [diff] [blame] | 389 | return Addr == 0; |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | RValue asRValue() const { |
| 393 | return RValue::getAggregate(getAddr(), isVolatile()); |
| 394 | } |
| 395 | |
Chris Lattner | 1b72677 | 2010-12-02 07:07:26 +0000 | [diff] [blame] | 396 | void setZeroed(bool V = true) { IsZeroed = V; } |
| 397 | bool isZeroed() const { |
| 398 | return IsZeroed; |
| 399 | } |
John McCall | 558d2ab | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 400 | }; |
| 401 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 402 | } // end namespace CodeGen |
| 403 | } // end namespace clang |
| 404 | |
| 405 | #endif |