Make classes in anonymous namespaces use VISIBILITY_HIDDEN to help reduce
[oota-llvm.git] / lib / Analysis / InstCount.cpp
1 //===-- InstCount.cpp - Collects the count of all instructions ------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source 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/Compiler.h"
19 #include "llvm/Support/InstVisitor.h"
20 #include "llvm/Support/Streams.h"
21 #include "llvm/ADT/Statistic.h"
22 #include <ostream>
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 VISIBILITY_HIDDEN InstCount 
38       : public FunctionPass, public InstVisitor<InstCount> {
39     friend class InstVisitor<InstCount>;
40
41     void visitFunction  (Function &F) { ++TotalFuncs; }
42     void visitBasicBlock(BasicBlock &BB) { ++TotalBlocks; }
43
44 #define HANDLE_INST(N, OPCODE, CLASS) \
45     void visit##OPCODE(CLASS &) { ++Num##OPCODE##Inst; ++TotalInsts; }
46
47 #include "llvm/Instruction.def"
48
49     void visitInstruction(Instruction &I) {
50       cerr << "Instruction Count does not know about " << I;
51       abort();
52     }
53   public:
54     virtual bool runOnFunction(Function &F);
55
56     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
57       AU.setPreservesAll();
58     }
59     virtual void print(std::ostream &O, const Module *M) const {}
60
61   };
62
63   RegisterPass<InstCount> X("instcount",
64                             "Counts the various types of Instructions");
65 }
66
67 FunctionPass *llvm::createInstCountPass() { return new InstCount(); }
68
69 // InstCount::run - This is the main Analysis entry point for a
70 // function.
71 //
72 bool InstCount::runOnFunction(Function &F) {
73   unsigned StartMemInsts =
74     NumGetElementPtrInst + NumLoadInst + NumStoreInst + NumCallInst +
75     NumInvokeInst + NumAllocaInst + NumMallocInst + NumFreeInst;
76   visit(F);
77   unsigned EndMemInsts =
78     NumGetElementPtrInst + NumLoadInst + NumStoreInst + NumCallInst +
79     NumInvokeInst + NumAllocaInst + NumMallocInst + NumFreeInst;
80   TotalMemInst += EndMemInsts-StartMemInsts;
81   return false;
82 }