Line | Count | Source |
1 | #include "parcoach/StatisticsAnalysis.h" | |
2 | ||
3 | #include "llvm/IR/InstIterator.h" | |
4 | ||
5 | using namespace llvm; | |
6 | namespace parcoach { | |
7 | AnalysisKey StatisticsAnalysis::Key; | |
8 | ||
9 | StatisticsAnalysis::Statistics | |
10 | 1 | StatisticsAnalysis::run(Module &M, ModuleAnalysisManager & /*unused*/) { |
11 | 1 | TimeTraceScope TTS("StatisticsAnalysis"); |
12 | 1 | Statistics Res{}; |
13 | 62 | auto IsCallInst = [](Instruction const &I) { return isa<CallInst>(I); }; |
14 | 11 | for (Function const &F : M) { |
15 | 11 | Res.Functions++; |
16 | 18 | for (auto const &I : make_filter_range(instructions(F), IsCallInst)) { |
17 | 18 | CallInst const &CI = cast<CallInst>(I); |
18 | 18 | if (CI.getCalledFunction()) { |
19 | 17 | Res.DirectCalls++; |
20 | 17 | } else { |
21 | 1 | Res.IndirectCalls++; |
22 | 1 | } |
23 | 18 | } |
24 | 11 | } |
25 | 1 | return Res; |
26 | 1 | } |
27 | ||
28 | 1 | void StatisticsAnalysis::Statistics::print(raw_ostream &Out) const { |
29 | 1 | Out << "nb functions : " << Functions << "\n"; |
30 | 1 | Out << "nb direct calls : " << DirectCalls << "\n"; |
31 | 1 | Out << "nb indirect calls : " << IndirectCalls << "\n"; |
32 | 1 | } |
33 | } // namespace parcoach |