X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FAnalysis%2FProfileInfo.cpp;h=85531be76add0b2e0e1650e18afc0535a5560f9d;hb=0af20d847ac89f797d613a8a4fc3e7127ccb0b36;hp=5a7f6918ecd543c4f0354221d7e7bd1781bdf15f;hpb=e2baf6b45549128c76a701c3edd8b4bb0b4835d4;p=oota-llvm.git diff --git a/lib/Analysis/ProfileInfo.cpp b/lib/Analysis/ProfileInfo.cpp index 5a7f6918ecd..85531be76ad 100644 --- a/lib/Analysis/ProfileInfo.cpp +++ b/lib/Analysis/ProfileInfo.cpp @@ -44,19 +44,19 @@ ProfileInfoT::~ProfileInfoT() { } template<> -char ProfileInfo::ID = 0; +char ProfileInfoT::ID = 0; template<> -char MachineProfileInfo::ID = 0; +char ProfileInfoT::ID = 0; template<> -const double ProfileInfo::MissingValue = -1; +const double ProfileInfoT::MissingValue = -1; -template<> -const double MachineProfileInfo::MissingValue = -1; +template<> const +double ProfileInfoT::MissingValue = -1; -template<> -double ProfileInfo::getExecutionCount(const BasicBlock *BB) { +template<> double +ProfileInfoT::getExecutionCount(const BasicBlock *BB) { std::map::iterator J = BlockInformation.find(BB->getParent()); if (J != BlockInformation.end()) { @@ -118,7 +118,8 @@ double ProfileInfo::getExecutionCount(const BasicBlock *BB) { } template<> -double MachineProfileInfo::getExecutionCount(const MachineBasicBlock *MBB) { +double ProfileInfoT:: + getExecutionCount(const MachineBasicBlock *MBB) { std::map::iterator J = BlockInformation.find(MBB->getParent()); if (J != BlockInformation.end()) { @@ -131,7 +132,7 @@ double MachineProfileInfo::getExecutionCount(const MachineBasicBlock *MBB) { } template<> -double ProfileInfo::getExecutionCount(const Function *F) { +double ProfileInfoT::getExecutionCount(const Function *F) { std::map::iterator J = FunctionInformation.find(F); if (J != FunctionInformation.end()) @@ -147,7 +148,8 @@ double ProfileInfo::getExecutionCount(const Function *F) { } template<> -double MachineProfileInfo::getExecutionCount(const MachineFunction *MF) { +double ProfileInfoT:: + getExecutionCount(const MachineFunction *MF) { std::map::iterator J = FunctionInformation.find(MF); if (J != FunctionInformation.end()) @@ -159,74 +161,79 @@ double MachineProfileInfo::getExecutionCount(const MachineFunction *MF) { } template<> -void ProfileInfo::setExecutionCount(const BasicBlock *BB, double w) { - DEBUG(errs() << "Creating Block " << BB->getName() +void ProfileInfoT:: + setExecutionCount(const BasicBlock *BB, double w) { + DEBUG(dbgs() << "Creating Block " << BB->getName() << " (weight: " << format("%.20g",w) << ")\n"); BlockInformation[BB->getParent()][BB] = w; } template<> -void MachineProfileInfo::setExecutionCount(const MachineBasicBlock *MBB, double w) { - DEBUG(errs() << "Creating Block " << MBB->getBasicBlock()->getName() +void ProfileInfoT:: + setExecutionCount(const MachineBasicBlock *MBB, double w) { + DEBUG(dbgs() << "Creating Block " << MBB->getBasicBlock()->getName() << " (weight: " << format("%.20g",w) << ")\n"); BlockInformation[MBB->getParent()][MBB] = w; } template<> -void ProfileInfo::addEdgeWeight(Edge e, double w) { +void ProfileInfoT::addEdgeWeight(Edge e, double w) { double oldw = getEdgeWeight(e); assert (oldw != MissingValue && "Adding weight to Edge with no previous weight"); - DEBUG(errs() << "Adding to Edge " << e + DEBUG(dbgs() << "Adding to Edge " << e << " (new weight: " << format("%.20g",oldw + w) << ")\n"); EdgeInformation[getFunction(e)][e] = oldw + w; } template<> -void ProfileInfo::addExecutionCount(const BasicBlock *BB, double w) { +void ProfileInfoT:: + addExecutionCount(const BasicBlock *BB, double w) { double oldw = getExecutionCount(BB); assert (oldw != MissingValue && "Adding weight to Block with no previous weight"); - DEBUG(errs() << "Adding to Block " << BB->getName() + DEBUG(dbgs() << "Adding to Block " << BB->getName() << " (new weight: " << format("%.20g",oldw + w) << ")\n"); BlockInformation[BB->getParent()][BB] = oldw + w; } template<> -void ProfileInfo::removeBlock(const BasicBlock *BB) { +void ProfileInfoT::removeBlock(const BasicBlock *BB) { std::map::iterator J = BlockInformation.find(BB->getParent()); if (J == BlockInformation.end()) return; - DEBUG(errs() << "Deleting " << BB->getName() << "\n"); + DEBUG(dbgs() << "Deleting " << BB->getName() << "\n"); J->second.erase(BB); } template<> -void ProfileInfo::removeEdge(Edge e) { +void ProfileInfoT::removeEdge(Edge e) { std::map::iterator J = EdgeInformation.find(getFunction(e)); if (J == EdgeInformation.end()) return; - DEBUG(errs() << "Deleting" << e << "\n"); + DEBUG(dbgs() << "Deleting" << e << "\n"); J->second.erase(e); } template<> -void ProfileInfo::replaceEdge(const Edge &oldedge, const Edge &newedge) { +void ProfileInfoT:: + replaceEdge(const Edge &oldedge, const Edge &newedge) { double w; if ((w = getEdgeWeight(newedge)) == MissingValue) { w = getEdgeWeight(oldedge); - DEBUG(errs() << "Replacing " << oldedge << " with " << newedge << "\n"); + DEBUG(dbgs() << "Replacing " << oldedge << " with " << newedge << "\n"); } else { w += getEdgeWeight(oldedge); - DEBUG(errs() << "Adding " << oldedge << " to " << newedge << "\n"); + DEBUG(dbgs() << "Adding " << oldedge << " to " << newedge << "\n"); } setEdgeWeight(newedge,w); removeEdge(oldedge); } template<> -const BasicBlock *ProfileInfo::GetPath(const BasicBlock *Src, const BasicBlock *Dest, - Path &P, unsigned Mode) { +const BasicBlock *ProfileInfoT:: + GetPath(const BasicBlock *Src, const BasicBlock *Dest, + Path &P, unsigned Mode) { const BasicBlock *BB = 0; bool hasFoundPath = false; @@ -268,8 +275,9 @@ const BasicBlock *ProfileInfo::GetPath(const BasicBlock *Src, const BasicBlock * } template<> -void ProfileInfo::divertFlow(const Edge &oldedge, const Edge &newedge) { - DEBUG(errs() << "Diverting " << oldedge << " via " << newedge ); +void ProfileInfoT:: + divertFlow(const Edge &oldedge, const Edge &newedge) { + DEBUG(dbgs() << "Diverting " << oldedge << " via " << newedge ); // First check if the old edge was taken, if not, just delete it... if (getEdgeWeight(oldedge) == 0) { @@ -283,7 +291,7 @@ void ProfileInfo::divertFlow(const Edge &oldedge, const Edge &newedge) { const BasicBlock *BB = GetPath(newedge.second,oldedge.second,P,GetPathToExit | GetPathToDest); double w = getEdgeWeight (oldedge); - DEBUG(errs() << ", Weight: " << format("%.20g",w) << "\n"); + DEBUG(dbgs() << ", Weight: " << format("%.20g",w) << "\n"); do { const BasicBlock *Parent = P.find(BB)->second; Edge e = getEdge(Parent,BB); @@ -302,9 +310,9 @@ void ProfileInfo::divertFlow(const Edge &oldedge, const Edge &newedge) { /// This checks all edges of the function the blocks reside in and replaces the /// occurences of RmBB with DestBB. template<> -void ProfileInfo::replaceAllUses(const BasicBlock *RmBB, - const BasicBlock *DestBB) { - DEBUG(errs() << "Replacing " << RmBB->getName() +void ProfileInfoT:: + replaceAllUses(const BasicBlock *RmBB, const BasicBlock *DestBB) { + DEBUG(dbgs() << "Replacing " << RmBB->getName() << " with " << DestBB->getName() << "\n"); const Function *F = DestBB->getParent(); std::map::iterator J = @@ -352,10 +360,10 @@ void ProfileInfo::replaceAllUses(const BasicBlock *RmBB, /// Since its possible that there is more than one edge in the CFG from FristBB /// to SecondBB its necessary to redirect the flow proporionally. template<> -void ProfileInfo::splitEdge(const BasicBlock *FirstBB, - const BasicBlock *SecondBB, - const BasicBlock *NewBB, - bool MergeIdenticalEdges) { +void ProfileInfoT::splitEdge(const BasicBlock *FirstBB, + const BasicBlock *SecondBB, + const BasicBlock *NewBB, + bool MergeIdenticalEdges) { const Function *F = FirstBB->getParent(); std::map::iterator J = EdgeInformation.find(F); @@ -398,13 +406,14 @@ void ProfileInfo::splitEdge(const BasicBlock *FirstBB, } template<> -void ProfileInfo::splitBlock(const BasicBlock *Old, const BasicBlock* New) { +void ProfileInfoT::splitBlock(const BasicBlock *Old, + const BasicBlock* New) { const Function *F = Old->getParent(); std::map::iterator J = EdgeInformation.find(F); if (J == EdgeInformation.end()) return; - DEBUG(errs() << "Splitting " << Old->getName() << " to " << New->getName() << "\n"); + DEBUG(dbgs() << "Splitting " << Old->getName() << " to " << New->getName() << "\n"); std::set Edges; for (EdgeWeights::iterator ewi = J->second.begin(), ewe = J->second.end(); @@ -426,14 +435,16 @@ void ProfileInfo::splitBlock(const BasicBlock *Old, const BasicBlock* New) { } template<> -void ProfileInfo::splitBlock(const BasicBlock *BB, const BasicBlock* NewBB, - BasicBlock *const *Preds, unsigned NumPreds) { +void ProfileInfoT::splitBlock(const BasicBlock *BB, + const BasicBlock* NewBB, + BasicBlock *const *Preds, + unsigned NumPreds) { const Function *F = BB->getParent(); std::map::iterator J = EdgeInformation.find(F); if (J == EdgeInformation.end()) return; - DEBUG(errs() << "Splitting " << NumPreds << " Edges from " << BB->getName() + DEBUG(dbgs() << "Splitting " << NumPreds << " Edges from " << BB->getName() << " to " << NewBB->getName() << "\n"); // Collect weight that was redirected over NewBB. @@ -461,8 +472,9 @@ void ProfileInfo::splitBlock(const BasicBlock *BB, const BasicBlock* NewBB, } template<> -void ProfileInfo::transfer(const Function *Old, const Function *New) { - DEBUG(errs() << "Replacing Function " << Old->getName() << " with " +void ProfileInfoT::transfer(const Function *Old, + const Function *New) { + DEBUG(dbgs() << "Replacing Function " << Old->getName() << " with " << New->getName() << "\n"); std::map::iterator J = EdgeInformation.find(Old); @@ -474,8 +486,8 @@ void ProfileInfo::transfer(const Function *Old, const Function *New) { FunctionInformation.erase(Old); } -static double readEdgeOrRemember(ProfileInfo::Edge edge, double w, ProfileInfo::Edge &tocalc, - unsigned &uncalc) { +static double readEdgeOrRemember(ProfileInfo::Edge edge, double w, + ProfileInfo::Edge &tocalc, unsigned &uncalc) { if (w == ProfileInfo::MissingValue) { tocalc = edge; uncalc++; @@ -486,7 +498,9 @@ static double readEdgeOrRemember(ProfileInfo::Edge edge, double w, ProfileInfo:: } template<> -bool ProfileInfo::CalculateMissingEdge(const BasicBlock *BB, Edge &removed, bool assumeEmptySelf) { +bool ProfileInfoT:: + CalculateMissingEdge(const BasicBlock *BB, Edge &removed, + bool assumeEmptySelf) { Edge edgetocalc; unsigned uncalculated = 0; @@ -538,7 +552,7 @@ bool ProfileInfo::CalculateMissingEdge(const BasicBlock *BB, Edge &removed, bool } else { EdgeInformation[BB->getParent()][edgetocalc] = incount-outcount; } - DEBUG(errs() << "--Calc Edge Counter for " << edgetocalc << ": " + DEBUG(dbgs() << "--Calc Edge Counter for " << edgetocalc << ": " << format("%.20g", getEdgeWeight(edgetocalc)) << "\n"); removed = edgetocalc; return true; @@ -562,7 +576,7 @@ static void readEdge(ProfileInfo *PI, ProfileInfo::Edge e, double &calcw, std::s } template<> -bool ProfileInfo::EstimateMissingEdges(const BasicBlock *BB) { +bool ProfileInfoT::EstimateMissingEdges(const BasicBlock *BB) { bool hasNoSuccessors = false; double inWeight = 0; @@ -619,7 +633,7 @@ bool ProfileInfo::EstimateMissingEdges(const BasicBlock *BB) { } template<> -void ProfileInfo::repair(const Function *F) { +void ProfileInfoT::repair(const Function *F) { // if (getExecutionCount(&(F->getEntryBlock())) == 0) { // for (Function::const_iterator FI = F->begin(), FE = F->end(); // FI != FE; ++FI) { @@ -968,9 +982,9 @@ void ProfileInfo::repair(const Function *F) { FI = Unvisited.begin(), FE = Unvisited.end(); while(FI != FE) { const BasicBlock *BB = *FI; ++FI; - errs() << BB->getName(); + dbgs() << BB->getName(); if (FI != FE) - errs() << ","; + dbgs() << ","; } errs() << "}"; @@ -1065,6 +1079,20 @@ namespace { struct NoProfileInfo : public ImmutablePass, public ProfileInfo { static char ID; // Class identification, replacement for typeinfo NoProfileInfo() : ImmutablePass(&ID) {} + + /// getAdjustedAnalysisPointer - This method is used when a pass implements + /// an analysis interface through multiple inheritance. If needed, it + /// should override this to adjust the this pointer as needed for the + /// specified pass info. + virtual void *getAdjustedAnalysisPointer(const PassInfo *PI) { + if (PI->isPassID(&ProfileInfo::ID)) + return (ProfileInfo*)this; + return this; + } + + virtual const char *getPassName() const { + return "NoProfileInfo"; + } }; } // End of anonymous namespace