diff options
author | Chris Lattner <sabre@nondot.org> | 2004-03-08 20:04:32 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-03-08 20:04:32 +0000 |
commit | 8c2730e347092e2c62ddb8442252e694bc498aa0 (patch) | |
tree | 47b534cce5437df152b4598700fae1dcf4e0dd58 /tools | |
parent | dbbbfef165ef730977d948e58b226e1bd8f450d4 (diff) | |
download | external_llvm-8c2730e347092e2c62ddb8442252e694bc498aa0.zip external_llvm-8c2730e347092e2c62ddb8442252e694bc498aa0.tar.gz external_llvm-8c2730e347092e2c62ddb8442252e694bc498aa0.tar.bz2 |
Annotate functions with edge counts as well, if they are available.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@12233 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools')
-rw-r--r-- | tools/llvm-prof/llvm-prof.cpp | 45 |
1 files changed, 39 insertions, 6 deletions
diff --git a/tools/llvm-prof/llvm-prof.cpp b/tools/llvm-prof/llvm-prof.cpp index 2a7789d..3288a4d 100644 --- a/tools/llvm-prof/llvm-prof.cpp +++ b/tools/llvm-prof/llvm-prof.cpp @@ -13,6 +13,7 @@ // //===----------------------------------------------------------------------===// +#include "llvm/InstrTypes.h" #include "llvm/Module.h" #include "llvm/Assembly/AsmAnnotationWriter.h" #include "llvm/Analysis/ProfileInfoLoader.h" @@ -59,21 +60,46 @@ namespace { class ProfileAnnotator : public AssemblyAnnotationWriter { std::map<const Function *, unsigned> &FuncFreqs; std::map<const BasicBlock*, unsigned> &BlockFreqs; + std::map<ProfileInfoLoader::Edge, unsigned> &EdgeFreqs; public: ProfileAnnotator(std::map<const Function *, unsigned> &FF, - std::map<const BasicBlock*, unsigned> &BF) - : FuncFreqs(FF), BlockFreqs(BF) {} + std::map<const BasicBlock*, unsigned> &BF, + std::map<ProfileInfoLoader::Edge, unsigned> &EF) + : FuncFreqs(FF), BlockFreqs(BF), EdgeFreqs(EF) {} virtual void emitFunctionAnnot(const Function *F, std::ostream &OS) { OS << ";;; %" << F->getName() << " called " << FuncFreqs[F] << " times.\n;;;\n"; } - virtual void emitBasicBlockAnnot(const BasicBlock *BB, std::ostream &OS) { + virtual void emitBasicBlockStartAnnot(const BasicBlock *BB, + std::ostream &OS) { if (BlockFreqs.empty()) return; if (unsigned Count = BlockFreqs[BB]) - OS << ";;; Executed " << Count << " times.\n"; + OS << "\t;;; Basic block executed " << Count << " times.\n"; else - OS << ";;; Never executed!\n"; + OS << "\t;;; Never executed!\n"; + } + + virtual void emitBasicBlockEndAnnot(const BasicBlock *BB, std::ostream &OS){ + if (EdgeFreqs.empty()) return; + + // Figure out how many times each successor executed. + std::vector<std::pair<const BasicBlock*, unsigned> > SuccCounts; + const TerminatorInst *TI = BB->getTerminator(); + + std::map<ProfileInfoLoader::Edge, unsigned>::iterator I = + EdgeFreqs.lower_bound(std::make_pair(const_cast<BasicBlock*>(BB), 0U)); + for (; I != EdgeFreqs.end() && I->first.first == BB; ++I) + if (I->second) + SuccCounts.push_back(std::make_pair(TI->getSuccessor(I->first.second), + I->second)); + if (!SuccCounts.empty()) { + OS << "\t;;; Out-edge counts:"; + for (unsigned i = 0, e = SuccCounts.size(); i != e; ++i) + OS << " [" << SuccCounts[i].second << " -> " + << SuccCounts[i].first->getName() << "]"; + OS << "\n"; + } } }; } @@ -97,6 +123,7 @@ int main(int argc, char **argv) { std::map<const Function *, unsigned> FuncFreqs; std::map<const BasicBlock*, unsigned> BlockFreqs; + std::map<ProfileInfoLoader::Edge, unsigned> EdgeFreqs; // Output a report. Eventually, there will be multiple reports selectable on // the command line, for now, just keep things simple. @@ -177,11 +204,17 @@ int main(int argc, char **argv) { BlockFreqs.insert(Counts.begin(), Counts.end()); } + if (PI.hasAccurateEdgeCounts()) { + std::vector<std::pair<ProfileInfoLoader::Edge, unsigned> > Counts; + PI.getEdgeCounts(Counts); + EdgeFreqs.insert(Counts.begin(), Counts.end()); + } + if (PrintAnnotatedLLVM || PrintAllCode) { std::cout << "\n===" << std::string(73, '-') << "===\n"; std::cout << "Annotated LLVM code for the module:\n\n"; - ProfileAnnotator PA(FuncFreqs, BlockFreqs); + ProfileAnnotator PA(FuncFreqs, BlockFreqs, EdgeFreqs); if (FunctionsToPrint.empty() || PrintAllCode) M->print(std::cout, &PA); |