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 | |
| 18 | #include "clang/AST/Type.h" |
| 19 | |
Daniel Dunbar | 46f45b9 | 2008-09-09 01:06:48 +0000 | [diff] [blame] | 20 | namespace llvm { |
| 21 | class Constant; |
| 22 | class Value; |
| 23 | } |
| 24 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 25 | namespace clang { |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 26 | class ObjCPropertyRefExpr; |
Fariborz Jahanian | 09105f5 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 27 | class ObjCImplicitSetterGetterRefExpr; |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 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 |
Fariborz Jahanian | 43f4470 | 2008-11-22 22:30:21 +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 |
Fariborz Jahanian | 43f4470 | 2008-11-22 22:30:21 +0000 | [diff] [blame] | 113 | KVCRef // This is an objective-c 'implicit' property ref, |
| 114 | // use getKVCRefExpr |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 115 | } LVType; |
Fariborz Jahanian | 5862650 | 2008-11-19 00:59:10 +0000 | [diff] [blame] | 116 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 117 | llvm::Value *V; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 118 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 119 | union { |
| 120 | // Index into a vector subscript: V[i] |
| 121 | llvm::Value *VectorIdx; |
| 122 | |
| 123 | // ExtVector element subset: V.xyx |
| 124 | llvm::Constant *VectorElts; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 125 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 126 | // BitField start bit and size |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 127 | const CGBitFieldInfo *BitFieldInfo; |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 128 | |
| 129 | // Obj-C property reference expression |
| 130 | const ObjCPropertyRefExpr *PropertyRefExpr; |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 131 | |
Fariborz Jahanian | 43f4470 | 2008-11-22 22:30:21 +0000 | [diff] [blame] | 132 | // ObjC 'implicit' property reference expression |
Fariborz Jahanian | 09105f5 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 133 | const ObjCImplicitSetterGetterRefExpr *KVCRefExpr; |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 134 | }; |
| 135 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 136 | // 'const' is unused here |
| 137 | Qualifiers Quals; |
Fariborz Jahanian | 5862650 | 2008-11-19 00:59:10 +0000 | [diff] [blame] | 138 | |
Daniel Dunbar | 9f4f7cf | 2010-08-21 02:39:23 +0000 | [diff] [blame^] | 139 | /// The alignment to use when accessing this lvalue. |
| 140 | unsigned char Alignment; |
| 141 | |
Fariborz Jahanian | d1cc804 | 2008-11-20 20:53:20 +0000 | [diff] [blame] | 142 | // objective-c's ivar |
| 143 | bool Ivar:1; |
Fariborz Jahanian | 1c1afc4 | 2009-09-18 00:04:00 +0000 | [diff] [blame] | 144 | |
| 145 | // objective-c's ivar is an array |
Fariborz Jahanian | fd02ed7 | 2009-09-21 18:54:29 +0000 | [diff] [blame] | 146 | bool ObjIsArray:1; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 147 | |
Fariborz Jahanian | 4f676ed | 2009-02-21 00:30:43 +0000 | [diff] [blame] | 148 | // LValue is non-gc'able for any reason, including being a parameter or local |
| 149 | // variable. |
| 150 | bool NonGC: 1; |
Fariborz Jahanian | d1cc804 | 2008-11-20 20:53:20 +0000 | [diff] [blame] | 151 | |
Fariborz Jahanian | bf63b87 | 2009-05-04 23:27:20 +0000 | [diff] [blame] | 152 | // Lvalue is a global reference of an objective-c object |
| 153 | bool GlobalObjCRef : 1; |
Fariborz Jahanian | 021a7a6 | 2010-07-20 20:30:03 +0000 | [diff] [blame] | 154 | |
| 155 | // Lvalue is a thread local reference |
| 156 | bool ThreadLocalRef : 1; |
Fariborz Jahanian | bf63b87 | 2009-05-04 23:27:20 +0000 | [diff] [blame] | 157 | |
Fariborz Jahanian | 6c7a1f3 | 2009-09-24 22:25:38 +0000 | [diff] [blame] | 158 | Expr *BaseIvarExp; |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 159 | private: |
Daniel Dunbar | 9f4f7cf | 2010-08-21 02:39:23 +0000 | [diff] [blame^] | 160 | void Initialize(Qualifiers Quals, unsigned Alignment = 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; |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 169 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 170 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 171 | public: |
| 172 | bool isSimple() const { return LVType == Simple; } |
| 173 | bool isVectorElt() const { return LVType == VectorElt; } |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 174 | bool isBitField() const { return LVType == BitField; } |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 175 | bool isExtVectorElt() const { return LVType == ExtVectorElt; } |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 176 | bool isPropertyRef() const { return LVType == PropertyRef; } |
Fariborz Jahanian | 43f4470 | 2008-11-22 22:30:21 +0000 | [diff] [blame] | 177 | bool isKVCRef() const { return LVType == KVCRef; } |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 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; } |
Fariborz Jahanian | fd02ed7 | 2009-09-21 18:54:29 +0000 | [diff] [blame] | 186 | bool isObjCArray() const { return ObjIsArray; } |
Fariborz Jahanian | 4f676ed | 2009-02-21 00:30:43 +0000 | [diff] [blame] | 187 | bool isNonGC () const { return NonGC; } |
Fariborz Jahanian | bf63b87 | 2009-05-04 23:27:20 +0000 | [diff] [blame] | 188 | bool isGlobalObjCRef() const { return GlobalObjCRef; } |
Fariborz Jahanian | 021a7a6 | 2010-07-20 20:30:03 +0000 | [diff] [blame] | 189 | bool isThreadLocalRef() const { return ThreadLocalRef; } |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 190 | bool isObjCWeak() const { return Quals.getObjCGCAttr() == Qualifiers::Weak; } |
| 191 | bool isObjCStrong() const { return Quals.getObjCGCAttr() == Qualifiers::Strong; } |
Fariborz Jahanian | 6c7a1f3 | 2009-09-24 22:25:38 +0000 | [diff] [blame] | 192 | |
| 193 | Expr *getBaseIvarExp() const { return BaseIvarExp; } |
| 194 | void setBaseIvarExp(Expr *V) { BaseIvarExp = V; } |
Mon P Wang | c6a38a4 | 2009-07-22 03:08:17 +0000 | [diff] [blame] | 195 | |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 196 | unsigned getAddressSpace() const { return Quals.getAddressSpace(); } |
Mon P Wang | c6a38a4 | 2009-07-22 03:08:17 +0000 | [diff] [blame] | 197 | |
Daniel Dunbar | 9f4f7cf | 2010-08-21 02:39:23 +0000 | [diff] [blame^] | 198 | unsigned getAlignment() const { return Alignment; } |
| 199 | |
Fariborz Jahanian | 2ab1968 | 2008-11-21 18:14:01 +0000 | [diff] [blame] | 200 | static void SetObjCIvar(LValue& R, bool iValue) { |
| 201 | R.Ivar = iValue; |
Fariborz Jahanian | d1cc804 | 2008-11-20 20:53:20 +0000 | [diff] [blame] | 202 | } |
Fariborz Jahanian | fd02ed7 | 2009-09-21 18:54:29 +0000 | [diff] [blame] | 203 | static void SetObjCArray(LValue& R, bool iValue) { |
| 204 | R.ObjIsArray = iValue; |
Fariborz Jahanian | 1c1afc4 | 2009-09-18 00:04:00 +0000 | [diff] [blame] | 205 | } |
Fariborz Jahanian | bf63b87 | 2009-05-04 23:27:20 +0000 | [diff] [blame] | 206 | static void SetGlobalObjCRef(LValue& R, bool iValue) { |
| 207 | R.GlobalObjCRef = iValue; |
| 208 | } |
Fariborz Jahanian | 021a7a6 | 2010-07-20 20:30:03 +0000 | [diff] [blame] | 209 | static void SetThreadLocalRef(LValue& R, bool iValue) { |
| 210 | R.ThreadLocalRef = iValue; |
| 211 | } |
Fariborz Jahanian | 4f676ed | 2009-02-21 00:30:43 +0000 | [diff] [blame] | 212 | static void SetObjCNonGC(LValue& R, bool iValue) { |
| 213 | R.NonGC = iValue; |
| 214 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 215 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 216 | // simple lvalue |
| 217 | llvm::Value *getAddress() const { assert(isSimple()); return V; } |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 218 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 219 | // vector elt lvalue |
| 220 | llvm::Value *getVectorAddr() const { assert(isVectorElt()); return V; } |
| 221 | llvm::Value *getVectorIdx() const { assert(isVectorElt()); return VectorIdx; } |
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 | // extended vector elements. |
| 224 | llvm::Value *getExtVectorAddr() const { assert(isExtVectorElt()); return V; } |
| 225 | llvm::Constant *getExtVectorElts() const { |
| 226 | assert(isExtVectorElt()); |
| 227 | return VectorElts; |
| 228 | } |
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 | // bitfield lvalue |
Daniel Dunbar | 7f28964 | 2010-04-08 02:59:45 +0000 | [diff] [blame] | 231 | llvm::Value *getBitFieldBaseAddr() const { |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 232 | assert(isBitField()); |
| 233 | return V; |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 234 | } |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 235 | const CGBitFieldInfo &getBitFieldInfo() const { |
| 236 | assert(isBitField()); |
| 237 | return *BitFieldInfo; |
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 | |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 240 | // property ref lvalue |
| 241 | const ObjCPropertyRefExpr *getPropertyRefExpr() const { |
| 242 | assert(isPropertyRef()); |
| 243 | return PropertyRefExpr; |
| 244 | } |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 245 | |
Fariborz Jahanian | 43f4470 | 2008-11-22 22:30:21 +0000 | [diff] [blame] | 246 | // 'implicit' property ref lvalue |
Fariborz Jahanian | 09105f5 | 2009-08-20 17:02:02 +0000 | [diff] [blame] | 247 | const ObjCImplicitSetterGetterRefExpr *getKVCRefExpr() const { |
Fariborz Jahanian | 43f4470 | 2008-11-22 22:30:21 +0000 | [diff] [blame] | 248 | assert(isKVCRef()); |
| 249 | return KVCRefExpr; |
| 250 | } |
| 251 | |
Daniel Dunbar | 9f4f7cf | 2010-08-21 02:39:23 +0000 | [diff] [blame^] | 252 | static LValue MakeAddr(llvm::Value *V, Qualifiers Quals, |
| 253 | unsigned Alignment = 0) { |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 254 | LValue R; |
| 255 | R.LVType = Simple; |
| 256 | R.V = V; |
Daniel Dunbar | 9f4f7cf | 2010-08-21 02:39:23 +0000 | [diff] [blame^] | 257 | R.Initialize(Quals, Alignment); |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 258 | return R; |
| 259 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 260 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 261 | static LValue MakeVectorElt(llvm::Value *Vec, llvm::Value *Idx, |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 262 | unsigned CVR) { |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 263 | LValue R; |
| 264 | R.LVType = VectorElt; |
| 265 | R.V = Vec; |
| 266 | R.VectorIdx = Idx; |
Daniel Dunbar | de98881 | 2010-08-21 02:31:58 +0000 | [diff] [blame] | 267 | R.Initialize(Qualifiers::fromCVRMask(CVR)); |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 268 | return R; |
| 269 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 270 | |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 271 | static LValue MakeExtVectorElt(llvm::Value *Vec, llvm::Constant *Elts, |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 272 | unsigned CVR) { |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 273 | LValue R; |
| 274 | R.LVType = ExtVectorElt; |
| 275 | R.V = Vec; |
| 276 | R.VectorElts = Elts; |
Daniel Dunbar | de98881 | 2010-08-21 02:31:58 +0000 | [diff] [blame] | 277 | R.Initialize(Qualifiers::fromCVRMask(CVR)); |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 278 | return R; |
| 279 | } |
| 280 | |
Daniel Dunbar | 7f28964 | 2010-04-08 02:59:45 +0000 | [diff] [blame] | 281 | /// \brief Create a new object to represent a bit-field access. |
| 282 | /// |
| 283 | /// \param BaseValue - The base address of the structure containing the |
| 284 | /// bit-field. |
| 285 | /// \param Info - The information describing how to perform the bit-field |
| 286 | /// access. |
| 287 | static LValue MakeBitfield(llvm::Value *BaseValue, const CGBitFieldInfo &Info, |
Daniel Dunbar | efbf487 | 2010-04-06 01:07:44 +0000 | [diff] [blame] | 288 | unsigned CVR) { |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 289 | LValue R; |
| 290 | R.LVType = BitField; |
Daniel Dunbar | 7f28964 | 2010-04-08 02:59:45 +0000 | [diff] [blame] | 291 | R.V = BaseValue; |
Daniel Dunbar | f0fe5bc | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 292 | R.BitFieldInfo = &Info; |
Daniel Dunbar | de98881 | 2010-08-21 02:31:58 +0000 | [diff] [blame] | 293 | R.Initialize(Qualifiers::fromCVRMask(CVR)); |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 294 | return R; |
| 295 | } |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 296 | |
Mike Stump | f5408fe | 2009-05-16 07:57:57 +0000 | [diff] [blame] | 297 | // FIXME: It is probably bad that we aren't emitting the target when we build |
| 298 | // the lvalue. However, this complicates the code a bit, and I haven't figured |
| 299 | // out how to make it go wrong yet. |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 300 | static LValue MakePropertyRef(const ObjCPropertyRefExpr *E, |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 301 | unsigned CVR) { |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 302 | LValue R; |
| 303 | R.LVType = PropertyRef; |
| 304 | R.PropertyRefExpr = E; |
Daniel Dunbar | de98881 | 2010-08-21 02:31:58 +0000 | [diff] [blame] | 305 | R.Initialize(Qualifiers::fromCVRMask(CVR)); |
Daniel Dunbar | 85c59ed | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 306 | return R; |
| 307 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 308 | |
| 309 | static LValue MakeKVCRef(const ObjCImplicitSetterGetterRefExpr *E, |
John McCall | 0953e76 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 310 | unsigned CVR) { |
Fariborz Jahanian | 43f4470 | 2008-11-22 22:30:21 +0000 | [diff] [blame] | 311 | LValue R; |
| 312 | R.LVType = KVCRef; |
| 313 | R.KVCRefExpr = E; |
Daniel Dunbar | de98881 | 2010-08-21 02:31:58 +0000 | [diff] [blame] | 314 | R.Initialize(Qualifiers::fromCVRMask(CVR)); |
Fariborz Jahanian | 43f4470 | 2008-11-22 22:30:21 +0000 | [diff] [blame] | 315 | return R; |
| 316 | } |
Daniel Dunbar | 2eecaab | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 317 | }; |
| 318 | |
| 319 | } // end namespace CodeGen |
| 320 | } // end namespace clang |
| 321 | |
| 322 | #endif |