1 //===- AliasAnalysisCounter.cpp - Alias Analysis Query Counter ------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements a pass which can be used to count how many alias queries
11 // are being made and how the alias analysis implementation being used responds.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/Analysis/AliasAnalysisCounter.h"
16 #include "llvm/Analysis/AliasAnalysis.h"
17 #include "llvm/IR/Module.h"
18 #include "llvm/Pass.h"
19 #include "llvm/Support/CommandLine.h"
20 #include "llvm/Support/Debug.h"
21 #include "llvm/Support/ErrorHandling.h"
22 #include "llvm/Support/raw_ostream.h"
26 PrintAll("count-aa-print-all-queries", cl::ReallyHidden, cl::init(true));
28 PrintAllFailures("count-aa-print-all-failed-queries", cl::ReallyHidden);
30 char AliasAnalysisCounter::ID = 0;
31 INITIALIZE_AG_PASS(AliasAnalysisCounter, AliasAnalysis, "count-aa",
32 "Count Alias Analysis Query Responses", false, true, false)
34 ModulePass *llvm::createAliasAnalysisCounterPass() {
35 return new AliasAnalysisCounter();
38 AliasResult AliasAnalysisCounter::alias(const MemoryLocation &LocA,
39 const MemoryLocation &LocB) {
40 AliasResult R = getAnalysis<AliasAnalysis>().alias(LocA, LocB);
42 const char *AliasString = nullptr;
44 case NoAlias: No++; AliasString = "No alias"; break;
45 case MayAlias: May++; AliasString = "May alias"; break;
46 case PartialAlias: Partial++; AliasString = "Partial alias"; break;
47 case MustAlias: Must++; AliasString = "Must alias"; break;
50 if (PrintAll || (PrintAllFailures && R == MayAlias)) {
51 errs() << AliasString << ":\t";
52 errs() << "[" << LocA.Size << "B] ";
53 LocA.Ptr->printAsOperand(errs(), true, M);
55 errs() << "[" << LocB.Size << "B] ";
56 LocB.Ptr->printAsOperand(errs(), true, M);
63 ModRefInfo AliasAnalysisCounter::getModRefInfo(ImmutableCallSite CS,
64 const MemoryLocation &Loc) {
65 ModRefInfo R = getAnalysis<AliasAnalysis>().getModRefInfo(CS, Loc);
67 const char *MRString = nullptr;
71 MRString = "MRI_NoModRef";
83 MRString = "MRI_ModRef";
87 if (PrintAll || (PrintAllFailures && R == MRI_ModRef)) {
88 errs() << MRString << ": Ptr: ";
89 errs() << "[" << Loc.Size << "B] ";
90 Loc.Ptr->printAsOperand(errs(), true, M);
91 errs() << "\t<->" << *CS.getInstruction() << '\n';