summaryrefslogtreecommitdiff
path: root/lib/Analysis/ProfileInfoLoaderPass.cpp
diff options
context:
space:
mode:
authorAndreas Neustifter <astifter-llvm@gmx.at>2009-09-09 17:51:39 +0000
committerAndreas Neustifter <astifter-llvm@gmx.at>2009-09-09 17:51:39 +0000
commit7fd7061de03ca8987e9997e498b67efb6d614fde (patch)
treed5e619a49935af8e75080fc9c59cdd8ae0594066 /lib/Analysis/ProfileInfoLoaderPass.cpp
parent88cfd964a3341ad7c89dd5e176f24db1fef6f287 (diff)
downloadllvm-7fd7061de03ca8987e9997e498b67efb6d614fde.tar.gz
llvm-7fd7061de03ca8987e9997e498b67efb6d614fde.tar.bz2
llvm-7fd7061de03ca8987e9997e498b67efb6d614fde.tar.xz
Cleaned up code by factoring out common portions of edge loading into funcion.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81358 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/ProfileInfoLoaderPass.cpp')
-rw-r--r--lib/Analysis/ProfileInfoLoaderPass.cpp49
1 files changed, 22 insertions, 27 deletions
diff --git a/lib/Analysis/ProfileInfoLoaderPass.cpp b/lib/Analysis/ProfileInfoLoaderPass.cpp
index e79dd8c0c2..9b5760f2cd 100644
--- a/lib/Analysis/ProfileInfoLoaderPass.cpp
+++ b/lib/Analysis/ProfileInfoLoaderPass.cpp
@@ -61,8 +61,8 @@ namespace {
// blocks as possbile.
virtual void recurseBasicBlock(const BasicBlock *BB);
virtual void readEdgeOrRemember(Edge, Edge&, unsigned &, unsigned &);
- virtual void readOrRememberEdge(ProfileInfo::Edge, unsigned,
- unsigned, Function*);
+ virtual unsigned readEdge(ProfileInfo::Edge, std::vector<unsigned>,
+ unsigned, Function*);
/// run - Load the profile information from the specified file.
virtual bool runOnModule(Module &M);
@@ -156,15 +156,21 @@ void LoaderPass::recurseBasicBlock(const BasicBlock *BB) {
}
}
-void LoaderPass::readOrRememberEdge(ProfileInfo::Edge e,
- unsigned weight, unsigned ei,
- Function *F) {
- if (weight != ~0U) {
- EdgeInformation[F][e] += weight;
- DEBUG(errs()<<"--Read Edge Counter for " << e
- <<" (# "<<ei<<"): "<<(unsigned)getEdgeWeight(e)<<"\n");
+unsigned LoaderPass::readEdge(ProfileInfo::Edge e, std::vector<unsigned> ECs,
+ unsigned ei, Function *F) {
+ if (ei < ECs.size()) {
+ double weight = ECs[ei];
+ if (weight != ~0U) {
+ EdgeInformation[F][e] += weight;
+ DEBUG(errs()<<"--Read Edge Counter for " << e
+ <<" (# "<<ei<<"): "<<(unsigned)getEdgeWeight(e)<<"\n");
+ } else {
+ // This happens only when loading edges for optimal edge profiling.
+ SpanningTree.insert(e);
+ }
+ return ei++
} else {
- SpanningTree.insert(e);
+ return ei;
}
}
@@ -177,18 +183,15 @@ bool LoaderPass::runOnModule(Module &M) {
unsigned ei = 0;
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
if (F->isDeclaration()) continue;
- if (ei < ECs.size())
- EdgeInformation[F][ProfileInfo::getEdge(0, &F->getEntryBlock())] +=
- ECs[ei++];
+ DEBUG(errs()<<"Working on "<<F->getNameStr()<<"\n");
+ ei = readEdge(getEdge(0,&F->getEntryBlock()), ECs, ei, F);
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
// Okay, we have to add a counter of each outgoing edge. If the
// outgoing edge is not critical don't split it, just insert the counter
// in the source or destination of the edge.
TerminatorInst *TI = BB->getTerminator();
for (unsigned s = 0, e = TI->getNumSuccessors(); s != e; ++s) {
- if (ei < ECs.size())
- EdgeInformation[F][ProfileInfo::getEdge(BB, TI->getSuccessor(s))] +=
- ECs[ei++];
+ ei = readEdge(getEdge(BB,TI->getSuccessor(s)), ECs, ei, F);
}
}
}
@@ -205,22 +208,14 @@ bool LoaderPass::runOnModule(Module &M) {
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
if (F->isDeclaration()) continue;
DEBUG(errs()<<"Working on "<<F->getNameStr()<<"\n");
- if (ei < ECs.size()) {
- readOrRememberEdge(getEdge(0,&F->getEntryBlock()), ECs[ei], ei, F);
- ei++;
- }
+ ei = readEdge(getEdge(0,&F->getEntryBlock()), ECs, ei, F);
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
TerminatorInst *TI = BB->getTerminator();
if (TI->getNumSuccessors() == 0) {
- if (ei < ECs.size()) {
- readOrRememberEdge(getEdge(BB,0), ECs[ei], ei, F); ei++;
- }
+ ei = readEdge(getEdge(BB,0), ECs, ei, F);
}
for (unsigned s = 0, e = TI->getNumSuccessors(); s != e; ++s) {
- if (ei < ECs.size()) {
- readOrRememberEdge(getEdge(BB,TI->getSuccessor(s)), ECs[ei], ei, F);
- ei++;
- }
+ ei = readEdge(getEdge(BB,TI->getSuccessor(s)), ECs, ei, F);
}
}
while (SpanningTree.size() > 0) {