Coverage Report

Created: 2022-01-18 06:27

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/CodeGen/CGValue.h
Line
Count
Source (jump to first uncovered line)
1
//===-- CGValue.h - LLVM CodeGen wrappers for llvm::Value* ------*- C++ -*-===//
2
//
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
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
14
#ifndef LLVM_CLANG_LIB_CODEGEN_CGVALUE_H
15
#define LLVM_CLANG_LIB_CODEGEN_CGVALUE_H
16
17
#include "clang/AST/ASTContext.h"
18
#include "clang/AST/Type.h"
19
#include "llvm/IR/Value.h"
20
#include "llvm/IR/Type.h"
21
#include "Address.h"
22
#include "CodeGenTBAA.h"
23
24
namespace llvm {
25
  class Constant;
26
  class MDNode;
27
}
28
29
namespace clang {
30
namespace CodeGen {
31
  class AggValueSlot;
32
  class CodeGenFunction;
33
  struct CGBitFieldInfo;
34
35
/// RValue - This trivial value class is used to represent the result of an
36
/// expression that is evaluated.  It can be one of three things: either a
37
/// simple LLVM SSA value, a pair of SSA values for complex numbers, or the
38
/// address of an aggregate value in memory.
39
class RValue {
40
  enum Flavor { Scalar, Complex, Aggregate };
41
42
  // The shift to make to an aggregate's alignment to make it look
43
  // like a pointer.
44
  enum { AggAlignShift = 4 };
45
46
  // Stores first value and flavor.
47
  llvm::PointerIntPair<llvm::Value *, 2, Flavor> V1;
48
  // Stores second value and volatility.
49
  llvm::PointerIntPair<llvm::Value *, 1, bool> V2;
50
  // Stores element type for aggregate values.
51
  llvm::Type *ElementType;
52
53
public:
54
3.66M
  bool isScalar() const { return V1.getInt() == Scalar; }
55
459
  bool isComplex() const { return V1.getInt() == Complex; }
56
617k
  bool isAggregate() const { return V1.getInt() == Aggregate; }
57
58
0
  bool isVolatileQualified() const { return V2.getInt(); }
59
60
  /// getScalarVal() - Return the Value* of this scalar value.
61
2.66M
  llvm::Value *getScalarVal() const {
62
2.66M
    assert(isScalar() && "Not a scalar!");
63
0
    return V1.getPointer();
64
2.66M
  }
65
66
  /// getComplexVal - Return the real/imag components of this complex value.
67
  ///
68
1.09k
  std::pair<llvm::Value *, llvm::Value *> getComplexVal() const {
69
1.09k
    return std::make_pair(V1.getPointer(), V2.getPointer());
70
1.09k
  }
71
72
  /// getAggregateAddr() - Return the Value* of the address of the aggregate.
73
5.82k
  Address getAggregateAddress() const {
74
5.82k
    assert(isAggregate() && "Not an aggregate!");
75
0
    auto align = reinterpret_cast<uintptr_t>(V2.getPointer()) >> AggAlignShift;
76
5.82k
    return Address(
77
5.82k
        V1.getPointer(), ElementType, CharUnits::fromQuantity(align));
78
5.82k
  }
79
178
  llvm::Value *getAggregatePointer() const {
80
178
    assert(isAggregate() && "Not an aggregate!");
81
0
    return V1.getPointer();
82
178
  }
83
84
1.52k
  static RValue getIgnored() {
85
    // FIXME: should we make this a more explicit state?
86
1.52k
    return get(nullptr);
87
1.52k
  }
88
89
2.79M
  static RValue get(llvm::Value *V) {
90
2.79M
    RValue ER;
91
2.79M
    ER.V1.setPointer(V);
92
2.79M
    ER.V1.setInt(Scalar);
93
2.79M
    ER.V2.setInt(false);
94
2.79M
    return ER;
95
2.79M
  }
96
1.54k
  static RValue getComplex(llvm::Value *V1, llvm::Value *V2) {
97
1.54k
    RValue ER;
98
1.54k
    ER.V1.setPointer(V1);
99
1.54k
    ER.V2.setPointer(V2);
100
1.54k
    ER.V1.setInt(Complex);
101
1.54k
    ER.V2.setInt(false);
102
1.54k
    return ER;
103
1.54k
  }
104
1.54k
  static RValue getComplex(const std::pair<llvm::Value *, llvm::Value *> &C) {
105
1.54k
    return getComplex(C.first, C.second);
106
1.54k
  }
107
  // FIXME: Aggregate rvalues need to retain information about whether they are
108
  // volatile or not.  Remove default to find all places that probably get this
109
  // wrong.
110
20.7k
  static RValue getAggregate(Address addr, bool isVolatile = false) {
111
20.7k
    RValue ER;
112
20.7k
    ER.V1.setPointer(addr.getPointer());
113
20.7k
    ER.V1.setInt(Aggregate);
114
20.7k
    ER.ElementType = addr.getElementType();
115
116
20.7k
    auto align = static_cast<uintptr_t>(addr.getAlignment().getQuantity());
117
20.7k
    ER.V2.setPointer(reinterpret_cast<llvm::Value*>(align << AggAlignShift));
118
20.7k
    ER.V2.setInt(isVolatile);
119
20.7k
    return ER;
120
20.7k
  }
121
};
122
123
/// Does an ARC strong l-value have precise lifetime?
124
enum ARCPreciseLifetime_t {
125
  ARCImpreciseLifetime, ARCPreciseLifetime
126
};
127
128
/// The source of the alignment of an l-value; an expression of
129
/// confidence in the alignment actually matching the estimate.
130
enum class AlignmentSource {
131
  /// The l-value was an access to a declared entity or something
132
  /// equivalently strong, like the address of an array allocated by a
133
  /// language runtime.
134
  Decl,
135
136
  /// The l-value was considered opaque, so the alignment was
137
  /// determined from a type, but that type was an explicitly-aligned
138
  /// typedef.
139
  AttributedType,
140
141
  /// The l-value was considered opaque, so the alignment was
142
  /// determined from a type.
143
  Type
144
};
145
146
/// Given that the base address has the given alignment source, what's
147
/// our confidence in the alignment of the field?
148
225k
static inline AlignmentSource getFieldAlignmentSource(AlignmentSource Source) {
149
  // For now, we don't distinguish fields of opaque pointers from
150
  // top-level declarations, but maybe we should.
151
225k
  return AlignmentSource::Decl;
152
225k
}
Unexecuted instantiation: CGAtomic.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGBlocks.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGBuiltin.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGCUDANV.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGCUDARuntime.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGCXX.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGCXXABI.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGCall.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGClass.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGCleanup.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGCoroutine.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGDebugInfo.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGDecl.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGDeclCXX.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGException.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
CGExpr.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Line
Count
Source
148
225k
static inline AlignmentSource getFieldAlignmentSource(AlignmentSource Source) {
149
  // For now, we don't distinguish fields of opaque pointers from
150
  // top-level declarations, but maybe we should.
151
225k
  return AlignmentSource::Decl;
152
225k
}
Unexecuted instantiation: CGExprAgg.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGExprCXX.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGExprComplex.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGExprConstant.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGExprScalar.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGGPUBuiltin.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGNonTrivialStruct.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGObjC.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGObjCGNU.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGObjCMac.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGObjCRuntime.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGOpenCLRuntime.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGOpenMPRuntime.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGOpenMPRuntimeGPU.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGRecordLayoutBuilder.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGStmt.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGStmtOpenMP.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGVTT.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CGVTables.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CodeGenFunction.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CodeGenModule.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CodeGenPGO.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CodeGenTypes.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: ConstantInitBuilder.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CoverageMappingGen.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: ItaniumCXXABI.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: MicrosoftCXXABI.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: ObjectFilePCHContainerOperations.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: PatternInit.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: SanitizerMetadata.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: SwiftCallingConv.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: TargetInfo.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CodeGenAction.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: ModuleBuilder.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
Unexecuted instantiation: CodeGenABITypes.cpp:clang::CodeGen::getFieldAlignmentSource(clang::CodeGen::AlignmentSource)
153
154
class LValueBaseInfo {
155
  AlignmentSource AlignSource;
156
157
public:
158
  explicit LValueBaseInfo(AlignmentSource Source = AlignmentSource::Type)
159
10.3M
    : AlignSource(Source) {}
160
237k
  AlignmentSource getAlignmentSource() const { return AlignSource; }
161
2.00k
  void setAlignmentSource(AlignmentSource Source) { AlignSource = Source; }
162
163
2.00k
  void mergeForCast(const LValueBaseInfo &Info) {
164
2.00k
    setAlignmentSource(Info.getAlignmentSource());
165
2.00k
  }
166
};
167
168
/// LValue - This represents an lvalue references.  Because C/C++ allow
169
/// bitfields, this is not a simple LLVM pointer, it may be a pointer plus a
170
/// bitrange.
171
class LValue {
172
  enum {
173
    Simple,       // This is a normal l-value, use getAddress().
174
    VectorElt,    // This is a vector element l-value (V[i]), use getVector*
175
    BitField,     // This is a bitfield l-value, use getBitfield*.
176
    ExtVectorElt, // This is an extended vector subset, use getExtVectorComp
177
    GlobalReg,    // This is a register l-value, use getGlobalReg()
178
    MatrixElt     // This is a matrix element, use getVector*
179
  } LVType;
180
181
  llvm::Value *V;
182
  llvm::Type *ElementType;
183
184
  union {
185
    // Index into a vector subscript: V[i]
186
    llvm::Value *VectorIdx;
187
188
    // ExtVector element subset: V.xyx
189
    llvm::Constant *VectorElts;
190
191
    // BitField start bit and size
192
    const CGBitFieldInfo *BitFieldInfo;
193
  };
194
195
  QualType Type;
196
197
  // 'const' is unused here
198
  Qualifiers Quals;
199
200
  // The alignment to use when accessing this lvalue.  (For vector elements,
201
  // this is the alignment of the whole vector.)
202
  unsigned Alignment;
203
204
  // objective-c's ivar
205
  bool Ivar:1;
206
207
  // objective-c's ivar is an array
208
  bool ObjIsArray:1;
209
210
  // LValue is non-gc'able for any reason, including being a parameter or local
211
  // variable.
212
  bool NonGC: 1;
213
214
  // Lvalue is a global reference of an objective-c object
215
  bool GlobalObjCRef : 1;
216
217
  // Lvalue is a thread local reference
218
  bool ThreadLocalRef : 1;
219
220
  // Lvalue has ARC imprecise lifetime.  We store this inverted to try
221
  // to make the default bitfield pattern all-zeroes.
222
  bool ImpreciseLifetime : 1;
223
224
  // This flag shows if a nontemporal load/stores should be used when accessing
225
  // this lvalue.
226
  bool Nontemporal : 1;
227
228
  LValueBaseInfo BaseInfo;
229
  TBAAAccessInfo TBAAInfo;
230
231
  Expr *BaseIvarExp;
232
233
private:
234
  void Initialize(QualType Type, Qualifiers Quals, CharUnits Alignment,
235
5.13M
                  LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo) {
236
5.13M
    assert((!Alignment.isZero() || Type->isIncompleteType()) &&
237
5.13M
           "initializing l-value with zero alignment!");
238
5.13M
    if (isGlobalReg())
239
50
      assert(ElementType == nullptr && "Global reg does not store elem type");
240
5.13M
    else
241
5.13M
      assert(llvm::cast<llvm::PointerType>(V->getType())
242
5.13M
                 ->isOpaqueOrPointeeTypeMatches(ElementType) &&
243
5.13M
             "Pointer element type mismatch");
244
245
0
    this->Type = Type;
246
5.13M
    this->Quals = Quals;
247
5.13M
    const unsigned MaxAlign = 1U << 31;
248
5.13M
    this->Alignment = Alignment.getQuantity() <= MaxAlign
249
5.13M
                          ? Alignment.getQuantity()
250
5.13M
                          : 
MaxAlign0
;
251
5.13M
    assert(this->Alignment == Alignment.getQuantity() &&
252
5.13M
           "Alignment exceeds allowed max!");
253
0
    this->BaseInfo = BaseInfo;
254
5.13M
    this->TBAAInfo = TBAAInfo;
255
256
    // Initialize Objective-C flags.
257
5.13M
    this->Ivar = this->ObjIsArray = this->NonGC = this->GlobalObjCRef = false;
258
5.13M
    this->ImpreciseLifetime = false;
259
5.13M
    this->Nontemporal = false;
260
5.13M
    this->ThreadLocalRef = false;
261
5.13M
    this->BaseIvarExp = nullptr;
262
5.13M
  }
263
264
public:
265
5.38M
  bool isSimple() const { return LVType == Simple; }
266
7.35k
  bool isVectorElt() const { return LVType == VectorElt; }
267
356k
  bool isBitField() const { return LVType == BitField; }
268
7.17k
  bool isExtVectorElt() const { return LVType == ExtVectorElt; }
269
5.14M
  bool isGlobalReg() const { return LVType == GlobalReg; }
270
6.18k
  bool isMatrixElt() const { return LVType == MatrixElt; }
271
272
31.2k
  bool isVolatileQualified() const { return Quals.hasVolatile(); }
273
0
  bool isRestrictQualified() const { return Quals.hasRestrict(); }
274
227k
  unsigned getVRQualifiers() const {
275
227k
    return Quals.getCVRQualifiers() & ~Qualifiers::Const;
276
227k
  }
277
278
5.69M
  QualType getType() const { return Type; }
279
280
199k
  Qualifiers::ObjCLifetime getObjCLifetime() const {
281
199k
    return Quals.getObjCLifetime();
282
199k
  }
283
284
381
  bool isObjCIvar() const { return Ivar; }
285
298
  void setObjCIvar(bool Value) { Ivar = Value; }
286
287
122
  bool isObjCArray() const { return ObjIsArray; }
288
1.32k
  void setObjCArray(bool Value) { ObjIsArray = Value; }
289
290
280
  bool isNonGC () const { return NonGC; }
291
1.31M
  void setNonGC(bool Value) { NonGC = Value; }
292
293
263
  bool isGlobalObjCRef() const { return GlobalObjCRef; }
294
288
  void setGlobalObjCRef(bool Value) { GlobalObjCRef = Value; }
295
296
81
  bool isThreadLocalRef() const { return ThreadLocalRef; }
297
284
  void setThreadLocalRef(bool Value) { ThreadLocalRef = Value;}
298
299
98
  ARCPreciseLifetime_t isARCPreciseLifetime() const {
300
98
    return ARCPreciseLifetime_t(!ImpreciseLifetime);
301
98
  }
302
1.17M
  void setARCPreciseLifetime(ARCPreciseLifetime_t value) {
303
1.17M
    ImpreciseLifetime = (value == ARCImpreciseLifetime);
304
1.17M
  }
305
2.12M
  bool isNontemporal() const { return Nontemporal; }
306
350
  void setNontemporal(bool Value) { Nontemporal = Value; }
307
308
1.54M
  bool isObjCWeak() const {
309
1.54M
    return Quals.getObjCGCAttr() == Qualifiers::Weak;
310
1.54M
  }
311
451k
  bool isObjCStrong() const {
312
451k
    return Quals.getObjCGCAttr() == Qualifiers::Strong;
313
451k
  }
314
315
2.20M
  bool isVolatile() const {
316
2.20M
    return Quals.hasVolatile();
317
2.20M
  }
318
319
108
  Expr *getBaseIvarExp() const { return BaseIvarExp; }
320
246
  void setBaseIvarExp(Expr *V) { BaseIvarExp = V; }
321
322
2.68M
  TBAAAccessInfo getTBAAInfo() const { return TBAAInfo; }
323
46
  void setTBAAInfo(TBAAAccessInfo Info) { TBAAInfo = Info; }
324
325
29.9k
  const Qualifiers &getQuals() const { return Quals; }
326
3.15M
  Qualifiers &getQuals() { return Quals; }
327
328
311
  LangAS getAddressSpace() const { return Quals.getAddressSpace(); }
329
330
3.14M
  CharUnits getAlignment() const { return CharUnits::fromQuantity(Alignment); }
331
0
  void setAlignment(CharUnits A) { Alignment = A.getQuantity(); }
332
333
2.39M
  LValueBaseInfo getBaseInfo() const { return BaseInfo; }
334
0
  void setBaseInfo(LValueBaseInfo Info) { BaseInfo = Info; }
335
336
  // simple lvalue
337
3.42M
  llvm::Value *getPointer(CodeGenFunction &CGF) const {
338
3.42M
    assert(isSimple());
339
0
    return V;
340
3.42M
  }
341
2.88M
  Address getAddress(CodeGenFunction &CGF) const {
342
2.88M
    return Address(getPointer(CGF), ElementType, getAlignment());
343
2.88M
  }
344
1.84k
  void setAddress(Address address) {
345
1.84k
    assert(isSimple());
346
0
    V = address.getPointer();
347
1.84k
    ElementType = address.getElementType();
348
1.84k
    Alignment = address.getAlignment().getQuantity();
349
1.84k
  }
350
351
  // vector elt lvalue
352
361
  Address getVectorAddress() const {
353
361
    return Address(getVectorPointer(), ElementType, getAlignment());
354
361
  }
355
393
  llvm::Value *getVectorPointer() const {
356
393
    assert(isVectorElt());
357
0
    return V;
358
393
  }
359
225
  llvm::Value *getVectorIdx() const {
360
225
    assert(isVectorElt());
361
0
    return VectorIdx;
362
225
  }
363
364
72
  Address getMatrixAddress() const {
365
72
    return Address(getMatrixPointer(), ElementType, getAlignment());
366
72
  }
367
72
  llvm::Value *getMatrixPointer() const {
368
72
    assert(isMatrixElt());
369
0
    return V;
370
72
  }
371
38
  llvm::Value *getMatrixIdx() const {
372
38
    assert(isMatrixElt());
373
0
    return VectorIdx;
374
38
  }
375
376
  // extended vector elements.
377
343
  Address getExtVectorAddress() const {
378
343
    return Address(getExtVectorPointer(), ElementType, getAlignment());
379
343
  }
380
375
  llvm::Value *getExtVectorPointer() const {
381
375
    assert(isExtVectorElt());
382
0
    return V;
383
375
  }
384
316
  llvm::Constant *getExtVectorElts() const {
385
316
    assert(isExtVectorElt());
386
0
    return VectorElts;
387
316
  }
388
389
  // bitfield lvalue
390
6.80k
  Address getBitFieldAddress() const {
391
6.80k
    return Address(getBitFieldPointer(), ElementType, getAlignment());
392
6.80k
  }
393
7.31k
  llvm::Value *getBitFieldPointer() const { assert(isBitField()); return V; }
394
7.10k
  const CGBitFieldInfo &getBitFieldInfo() const {
395
7.10k
    assert(isBitField());
396
0
    return *BitFieldInfo;
397
7.10k
  }
398
399
  // global register lvalue
400
56
  llvm::Value *getGlobalReg() const { assert(isGlobalReg()); return V; }
401
402
  static LValue MakeAddr(Address address, QualType type, ASTContext &Context,
403
5.12M
                         LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo) {
404
5.12M
    Qualifiers qs = type.getQualifiers();
405
5.12M
    qs.setObjCGCAttr(Context.getObjCGCAttrKind(type));
406
407
5.12M
    LValue R;
408
5.12M
    R.LVType = Simple;
409
5.12M
    assert(address.getPointer()->getType()->isPointerTy());
410
0
    R.V = address.getPointer();
411
5.12M
    R.ElementType = address.getElementType();
412
5.12M
    R.Initialize(type, qs, address.getAlignment(), BaseInfo, TBAAInfo);
413
5.12M
    return R;
414
5.12M
  }
415
416
  static LValue MakeVectorElt(Address vecAddress, llvm::Value *Idx,
417
                              QualType type, LValueBaseInfo BaseInfo,
418
171
                              TBAAAccessInfo TBAAInfo) {
419
171
    LValue R;
420
171
    R.LVType = VectorElt;
421
171
    R.V = vecAddress.getPointer();
422
171
    R.ElementType = vecAddress.getElementType();
423
171
    R.VectorIdx = Idx;
424
171
    R.Initialize(type, type.getQualifiers(), vecAddress.getAlignment(),
425
171
                 BaseInfo, TBAAInfo);
426
171
    return R;
427
171
  }
428
429
  static LValue MakeExtVectorElt(Address vecAddress, llvm::Constant *Elts,
430
                                 QualType type, LValueBaseInfo BaseInfo,
431
310
                                 TBAAAccessInfo TBAAInfo) {
432
310
    LValue R;
433
310
    R.LVType = ExtVectorElt;
434
310
    R.V = vecAddress.getPointer();
435
310
    R.ElementType = vecAddress.getElementType();
436
310
    R.VectorElts = Elts;
437
310
    R.Initialize(type, type.getQualifiers(), vecAddress.getAlignment(),
438
310
                 BaseInfo, TBAAInfo);
439
310
    return R;
440
310
  }
441
442
  /// Create a new object to represent a bit-field access.
443
  ///
444
  /// \param Addr - The base address of the bit-field sequence this
445
  /// bit-field refers to.
446
  /// \param Info - The information describing how to perform the bit-field
447
  /// access.
448
  static LValue MakeBitfield(Address Addr, const CGBitFieldInfo &Info,
449
                             QualType type, LValueBaseInfo BaseInfo,
450
6.73k
                             TBAAAccessInfo TBAAInfo) {
451
6.73k
    LValue R;
452
6.73k
    R.LVType = BitField;
453
6.73k
    R.V = Addr.getPointer();
454
6.73k
    R.ElementType = Addr.getElementType();
455
6.73k
    R.BitFieldInfo = &Info;
456
6.73k
    R.Initialize(type, type.getQualifiers(), Addr.getAlignment(), BaseInfo,
457
6.73k
                 TBAAInfo);
458
6.73k
    return R;
459
6.73k
  }
460
461
  static LValue MakeGlobalReg(llvm::Value *V, CharUnits alignment,
462
50
                              QualType type) {
463
50
    LValue R;
464
50
    R.LVType = GlobalReg;
465
50
    R.V = V;
466
50
    R.ElementType = nullptr;
467
50
    R.Initialize(type, type.getQualifiers(), alignment,
468
50
                 LValueBaseInfo(AlignmentSource::Decl), TBAAAccessInfo());
469
50
    return R;
470
50
  }
471
472
  static LValue MakeMatrixElt(Address matAddress, llvm::Value *Idx,
473
                              QualType type, LValueBaseInfo BaseInfo,
474
34
                              TBAAAccessInfo TBAAInfo) {
475
34
    LValue R;
476
34
    R.LVType = MatrixElt;
477
34
    R.V = matAddress.getPointer();
478
34
    R.ElementType = matAddress.getElementType();
479
34
    R.VectorIdx = Idx;
480
34
    R.Initialize(type, type.getQualifiers(), matAddress.getAlignment(),
481
34
                 BaseInfo, TBAAInfo);
482
34
    return R;
483
34
  }
484
485
9.40k
  RValue asAggregateRValue(CodeGenFunction &CGF) const {
486
9.40k
    return RValue::getAggregate(getAddress(CGF), isVolatileQualified());
487
9.40k
  }
488
};
489
490
/// An aggregate value slot.
491
class AggValueSlot {
492
  /// The address.
493
  Address Addr;
494
495
  // Qualifiers
496
  Qualifiers Quals;
497
498
  /// DestructedFlag - This is set to true if some external code is
499
  /// responsible for setting up a destructor for the slot.  Otherwise
500
  /// the code which constructs it should push the appropriate cleanup.
501
  bool DestructedFlag : 1;
502
503
  /// ObjCGCFlag - This is set to true if writing to the memory in the
504
  /// slot might require calling an appropriate Objective-C GC
505
  /// barrier.  The exact interaction here is unnecessarily mysterious.
506
  bool ObjCGCFlag : 1;
507
508
  /// ZeroedFlag - This is set to true if the memory in the slot is
509
  /// known to be zero before the assignment into it.  This means that
510
  /// zero fields don't need to be set.
511
  bool ZeroedFlag : 1;
512
513
  /// AliasedFlag - This is set to true if the slot might be aliased
514
  /// and it's not undefined behavior to access it through such an
515
  /// alias.  Note that it's always undefined behavior to access a C++
516
  /// object that's under construction through an alias derived from
517
  /// outside the construction process.
518
  ///
519
  /// This flag controls whether calls that produce the aggregate
520
  /// value may be evaluated directly into the slot, or whether they
521
  /// must be evaluated into an unaliased temporary and then memcpy'ed
522
  /// over.  Since it's invalid in general to memcpy a non-POD C++
523
  /// object, it's important that this flag never be set when
524
  /// evaluating an expression which constructs such an object.
525
  bool AliasedFlag : 1;
526
527
  /// This is set to true if the tail padding of this slot might overlap
528
  /// another object that may have already been initialized (and whose
529
  /// value must be preserved by this initialization). If so, we may only
530
  /// store up to the dsize of the type. Otherwise we can widen stores to
531
  /// the size of the type.
532
  bool OverlapFlag : 1;
533
534
  /// If is set to true, sanitizer checks are already generated for this address
535
  /// or not required. For instance, if this address represents an object
536
  /// created in 'new' expression, sanitizer checks for memory is made as a part
537
  /// of 'operator new' emission and object constructor should not generate
538
  /// them.
539
  bool SanitizerCheckedFlag : 1;
540
541
  AggValueSlot(Address Addr, Qualifiers Quals, bool DestructedFlag,
542
               bool ObjCGCFlag, bool ZeroedFlag, bool AliasedFlag,
543
               bool OverlapFlag, bool SanitizerCheckedFlag)
544
      : Addr(Addr), Quals(Quals), DestructedFlag(DestructedFlag),
545
        ObjCGCFlag(ObjCGCFlag), ZeroedFlag(ZeroedFlag),
546
        AliasedFlag(AliasedFlag), OverlapFlag(OverlapFlag),
547
1.05M
        SanitizerCheckedFlag(SanitizerCheckedFlag) {}
548
549
public:
550
  enum IsAliased_t { IsNotAliased, IsAliased };
551
  enum IsDestructed_t { IsNotDestructed, IsDestructed };
552
  enum IsZeroed_t { IsNotZeroed, IsZeroed };
553
  enum Overlap_t { DoesNotOverlap, MayOverlap };
554
  enum NeedsGCBarriers_t { DoesNotNeedGCBarriers, NeedsGCBarriers };
555
  enum IsSanitizerChecked_t { IsNotSanitizerChecked, IsSanitizerChecked };
556
557
  /// ignored - Returns an aggregate value slot indicating that the
558
  /// aggregate value is being ignored.
559
986k
  static AggValueSlot ignored() {
560
986k
    return forAddr(Address::invalid(), Qualifiers(), IsNotDestructed,
561
986k
                   DoesNotNeedGCBarriers, IsNotAliased, DoesNotOverlap);
562
986k
  }
563
564
  /// forAddr - Make a slot for an aggregate value.
565
  ///
566
  /// \param quals - The qualifiers that dictate how the slot should
567
  /// be initialied. Only 'volatile' and the Objective-C lifetime
568
  /// qualifiers matter.
569
  ///
570
  /// \param isDestructed - true if something else is responsible
571
  ///   for calling destructors on this object
572
  /// \param needsGC - true if the slot is potentially located
573
  ///   somewhere that ObjC GC calls should be emitted for
574
  static AggValueSlot forAddr(Address addr,
575
                              Qualifiers quals,
576
                              IsDestructed_t isDestructed,
577
                              NeedsGCBarriers_t needsGC,
578
                              IsAliased_t isAliased,
579
                              Overlap_t mayOverlap,
580
                              IsZeroed_t isZeroed = IsNotZeroed,
581
1.05M
                       IsSanitizerChecked_t isChecked = IsNotSanitizerChecked) {
582
1.05M
    return AggValueSlot(addr, quals, isDestructed, needsGC, isZeroed, isAliased,
583
1.05M
                        mayOverlap, isChecked);
584
1.05M
  }
585
586
  static AggValueSlot
587
  forLValue(const LValue &LV, CodeGenFunction &CGF, IsDestructed_t isDestructed,
588
            NeedsGCBarriers_t needsGC, IsAliased_t isAliased,
589
            Overlap_t mayOverlap, IsZeroed_t isZeroed = IsNotZeroed,
590
29.9k
            IsSanitizerChecked_t isChecked = IsNotSanitizerChecked) {
591
29.9k
    return forAddr(LV.getAddress(CGF), LV.getQuals(), isDestructed, needsGC,
592
29.9k
                   isAliased, mayOverlap, isZeroed, isChecked);
593
29.9k
  }
594
595
22.9k
  IsDestructed_t isExternallyDestructed() const {
596
22.9k
    return IsDestructed_t(DestructedFlag);
597
22.9k
  }
598
7.81k
  void setExternallyDestructed(bool destructed = true) {
599
7.81k
    DestructedFlag = destructed;
600
7.81k
  }
601
602
44.6k
  Qualifiers getQualifiers() const { return Quals; }
603
604
111k
  bool isVolatile() const {
605
111k
    return Quals.hasVolatile();
606
111k
  }
607
608
7
  void setVolatile(bool flag) {
609
7
    if (flag)
610
7
      Quals.addVolatile();
611
0
    else
612
0
      Quals.removeVolatile();
613
7
  }
614
615
0
  Qualifiers::ObjCLifetime getObjCLifetime() const {
616
0
    return Quals.getObjCLifetime();
617
0
  }
618
619
10.4k
  NeedsGCBarriers_t requiresGCollection() const {
620
10.4k
    return NeedsGCBarriers_t(ObjCGCFlag);
621
10.4k
  }
622
623
178
  llvm::Value *getPointer() const {
624
178
    return Addr.getPointer();
625
178
  }
626
627
258k
  Address getAddress() const {
628
258k
    return Addr;
629
258k
  }
630
631
257k
  bool isIgnored() const {
632
257k
    return !Addr.isValid();
633
257k
  }
634
635
0
  CharUnits getAlignment() const {
636
0
    return Addr.getAlignment();
637
0
  }
638
639
8.22k
  IsAliased_t isPotentiallyAliased() const {
640
8.22k
    return IsAliased_t(AliasedFlag);
641
8.22k
  }
642
643
75.0k
  Overlap_t mayOverlap() const {
644
75.0k
    return Overlap_t(OverlapFlag);
645
75.0k
  }
646
647
39.5k
  bool isSanitizerChecked() const {
648
39.5k
    return SanitizerCheckedFlag;
649
39.5k
  }
650
651
12.0k
  RValue asRValue() const {
652
12.0k
    if (isIgnored()) {
653
1.49k
      return RValue::getIgnored();
654
10.5k
    } else {
655
10.5k
      return RValue::getAggregate(getAddress(), isVolatile());
656
10.5k
    }
657
12.0k
  }
658
659
69
  void setZeroed(bool V = true) { ZeroedFlag = V; }
660
102k
  IsZeroed_t isZeroed() const {
661
102k
    return IsZeroed_t(ZeroedFlag);
662
102k
  }
663
664
  /// Get the preferred size to use when storing a value to this slot. This
665
  /// is the type size unless that might overlap another object, in which
666
  /// case it's the dsize.
667
27.2k
  CharUnits getPreferredSize(ASTContext &Ctx, QualType Type) const {
668
27.2k
    return mayOverlap() ? 
Ctx.getTypeInfoDataSizeInChars(Type).Width7.30k
669
27.2k
                        : 
Ctx.getTypeSizeInChars(Type)19.9k
;
670
27.2k
  }
671
};
672
673
}  // end namespace CodeGen
674
}  // end namespace clang
675
676
#endif