1+ #include " llvm/Transforms/BogomazovCount/BogomazovCount.h"
2+
3+
4+ #include " llvm/ADT/Statistic.h"
5+ #include " llvm/IR/InstIterator.h"
6+ #include " llvm/Analysis/LoopInfo.h"
7+
8+ #define DEBUG_TYPE " BogomazovCount"
9+
10+ using namespace llvm ;
11+
12+ ALWAYS_ENABLED_STATISTIC (F_count, " Number of functions" );
13+ ALWAYS_ENABLED_STATISTIC (BB_count, " BB amount" );
14+ ALWAYS_ENABLED_STATISTIC (OPS_count, " OPS amount" );
15+ ALWAYS_ENABLED_STATISTIC (loops_count, " Loops amount" );
16+
17+
18+ PreservedAnalyses BogomazovCountPass::run (Function &F, FunctionAnalysisManager &AM) {
19+ F_count ++;
20+
21+ for (auto BB = F.begin (); BB != F.end (); ++BB) {
22+ BB_count += 1 ;
23+ for (auto I = BB->begin (); I != BB->end (); ++I) {
24+ switch (I->getOpcode ()) {
25+ case Instruction::Add:
26+ OPS_count += 1 ;
27+ break ;
28+ case Instruction::FAdd:
29+ OPS_count += 1 ;
30+ break ;
31+ case Instruction::Mul:
32+ OPS_count += 1 ;
33+ break ;
34+ case Instruction::FDiv:
35+ OPS_count += 1 ;
36+ break ;
37+ case Instruction::SDiv:
38+ OPS_count += 1 ;
39+ break ;
40+ case Instruction::UDiv:
41+ OPS_count += 1 ;
42+ break ;
43+ case Instruction::Sub:
44+ OPS_count += 1 ;
45+ break ;
46+ case Instruction::FSub:
47+ OPS_count += 1 ;
48+ break ;
49+ }
50+ }
51+ }
52+
53+ auto & LA = AM.getResult <LoopAnalysis>(F);
54+ for (auto & L : LA) ++loops_count;
55+
56+ errs () << " Functions: " << F_count << " \n "
57+ << " BB: " << BB_count << " \n "
58+ << " OPS: " << OPS_count << " \n "
59+ << " Loops: " << loops_count << " \n " ;
60+
61+ return PreservedAnalyses::all ();
62+ }
0 commit comments