------------------------------------------------------------------------------ StaticCallCounter Implementation ------------------------------------------------------------------------------
| 35 | // StaticCallCounter Implementation |
| 36 | //------------------------------------------------------------------------------ |
| 37 | StaticCallCounter::Result StaticCallCounter::runOnModule(Module &M) { |
| 38 | llvm::MapVector<const llvm::Function *, unsigned> Res; |
| 39 | |
| 40 | for (auto &Func : M) { |
| 41 | for (auto &BB : Func) { |
| 42 | for (auto &Ins : BB) { |
| 43 | |
| 44 | // If this is a call instruction then CB will be not null. |
| 45 | auto *CB = dyn_cast<CallBase>(&Ins); |
| 46 | if (nullptr == CB) { |
| 47 | continue; |
| 48 | } |
| 49 | |
| 50 | // If CB is a direct function call then DirectInvoc will be not null. |
| 51 | auto DirectInvoc = CB->getCalledFunction(); |
| 52 | if (nullptr == DirectInvoc) { |
| 53 | continue; |
| 54 | } |
| 55 | |
| 56 | // We have a direct function call - update the count for the function |
| 57 | // being called. |
| 58 | auto CallCount = Res.find(DirectInvoc); |
| 59 | if (Res.end() == CallCount) { |
| 60 | CallCount = Res.insert(std::make_pair(DirectInvoc, 0)).first; |
| 61 | } |
| 62 | ++CallCount->second; |
| 63 | } |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | return Res; |
| 68 | } |
| 69 | |
| 70 | PreservedAnalyses |
| 71 | StaticCallCounterPrinter::run(Module &M, |
nothing calls this directly
no outgoing calls
no test coverage detected