1 //===- TypeBasedAliasAnalysis.cpp - Type-Based Alias Analysis -------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the TypeBasedAliasAnalysis pass, which implements
11 // metadata-based TBAA.
12 //
13 // In LLVM IR, memory does not have types, so LLVM's own type system is not
14 // suitable for doing TBAA. Instead, metadata is added to the IR to describe
15 // a type system of a higher level language. This can be used to implement
16 // typical C/C++ TBAA, but it can also be used to implement custom alias
17 // analysis behavior for other languages.
18 //
19 // We now support two types of metadata format: scalar TBAA and struct-path
20 // aware TBAA. After all testing cases are upgraded to use struct-path aware
21 // TBAA and we can auto-upgrade existing bc files, the support for scalar TBAA
22 // can be dropped.
23 //
24 // The scalar TBAA metadata format is very simple. TBAA MDNodes have up to
25 // three fields, e.g.:
26 //   !0 = metadata !{ metadata !"an example type tree" }
27 //   !1 = metadata !{ metadata !"int", metadata !0 }
28 //   !2 = metadata !{ metadata !"float", metadata !0 }
29 //   !3 = metadata !{ metadata !"const float", metadata !2, i64 1 }
30 //
31 // The first field is an identity field. It can be any value, usually
32 // an MDString, which uniquely identifies the type. The most important
33 // name in the tree is the name of the root node. Two trees with
34 // different root node names are entirely disjoint, even if they
35 // have leaves with common names.
36 //
37 // The second field identifies the type's parent node in the tree, or
38 // is null or omitted for a root node. A type is considered to alias
39 // all of its descendants and all of its ancestors in the tree. Also,
40 // a type is considered to alias all types in other trees, so that
41 // bitcode produced from multiple front-ends is handled conservatively.
42 //
43 // If the third field is present, it's an integer which if equal to 1
44 // indicates that the type is "constant" (meaning pointsToConstantMemory
45 // should return true; see
46 // http://llvm.org/docs/AliasAnalysis.html#OtherItfs).
47 //
48 // With struct-path aware TBAA, the MDNodes attached to an instruction using
49 // "!tbaa" are called path tag nodes.
50 //
51 // The path tag node has 4 fields with the last field being optional.
52 //
53 // The first field is the base type node, it can be a struct type node
54 // or a scalar type node. The second field is the access type node, it
55 // must be a scalar type node. The third field is the offset into the base type.
56 // The last field has the same meaning as the last field of our scalar TBAA:
57 // it's an integer which if equal to 1 indicates that the access is "constant".
58 //
59 // The struct type node has a name and a list of pairs, one pair for each member
60 // of the struct. The first element of each pair is a type node (a struct type
61 // node or a sclar type node), specifying the type of the member, the second
62 // element of each pair is the offset of the member.
63 //
64 // Given an example
65 // typedef struct {
66 //   short s;
67 // } A;
68 // typedef struct {
69 //   uint16_t s;
70 //   A a;
71 // } B;
72 //
73 // For an acess to B.a.s, we attach !5 (a path tag node) to the load/store
74 // instruction. The base type is !4 (struct B), the access type is !2 (scalar
75 // type short) and the offset is 4.
76 //
77 // !0 = metadata !{metadata !"Simple C/C++ TBAA"}
78 // !1 = metadata !{metadata !"omnipotent char", metadata !0} // Scalar type node
79 // !2 = metadata !{metadata !"short", metadata !1}           // Scalar type node
80 // !3 = metadata !{metadata !"A", metadata !2, i64 0}        // Struct type node
81 // !4 = metadata !{metadata !"B", metadata !2, i64 0, metadata !3, i64 4}
82 //                                                           // Struct type node
83 // !5 = metadata !{metadata !4, metadata !2, i64 4}          // Path tag node
84 //
85 // The struct type nodes and the scalar type nodes form a type DAG.
86 //         Root (!0)
87 //         char (!1)  -- edge to Root
88 //         short (!2) -- edge to char
89 //         A (!3) -- edge with offset 0 to short
90 //         B (!4) -- edge with offset 0 to short and edge with offset 4 to A
91 //
92 // To check if two tags (tagX and tagY) can alias, we start from the base type
93 // of tagX, follow the edge with the correct offset in the type DAG and adjust
94 // the offset until we reach the base type of tagY or until we reach the Root
95 // node.
96 // If we reach the base type of tagY, compare the adjusted offset with
97 // offset of tagY, return Alias if the offsets are the same, return NoAlias
98 // otherwise.
99 // If we reach the Root node, perform the above starting from base type of tagY
100 // to see if we reach base type of tagX.
101 //
102 // If they have different roots, they're part of different potentially
103 // unrelated type systems, so we return Alias to be conservative.
104 // If neither node is an ancestor of the other and they have the same root,
105 // then we say NoAlias.
106 //
107 // TODO: The current metadata format doesn't support struct
108 // fields. For example:
109 //   struct X {
110 //     double d;
111 //     int i;
112 //   };
113 //   void foo(struct X *x, struct X *y, double *p) {
114 //     *x = *y;
115 //     *p = 0.0;
116 //   }
117 // Struct X has a double member, so the store to *x can alias the store to *p.
118 // Currently it's not possible to precisely describe all the things struct X
119 // aliases, so struct assignments must use conservative TBAA nodes. There's
120 // no scheme for attaching metadata to @llvm.memcpy yet either.
121 //
122 //===----------------------------------------------------------------------===//
123 
124 #include "llvm/Analysis/TypeBasedAliasAnalysis.h"
125 #include "llvm/Analysis/TargetLibraryInfo.h"
126 #include "llvm/ADT/SetVector.h"
127 #include "llvm/IR/Constants.h"
128 #include "llvm/IR/LLVMContext.h"
129 #include "llvm/IR/Module.h"
130 #include "llvm/Support/CommandLine.h"
131 using namespace llvm;
132 
133 // A handy option for disabling TBAA functionality. The same effect can also be
134 // achieved by stripping the !tbaa tags from IR, but this option is sometimes
135 // more convenient.
136 static cl::opt<bool> EnableTBAA("enable-tbaa", cl::init(true));
137 
138 namespace {
139 /// TBAANode - This is a simple wrapper around an MDNode which provides a
140 /// higher-level interface by hiding the details of how alias analysis
141 /// information is encoded in its operands.
142 class TBAANode {
143   const MDNode *Node;
144 
145 public:
TBAANode()146   TBAANode() : Node(nullptr) {}
TBAANode(const MDNode * N)147   explicit TBAANode(const MDNode *N) : Node(N) {}
148 
149   /// getNode - Get the MDNode for this TBAANode.
getNode() const150   const MDNode *getNode() const { return Node; }
151 
152   /// getParent - Get this TBAANode's Alias tree parent.
getParent() const153   TBAANode getParent() const {
154     if (Node->getNumOperands() < 2)
155       return TBAANode();
156     MDNode *P = dyn_cast_or_null<MDNode>(Node->getOperand(1));
157     if (!P)
158       return TBAANode();
159     // Ok, this node has a valid parent. Return it.
160     return TBAANode(P);
161   }
162 
163   /// TypeIsImmutable - Test if this TBAANode represents a type for objects
164   /// which are not modified (by any means) in the context where this
165   /// AliasAnalysis is relevant.
TypeIsImmutable() const166   bool TypeIsImmutable() const {
167     if (Node->getNumOperands() < 3)
168       return false;
169     ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(Node->getOperand(2));
170     if (!CI)
171       return false;
172     return CI->getValue()[0];
173   }
174 };
175 
176 /// This is a simple wrapper around an MDNode which provides a
177 /// higher-level interface by hiding the details of how alias analysis
178 /// information is encoded in its operands.
179 class TBAAStructTagNode {
180   /// This node should be created with createTBAAStructTagNode.
181   const MDNode *Node;
182 
183 public:
TBAAStructTagNode(const MDNode * N)184   explicit TBAAStructTagNode(const MDNode *N) : Node(N) {}
185 
186   /// Get the MDNode for this TBAAStructTagNode.
getNode() const187   const MDNode *getNode() const { return Node; }
188 
getBaseType() const189   const MDNode *getBaseType() const {
190     return dyn_cast_or_null<MDNode>(Node->getOperand(0));
191   }
getAccessType() const192   const MDNode *getAccessType() const {
193     return dyn_cast_or_null<MDNode>(Node->getOperand(1));
194   }
getOffset() const195   uint64_t getOffset() const {
196     return mdconst::extract<ConstantInt>(Node->getOperand(2))->getZExtValue();
197   }
198   /// TypeIsImmutable - Test if this TBAAStructTagNode represents a type for
199   /// objects which are not modified (by any means) in the context where this
200   /// AliasAnalysis is relevant.
TypeIsImmutable() const201   bool TypeIsImmutable() const {
202     if (Node->getNumOperands() < 4)
203       return false;
204     ConstantInt *CI = mdconst::dyn_extract<ConstantInt>(Node->getOperand(3));
205     if (!CI)
206       return false;
207     return CI->getValue()[0];
208   }
209 };
210 
211 /// This is a simple wrapper around an MDNode which provides a
212 /// higher-level interface by hiding the details of how alias analysis
213 /// information is encoded in its operands.
214 class TBAAStructTypeNode {
215   /// This node should be created with createTBAAStructTypeNode.
216   const MDNode *Node;
217 
218 public:
TBAAStructTypeNode()219   TBAAStructTypeNode() : Node(nullptr) {}
TBAAStructTypeNode(const MDNode * N)220   explicit TBAAStructTypeNode(const MDNode *N) : Node(N) {}
221 
222   /// Get the MDNode for this TBAAStructTypeNode.
getNode() const223   const MDNode *getNode() const { return Node; }
224 
225   /// Get this TBAAStructTypeNode's field in the type DAG with
226   /// given offset. Update the offset to be relative to the field type.
getParent(uint64_t & Offset) const227   TBAAStructTypeNode getParent(uint64_t &Offset) const {
228     // Parent can be omitted for the root node.
229     if (Node->getNumOperands() < 2)
230       return TBAAStructTypeNode();
231 
232     // Fast path for a scalar type node and a struct type node with a single
233     // field.
234     if (Node->getNumOperands() <= 3) {
235       uint64_t Cur = Node->getNumOperands() == 2
236                          ? 0
237                          : mdconst::extract<ConstantInt>(Node->getOperand(2))
238                                ->getZExtValue();
239       Offset -= Cur;
240       MDNode *P = dyn_cast_or_null<MDNode>(Node->getOperand(1));
241       if (!P)
242         return TBAAStructTypeNode();
243       return TBAAStructTypeNode(P);
244     }
245 
246     // Assume the offsets are in order. We return the previous field if
247     // the current offset is bigger than the given offset.
248     unsigned TheIdx = 0;
249     for (unsigned Idx = 1; Idx < Node->getNumOperands(); Idx += 2) {
250       uint64_t Cur = mdconst::extract<ConstantInt>(Node->getOperand(Idx + 1))
251                          ->getZExtValue();
252       if (Cur > Offset) {
253         assert(Idx >= 3 &&
254                "TBAAStructTypeNode::getParent should have an offset match!");
255         TheIdx = Idx - 2;
256         break;
257       }
258     }
259     // Move along the last field.
260     if (TheIdx == 0)
261       TheIdx = Node->getNumOperands() - 2;
262     uint64_t Cur = mdconst::extract<ConstantInt>(Node->getOperand(TheIdx + 1))
263                        ->getZExtValue();
264     Offset -= Cur;
265     MDNode *P = dyn_cast_or_null<MDNode>(Node->getOperand(TheIdx));
266     if (!P)
267       return TBAAStructTypeNode();
268     return TBAAStructTypeNode(P);
269   }
270 };
271 }
272 
273 /// Check the first operand of the tbaa tag node, if it is a MDNode, we treat
274 /// it as struct-path aware TBAA format, otherwise, we treat it as scalar TBAA
275 /// format.
isStructPathTBAA(const MDNode * MD)276 static bool isStructPathTBAA(const MDNode *MD) {
277   // Anonymous TBAA root starts with a MDNode and dragonegg uses it as
278   // a TBAA tag.
279   return isa<MDNode>(MD->getOperand(0)) && MD->getNumOperands() >= 3;
280 }
281 
alias(const MemoryLocation & LocA,const MemoryLocation & LocB)282 AliasResult TypeBasedAAResult::alias(const MemoryLocation &LocA,
283                                      const MemoryLocation &LocB) {
284   if (!EnableTBAA)
285     return AAResultBase::alias(LocA, LocB);
286 
287   // Get the attached MDNodes. If either value lacks a tbaa MDNode, we must
288   // be conservative.
289   const MDNode *AM = LocA.AATags.TBAA;
290   if (!AM)
291     return AAResultBase::alias(LocA, LocB);
292   const MDNode *BM = LocB.AATags.TBAA;
293   if (!BM)
294     return AAResultBase::alias(LocA, LocB);
295 
296   // If they may alias, chain to the next AliasAnalysis.
297   if (Aliases(AM, BM))
298     return AAResultBase::alias(LocA, LocB);
299 
300   // Otherwise return a definitive result.
301   return NoAlias;
302 }
303 
pointsToConstantMemory(const MemoryLocation & Loc,bool OrLocal)304 bool TypeBasedAAResult::pointsToConstantMemory(const MemoryLocation &Loc,
305                                                bool OrLocal) {
306   if (!EnableTBAA)
307     return AAResultBase::pointsToConstantMemory(Loc, OrLocal);
308 
309   const MDNode *M = Loc.AATags.TBAA;
310   if (!M)
311     return AAResultBase::pointsToConstantMemory(Loc, OrLocal);
312 
313   // If this is an "immutable" type, we can assume the pointer is pointing
314   // to constant memory.
315   if ((!isStructPathTBAA(M) && TBAANode(M).TypeIsImmutable()) ||
316       (isStructPathTBAA(M) && TBAAStructTagNode(M).TypeIsImmutable()))
317     return true;
318 
319   return AAResultBase::pointsToConstantMemory(Loc, OrLocal);
320 }
321 
322 FunctionModRefBehavior
getModRefBehavior(ImmutableCallSite CS)323 TypeBasedAAResult::getModRefBehavior(ImmutableCallSite CS) {
324   if (!EnableTBAA)
325     return AAResultBase::getModRefBehavior(CS);
326 
327   FunctionModRefBehavior Min = FMRB_UnknownModRefBehavior;
328 
329   // If this is an "immutable" type, we can assume the call doesn't write
330   // to memory.
331   if (const MDNode *M = CS.getInstruction()->getMetadata(LLVMContext::MD_tbaa))
332     if ((!isStructPathTBAA(M) && TBAANode(M).TypeIsImmutable()) ||
333         (isStructPathTBAA(M) && TBAAStructTagNode(M).TypeIsImmutable()))
334       Min = FMRB_OnlyReadsMemory;
335 
336   return FunctionModRefBehavior(AAResultBase::getModRefBehavior(CS) & Min);
337 }
338 
getModRefBehavior(const Function * F)339 FunctionModRefBehavior TypeBasedAAResult::getModRefBehavior(const Function *F) {
340   // Functions don't have metadata. Just chain to the next implementation.
341   return AAResultBase::getModRefBehavior(F);
342 }
343 
getModRefInfo(ImmutableCallSite CS,const MemoryLocation & Loc)344 ModRefInfo TypeBasedAAResult::getModRefInfo(ImmutableCallSite CS,
345                                             const MemoryLocation &Loc) {
346   if (!EnableTBAA)
347     return AAResultBase::getModRefInfo(CS, Loc);
348 
349   if (const MDNode *L = Loc.AATags.TBAA)
350     if (const MDNode *M =
351             CS.getInstruction()->getMetadata(LLVMContext::MD_tbaa))
352       if (!Aliases(L, M))
353         return MRI_NoModRef;
354 
355   return AAResultBase::getModRefInfo(CS, Loc);
356 }
357 
getModRefInfo(ImmutableCallSite CS1,ImmutableCallSite CS2)358 ModRefInfo TypeBasedAAResult::getModRefInfo(ImmutableCallSite CS1,
359                                             ImmutableCallSite CS2) {
360   if (!EnableTBAA)
361     return AAResultBase::getModRefInfo(CS1, CS2);
362 
363   if (const MDNode *M1 =
364           CS1.getInstruction()->getMetadata(LLVMContext::MD_tbaa))
365     if (const MDNode *M2 =
366             CS2.getInstruction()->getMetadata(LLVMContext::MD_tbaa))
367       if (!Aliases(M1, M2))
368         return MRI_NoModRef;
369 
370   return AAResultBase::getModRefInfo(CS1, CS2);
371 }
372 
isTBAAVtableAccess() const373 bool MDNode::isTBAAVtableAccess() const {
374   if (!isStructPathTBAA(this)) {
375     if (getNumOperands() < 1)
376       return false;
377     if (MDString *Tag1 = dyn_cast<MDString>(getOperand(0))) {
378       if (Tag1->getString() == "vtable pointer")
379         return true;
380     }
381     return false;
382   }
383 
384   // For struct-path aware TBAA, we use the access type of the tag.
385   if (getNumOperands() < 2)
386     return false;
387   MDNode *Tag = cast_or_null<MDNode>(getOperand(1));
388   if (!Tag)
389     return false;
390   if (MDString *Tag1 = dyn_cast<MDString>(Tag->getOperand(0))) {
391     if (Tag1->getString() == "vtable pointer")
392       return true;
393   }
394   return false;
395 }
396 
getMostGenericTBAA(MDNode * A,MDNode * B)397 MDNode *MDNode::getMostGenericTBAA(MDNode *A, MDNode *B) {
398   if (!A || !B)
399     return nullptr;
400 
401   if (A == B)
402     return A;
403 
404   // For struct-path aware TBAA, we use the access type of the tag.
405   bool StructPath = isStructPathTBAA(A) && isStructPathTBAA(B);
406   if (StructPath) {
407     A = cast_or_null<MDNode>(A->getOperand(1));
408     if (!A)
409       return nullptr;
410     B = cast_or_null<MDNode>(B->getOperand(1));
411     if (!B)
412       return nullptr;
413   }
414 
415   SmallSetVector<MDNode *, 4> PathA;
416   MDNode *T = A;
417   while (T) {
418     if (PathA.count(T))
419       report_fatal_error("Cycle found in TBAA metadata.");
420     PathA.insert(T);
421     T = T->getNumOperands() >= 2 ? cast_or_null<MDNode>(T->getOperand(1))
422                                  : nullptr;
423   }
424 
425   SmallSetVector<MDNode *, 4> PathB;
426   T = B;
427   while (T) {
428     if (PathB.count(T))
429       report_fatal_error("Cycle found in TBAA metadata.");
430     PathB.insert(T);
431     T = T->getNumOperands() >= 2 ? cast_or_null<MDNode>(T->getOperand(1))
432                                  : nullptr;
433   }
434 
435   int IA = PathA.size() - 1;
436   int IB = PathB.size() - 1;
437 
438   MDNode *Ret = nullptr;
439   while (IA >= 0 && IB >= 0) {
440     if (PathA[IA] == PathB[IB])
441       Ret = PathA[IA];
442     else
443       break;
444     --IA;
445     --IB;
446   }
447   if (!StructPath)
448     return Ret;
449 
450   if (!Ret)
451     return nullptr;
452   // We need to convert from a type node to a tag node.
453   Type *Int64 = IntegerType::get(A->getContext(), 64);
454   Metadata *Ops[3] = {Ret, Ret,
455                       ConstantAsMetadata::get(ConstantInt::get(Int64, 0))};
456   return MDNode::get(A->getContext(), Ops);
457 }
458 
getAAMetadata(AAMDNodes & N,bool Merge) const459 void Instruction::getAAMetadata(AAMDNodes &N, bool Merge) const {
460   if (Merge)
461     N.TBAA =
462         MDNode::getMostGenericTBAA(N.TBAA, getMetadata(LLVMContext::MD_tbaa));
463   else
464     N.TBAA = getMetadata(LLVMContext::MD_tbaa);
465 
466   if (Merge)
467     N.Scope = MDNode::getMostGenericAliasScope(
468         N.Scope, getMetadata(LLVMContext::MD_alias_scope));
469   else
470     N.Scope = getMetadata(LLVMContext::MD_alias_scope);
471 
472   if (Merge)
473     N.NoAlias =
474         MDNode::intersect(N.NoAlias, getMetadata(LLVMContext::MD_noalias));
475   else
476     N.NoAlias = getMetadata(LLVMContext::MD_noalias);
477 }
478 
479 /// Aliases - Test whether the type represented by A may alias the
480 /// type represented by B.
Aliases(const MDNode * A,const MDNode * B) const481 bool TypeBasedAAResult::Aliases(const MDNode *A, const MDNode *B) const {
482   // Make sure that both MDNodes are struct-path aware.
483   if (isStructPathTBAA(A) && isStructPathTBAA(B))
484     return PathAliases(A, B);
485 
486   // Keep track of the root node for A and B.
487   TBAANode RootA, RootB;
488 
489   // Climb the tree from A to see if we reach B.
490   for (TBAANode T(A);;) {
491     if (T.getNode() == B)
492       // B is an ancestor of A.
493       return true;
494 
495     RootA = T;
496     T = T.getParent();
497     if (!T.getNode())
498       break;
499   }
500 
501   // Climb the tree from B to see if we reach A.
502   for (TBAANode T(B);;) {
503     if (T.getNode() == A)
504       // A is an ancestor of B.
505       return true;
506 
507     RootB = T;
508     T = T.getParent();
509     if (!T.getNode())
510       break;
511   }
512 
513   // Neither node is an ancestor of the other.
514 
515   // If they have different roots, they're part of different potentially
516   // unrelated type systems, so we must be conservative.
517   if (RootA.getNode() != RootB.getNode())
518     return true;
519 
520   // If they have the same root, then we've proved there's no alias.
521   return false;
522 }
523 
524 /// Test whether the struct-path tag represented by A may alias the
525 /// struct-path tag represented by B.
PathAliases(const MDNode * A,const MDNode * B) const526 bool TypeBasedAAResult::PathAliases(const MDNode *A, const MDNode *B) const {
527   // Verify that both input nodes are struct-path aware.
528   assert(isStructPathTBAA(A) && "MDNode A is not struct-path aware.");
529   assert(isStructPathTBAA(B) && "MDNode B is not struct-path aware.");
530 
531   // Keep track of the root node for A and B.
532   TBAAStructTypeNode RootA, RootB;
533   TBAAStructTagNode TagA(A), TagB(B);
534 
535   // TODO: We need to check if AccessType of TagA encloses AccessType of
536   // TagB to support aggregate AccessType. If yes, return true.
537 
538   // Start from the base type of A, follow the edge with the correct offset in
539   // the type DAG and adjust the offset until we reach the base type of B or
540   // until we reach the Root node.
541   // Compare the adjusted offset once we have the same base.
542 
543   // Climb the type DAG from base type of A to see if we reach base type of B.
544   const MDNode *BaseA = TagA.getBaseType();
545   const MDNode *BaseB = TagB.getBaseType();
546   uint64_t OffsetA = TagA.getOffset(), OffsetB = TagB.getOffset();
547   for (TBAAStructTypeNode T(BaseA);;) {
548     if (T.getNode() == BaseB)
549       // Base type of A encloses base type of B, check if the offsets match.
550       return OffsetA == OffsetB;
551 
552     RootA = T;
553     // Follow the edge with the correct offset, OffsetA will be adjusted to
554     // be relative to the field type.
555     T = T.getParent(OffsetA);
556     if (!T.getNode())
557       break;
558   }
559 
560   // Reset OffsetA and climb the type DAG from base type of B to see if we reach
561   // base type of A.
562   OffsetA = TagA.getOffset();
563   for (TBAAStructTypeNode T(BaseB);;) {
564     if (T.getNode() == BaseA)
565       // Base type of B encloses base type of A, check if the offsets match.
566       return OffsetA == OffsetB;
567 
568     RootB = T;
569     // Follow the edge with the correct offset, OffsetB will be adjusted to
570     // be relative to the field type.
571     T = T.getParent(OffsetB);
572     if (!T.getNode())
573       break;
574   }
575 
576   // Neither node is an ancestor of the other.
577 
578   // If they have different roots, they're part of different potentially
579   // unrelated type systems, so we must be conservative.
580   if (RootA.getNode() != RootB.getNode())
581     return true;
582 
583   // If they have the same root, then we've proved there's no alias.
584   return false;
585 }
586 
run(Function & F,AnalysisManager<Function> * AM)587 TypeBasedAAResult TypeBasedAA::run(Function &F, AnalysisManager<Function> *AM) {
588   return TypeBasedAAResult(AM->getResult<TargetLibraryAnalysis>(F));
589 }
590 
591 char TypeBasedAA::PassID;
592 
593 char TypeBasedAAWrapperPass::ID = 0;
594 INITIALIZE_PASS_BEGIN(TypeBasedAAWrapperPass, "tbaa",
595                       "Type-Based Alias Analysis", false, true)
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)596 INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)
597 INITIALIZE_PASS_END(TypeBasedAAWrapperPass, "tbaa", "Type-Based Alias Analysis",
598                     false, true)
599 
600 ImmutablePass *llvm::createTypeBasedAAWrapperPass() {
601   return new TypeBasedAAWrapperPass();
602 }
603 
TypeBasedAAWrapperPass()604 TypeBasedAAWrapperPass::TypeBasedAAWrapperPass() : ImmutablePass(ID) {
605   initializeTypeBasedAAWrapperPassPass(*PassRegistry::getPassRegistry());
606 }
607 
doInitialization(Module & M)608 bool TypeBasedAAWrapperPass::doInitialization(Module &M) {
609   Result.reset(new TypeBasedAAResult(
610       getAnalysis<TargetLibraryInfoWrapperPass>().getTLI()));
611   return false;
612 }
613 
doFinalization(Module & M)614 bool TypeBasedAAWrapperPass::doFinalization(Module &M) {
615   Result.reset();
616   return false;
617 }
618 
getAnalysisUsage(AnalysisUsage & AU) const619 void TypeBasedAAWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const {
620   AU.setPreservesAll();
621   AU.addRequired<TargetLibraryInfoWrapperPass>();
622 }
623