MCPcopy Create free account
hub / github.com/banach-space/llvm-tutor / runOnModule

Method runOnModule

lib/StaticCallCounter.cpp:37–68  ·  view source on GitHub ↗

------------------------------------------------------------------------------ StaticCallCounter Implementation ------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

35// StaticCallCounter Implementation
36//------------------------------------------------------------------------------
37StaticCallCounter::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
70PreservedAnalyses
71StaticCallCounterPrinter::run(Module &M,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected