X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FAnalysis%2FProfileInfo.cpp;h=173de2c027915ec5325fea750515d05325c30f58;hb=4032eaf98c63b0fb1f2418a1cdc56b72bc76c329;hp=c49c6e1fa78de82882d6296d80672ce63a43b3f3;hpb=bc8858c3b058bbee5a1a1fd5950050cf610fd507;p=oota-llvm.git diff --git a/lib/Analysis/ProfileInfo.cpp b/lib/Analysis/ProfileInfo.cpp index c49c6e1fa78..173de2c0279 100644 --- a/lib/Analysis/ProfileInfo.cpp +++ b/lib/Analysis/ProfileInfo.cpp @@ -24,8 +24,12 @@ #include using namespace llvm; +namespace llvm { + template<> char ProfileInfoT::ID = 0; +} + // Register the ProfileInfo interface, providing a nice name to refer to. -static RegisterAnalysisGroup Z("Profile Information"); +INITIALIZE_ANALYSIS_GROUP(ProfileInfo, "Profile Information", NoProfileInfo) namespace llvm { @@ -43,9 +47,6 @@ ProfileInfoT::~ProfileInfoT() { if (MachineProfile) delete MachineProfile; } -template<> -char ProfileInfoT::ID = 0; - template<> char ProfileInfoT::ID = 0; @@ -67,26 +68,28 @@ ProfileInfoT::getExecutionCount(const BasicBlock *BB) { double Count = MissingValue; - pred_const_iterator PI = pred_begin(BB), PE = pred_end(BB); + const_pred_iterator PI = pred_begin(BB), PE = pred_end(BB); // Are there zero predecessors of this block? if (PI == PE) { - Edge e = getEdge(0,BB); + Edge e = getEdge(0, BB); Count = getEdgeWeight(e); } else { // Otherwise, if there are predecessors, the execution count of this block is // the sum of the edge frequencies from the incoming edges. std::set ProcessedPreds; Count = 0; - for (; PI != PE; ++PI) - if (ProcessedPreds.insert(*PI).second) { - double w = getEdgeWeight(getEdge(*PI, BB)); + for (; PI != PE; ++PI) { + const BasicBlock *P = *PI; + if (ProcessedPreds.insert(P).second) { + double w = getEdgeWeight(getEdge(P, BB)); if (w == MissingValue) { Count = MissingValue; break; } Count += w; } + } } // If the predecessors did not suffice to get block weight, try successors. @@ -163,7 +166,7 @@ double ProfileInfoT:: template<> void ProfileInfoT:: setExecutionCount(const BasicBlock *BB, double w) { - DEBUG(errs() << "Creating Block " << BB->getName() + DEBUG(dbgs() << "Creating Block " << BB->getName() << " (weight: " << format("%.20g",w) << ")\n"); BlockInformation[BB->getParent()][BB] = w; } @@ -171,7 +174,7 @@ void ProfileInfoT:: template<> void ProfileInfoT:: setExecutionCount(const MachineBasicBlock *MBB, double w) { - DEBUG(errs() << "Creating Block " << MBB->getBasicBlock()->getName() + DEBUG(dbgs() << "Creating Block " << MBB->getBasicBlock()->getName() << " (weight: " << format("%.20g",w) << ")\n"); BlockInformation[MBB->getParent()][MBB] = w; } @@ -180,7 +183,7 @@ template<> 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; } @@ -190,7 +193,7 @@ 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; } @@ -201,7 +204,7 @@ void ProfileInfoT::removeBlock(const BasicBlock *BB) { 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); } @@ -211,7 +214,7 @@ void ProfileInfoT::removeEdge(Edge e) { EdgeInformation.find(getFunction(e)); if (J == EdgeInformation.end()) return; - DEBUG(errs() << "Deleting" << e << "\n"); + DEBUG(dbgs() << "Deleting" << e << "\n"); J->second.erase(e); } @@ -221,10 +224,10 @@ void ProfileInfoT:: 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); @@ -277,7 +280,7 @@ const BasicBlock *ProfileInfoT:: template<> void ProfileInfoT:: divertFlow(const Edge &oldedge, const Edge &newedge) { - DEBUG(errs() << "Diverting " << oldedge << " via " << newedge ); + DEBUG(dbgs() << "Diverting " << oldedge << " via " << newedge ); // First check if the old edge was taken, if not, just delete it... if (getEdgeWeight(oldedge) == 0) { @@ -291,7 +294,7 @@ void ProfileInfoT:: 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); @@ -306,13 +309,13 @@ void ProfileInfoT:: removeEdge(oldedge); } -/// Replaces all occurences of RmBB in the ProfilingInfo with DestBB. +/// Replaces all occurrences of RmBB in the ProfilingInfo with DestBB. /// This checks all edges of the function the blocks reside in and replaces the -/// occurences of RmBB with DestBB. +/// occurrences of RmBB with DestBB. template<> void ProfileInfoT:: replaceAllUses(const BasicBlock *RmBB, const BasicBlock *DestBB) { - DEBUG(errs() << "Replacing " << RmBB->getName() + DEBUG(dbgs() << "Replacing " << RmBB->getName() << " with " << DestBB->getName() << "\n"); const Function *F = DestBB->getParent(); std::map::iterator J = @@ -413,7 +416,7 @@ void ProfileInfoT::splitBlock(const BasicBlock *Old, 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(); @@ -444,7 +447,7 @@ void ProfileInfoT::splitBlock(const BasicBlock *BB, 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. @@ -474,7 +477,7 @@ void ProfileInfoT::splitBlock(const BasicBlock *BB, template<> void ProfileInfoT::transfer(const Function *Old, const Function *New) { - DEBUG(errs() << "Replacing Function " << Old->getName() << " with " + DEBUG(dbgs() << "Replacing Function " << Old->getName() << " with " << New->getName() << "\n"); std::map::iterator J = EdgeInformation.find(Old); @@ -508,7 +511,7 @@ bool ProfileInfoT:: // have no value double incount = 0; SmallSet pred_visited; - pred_const_iterator bbi = pred_begin(BB), bbe = pred_end(BB); + const_pred_iterator bbi = pred_begin(BB), bbe = pred_end(BB); if (bbi==bbe) { Edge e = getEdge(0,BB); incount += readEdgeOrRemember(e, getEdgeWeight(e) ,edgetocalc,uncalculated); @@ -552,7 +555,7 @@ bool ProfileInfoT:: } 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; @@ -577,12 +580,10 @@ static void readEdge(ProfileInfo *PI, ProfileInfo::Edge e, double &calcw, std::s template<> bool ProfileInfoT::EstimateMissingEdges(const BasicBlock *BB) { - bool hasNoSuccessors = false; - double inWeight = 0; std::set inMissing; std::set ProcessedPreds; - pred_const_iterator bbi = pred_begin(BB), bbe = pred_end(BB); + const_pred_iterator bbi = pred_begin(BB), bbe = pred_end(BB); if (bbi == bbe) { readEdge(this,getEdge(0,BB),inWeight,inMissing); } @@ -596,10 +597,8 @@ bool ProfileInfoT::EstimateMissingEdges(const BasicBlock *B std::set outMissing; std::set ProcessedSuccs; succ_const_iterator sbbi = succ_begin(BB), sbbe = succ_end(BB); - if (sbbi == sbbe) { + if (sbbi == sbbe) readEdge(this,getEdge(BB,0),outWeight,outMissing); - hasNoSuccessors = true; - } for ( ; sbbi != sbbe; ++sbbi ) { if (ProcessedSuccs.insert(*sbbi).second) { readEdge(this,getEdge(BB,*sbbi),outWeight,outMissing); @@ -639,7 +638,7 @@ void ProfileInfoT::repair(const Function *F) { // FI != FE; ++FI) { // const BasicBlock* BB = &(*FI); // { -// pred_const_iterator NBB = pred_begin(BB), End = pred_end(BB); +// const_pred_iterator NBB = pred_begin(BB), End = pred_end(BB); // if (NBB == End) { // setEdgeWeight(getEdge(0,BB),0); // } @@ -779,7 +778,7 @@ void ProfileInfoT::repair(const Function *F) { // Calculate incoming flow. double iw = 0; unsigned inmissing = 0; unsigned incount = 0; unsigned invalid = 0; std::set Processed; - for (pred_const_iterator NBB = pred_begin(BB), End = pred_end(BB); + for (const_pred_iterator NBB = pred_begin(BB), End = pred_end(BB); NBB != End; ++NBB) { if (Processed.insert(*NBB).second) { Edge e = getEdge(*NBB, BB); @@ -813,7 +812,7 @@ void ProfileInfoT::repair(const Function *F) { } if (iw < 0) continue; - // Check the recieving end of the path if it can handle the flow. + // Check the receiving end of the path if it can handle the flow. double ow = getExecutionCount(Dest); Processed.clear(); for (succ_const_iterator NBB = succ_begin(BB), End = succ_end(BB); @@ -869,7 +868,7 @@ void ProfileInfoT::repair(const Function *F) { if (getEdgeWeight(e) == MissingValue) { double iw = 0; std::set Processed; - for (pred_const_iterator NBB = pred_begin(BB), End = pred_end(BB); + for (const_pred_iterator NBB = pred_begin(BB), End = pred_end(BB); NBB != End; ++NBB) { if (Processed.insert(*NBB).second) { Edge e = getEdge(*NBB, BB); @@ -890,10 +889,10 @@ void ProfileInfoT::repair(const Function *F) { FI = Unvisited.begin(), FE = Unvisited.end(); while(FI != FE && !FoundPath) { const BasicBlock *BB = *FI; ++FI; - const BasicBlock *Dest; + const BasicBlock *Dest = 0; Path P; bool BackEdgeFound = false; - for (pred_const_iterator NBB = pred_begin(BB), End = pred_end(BB); + for (const_pred_iterator NBB = pred_begin(BB), End = pred_end(BB); NBB != End; ++NBB) { Dest = GetPath(BB, *NBB, P, GetPathToDest | GetPathWithNewEdges); if (Dest == *NBB) { @@ -935,7 +934,7 @@ void ProfileInfoT::repair(const Function *F) { // Calculate incoming flow. double iw = 0; std::set Processed; - for (pred_const_iterator NBB = pred_begin(BB), End = pred_end(BB); + for (const_pred_iterator NBB = pred_begin(BB), End = pred_end(BB); NBB != End; ++NBB) { if (Processed.insert(*NBB).second) { Edge e = getEdge(*NBB, BB); @@ -965,7 +964,7 @@ void ProfileInfoT::repair(const Function *F) { while(FI != FE && !FoundPath) { const BasicBlock *BB = *FI; ++FI; - for (pred_const_iterator NBB = pred_begin(BB), End = pred_end(BB); + for (const_pred_iterator NBB = pred_begin(BB), End = pred_end(BB); NBB != End; ++NBB) { Edge e = getEdge(*NBB,BB); double w = getEdgeWeight(e); @@ -982,9 +981,9 @@ void ProfileInfoT::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() << "}"; @@ -1078,16 +1077,29 @@ raw_ostream& operator<<(raw_ostream &O, std::pair -X("no-profile", "No Profile Information", false, true); - -// Declare that we implement the ProfileInfo interface -static RegisterAnalysisGroup Y(X); +INITIALIZE_AG_PASS(NoProfileInfo, ProfileInfo, "no-profile", + "No Profile Information", false, true, true) ImmutablePass *llvm::createNoProfileInfoPass() { return new NoProfileInfo(); }