1 //===-- InstCount.cpp - Collects the count of all instructions ------------===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This pass collects the count of all instructions and reports them
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Pass.h"
15 #include "llvm/Function.h"
16 #include "llvm/Support/InstVisitor.h"
17 #include "llvm/ADT/Statistic.h"
22 Statistic<> TotalInsts ("instcount", "Number of instructions (of all types)");
23 Statistic<> TotalBlocks("instcount", "Number of basic blocks");
24 Statistic<> TotalFuncs ("instcount", "Number of non-external functions");
26 #define HANDLE_INST(N, OPCODE, CLASS) \
27 Statistic<> Num##OPCODE##Inst("instcount", "Number of " #OPCODE " insts");
29 #include "llvm/Instruction.def"
31 class InstCount : public FunctionPass, public InstVisitor<InstCount> {
32 friend class InstVisitor<InstCount>;
34 void visitFunction (Function &F) { ++TotalFuncs; }
35 void visitBasicBlock(BasicBlock &BB) { ++TotalBlocks; }
37 #define HANDLE_INST(N, OPCODE, CLASS) \
38 void visit##OPCODE(CLASS &) { ++Num##OPCODE##Inst; ++TotalInsts; }
40 #include "llvm/Instruction.def"
42 void visitInstruction(Instruction &I) {
43 std::cerr << "Instruction Count does not know about " << I;
47 virtual bool runOnFunction(Function &F);
49 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
52 virtual void print(std::ostream &O, const Module *M) const {}
56 RegisterAnalysis<InstCount> X("instcount",
57 "Counts the various types of Instructions");
60 // InstCount::run - This is the main Analysis entry point for a
63 bool InstCount::runOnFunction(Function &F) {
68 } // End llvm namespace