~louis/ubuntu/trusty/clamav/lp799623_fix_logrotate

« back to all changes in this revision

Viewing changes to libclamav/c++/llvm/lib/Analysis/AliasAnalysisCounter.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-03-12 11:30:04 UTC
  • mfrom: (0.41.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100312113004-b0fop4bkycszdd0z
Tags: 0.96~rc1+dfsg-0ubuntu1
* New upstream RC - FFE (LP: #537636):
  - Add OfficialDatabaseOnly option to clamav-base.postinst.in
  - Add LocalSocketGroup option to clamav-base.postinst.in
  - Add LocalSocketMode option to clamav-base.postinst.in
  - Add CrossFilesystems option to clamav-base.postinst.in
  - Add ClamukoScannerCount option to clamav-base.postinst.in
  - Add BytecodeSecurity opiton to clamav-base.postinst.in
  - Add DetectionStatsHostID option to clamav-freshclam.postinst.in
  - Add Bytecode option to clamav-freshclam.postinst.in
  - Add MilterSocketGroup option to clamav-milter.postinst.in
  - Add MilterSocketMode option to clamav-milter.postinst.in
  - Add ReportHostname option to clamav-milter.postinst.in
  - Bump libclamav SO version to 6.1.0 in libclamav6.install
  - Drop clamdmon from clamav.examples (no longer shipped by upstream)
  - Drop libclamav.a from libclamav-dev.install (not built by upstream)
  - Update SO version for lintian override for libclamav6
  - Add new Bytecode Testing Tool, usr/bin/clambc, to clamav.install
  - Add build-depends on python and python-setuptools for new test suite
  - Update debian/copyright for the embedded copy of llvm (using the system
    llvm is not currently feasible)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//===- AliasAnalysisCounter.cpp - Alias Analysis Query Counter ------------===//
 
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 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.
 
12
//
 
13
//===----------------------------------------------------------------------===//
 
14
 
 
15
#include "llvm/Analysis/Passes.h"
 
16
#include "llvm/Pass.h"
 
17
#include "llvm/Analysis/AliasAnalysis.h"
 
18
#include "llvm/Assembly/Writer.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"
 
23
using namespace llvm;
 
24
 
 
25
static cl::opt<bool>
 
26
PrintAll("count-aa-print-all-queries", cl::ReallyHidden, cl::init(true));
 
27
static cl::opt<bool>
 
28
PrintAllFailures("count-aa-print-all-failed-queries", cl::ReallyHidden);
 
29
 
 
30
namespace {
 
31
  class AliasAnalysisCounter : public ModulePass, public AliasAnalysis {
 
32
    unsigned No, May, Must;
 
33
    unsigned NoMR, JustRef, JustMod, MR;
 
34
    Module *M;
 
35
  public:
 
36
    static char ID; // Class identification, replacement for typeinfo
 
37
    AliasAnalysisCounter() : ModulePass(&ID) {
 
38
      No = May = Must = 0;
 
39
      NoMR = JustRef = JustMod = MR = 0;
 
40
    }
 
41
 
 
42
    void printLine(const char *Desc, unsigned Val, unsigned Sum) {
 
43
      errs() <<  "  " << Val << " " << Desc << " responses ("
 
44
             << Val*100/Sum << "%)\n";
 
45
    }
 
46
    ~AliasAnalysisCounter() {
 
47
      unsigned AASum = No+May+Must;
 
48
      unsigned MRSum = NoMR+JustRef+JustMod+MR;
 
49
      if (AASum + MRSum) { // Print a report if any counted queries occurred...
 
50
        errs() << "\n===== Alias Analysis Counter Report =====\n"
 
51
               << "  Analysis counted:\n"
 
52
               << "  " << AASum << " Total Alias Queries Performed\n";
 
53
        if (AASum) {
 
54
          printLine("no alias",     No, AASum);
 
55
          printLine("may alias",   May, AASum);
 
56
          printLine("must alias", Must, AASum);
 
57
          errs() << "  Alias Analysis Counter Summary: " << No*100/AASum << "%/"
 
58
                 << May*100/AASum << "%/" << Must*100/AASum<<"%\n\n";
 
59
        }
 
60
 
 
61
        errs() << "  " << MRSum    << " Total Mod/Ref Queries Performed\n";
 
62
        if (MRSum) {
 
63
          printLine("no mod/ref",    NoMR, MRSum);
 
64
          printLine("ref",        JustRef, MRSum);
 
65
          printLine("mod",        JustMod, MRSum);
 
66
          printLine("mod/ref",         MR, MRSum);
 
67
          errs() << "  Mod/Ref Analysis Counter Summary: " <<NoMR*100/MRSum
 
68
                 << "%/" << JustRef*100/MRSum << "%/" << JustMod*100/MRSum
 
69
                 << "%/" << MR*100/MRSum <<"%\n\n";
 
70
        }
 
71
      }
 
72
    }
 
73
 
 
74
    bool runOnModule(Module &M) {
 
75
      this->M = &M;
 
76
      InitializeAliasAnalysis(this);
 
77
      return false;
 
78
    }
 
79
 
 
80
    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
 
81
      AliasAnalysis::getAnalysisUsage(AU);
 
82
      AU.addRequired<AliasAnalysis>();
 
83
      AU.setPreservesAll();
 
84
    }
 
85
 
 
86
    /// getAdjustedAnalysisPointer - This method is used when a pass implements
 
87
    /// an analysis interface through multiple inheritance.  If needed, it
 
88
    /// should override this to adjust the this pointer as needed for the
 
89
    /// specified pass info.
 
90
    virtual void *getAdjustedAnalysisPointer(const PassInfo *PI) {
 
91
      if (PI->isPassID(&AliasAnalysis::ID))
 
92
        return (AliasAnalysis*)this;
 
93
      return this;
 
94
    }
 
95
    
 
96
    // FIXME: We could count these too...
 
97
    bool pointsToConstantMemory(const Value *P) {
 
98
      return getAnalysis<AliasAnalysis>().pointsToConstantMemory(P);
 
99
    }
 
100
 
 
101
    // Forwarding functions: just delegate to a real AA implementation, counting
 
102
    // the number of responses...
 
103
    AliasResult alias(const Value *V1, unsigned V1Size,
 
104
                      const Value *V2, unsigned V2Size);
 
105
 
 
106
    ModRefResult getModRefInfo(CallSite CS, Value *P, unsigned Size);
 
107
    ModRefResult getModRefInfo(CallSite CS1, CallSite CS2) {
 
108
      return AliasAnalysis::getModRefInfo(CS1,CS2);
 
109
    }
 
110
  };
 
111
}
 
112
 
 
113
char AliasAnalysisCounter::ID = 0;
 
114
static RegisterPass<AliasAnalysisCounter>
 
115
X("count-aa", "Count Alias Analysis Query Responses", false, true);
 
116
static RegisterAnalysisGroup<AliasAnalysis> Y(X);
 
117
 
 
118
ModulePass *llvm::createAliasAnalysisCounterPass() {
 
119
  return new AliasAnalysisCounter();
 
120
}
 
121
 
 
122
AliasAnalysis::AliasResult
 
123
AliasAnalysisCounter::alias(const Value *V1, unsigned V1Size,
 
124
                            const Value *V2, unsigned V2Size) {
 
125
  AliasResult R = getAnalysis<AliasAnalysis>().alias(V1, V1Size, V2, V2Size);
 
126
 
 
127
  const char *AliasString;
 
128
  switch (R) {
 
129
  default: llvm_unreachable("Unknown alias type!");
 
130
  case NoAlias:   No++;   AliasString = "No alias"; break;
 
131
  case MayAlias:  May++;  AliasString = "May alias"; break;
 
132
  case MustAlias: Must++; AliasString = "Must alias"; break;
 
133
  }
 
134
 
 
135
  if (PrintAll || (PrintAllFailures && R == MayAlias)) {
 
136
    errs() << AliasString << ":\t";
 
137
    errs() << "[" << V1Size << "B] ";
 
138
    WriteAsOperand(errs(), V1, true, M);
 
139
    errs() << ", ";
 
140
    errs() << "[" << V2Size << "B] ";
 
141
    WriteAsOperand(errs(), V2, true, M);
 
142
    errs() << "\n";
 
143
  }
 
144
 
 
145
  return R;
 
146
}
 
147
 
 
148
AliasAnalysis::ModRefResult
 
149
AliasAnalysisCounter::getModRefInfo(CallSite CS, Value *P, unsigned Size) {
 
150
  ModRefResult R = getAnalysis<AliasAnalysis>().getModRefInfo(CS, P, Size);
 
151
 
 
152
  const char *MRString;
 
153
  switch (R) {
 
154
  default:       llvm_unreachable("Unknown mod/ref type!");
 
155
  case NoModRef: NoMR++;     MRString = "NoModRef"; break;
 
156
  case Ref:      JustRef++;  MRString = "JustRef"; break;
 
157
  case Mod:      JustMod++;  MRString = "JustMod"; break;
 
158
  case ModRef:   MR++;       MRString = "ModRef"; break;
 
159
  }
 
160
 
 
161
  if (PrintAll || (PrintAllFailures && R == ModRef)) {
 
162
    errs() << MRString << ":  Ptr: ";
 
163
    errs() << "[" << Size << "B] ";
 
164
    WriteAsOperand(errs(), P, true, M);
 
165
    errs() << "\t<->" << *CS.getInstruction() << '\n';
 
166
  }
 
167
  return R;
 
168
}