forked from OSchip/llvm-project
parent
11289f4280
commit
9ded9ac8af
|
@ -42,8 +42,6 @@ public:
|
||||||
ProfileInfoLoader(const char *ToolName, const std::string &Filename,
|
ProfileInfoLoader(const char *ToolName, const std::string &Filename,
|
||||||
Module &M);
|
Module &M);
|
||||||
|
|
||||||
static const unsigned Uncounted = ~0U;
|
|
||||||
|
|
||||||
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]; }
|
||||||
|
|
||||||
|
|
|
@ -34,8 +34,8 @@ static inline unsigned ByteSwap(unsigned Var, bool Really) {
|
||||||
|
|
||||||
static unsigned AddCounts(unsigned A, unsigned B) {
|
static unsigned AddCounts(unsigned A, unsigned B) {
|
||||||
// If either value is undefined, use the other.
|
// If either value is undefined, use the other.
|
||||||
if (A == ProfileInfoLoader::Uncounted) return B;
|
if (A == ~0U) return B;
|
||||||
if (B == ProfileInfoLoader::Uncounted) return A;
|
if (B == ~0U) return A;
|
||||||
return A + B;
|
return A + B;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ static void ReadProfilingBlock(const char *ToolName, FILE *F,
|
||||||
// Make sure we have enough space... The space is initialised to -1 to
|
// Make sure we have enough space... The space is initialised to -1 to
|
||||||
// facitiltate the loading of missing values for OptimalEdgeProfiling.
|
// facitiltate the loading of missing values for OptimalEdgeProfiling.
|
||||||
if (Data.size() < NumEntries)
|
if (Data.size() < NumEntries)
|
||||||
Data.resize(NumEntries, ProfileInfoLoader::Uncounted);
|
Data.resize(NumEntries, ~0U);
|
||||||
|
|
||||||
// Accumulate the data we just read into the data.
|
// Accumulate the data we just read into the data.
|
||||||
if (!ShouldByteSwap) {
|
if (!ShouldByteSwap) {
|
||||||
|
|
|
@ -159,12 +159,8 @@ void LoaderPass::recurseBasicBlock(const BasicBlock *BB) {
|
||||||
void LoaderPass::readOrRememberEdge(ProfileInfo::Edge e,
|
void LoaderPass::readOrRememberEdge(ProfileInfo::Edge e,
|
||||||
unsigned weight, unsigned ei,
|
unsigned weight, unsigned ei,
|
||||||
Function *F) {
|
Function *F) {
|
||||||
if (weight != ProfileInfoLoader::Uncounted) {
|
if (weight != ~0U) {
|
||||||
// Here the data realm changes from the unsigned of the file to the double
|
EdgeInformation[F][e] += weight;
|
||||||
// of the ProfileInfo. This conversion is save because we know that
|
|
||||||
// everything thats representable in unsinged is also representable in
|
|
||||||
// double.
|
|
||||||
EdgeInformation[F][e] += (double)weight;
|
|
||||||
DEBUG(errs()<<"--Read Edge Counter for " << e
|
DEBUG(errs()<<"--Read Edge Counter for " << e
|
||||||
<<" (# "<<ei<<"): "<<(unsigned)getEdgeWeight(e)<<"\n");
|
<<" (# "<<ei<<"): "<<(unsigned)getEdgeWeight(e)<<"\n");
|
||||||
} else {
|
} else {
|
||||||
|
@ -182,12 +178,8 @@ 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;
|
||||||
if (ei < ECs.size())
|
if (ei < ECs.size())
|
||||||
// Here the data realm changes from the unsigned of the file to the
|
|
||||||
// double of the ProfileInfo. This conversion is save because we know
|
|
||||||
// that everything thats representable in unsinged is also
|
|
||||||
// representable in double.
|
|
||||||
EdgeInformation[F][ProfileInfo::getEdge(0, &F->getEntryBlock())] +=
|
EdgeInformation[F][ProfileInfo::getEdge(0, &F->getEntryBlock())] +=
|
||||||
(double)ECs[ei++];
|
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
|
||||||
|
@ -195,10 +187,8 @@ bool LoaderPass::runOnModule(Module &M) {
|
||||||
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())
|
if (ei < ECs.size())
|
||||||
// Here the data realm changes from the unsigned of the file to
|
|
||||||
// the double of the ProfileInfo.
|
|
||||||
EdgeInformation[F][ProfileInfo::getEdge(BB, TI->getSuccessor(s))] +=
|
EdgeInformation[F][ProfileInfo::getEdge(BB, TI->getSuccessor(s))] +=
|
||||||
(double)ECs[ei++];
|
ECs[ei++];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -274,11 +264,7 @@ bool LoaderPass::runOnModule(Module &M) {
|
||||||
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 (bi < BCs.size())
|
||||||
// Here the data realm changes from the unsigned of the file to the
|
BlockInformation[F][BB] = BCs[bi++];
|
||||||
// double of the ProfileInfo. This conversion is save because we know
|
|
||||||
// that everything thats representable in unsinged is also
|
|
||||||
// representable in double.
|
|
||||||
BlockInformation[F][BB] = (double)BCs[bi++];
|
|
||||||
}
|
}
|
||||||
if (bi != BCs.size()) {
|
if (bi != BCs.size()) {
|
||||||
errs() << "WARNING: profile information is inconsistent with "
|
errs() << "WARNING: profile information is inconsistent with "
|
||||||
|
@ -293,11 +279,7 @@ 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;
|
||||||
if (fi < FCs.size())
|
if (fi < FCs.size())
|
||||||
// Here the data realm changes from the unsigned of the file to the
|
FunctionInformation[F] = FCs[fi++];
|
||||||
// double of the ProfileInfo. This conversion is save because we know
|
|
||||||
// that everything thats representable in unsinged is also
|
|
||||||
// representable in double.
|
|
||||||
FunctionInformation[F] = (double)FCs[fi++];
|
|
||||||
}
|
}
|
||||||
if (fi != FCs.size()) {
|
if (fi != FCs.size()) {
|
||||||
errs() << "WARNING: profile information is inconsistent with "
|
errs() << "WARNING: profile information is inconsistent with "
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
#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"
|
||||||
#include "llvm/Analysis/ProfileInfoLoader.h"
|
|
||||||
#include "llvm/Support/Compiler.h"
|
#include "llvm/Support/Compiler.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
|
@ -114,8 +113,8 @@ bool OptimalEdgeProfiler::runOnModule(Module &M) {
|
||||||
NumEdgesInserted = 0;
|
NumEdgesInserted = 0;
|
||||||
|
|
||||||
std::vector<Constant*> Initializer(NumEdges);
|
std::vector<Constant*> Initializer(NumEdges);
|
||||||
Constant* Zero = ConstantInt::get(Int32, 0);
|
Constant* zeroc = ConstantInt::get(Int32, 0);
|
||||||
Constant* Uncounted = ConstantInt::get(Int32, ProfileInfoLoader::Uncounted);
|
Constant* minusonec = ConstantInt::get(Int32, ProfileInfo::MissingValue);
|
||||||
|
|
||||||
// Instrument all of the edges not in MST...
|
// Instrument all of the edges not in MST...
|
||||||
unsigned i = 0;
|
unsigned i = 0;
|
||||||
|
@ -145,9 +144,9 @@ bool OptimalEdgeProfiler::runOnModule(Module &M) {
|
||||||
if (!std::binary_search(MST.begin(), MST.end(), edge)) {
|
if (!std::binary_search(MST.begin(), MST.end(), edge)) {
|
||||||
printEdgeCounter(edge,entry,i);
|
printEdgeCounter(edge,entry,i);
|
||||||
IncrementCounterInBlock(entry, i, Counters); NumEdgesInserted++;
|
IncrementCounterInBlock(entry, i, Counters); NumEdgesInserted++;
|
||||||
Initializer[i++] = (Zero);
|
Initializer[i++] = (zeroc);
|
||||||
} else{
|
} else{
|
||||||
Initializer[i++] = (Uncounted);
|
Initializer[i++] = (minusonec);
|
||||||
}
|
}
|
||||||
|
|
||||||
// InsertedBlocks contains all blocks that were inserted for splitting an
|
// InsertedBlocks contains all blocks that were inserted for splitting an
|
||||||
|
@ -168,9 +167,9 @@ bool OptimalEdgeProfiler::runOnModule(Module &M) {
|
||||||
if (!std::binary_search(MST.begin(), MST.end(), edge)) {
|
if (!std::binary_search(MST.begin(), MST.end(), edge)) {
|
||||||
printEdgeCounter(edge,BB,i);
|
printEdgeCounter(edge,BB,i);
|
||||||
IncrementCounterInBlock(BB, i, Counters); NumEdgesInserted++;
|
IncrementCounterInBlock(BB, i, Counters); NumEdgesInserted++;
|
||||||
Initializer[i++] = (Zero);
|
Initializer[i++] = (zeroc);
|
||||||
} else{
|
} else{
|
||||||
Initializer[i++] = (Uncounted);
|
Initializer[i++] = (minusonec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (unsigned s = 0, e = TI->getNumSuccessors(); s != e; ++s) {
|
for (unsigned s = 0, e = TI->getNumSuccessors(); s != e; ++s) {
|
||||||
|
@ -196,9 +195,9 @@ bool OptimalEdgeProfiler::runOnModule(Module &M) {
|
||||||
printEdgeCounter(edge,Succ,i);
|
printEdgeCounter(edge,Succ,i);
|
||||||
IncrementCounterInBlock(Succ, i, Counters); NumEdgesInserted++;
|
IncrementCounterInBlock(Succ, i, Counters); NumEdgesInserted++;
|
||||||
}
|
}
|
||||||
Initializer[i++] = (Zero);
|
Initializer[i++] = (zeroc);
|
||||||
} else {
|
} else {
|
||||||
Initializer[i++] = (Uncounted);
|
Initializer[i++] = (minusonec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue