Dinakar Dhurjati | a7be9a7 | 2002-11-13 18:22:13 +0000 | [diff] [blame] | 1 | //===-- InstCount.cpp - Collects the count of all instructions ------------===// |
| 2 | // |
| 3 | // This pass collects the count of all instructions and reports them |
| 4 | // |
Dinakar Dhurjati | a7be9a7 | 2002-11-13 18:22:13 +0000 | [diff] [blame] | 5 | //===----------------------------------------------------------------------===// |
| 6 | |
| 7 | #include "llvm/Pass.h" |
| 8 | #include "llvm/Module.h" |
Dinakar Dhurjati | a7be9a7 | 2002-11-13 18:22:13 +0000 | [diff] [blame] | 9 | #include "llvm/Support/InstVisitor.h" |
Dinakar Dhurjati | a7be9a7 | 2002-11-13 18:22:13 +0000 | [diff] [blame] | 10 | #include "Support/Statistic.h" |
Dinakar Dhurjati | a7be9a7 | 2002-11-13 18:22:13 +0000 | [diff] [blame] | 11 | |
| 12 | namespace { |
Chris Lattner | 5e05817 | 2002-12-03 19:40:16 +0000 | [diff] [blame] | 13 | #define HANDLE_INST(N, OPCODE, CLASS) \ |
| 14 | Statistic<> Num##OPCODE##Inst("instcount", "Number of " #OPCODE " insts"); |
Dinakar Dhurjati | a7be9a7 | 2002-11-13 18:22:13 +0000 | [diff] [blame] | 15 | |
Chris Lattner | 5e05817 | 2002-12-03 19:40:16 +0000 | [diff] [blame] | 16 | #include "llvm/Instruction.def" |
| 17 | |
Dinakar Dhurjati | a7be9a7 | 2002-11-13 18:22:13 +0000 | [diff] [blame] | 18 | class InstCount : public Pass, public InstVisitor<InstCount> { |
Chris Lattner | 5e05817 | 2002-12-03 19:40:16 +0000 | [diff] [blame] | 19 | friend class InstVisitor<InstCount>; |
Dinakar Dhurjati | a7be9a7 | 2002-11-13 18:22:13 +0000 | [diff] [blame] | 20 | |
Chris Lattner | 5e05817 | 2002-12-03 19:40:16 +0000 | [diff] [blame] | 21 | #define HANDLE_INST(N, OPCODE, CLASS) \ |
| 22 | void visit##OPCODE(CLASS &) { Num##OPCODE##Inst++; } |
Dinakar Dhurjati | a7be9a7 | 2002-11-13 18:22:13 +0000 | [diff] [blame] | 23 | |
Chris Lattner | 5e05817 | 2002-12-03 19:40:16 +0000 | [diff] [blame] | 24 | #include "llvm/Instruction.def" |
Dinakar Dhurjati | a7be9a7 | 2002-11-13 18:22:13 +0000 | [diff] [blame] | 25 | |
Chris Lattner | 5e05817 | 2002-12-03 19:40:16 +0000 | [diff] [blame] | 26 | void visitInstruction(Instruction &I) { |
Dinakar Dhurjati | a7be9a7 | 2002-11-13 18:22:13 +0000 | [diff] [blame] | 27 | std::cerr << "Instruction Count does not know about " << I; |
| 28 | abort(); |
| 29 | } |
| 30 | public: |
| 31 | virtual bool run(Module &M); |
| 32 | |
| 33 | virtual void getAnalysisUsage(AnalysisUsage &AU) const { |
| 34 | AU.setPreservesAll(); |
| 35 | } |
Chris Lattner | 5e05817 | 2002-12-03 19:40:16 +0000 | [diff] [blame] | 36 | virtual void print(std::ostream &O, Module *M) const {} |
| 37 | |
Dinakar Dhurjati | a7be9a7 | 2002-11-13 18:22:13 +0000 | [diff] [blame] | 38 | }; |
| 39 | |
Chris Lattner | 342f681 | 2002-11-17 22:15:40 +0000 | [diff] [blame] | 40 | RegisterAnalysis<InstCount> X("instcount", |
Chris Lattner | 5e05817 | 2002-12-03 19:40:16 +0000 | [diff] [blame] | 41 | "Counts the various types of Instructions"); |
Dinakar Dhurjati | a7be9a7 | 2002-11-13 18:22:13 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Dinakar Dhurjati | a7be9a7 | 2002-11-13 18:22:13 +0000 | [diff] [blame] | 44 | // InstCount::run - This is the main Analysis entry point for a |
| 45 | // function. |
| 46 | // |
| 47 | bool InstCount::run(Module &M) { |
Chris Lattner | 5e05817 | 2002-12-03 19:40:16 +0000 | [diff] [blame] | 48 | visit(M); |
Dinakar Dhurjati | a7be9a7 | 2002-11-13 18:22:13 +0000 | [diff] [blame] | 49 | return false; |
| 50 | } |