mirror of
https://github.com/RPCS3/llvm.git
synced 2024-12-17 17:06:59 +00:00
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
This commit is contained in:
parent
88cfd964a3
commit
7fd7061de0
@ -61,8 +61,8 @@ namespace {
|
|||||||
// blocks as possbile.
|
// blocks as possbile.
|
||||||
virtual void recurseBasicBlock(const BasicBlock *BB);
|
virtual void recurseBasicBlock(const BasicBlock *BB);
|
||||||
virtual void readEdgeOrRemember(Edge, Edge&, unsigned &, unsigned &);
|
virtual void readEdgeOrRemember(Edge, Edge&, unsigned &, unsigned &);
|
||||||
virtual void readOrRememberEdge(ProfileInfo::Edge, unsigned,
|
virtual unsigned readEdge(ProfileInfo::Edge, std::vector<unsigned>,
|
||||||
unsigned, Function*);
|
unsigned, Function*);
|
||||||
|
|
||||||
/// run - Load the profile information from the specified file.
|
/// run - Load the profile information from the specified file.
|
||||||
virtual bool runOnModule(Module &M);
|
virtual bool runOnModule(Module &M);
|
||||||
@ -156,15 +156,21 @@ void LoaderPass::recurseBasicBlock(const BasicBlock *BB) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoaderPass::readOrRememberEdge(ProfileInfo::Edge e,
|
unsigned LoaderPass::readEdge(ProfileInfo::Edge e, std::vector<unsigned> ECs,
|
||||||
unsigned weight, unsigned ei,
|
unsigned ei, Function *F) {
|
||||||
Function *F) {
|
if (ei < ECs.size()) {
|
||||||
if (weight != ~0U) {
|
double weight = ECs[ei];
|
||||||
EdgeInformation[F][e] += weight;
|
if (weight != ~0U) {
|
||||||
DEBUG(errs()<<"--Read Edge Counter for " << e
|
EdgeInformation[F][e] += weight;
|
||||||
<<" (# "<<ei<<"): "<<(unsigned)getEdgeWeight(e)<<"\n");
|
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 {
|
} else {
|
||||||
SpanningTree.insert(e);
|
return ei;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,18 +183,15 @@ bool LoaderPass::runOnModule(Module &M) {
|
|||||||
unsigned ei = 0;
|
unsigned ei = 0;
|
||||||
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
|
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
|
||||||
if (F->isDeclaration()) continue;
|
if (F->isDeclaration()) continue;
|
||||||
if (ei < ECs.size())
|
DEBUG(errs()<<"Working on "<<F->getNameStr()<<"\n");
|
||||||
EdgeInformation[F][ProfileInfo::getEdge(0, &F->getEntryBlock())] +=
|
ei = readEdge(getEdge(0,&F->getEntryBlock()), ECs, ei, F);
|
||||||
ECs[ei++];
|
|
||||||
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
|
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
|
// 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
|
// outgoing edge is not critical don't split it, just insert the counter
|
||||||
// in the source or destination of the edge.
|
// in the source or destination of the edge.
|
||||||
TerminatorInst *TI = BB->getTerminator();
|
TerminatorInst *TI = BB->getTerminator();
|
||||||
for (unsigned s = 0, e = TI->getNumSuccessors(); s != e; ++s) {
|
for (unsigned s = 0, e = TI->getNumSuccessors(); s != e; ++s) {
|
||||||
if (ei < ECs.size())
|
ei = readEdge(getEdge(BB,TI->getSuccessor(s)), ECs, ei, F);
|
||||||
EdgeInformation[F][ProfileInfo::getEdge(BB, TI->getSuccessor(s))] +=
|
|
||||||
ECs[ei++];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -205,22 +208,14 @@ bool LoaderPass::runOnModule(Module &M) {
|
|||||||
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
|
for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
|
||||||
if (F->isDeclaration()) continue;
|
if (F->isDeclaration()) continue;
|
||||||
DEBUG(errs()<<"Working on "<<F->getNameStr()<<"\n");
|
DEBUG(errs()<<"Working on "<<F->getNameStr()<<"\n");
|
||||||
if (ei < ECs.size()) {
|
ei = readEdge(getEdge(0,&F->getEntryBlock()), ECs, ei, F);
|
||||||
readOrRememberEdge(getEdge(0,&F->getEntryBlock()), ECs[ei], ei, F);
|
|
||||||
ei++;
|
|
||||||
}
|
|
||||||
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
|
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
|
||||||
TerminatorInst *TI = BB->getTerminator();
|
TerminatorInst *TI = BB->getTerminator();
|
||||||
if (TI->getNumSuccessors() == 0) {
|
if (TI->getNumSuccessors() == 0) {
|
||||||
if (ei < ECs.size()) {
|
ei = readEdge(getEdge(BB,0), ECs, ei, F);
|
||||||
readOrRememberEdge(getEdge(BB,0), ECs[ei], ei, F); ei++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for (unsigned s = 0, e = TI->getNumSuccessors(); s != e; ++s) {
|
for (unsigned s = 0, e = TI->getNumSuccessors(); s != e; ++s) {
|
||||||
if (ei < ECs.size()) {
|
ei = readEdge(getEdge(BB,TI->getSuccessor(s)), ECs, ei, F);
|
||||||
readOrRememberEdge(getEdge(BB,TI->getSuccessor(s)), ECs[ei], ei, F);
|
|
||||||
ei++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (SpanningTree.size() > 0) {
|
while (SpanningTree.size() > 0) {
|
||||||
|
Loading…
Reference in New Issue
Block a user