Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 1 | //===-- CGValue.h - LLVM CodeGen wrappers for llvm::Value* ------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame^] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // These classes implement wrappers around llvm::Value in order to |
| 10 | // fully represent the range of values for C L- and R- values. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Benjamin Kramer | 2f5db8b | 2014-08-13 16:25:19 +0000 | [diff] [blame] | 14 | #ifndef LLVM_CLANG_LIB_CODEGEN_CGVALUE_H |
| 15 | #define LLVM_CLANG_LIB_CODEGEN_CGVALUE_H |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 16 | |
Daniel Dunbar | 93b00a9 | 2010-08-21 02:53:44 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTContext.h" |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 18 | #include "clang/AST/Type.h" |
John McCall | 47fb950 | 2013-03-07 21:37:08 +0000 | [diff] [blame] | 19 | #include "llvm/IR/Value.h" |
David Blaikie | e3b172a | 2015-04-02 18:55:21 +0000 | [diff] [blame] | 20 | #include "llvm/IR/Type.h" |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 21 | #include "Address.h" |
Ivan A. Kosarev | a511ed7 | 2017-10-03 10:52:39 +0000 | [diff] [blame] | 22 | #include "CodeGenTBAA.h" |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 23 | |
Daniel Dunbar | 41cf9de | 2008-09-09 01:06:48 +0000 | [diff] [blame] | 24 | namespace llvm { |
| 25 | class Constant; |
John McCall | 47fb950 | 2013-03-07 21:37:08 +0000 | [diff] [blame] | 26 | class MDNode; |
Daniel Dunbar | 41cf9de | 2008-09-09 01:06:48 +0000 | [diff] [blame] | 27 | } |
| 28 | |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 29 | namespace clang { |
| 30 | namespace CodeGen { |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 31 | class AggValueSlot; |
Chandler Carruth | ff0e3a1 | 2012-12-06 11:14:44 +0000 | [diff] [blame] | 32 | struct CGBitFieldInfo; |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 33 | |
| 34 | /// RValue - This trivial value class is used to represent the result of an |
| 35 | /// expression that is evaluated. It can be one of three things: either a |
| 36 | /// simple LLVM SSA value, a pair of SSA values for complex numbers, or the |
| 37 | /// address of an aggregate value in memory. |
| 38 | class RValue { |
Benjamin Kramer | 2718b4d | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 39 | enum Flavor { Scalar, Complex, Aggregate }; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 40 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 41 | // The shift to make to an aggregate's alignment to make it look |
| 42 | // like a pointer. |
| 43 | enum { AggAlignShift = 4 }; |
| 44 | |
Benjamin Kramer | 2718b4d | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 45 | // Stores first value and flavor. |
| 46 | llvm::PointerIntPair<llvm::Value *, 2, Flavor> V1; |
| 47 | // Stores second value and volatility. |
| 48 | llvm::PointerIntPair<llvm::Value *, 1, bool> V2; |
| 49 | |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 50 | public: |
Benjamin Kramer | 2718b4d | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 51 | bool isScalar() const { return V1.getInt() == Scalar; } |
| 52 | bool isComplex() const { return V1.getInt() == Complex; } |
| 53 | bool isAggregate() const { return V1.getInt() == Aggregate; } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 54 | |
Benjamin Kramer | 2718b4d | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 55 | bool isVolatileQualified() const { return V2.getInt(); } |
Mike Stump | 93700fc | 2009-05-23 20:21:36 +0000 | [diff] [blame] | 56 | |
Mike Stump | 462a4aa | 2009-11-03 16:11:57 +0000 | [diff] [blame] | 57 | /// getScalarVal() - Return the Value* of this scalar value. |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 58 | llvm::Value *getScalarVal() const { |
| 59 | assert(isScalar() && "Not a scalar!"); |
Benjamin Kramer | 2718b4d | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 60 | return V1.getPointer(); |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | /// getComplexVal - Return the real/imag components of this complex value. |
| 64 | /// |
| 65 | std::pair<llvm::Value *, llvm::Value *> getComplexVal() const { |
Benjamin Kramer | 2718b4d | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 66 | return std::make_pair(V1.getPointer(), V2.getPointer()); |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 67 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 68 | |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 69 | /// getAggregateAddr() - Return the Value* of the address of the aggregate. |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 70 | Address getAggregateAddress() const { |
| 71 | assert(isAggregate() && "Not an aggregate!"); |
| 72 | auto align = reinterpret_cast<uintptr_t>(V2.getPointer()) >> AggAlignShift; |
| 73 | return Address(V1.getPointer(), CharUnits::fromQuantity(align)); |
| 74 | } |
| 75 | llvm::Value *getAggregatePointer() const { |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 76 | assert(isAggregate() && "Not an aggregate!"); |
Benjamin Kramer | 2718b4d | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 77 | return V1.getPointer(); |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 78 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 79 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 80 | static RValue getIgnored() { |
| 81 | // FIXME: should we make this a more explicit state? |
| 82 | return get(nullptr); |
| 83 | } |
| 84 | |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 85 | static RValue get(llvm::Value *V) { |
| 86 | RValue ER; |
Benjamin Kramer | 2718b4d | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 87 | ER.V1.setPointer(V); |
| 88 | ER.V1.setInt(Scalar); |
| 89 | ER.V2.setInt(false); |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 90 | return ER; |
| 91 | } |
| 92 | static RValue getComplex(llvm::Value *V1, llvm::Value *V2) { |
| 93 | RValue ER; |
Benjamin Kramer | 2718b4d | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 94 | ER.V1.setPointer(V1); |
| 95 | ER.V2.setPointer(V2); |
| 96 | ER.V1.setInt(Complex); |
| 97 | ER.V2.setInt(false); |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 98 | return ER; |
| 99 | } |
| 100 | static RValue getComplex(const std::pair<llvm::Value *, llvm::Value *> &C) { |
Benjamin Kramer | 2718b4d | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 101 | return getComplex(C.first, C.second); |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 102 | } |
Mike Stump | 93700fc | 2009-05-23 20:21:36 +0000 | [diff] [blame] | 103 | // FIXME: Aggregate rvalues need to retain information about whether they are |
| 104 | // volatile or not. Remove default to find all places that probably get this |
| 105 | // wrong. |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 106 | static RValue getAggregate(Address addr, bool isVolatile = false) { |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 107 | RValue ER; |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 108 | ER.V1.setPointer(addr.getPointer()); |
Benjamin Kramer | 2718b4d | 2010-05-02 14:59:10 +0000 | [diff] [blame] | 109 | ER.V1.setInt(Aggregate); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 110 | |
| 111 | auto align = static_cast<uintptr_t>(addr.getAlignment().getQuantity()); |
| 112 | ER.V2.setPointer(reinterpret_cast<llvm::Value*>(align << AggAlignShift)); |
| 113 | ER.V2.setInt(isVolatile); |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 114 | return ER; |
| 115 | } |
| 116 | }; |
| 117 | |
John McCall | cdda29c | 2013-03-13 03:10:54 +0000 | [diff] [blame] | 118 | /// Does an ARC strong l-value have precise lifetime? |
| 119 | enum ARCPreciseLifetime_t { |
John McCall | 4d31b81 | 2013-03-13 05:02:21 +0000 | [diff] [blame] | 120 | ARCImpreciseLifetime, ARCPreciseLifetime |
John McCall | cdda29c | 2013-03-13 03:10:54 +0000 | [diff] [blame] | 121 | }; |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 122 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 123 | /// The source of the alignment of an l-value; an expression of |
| 124 | /// confidence in the alignment actually matching the estimate. |
| 125 | enum class AlignmentSource { |
| 126 | /// The l-value was an access to a declared entity or something |
| 127 | /// equivalently strong, like the address of an array allocated by a |
| 128 | /// language runtime. |
| 129 | Decl, |
| 130 | |
| 131 | /// The l-value was considered opaque, so the alignment was |
| 132 | /// determined from a type, but that type was an explicitly-aligned |
| 133 | /// typedef. |
| 134 | AttributedType, |
| 135 | |
| 136 | /// The l-value was considered opaque, so the alignment was |
| 137 | /// determined from a type. |
| 138 | Type |
| 139 | }; |
| 140 | |
| 141 | /// Given that the base address has the given alignment source, what's |
| 142 | /// our confidence in the alignment of the field? |
| 143 | static inline AlignmentSource getFieldAlignmentSource(AlignmentSource Source) { |
| 144 | // For now, we don't distinguish fields of opaque pointers from |
| 145 | // top-level declarations, but maybe we should. |
| 146 | return AlignmentSource::Decl; |
| 147 | } |
| 148 | |
Krzysztof Parzyszek | 8f24823 | 2017-05-18 17:07:11 +0000 | [diff] [blame] | 149 | class LValueBaseInfo { |
| 150 | AlignmentSource AlignSource; |
Krzysztof Parzyszek | 8f24823 | 2017-05-18 17:07:11 +0000 | [diff] [blame] | 151 | |
| 152 | public: |
Ivan A. Kosarev | b9c59f3 | 2017-10-31 11:05:34 +0000 | [diff] [blame] | 153 | explicit LValueBaseInfo(AlignmentSource Source = AlignmentSource::Type) |
| 154 | : AlignSource(Source) {} |
Krzysztof Parzyszek | 8f24823 | 2017-05-18 17:07:11 +0000 | [diff] [blame] | 155 | AlignmentSource getAlignmentSource() const { return AlignSource; } |
| 156 | void setAlignmentSource(AlignmentSource Source) { AlignSource = Source; } |
Krzysztof Parzyszek | 8f24823 | 2017-05-18 17:07:11 +0000 | [diff] [blame] | 157 | |
| 158 | void mergeForCast(const LValueBaseInfo &Info) { |
| 159 | setAlignmentSource(Info.getAlignmentSource()); |
Krzysztof Parzyszek | 8f24823 | 2017-05-18 17:07:11 +0000 | [diff] [blame] | 160 | } |
| 161 | }; |
| 162 | |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 163 | /// LValue - This represents an lvalue references. Because C/C++ allow |
| 164 | /// bitfields, this is not a simple LLVM pointer, it may be a pointer plus a |
| 165 | /// bitrange. |
| 166 | class LValue { |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 167 | enum { |
| 168 | Simple, // This is a normal l-value, use getAddress(). |
| 169 | VectorElt, // This is a vector element l-value (V[i]), use getVector* |
| 170 | BitField, // This is a bitfield l-value, use getBitfield*. |
Renato Golin | 230c5eb | 2014-05-19 18:15:42 +0000 | [diff] [blame] | 171 | ExtVectorElt, // This is an extended vector subset, use getExtVectorComp |
| 172 | GlobalReg // This is a register l-value, use getGlobalReg() |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 173 | } LVType; |
Fariborz Jahanian | d7db964 | 2008-11-19 00:59:10 +0000 | [diff] [blame] | 174 | |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 175 | llvm::Value *V; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 176 | |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 177 | union { |
| 178 | // Index into a vector subscript: V[i] |
| 179 | llvm::Value *VectorIdx; |
| 180 | |
| 181 | // ExtVector element subset: V.xyx |
| 182 | llvm::Constant *VectorElts; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 183 | |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 184 | // BitField start bit and size |
Daniel Dunbar | dc406b8 | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 185 | const CGBitFieldInfo *BitFieldInfo; |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 186 | }; |
| 187 | |
John McCall | 1553b19 | 2011-06-16 04:16:24 +0000 | [diff] [blame] | 188 | QualType Type; |
| 189 | |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 190 | // 'const' is unused here |
| 191 | Qualifiers Quals; |
Fariborz Jahanian | d7db964 | 2008-11-19 00:59:10 +0000 | [diff] [blame] | 192 | |
Eli Friedman | 610bb87 | 2012-03-22 22:36:39 +0000 | [diff] [blame] | 193 | // The alignment to use when accessing this lvalue. (For vector elements, |
| 194 | // this is the alignment of the whole vector.) |
Yaxun Liu | d938982 | 2018-03-14 15:02:28 +0000 | [diff] [blame] | 195 | unsigned Alignment; |
Daniel Dunbar | e3b8dd4 | 2010-08-21 02:39:23 +0000 | [diff] [blame] | 196 | |
Fariborz Jahanian | 75686a5 | 2008-11-20 20:53:20 +0000 | [diff] [blame] | 197 | // objective-c's ivar |
| 198 | bool Ivar:1; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 199 | |
Fariborz Jahanian | 2e32ddc | 2009-09-18 00:04:00 +0000 | [diff] [blame] | 200 | // objective-c's ivar is an array |
Fariborz Jahanian | 38c3ae9 | 2009-09-21 18:54:29 +0000 | [diff] [blame] | 201 | bool ObjIsArray:1; |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 202 | |
Fariborz Jahanian | 10bec10 | 2009-02-21 00:30:43 +0000 | [diff] [blame] | 203 | // LValue is non-gc'able for any reason, including being a parameter or local |
| 204 | // variable. |
| 205 | bool NonGC: 1; |
Fariborz Jahanian | 75686a5 | 2008-11-20 20:53:20 +0000 | [diff] [blame] | 206 | |
Fariborz Jahanian | 32ff7ae | 2009-05-04 23:27:20 +0000 | [diff] [blame] | 207 | // Lvalue is a global reference of an objective-c object |
| 208 | bool GlobalObjCRef : 1; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 209 | |
Fariborz Jahanian | 217af24 | 2010-07-20 20:30:03 +0000 | [diff] [blame] | 210 | // Lvalue is a thread local reference |
| 211 | bool ThreadLocalRef : 1; |
Fariborz Jahanian | 32ff7ae | 2009-05-04 23:27:20 +0000 | [diff] [blame] | 212 | |
John McCall | cdda29c | 2013-03-13 03:10:54 +0000 | [diff] [blame] | 213 | // Lvalue has ARC imprecise lifetime. We store this inverted to try |
| 214 | // to make the default bitfield pattern all-zeroes. |
| 215 | bool ImpreciseLifetime : 1; |
| 216 | |
Michael Zolotukhin | 84df123 | 2015-09-08 23:52:33 +0000 | [diff] [blame] | 217 | // This flag shows if a nontemporal load/stores should be used when accessing |
| 218 | // this lvalue. |
| 219 | bool Nontemporal : 1; |
| 220 | |
Yaxun Liu | d938982 | 2018-03-14 15:02:28 +0000 | [diff] [blame] | 221 | LValueBaseInfo BaseInfo; |
| 222 | TBAAAccessInfo TBAAInfo; |
| 223 | |
Fariborz Jahanian | 7a95d72 | 2009-09-24 22:25:38 +0000 | [diff] [blame] | 224 | Expr *BaseIvarExp; |
Dan Gohman | 947c9af | 2010-10-14 23:06:10 +0000 | [diff] [blame] | 225 | |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 226 | private: |
Ivan A. Kosarev | d17f12a | 2017-10-17 10:17:43 +0000 | [diff] [blame] | 227 | void Initialize(QualType Type, Qualifiers Quals, CharUnits Alignment, |
| 228 | LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo) { |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 229 | assert((!Alignment.isZero() || Type->isIncompleteType()) && |
| 230 | "initializing l-value with zero alignment!"); |
John McCall | 1553b19 | 2011-06-16 04:16:24 +0000 | [diff] [blame] | 231 | this->Type = Type; |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 232 | this->Quals = Quals; |
Yaxun Liu | d938982 | 2018-03-14 15:02:28 +0000 | [diff] [blame] | 233 | const unsigned MaxAlign = 1U << 31; |
| 234 | this->Alignment = Alignment.getQuantity() <= MaxAlign |
| 235 | ? Alignment.getQuantity() |
| 236 | : MaxAlign; |
Eli Friedman | a0544d6 | 2011-12-03 04:14:32 +0000 | [diff] [blame] | 237 | assert(this->Alignment == Alignment.getQuantity() && |
| 238 | "Alignment exceeds allowed max!"); |
Krzysztof Parzyszek | 8f24823 | 2017-05-18 17:07:11 +0000 | [diff] [blame] | 239 | this->BaseInfo = BaseInfo; |
Ivan A. Kosarev | 383890b | 2017-10-06 08:17:48 +0000 | [diff] [blame] | 240 | this->TBAAInfo = TBAAInfo; |
Daniel Dunbar | e3b8dd4 | 2010-08-21 02:39:23 +0000 | [diff] [blame] | 241 | |
| 242 | // Initialize Objective-C flags. |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 243 | this->Ivar = this->ObjIsArray = this->NonGC = this->GlobalObjCRef = false; |
John McCall | cdda29c | 2013-03-13 03:10:54 +0000 | [diff] [blame] | 244 | this->ImpreciseLifetime = false; |
Michael Zolotukhin | 84df123 | 2015-09-08 23:52:33 +0000 | [diff] [blame] | 245 | this->Nontemporal = false; |
Fariborz Jahanian | 217af24 | 2010-07-20 20:30:03 +0000 | [diff] [blame] | 246 | this->ThreadLocalRef = false; |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 247 | this->BaseIvarExp = nullptr; |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 248 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 249 | |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 250 | public: |
| 251 | bool isSimple() const { return LVType == Simple; } |
| 252 | bool isVectorElt() const { return LVType == VectorElt; } |
Daniel Dunbar | dc406b8 | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 253 | bool isBitField() const { return LVType == BitField; } |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 254 | bool isExtVectorElt() const { return LVType == ExtVectorElt; } |
Renato Golin | 230c5eb | 2014-05-19 18:15:42 +0000 | [diff] [blame] | 255 | bool isGlobalReg() const { return LVType == GlobalReg; } |
Daniel Dunbar | 9e22c0d | 2008-08-29 08:11:39 +0000 | [diff] [blame] | 256 | |
John McCall | 8ccfcb5 | 2009-09-24 19:53:00 +0000 | [diff] [blame] | 257 | bool isVolatileQualified() const { return Quals.hasVolatile(); } |
| 258 | bool isRestrictQualified() const { return Quals.hasRestrict(); } |
| 259 | unsigned getVRQualifiers() const { |
| 260 | return Quals.getCVRQualifiers() & ~Qualifiers::Const; |
Chris Lattner | e084c01 | 2009-02-16 22:25:49 +0000 | [diff] [blame] | 261 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 262 | |
John McCall | 1553b19 | 2011-06-16 04:16:24 +0000 | [diff] [blame] | 263 | QualType getType() const { return Type; } |
| 264 | |
| 265 | Qualifiers::ObjCLifetime getObjCLifetime() const { |
| 266 | return Quals.getObjCLifetime(); |
| 267 | } |
| 268 | |
Fariborz Jahanian | 75686a5 | 2008-11-20 20:53:20 +0000 | [diff] [blame] | 269 | bool isObjCIvar() const { return Ivar; } |
Daniel Dunbar | 4bb04ce | 2010-08-21 03:51:29 +0000 | [diff] [blame] | 270 | void setObjCIvar(bool Value) { Ivar = Value; } |
| 271 | |
Fariborz Jahanian | 38c3ae9 | 2009-09-21 18:54:29 +0000 | [diff] [blame] | 272 | bool isObjCArray() const { return ObjIsArray; } |
Daniel Dunbar | 4bb04ce | 2010-08-21 03:51:29 +0000 | [diff] [blame] | 273 | void setObjCArray(bool Value) { ObjIsArray = Value; } |
Daniel Dunbar | e50dda9 | 2010-08-21 03:22:38 +0000 | [diff] [blame] | 274 | |
Fariborz Jahanian | 10bec10 | 2009-02-21 00:30:43 +0000 | [diff] [blame] | 275 | bool isNonGC () const { return NonGC; } |
Daniel Dunbar | e50dda9 | 2010-08-21 03:22:38 +0000 | [diff] [blame] | 276 | void setNonGC(bool Value) { NonGC = Value; } |
| 277 | |
Fariborz Jahanian | 32ff7ae | 2009-05-04 23:27:20 +0000 | [diff] [blame] | 278 | bool isGlobalObjCRef() const { return GlobalObjCRef; } |
Daniel Dunbar | 4bb04ce | 2010-08-21 03:51:29 +0000 | [diff] [blame] | 279 | void setGlobalObjCRef(bool Value) { GlobalObjCRef = Value; } |
| 280 | |
Fariborz Jahanian | 217af24 | 2010-07-20 20:30:03 +0000 | [diff] [blame] | 281 | bool isThreadLocalRef() const { return ThreadLocalRef; } |
Daniel Dunbar | 4bb04ce | 2010-08-21 03:51:29 +0000 | [diff] [blame] | 282 | void setThreadLocalRef(bool Value) { ThreadLocalRef = Value;} |
| 283 | |
John McCall | cdda29c | 2013-03-13 03:10:54 +0000 | [diff] [blame] | 284 | ARCPreciseLifetime_t isARCPreciseLifetime() const { |
| 285 | return ARCPreciseLifetime_t(!ImpreciseLifetime); |
| 286 | } |
| 287 | void setARCPreciseLifetime(ARCPreciseLifetime_t value) { |
| 288 | ImpreciseLifetime = (value == ARCImpreciseLifetime); |
| 289 | } |
Michael Zolotukhin | 84df123 | 2015-09-08 23:52:33 +0000 | [diff] [blame] | 290 | bool isNontemporal() const { return Nontemporal; } |
| 291 | void setNontemporal(bool Value) { Nontemporal = Value; } |
John McCall | cdda29c | 2013-03-13 03:10:54 +0000 | [diff] [blame] | 292 | |
Daniel Dunbar | 4bb04ce | 2010-08-21 03:51:29 +0000 | [diff] [blame] | 293 | bool isObjCWeak() const { |
| 294 | return Quals.getObjCGCAttr() == Qualifiers::Weak; |
| 295 | } |
| 296 | bool isObjCStrong() const { |
| 297 | return Quals.getObjCGCAttr() == Qualifiers::Strong; |
| 298 | } |
John McCall | 1553b19 | 2011-06-16 04:16:24 +0000 | [diff] [blame] | 299 | |
| 300 | bool isVolatile() const { |
| 301 | return Quals.hasVolatile(); |
| 302 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 303 | |
Fariborz Jahanian | 7a95d72 | 2009-09-24 22:25:38 +0000 | [diff] [blame] | 304 | Expr *getBaseIvarExp() const { return BaseIvarExp; } |
| 305 | void setBaseIvarExp(Expr *V) { BaseIvarExp = V; } |
Mon P Wang | acedf77 | 2009-07-22 03:08:17 +0000 | [diff] [blame] | 306 | |
Ivan A. Kosarev | a511ed7 | 2017-10-03 10:52:39 +0000 | [diff] [blame] | 307 | TBAAAccessInfo getTBAAInfo() const { return TBAAInfo; } |
| 308 | void setTBAAInfo(TBAAAccessInfo Info) { TBAAInfo = Info; } |
Manman Ren | c451e57 | 2013-04-04 21:53:22 +0000 | [diff] [blame] | 309 | |
Daniel Dunbar | b657ac5 | 2010-08-21 03:29:54 +0000 | [diff] [blame] | 310 | const Qualifiers &getQuals() const { return Quals; } |
| 311 | Qualifiers &getQuals() { return Quals; } |
| 312 | |
Alexander Richardson | 6d98943 | 2017-10-15 18:48:14 +0000 | [diff] [blame] | 313 | LangAS getAddressSpace() const { return Quals.getAddressSpace(); } |
Mon P Wang | acedf77 | 2009-07-22 03:08:17 +0000 | [diff] [blame] | 314 | |
Eli Friedman | a0544d6 | 2011-12-03 04:14:32 +0000 | [diff] [blame] | 315 | CharUnits getAlignment() const { return CharUnits::fromQuantity(Alignment); } |
| 316 | void setAlignment(CharUnits A) { Alignment = A.getQuantity(); } |
Daniel Dunbar | e3b8dd4 | 2010-08-21 02:39:23 +0000 | [diff] [blame] | 317 | |
Krzysztof Parzyszek | 8f24823 | 2017-05-18 17:07:11 +0000 | [diff] [blame] | 318 | LValueBaseInfo getBaseInfo() const { return BaseInfo; } |
| 319 | void setBaseInfo(LValueBaseInfo Info) { BaseInfo = Info; } |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 320 | |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 321 | // simple lvalue |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 322 | llvm::Value *getPointer() const { |
John McCall | 1553b19 | 2011-06-16 04:16:24 +0000 | [diff] [blame] | 323 | assert(isSimple()); |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 324 | return V; |
| 325 | } |
| 326 | Address getAddress() const { return Address(getPointer(), getAlignment()); } |
| 327 | void setAddress(Address address) { |
| 328 | assert(isSimple()); |
| 329 | V = address.getPointer(); |
| 330 | Alignment = address.getAlignment().getQuantity(); |
John McCall | 1553b19 | 2011-06-16 04:16:24 +0000 | [diff] [blame] | 331 | } |
Daniel Dunbar | dc406b8 | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 332 | |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 333 | // vector elt lvalue |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 334 | Address getVectorAddress() const { |
| 335 | return Address(getVectorPointer(), getAlignment()); |
| 336 | } |
| 337 | llvm::Value *getVectorPointer() const { assert(isVectorElt()); return V; } |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 338 | llvm::Value *getVectorIdx() const { assert(isVectorElt()); return VectorIdx; } |
Daniel Dunbar | dc406b8 | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 339 | |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 340 | // extended vector elements. |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 341 | Address getExtVectorAddress() const { |
| 342 | return Address(getExtVectorPointer(), getAlignment()); |
| 343 | } |
| 344 | llvm::Value *getExtVectorPointer() const { |
| 345 | assert(isExtVectorElt()); |
| 346 | return V; |
| 347 | } |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 348 | llvm::Constant *getExtVectorElts() const { |
| 349 | assert(isExtVectorElt()); |
| 350 | return VectorElts; |
| 351 | } |
Daniel Dunbar | dc406b8 | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 352 | |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 353 | // bitfield lvalue |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 354 | Address getBitFieldAddress() const { |
| 355 | return Address(getBitFieldPointer(), getAlignment()); |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 356 | } |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 357 | llvm::Value *getBitFieldPointer() const { assert(isBitField()); return V; } |
Daniel Dunbar | dc406b8 | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 358 | const CGBitFieldInfo &getBitFieldInfo() const { |
| 359 | assert(isBitField()); |
| 360 | return *BitFieldInfo; |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 361 | } |
Daniel Dunbar | dc406b8 | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 362 | |
Renato Golin | 230c5eb | 2014-05-19 18:15:42 +0000 | [diff] [blame] | 363 | // global register lvalue |
| 364 | llvm::Value *getGlobalReg() const { assert(isGlobalReg()); return V; } |
| 365 | |
Ivan A. Kosarev | 383890b | 2017-10-06 08:17:48 +0000 | [diff] [blame] | 366 | static LValue MakeAddr(Address address, QualType type, ASTContext &Context, |
| 367 | LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo) { |
John McCall | 1553b19 | 2011-06-16 04:16:24 +0000 | [diff] [blame] | 368 | Qualifiers qs = type.getQualifiers(); |
| 369 | qs.setObjCGCAttr(Context.getObjCGCAttrKind(type)); |
Daniel Dunbar | 226bdda | 2010-08-21 03:58:45 +0000 | [diff] [blame] | 370 | |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 371 | LValue R; |
| 372 | R.LVType = Simple; |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 373 | assert(address.getPointer()->getType()->isPointerTy()); |
| 374 | R.V = address.getPointer(); |
Ivan A. Kosarev | 383890b | 2017-10-06 08:17:48 +0000 | [diff] [blame] | 375 | R.Initialize(type, qs, address.getAlignment(), BaseInfo, TBAAInfo); |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 376 | return R; |
| 377 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 378 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 379 | static LValue MakeVectorElt(Address vecAddress, llvm::Value *Idx, |
Ivan A. Kosarev | d17f12a | 2017-10-17 10:17:43 +0000 | [diff] [blame] | 380 | QualType type, LValueBaseInfo BaseInfo, |
| 381 | TBAAAccessInfo TBAAInfo) { |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 382 | LValue R; |
| 383 | R.LVType = VectorElt; |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 384 | R.V = vecAddress.getPointer(); |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 385 | R.VectorIdx = Idx; |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 386 | R.Initialize(type, type.getQualifiers(), vecAddress.getAlignment(), |
Ivan A. Kosarev | d17f12a | 2017-10-17 10:17:43 +0000 | [diff] [blame] | 387 | BaseInfo, TBAAInfo); |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 388 | return R; |
| 389 | } |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 390 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 391 | static LValue MakeExtVectorElt(Address vecAddress, llvm::Constant *Elts, |
Ivan A. Kosarev | d17f12a | 2017-10-17 10:17:43 +0000 | [diff] [blame] | 392 | QualType type, LValueBaseInfo BaseInfo, |
| 393 | TBAAAccessInfo TBAAInfo) { |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 394 | LValue R; |
| 395 | R.LVType = ExtVectorElt; |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 396 | R.V = vecAddress.getPointer(); |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 397 | R.VectorElts = Elts; |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 398 | R.Initialize(type, type.getQualifiers(), vecAddress.getAlignment(), |
Ivan A. Kosarev | d17f12a | 2017-10-17 10:17:43 +0000 | [diff] [blame] | 399 | BaseInfo, TBAAInfo); |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 400 | return R; |
| 401 | } |
| 402 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 403 | /// Create a new object to represent a bit-field access. |
Daniel Dunbar | c75c8bd | 2010-04-08 02:59:45 +0000 | [diff] [blame] | 404 | /// |
NAKAMURA Takumi | 368d2ee | 2012-12-24 01:48:48 +0000 | [diff] [blame] | 405 | /// \param Addr - The base address of the bit-field sequence this |
Chandler Carruth | ff0e3a1 | 2012-12-06 11:14:44 +0000 | [diff] [blame] | 406 | /// bit-field refers to. |
Daniel Dunbar | c75c8bd | 2010-04-08 02:59:45 +0000 | [diff] [blame] | 407 | /// \param Info - The information describing how to perform the bit-field |
| 408 | /// access. |
Ivan A. Kosarev | d17f12a | 2017-10-17 10:17:43 +0000 | [diff] [blame] | 409 | static LValue MakeBitfield(Address Addr, const CGBitFieldInfo &Info, |
| 410 | QualType type, LValueBaseInfo BaseInfo, |
| 411 | TBAAAccessInfo TBAAInfo) { |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 412 | LValue R; |
| 413 | R.LVType = BitField; |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 414 | R.V = Addr.getPointer(); |
Daniel Dunbar | dc406b8 | 2010-04-05 21:36:35 +0000 | [diff] [blame] | 415 | R.BitFieldInfo = &Info; |
Ivan A. Kosarev | d17f12a | 2017-10-17 10:17:43 +0000 | [diff] [blame] | 416 | R.Initialize(type, type.getQualifiers(), Addr.getAlignment(), BaseInfo, |
| 417 | TBAAInfo); |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 418 | return R; |
| 419 | } |
Eli Friedman | 2869b5a | 2011-12-03 03:08:40 +0000 | [diff] [blame] | 420 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 421 | static LValue MakeGlobalReg(Address Reg, QualType type) { |
Renato Golin | 230c5eb | 2014-05-19 18:15:42 +0000 | [diff] [blame] | 422 | LValue R; |
| 423 | R.LVType = GlobalReg; |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 424 | R.V = Reg.getPointer(); |
| 425 | R.Initialize(type, type.getQualifiers(), Reg.getAlignment(), |
Ivan A. Kosarev | b9c59f3 | 2017-10-31 11:05:34 +0000 | [diff] [blame] | 426 | LValueBaseInfo(AlignmentSource::Decl), TBAAAccessInfo()); |
Renato Golin | 230c5eb | 2014-05-19 18:15:42 +0000 | [diff] [blame] | 427 | return R; |
| 428 | } |
| 429 | |
Eli Friedman | 2869b5a | 2011-12-03 03:08:40 +0000 | [diff] [blame] | 430 | RValue asAggregateRValue() const { |
Eli Friedman | 2869b5a | 2011-12-03 03:08:40 +0000 | [diff] [blame] | 431 | return RValue::getAggregate(getAddress(), isVolatileQualified()); |
| 432 | } |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 433 | }; |
| 434 | |
John McCall | 7a626f6 | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 435 | /// An aggregate value slot. |
| 436 | class AggValueSlot { |
Fariborz Jahanian | b60e70f | 2010-09-16 00:20:07 +0000 | [diff] [blame] | 437 | /// The address. |
John McCall | 2a8b9a3 | 2010-09-16 03:16:41 +0000 | [diff] [blame] | 438 | llvm::Value *Addr; |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 439 | |
| 440 | // Qualifiers |
| 441 | Qualifiers Quals; |
John McCall | 8d6fc95 | 2011-08-25 20:40:09 +0000 | [diff] [blame] | 442 | |
David Majnemer | ec4b734 | 2016-03-02 06:48:47 +0000 | [diff] [blame] | 443 | unsigned Alignment; |
Eli Friedman | c1d85b9 | 2011-12-03 00:54:26 +0000 | [diff] [blame] | 444 | |
John McCall | cac9385 | 2011-08-26 08:02:37 +0000 | [diff] [blame] | 445 | /// DestructedFlag - This is set to true if some external code is |
| 446 | /// responsible for setting up a destructor for the slot. Otherwise |
| 447 | /// the code which constructs it should push the appropriate cleanup. |
Chad Rosier | 615ed1a | 2012-03-29 17:37:10 +0000 | [diff] [blame] | 448 | bool DestructedFlag : 1; |
John McCall | cac9385 | 2011-08-26 08:02:37 +0000 | [diff] [blame] | 449 | |
| 450 | /// ObjCGCFlag - This is set to true if writing to the memory in the |
| 451 | /// slot might require calling an appropriate Objective-C GC |
| 452 | /// barrier. The exact interaction here is unnecessarily mysterious. |
Chad Rosier | 615ed1a | 2012-03-29 17:37:10 +0000 | [diff] [blame] | 453 | bool ObjCGCFlag : 1; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 454 | |
John McCall | cac9385 | 2011-08-26 08:02:37 +0000 | [diff] [blame] | 455 | /// ZeroedFlag - This is set to true if the memory in the slot is |
| 456 | /// known to be zero before the assignment into it. This means that |
| 457 | /// zero fields don't need to be set. |
Chad Rosier | 615ed1a | 2012-03-29 17:37:10 +0000 | [diff] [blame] | 458 | bool ZeroedFlag : 1; |
John McCall | 7a626f6 | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 459 | |
John McCall | cac9385 | 2011-08-26 08:02:37 +0000 | [diff] [blame] | 460 | /// AliasedFlag - This is set to true if the slot might be aliased |
| 461 | /// and it's not undefined behavior to access it through such an |
| 462 | /// alias. Note that it's always undefined behavior to access a C++ |
| 463 | /// object that's under construction through an alias derived from |
| 464 | /// outside the construction process. |
| 465 | /// |
| 466 | /// This flag controls whether calls that produce the aggregate |
| 467 | /// value may be evaluated directly into the slot, or whether they |
| 468 | /// must be evaluated into an unaliased temporary and then memcpy'ed |
| 469 | /// over. Since it's invalid in general to memcpy a non-POD C++ |
| 470 | /// object, it's important that this flag never be set when |
| 471 | /// evaluating an expression which constructs such an object. |
Chad Rosier | 615ed1a | 2012-03-29 17:37:10 +0000 | [diff] [blame] | 472 | bool AliasedFlag : 1; |
John McCall | a5efa73 | 2011-08-25 23:04:34 +0000 | [diff] [blame] | 473 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 474 | /// This is set to true if the tail padding of this slot might overlap |
Richard Smith | e78fac5 | 2018-04-05 20:52:58 +0000 | [diff] [blame] | 475 | /// another object that may have already been initialized (and whose |
| 476 | /// value must be preserved by this initialization). If so, we may only |
| 477 | /// store up to the dsize of the type. Otherwise we can widen stores to |
| 478 | /// the size of the type. |
| 479 | bool OverlapFlag : 1; |
| 480 | |
Serge Pavlov | 3760518 | 2018-07-28 15:33:03 +0000 | [diff] [blame] | 481 | /// If is set to true, sanitizer checks are already generated for this address |
| 482 | /// or not required. For instance, if this address represents an object |
| 483 | /// created in 'new' expression, sanitizer checks for memory is made as a part |
| 484 | /// of 'operator new' emission and object constructor should not generate |
| 485 | /// them. |
| 486 | bool SanitizerCheckedFlag : 1; |
| 487 | |
John McCall | 7a626f6 | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 488 | public: |
John McCall | a5efa73 | 2011-08-25 23:04:34 +0000 | [diff] [blame] | 489 | enum IsAliased_t { IsNotAliased, IsAliased }; |
John McCall | 8d6fc95 | 2011-08-25 20:40:09 +0000 | [diff] [blame] | 490 | enum IsDestructed_t { IsNotDestructed, IsDestructed }; |
John McCall | a5efa73 | 2011-08-25 23:04:34 +0000 | [diff] [blame] | 491 | enum IsZeroed_t { IsNotZeroed, IsZeroed }; |
Richard Smith | e78fac5 | 2018-04-05 20:52:58 +0000 | [diff] [blame] | 492 | enum Overlap_t { DoesNotOverlap, MayOverlap }; |
John McCall | 8d6fc95 | 2011-08-25 20:40:09 +0000 | [diff] [blame] | 493 | enum NeedsGCBarriers_t { DoesNotNeedGCBarriers, NeedsGCBarriers }; |
Serge Pavlov | 3760518 | 2018-07-28 15:33:03 +0000 | [diff] [blame] | 494 | enum IsSanitizerChecked_t { IsNotSanitizerChecked, IsSanitizerChecked }; |
John McCall | 8d6fc95 | 2011-08-25 20:40:09 +0000 | [diff] [blame] | 495 | |
John McCall | 7a626f6 | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 496 | /// ignored - Returns an aggregate value slot indicating that the |
| 497 | /// aggregate value is being ignored. |
| 498 | static AggValueSlot ignored() { |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 499 | return forAddr(Address::invalid(), Qualifiers(), IsNotDestructed, |
Richard Smith | e78fac5 | 2018-04-05 20:52:58 +0000 | [diff] [blame] | 500 | DoesNotNeedGCBarriers, IsNotAliased, DoesNotOverlap); |
John McCall | 7a626f6 | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | /// forAddr - Make a slot for an aggregate value. |
| 504 | /// |
John McCall | 8d6fc95 | 2011-08-25 20:40:09 +0000 | [diff] [blame] | 505 | /// \param quals - The qualifiers that dictate how the slot should |
| 506 | /// be initialied. Only 'volatile' and the Objective-C lifetime |
| 507 | /// qualifiers matter. |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 508 | /// |
John McCall | 8d6fc95 | 2011-08-25 20:40:09 +0000 | [diff] [blame] | 509 | /// \param isDestructed - true if something else is responsible |
| 510 | /// for calling destructors on this object |
| 511 | /// \param needsGC - true if the slot is potentially located |
John McCall | 58649dc | 2010-09-16 03:13:23 +0000 | [diff] [blame] | 512 | /// somewhere that ObjC GC calls should be emitted for |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 513 | static AggValueSlot forAddr(Address addr, |
Eli Friedman | c1d85b9 | 2011-12-03 00:54:26 +0000 | [diff] [blame] | 514 | Qualifiers quals, |
John McCall | 8d6fc95 | 2011-08-25 20:40:09 +0000 | [diff] [blame] | 515 | IsDestructed_t isDestructed, |
| 516 | NeedsGCBarriers_t needsGC, |
John McCall | 46759f4 | 2011-08-26 07:31:35 +0000 | [diff] [blame] | 517 | IsAliased_t isAliased, |
Richard Smith | e78fac5 | 2018-04-05 20:52:58 +0000 | [diff] [blame] | 518 | Overlap_t mayOverlap, |
Serge Pavlov | 3760518 | 2018-07-28 15:33:03 +0000 | [diff] [blame] | 519 | IsZeroed_t isZeroed = IsNotZeroed, |
| 520 | IsSanitizerChecked_t isChecked = IsNotSanitizerChecked) { |
John McCall | 7a626f6 | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 521 | AggValueSlot AV; |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 522 | if (addr.isValid()) { |
| 523 | AV.Addr = addr.getPointer(); |
| 524 | AV.Alignment = addr.getAlignment().getQuantity(); |
| 525 | } else { |
| 526 | AV.Addr = nullptr; |
| 527 | AV.Alignment = 0; |
| 528 | } |
John McCall | 8d6fc95 | 2011-08-25 20:40:09 +0000 | [diff] [blame] | 529 | AV.Quals = quals; |
John McCall | cac9385 | 2011-08-26 08:02:37 +0000 | [diff] [blame] | 530 | AV.DestructedFlag = isDestructed; |
| 531 | AV.ObjCGCFlag = needsGC; |
John McCall | 8d6fc95 | 2011-08-25 20:40:09 +0000 | [diff] [blame] | 532 | AV.ZeroedFlag = isZeroed; |
John McCall | a5efa73 | 2011-08-25 23:04:34 +0000 | [diff] [blame] | 533 | AV.AliasedFlag = isAliased; |
Richard Smith | e78fac5 | 2018-04-05 20:52:58 +0000 | [diff] [blame] | 534 | AV.OverlapFlag = mayOverlap; |
Serge Pavlov | 3760518 | 2018-07-28 15:33:03 +0000 | [diff] [blame] | 535 | AV.SanitizerCheckedFlag = isChecked; |
John McCall | 7a626f6 | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 536 | return AV; |
| 537 | } |
| 538 | |
John McCall | 4e8ca4f | 2012-07-02 23:58:38 +0000 | [diff] [blame] | 539 | static AggValueSlot forLValue(const LValue &LV, |
| 540 | IsDestructed_t isDestructed, |
John McCall | 8d6fc95 | 2011-08-25 20:40:09 +0000 | [diff] [blame] | 541 | NeedsGCBarriers_t needsGC, |
John McCall | 46759f4 | 2011-08-26 07:31:35 +0000 | [diff] [blame] | 542 | IsAliased_t isAliased, |
Richard Smith | e78fac5 | 2018-04-05 20:52:58 +0000 | [diff] [blame] | 543 | Overlap_t mayOverlap, |
Serge Pavlov | 3760518 | 2018-07-28 15:33:03 +0000 | [diff] [blame] | 544 | IsZeroed_t isZeroed = IsNotZeroed, |
| 545 | IsSanitizerChecked_t isChecked = IsNotSanitizerChecked) { |
Richard Smith | e78fac5 | 2018-04-05 20:52:58 +0000 | [diff] [blame] | 546 | return forAddr(LV.getAddress(), LV.getQuals(), isDestructed, needsGC, |
Serge Pavlov | 3760518 | 2018-07-28 15:33:03 +0000 | [diff] [blame] | 547 | isAliased, mayOverlap, isZeroed, isChecked); |
John McCall | 7a626f6 | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 548 | } |
Fariborz Jahanian | c123623 | 2010-10-22 22:05:03 +0000 | [diff] [blame] | 549 | |
John McCall | cac9385 | 2011-08-26 08:02:37 +0000 | [diff] [blame] | 550 | IsDestructed_t isExternallyDestructed() const { |
| 551 | return IsDestructed_t(DestructedFlag); |
John McCall | 7a626f6 | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 552 | } |
John McCall | cac9385 | 2011-08-26 08:02:37 +0000 | [diff] [blame] | 553 | void setExternallyDestructed(bool destructed = true) { |
| 554 | DestructedFlag = destructed; |
John McCall | 7a626f6 | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 555 | } |
| 556 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 557 | Qualifiers getQualifiers() const { return Quals; } |
| 558 | |
John McCall | 7a626f6 | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 559 | bool isVolatile() const { |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 560 | return Quals.hasVolatile(); |
| 561 | } |
| 562 | |
Fariborz Jahanian | 7865220 | 2013-01-25 23:57:05 +0000 | [diff] [blame] | 563 | void setVolatile(bool flag) { |
Mikael Nilsson | 9d2872d | 2018-12-13 10:15:27 +0000 | [diff] [blame] | 564 | if (flag) |
| 565 | Quals.addVolatile(); |
| 566 | else |
| 567 | Quals.removeVolatile(); |
Fariborz Jahanian | 7865220 | 2013-01-25 23:57:05 +0000 | [diff] [blame] | 568 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 569 | |
John McCall | 31168b0 | 2011-06-15 23:02:42 +0000 | [diff] [blame] | 570 | Qualifiers::ObjCLifetime getObjCLifetime() const { |
| 571 | return Quals.getObjCLifetime(); |
John McCall | 7a626f6 | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 572 | } |
| 573 | |
John McCall | 8d6fc95 | 2011-08-25 20:40:09 +0000 | [diff] [blame] | 574 | NeedsGCBarriers_t requiresGCollection() const { |
John McCall | cac9385 | 2011-08-26 08:02:37 +0000 | [diff] [blame] | 575 | return NeedsGCBarriers_t(ObjCGCFlag); |
Fariborz Jahanian | b60e70f | 2010-09-16 00:20:07 +0000 | [diff] [blame] | 576 | } |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 577 | |
| 578 | llvm::Value *getPointer() const { |
John McCall | 2a8b9a3 | 2010-09-16 03:16:41 +0000 | [diff] [blame] | 579 | return Addr; |
John McCall | 7a626f6 | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 580 | } |
| 581 | |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 582 | Address getAddress() const { |
| 583 | return Address(Addr, getAlignment()); |
| 584 | } |
| 585 | |
John McCall | 7a626f6 | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 586 | bool isIgnored() const { |
Craig Topper | 8a13c41 | 2014-05-21 05:09:00 +0000 | [diff] [blame] | 587 | return Addr == nullptr; |
John McCall | 7a626f6 | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 588 | } |
| 589 | |
Eli Friedman | 38cd36d | 2011-12-03 02:13:40 +0000 | [diff] [blame] | 590 | CharUnits getAlignment() const { |
| 591 | return CharUnits::fromQuantity(Alignment); |
Eli Friedman | c1d85b9 | 2011-12-03 00:54:26 +0000 | [diff] [blame] | 592 | } |
| 593 | |
John McCall | a5efa73 | 2011-08-25 23:04:34 +0000 | [diff] [blame] | 594 | IsAliased_t isPotentiallyAliased() const { |
| 595 | return IsAliased_t(AliasedFlag); |
| 596 | } |
| 597 | |
Richard Smith | e78fac5 | 2018-04-05 20:52:58 +0000 | [diff] [blame] | 598 | Overlap_t mayOverlap() const { |
| 599 | return Overlap_t(OverlapFlag); |
| 600 | } |
| 601 | |
Serge Pavlov | 3760518 | 2018-07-28 15:33:03 +0000 | [diff] [blame] | 602 | bool isSanitizerChecked() const { |
| 603 | return SanitizerCheckedFlag; |
| 604 | } |
| 605 | |
John McCall | 7a626f6 | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 606 | RValue asRValue() const { |
John McCall | 7f416cc | 2015-09-08 08:05:57 +0000 | [diff] [blame] | 607 | if (isIgnored()) { |
| 608 | return RValue::getIgnored(); |
| 609 | } else { |
| 610 | return RValue::getAggregate(getAddress(), isVolatile()); |
| 611 | } |
John McCall | 7a626f6 | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 612 | } |
John McCall | fe96e0b | 2011-11-06 09:01:30 +0000 | [diff] [blame] | 613 | |
John McCall | 8d6fc95 | 2011-08-25 20:40:09 +0000 | [diff] [blame] | 614 | void setZeroed(bool V = true) { ZeroedFlag = V; } |
| 615 | IsZeroed_t isZeroed() const { |
| 616 | return IsZeroed_t(ZeroedFlag); |
Chris Lattner | 27a3631 | 2010-12-02 07:07:26 +0000 | [diff] [blame] | 617 | } |
Richard Smith | e78fac5 | 2018-04-05 20:52:58 +0000 | [diff] [blame] | 618 | |
| 619 | /// Get the preferred size to use when storing a value to this slot. This |
| 620 | /// is the type size unless that might overlap another object, in which |
| 621 | /// case it's the dsize. |
| 622 | CharUnits getPreferredSize(ASTContext &Ctx, QualType Type) const { |
| 623 | return mayOverlap() ? Ctx.getTypeInfoDataSizeInChars(Type).first |
| 624 | : Ctx.getTypeSizeInChars(Type); |
| 625 | } |
John McCall | 7a626f6 | 2010-09-15 10:14:12 +0000 | [diff] [blame] | 626 | }; |
| 627 | |
Daniel Dunbar | d4f616b | 2008-08-23 03:10:25 +0000 | [diff] [blame] | 628 | } // end namespace CodeGen |
| 629 | } // end namespace clang |
| 630 | |
| 631 | #endif |