X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FAnalysis%2FProfileEstimatorPass.cpp;h=b594e2ba55065e0a9ddc56b160e7a951d229a4f5;hb=404b53e38ca7a77c6e86596ace68f3167cd33922;hp=8148429597ec3356a1528b9e02f202e4b32339c1;hpb=88a91b579bb300f700a4acc5917f9e3a048dd05c;p=oota-llvm.git diff --git a/lib/Analysis/ProfileEstimatorPass.cpp b/lib/Analysis/ProfileEstimatorPass.cpp index 8148429597e..b594e2ba550 100644 --- a/lib/Analysis/ProfileEstimatorPass.cpp +++ b/lib/Analysis/ProfileEstimatorPass.cpp @@ -39,7 +39,8 @@ namespace { public: static char ID; // Class identification, replacement for typeinfo explicit ProfileEstimatorPass(const double execcount = 0) - : FunctionPass(&ID), ExecCount(execcount) { + : FunctionPass(ID), ExecCount(execcount) { + initializeProfileEstimatorPassPass(*PassRegistry::getPassRegistry()); if (execcount == 0) ExecCount = LoopWeight; } @@ -55,6 +56,16 @@ namespace { /// run - Estimate the profile information from the specified file. virtual bool runOnFunction(Function &F); + /// 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(AnalysisID PI) { + if (PI == &ProfileInfo::ID) + return (ProfileInfo*)this; + return this; + } + virtual void recurseBasicBlock(BasicBlock *BB); void inline printEdgeWeight(Edge); @@ -62,13 +73,14 @@ namespace { } // End of anonymous namespace char ProfileEstimatorPass::ID = 0; -static RegisterPass -X("profile-estimator", "Estimate profiling information", false, true); - -static RegisterAnalysisGroup Y(X); +INITIALIZE_AG_PASS_BEGIN(ProfileEstimatorPass, ProfileInfo, "profile-estimator", + "Estimate profiling information", false, true, false) +INITIALIZE_PASS_DEPENDENCY(LoopInfo) +INITIALIZE_AG_PASS_END(ProfileEstimatorPass, ProfileInfo, "profile-estimator", + "Estimate profiling information", false, true, false) namespace llvm { - const PassInfo *ProfileEstimatorPassID = &X; + char &ProfileEstimatorPassID = ProfileEstimatorPass::ID; FunctionPass *createProfileEstimatorPass() { return new ProfileEstimatorPass(); @@ -87,11 +99,11 @@ static double ignoreMissing(double w) { } static void inline printEdgeError(ProfileInfo::Edge e, const char *M) { - DEBUG(errs() << "-- Edge " << e << " is not calculated, " << M << "\n"); + DEBUG(dbgs() << "-- Edge " << e << " is not calculated, " << M << "\n"); } void inline ProfileEstimatorPass::printEdgeWeight(Edge E) { - DEBUG(errs() << "-- Weight of Edge " << E << ":" + DEBUG(dbgs() << "-- Weight of Edge " << E << ":" << format("%20.20g", getEdgeWeight(E)) << "\n"); } @@ -128,7 +140,7 @@ void ProfileEstimatorPass::recurseBasicBlock(BasicBlock *BB) { // loop, thus the edge is a backedge, continue and do not check if the // value is valid. if (BBisHeader && BBLoop->contains(*bbi)) { - printEdgeError(edge, "but is backedge, continueing"); + printEdgeError(edge, "but is backedge, continuing"); continue; } // If the edges value is missing (and this is no loop header, and this is @@ -179,7 +191,7 @@ void ProfileEstimatorPass::recurseBasicBlock(BasicBlock *BB) { // from weight. if (MinimalWeight.find(*ei) != MinimalWeight.end()) { incoming -= MinimalWeight[*ei]; - DEBUG(errs() << "Reserving " << format("%.20g",MinimalWeight[*ei]) << " at " << (*ei) << "\n"); + DEBUG(dbgs() << "Reserving " << format("%.20g",MinimalWeight[*ei]) << " at " << (*ei) << "\n"); } } else { incoming -= w; @@ -217,7 +229,7 @@ void ProfileEstimatorPass::recurseBasicBlock(BasicBlock *BB) { // Read necessary minimal weight. if (MinimalWeight.find(*ei) != MinimalWeight.end()) { EdgeInformation[BB->getParent()][*ei] += MinimalWeight[*ei]; - DEBUG(errs() << "Additionally " << format("%.20g",MinimalWeight[*ei]) << " at " << (*ei) << "\n"); + DEBUG(dbgs() << "Additionally " << format("%.20g",MinimalWeight[*ei]) << " at " << (*ei) << "\n"); } printEdgeWeight(*ei); @@ -232,7 +244,7 @@ void ProfileEstimatorPass::recurseBasicBlock(BasicBlock *BB) { MinimalWeight[e] = 0; } MinimalWeight[e] += w; - DEBUG(errs() << "Minimal Weight for " << e << ": " << format("%.20g",MinimalWeight[e]) << "\n"); + DEBUG(dbgs() << "Minimal Weight for " << e << ": " << format("%.20g",MinimalWeight[e]) << "\n"); Dest = Parent; } } @@ -268,7 +280,7 @@ void ProfileEstimatorPass::recurseBasicBlock(BasicBlock *BB) { // from block weight, this is readded later on. if (MinimalWeight.find(edge) != MinimalWeight.end()) { BBWeight -= MinimalWeight[edge]; - DEBUG(errs() << "Reserving " << format("%.20g",MinimalWeight[edge]) << " at " << edge << "\n"); + DEBUG(dbgs() << "Reserving " << format("%.20g",MinimalWeight[edge]) << " at " << edge << "\n"); } } } @@ -288,7 +300,7 @@ void ProfileEstimatorPass::recurseBasicBlock(BasicBlock *BB) { // Readd minial necessary weight. if (MinimalWeight.find(*ei) != MinimalWeight.end()) { EdgeInformation[BB->getParent()][*ei] += MinimalWeight[*ei]; - DEBUG(errs() << "Additionally " << format("%.20g",MinimalWeight[*ei]) << " at " << (*ei) << "\n"); + DEBUG(dbgs() << "Additionally " << format("%.20g",MinimalWeight[*ei]) << " at " << (*ei) << "\n"); } printEdgeWeight(*ei); } @@ -311,6 +323,7 @@ bool ProfileEstimatorPass::runOnFunction(Function &F) { FunctionInformation.erase(&F); BlockInformation[&F].clear(); EdgeInformation[&F].clear(); + BBToVisit.clear(); // Mark all blocks as to visit. for (Function::iterator bi = F.begin(), be = F.end(); bi != be; ++bi) @@ -319,7 +332,7 @@ bool ProfileEstimatorPass::runOnFunction(Function &F) { // Clear Minimal Edges. MinimalWeight.clear(); - DEBUG(errs() << "Working on function " << F.getNameStr() << "\n"); + DEBUG(dbgs() << "Working on function " << F.getNameStr() << "\n"); // Since the entry block is the first one and has no predecessors, the edge // (0,entry) is inserted with the starting weight of 1. @@ -366,7 +379,7 @@ bool ProfileEstimatorPass::runOnFunction(Function &F) { if (Dest != *bbi) { // If there is no circle, just set edge weight to 0 EdgeInformation[&F][e] = 0; - DEBUG(errs() << "Assuming edge weight: "); + DEBUG(dbgs() << "Assuming edge weight: "); printEdgeWeight(e); found = true; } @@ -375,7 +388,7 @@ bool ProfileEstimatorPass::runOnFunction(Function &F) { } if (!found) { cleanup = true; - DEBUG(errs() << "No assumption possible in Fuction "<