LLVM: lib/Analysis/AliasAnalysisEvaluator.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
19using namespace llvm;
20
22
27
32
34
36 std::pair<const Value *, Type *> Loc1,
37 std::pair<const Value *, Type *> Loc2,
39 if (PrintAll || P) {
40 Type *Ty1 = Loc1.second, *Ty2 = Loc2.second;
41 unsigned AS1 = Loc1.first->getType()->getPointerAddressSpace();
42 unsigned AS2 = Loc2.first->getType()->getPointerAddressSpace();
43 std::string o1, o2;
44 {
46 Loc1.first->printAsOperand(os1, false, M);
47 Loc2.first->printAsOperand(os2, false, M);
48 }
49
50 if (o2 < o1) {
54
56 }
57 errs() << " " << AR << ":\t";
58 Ty1->print(errs(), false, true);
59 if (AS1 != 0)
60 errs() << " addrspace(" << AS1 << ")";
61 errs() << "* " << o1 << ", ";
62 Ty2->print(errs(), false, true);
63 if (AS2 != 0)
64 errs() << " addrspace(" << AS2 << ")";
65 errs() << "* " << o2 << "\n";
66 }
67}
68
71 std::pair<const Value *, Type *> Loc, Module *M) {
72 if (PrintAll || P) {
73 errs() << " " << Msg << ": Ptr: ";
74 Loc.second->print(errs(), false, true);
75 errs() << "* ";
76 Loc.first->printAsOperand(errs(), false, M);
77 errs() << "\t<->" << *I << '\n';
78 }
79}
80
83 if (PrintAll || P) {
84 errs() << " " << Msg << ": " << *CallA << " <-> " << *CallB << '\n';
85 }
86}
87
91 if (PrintAll || P) {
92 errs() << " " << AR << ": " << *V1 << " <-> " << *V2 << '\n';
93 }
94}
95
100
103
104 ++FunctionCount;
105
110
113 Pointers.insert({LI->getPointerOperand(), LI->getType()});
116 Pointers.insert({SI->getPointerOperand(),
117 SI->getValueOperand()->getType()});
121 }
122
125 errs() << "Function: " << F.getName() << ": " << Pointers.size()
126 << " pointers, " << Calls.size() << " call sites\n";
127
128
129 for (auto I1 = Pointers.begin(), E = Pointers.end(); I1 != E; ++I1) {
131 for (auto I2 = Pointers.begin(); I2 != I1; ++I2) {
132 LocationSize Size2 =
134 AliasResult AR = AA.alias(I1->first, Size1, I2->first, Size2);
135 switch (AR) {
138 ++NoAliasCount;
139 break;
142 ++MayAliasCount;
143 break;
146 ++PartialAliasCount;
147 break;
150 ++MustAliasCount;
151 break;
152 }
153 }
154 }
155
157
158 for (Value *Load : Loads) {
159 for (Value *Store : Stores) {
162 switch (AR) {
165 ++NoAliasCount;
166 break;
169 ++MayAliasCount;
170 break;
173 ++PartialAliasCount;
174 break;
177 ++MustAliasCount;
178 break;
179 }
180 }
181 }
182
183
185 I1 != E; ++I1) {
189 switch (AR) {
192 ++NoAliasCount;
193 break;
196 ++MayAliasCount;
197 break;
200 ++PartialAliasCount;
201 break;
204 ++MustAliasCount;
205 break;
206 }
207 }
208 }
209 }
210
211
212 for (CallBase *Call : Calls) {
213 for (const auto &Pointer : Pointers) {
214 LocationSize Size =
220 ++NoModRefCount;
221 break;
224 ++ModCount;
225 break;
228 ++RefCount;
229 break;
233 ++ModRefCount;
234 break;
235 }
236 }
237 }
238
239
240 for (CallBase *CallA : Calls) {
241 for (CallBase *CallB : Calls) {
242 if (CallA == CallB)
243 continue;
247 F.getParent());
248 ++NoModRefCount;
249 break;
252 ++ModCount;
253 break;
256 ++RefCount;
257 break;
260 F.getParent());
261 ++ModRefCount;
262 break;
263 }
264 }
265 }
266}
267
269 errs() << "(" << Num * 100LL / Sum << "." << ((Num * 1000LL / Sum) % 10)
270 << "%)\n";
271}
272
274 if (FunctionCount == 0)
275 return;
276
277 int64_t AliasSum =
278 NoAliasCount + MayAliasCount + PartialAliasCount + MustAliasCount;
279 errs() << "===== Alias Analysis Evaluator Report =====\n";
280 if (AliasSum == 0) {
281 errs() << " Alias Analysis Evaluator Summary: No pointers!\n";
282 } else {
283 errs() << " " << AliasSum << " Total Alias Queries Performed\n";
284 errs() << " " << NoAliasCount << " no alias responses ";
286 errs() << " " << MayAliasCount << " may alias responses ";
288 errs() << " " << PartialAliasCount << " partial alias responses ";
290 errs() << " " << MustAliasCount << " must alias responses ";
292 errs() << " Alias Analysis Evaluator Pointer Alias Summary: "
293 << NoAliasCount * 100 / AliasSum << "%/"
294 << MayAliasCount * 100 / AliasSum << "%/"
295 << PartialAliasCount * 100 / AliasSum << "%/"
296 << MustAliasCount * 100 / AliasSum << "%\n";
297 }
298
299
300 int64_t ModRefSum = NoModRefCount + RefCount + ModCount + ModRefCount;
301 if (ModRefSum == 0) {
302 errs() << " Alias Analysis Mod/Ref Evaluator Summary: no "
303 "mod/ref!\n";
304 } else {
305 errs() << " " << ModRefSum << " Total ModRef Queries Performed\n";
306 errs() << " " << NoModRefCount << " no mod/ref responses ";
308 errs() << " " << ModCount << " mod responses ";
310 errs() << " " << RefCount << " ref responses ";
312 errs() << " " << ModRefCount << " mod & ref responses ";
314 errs() << " Alias Analysis Evaluator Mod/Ref Summary: "
315 << NoModRefCount * 100 / ModRefSum << "%/"
316 << ModCount * 100 / ModRefSum << "%/" << RefCount * 100 / ModRefSum
317 << "%/" << ModRefCount * 100 / ModRefSum << "%\n";
318 }
319}
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static void PrintModRefResults(const char *Msg, bool P, Instruction *I, std::pair< const Value *, Type * > Loc, Module *M)
Definition AliasAnalysisEvaluator.cpp:69
static cl::opt< bool > PrintModRef("print-modref", cl::ReallyHidden)
static void PrintLoadStoreResults(AliasResult AR, bool P, const Value *V1, const Value *V2, const Module *M)
Definition AliasAnalysisEvaluator.cpp:88
static void PrintPercent(int64_t Num, int64_t Sum)
Definition AliasAnalysisEvaluator.cpp:268
static cl::opt< bool > EvalAAMD("evaluate-aa-metadata", cl::ReallyHidden)
static cl::opt< bool > PrintRef("print-ref", cl::ReallyHidden)
static cl::opt< bool > PrintNoAlias("print-no-aliases", cl::ReallyHidden)
static cl::opt< bool > PrintMayAlias("print-may-aliases", cl::ReallyHidden)
static cl::opt< bool > PrintMod("print-mod", cl::ReallyHidden)
static cl::opt< bool > PrintMustAlias("print-must-aliases", cl::ReallyHidden)
static cl::opt< bool > PrintAll("print-all-alias-modref-info", cl::ReallyHidden)
static cl::opt< bool > PrintNoModRef("print-no-modref", cl::ReallyHidden)
static cl::opt< bool > PrintPartialAlias("print-partial-aliases", cl::ReallyHidden)
This file implements a simple N^2 alias analysis accuracy evaluator.
static cl::opt< bool > PrintResults("print-debug-ata", cl::init(false), cl::Hidden)
Print the results of the analysis. Respects -filter-print-funcs.
Expand Atomic instructions
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
Module.h This file contains the declarations for the Module class.
This file implements a set that has insertion order iteration characteristics.
LLVM_ABI PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
Run the pass over the function.
Definition AliasAnalysisEvaluator.cpp:96
LLVM_ABI ~AAEvaluator()
Definition AliasAnalysisEvaluator.cpp:273
A manager for alias analyses.
ModRefInfo getModRefInfo(const Instruction *I, const std::optional< MemoryLocation > &OptLoc)
Check whether or not an instruction may read or write the optionally specified memory location.
LLVM_ABI AliasResult alias(const MemoryLocation &LocA, const MemoryLocation &LocB)
The main low level interface to the alias analysis implementation.
The possible results of an alias query.
void swap(bool DoSwap=true)
Helper for processing AliasResult for swapped memory location pairs.
@ MayAlias
The two locations may or may not alias.
@ NoAlias
The two locations do not alias at all.
@ PartialAlias
The two locations alias, but only due to a partial overlap.
@ MustAlias
The two locations precisely alias each other.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
A parsed version of the target data layout string in and methods for querying it.
static LocationSize precise(uint64_t Value)
static LLVM_ABI MemoryLocation get(const LoadInst *LI)
Return a location with information about the memory reference by the given instruction.
A Module instance is used to store all the information related to an LLVM module.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
A vector that has set insertion semantics.
size_type size() const
Determine the number of elements in the SetVector.
typename vector_type::const_iterator iterator
iterator end()
Get an iterator to the end of the SetVector.
iterator begin()
Get an iterator to the beginning of the SetVector.
bool insert(const value_type &X)
Insert a new element into the SetVector.
A SetVector that performs no allocations if smaller than a certain size.
The instances of the Type class are immutable: once they are created, they are never changed.
LLVM_ABI void print(raw_ostream &O, bool IsForDebug=false, bool NoDetails=false) const
Print the current type.
LLVM Value Representation.
const ParentTy * getParent() const
A raw_ostream that writes to an std::string.
Abstract Attribute helper functions.
This is an optimization pass for GlobalISel generic memory operations.
FunctionAddr VTableAddr Value
decltype(auto) dyn_cast(const From &Val)
dyn_cast - Return the argument parameter cast to the specified type.
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
@ Ref
The access may reference the value stored in memory.
@ ModRef
The access may reference and may modify the value stored in memory.
@ Mod
The access may modify the value stored in memory.
@ NoModRef
The access neither references nor modifies the value stored in memory.
decltype(auto) cast(const From &Val)
cast - Return the argument parameter cast to the specified type.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.