clang: lib/CodeGen/CGValue.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef LLVM_CLANG_LIB_CODEGEN_CGVALUE_H
15#define LLVM_CLANG_LIB_CODEGEN_CGVALUE_H
16
23#include "llvm/IR/Type.h"
24#include "llvm/IR/Value.h"
25
26namespace llvm {
27 class Constant;
28 class MDNode;
29}
30
32namespace CodeGen {
33class AggValueSlot;
34class CGBuilderTy;
35class CodeGenFunction;
36struct CGBitFieldInfo;
37
38
39
40
41
44
45 enum FlavorEnum { Scalar, Complex, Aggregate };
46
47 union {
48
49 struct {
52 } Vals;
53
54
56 };
57
58 unsigned IsVolatile : 1;
59 unsigned Flavor : 2;
60
61public:
62 RValue() : Vals{nullptr, nullptr}, Flavor(Scalar) {}
63
64 bool isScalar() const { return Flavor == Scalar; }
65 bool isComplex() const { return Flavor == Complex; }
66 bool isAggregate() const { return Flavor == Aggregate; }
67
69
70
72 assert(isScalar() && "Not a scalar!");
73 return Vals.first;
74 }
75
76
77
78 std::pair<llvm::Value *, llvm::Value *> getComplexVal() const {
79 return std::make_pair(Vals.first, Vals.second);
80 }
81
82
84 assert(isAggregate() && "Not an aggregate!");
86 }
87
91 }
92
94
95 return get(nullptr);
96 }
97
101 ER.Flavor = Scalar;
102 ER.IsVolatile = false;
103 return ER;
104 }
107 }
110 ER.Vals = {V1, V2};
111 ER.Flavor = Complex;
112 ER.IsVolatile = false;
113 return ER;
114 }
117 }
118
119
120
121
122
123
124
128 ER.Flavor = Aggregate;
129 ER.IsVolatile = isVolatile;
130 return ER;
131 }
132};
133
134
138
139
140
142
143
144
146
147
148
149
151
152
153
155};
156
157
158
160
161
163}
164
167
168public:
170 : AlignSource(Source) {}
173
176 }
177};
178
179
180
181
183 enum {
184 Simple,
185 VectorElt,
186 BitField,
187 ExtVectorElt,
188 GlobalReg,
189 MatrixElt
190 } LVType;
191
192 union {
195 };
196
197 union {
198
200
201
203
204
206 };
207
209
210
212
213
214 bool Ivar:1;
215
216
217 bool ObjIsArray:1;
218
219
220
221 bool NonGC: 1;
222
223
224 bool GlobalObjCRef : 1;
225
226
227 bool ThreadLocalRef : 1;
228
229
230
231 bool ImpreciseLifetime : 1;
232
233
234
235 bool Nontemporal : 1;
236
239
240 Expr *BaseIvarExp;
241
242private:
245 this->Type = Type;
246 this->Quals = Quals;
247 const unsigned MaxAlign = 1U << 31;
250 "initializing l-value with zero alignment!");
251 if (Alignment.getQuantity() > MaxAlign) {
252 assert(false && "Alignment exceeds allowed max!");
254 }
255 this->Addr = Addr;
256 this->BaseInfo = BaseInfo;
257 this->TBAAInfo = TBAAInfo;
258
259
260 this->Ivar = this->ObjIsArray = this->NonGC = this->GlobalObjCRef = false;
261 this->ImpreciseLifetime = false;
262 this->Nontemporal = false;
263 this->ThreadLocalRef = false;
264 this->BaseIvarExp = nullptr;
265 }
266
267 void initializeSimpleLValue(Address Addr, QualType Type,
268 LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo,
269 ASTContext &Context) {
270 Qualifiers QS = Type.getQualifiers();
271 QS.setObjCGCAttr(Context.getObjCGCAttrKind(Type));
272 LVType = Simple;
273 Initialize(Type, QS, Addr, BaseInfo, TBAAInfo);
275 }
276
277public:
278 bool isSimple() const { return LVType == Simple; }
279 bool isVectorElt() const { return LVType == VectorElt; }
280 bool isBitField() const { return LVType == BitField; }
282 bool isGlobalReg() const { return LVType == GlobalReg; }
283 bool isMatrixElt() const { return LVType == MatrixElt; }
284
289 }
290
292
295 }
296
299
302
303 bool isNonGC () const { return NonGC; }
305
308
311
314 }
317 }
320
323 }
326 }
327
330 }
331
334
337
340
342
345
348
352 return *this;
353 }
354
355
360
362
364
367 }
368
369
373 }
377 }
381 }
385 }
386
390 }
394 }
398 }
399
400
404 }
408 }
412 }
413
414
418 }
422 }
423
427 }
428
429
431
435 R.LVType = Simple;
436 R.initializeSimpleLValue(Addr, type, BaseInfo, TBAAInfo, Context);
439 return R;
440 }
441
446 R.LVType = VectorElt;
448 R.Initialize(type, type.getQualifiers(), vecAddress, BaseInfo, TBAAInfo);
449 return R;
450 }
451
456 R.LVType = ExtVectorElt;
458 R.Initialize(type, type.getQualifiers(), Addr, BaseInfo, TBAAInfo);
459 return R;
460 }
461
462
463
464
465
466
467
472 R.LVType = BitField;
474 R.Initialize(type, type.getQualifiers(), Addr, BaseInfo, TBAAInfo);
475 return R;
476 }
477
481 R.LVType = GlobalReg;
485 return R;
486 }
487
492 R.LVType = MatrixElt;
494 R.Initialize(type, type.getQualifiers(), matAddress, BaseInfo, TBAAInfo);
495 return R;
496 }
497
500 }
501};
502
503
505
507
508
510
511
512
513
514 bool DestructedFlag : 1;
515
516
517
518
519 bool ObjCGCFlag : 1;
520
521
522
523
524 bool ZeroedFlag : 1;
525
526
527
528
529
530
531
532
533
534
535
536
537
538 bool AliasedFlag : 1;
539
540
541
542
543
544
545 bool OverlapFlag : 1;
546
547
548
549
550
551
552 bool SanitizerCheckedFlag : 1;
553
555 bool ObjCGCFlag, bool ZeroedFlag, bool AliasedFlag,
556 bool OverlapFlag, bool SanitizerCheckedFlag)
557 : Addr(Addr), Quals(Quals), DestructedFlag(DestructedFlag),
558 ObjCGCFlag(ObjCGCFlag), ZeroedFlag(ZeroedFlag),
559 AliasedFlag(AliasedFlag), OverlapFlag(OverlapFlag),
560 SanitizerCheckedFlag(SanitizerCheckedFlag) {}
561
562public:
569
570
571
575 }
576
577
578
579
580
581
582
583
584
585
586
599 }
600
608 }
609
612 }
614 DestructedFlag = destructed;
615 }
616
618
621 }
622
624 if (flag)
626 else
628 }
629
632 }
633
636 }
637
639
642 }
643
645 return Addr;
646 }
647
649
652 }
653
656 }
657
660 }
661
663 return SanitizerCheckedFlag;
664 }
665
669 } else {
671 }
672 }
673
677 }
678
679
680
681
685 }
686};
687
688}
689}
690
691#endif
Defines the clang::ASTContext interface.
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
TypeInfoChars getTypeInfoDataSizeInChars(QualType T) const
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
CharUnits - This is an opaque type for sizes expressed in character units.
bool isZero() const
isZero - Test whether the quantity equals zero.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
Like RawAddress, an abstract representation of an aligned address, but the pointer contained in this ...
llvm::Value * getBasePointer() const
llvm::Value * emitRawPointer(CodeGenFunction &CGF) const
Return the pointer contained in this class after authenticating it and adding offset to it if necessa...
CharUnits getAlignment() const
KnownNonNull_t isKnownNonNull() const
Whether the pointer is known not to be null.
Address setKnownNonNull()
void setAlignment(CharUnits Value)
const CGPointerAuthInfo & getPointerAuthInfo() const
llvm::PointerType * getType() const
Return the type of the pointer value.
void setVolatile(bool flag)
static AggValueSlot ignored()
ignored - Returns an aggregate value slot indicating that the aggregate value is being ignored.
bool isSanitizerChecked() const
Address getAddress() const
CharUnits getPreferredSize(ASTContext &Ctx, QualType Type) const
Get the preferred size to use when storing a value to this slot.
CharUnits getAlignment() const
NeedsGCBarriers_t requiresGCollection() const
void setExternallyDestructed(bool destructed=true)
void setZeroed(bool V=true)
llvm::Value * getPointer(QualType PointeeTy, CodeGenFunction &CGF) const
IsZeroed_t isZeroed() const
Qualifiers getQualifiers() const
static AggValueSlot forLValue(const LValue &LV, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed, IsSanitizerChecked_t isChecked=IsNotSanitizerChecked)
IsAliased_t isPotentiallyAliased() const
Qualifiers::ObjCLifetime getObjCLifetime() const
static AggValueSlot forAddr(Address addr, Qualifiers quals, IsDestructed_t isDestructed, NeedsGCBarriers_t needsGC, IsAliased_t isAliased, Overlap_t mayOverlap, IsZeroed_t isZeroed=IsNotZeroed, IsSanitizerChecked_t isChecked=IsNotSanitizerChecked)
forAddr - Make a slot for an aggregate value.
IsDestructed_t isExternallyDestructed() const
Overlap_t mayOverlap() const
llvm::Value * emitRawPointer(CodeGenFunction &CGF) const
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
void setAlignmentSource(AlignmentSource Source)
void mergeForCast(const LValueBaseInfo &Info)
AlignmentSource getAlignmentSource() const
LValueBaseInfo(AlignmentSource Source=AlignmentSource::Type)
LValue - This represents an lvalue references.
llvm::Value * getRawExtVectorPointer(CodeGenFunction &CGF) const
Expr * getBaseIvarExp() const
llvm::Value * emitResignedPointer(QualType PointeeTy, CodeGenFunction &CGF) const
llvm::Constant * getExtVectorElts() const
static LValue MakeGlobalReg(llvm::Value *V, CharUnits alignment, QualType type)
void setObjCIvar(bool Value)
bool isObjCStrong() const
bool isRestrictQualified() const
void setAlignment(CharUnits A)
bool isGlobalObjCRef() const
void setObjCArray(bool Value)
llvm::Value * getMatrixPointer() const
bool isVolatileQualified() const
llvm::Constant * VectorElts
llvm::Value * getRawBitFieldPointer(CodeGenFunction &CGF) const
RValue asAggregateRValue() const
void setTBAAInfo(TBAAAccessInfo Info)
LangAS getAddressSpace() const
CharUnits getAlignment() const
llvm::Value * getPointer(CodeGenFunction &CGF) const
llvm::Value * getMatrixIdx() const
llvm::Value * getGlobalReg() const
static LValue MakeAddr(Address Addr, QualType type, ASTContext &Context, LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo)
const Qualifiers & getQuals() const
static LValue MakeExtVectorElt(Address Addr, llvm::Constant *Elts, QualType type, LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo)
llvm::Value * getVectorPointer() const
Address getAddress() const
unsigned getVRQualifiers() const
void setThreadLocalRef(bool Value)
const CGBitFieldInfo * BitFieldInfo
void setGlobalObjCRef(bool Value)
llvm::Value * getRawVectorPointer(CodeGenFunction &CGF) const
bool isExtVectorElt() const
llvm::Value * getVectorIdx() const
void setNontemporal(bool Value)
LValueBaseInfo getBaseInfo() const
ARCPreciseLifetime_t isARCPreciseLifetime() const
void setARCPreciseLifetime(ARCPreciseLifetime_t value)
const CGBitFieldInfo & getBitFieldInfo() const
CGPointerAuthInfo getPointerAuthInfo() const
bool isThreadLocalRef() const
KnownNonNull_t isKnownNonNull() const
TBAAAccessInfo getTBAAInfo() const
void setNonGC(bool Value)
void setBaseInfo(LValueBaseInfo Info)
Address getVectorAddress() const
bool isNontemporal() const
static LValue MakeBitfield(Address Addr, const CGBitFieldInfo &Info, QualType type, LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo)
Create a new object to represent a bit-field access.
llvm::Value * emitRawPointer(CodeGenFunction &CGF) const
static LValue MakeVectorElt(Address vecAddress, llvm::Value *Idx, QualType type, LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo)
void setAddress(Address address)
Qualifiers::ObjCLifetime getObjCLifetime() const
void setBaseIvarExp(Expr *V)
Address getExtVectorAddress() const
static LValue MakeMatrixElt(Address matAddress, llvm::Value *Idx, QualType type, LValueBaseInfo BaseInfo, TBAAAccessInfo TBAAInfo)
Address getMatrixAddress() const
Address getBitFieldAddress() const
RValue - This trivial value class is used to represent the result of an expression that is evaluated.
llvm::Value * getAggregatePointer(QualType PointeeType, CodeGenFunction &CGF) const
static RValue getIgnored()
static RValue get(llvm::Value *V)
static RValue get(Address Addr, CodeGenFunction &CGF)
static RValue getComplex(const std::pair< llvm::Value *, llvm::Value * > &C)
static RValue getAggregate(Address addr, bool isVolatile=false)
Convert an Address to an RValue.
static RValue getComplex(llvm::Value *V1, llvm::Value *V2)
Address getAggregateAddress() const
getAggregateAddr() - Return the Value* of the address of the aggregate.
llvm::Value * getScalarVal() const
getScalarVal() - Return the Value* of this scalar value.
struct clang::CodeGen::RValue::@315::@317 Vals
bool isVolatileQualified() const
std::pair< llvm::Value *, llvm::Value * > getComplexVal() const
getComplexVal - Return the real/imag components of this complex value.
This represents one expression.
A (possibly-)qualified type.
The collection of all-type qualifiers we support.
unsigned getCVRQualifiers() const
ObjCLifetime getObjCLifetime() const
LangAS getAddressSpace() const
The base class of the type hierarchy.
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
AlignmentSource
The source of the alignment of an l-value; an expression of confidence in the alignment actually matc...
@ AttributedType
The l-value was considered opaque, so the alignment was determined from a type, but that type was an ...
@ Type
The l-value was considered opaque, so the alignment was determined from a type.
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
ARCPreciseLifetime_t
Does an ARC strong l-value have precise lifetime?
static AlignmentSource getFieldAlignmentSource(AlignmentSource Source)
Given that the base address has the given alignment source, what's our confidence in the alignment of...
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
The JSON file list parser is used to communicate input to InstallAPI.
LangAS
Defines the address space values used by the address space qualifier of QualType.
Diagnostic wrappers for TextAPI types for error reporting.
Structure with information about how a bitfield should be accessed.
A metaprogramming class for ensuring that a value will dominate an arbitrary position in a function.