24 #define DEBUG_TYPE "instcount"
26 STATISTIC(TotalInsts ,
"Number of instructions (of all types)");
27 STATISTIC(TotalBlocks,
"Number of basic blocks");
28 STATISTIC(TotalFuncs ,
"Number of non-external functions");
29 STATISTIC(TotalMemInst,
"Number of memory instructions");
31 #define HANDLE_INST(N, OPCODE, CLASS) \
32 STATISTIC(Num ## OPCODE ## Inst, "Number of " #OPCODE " insts");
34 #include "llvm/IR/Instruction.def"
41 void visitFunction (
Function &
F) { ++TotalFuncs; }
42 void visitBasicBlock(
BasicBlock &BB) { ++TotalBlocks; }
44 #define HANDLE_INST(N, OPCODE, CLASS) \
45 void visit##OPCODE(CLASS &) { ++Num##OPCODE##Inst; ++TotalInsts; }
47 #include "llvm/IR/Instruction.def"
50 errs() <<
"Instruction Count does not know about " <<
I;
71 "Counts the various types of Instructions",
false,
true)
78 bool InstCount::runOnFunction(
Function &
F) {
79 unsigned StartMemInsts =
80 NumGetElementPtrInst + NumLoadInst + NumStoreInst + NumCallInst +
81 NumInvokeInst + NumAllocaInst;
83 unsigned EndMemInsts =
84 NumGetElementPtrInst + NumLoadInst + NumStoreInst + NumCallInst +
85 NumInvokeInst + NumAllocaInst;
86 TotalMemInst += EndMemInsts-StartMemInsts;
FunctionPass * createInstCountPass()
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Base class for instruction visitors.
STATISTIC(NumFunctions,"Total number of functions")
A Module instance is used to store all the information related to an LLVM module. ...
void initializeInstCountPass(PassRegistry &)
LLVM Basic Block Representation.
INITIALIZE_PASS(InstCount,"instcount","Counts the various types of Instructions", false, true) FunctionPass *llvm
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void setPreservesAll()
Set by analyses that do not transform their input at all.
This class implements an extremely fast bulk output stream that can only output to a stream...