~louis/ubuntu/trusty/clamav/lp799623_fix_logrotate

« back to all changes in this revision

Viewing changes to libclamav/c++/llvm/lib/Analysis/InstCount.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
//===-- InstCount.cpp - Collects the count of all instructions ------------===//
 
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 pass collects the count of all instructions and reports them
 
11
//
 
12
//===----------------------------------------------------------------------===//
 
13
 
 
14
#define DEBUG_TYPE "instcount"
 
15
#include "llvm/Analysis/Passes.h"
 
16
#include "llvm/Pass.h"
 
17
#include "llvm/Function.h"
 
18
#include "llvm/Support/Debug.h"
 
19
#include "llvm/Support/ErrorHandling.h"
 
20
#include "llvm/Support/InstVisitor.h"
 
21
#include "llvm/Support/raw_ostream.h"
 
22
#include "llvm/ADT/Statistic.h"
 
23
using namespace llvm;
 
24
 
 
25
STATISTIC(TotalInsts , "Number of instructions (of all types)");
 
26
STATISTIC(TotalBlocks, "Number of basic blocks");
 
27
STATISTIC(TotalFuncs , "Number of non-external functions");
 
28
STATISTIC(TotalMemInst, "Number of memory instructions");
 
29
 
 
30
#define HANDLE_INST(N, OPCODE, CLASS) \
 
31
  STATISTIC(Num ## OPCODE ## Inst, "Number of " #OPCODE " insts");
 
32
 
 
33
#include "llvm/Instruction.def"
 
34
 
 
35
 
 
36
namespace {
 
37
  class InstCount : public FunctionPass, public InstVisitor<InstCount> {
 
38
    friend class InstVisitor<InstCount>;
 
39
 
 
40
    void visitFunction  (Function &F) { ++TotalFuncs; }
 
41
    void visitBasicBlock(BasicBlock &BB) { ++TotalBlocks; }
 
42
 
 
43
#define HANDLE_INST(N, OPCODE, CLASS) \
 
44
    void visit##OPCODE(CLASS &) { ++Num##OPCODE##Inst; ++TotalInsts; }
 
45
 
 
46
#include "llvm/Instruction.def"
 
47
 
 
48
    void visitInstruction(Instruction &I) {
 
49
      errs() << "Instruction Count does not know about " << I;
 
50
      llvm_unreachable(0);
 
51
    }
 
52
  public:
 
53
    static char ID; // Pass identification, replacement for typeid
 
54
    InstCount() : FunctionPass(&ID) {}
 
55
 
 
56
    virtual bool runOnFunction(Function &F);
 
57
 
 
58
    virtual void getAnalysisUsage(AnalysisUsage &AU) const {
 
59
      AU.setPreservesAll();
 
60
    }
 
61
    virtual void print(raw_ostream &O, const Module *M) const {}
 
62
 
 
63
  };
 
64
}
 
65
 
 
66
char InstCount::ID = 0;
 
67
static RegisterPass<InstCount>
 
68
X("instcount", "Counts the various types of Instructions", false, true);
 
69
 
 
70
FunctionPass *llvm::createInstCountPass() { return new InstCount(); }
 
71
 
 
72
// InstCount::run - This is the main Analysis entry point for a
 
73
// function.
 
74
//
 
75
bool InstCount::runOnFunction(Function &F) {
 
76
  unsigned StartMemInsts =
 
77
    NumGetElementPtrInst + NumLoadInst + NumStoreInst + NumCallInst +
 
78
    NumInvokeInst + NumAllocaInst;
 
79
  visit(F);
 
80
  unsigned EndMemInsts =
 
81
    NumGetElementPtrInst + NumLoadInst + NumStoreInst + NumCallInst +
 
82
    NumInvokeInst + NumAllocaInst;
 
83
  TotalMemInst += EndMemInsts-StartMemInsts;
 
84
  return false;
 
85
}