1 //===-- InstCount.cpp - Collects the count of all instructions ------------===//
3 // This pass collects the count of all instructions and reports them
5 //===----------------------------------------------------------------------===//
8 #include "llvm/Module.h"
9 #include "llvm/Support/InstVisitor.h"
10 #include "Support/Statistic.h"
13 Statistic<> TotalInsts ("instcount", "Number of instructions (of all types)");
14 Statistic<> TotalBlocks("instcount", "Number of basic blocks");
15 Statistic<> TotalFuncs ("instcount", "Number of non-external functions");
17 #define HANDLE_INST(N, OPCODE, CLASS) \
18 Statistic<> Num##OPCODE##Inst("instcount", "Number of " #OPCODE " insts");
20 #include "llvm/Instruction.def"
22 class InstCount : public Pass, public InstVisitor<InstCount> {
23 friend class InstVisitor<InstCount>;
25 void visitFunction (Function &F) { ++TotalFuncs; }
26 void visitBasicBlock(BasicBlock &BB) { ++TotalBlocks; }
28 #define HANDLE_INST(N, OPCODE, CLASS) \
29 void visit##OPCODE(CLASS &) { ++Num##OPCODE##Inst; ++TotalInsts; }
31 #include "llvm/Instruction.def"
33 void visitInstruction(Instruction &I) {
34 std::cerr << "Instruction Count does not know about " << I;
38 virtual bool run(Module &M);
40 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
43 virtual void print(std::ostream &O, const Module *M) const {}
47 RegisterAnalysis<InstCount> X("instcount",
48 "Counts the various types of Instructions");
51 // InstCount::run - This is the main Analysis entry point for a
54 bool InstCount::run(Module &M) {