clang 19.0.0git
CodeGenTBAA.cpp
Go to the documentation of this file.
1//===-- CodeGenTBAA.cpp - TBAA information for LLVM CodeGen ---------------===//
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// This is the code that manages TBAA information and defines the TBAA policy
10// for the optimizer to use. Relevant standards text includes:
11//
12// C99 6.5p7
13// C++ [basic.lval] (p10 in n3126, p15 in some earlier versions)
14//
15//===----------------------------------------------------------------------===//
16
17#include "CodeGenTBAA.h"
18#include "CGRecordLayout.h"
19#include "CodeGenTypes.h"
21#include "clang/AST/Attr.h"
22#include "clang/AST/Mangle.h"
25#include "llvm/ADT/SmallSet.h"
26#include "llvm/IR/Constants.h"
27#include "llvm/IR/LLVMContext.h"
28#include "llvm/IR/Metadata.h"
29#include "llvm/IR/Module.h"
30#include "llvm/IR/Type.h"
31#include "llvm/Support/Debug.h"
32using namespace clang;
33using namespace CodeGen;
34
36 llvm::Module &M, const CodeGenOptions &CGO,
37 const LangOptions &Features, MangleContext &MContext)
38 : Context(Ctx), CGTypes(CGTypes), Module(M), CodeGenOpts(CGO),
39 Features(Features), MContext(MContext), MDHelper(M.getContext()),
40 Root(nullptr), Char(nullptr) {}
41
43}
44
45llvm::MDNode *CodeGenTBAA::getRoot() {
46 // Define the root of the tree. This identifies the tree, so that
47 // if our LLVM IR is linked with LLVM IR from a different front-end
48 // (or a different version of this front-end), their TBAA trees will
49 // remain distinct, and the optimizer will treat them conservatively.
50 if (!Root) {
51 if (Features.CPlusPlus)
52 Root = MDHelper.createTBAARoot("Simple C++ TBAA");
53 else
54 Root = MDHelper.createTBAARoot("Simple C/C++ TBAA");
55 }
56
57 return Root;
58}
59
60llvm::MDNode *CodeGenTBAA::createScalarTypeNode(StringRef Name,
61 llvm::MDNode *Parent,
62 uint64_t Size) {
63 if (CodeGenOpts.NewStructPathTBAA) {
64 llvm::Metadata *Id = MDHelper.createString(Name);
65 return MDHelper.createTBAATypeNode(Parent, Size, Id);
66 }
67 return MDHelper.createTBAAScalarTypeNode(Name, Parent);
68}
69
70llvm::MDNode *CodeGenTBAA::getChar() {
71 // Define the root of the tree for user-accessible memory. C and C++
72 // give special powers to char and certain similar types. However,
73 // these special powers only cover user-accessible memory, and doesn't
74 // include things like vtables.
75 if (!Char)
76 Char = createScalarTypeNode("omnipotent char", getRoot(), /* Size= */ 1);
77
78 return Char;
79}
80
81static bool TypeHasMayAlias(QualType QTy) {
82 // Tagged types have declarations, and therefore may have attributes.
83 if (auto *TD = QTy->getAsTagDecl())
84 if (TD->hasAttr<MayAliasAttr>())
85 return true;
86
87 // Also look for may_alias as a declaration attribute on a typedef.
88 // FIXME: We should follow GCC and model may_alias as a type attribute
89 // rather than as a declaration attribute.
90 while (auto *TT = QTy->getAs<TypedefType>()) {
91 if (TT->getDecl()->hasAttr<MayAliasAttr>())
92 return true;
93 QTy = TT->desugar();
94 }
95 return false;
96}
97
98/// Check if the given type is a valid base type to be used in access tags.
99static bool isValidBaseType(QualType QTy) {
100 if (QTy->isReferenceType())
101 return false;
102 if (const RecordType *TTy = QTy->getAs<RecordType>()) {
103 const RecordDecl *RD = TTy->getDecl()->getDefinition();
104 // Incomplete types are not valid base access types.
105 if (!RD)
106 return false;
107 if (RD->hasFlexibleArrayMember())
108 return false;
109 // RD can be struct, union, class, interface or enum.
110 // For now, we only handle struct and class.
111 if (RD->isStruct() || RD->isClass())
112 return true;
113 }
114 return false;
115}
116
117llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type *Ty) {
119
120 // Handle builtin types.
121 if (const BuiltinType *BTy = dyn_cast<BuiltinType>(Ty)) {
122 switch (BTy->getKind()) {
123 // Character types are special and can alias anything.
124 // In C++, this technically only includes "char" and "unsigned char",
125 // and not "signed char". In C, it includes all three. For now,
126 // the risk of exploiting this detail in C++ seems likely to outweigh
127 // the benefit.
128 case BuiltinType::Char_U:
129 case BuiltinType::Char_S:
130 case BuiltinType::UChar:
131 case BuiltinType::SChar:
132 return getChar();
133
134 // Unsigned types can alias their corresponding signed types.
135 case BuiltinType::UShort:
136 return getTypeInfo(Context.ShortTy);
137 case BuiltinType::UInt:
138 return getTypeInfo(Context.IntTy);
139 case BuiltinType::ULong:
140 return getTypeInfo(Context.LongTy);
141 case BuiltinType::ULongLong:
142 return getTypeInfo(Context.LongLongTy);
143 case BuiltinType::UInt128:
144 return getTypeInfo(Context.Int128Ty);
145
146 case BuiltinType::UShortFract:
147 return getTypeInfo(Context.ShortFractTy);
148 case BuiltinType::UFract:
149 return getTypeInfo(Context.FractTy);
150 case BuiltinType::ULongFract:
151 return getTypeInfo(Context.LongFractTy);
152
153 case BuiltinType::SatUShortFract:
154 return getTypeInfo(Context.SatShortFractTy);
155 case BuiltinType::SatUFract:
156 return getTypeInfo(Context.SatFractTy);
157 case BuiltinType::SatULongFract:
158 return getTypeInfo(Context.SatLongFractTy);
159
160 case BuiltinType::UShortAccum:
161 return getTypeInfo(Context.ShortAccumTy);
162 case BuiltinType::UAccum:
163 return getTypeInfo(Context.AccumTy);
164 case BuiltinType::ULongAccum:
165 return getTypeInfo(Context.LongAccumTy);
166
167 case BuiltinType::SatUShortAccum:
168 return getTypeInfo(Context.SatShortAccumTy);
169 case BuiltinType::SatUAccum:
170 return getTypeInfo(Context.SatAccumTy);
171 case BuiltinType::SatULongAccum:
172 return getTypeInfo(Context.SatLongAccumTy);
173
174 // Treat all other builtin types as distinct types. This includes
175 // treating wchar_t, char16_t, and char32_t as distinct from their
176 // "underlying types".
177 default:
178 return createScalarTypeNode(BTy->getName(Features), getChar(), Size);
179 }
180 }
181
182 // C++1z [basic.lval]p10: "If a program attempts to access the stored value of
183 // an object through a glvalue of other than one of the following types the
184 // behavior is undefined: [...] a char, unsigned char, or std::byte type."
185 if (Ty->isStdByteType())
186 return getChar();
187
188 // Handle pointers and references.
189 // TODO: Implement C++'s type "similarity" and consider dis-"similar"
190 // pointers distinct.
191 if (Ty->isPointerType() || Ty->isReferenceType())
192 return createScalarTypeNode("any pointer", getChar(), Size);
193
194 // Accesses to arrays are accesses to objects of their element types.
195 if (CodeGenOpts.NewStructPathTBAA && Ty->isArrayType())
196 return getTypeInfo(cast<ArrayType>(Ty)->getElementType());
197
198 // Enum types are distinct types. In C++ they have "underlying types",
199 // however they aren't related for TBAA.
200 if (const EnumType *ETy = dyn_cast<EnumType>(Ty)) {
201 if (!Features.CPlusPlus)
202 return getTypeInfo(ETy->getDecl()->getIntegerType());
203
204 // In C++ mode, types have linkage, so we can rely on the ODR and
205 // on their mangled names, if they're external.
206 // TODO: Is there a way to get a program-wide unique name for a
207 // decl with local linkage or no linkage?
208 if (!ETy->getDecl()->isExternallyVisible())
209 return getChar();
210
211 SmallString<256> OutName;
212 llvm::raw_svector_ostream Out(OutName);
213 MContext.mangleCanonicalTypeName(QualType(ETy, 0), Out);
214 return createScalarTypeNode(OutName, getChar(), Size);
215 }
216
217 if (const auto *EIT = dyn_cast<BitIntType>(Ty)) {
218 SmallString<256> OutName;
219 llvm::raw_svector_ostream Out(OutName);
220 // Don't specify signed/unsigned since integer types can alias despite sign
221 // differences.
222 Out << "_BitInt(" << EIT->getNumBits() << ')';
223 return createScalarTypeNode(OutName, getChar(), Size);
224 }
225
226 // For now, handle any other kind of type conservatively.
227 return getChar();
228}
229
231 // At -O0 or relaxed aliasing, TBAA is not emitted for regular types.
232 if (CodeGenOpts.OptimizationLevel == 0 || CodeGenOpts.RelaxedAliasing)
233 return nullptr;
234
235 // If the type has the may_alias attribute (even on a typedef), it is
236 // effectively in the general char alias class.
237 if (TypeHasMayAlias(QTy))
238 return getChar();
239
240 // We need this function to not fall back to returning the "omnipotent char"
241 // type node for aggregate and union types. Otherwise, any dereference of an
242 // aggregate will result into the may-alias access descriptor, meaning all
243 // subsequent accesses to direct and indirect members of that aggregate will
244 // be considered may-alias too.
245 // TODO: Combine getTypeInfo() and getBaseTypeInfo() into a single function.
246 if (isValidBaseType(QTy))
247 return getBaseTypeInfo(QTy);
248
249 const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
250 if (llvm::MDNode *N = MetadataCache[Ty])
251 return N;
252
253 // Note that the following helper call is allowed to add new nodes to the
254 // cache, which invalidates all its previously obtained iterators. So we
255 // first generate the node for the type and then add that node to the cache.
256 llvm::MDNode *TypeNode = getTypeInfoHelper(Ty);
257 return MetadataCache[Ty] = TypeNode;
258}
259
261 // Pointee values may have incomplete types, but they shall never be
262 // dereferenced.
263 if (AccessType->isIncompleteType())
265
266 if (TypeHasMayAlias(AccessType))
268
269 uint64_t Size = Context.getTypeSizeInChars(AccessType).getQuantity();
270 return TBAAAccessInfo(getTypeInfo(AccessType), Size);
271}
272
274 llvm::DataLayout DL(&Module);
275 unsigned Size = DL.getPointerTypeSize(VTablePtrType);
276 return TBAAAccessInfo(createScalarTypeNode("vtable pointer", getRoot(), Size),
277 Size);
278}
279
280bool
281CodeGenTBAA::CollectFields(uint64_t BaseOffset,
282 QualType QTy,
284 Fields,
285 bool MayAlias) {
286 /* Things not handled yet include: C++ base classes, bitfields, */
287
288 if (const RecordType *TTy = QTy->getAs<RecordType>()) {
289 if (TTy->isUnionType()) {
290 uint64_t Size = Context.getTypeSizeInChars(QTy).getQuantity();
291 llvm::MDNode *TBAAType = getChar();
292 llvm::MDNode *TBAATag = getAccessTagInfo(TBAAAccessInfo(TBAAType, Size));
293 Fields.push_back(
294 llvm::MDBuilder::TBAAStructField(BaseOffset, Size, TBAATag));
295 return true;
296 }
297 const RecordDecl *RD = TTy->getDecl()->getDefinition();
298 if (RD->hasFlexibleArrayMember())
299 return false;
300
301 // TODO: Handle C++ base classes.
302 if (const CXXRecordDecl *Decl = dyn_cast<CXXRecordDecl>(RD))
303 if (Decl->bases_begin() != Decl->bases_end())
304 return false;
305
306 const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
307 const CGRecordLayout &CGRL = CGTypes.getCGRecordLayout(RD);
308
309 unsigned idx = 0;
310 for (RecordDecl::field_iterator i = RD->field_begin(), e = RD->field_end();
311 i != e; ++i, ++idx) {
312 if ((*i)->isZeroSize(Context))
313 continue;
314
315 uint64_t Offset =
316 BaseOffset + Layout.getFieldOffset(idx) / Context.getCharWidth();
317
318 // Create a single field for consecutive named bitfields using char as
319 // base type.
320 if ((*i)->isBitField()) {
321 const CGBitFieldInfo &Info = CGRL.getBitFieldInfo(*i);
322 if (Info.Offset != 0)
323 continue;
324 unsigned CurrentBitFieldSize = Info.StorageSize;
325 uint64_t Size =
326 llvm::divideCeil(CurrentBitFieldSize, Context.getCharWidth());
327 llvm::MDNode *TBAAType = getChar();
328 llvm::MDNode *TBAATag =
329 getAccessTagInfo(TBAAAccessInfo(TBAAType, Size));
330 Fields.push_back(
331 llvm::MDBuilder::TBAAStructField(Offset, Size, TBAATag));
332 continue;
333 }
334
335 QualType FieldQTy = i->getType();
336 if (!CollectFields(Offset, FieldQTy, Fields,
337 MayAlias || TypeHasMayAlias(FieldQTy)))
338 return false;
339 }
340 return true;
341 }
342
343 /* Otherwise, treat whatever it is as a field. */
344 uint64_t Offset = BaseOffset;
346 llvm::MDNode *TBAAType = MayAlias ? getChar() : getTypeInfo(QTy);
347 llvm::MDNode *TBAATag = getAccessTagInfo(TBAAAccessInfo(TBAAType, Size));
348 Fields.push_back(llvm::MDBuilder::TBAAStructField(Offset, Size, TBAATag));
349 return true;
350}
351
352llvm::MDNode *
354 if (CodeGenOpts.OptimizationLevel == 0 || CodeGenOpts.RelaxedAliasing)
355 return nullptr;
356
357 const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
358
359 if (llvm::MDNode *N = StructMetadataCache[Ty])
360 return N;
361
363 if (CollectFields(0, QTy, Fields, TypeHasMayAlias(QTy)))
364 return MDHelper.createTBAAStructNode(Fields);
365
366 // For now, handle any other kind of type conservatively.
367 return StructMetadataCache[Ty] = nullptr;
368}
369
370llvm::MDNode *CodeGenTBAA::getBaseTypeInfoHelper(const Type *Ty) {
371 if (auto *TTy = dyn_cast<RecordType>(Ty)) {
372 const RecordDecl *RD = TTy->getDecl()->getDefinition();
373 const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
374 using TBAAStructField = llvm::MDBuilder::TBAAStructField;
376 if (const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
377 // Handle C++ base classes. Non-virtual bases can treated a kind of
378 // field. Virtual bases are more complex and omitted, but avoid an
379 // incomplete view for NewStructPathTBAA.
380 if (CodeGenOpts.NewStructPathTBAA && CXXRD->getNumVBases() != 0)
381 return nullptr;
382 for (const CXXBaseSpecifier &B : CXXRD->bases()) {
383 if (B.isVirtual())
384 continue;
385 QualType BaseQTy = B.getType();
386 const CXXRecordDecl *BaseRD = BaseQTy->getAsCXXRecordDecl();
387 if (BaseRD->isEmpty())
388 continue;
389 llvm::MDNode *TypeNode = isValidBaseType(BaseQTy)
390 ? getBaseTypeInfo(BaseQTy)
391 : getTypeInfo(BaseQTy);
392 if (!TypeNode)
393 return nullptr;
394 uint64_t Offset = Layout.getBaseClassOffset(BaseRD).getQuantity();
395 uint64_t Size =
396 Context.getASTRecordLayout(BaseRD).getDataSize().getQuantity();
397 Fields.push_back(
398 llvm::MDBuilder::TBAAStructField(Offset, Size, TypeNode));
399 }
400 // The order in which base class subobjects are allocated is unspecified,
401 // so may differ from declaration order. In particular, Itanium ABI will
402 // allocate a primary base first.
403 // Since we exclude empty subobjects, the objects are not overlapping and
404 // their offsets are unique.
405 llvm::sort(Fields,
406 [](const TBAAStructField &A, const TBAAStructField &B) {
407 return A.Offset < B.Offset;
408 });
409 }
410 for (FieldDecl *Field : RD->fields()) {
411 if (Field->isZeroSize(Context) || Field->isUnnamedBitfield())
412 continue;
413 QualType FieldQTy = Field->getType();
414 llvm::MDNode *TypeNode = isValidBaseType(FieldQTy) ?
415 getBaseTypeInfo(FieldQTy) : getTypeInfo(FieldQTy);
416 if (!TypeNode)
417 return nullptr;
418
419 uint64_t BitOffset = Layout.getFieldOffset(Field->getFieldIndex());
420 uint64_t Offset = Context.toCharUnitsFromBits(BitOffset).getQuantity();
421 uint64_t Size = Context.getTypeSizeInChars(FieldQTy).getQuantity();
422 Fields.push_back(llvm::MDBuilder::TBAAStructField(Offset, Size,
423 TypeNode));
424 }
425
426 SmallString<256> OutName;
427 if (Features.CPlusPlus) {
428 // Don't use the mangler for C code.
429 llvm::raw_svector_ostream Out(OutName);
430 MContext.mangleCanonicalTypeName(QualType(Ty, 0), Out);
431 } else {
432 OutName = RD->getName();
433 }
434
435 if (CodeGenOpts.NewStructPathTBAA) {
436 llvm::MDNode *Parent = getChar();
438 llvm::Metadata *Id = MDHelper.createString(OutName);
439 return MDHelper.createTBAATypeNode(Parent, Size, Id, Fields);
440 }
441
442 // Create the struct type node with a vector of pairs (offset, type).
444 for (const auto &Field : Fields)
445 OffsetsAndTypes.push_back(std::make_pair(Field.Type, Field.Offset));
446 return MDHelper.createTBAAStructTypeNode(OutName, OffsetsAndTypes);
447 }
448
449 return nullptr;
450}
451
453 if (!isValidBaseType(QTy))
454 return nullptr;
455
456 const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
457
458 // nullptr is a valid value in the cache, so use find rather than []
459 auto I = BaseTypeMetadataCache.find(Ty);
460 if (I != BaseTypeMetadataCache.end())
461 return I->second;
462
463 // First calculate the metadata, before recomputing the insertion point, as
464 // the helper can recursively call us.
465 llvm::MDNode *TypeNode = getBaseTypeInfoHelper(Ty);
466 LLVM_ATTRIBUTE_UNUSED auto inserted =
467 BaseTypeMetadataCache.insert({Ty, TypeNode});
468 assert(inserted.second && "BaseType metadata was already inserted");
469
470 return TypeNode;
471}
472
474 assert(!Info.isIncomplete() && "Access to an object of an incomplete type!");
475
476 if (Info.isMayAlias())
477 Info = TBAAAccessInfo(getChar(), Info.Size);
478
479 if (!Info.AccessType)
480 return nullptr;
481
482 if (!CodeGenOpts.StructPathTBAA)
483 Info = TBAAAccessInfo(Info.AccessType, Info.Size);
484
485 llvm::MDNode *&N = AccessTagMetadataCache[Info];
486 if (N)
487 return N;
488
489 if (!Info.BaseType) {
490 Info.BaseType = Info.AccessType;
491 assert(!Info.Offset && "Nonzero offset for an access with no base type!");
492 }
493 if (CodeGenOpts.NewStructPathTBAA) {
494 return N = MDHelper.createTBAAAccessTag(Info.BaseType, Info.AccessType,
495 Info.Offset, Info.Size);
496 }
497 return N = MDHelper.createTBAAStructTagNode(Info.BaseType, Info.AccessType,
498 Info.Offset);
499}
500
503 if (SourceInfo.isMayAlias() || TargetInfo.isMayAlias())
505 return TargetInfo;
506}
507
510 TBAAAccessInfo InfoB) {
511 if (InfoA == InfoB)
512 return InfoA;
513
514 if (!InfoA || !InfoB)
515 return TBAAAccessInfo();
516
517 if (InfoA.isMayAlias() || InfoB.isMayAlias())
519
520 // TODO: Implement the rest of the logic here. For example, two accesses
521 // with same final access types result in an access to an object of that final
522 // access type regardless of their base types.
524}
525
528 TBAAAccessInfo SrcInfo) {
529 if (DestInfo == SrcInfo)
530 return DestInfo;
531
532 if (!DestInfo || !SrcInfo)
533 return TBAAAccessInfo();
534
535 if (DestInfo.isMayAlias() || SrcInfo.isMayAlias())
537
538 // TODO: Implement the rest of the logic here. For example, two accesses
539 // with same final access types result in an access to an object of that final
540 // access type regardless of their base types.
542}
Defines the clang::ASTContext interface.
NodeId Parent
Definition: ASTDiff.cpp:191
int Id
Definition: ASTDiff.cpp:190
static bool TypeHasMayAlias(QualType QTy)
Definition: CodeGenTBAA.cpp:81
static bool isValidBaseType(QualType QTy)
Check if the given type is a valid base type to be used in access tags.
Definition: CodeGenTBAA.cpp:99
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:182
CanQualType AccumTy
Definition: ASTContext.h:1099
CanQualType LongTy
Definition: ASTContext.h:1095
CanQualType Int128Ty
Definition: ASTContext.h:1095
CanQualType SatAccumTy
Definition: ASTContext.h:1104
CanQualType ShortAccumTy
Definition: ASTContext.h:1099
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D,...
CanQualType getCanonicalType(QualType T) const
Return the canonical (structural) type corresponding to the specified potentially non-canonical type ...
Definition: ASTContext.h:2549
CanQualType SatLongAccumTy
Definition: ASTContext.h:1104
CanQualType SatShortFractTy
Definition: ASTContext.h:1107
CanQualType ShortFractTy
Definition: ASTContext.h:1102
CanQualType IntTy
Definition: ASTContext.h:1095
CharUnits getTypeSizeInChars(QualType T) const
Return the size of the specified (complete) type T, in characters.
CanQualType ShortTy
Definition: ASTContext.h:1095
CanQualType FractTy
Definition: ASTContext.h:1102
CanQualType LongAccumTy
Definition: ASTContext.h:1100
CanQualType SatFractTy
Definition: ASTContext.h:1107
CanQualType SatLongFractTy
Definition: ASTContext.h:1107
CanQualType LongFractTy
Definition: ASTContext.h:1102
CanQualType SatShortAccumTy
Definition: ASTContext.h:1104
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
CanQualType LongLongTy
Definition: ASTContext.h:1095
uint64_t getCharWidth() const
Return the size of the character type, in bits.
Definition: ASTContext.h:2319
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
Definition: RecordLayout.h:38
uint64_t getFieldOffset(unsigned FieldNo) const
getFieldOffset - Get the offset of the given field index, in bits.
Definition: RecordLayout.h:200
CharUnits getDataSize() const
getDataSize() - Get the record data size, which is the record size without tail padding,...
Definition: RecordLayout.h:206
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
Definition: RecordLayout.h:249
This class is used for builtin types like 'int'.
Definition: Type.h:2740
Represents a base class of a C++ class.
Definition: DeclCXX.h:146
Represents a C++ struct/union/class.
Definition: DeclCXX.h:258
bool isEmpty() const
Determine whether this is an empty class in the sense of (C++11 [meta.unary.prop]).
Definition: DeclCXX.h:1189
const T * getTypePtr() const
Retrieve the underlying type pointer, which refers to a canonical type.
Definition: CanonicalType.h:83
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
Definition: CharUnits.h:185
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
CGRecordLayout - This class handles struct and union layout info while lowering AST types to LLVM typ...
const CGBitFieldInfo & getBitFieldInfo(const FieldDecl *FD) const
Return the BitFieldInfo that corresponds to the field FD.
llvm::MDNode * getBaseTypeInfo(QualType QTy)
getBaseTypeInfo - Get metadata that describes the given base access type.
llvm::MDNode * getTypeInfo(QualType QTy)
getTypeInfo - Get metadata used to describe accesses to objects of the given type.
TBAAAccessInfo getVTablePtrAccessInfo(llvm::Type *VTablePtrType)
getVTablePtrAccessInfo - Get the TBAA information that describes an access to a virtual table pointer...
TBAAAccessInfo mergeTBAAInfoForMemoryTransfer(TBAAAccessInfo DestInfo, TBAAAccessInfo SrcInfo)
mergeTBAAInfoForMemoryTransfer - Get merged TBAA information for the purpose of memory transfer calls...
TBAAAccessInfo mergeTBAAInfoForCast(TBAAAccessInfo SourceInfo, TBAAAccessInfo TargetInfo)
mergeTBAAInfoForCast - Get merged TBAA information for the purpose of type casts.
TBAAAccessInfo mergeTBAAInfoForConditionalOperator(TBAAAccessInfo InfoA, TBAAAccessInfo InfoB)
mergeTBAAInfoForConditionalOperator - Get merged TBAA information for the purpose of conditional oper...
llvm::MDNode * getAccessTagInfo(TBAAAccessInfo Info)
getAccessTagInfo - Get TBAA tag for a given memory access.
llvm::MDNode * getTBAAStructInfo(QualType QTy)
getTBAAStructInfo - Get the TBAAStruct MDNode to be used for a memcpy of the given type.
CodeGenTBAA(ASTContext &Ctx, CodeGenTypes &CGTypes, llvm::Module &M, const CodeGenOptions &CGO, const LangOptions &Features, MangleContext &MContext)
Definition: CodeGenTBAA.cpp:35
TBAAAccessInfo getAccessInfo(QualType AccessType)
getAccessInfo - Get TBAA information that describes an access to an object of the given type.
This class organizes the cross-module state that is used while lowering AST types to LLVM types.
Definition: CodeGenTypes.h:54
const CGRecordLayout & getCGRecordLayout(const RecordDecl *)
getCGRecordLayout - Return record layout info for the given record decl.
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext,...
Definition: DeclBase.h:2352
Decl - This represents one declaration (or definition), e.g.
Definition: DeclBase.h:85
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
Definition: Type.h:5118
Represents a member of a struct/union/class.
Definition: Decl.h:3025
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:418
MangleContext - Context for tracking state which persists across multiple calls to the C++ name mangl...
Definition: Mangle.h:45
virtual void mangleCanonicalTypeName(QualType T, raw_ostream &, bool NormalizeIntegers=false)=0
Generates a unique string for an externally visible type for use with TBAA or type uniquing.
Describes a module or submodule.
Definition: Module.h:105
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
Definition: Decl.h:276
A (possibly-)qualified type.
Definition: Type.h:737
Represents a struct/union/class.
Definition: Decl.h:4133
bool hasFlexibleArrayMember() const
Definition: Decl.h:4166
field_iterator field_end() const
Definition: Decl.h:4342
field_range fields() const
Definition: Decl.h:4339
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
Definition: Decl.h:4324
field_iterator field_begin() const
Definition: Decl.cpp:5035
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Definition: Type.h:5092
bool isStruct() const
Definition: Decl.h:3752
bool isClass() const
Definition: Decl.h:3754
Exposes information about the current target.
Definition: TargetInfo.h:213
The base class of the type hierarchy.
Definition: Type.h:1606
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Definition: Type.cpp:1819
bool isArrayType() const
Definition: Type.h:7220
bool isPointerType() const
Definition: Type.h:7154
bool isReferenceType() const
Definition: Type.h:7166
bool isStdByteType() const
Definition: Type.cpp:3016
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
Definition: Type.cpp:2299
const T * getAs() const
Member-template getAs<specific type>'.
Definition: Type.h:7657
TagDecl * getAsTagDecl() const
Retrieves the TagDecl that this type refers to, either because the type is a TagType or because it is...
Definition: Type.cpp:1827
The JSON file list parser is used to communicate input to InstallAPI.
unsigned long uint64_t
Structure with information about how a bitfield should be accessed.
unsigned Offset
The offset within a contiguous run of bitfields that are represented as a single "field" within the L...
unsigned StorageSize
The storage size in bits which should be used when accessing this bitfield.
llvm::MDNode * AccessType
AccessType - The final access type.
Definition: CodeGenTBAA.h:105
uint64_t Offset
Offset - The byte offset of the final access within the base one.
Definition: CodeGenTBAA.h:109
static TBAAAccessInfo getMayAliasInfo()
Definition: CodeGenTBAA.h:63
uint64_t Size
Size - The size of access, in bytes.
Definition: CodeGenTBAA.h:112
static TBAAAccessInfo getIncompleteInfo()
Definition: CodeGenTBAA.h:71
llvm::MDNode * BaseType
BaseType - The base/leading access type.
Definition: CodeGenTBAA.h:101