1f4a2713aSLionel Sambuc //===--- CodeGenTypes.cpp - TBAA information for LLVM CodeGen -------------===//
2f4a2713aSLionel Sambuc //
3f4a2713aSLionel Sambuc // The LLVM Compiler Infrastructure
4f4a2713aSLionel Sambuc //
5f4a2713aSLionel Sambuc // This file is distributed under the University of Illinois Open Source
6f4a2713aSLionel Sambuc // License. See LICENSE.TXT for details.
7f4a2713aSLionel Sambuc //
8f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
9f4a2713aSLionel Sambuc //
10f4a2713aSLionel Sambuc // This is the code that manages TBAA information and defines the TBAA policy
11f4a2713aSLionel Sambuc // for the optimizer to use. Relevant standards text includes:
12f4a2713aSLionel Sambuc //
13f4a2713aSLionel Sambuc // C99 6.5p7
14f4a2713aSLionel Sambuc // C++ [basic.lval] (p10 in n3126, p15 in some earlier versions)
15f4a2713aSLionel Sambuc //
16f4a2713aSLionel Sambuc //===----------------------------------------------------------------------===//
17f4a2713aSLionel Sambuc
18f4a2713aSLionel Sambuc #include "CodeGenTBAA.h"
19f4a2713aSLionel Sambuc #include "clang/AST/ASTContext.h"
20f4a2713aSLionel Sambuc #include "clang/AST/Attr.h"
21f4a2713aSLionel Sambuc #include "clang/AST/Mangle.h"
22f4a2713aSLionel Sambuc #include "clang/AST/RecordLayout.h"
23f4a2713aSLionel Sambuc #include "clang/Frontend/CodeGenOptions.h"
24f4a2713aSLionel Sambuc #include "llvm/ADT/SmallSet.h"
25f4a2713aSLionel Sambuc #include "llvm/IR/Constants.h"
26f4a2713aSLionel Sambuc #include "llvm/IR/LLVMContext.h"
27f4a2713aSLionel Sambuc #include "llvm/IR/Metadata.h"
28f4a2713aSLionel Sambuc #include "llvm/IR/Type.h"
29f4a2713aSLionel Sambuc using namespace clang;
30f4a2713aSLionel Sambuc using namespace CodeGen;
31f4a2713aSLionel Sambuc
CodeGenTBAA(ASTContext & Ctx,llvm::LLVMContext & VMContext,const CodeGenOptions & CGO,const LangOptions & Features,MangleContext & MContext)32f4a2713aSLionel Sambuc CodeGenTBAA::CodeGenTBAA(ASTContext &Ctx, llvm::LLVMContext& VMContext,
33f4a2713aSLionel Sambuc const CodeGenOptions &CGO,
34f4a2713aSLionel Sambuc const LangOptions &Features, MangleContext &MContext)
35f4a2713aSLionel Sambuc : Context(Ctx), CodeGenOpts(CGO), Features(Features), MContext(MContext),
36*0a6a1f1dSLionel Sambuc MDHelper(VMContext), Root(nullptr), Char(nullptr) {
37f4a2713aSLionel Sambuc }
38f4a2713aSLionel Sambuc
~CodeGenTBAA()39f4a2713aSLionel Sambuc CodeGenTBAA::~CodeGenTBAA() {
40f4a2713aSLionel Sambuc }
41f4a2713aSLionel Sambuc
getRoot()42f4a2713aSLionel Sambuc llvm::MDNode *CodeGenTBAA::getRoot() {
43f4a2713aSLionel Sambuc // Define the root of the tree. This identifies the tree, so that
44f4a2713aSLionel Sambuc // if our LLVM IR is linked with LLVM IR from a different front-end
45f4a2713aSLionel Sambuc // (or a different version of this front-end), their TBAA trees will
46f4a2713aSLionel Sambuc // remain distinct, and the optimizer will treat them conservatively.
47f4a2713aSLionel Sambuc if (!Root)
48f4a2713aSLionel Sambuc Root = MDHelper.createTBAARoot("Simple C/C++ TBAA");
49f4a2713aSLionel Sambuc
50f4a2713aSLionel Sambuc return Root;
51f4a2713aSLionel Sambuc }
52f4a2713aSLionel Sambuc
53f4a2713aSLionel Sambuc // For both scalar TBAA and struct-path aware TBAA, the scalar type has the
54f4a2713aSLionel Sambuc // same format: name, parent node, and offset.
createTBAAScalarType(StringRef Name,llvm::MDNode * Parent)55f4a2713aSLionel Sambuc llvm::MDNode *CodeGenTBAA::createTBAAScalarType(StringRef Name,
56f4a2713aSLionel Sambuc llvm::MDNode *Parent) {
57f4a2713aSLionel Sambuc return MDHelper.createTBAAScalarTypeNode(Name, Parent);
58f4a2713aSLionel Sambuc }
59f4a2713aSLionel Sambuc
getChar()60f4a2713aSLionel Sambuc llvm::MDNode *CodeGenTBAA::getChar() {
61f4a2713aSLionel Sambuc // Define the root of the tree for user-accessible memory. C and C++
62f4a2713aSLionel Sambuc // give special powers to char and certain similar types. However,
63f4a2713aSLionel Sambuc // these special powers only cover user-accessible memory, and doesn't
64f4a2713aSLionel Sambuc // include things like vtables.
65f4a2713aSLionel Sambuc if (!Char)
66f4a2713aSLionel Sambuc Char = createTBAAScalarType("omnipotent char", getRoot());
67f4a2713aSLionel Sambuc
68f4a2713aSLionel Sambuc return Char;
69f4a2713aSLionel Sambuc }
70f4a2713aSLionel Sambuc
TypeHasMayAlias(QualType QTy)71f4a2713aSLionel Sambuc static bool TypeHasMayAlias(QualType QTy) {
72f4a2713aSLionel Sambuc // Tagged types have declarations, and therefore may have attributes.
73f4a2713aSLionel Sambuc if (const TagType *TTy = dyn_cast<TagType>(QTy))
74f4a2713aSLionel Sambuc return TTy->getDecl()->hasAttr<MayAliasAttr>();
75f4a2713aSLionel Sambuc
76f4a2713aSLionel Sambuc // Typedef types have declarations, and therefore may have attributes.
77f4a2713aSLionel Sambuc if (const TypedefType *TTy = dyn_cast<TypedefType>(QTy)) {
78f4a2713aSLionel Sambuc if (TTy->getDecl()->hasAttr<MayAliasAttr>())
79f4a2713aSLionel Sambuc return true;
80f4a2713aSLionel Sambuc // Also, their underlying types may have relevant attributes.
81f4a2713aSLionel Sambuc return TypeHasMayAlias(TTy->desugar());
82f4a2713aSLionel Sambuc }
83f4a2713aSLionel Sambuc
84f4a2713aSLionel Sambuc return false;
85f4a2713aSLionel Sambuc }
86f4a2713aSLionel Sambuc
87f4a2713aSLionel Sambuc llvm::MDNode *
getTBAAInfo(QualType QTy)88f4a2713aSLionel Sambuc CodeGenTBAA::getTBAAInfo(QualType QTy) {
89f4a2713aSLionel Sambuc // At -O0 or relaxed aliasing, TBAA is not emitted for regular types.
90f4a2713aSLionel Sambuc if (CodeGenOpts.OptimizationLevel == 0 || CodeGenOpts.RelaxedAliasing)
91*0a6a1f1dSLionel Sambuc return nullptr;
92f4a2713aSLionel Sambuc
93f4a2713aSLionel Sambuc // If the type has the may_alias attribute (even on a typedef), it is
94f4a2713aSLionel Sambuc // effectively in the general char alias class.
95f4a2713aSLionel Sambuc if (TypeHasMayAlias(QTy))
96f4a2713aSLionel Sambuc return getChar();
97f4a2713aSLionel Sambuc
98f4a2713aSLionel Sambuc const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
99f4a2713aSLionel Sambuc
100f4a2713aSLionel Sambuc if (llvm::MDNode *N = MetadataCache[Ty])
101f4a2713aSLionel Sambuc return N;
102f4a2713aSLionel Sambuc
103f4a2713aSLionel Sambuc // Handle builtin types.
104f4a2713aSLionel Sambuc if (const BuiltinType *BTy = dyn_cast<BuiltinType>(Ty)) {
105f4a2713aSLionel Sambuc switch (BTy->getKind()) {
106f4a2713aSLionel Sambuc // Character types are special and can alias anything.
107f4a2713aSLionel Sambuc // In C++, this technically only includes "char" and "unsigned char",
108f4a2713aSLionel Sambuc // and not "signed char". In C, it includes all three. For now,
109f4a2713aSLionel Sambuc // the risk of exploiting this detail in C++ seems likely to outweigh
110f4a2713aSLionel Sambuc // the benefit.
111f4a2713aSLionel Sambuc case BuiltinType::Char_U:
112f4a2713aSLionel Sambuc case BuiltinType::Char_S:
113f4a2713aSLionel Sambuc case BuiltinType::UChar:
114f4a2713aSLionel Sambuc case BuiltinType::SChar:
115f4a2713aSLionel Sambuc return getChar();
116f4a2713aSLionel Sambuc
117f4a2713aSLionel Sambuc // Unsigned types can alias their corresponding signed types.
118f4a2713aSLionel Sambuc case BuiltinType::UShort:
119f4a2713aSLionel Sambuc return getTBAAInfo(Context.ShortTy);
120f4a2713aSLionel Sambuc case BuiltinType::UInt:
121f4a2713aSLionel Sambuc return getTBAAInfo(Context.IntTy);
122f4a2713aSLionel Sambuc case BuiltinType::ULong:
123f4a2713aSLionel Sambuc return getTBAAInfo(Context.LongTy);
124f4a2713aSLionel Sambuc case BuiltinType::ULongLong:
125f4a2713aSLionel Sambuc return getTBAAInfo(Context.LongLongTy);
126f4a2713aSLionel Sambuc case BuiltinType::UInt128:
127f4a2713aSLionel Sambuc return getTBAAInfo(Context.Int128Ty);
128f4a2713aSLionel Sambuc
129f4a2713aSLionel Sambuc // Treat all other builtin types as distinct types. This includes
130f4a2713aSLionel Sambuc // treating wchar_t, char16_t, and char32_t as distinct from their
131f4a2713aSLionel Sambuc // "underlying types".
132f4a2713aSLionel Sambuc default:
133f4a2713aSLionel Sambuc return MetadataCache[Ty] =
134f4a2713aSLionel Sambuc createTBAAScalarType(BTy->getName(Features), getChar());
135f4a2713aSLionel Sambuc }
136f4a2713aSLionel Sambuc }
137f4a2713aSLionel Sambuc
138f4a2713aSLionel Sambuc // Handle pointers.
139f4a2713aSLionel Sambuc // TODO: Implement C++'s type "similarity" and consider dis-"similar"
140f4a2713aSLionel Sambuc // pointers distinct.
141f4a2713aSLionel Sambuc if (Ty->isPointerType())
142f4a2713aSLionel Sambuc return MetadataCache[Ty] = createTBAAScalarType("any pointer",
143f4a2713aSLionel Sambuc getChar());
144f4a2713aSLionel Sambuc
145f4a2713aSLionel Sambuc // Enum types are distinct types. In C++ they have "underlying types",
146f4a2713aSLionel Sambuc // however they aren't related for TBAA.
147f4a2713aSLionel Sambuc if (const EnumType *ETy = dyn_cast<EnumType>(Ty)) {
148f4a2713aSLionel Sambuc // In C++ mode, types have linkage, so we can rely on the ODR and
149f4a2713aSLionel Sambuc // on their mangled names, if they're external.
150f4a2713aSLionel Sambuc // TODO: Is there a way to get a program-wide unique name for a
151f4a2713aSLionel Sambuc // decl with local linkage or no linkage?
152f4a2713aSLionel Sambuc if (!Features.CPlusPlus || !ETy->getDecl()->isExternallyVisible())
153f4a2713aSLionel Sambuc return MetadataCache[Ty] = getChar();
154f4a2713aSLionel Sambuc
155f4a2713aSLionel Sambuc SmallString<256> OutName;
156f4a2713aSLionel Sambuc llvm::raw_svector_ostream Out(OutName);
157f4a2713aSLionel Sambuc MContext.mangleTypeName(QualType(ETy, 0), Out);
158f4a2713aSLionel Sambuc Out.flush();
159f4a2713aSLionel Sambuc return MetadataCache[Ty] = createTBAAScalarType(OutName, getChar());
160f4a2713aSLionel Sambuc }
161f4a2713aSLionel Sambuc
162f4a2713aSLionel Sambuc // For now, handle any other kind of type conservatively.
163f4a2713aSLionel Sambuc return MetadataCache[Ty] = getChar();
164f4a2713aSLionel Sambuc }
165f4a2713aSLionel Sambuc
getTBAAInfoForVTablePtr()166f4a2713aSLionel Sambuc llvm::MDNode *CodeGenTBAA::getTBAAInfoForVTablePtr() {
167f4a2713aSLionel Sambuc return createTBAAScalarType("vtable pointer", getRoot());
168f4a2713aSLionel Sambuc }
169f4a2713aSLionel Sambuc
170f4a2713aSLionel Sambuc bool
CollectFields(uint64_t BaseOffset,QualType QTy,SmallVectorImpl<llvm::MDBuilder::TBAAStructField> & Fields,bool MayAlias)171f4a2713aSLionel Sambuc CodeGenTBAA::CollectFields(uint64_t BaseOffset,
172f4a2713aSLionel Sambuc QualType QTy,
173f4a2713aSLionel Sambuc SmallVectorImpl<llvm::MDBuilder::TBAAStructField> &
174f4a2713aSLionel Sambuc Fields,
175f4a2713aSLionel Sambuc bool MayAlias) {
176f4a2713aSLionel Sambuc /* Things not handled yet include: C++ base classes, bitfields, */
177f4a2713aSLionel Sambuc
178f4a2713aSLionel Sambuc if (const RecordType *TTy = QTy->getAs<RecordType>()) {
179f4a2713aSLionel Sambuc const RecordDecl *RD = TTy->getDecl()->getDefinition();
180f4a2713aSLionel Sambuc if (RD->hasFlexibleArrayMember())
181f4a2713aSLionel Sambuc return false;
182f4a2713aSLionel Sambuc
183f4a2713aSLionel Sambuc // TODO: Handle C++ base classes.
184f4a2713aSLionel Sambuc if (const CXXRecordDecl *Decl = dyn_cast<CXXRecordDecl>(RD))
185f4a2713aSLionel Sambuc if (Decl->bases_begin() != Decl->bases_end())
186f4a2713aSLionel Sambuc return false;
187f4a2713aSLionel Sambuc
188f4a2713aSLionel Sambuc const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
189f4a2713aSLionel Sambuc
190f4a2713aSLionel Sambuc unsigned idx = 0;
191f4a2713aSLionel Sambuc for (RecordDecl::field_iterator i = RD->field_begin(),
192f4a2713aSLionel Sambuc e = RD->field_end(); i != e; ++i, ++idx) {
193f4a2713aSLionel Sambuc uint64_t Offset = BaseOffset +
194f4a2713aSLionel Sambuc Layout.getFieldOffset(idx) / Context.getCharWidth();
195f4a2713aSLionel Sambuc QualType FieldQTy = i->getType();
196f4a2713aSLionel Sambuc if (!CollectFields(Offset, FieldQTy, Fields,
197f4a2713aSLionel Sambuc MayAlias || TypeHasMayAlias(FieldQTy)))
198f4a2713aSLionel Sambuc return false;
199f4a2713aSLionel Sambuc }
200f4a2713aSLionel Sambuc return true;
201f4a2713aSLionel Sambuc }
202f4a2713aSLionel Sambuc
203f4a2713aSLionel Sambuc /* Otherwise, treat whatever it is as a field. */
204f4a2713aSLionel Sambuc uint64_t Offset = BaseOffset;
205f4a2713aSLionel Sambuc uint64_t Size = Context.getTypeSizeInChars(QTy).getQuantity();
206f4a2713aSLionel Sambuc llvm::MDNode *TBAAInfo = MayAlias ? getChar() : getTBAAInfo(QTy);
207f4a2713aSLionel Sambuc llvm::MDNode *TBAATag = getTBAAScalarTagInfo(TBAAInfo);
208f4a2713aSLionel Sambuc Fields.push_back(llvm::MDBuilder::TBAAStructField(Offset, Size, TBAATag));
209f4a2713aSLionel Sambuc return true;
210f4a2713aSLionel Sambuc }
211f4a2713aSLionel Sambuc
212f4a2713aSLionel Sambuc llvm::MDNode *
getTBAAStructInfo(QualType QTy)213f4a2713aSLionel Sambuc CodeGenTBAA::getTBAAStructInfo(QualType QTy) {
214f4a2713aSLionel Sambuc const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
215f4a2713aSLionel Sambuc
216f4a2713aSLionel Sambuc if (llvm::MDNode *N = StructMetadataCache[Ty])
217f4a2713aSLionel Sambuc return N;
218f4a2713aSLionel Sambuc
219f4a2713aSLionel Sambuc SmallVector<llvm::MDBuilder::TBAAStructField, 4> Fields;
220f4a2713aSLionel Sambuc if (CollectFields(0, QTy, Fields, TypeHasMayAlias(QTy)))
221f4a2713aSLionel Sambuc return MDHelper.createTBAAStructNode(Fields);
222f4a2713aSLionel Sambuc
223f4a2713aSLionel Sambuc // For now, handle any other kind of type conservatively.
224*0a6a1f1dSLionel Sambuc return StructMetadataCache[Ty] = nullptr;
225f4a2713aSLionel Sambuc }
226f4a2713aSLionel Sambuc
227f4a2713aSLionel Sambuc /// Check if the given type can be handled by path-aware TBAA.
isTBAAPathStruct(QualType QTy)228f4a2713aSLionel Sambuc static bool isTBAAPathStruct(QualType QTy) {
229f4a2713aSLionel Sambuc if (const RecordType *TTy = QTy->getAs<RecordType>()) {
230f4a2713aSLionel Sambuc const RecordDecl *RD = TTy->getDecl()->getDefinition();
231f4a2713aSLionel Sambuc if (RD->hasFlexibleArrayMember())
232f4a2713aSLionel Sambuc return false;
233f4a2713aSLionel Sambuc // RD can be struct, union, class, interface or enum.
234f4a2713aSLionel Sambuc // For now, we only handle struct and class.
235f4a2713aSLionel Sambuc if (RD->isStruct() || RD->isClass())
236f4a2713aSLionel Sambuc return true;
237f4a2713aSLionel Sambuc }
238f4a2713aSLionel Sambuc return false;
239f4a2713aSLionel Sambuc }
240f4a2713aSLionel Sambuc
241f4a2713aSLionel Sambuc llvm::MDNode *
getTBAAStructTypeInfo(QualType QTy)242f4a2713aSLionel Sambuc CodeGenTBAA::getTBAAStructTypeInfo(QualType QTy) {
243f4a2713aSLionel Sambuc const Type *Ty = Context.getCanonicalType(QTy).getTypePtr();
244f4a2713aSLionel Sambuc assert(isTBAAPathStruct(QTy));
245f4a2713aSLionel Sambuc
246f4a2713aSLionel Sambuc if (llvm::MDNode *N = StructTypeMetadataCache[Ty])
247f4a2713aSLionel Sambuc return N;
248f4a2713aSLionel Sambuc
249f4a2713aSLionel Sambuc if (const RecordType *TTy = QTy->getAs<RecordType>()) {
250f4a2713aSLionel Sambuc const RecordDecl *RD = TTy->getDecl()->getDefinition();
251f4a2713aSLionel Sambuc
252f4a2713aSLionel Sambuc const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);
253f4a2713aSLionel Sambuc SmallVector <std::pair<llvm::MDNode*, uint64_t>, 4> Fields;
254f4a2713aSLionel Sambuc unsigned idx = 0;
255f4a2713aSLionel Sambuc for (RecordDecl::field_iterator i = RD->field_begin(),
256f4a2713aSLionel Sambuc e = RD->field_end(); i != e; ++i, ++idx) {
257f4a2713aSLionel Sambuc QualType FieldQTy = i->getType();
258f4a2713aSLionel Sambuc llvm::MDNode *FieldNode;
259f4a2713aSLionel Sambuc if (isTBAAPathStruct(FieldQTy))
260f4a2713aSLionel Sambuc FieldNode = getTBAAStructTypeInfo(FieldQTy);
261f4a2713aSLionel Sambuc else
262f4a2713aSLionel Sambuc FieldNode = getTBAAInfo(FieldQTy);
263f4a2713aSLionel Sambuc if (!FieldNode)
264*0a6a1f1dSLionel Sambuc return StructTypeMetadataCache[Ty] = nullptr;
265f4a2713aSLionel Sambuc Fields.push_back(std::make_pair(
266f4a2713aSLionel Sambuc FieldNode, Layout.getFieldOffset(idx) / Context.getCharWidth()));
267f4a2713aSLionel Sambuc }
268f4a2713aSLionel Sambuc
269f4a2713aSLionel Sambuc SmallString<256> OutName;
270f4a2713aSLionel Sambuc if (Features.CPlusPlus) {
271f4a2713aSLionel Sambuc // Don't use the mangler for C code.
272f4a2713aSLionel Sambuc llvm::raw_svector_ostream Out(OutName);
273f4a2713aSLionel Sambuc MContext.mangleTypeName(QualType(Ty, 0), Out);
274f4a2713aSLionel Sambuc Out.flush();
275f4a2713aSLionel Sambuc } else {
276f4a2713aSLionel Sambuc OutName = RD->getName();
277f4a2713aSLionel Sambuc }
278f4a2713aSLionel Sambuc // Create the struct type node with a vector of pairs (offset, type).
279f4a2713aSLionel Sambuc return StructTypeMetadataCache[Ty] =
280f4a2713aSLionel Sambuc MDHelper.createTBAAStructTypeNode(OutName, Fields);
281f4a2713aSLionel Sambuc }
282f4a2713aSLionel Sambuc
283*0a6a1f1dSLionel Sambuc return StructMetadataCache[Ty] = nullptr;
284f4a2713aSLionel Sambuc }
285f4a2713aSLionel Sambuc
286f4a2713aSLionel Sambuc /// Return a TBAA tag node for both scalar TBAA and struct-path aware TBAA.
287f4a2713aSLionel Sambuc llvm::MDNode *
getTBAAStructTagInfo(QualType BaseQTy,llvm::MDNode * AccessNode,uint64_t Offset)288f4a2713aSLionel Sambuc CodeGenTBAA::getTBAAStructTagInfo(QualType BaseQTy, llvm::MDNode *AccessNode,
289f4a2713aSLionel Sambuc uint64_t Offset) {
290f4a2713aSLionel Sambuc if (!AccessNode)
291*0a6a1f1dSLionel Sambuc return nullptr;
292f4a2713aSLionel Sambuc
293f4a2713aSLionel Sambuc if (!CodeGenOpts.StructPathTBAA)
294f4a2713aSLionel Sambuc return getTBAAScalarTagInfo(AccessNode);
295f4a2713aSLionel Sambuc
296f4a2713aSLionel Sambuc const Type *BTy = Context.getCanonicalType(BaseQTy).getTypePtr();
297f4a2713aSLionel Sambuc TBAAPathTag PathTag = TBAAPathTag(BTy, AccessNode, Offset);
298f4a2713aSLionel Sambuc if (llvm::MDNode *N = StructTagMetadataCache[PathTag])
299f4a2713aSLionel Sambuc return N;
300f4a2713aSLionel Sambuc
301*0a6a1f1dSLionel Sambuc llvm::MDNode *BNode = nullptr;
302f4a2713aSLionel Sambuc if (isTBAAPathStruct(BaseQTy))
303f4a2713aSLionel Sambuc BNode = getTBAAStructTypeInfo(BaseQTy);
304f4a2713aSLionel Sambuc if (!BNode)
305f4a2713aSLionel Sambuc return StructTagMetadataCache[PathTag] =
306f4a2713aSLionel Sambuc MDHelper.createTBAAStructTagNode(AccessNode, AccessNode, 0);
307f4a2713aSLionel Sambuc
308f4a2713aSLionel Sambuc return StructTagMetadataCache[PathTag] =
309f4a2713aSLionel Sambuc MDHelper.createTBAAStructTagNode(BNode, AccessNode, Offset);
310f4a2713aSLionel Sambuc }
311f4a2713aSLionel Sambuc
312f4a2713aSLionel Sambuc llvm::MDNode *
getTBAAScalarTagInfo(llvm::MDNode * AccessNode)313f4a2713aSLionel Sambuc CodeGenTBAA::getTBAAScalarTagInfo(llvm::MDNode *AccessNode) {
314f4a2713aSLionel Sambuc if (!AccessNode)
315*0a6a1f1dSLionel Sambuc return nullptr;
316f4a2713aSLionel Sambuc if (llvm::MDNode *N = ScalarTagMetadataCache[AccessNode])
317f4a2713aSLionel Sambuc return N;
318f4a2713aSLionel Sambuc
319f4a2713aSLionel Sambuc return ScalarTagMetadataCache[AccessNode] =
320f4a2713aSLionel Sambuc MDHelper.createTBAAStructTagNode(AccessNode, AccessNode, 0);
321f4a2713aSLionel Sambuc }
322