mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-13 20:32:21 +00:00
Remove unnecessary ProfileInfoLoader methods.
- Part of optimal static profiling patch sequence by Andreas Neustifter. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78199 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
96a0a02119
commit
ee16638bfc
@ -27,6 +27,7 @@ class Function;
|
|||||||
class BasicBlock;
|
class BasicBlock;
|
||||||
|
|
||||||
class ProfileInfoLoader {
|
class ProfileInfoLoader {
|
||||||
|
const std::string &Filename;
|
||||||
Module &M;
|
Module &M;
|
||||||
std::vector<std::string> CommandLines;
|
std::vector<std::string> CommandLines;
|
||||||
std::vector<unsigned> FunctionCounts;
|
std::vector<unsigned> FunctionCounts;
|
||||||
@ -43,46 +44,28 @@ public:
|
|||||||
unsigned getNumExecutions() const { return CommandLines.size(); }
|
unsigned getNumExecutions() const { return CommandLines.size(); }
|
||||||
const std::string &getExecution(unsigned i) const { return CommandLines[i]; }
|
const std::string &getExecution(unsigned i) const { return CommandLines[i]; }
|
||||||
|
|
||||||
// getFunctionCounts - This method is used by consumers of function counting
|
const std::string &getFileName() const { return Filename; }
|
||||||
// information. If we do not directly have function count information, we
|
|
||||||
// compute it from other, more refined, types of profile information.
|
|
||||||
//
|
|
||||||
void getFunctionCounts(std::vector<std::pair<Function*, unsigned> > &Counts);
|
|
||||||
|
|
||||||
// hasAccurateBlockCounts - Return true if we can synthesize accurate block
|
// getRawFunctionCounts - This method is used by consumers of function
|
||||||
// frequency information from whatever we have.
|
// counting information.
|
||||||
//
|
//
|
||||||
bool hasAccurateBlockCounts() const {
|
const std::vector<unsigned> &getRawFunctionCounts() const {
|
||||||
return !BlockCounts.empty() || !EdgeCounts.empty();
|
return FunctionCounts;
|
||||||
}
|
}
|
||||||
|
|
||||||
// hasAccurateEdgeCounts - Return true if we can synthesize accurate edge
|
// getRawBlockCounts - This method is used by consumers of block counting
|
||||||
// frequency information from whatever we have.
|
|
||||||
//
|
|
||||||
bool hasAccurateEdgeCounts() const {
|
|
||||||
return !EdgeCounts.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<std::pair<BasicBlock*, unsigned> > &Counts);
|
|
||||||
|
|
||||||
// getEdgeCounts - This method is used by consumers of edge counting
|
|
||||||
// information. If we do not directly have edge count information, we compute
|
|
||||||
// it from other, more refined, types of profile information.
|
|
||||||
//
|
|
||||||
// Edges are represented as a pair, where the first element is the basic block
|
|
||||||
// and the second element is the successor number.
|
|
||||||
//
|
|
||||||
typedef std::pair<BasicBlock*, unsigned> Edge;
|
|
||||||
void getEdgeCounts(std::vector<std::pair<Edge, unsigned> > &Counts);
|
|
||||||
|
|
||||||
// getBBTrace - This method is used by consumers of basic-block trace
|
|
||||||
// information.
|
// information.
|
||||||
//
|
//
|
||||||
void getBBTrace(std::vector<BasicBlock *> &Trace);
|
const std::vector<unsigned> &getRawBlockCounts() const {
|
||||||
|
return BlockCounts;
|
||||||
|
}
|
||||||
|
|
||||||
|
// getEdgeCounts - This method is used by consumers of edge counting
|
||||||
|
// information.
|
||||||
|
//
|
||||||
|
const std::vector<unsigned> &getRawEdgeCounts() const {
|
||||||
|
return EdgeCounts;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // End llvm namespace
|
} // End llvm namespace
|
||||||
|
@ -73,8 +73,9 @@ static void ReadProfilingBlock(const char *ToolName, FILE *F,
|
|||||||
//
|
//
|
||||||
ProfileInfoLoader::ProfileInfoLoader(const char *ToolName,
|
ProfileInfoLoader::ProfileInfoLoader(const char *ToolName,
|
||||||
const std::string &Filename,
|
const std::string &Filename,
|
||||||
Module &TheModule) :
|
Module &TheModule) :
|
||||||
M(TheModule), Warned(false) {
|
Filename(Filename),
|
||||||
|
M(TheModule), Warned(false) {
|
||||||
FILE *F = fopen(Filename.c_str(), "r");
|
FILE *F = fopen(Filename.c_str(), "r");
|
||||||
if (F == 0) {
|
if (F == 0) {
|
||||||
cerr << ToolName << ": Error opening '" << Filename << "': ";
|
cerr << ToolName << ": Error opening '" << Filename << "': ";
|
||||||
@ -139,139 +140,3 @@ ProfileInfoLoader::ProfileInfoLoader(const char *ToolName,
|
|||||||
fclose(F);
|
fclose(F);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// getFunctionCounts - This method is used by consumers of function counting
|
|
||||||
// information. If we do not directly have function count information, we
|
|
||||||
// compute it from other, more refined, types of profile information.
|
|
||||||
//
|
|
||||||
void ProfileInfoLoader::getFunctionCounts(std::vector<std::pair<Function*,
|
|
||||||
unsigned> > &Counts) {
|
|
||||||
if (FunctionCounts.empty()) {
|
|
||||||
if (hasAccurateBlockCounts()) {
|
|
||||||
// Synthesize function frequency information from the number of times
|
|
||||||
// their entry blocks were executed.
|
|
||||||
std::vector<std::pair<BasicBlock*, unsigned> > BlockCounts;
|
|
||||||
getBlockCounts(BlockCounts);
|
|
||||||
|
|
||||||
for (unsigned i = 0, e = BlockCounts.size(); i != e; ++i)
|
|
||||||
if (&BlockCounts[i].first->getParent()->getEntryBlock() ==
|
|
||||||
BlockCounts[i].first)
|
|
||||||
Counts.push_back(std::make_pair(BlockCounts[i].first->getParent(),
|
|
||||||
BlockCounts[i].second));
|
|
||||||
} else {
|
|
||||||
cerr << "Function counts are not available!\n";
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned Counter = 0;
|
|
||||||
for (Module::iterator I = M.begin(), E = M.end();
|
|
||||||
I != E && Counter != FunctionCounts.size(); ++I)
|
|
||||||
if (!I->isDeclaration())
|
|
||||||
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 ProfileInfoLoader::getBlockCounts(std::vector<std::pair<BasicBlock*,
|
|
||||||
unsigned> > &Counts) {
|
|
||||||
if (BlockCounts.empty()) {
|
|
||||||
if (hasAccurateEdgeCounts()) {
|
|
||||||
// Synthesize block count information from edge frequency information.
|
|
||||||
// The block execution frequency is equal to the sum of the execution
|
|
||||||
// frequency of all outgoing edges from a block.
|
|
||||||
//
|
|
||||||
// If a block has no successors, this will not be correct, so we have to
|
|
||||||
// special case it. :(
|
|
||||||
std::vector<std::pair<Edge, unsigned> > EdgeCounts;
|
|
||||||
getEdgeCounts(EdgeCounts);
|
|
||||||
|
|
||||||
std::map<BasicBlock*, unsigned> InEdgeFreqs;
|
|
||||||
|
|
||||||
BasicBlock *LastBlock = 0;
|
|
||||||
TerminatorInst *TI = 0;
|
|
||||||
for (unsigned i = 0, e = EdgeCounts.size(); i != e; ++i) {
|
|
||||||
if (EdgeCounts[i].first.first != LastBlock) {
|
|
||||||
LastBlock = EdgeCounts[i].first.first;
|
|
||||||
TI = LastBlock->getTerminator();
|
|
||||||
Counts.push_back(std::make_pair(LastBlock, 0));
|
|
||||||
}
|
|
||||||
Counts.back().second += EdgeCounts[i].second;
|
|
||||||
unsigned SuccNum = EdgeCounts[i].first.second;
|
|
||||||
if (SuccNum >= TI->getNumSuccessors()) {
|
|
||||||
if (!Warned) {
|
|
||||||
cerr << "WARNING: profile info doesn't seem to match"
|
|
||||||
<< " the program!\n";
|
|
||||||
Warned = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// If this successor has no successors of its own, we will never
|
|
||||||
// compute an execution count for that block. Remember the incoming
|
|
||||||
// edge frequencies to add later.
|
|
||||||
BasicBlock *Succ = TI->getSuccessor(SuccNum);
|
|
||||||
if (Succ->getTerminator()->getNumSuccessors() == 0)
|
|
||||||
InEdgeFreqs[Succ] += EdgeCounts[i].second;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now we have to accumulate information for those blocks without
|
|
||||||
// successors into our table.
|
|
||||||
for (std::map<BasicBlock*, unsigned>::iterator I = InEdgeFreqs.begin(),
|
|
||||||
E = InEdgeFreqs.end(); I != E; ++I) {
|
|
||||||
unsigned i = 0;
|
|
||||||
for (; i != Counts.size() && Counts[i].first != I->first; ++i)
|
|
||||||
/*empty*/;
|
|
||||||
if (i == Counts.size()) Counts.push_back(std::make_pair(I->first, 0));
|
|
||||||
Counts[i].second += I->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
cerr << "Block counts are not available!\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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// getEdgeCounts - This method is used by consumers of edge counting
|
|
||||||
// information. If we do not directly have edge count information, we compute
|
|
||||||
// it from other, more refined, types of profile information.
|
|
||||||
//
|
|
||||||
void ProfileInfoLoader::getEdgeCounts(std::vector<std::pair<Edge,
|
|
||||||
unsigned> > &Counts) {
|
|
||||||
if (EdgeCounts.empty()) {
|
|
||||||
cerr << "Edge 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)
|
|
||||||
for (unsigned i = 0, e = BB->getTerminator()->getNumSuccessors();
|
|
||||||
i != e; ++i) {
|
|
||||||
Counts.push_back(std::make_pair(Edge(BB, i), EdgeCounts[Counter++]));
|
|
||||||
if (Counter == EdgeCounts.size())
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// getBBTrace - This method is used by consumers of basic-block trace
|
|
||||||
// information.
|
|
||||||
//
|
|
||||||
void ProfileInfoLoader::getBBTrace(std::vector<BasicBlock *> &Trace) {
|
|
||||||
if (BBTrace.empty ()) {
|
|
||||||
cerr << "Basic block trace is not available!\n";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
cerr << "Basic block trace loading is not implemented yet!\n";
|
|
||||||
}
|
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
#include "llvm/BasicBlock.h"
|
#include "llvm/BasicBlock.h"
|
||||||
#include "llvm/InstrTypes.h"
|
#include "llvm/InstrTypes.h"
|
||||||
|
#include "llvm/Module.h"
|
||||||
#include "llvm/Pass.h"
|
#include "llvm/Pass.h"
|
||||||
#include "llvm/Analysis/Passes.h"
|
#include "llvm/Analysis/Passes.h"
|
||||||
#include "llvm/Analysis/ProfileInfo.h"
|
#include "llvm/Analysis/ProfileInfo.h"
|
||||||
@ -69,23 +70,25 @@ Pass *llvm::createProfileLoaderPass(const std::string &Filename) {
|
|||||||
bool LoaderPass::runOnModule(Module &M) {
|
bool LoaderPass::runOnModule(Module &M) {
|
||||||
ProfileInfoLoader PIL("profile-loader", Filename, M);
|
ProfileInfoLoader PIL("profile-loader", Filename, M);
|
||||||
EdgeCounts.clear();
|
EdgeCounts.clear();
|
||||||
bool PrintedWarning = false;
|
|
||||||
|
|
||||||
std::vector<std::pair<ProfileInfoLoader::Edge, unsigned> > ECs;
|
std::vector<unsigned> ECs = PIL.getRawEdgeCounts();
|
||||||
PIL.getEdgeCounts(ECs);
|
// Instrument all of the edges...
|
||||||
for (unsigned i = 0, e = ECs.size(); i != e; ++i) {
|
unsigned i = 0;
|
||||||
BasicBlock *BB = ECs[i].first.first;
|
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F)
|
||||||
unsigned SuccNum = ECs[i].first.second;
|
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
|
||||||
TerminatorInst *TI = BB->getTerminator();
|
// Okay, we have to add a counter of each outgoing edge. If the
|
||||||
if (SuccNum >= TI->getNumSuccessors()) {
|
// outgoing edge is not critical don't split it, just insert the counter
|
||||||
if (!PrintedWarning) {
|
// in the source or destination of the edge.
|
||||||
cerr << "WARNING: profile information is inconsistent with "
|
TerminatorInst *TI = BB->getTerminator();
|
||||||
<< "the current program!\n";
|
for (unsigned s = 0, e = TI->getNumSuccessors(); s != e; ++s) {
|
||||||
PrintedWarning = true;
|
if (i < ECs.size())
|
||||||
|
EdgeCounts[std::make_pair(BB, TI->getSuccessor(s))]+= ECs[i++];
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
EdgeCounts[std::make_pair(BB, TI->getSuccessor(SuccNum))]+= ECs[i].second;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (i != ECs.size()) {
|
||||||
|
cerr << "WARNING: profile information is inconsistent with "
|
||||||
|
<< "the current program!\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "llvm/Assembly/AsmAnnotationWriter.h"
|
#include "llvm/Assembly/AsmAnnotationWriter.h"
|
||||||
#include "llvm/Analysis/ProfileInfo.h"
|
#include "llvm/Analysis/ProfileInfo.h"
|
||||||
#include "llvm/Analysis/ProfileInfoLoader.h"
|
#include "llvm/Analysis/ProfileInfoLoader.h"
|
||||||
|
#include "llvm/Analysis/Passes.h"
|
||||||
#include "llvm/Bitcode/ReaderWriter.h"
|
#include "llvm/Bitcode/ReaderWriter.h"
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
#include "llvm/Support/ManagedStatic.h"
|
#include "llvm/Support/ManagedStatic.h"
|
||||||
@ -67,48 +68,38 @@ struct PairSecondSortReverse
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
class ProfileAnnotator : public AssemblyAnnotationWriter {
|
class ProfileAnnotator : public AssemblyAnnotationWriter {
|
||||||
std::map<const Function *, unsigned> &FuncFreqs;
|
ProfileInfo &PI;
|
||||||
std::map<const BasicBlock*, unsigned> &BlockFreqs;
|
|
||||||
std::map<ProfileInfoLoader::Edge, unsigned> &EdgeFreqs;
|
|
||||||
public:
|
public:
|
||||||
ProfileAnnotator(std::map<const Function *, unsigned> &FF,
|
ProfileAnnotator(ProfileInfo& pi) : PI(pi) {}
|
||||||
std::map<const BasicBlock*, unsigned> &BF,
|
|
||||||
std::map<ProfileInfoLoader::Edge, unsigned> &EF)
|
|
||||||
: FuncFreqs(FF), BlockFreqs(BF), EdgeFreqs(EF) {}
|
|
||||||
|
|
||||||
virtual void emitFunctionAnnot(const Function *F, raw_ostream &OS) {
|
virtual void emitFunctionAnnot(const Function *F, raw_ostream &OS) {
|
||||||
OS << ";;; %" << F->getName() << " called " << FuncFreqs[F]
|
OS << ";;; %" << F->getName() << " called " << PI.getExecutionCount(F)
|
||||||
<< " times.\n;;;\n";
|
<< " times.\n;;;\n";
|
||||||
}
|
}
|
||||||
virtual void emitBasicBlockStartAnnot(const BasicBlock *BB,
|
virtual void emitBasicBlockStartAnnot(const BasicBlock *BB,
|
||||||
raw_ostream &OS) {
|
raw_ostream &OS) {
|
||||||
if (BlockFreqs.empty()) return;
|
unsigned w = PI.getExecutionCount(BB);
|
||||||
std::map<const BasicBlock *, unsigned>::const_iterator I =
|
if (w != 0)
|
||||||
BlockFreqs.find(BB);
|
OS << "\t;;; Basic block executed " << w << " times.\n";
|
||||||
if (I != BlockFreqs.end())
|
|
||||||
OS << "\t;;; Basic block executed " << I->second << " times.\n";
|
|
||||||
else
|
else
|
||||||
OS << "\t;;; Never executed!\n";
|
OS << "\t;;; Never executed!\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void emitBasicBlockEndAnnot(const BasicBlock *BB, raw_ostream &OS) {
|
virtual void emitBasicBlockEndAnnot(const BasicBlock *BB, raw_ostream &OS) {
|
||||||
if (EdgeFreqs.empty()) return;
|
|
||||||
|
|
||||||
// Figure out how many times each successor executed.
|
// Figure out how many times each successor executed.
|
||||||
std::vector<std::pair<const BasicBlock*, unsigned> > SuccCounts;
|
std::vector<std::pair<ProfileInfo::Edge, unsigned> > SuccCounts;
|
||||||
const TerminatorInst *TI = BB->getTerminator();
|
|
||||||
|
|
||||||
std::map<ProfileInfoLoader::Edge, unsigned>::iterator I =
|
const TerminatorInst *TI = BB->getTerminator();
|
||||||
EdgeFreqs.lower_bound(std::make_pair(const_cast<BasicBlock*>(BB), 0U));
|
for (unsigned s = 0, e = TI->getNumSuccessors(); s != e; ++s) {
|
||||||
for (; I != EdgeFreqs.end() && I->first.first == BB; ++I)
|
BasicBlock* Succ = TI->getSuccessor(s);
|
||||||
if (I->second)
|
SuccCounts.push_back(std::make_pair(std::make_pair(BB,Succ),
|
||||||
SuccCounts.push_back(std::make_pair(TI->getSuccessor(I->first.second),
|
PI.getEdgeWeight(BB,Succ)));
|
||||||
I->second));
|
}
|
||||||
if (!SuccCounts.empty()) {
|
if (!SuccCounts.empty()) {
|
||||||
OS << "\t;;; Out-edge counts:";
|
OS << "\t;;; Out-edge counts:";
|
||||||
for (unsigned i = 0, e = SuccCounts.size(); i != e; ++i)
|
for (unsigned i = 0, e = SuccCounts.size(); i != e; ++i)
|
||||||
OS << " [" << SuccCounts[i].second << " -> "
|
OS << " [" << (SuccCounts[i]).second << " -> "
|
||||||
<< SuccCounts[i].first->getName() << "]";
|
<< (SuccCounts[i]).first.second->getName() << "]";
|
||||||
OS << "\n";
|
OS << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -139,17 +130,26 @@ namespace {
|
|||||||
char ProfileInfoPrinterPass::ID = 0;
|
char ProfileInfoPrinterPass::ID = 0;
|
||||||
|
|
||||||
bool ProfileInfoPrinterPass::runOnModule(Module &M) {
|
bool ProfileInfoPrinterPass::runOnModule(Module &M) {
|
||||||
|
ProfileInfo &PI = getAnalysis<ProfileInfo>();
|
||||||
std::map<const Function *, unsigned> FuncFreqs;
|
std::map<const Function *, unsigned> FuncFreqs;
|
||||||
std::map<const BasicBlock*, unsigned> BlockFreqs;
|
std::map<const BasicBlock*, unsigned> BlockFreqs;
|
||||||
std::map<ProfileInfoLoader::Edge, unsigned> EdgeFreqs;
|
std::map<ProfileInfo::Edge, unsigned> EdgeFreqs;
|
||||||
|
|
||||||
// Output a report. Eventually, there will be multiple reports selectable on
|
// Output a report. Eventually, there will be multiple reports selectable on
|
||||||
// the command line, for now, just keep things simple.
|
// the command line, for now, just keep things simple.
|
||||||
|
|
||||||
// Emit the most frequent function table...
|
// Emit the most frequent function table...
|
||||||
std::vector<std::pair<Function*, unsigned> > FunctionCounts;
|
std::vector<std::pair<Function*, unsigned> > FunctionCounts;
|
||||||
PIL.getFunctionCounts(FunctionCounts);
|
std::vector<std::pair<BasicBlock*, unsigned> > Counts;
|
||||||
FuncFreqs.insert(FunctionCounts.begin(), FunctionCounts.end());
|
for (Module::iterator FI = M.begin(), FE = M.end(); FI != FE; ++FI) {
|
||||||
|
unsigned w = PI.getExecutionCount(FI);
|
||||||
|
if (w != (unsigned) -1)
|
||||||
|
FunctionCounts.push_back(std::make_pair(FI,PI.getExecutionCount(FI)));
|
||||||
|
for (Function::iterator BB = FI->begin(), BBE = FI->end();
|
||||||
|
BB != BBE; ++BB) {
|
||||||
|
Counts.push_back(std::make_pair(BB,PI.getExecutionCount(BB)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Sort by the frequency, backwards.
|
// Sort by the frequency, backwards.
|
||||||
sort(FunctionCounts.begin(), FunctionCounts.end(),
|
sort(FunctionCounts.begin(), FunctionCounts.end(),
|
||||||
@ -190,54 +190,39 @@ bool ProfileInfoPrinterPass::runOnModule(Module &M) {
|
|||||||
|
|
||||||
std::set<Function*> FunctionsToPrint;
|
std::set<Function*> FunctionsToPrint;
|
||||||
|
|
||||||
// If we have block count information, print out the LLVM module with
|
TotalExecutions = 0;
|
||||||
// frequency annotations.
|
for (unsigned i = 0, e = Counts.size(); i != e; ++i)
|
||||||
if (PIL.hasAccurateBlockCounts()) {
|
TotalExecutions += Counts[i].second;
|
||||||
std::vector<std::pair<BasicBlock*, unsigned> > Counts;
|
|
||||||
PIL.getBlockCounts(Counts);
|
// Sort by the frequency, backwards.
|
||||||
|
sort(Counts.begin(), Counts.end(),
|
||||||
TotalExecutions = 0;
|
PairSecondSortReverse<BasicBlock*>());
|
||||||
for (unsigned i = 0, e = Counts.size(); i != e; ++i)
|
|
||||||
TotalExecutions += Counts[i].second;
|
std::cout << "\n===" << std::string(73, '-') << "===\n";
|
||||||
|
std::cout << "Top 20 most frequently executed basic blocks:\n\n";
|
||||||
// Sort by the frequency, backwards.
|
|
||||||
sort(Counts.begin(), Counts.end(),
|
// Print out the function frequencies...
|
||||||
PairSecondSortReverse<BasicBlock*>());
|
std::cout <<" ## %% \tFrequency\n";
|
||||||
|
unsigned BlocksToPrint = Counts.size();
|
||||||
std::cout << "\n===" << std::string(73, '-') << "===\n";
|
if (BlocksToPrint > 20) BlocksToPrint = 20;
|
||||||
std::cout << "Top 20 most frequently executed basic blocks:\n\n";
|
for (unsigned i = 0; i != BlocksToPrint; ++i) {
|
||||||
|
if (Counts[i].second == 0) break;
|
||||||
// Print out the function frequencies...
|
Function *F = Counts[i].first->getParent();
|
||||||
std::cout <<" ## %% \tFrequency\n";
|
std::cout << std::setw(3) << i+1 << ". "
|
||||||
unsigned BlocksToPrint = Counts.size();
|
<< std::setw(5) << std::setprecision(2)
|
||||||
if (BlocksToPrint > 20) BlocksToPrint = 20;
|
<< Counts[i].second/(double)TotalExecutions*100 << "% "
|
||||||
for (unsigned i = 0; i != BlocksToPrint; ++i) {
|
<< std::setw(5) << Counts[i].second << "/"
|
||||||
if (Counts[i].second == 0) break;
|
<< TotalExecutions << "\t"
|
||||||
Function *F = Counts[i].first->getParent();
|
<< F->getNameStr() << "() - "
|
||||||
std::cout << std::setw(3) << i+1 << ". "
|
<< Counts[i].first->getNameStr() << "\n";
|
||||||
<< std::setw(5) << std::setprecision(2)
|
FunctionsToPrint.insert(F);
|
||||||
<< Counts[i].second/(double)TotalExecutions*100 << "% "
|
|
||||||
<< std::setw(5) << Counts[i].second << "/"
|
|
||||||
<< TotalExecutions << "\t"
|
|
||||||
<< F->getNameStr() << "() - "
|
|
||||||
<< Counts[i].first->getNameStr() << "\n";
|
|
||||||
FunctionsToPrint.insert(F);
|
|
||||||
}
|
|
||||||
|
|
||||||
BlockFreqs.insert(Counts.begin(), Counts.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (PIL.hasAccurateEdgeCounts()) {
|
|
||||||
std::vector<std::pair<ProfileInfoLoader::Edge, unsigned> > Counts;
|
|
||||||
PIL.getEdgeCounts(Counts);
|
|
||||||
EdgeFreqs.insert(Counts.begin(), Counts.end());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PrintAnnotatedLLVM || PrintAllCode) {
|
if (PrintAnnotatedLLVM || PrintAllCode) {
|
||||||
std::cout << "\n===" << std::string(73, '-') << "===\n";
|
std::cout << "\n===" << std::string(73, '-') << "===\n";
|
||||||
std::cout << "Annotated LLVM code for the module:\n\n";
|
std::cout << "Annotated LLVM code for the module:\n\n";
|
||||||
|
|
||||||
ProfileAnnotator PA(FuncFreqs, BlockFreqs, EdgeFreqs);
|
ProfileAnnotator PA(PI);
|
||||||
|
|
||||||
if (FunctionsToPrint.empty() || PrintAllCode)
|
if (FunctionsToPrint.empty() || PrintAllCode)
|
||||||
M.print(std::cout, &PA);
|
M.print(std::cout, &PA);
|
||||||
|
Loading…
Reference in New Issue
Block a user