1 //===- llvm/Analysis/AliasSetTracker.h - Build Alias Sets -------*- C++ -*-===//
3 // This file defines two classes: AliasSetTracker and AliasSet. These interface
4 // are used to classify a collection of pointer references into a maximal number
5 // of disjoint sets. Each AliasSet object constructed by the AliasSetTracker
6 // object refers to memory disjoint from the other sets.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_ANALYSIS_ALIASSETTRACKER_H
11 #define LLVM_ANALYSIS_ALIASSETTRACKER_H
20 class AliasSetTracker;
23 friend class AliasSetTracker;
24 std::vector<LoadInst*> Loads;
25 std::vector<StoreInst*> Stores;
26 std::vector<CallInst*> Calls;
27 std::vector<InvokeInst*> Invokes;
29 /// AccessType - Keep track of whether this alias set merely refers to the
30 /// locations of memory, whether it modifies the memory, or whether it does
31 /// both. The lattice goes from "None" (alias set not present) to either Refs
32 /// or Mods, then to ModRef as neccesary.
38 /// AliasType - Keep track the relationships between the pointers in the set.
39 /// Lattice goes from MustAlias to MayAlias.
45 enum AccessType AccessTy;
46 enum AliasType AliasTy;
49 enum AccessType getAccessType() const { return AccessTy; }
50 enum AliasType getAliasType() const { return AliasTy; }
52 // TODO: in the future, add a fixed size (4? 2?) cache of pointers that we
53 // know are in the alias set, to cut down time answering "pointeraliasesset"
56 /// pointerAliasesSet - Return true if the specified pointer "may" (or must)
57 /// alias one of the members in the set.
59 bool pointerAliasesSet(const Value *Ptr, AliasAnalysis &AA) const;
61 /// mergeSetIn - Merge the specified alias set into this alias set...
63 void mergeSetIn(const AliasSet &AS);
65 const std::vector<LoadInst*> &getLoads() const { return Loads; }
66 const std::vector<StoreInst*> &getStores() const { return Stores; }
67 const std::vector<CallInst*> &getCalls() const { return Calls; }
68 const std::vector<InvokeInst*> &getInvokes() const { return Invokes; }
71 AliasSet() : AliasTy(MustAlias) {} // Can only be created by AliasSetTracker
72 void updateAccessType();
73 Value *getSomePointer() const;
77 class AliasSetTracker {
79 std::vector<AliasSet> AliasSets;
81 /// AliasSetTracker ctor - Create an empty collection of AliasSets, and use
82 /// the specified alias analysis object to disambiguate load and store
84 AliasSetTracker(AliasAnalysis &aa) : AA(aa) {}
87 /// add methods - These methods are used to add different types of
88 /// instructions to the alias sets. Adding a new instruction can result in
89 /// one of three actions happening:
91 /// 1. If the instruction doesn't alias any other sets, create a new set.
92 /// 2. If the instruction aliases exactly one set, add it to the set
93 /// 3. If the instruction aliases multiple sets, merge the sets, and add
94 /// the instruction to the result.
96 void add(LoadInst *LI);
97 void add(StoreInst *SI);
98 void add(CallInst *CI);
99 void add(InvokeInst *II);
101 /// getAliasSets - Return the alias sets that are active.
102 const std::vector<AliasSet> &getAliasSets() const { return AliasSets; }
105 AliasSet *findAliasSetForPointer(const Value *Ptr);