blob: baf8f3f881dbeeee07fbb2d4b029f04bc97778b4 [file] [log] [blame]
Chris Lattner4fdb75f2003-02-06 21:29:49 +00001//===- AliasAnalysisEvaluator.cpp - Alias Analysis Accuracy Evaluator -----===//
Misha Brukman01808ca2005-04-21 21:13:18 +00002//
John Criswell482202a2003-10-20 19:43:21 +00003// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Misha Brukman01808ca2005-04-21 21:13:18 +00007//
John Criswell482202a2003-10-20 19:43:21 +00008//===----------------------------------------------------------------------===//
Chris Lattner4fdb75f2003-02-06 21:29:49 +00009
Chandler Carruth4f846a52016-02-20 03:46:03 +000010#include "llvm/Analysis/AliasAnalysisEvaluator.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000011#include "llvm/ADT/SetVector.h"
12#include "llvm/Analysis/AliasAnalysis.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000013#include "llvm/IR/Constants.h"
Chandler Carruth50fee932015-08-06 02:05:46 +000014#include "llvm/IR/DataLayout.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000015#include "llvm/IR/DerivedTypes.h"
16#include "llvm/IR/Function.h"
Chandler Carruth50fee932015-08-06 02:05:46 +000017#include "llvm/IR/Module.h"
Chandler Carruth83948572014-03-04 10:30:26 +000018#include "llvm/IR/InstIterator.h"
Chandler Carruth9fb823b2013-01-02 11:36:10 +000019#include "llvm/IR/Instructions.h"
Misha Brukmanbf28cf62004-03-12 06:15:08 +000020#include "llvm/Pass.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000021#include "llvm/Support/CommandLine.h"
David Greene22819982009-12-23 19:21:19 +000022#include "llvm/Support/Debug.h"
Daniel Dunbar0dd5e1e2009-07-25 00:23:56 +000023#include "llvm/Support/raw_ostream.h"
Chris Lattner8dee8412003-12-10 15:33:59 +000024using namespace llvm;
Brian Gaeke960707c2003-11-11 22:41:34 +000025
Dan Gohmand78c4002008-05-13 00:00:25 +000026static cl::opt<bool> PrintAll("print-all-alias-modref-info", cl::ReallyHidden);
27
28static cl::opt<bool> PrintNoAlias("print-no-aliases", cl::ReallyHidden);
29static cl::opt<bool> PrintMayAlias("print-may-aliases", cl::ReallyHidden);
Dan Gohman105d60a2010-12-10 19:52:40 +000030static cl::opt<bool> PrintPartialAlias("print-partial-aliases", cl::ReallyHidden);
Dan Gohmand78c4002008-05-13 00:00:25 +000031static cl::opt<bool> PrintMustAlias("print-must-aliases", cl::ReallyHidden);
32
33static cl::opt<bool> PrintNoModRef("print-no-modref", cl::ReallyHidden);
34static cl::opt<bool> PrintMod("print-mod", cl::ReallyHidden);
35static cl::opt<bool> PrintRef("print-ref", cl::ReallyHidden);
36static cl::opt<bool> PrintModRef("print-modref", cl::ReallyHidden);
37
Hal Finkelcc39b672014-07-24 12:16:19 +000038static cl::opt<bool> EvalAAMD("evaluate-aa-metadata", cl::ReallyHidden);
Manman Ren0827e972013-03-22 22:34:41 +000039
Chris Lattnerb1d782b2009-08-23 05:17:37 +000040static void PrintResults(const char *Msg, bool P, const Value *V1,
41 const Value *V2, const Module *M) {
Chandler Carruth4f846a52016-02-20 03:46:03 +000042 if (PrintAll || P) {
Chris Lattnerb1d782b2009-08-23 05:17:37 +000043 std::string o1, o2;
44 {
45 raw_string_ostream os1(o1), os2(o2);
Chandler Carruthd48cdbf2014-01-09 02:29:41 +000046 V1->printAsOperand(os1, true, M);
47 V2->printAsOperand(os2, true, M);
Chris Lattnerb1d782b2009-08-23 05:17:37 +000048 }
49
Gabor Greiff77e6972008-02-28 08:38:45 +000050 if (o2 < o1)
Daniel Dunbar0dd5e1e2009-07-25 00:23:56 +000051 std::swap(o1, o2);
David Greene0295ecf2009-12-23 22:49:57 +000052 errs() << " " << Msg << ":\t"
Daniel Dunbar0dd5e1e2009-07-25 00:23:56 +000053 << o1 << ", "
54 << o2 << "\n";
Chris Lattnerb0208e12003-02-09 20:40:13 +000055 }
56}
57
Misha Brukman01808ca2005-04-21 21:13:18 +000058static inline void
Chris Lattner2e8690b2004-07-17 06:43:20 +000059PrintModRefResults(const char *Msg, bool P, Instruction *I, Value *Ptr,
60 Module *M) {
Chandler Carruth4f846a52016-02-20 03:46:03 +000061 if (PrintAll || P) {
David Greene0295ecf2009-12-23 22:49:57 +000062 errs() << " " << Msg << ": Ptr: ";
Chandler Carruthd48cdbf2014-01-09 02:29:41 +000063 Ptr->printAsOperand(errs(), true, M);
David Greene0295ecf2009-12-23 22:49:57 +000064 errs() << "\t<->" << *I << '\n';
Chris Lattner2e8690b2004-07-17 06:43:20 +000065 }
66}
67
Dan Gohmanbd33dab2010-08-04 22:56:29 +000068static inline void
69PrintModRefResults(const char *Msg, bool P, CallSite CSA, CallSite CSB,
70 Module *M) {
Chandler Carruth4f846a52016-02-20 03:46:03 +000071 if (PrintAll || P) {
Dan Gohmanbd33dab2010-08-04 22:56:29 +000072 errs() << " " << Msg << ": " << *CSA.getInstruction()
73 << " <-> " << *CSB.getInstruction() << '\n';
74 }
75}
76
Manman Ren0827e972013-03-22 22:34:41 +000077static inline void
78PrintLoadStoreResults(const char *Msg, bool P, const Value *V1,
79 const Value *V2, const Module *M) {
Chandler Carruth4f846a52016-02-20 03:46:03 +000080 if (PrintAll || P) {
Manman Ren0827e972013-03-22 22:34:41 +000081 errs() << " " << Msg << ": " << *V1
82 << " <-> " << *V2 << '\n';
83 }
84}
85
Gabor Greif64d8d1a2010-04-08 16:46:24 +000086static inline bool isInterestingPointer(Value *V) {
87 return V->getType()->isPointerTy()
88 && !isa<ConstantPointerNull>(V);
89}
90
Chandler Carruthb47f8012016-03-11 11:05:24 +000091PreservedAnalyses AAEvaluator::run(Function &F, AnalysisManager<Function> &AM) {
92 runInternal(F, AM.getResult<AAManager>(F));
Chandler Carruth4f846a52016-02-20 03:46:03 +000093 return PreservedAnalyses::all();
94}
95
96void AAEvaluator::runInternal(Function &F, AAResults &AA) {
Chandler Carruth50fee932015-08-06 02:05:46 +000097 const DataLayout &DL = F.getParent()->getDataLayout();
Chandler Carruth4f846a52016-02-20 03:46:03 +000098
99 ++FunctionCount;
Dan Gohman00ef9322010-07-07 14:27:09 +0000100
101 SetVector<Value *> Pointers;
Rafael Espindola55512f92015-11-18 06:52:18 +0000102 SmallSetVector<CallSite, 16> CallSites;
Manman Ren0827e972013-03-22 22:34:41 +0000103 SetVector<Value *> Loads;
104 SetVector<Value *> Stores;
Dan Gohman00ef9322010-07-07 14:27:09 +0000105
Duncan P. N. Exon Smith5a82c912015-10-10 00:53:03 +0000106 for (auto &I : F.args())
107 if (I.getType()->isPointerTy()) // Add all pointer arguments.
108 Pointers.insert(&I);
Chris Lattner4fdb75f2003-02-06 21:29:49 +0000109
Chris Lattner83e21a02003-06-29 00:07:11 +0000110 for (inst_iterator I = inst_begin(F), E = inst_end(F); I != E; ++I) {
Gabor Greif64d8d1a2010-04-08 16:46:24 +0000111 if (I->getType()->isPointerTy()) // Add all pointer instructions.
Chris Lattner2d3a7a62004-04-27 15:13:33 +0000112 Pointers.insert(&*I);
Hal Finkelcc39b672014-07-24 12:16:19 +0000113 if (EvalAAMD && isa<LoadInst>(&*I))
Manman Ren0827e972013-03-22 22:34:41 +0000114 Loads.insert(&*I);
Hal Finkelcc39b672014-07-24 12:16:19 +0000115 if (EvalAAMD && isa<StoreInst>(&*I))
Manman Ren0827e972013-03-22 22:34:41 +0000116 Stores.insert(&*I);
Chris Lattner9c9f68c2005-03-17 20:25:04 +0000117 Instruction &Inst = *I;
Benjamin Kramer3a09ef62015-04-10 14:50:08 +0000118 if (auto CS = CallSite(&Inst)) {
Gabor Greif64d8d1a2010-04-08 16:46:24 +0000119 Value *Callee = CS.getCalledValue();
120 // Skip actual functions for direct function calls.
121 if (!isa<Function>(Callee) && isInterestingPointer(Callee))
122 Pointers.insert(Callee);
123 // Consider formals.
David Majnemer2bc25382015-12-23 09:58:46 +0000124 for (Use &DataOp : CS.data_ops())
125 if (isInterestingPointer(DataOp))
126 Pointers.insert(DataOp);
Gabor Greife497e5e2010-07-28 15:31:37 +0000127 CallSites.insert(CS);
Gabor Greif64d8d1a2010-04-08 16:46:24 +0000128 } else {
129 // Consider all operands.
130 for (Instruction::op_iterator OI = Inst.op_begin(), OE = Inst.op_end();
131 OI != OE; ++OI)
132 if (isInterestingPointer(*OI))
133 Pointers.insert(*OI);
134 }
Misha Brukmanbf28cf62004-03-12 06:15:08 +0000135 }
136
Chandler Carruth4f846a52016-02-20 03:46:03 +0000137 if (PrintAll || PrintNoAlias || PrintMayAlias || PrintPartialAlias ||
138 PrintMustAlias || PrintNoModRef || PrintMod || PrintRef || PrintModRef)
Dan Gohman00ef9322010-07-07 14:27:09 +0000139 errs() << "Function: " << F.getName() << ": " << Pointers.size()
140 << " pointers, " << CallSites.size() << " call sites\n";
Chris Lattnerb0208e12003-02-09 20:40:13 +0000141
Chris Lattner4fdb75f2003-02-06 21:29:49 +0000142 // iterate over the worklist, and run the full (n^2)/2 disambiguations
Dan Gohman0672e922009-08-26 14:32:17 +0000143 for (SetVector<Value *>::iterator I1 = Pointers.begin(), E = Pointers.end();
Chris Lattnerf30656b2004-11-26 21:05:39 +0000144 I1 != E; ++I1) {
Chandler Carruthecbd1682015-06-17 07:21:38 +0000145 uint64_t I1Size = MemoryLocation::UnknownSize;
Chris Lattner229907c2011-07-18 04:54:35 +0000146 Type *I1ElTy = cast<PointerType>((*I1)->getType())->getElementType();
Chandler Carruth50fee932015-08-06 02:05:46 +0000147 if (I1ElTy->isSized()) I1Size = DL.getTypeStoreSize(I1ElTy);
Chris Lattnerf30656b2004-11-26 21:05:39 +0000148
Dan Gohman0672e922009-08-26 14:32:17 +0000149 for (SetVector<Value *>::iterator I2 = Pointers.begin(); I2 != I1; ++I2) {
Chandler Carruthecbd1682015-06-17 07:21:38 +0000150 uint64_t I2Size = MemoryLocation::UnknownSize;
Chris Lattner229907c2011-07-18 04:54:35 +0000151 Type *I2ElTy =cast<PointerType>((*I2)->getType())->getElementType();
Chandler Carruth50fee932015-08-06 02:05:46 +0000152 if (I2ElTy->isSized()) I2Size = DL.getTypeStoreSize(I2ElTy);
Chris Lattnerf30656b2004-11-26 21:05:39 +0000153
Dan Gohman00ef9322010-07-07 14:27:09 +0000154 switch (AA.alias(*I1, I1Size, *I2, I2Size)) {
Chandler Carruthc3f49eb2015-06-22 02:16:51 +0000155 case NoAlias:
Dan Gohman00ef9322010-07-07 14:27:09 +0000156 PrintResults("NoAlias", PrintNoAlias, *I1, *I2, F.getParent());
Chandler Carruthd1a130c2015-06-17 07:21:41 +0000157 ++NoAliasCount;
158 break;
Chandler Carruthc3f49eb2015-06-22 02:16:51 +0000159 case MayAlias:
Dan Gohman00ef9322010-07-07 14:27:09 +0000160 PrintResults("MayAlias", PrintMayAlias, *I1, *I2, F.getParent());
Chandler Carruthd1a130c2015-06-17 07:21:41 +0000161 ++MayAliasCount;
162 break;
Chandler Carruthc3f49eb2015-06-22 02:16:51 +0000163 case PartialAlias:
Dan Gohman105d60a2010-12-10 19:52:40 +0000164 PrintResults("PartialAlias", PrintPartialAlias, *I1, *I2,
165 F.getParent());
Chandler Carruthd1a130c2015-06-17 07:21:41 +0000166 ++PartialAliasCount;
167 break;
Chandler Carruthc3f49eb2015-06-22 02:16:51 +0000168 case MustAlias:
Dan Gohman00ef9322010-07-07 14:27:09 +0000169 PrintResults("MustAlias", PrintMustAlias, *I1, *I2, F.getParent());
Chandler Carruthd1a130c2015-06-17 07:21:41 +0000170 ++MustAliasCount;
171 break;
Chris Lattner4fdb75f2003-02-06 21:29:49 +0000172 }
Chris Lattnerf30656b2004-11-26 21:05:39 +0000173 }
174 }
Chris Lattner4fdb75f2003-02-06 21:29:49 +0000175
Hal Finkelcc39b672014-07-24 12:16:19 +0000176 if (EvalAAMD) {
Manman Ren0827e972013-03-22 22:34:41 +0000177 // iterate over all pairs of load, store
Benjamin Krameraa209152016-06-26 17:27:42 +0000178 for (Value *Load : Loads) {
179 for (Value *Store : Stores) {
180 switch (AA.alias(MemoryLocation::get(cast<LoadInst>(Load)),
181 MemoryLocation::get(cast<StoreInst>(Store)))) {
Chandler Carruthc3f49eb2015-06-22 02:16:51 +0000182 case NoAlias:
Benjamin Krameraa209152016-06-26 17:27:42 +0000183 PrintLoadStoreResults("NoAlias", PrintNoAlias, Load, Store,
Manman Ren0827e972013-03-22 22:34:41 +0000184 F.getParent());
Chandler Carruthd1a130c2015-06-17 07:21:41 +0000185 ++NoAliasCount;
186 break;
Chandler Carruthc3f49eb2015-06-22 02:16:51 +0000187 case MayAlias:
Benjamin Krameraa209152016-06-26 17:27:42 +0000188 PrintLoadStoreResults("MayAlias", PrintMayAlias, Load, Store,
Manman Ren0827e972013-03-22 22:34:41 +0000189 F.getParent());
Chandler Carruthd1a130c2015-06-17 07:21:41 +0000190 ++MayAliasCount;
191 break;
Chandler Carruthc3f49eb2015-06-22 02:16:51 +0000192 case PartialAlias:
Benjamin Krameraa209152016-06-26 17:27:42 +0000193 PrintLoadStoreResults("PartialAlias", PrintPartialAlias, Load, Store,
Manman Ren0827e972013-03-22 22:34:41 +0000194 F.getParent());
Chandler Carruthd1a130c2015-06-17 07:21:41 +0000195 ++PartialAliasCount;
196 break;
Chandler Carruthc3f49eb2015-06-22 02:16:51 +0000197 case MustAlias:
Benjamin Krameraa209152016-06-26 17:27:42 +0000198 PrintLoadStoreResults("MustAlias", PrintMustAlias, Load, Store,
Manman Ren0827e972013-03-22 22:34:41 +0000199 F.getParent());
Chandler Carruthd1a130c2015-06-17 07:21:41 +0000200 ++MustAliasCount;
201 break;
Manman Ren0827e972013-03-22 22:34:41 +0000202 }
203 }
204 }
205
206 // iterate over all pairs of store, store
207 for (SetVector<Value *>::iterator I1 = Stores.begin(), E = Stores.end();
208 I1 != E; ++I1) {
209 for (SetVector<Value *>::iterator I2 = Stores.begin(); I2 != I1; ++I2) {
Chandler Carruth70c61c12015-06-04 02:03:15 +0000210 switch (AA.alias(MemoryLocation::get(cast<StoreInst>(*I1)),
211 MemoryLocation::get(cast<StoreInst>(*I2)))) {
Chandler Carruthc3f49eb2015-06-22 02:16:51 +0000212 case NoAlias:
Manman Ren0827e972013-03-22 22:34:41 +0000213 PrintLoadStoreResults("NoAlias", PrintNoAlias, *I1, *I2,
214 F.getParent());
Chandler Carruthd1a130c2015-06-17 07:21:41 +0000215 ++NoAliasCount;
216 break;
Chandler Carruthc3f49eb2015-06-22 02:16:51 +0000217 case MayAlias:
Manman Ren0827e972013-03-22 22:34:41 +0000218 PrintLoadStoreResults("MayAlias", PrintMayAlias, *I1, *I2,
219 F.getParent());
Chandler Carruthd1a130c2015-06-17 07:21:41 +0000220 ++MayAliasCount;
221 break;
Chandler Carruthc3f49eb2015-06-22 02:16:51 +0000222 case PartialAlias:
Manman Ren0827e972013-03-22 22:34:41 +0000223 PrintLoadStoreResults("PartialAlias", PrintPartialAlias, *I1, *I2,
224 F.getParent());
Chandler Carruthd1a130c2015-06-17 07:21:41 +0000225 ++PartialAliasCount;
226 break;
Chandler Carruthc3f49eb2015-06-22 02:16:51 +0000227 case MustAlias:
Manman Ren0827e972013-03-22 22:34:41 +0000228 PrintLoadStoreResults("MustAlias", PrintMustAlias, *I1, *I2,
229 F.getParent());
Chandler Carruthd1a130c2015-06-17 07:21:41 +0000230 ++MustAliasCount;
231 break;
Manman Ren0827e972013-03-22 22:34:41 +0000232 }
233 }
234 }
235 }
236
Misha Brukmanbf28cf62004-03-12 06:15:08 +0000237 // Mod/ref alias analysis: compare all pairs of calls and values
Benjamin Krameraa209152016-06-26 17:27:42 +0000238 for (CallSite C : CallSites) {
239 Instruction *I = C.getInstruction();
Misha Brukman01808ca2005-04-21 21:13:18 +0000240
Benjamin Krameraa209152016-06-26 17:27:42 +0000241 for (auto Pointer : Pointers) {
Chandler Carruthecbd1682015-06-17 07:21:38 +0000242 uint64_t Size = MemoryLocation::UnknownSize;
Benjamin Krameraa209152016-06-26 17:27:42 +0000243 Type *ElTy = cast<PointerType>(Pointer->getType())->getElementType();
Chandler Carruth50fee932015-08-06 02:05:46 +0000244 if (ElTy->isSized()) Size = DL.getTypeStoreSize(ElTy);
Misha Brukman01808ca2005-04-21 21:13:18 +0000245
Benjamin Krameraa209152016-06-26 17:27:42 +0000246 switch (AA.getModRefInfo(C, Pointer, Size)) {
Chandler Carruth194f59c2015-07-22 23:15:57 +0000247 case MRI_NoModRef:
Benjamin Krameraa209152016-06-26 17:27:42 +0000248 PrintModRefResults("NoModRef", PrintNoModRef, I, Pointer,
249 F.getParent());
Chandler Carruthd1a130c2015-06-17 07:21:41 +0000250 ++NoModRefCount;
251 break;
Chandler Carruth194f59c2015-07-22 23:15:57 +0000252 case MRI_Mod:
Benjamin Krameraa209152016-06-26 17:27:42 +0000253 PrintModRefResults("Just Mod", PrintMod, I, Pointer, F.getParent());
Chandler Carruthd1a130c2015-06-17 07:21:41 +0000254 ++ModCount;
255 break;
Chandler Carruth194f59c2015-07-22 23:15:57 +0000256 case MRI_Ref:
Benjamin Krameraa209152016-06-26 17:27:42 +0000257 PrintModRefResults("Just Ref", PrintRef, I, Pointer, F.getParent());
Chandler Carruthd1a130c2015-06-17 07:21:41 +0000258 ++RefCount;
259 break;
Chandler Carruth194f59c2015-07-22 23:15:57 +0000260 case MRI_ModRef:
Benjamin Krameraa209152016-06-26 17:27:42 +0000261 PrintModRefResults("Both ModRef", PrintModRef, I, Pointer,
262 F.getParent());
Chandler Carruthd1a130c2015-06-17 07:21:41 +0000263 ++ModRefCount;
264 break;
Misha Brukmanbf28cf62004-03-12 06:15:08 +0000265 }
Chris Lattnerf30656b2004-11-26 21:05:39 +0000266 }
Chris Lattner3bbaaaa2004-07-17 07:40:34 +0000267 }
Misha Brukman01808ca2005-04-21 21:13:18 +0000268
Dan Gohmanbd33dab2010-08-04 22:56:29 +0000269 // Mod/ref alias analysis: compare all pairs of calls
Rafael Espindola55512f92015-11-18 06:52:18 +0000270 for (auto C = CallSites.begin(), Ce = CallSites.end(); C != Ce; ++C) {
271 for (auto D = CallSites.begin(); D != Ce; ++D) {
Dan Gohmanbd33dab2010-08-04 22:56:29 +0000272 if (D == C)
273 continue;
274 switch (AA.getModRefInfo(*C, *D)) {
Chandler Carruth194f59c2015-07-22 23:15:57 +0000275 case MRI_NoModRef:
Dan Gohmanbd33dab2010-08-04 22:56:29 +0000276 PrintModRefResults("NoModRef", PrintNoModRef, *C, *D, F.getParent());
Chandler Carruthd1a130c2015-06-17 07:21:41 +0000277 ++NoModRefCount;
278 break;
Chandler Carruth194f59c2015-07-22 23:15:57 +0000279 case MRI_Mod:
Dan Gohman10956182010-08-04 23:37:55 +0000280 PrintModRefResults("Just Mod", PrintMod, *C, *D, F.getParent());
Chandler Carruthd1a130c2015-06-17 07:21:41 +0000281 ++ModCount;
282 break;
Chandler Carruth194f59c2015-07-22 23:15:57 +0000283 case MRI_Ref:
Dan Gohman10956182010-08-04 23:37:55 +0000284 PrintModRefResults("Just Ref", PrintRef, *C, *D, F.getParent());
Chandler Carruthd1a130c2015-06-17 07:21:41 +0000285 ++RefCount;
286 break;
Chandler Carruth194f59c2015-07-22 23:15:57 +0000287 case MRI_ModRef:
Dan Gohman10956182010-08-04 23:37:55 +0000288 PrintModRefResults("Both ModRef", PrintModRef, *C, *D, F.getParent());
Chandler Carruthd1a130c2015-06-17 07:21:41 +0000289 ++ModRefCount;
290 break;
Dan Gohmanbd33dab2010-08-04 22:56:29 +0000291 }
292 }
293 }
Chris Lattner4fdb75f2003-02-06 21:29:49 +0000294}
295
Chandler Carruth4f846a52016-02-20 03:46:03 +0000296static void PrintPercent(int64_t Num, int64_t Sum) {
297 errs() << "(" << Num * 100LL / Sum << "." << ((Num * 1000LL / Sum) % 10)
298 << "%)\n";
Chris Lattner3f08e782005-03-26 23:56:33 +0000299}
300
Chandler Carruth4f846a52016-02-20 03:46:03 +0000301AAEvaluator::~AAEvaluator() {
302 if (FunctionCount == 0)
303 return;
304
305 int64_t AliasSum =
Chandler Carruthd1a130c2015-06-17 07:21:41 +0000306 NoAliasCount + MayAliasCount + PartialAliasCount + MustAliasCount;
David Greene0295ecf2009-12-23 22:49:57 +0000307 errs() << "===== Alias Analysis Evaluator Report =====\n";
Misha Brukmanbf28cf62004-03-12 06:15:08 +0000308 if (AliasSum == 0) {
David Greene0295ecf2009-12-23 22:49:57 +0000309 errs() << " Alias Analysis Evaluator Summary: No pointers!\n";
Misha Brukman01808ca2005-04-21 21:13:18 +0000310 } else {
David Greene0295ecf2009-12-23 22:49:57 +0000311 errs() << " " << AliasSum << " Total Alias Queries Performed\n";
Chandler Carruthd1a130c2015-06-17 07:21:41 +0000312 errs() << " " << NoAliasCount << " no alias responses ";
313 PrintPercent(NoAliasCount, AliasSum);
314 errs() << " " << MayAliasCount << " may alias responses ";
315 PrintPercent(MayAliasCount, AliasSum);
316 errs() << " " << PartialAliasCount << " partial alias responses ";
317 PrintPercent(PartialAliasCount, AliasSum);
318 errs() << " " << MustAliasCount << " must alias responses ";
319 PrintPercent(MustAliasCount, AliasSum);
David Greene0295ecf2009-12-23 22:49:57 +0000320 errs() << " Alias Analysis Evaluator Pointer Alias Summary: "
Chandler Carruthd1a130c2015-06-17 07:21:41 +0000321 << NoAliasCount * 100 / AliasSum << "%/"
322 << MayAliasCount * 100 / AliasSum << "%/"
323 << PartialAliasCount * 100 / AliasSum << "%/"
324 << MustAliasCount * 100 / AliasSum << "%\n";
Chris Lattnereadcadc2003-02-08 23:04:50 +0000325 }
326
Misha Brukmanbf28cf62004-03-12 06:15:08 +0000327 // Display the summary for mod/ref analysis
Chandler Carruth4f846a52016-02-20 03:46:03 +0000328 int64_t ModRefSum = NoModRefCount + ModCount + RefCount + ModRefCount;
Misha Brukmanbf28cf62004-03-12 06:15:08 +0000329 if (ModRefSum == 0) {
Chandler Carruthd1a130c2015-06-17 07:21:41 +0000330 errs() << " Alias Analysis Mod/Ref Evaluator Summary: no "
331 "mod/ref!\n";
Misha Brukmanbf28cf62004-03-12 06:15:08 +0000332 } else {
David Greene0295ecf2009-12-23 22:49:57 +0000333 errs() << " " << ModRefSum << " Total ModRef Queries Performed\n";
Chandler Carruthd1a130c2015-06-17 07:21:41 +0000334 errs() << " " << NoModRefCount << " no mod/ref responses ";
335 PrintPercent(NoModRefCount, ModRefSum);
336 errs() << " " << ModCount << " mod responses ";
337 PrintPercent(ModCount, ModRefSum);
338 errs() << " " << RefCount << " ref responses ";
339 PrintPercent(RefCount, ModRefSum);
340 errs() << " " << ModRefCount << " mod & ref responses ";
341 PrintPercent(ModRefCount, ModRefSum);
David Greene0295ecf2009-12-23 22:49:57 +0000342 errs() << " Alias Analysis Evaluator Mod/Ref Summary: "
Chandler Carruthd1a130c2015-06-17 07:21:41 +0000343 << NoModRefCount * 100 / ModRefSum << "%/"
344 << ModCount * 100 / ModRefSum << "%/" << RefCount * 100 / ModRefSum
345 << "%/" << ModRefCount * 100 / ModRefSum << "%\n";
Misha Brukmanbf28cf62004-03-12 06:15:08 +0000346 }
Chris Lattner4fdb75f2003-02-06 21:29:49 +0000347}
Chandler Carruth4f846a52016-02-20 03:46:03 +0000348
349namespace llvm {
350class AAEvalLegacyPass : public FunctionPass {
351 std::unique_ptr<AAEvaluator> P;
352
353public:
354 static char ID; // Pass identification, replacement for typeid
355 AAEvalLegacyPass() : FunctionPass(ID) {
356 initializeAAEvalLegacyPassPass(*PassRegistry::getPassRegistry());
357 }
358
359 void getAnalysisUsage(AnalysisUsage &AU) const override {
360 AU.addRequired<AAResultsWrapperPass>();
361 AU.setPreservesAll();
362 }
363
364 bool doInitialization(Module &M) override {
365 P.reset(new AAEvaluator());
366 return false;
367 }
368
369 bool runOnFunction(Function &F) override {
370 P->runInternal(F, getAnalysis<AAResultsWrapperPass>().getAAResults());
371 return false;
372 }
373 bool doFinalization(Module &M) override {
374 P.reset();
375 return false;
376 }
377};
378}
379
380char AAEvalLegacyPass::ID = 0;
381INITIALIZE_PASS_BEGIN(AAEvalLegacyPass, "aa-eval",
382 "Exhaustive Alias Analysis Precision Evaluator", false,
383 true)
384INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass)
385INITIALIZE_PASS_END(AAEvalLegacyPass, "aa-eval",
386 "Exhaustive Alias Analysis Precision Evaluator", false,
387 true)
388
389FunctionPass *llvm::createAAEvalPass() { return new AAEvalLegacyPass(); }