mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-08 21:32:39 +00:00
Cleaned up code by factoring out common portions of edge loading into function.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81438 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
fd5249e15b
commit
b4b1c9fa23
@ -42,6 +42,7 @@ namespace {
|
|||||||
std::string Filename;
|
std::string Filename;
|
||||||
std::set<Edge> SpanningTree;
|
std::set<Edge> SpanningTree;
|
||||||
std::set<const BasicBlock*> BBisUnvisited;
|
std::set<const BasicBlock*> BBisUnvisited;
|
||||||
|
unsigned ReadCount;
|
||||||
public:
|
public:
|
||||||
static char ID; // Class identification, replacement for typeinfo
|
static char ID; // Class identification, replacement for typeinfo
|
||||||
explicit LoaderPass(const std::string &filename = "")
|
explicit LoaderPass(const std::string &filename = "")
|
||||||
@ -61,8 +62,7 @@ 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 void readEdge(ProfileInfo::Edge, std::vector<unsigned>&);
|
||||||
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,20 @@ void LoaderPass::recurseBasicBlock(const BasicBlock *BB) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LoaderPass::readOrRememberEdge(ProfileInfo::Edge e,
|
void LoaderPass::readEdge(ProfileInfo::Edge e,
|
||||||
unsigned weight, unsigned ei,
|
std::vector<unsigned> &ECs) {
|
||||||
Function *F) {
|
if (ReadCount < ECs.size()) {
|
||||||
if (weight != ~0U) {
|
double weight = ECs[ReadCount++];
|
||||||
EdgeInformation[F][e] += weight;
|
if (weight != ~0U) {
|
||||||
DEBUG(errs()<<"--Read Edge Counter for " << e
|
EdgeInformation[getFunction(e)][e] += weight;
|
||||||
<<" (# "<<ei<<"): "<<(unsigned)getEdgeWeight(e)<<"\n");
|
DEBUG(errs() << "--Read Edge Counter for " << e
|
||||||
} else {
|
<< " (# "<< (ReadCount-1) << "): "
|
||||||
SpanningTree.insert(e);
|
<< (unsigned)getEdgeWeight(e) << "\n");
|
||||||
|
} else {
|
||||||
|
// This happens only if reading optimal profiling information, not when
|
||||||
|
// reading regular profiling information.
|
||||||
|
SpanningTree.insert(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,55 +177,44 @@ bool LoaderPass::runOnModule(Module &M) {
|
|||||||
ProfileInfoLoader PIL("profile-loader", Filename, M);
|
ProfileInfoLoader PIL("profile-loader", Filename, M);
|
||||||
|
|
||||||
EdgeInformation.clear();
|
EdgeInformation.clear();
|
||||||
std::vector<unsigned> ECs = PIL.getRawEdgeCounts();
|
std::vector<unsigned> Counters = PIL.getRawEdgeCounts();
|
||||||
if (ECs.size() > 0) {
|
if (Counters.size() > 0) {
|
||||||
unsigned ei = 0;
|
ReadCount = 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())] +=
|
readEdge(getEdge(0,&F->getEntryBlock()), Counters);
|
||||||
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())
|
readEdge(getEdge(BB,TI->getSuccessor(s)), Counters);
|
||||||
EdgeInformation[F][ProfileInfo::getEdge(BB, TI->getSuccessor(s))] +=
|
|
||||||
ECs[ei++];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ei != ECs.size()) {
|
if (ReadCount != Counters.size()) {
|
||||||
errs() << "WARNING: profile information is inconsistent with "
|
errs() << "WARNING: profile information is inconsistent with "
|
||||||
<< "the current program!\n";
|
<< "the current program!\n";
|
||||||
}
|
}
|
||||||
NumEdgesRead = ei;
|
NumEdgesRead = ReadCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
ECs = PIL.getRawOptimalEdgeCounts();
|
Counters = PIL.getRawOptimalEdgeCounts();
|
||||||
if (ECs.size() > 0) {
|
if (Counters.size() > 0) {
|
||||||
unsigned ei = 0;
|
ReadCount = 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;
|
||||||
DEBUG(errs()<<"Working on "<<F->getNameStr()<<"\n");
|
DEBUG(errs()<<"Working on "<<F->getNameStr()<<"\n");
|
||||||
if (ei < ECs.size()) {
|
readEdge(getEdge(0,&F->getEntryBlock()), Counters);
|
||||||
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()) {
|
readEdge(getEdge(BB,0), Counters);
|
||||||
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()) {
|
readEdge(getEdge(BB,TI->getSuccessor(s)), Counters);
|
||||||
readOrRememberEdge(getEdge(BB,TI->getSuccessor(s)), ECs[ei], ei, F);
|
|
||||||
ei++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (SpanningTree.size() > 0) {
|
while (SpanningTree.size() > 0) {
|
||||||
@ -249,39 +243,39 @@ bool LoaderPass::runOnModule(Module &M) {
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ei != ECs.size()) {
|
if (ReadCount != Counters.size()) {
|
||||||
errs() << "WARNING: profile information is inconsistent with "
|
errs() << "WARNING: profile information is inconsistent with "
|
||||||
<< "the current program!\n";
|
<< "the current program!\n";
|
||||||
}
|
}
|
||||||
NumEdgesRead = ei;
|
NumEdgesRead = ReadCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
BlockInformation.clear();
|
BlockInformation.clear();
|
||||||
std::vector<unsigned> BCs = PIL.getRawBlockCounts();
|
Counters = PIL.getRawBlockCounts();
|
||||||
if (BCs.size() > 0) {
|
if (Counters.size() > 0) {
|
||||||
unsigned bi = 0;
|
ReadCount = 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;
|
||||||
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
|
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
|
||||||
if (bi < BCs.size())
|
if (ReadCount < Counters.size())
|
||||||
BlockInformation[F][BB] = BCs[bi++];
|
BlockInformation[F][BB] = Counters[ReadCount++];
|
||||||
}
|
}
|
||||||
if (bi != BCs.size()) {
|
if (ReadCount != Counters.size()) {
|
||||||
errs() << "WARNING: profile information is inconsistent with "
|
errs() << "WARNING: profile information is inconsistent with "
|
||||||
<< "the current program!\n";
|
<< "the current program!\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FunctionInformation.clear();
|
FunctionInformation.clear();
|
||||||
std::vector<unsigned> FCs = PIL.getRawFunctionCounts();
|
Counters = PIL.getRawFunctionCounts();
|
||||||
if (FCs.size() > 0) {
|
if (Counters.size() > 0) {
|
||||||
unsigned fi = 0;
|
ReadCount = 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 (fi < FCs.size())
|
if (ReadCount < Counters.size())
|
||||||
FunctionInformation[F] = FCs[fi++];
|
FunctionInformation[F] = Counters[ReadCount++];
|
||||||
}
|
}
|
||||||
if (fi != FCs.size()) {
|
if (ReadCount != Counters.size()) {
|
||||||
errs() << "WARNING: profile information is inconsistent with "
|
errs() << "WARNING: profile information is inconsistent with "
|
||||||
<< "the current program!\n";
|
<< "the current program!\n";
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user