From 2091cc4310515fbb6ee866249497bfcd9357b26e Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 28 Oct 2003 21:25:23 +0000 Subject: [PATCH] Add support for reading block frequencies. Fix bug in attribution of counts to functions llvm-svn: 9559 --- llvm/tools/llvm-prof/ProfileInfo.cpp | 25 +++++++++++++++++++++++-- llvm/tools/llvm-prof/ProfileInfo.h | 13 +++++++++++++ llvm/tools/llvm-prof/llvm-prof.cpp | 12 ++++++++++++ 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/llvm/tools/llvm-prof/ProfileInfo.cpp b/llvm/tools/llvm-prof/ProfileInfo.cpp index 2341db0bb9f4..4c31138aa342 100644 --- a/llvm/tools/llvm-prof/ProfileInfo.cpp +++ b/llvm/tools/llvm-prof/ProfileInfo.cpp @@ -148,7 +148,28 @@ void ProfileInfo::getFunctionCounts(std::vectorisExternal()) - Counts.push_back(std::make_pair(I, FunctionCounts[Counter])); + Counts.push_back(std::make_pair(I, FunctionCounts[Counter++])); +} + +// getBlockCounts - This method is used by consumers of block counting +// information. If we do not directly have block count information, we +// compute it from other, more refined, types of profile information. +// +void ProfileInfo::getBlockCounts(std::vector > &Counts) { + if (BlockCounts.empty()) { + std::cerr << "Block counts not available, and no synthesis " + << "is implemented yet!\n"; + return; + } + + unsigned Counter = 0; + for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) + for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) { + Counts.push_back(std::make_pair(BB, BlockCounts[Counter++])); + if (Counter == BlockCounts.size()) + return; + } } diff --git a/llvm/tools/llvm-prof/ProfileInfo.h b/llvm/tools/llvm-prof/ProfileInfo.h index 360d5fa1c924..eab9bc9781c3 100644 --- a/llvm/tools/llvm-prof/ProfileInfo.h +++ b/llvm/tools/llvm-prof/ProfileInfo.h @@ -20,6 +20,7 @@ #include class Module; class Function; +class BasicBlock; class ProfileInfo { Module &M; @@ -37,6 +38,18 @@ public: // void getFunctionCounts(std::vector > &Counts); + // hasAccurateBlockCounts - Return true if we can synthesize accurate block + // frequency information from whatever we have. + // + bool hasAccurateBlockCounts() const { + return !BlockCounts.empty(); + } + + // getBlockCounts - This method is used by consumers of block counting + // information. If we do not directly have block count information, we + // compute it from other, more refined, types of profile information. + // + void getBlockCounts(std::vector > &Counts); }; #endif diff --git a/llvm/tools/llvm-prof/llvm-prof.cpp b/llvm/tools/llvm-prof/llvm-prof.cpp index cb907258e5d7..2b6730ec64a2 100644 --- a/llvm/tools/llvm-prof/llvm-prof.cpp +++ b/llvm/tools/llvm-prof/llvm-prof.cpp @@ -19,6 +19,7 @@ #include "Support/CommandLine.h" #include #include +#include namespace { cl::opt @@ -77,5 +78,16 @@ int main(int argc, char **argv) { for (unsigned i = 0, e = FunctionCounts.size(); i != e; ++i) printf("%3d. %5d/%d %s\n", i, FunctionCounts[i].second, TotalExecutions, FunctionCounts[i].first->getName().c_str()); + + + // If we have block count information, print out the LLVM module with + // frequency annotations. + if (PI.hasAccurateBlockCounts()) { + std::vector > Counts; + PI.getBlockCounts(Counts); + std::map BlockFreqs(Counts.begin(), Counts.end()); + + } + return 0; }