From d4d79067c0c33875b00ad98afd569a77187bae1e Mon Sep 17 00:00:00 2001 From: Anand Shukla Date: Mon, 8 Jul 2002 19:36:01 +0000 Subject: [PATCH] changed function numbering git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2815 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../ProfilePaths/ProfilePaths.cpp | 189 +++++++++--------- 1 file changed, 91 insertions(+), 98 deletions(-) diff --git a/lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp b/lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp index 8bd8a6beda3..a3ddab2d64f 100644 --- a/lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp +++ b/lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp @@ -69,6 +69,17 @@ static Node *findBB(std::vector &st, BasicBlock *BB){ bool ProfilePaths::runOnFunction(Function &F){ static int mn = -1; + + if(F.size() <=1) { + return false; + } + + //increment counter for instrumented functions. mn is now function# + mn++; + + //std::cerr<<"MN = "<().getExitNode(); @@ -82,18 +93,10 @@ bool ProfilePaths::runOnFunction(Function &F){ // The nodes must be uniquesly identified: // That is, no two nodes must hav same BB* - // First enter just nodes: later enter edges - //<<<<<<< ProfilePaths.cpp - //for (Function::iterator BB = M->begin(), BE=M->end(); BB != BE; ++BB){ - //Node *nd=new Node(*BB); - //nodes.push_back(nd); - //if(*BB==ExitNode) - //======= for (Function::iterator BB = F.begin(), BE = F.end(); BB != BE; ++BB) { Node *nd=new Node(BB); nodes.push_back(nd); if(&*BB == ExitNode) - //>>>>>>> 1.13 exitNode=nd; if(&*BB==F.begin()) startNode=nd; @@ -106,13 +109,6 @@ bool ProfilePaths::runOnFunction(Function &F){ for(BasicBlock::succ_iterator s=succ_begin(BB), se=succ_end(BB); s!=se; ++s){ - //tempVec.push_back(*s); - //} - - //sort(tempVec.begin(), tempVec.end(), BBSort()); - - //for(vector::iterator s=tempVec.begin(), se=tempVec.end(); - //s!=se; ++s){ Node *nd2=findBB(nodes,*s); assert(nd2 && "No node for this edge!"); Edge ed(nd,nd2,0); @@ -122,104 +118,101 @@ bool ProfilePaths::runOnFunction(Function &F){ Graph g(nodes,edges, startNode, exitNode); - //#ifdef DEBUG_PATH_PROFILES - //std::cerr<<"Original graph\n"; - //printGraph(g); - //#endif +#ifdef DEBUG_PATH_PROFILES + std::cerr<<"Original graph\n"; + printGraph(g); +#endif - BasicBlock *fr=&F.front(); + BasicBlock *fr = &F.front(); - // If only one BB, don't instrument - if (++F.begin() == F.end()) { - mn++; - // The graph is made acyclic: this is done - // by removing back edges for now, and adding them later on - vector be; - g.getBackEdges(be); + // The graph is made acyclic: this is done + // by removing back edges for now, and adding them later on + vector be; + g.getBackEdges(be); - //std::cerr<<"BackEdges-------------\n"; - // for(vector::iterator VI=be.begin(); VI!=be.end(); ++VI){ - //printEdge(*VI); - //cerr<<"\n"; - //} - //std::cerr<<"------\n"; + //std::cerr<<"BackEdges-------------\n"; + // for(vector::iterator VI=be.begin(); VI!=be.end(); ++VI){ + //printEdge(*VI); + //cerr<<"\n"; + //} + //std::cerr<<"------\n"; #ifdef DEBUG_PATH_PROFILES - cerr<<"Backedges:"<b is a back edge - //Then we add 2 back edges for it: - //1. from root->b (in vector stDummy) - //and 2. from a->exit (in vector exDummy) - vector stDummy; - vector exDummy; - addDummyEdges(stDummy, exDummy, g, be); + //Now we need to reflect the effect of back edges + //This is done by adding dummy edges + //If a->b is a back edge + //Then we add 2 back edges for it: + //1. from root->b (in vector stDummy) + //and 2. from a->exit (in vector exDummy) + vector stDummy; + vector exDummy; + addDummyEdges(stDummy, exDummy, g, be); - //std::cerr<<"After adding dummy edges\n"; - //printGraph(g); + //std::cerr<<"After adding dummy edges\n"; + //printGraph(g); - // Now, every edge in the graph is assigned a weight - // This weight later adds on to assign path - // numbers to different paths in the graph - // All paths for now are acyclic, - // since no back edges in the graph now - // numPaths is the number of acyclic paths in the graph - int numPaths=valueAssignmentToEdges(g); + // Now, every edge in the graph is assigned a weight + // This weight later adds on to assign path + // numbers to different paths in the graph + // All paths for now are acyclic, + // since no back edges in the graph now + // numPaths is the number of acyclic paths in the graph + int numPaths=valueAssignmentToEdges(g); - //std::cerr<<"Numpaths="< vBB; + //now process the graph: get path numbers, + //get increments along different paths, + //and assign "increments" and "updates" (to r and count) + //"optimally". Finally, insert llvm code along various edges + processGraph(g, rVar, countVar, be, stDummy, exDummy, numPaths); + /* + //get the paths + static std::ofstream to("paths.sizes"); + static std::ofstream bbs("paths.look"); + assert(to && "Cannot open file\n"); + assert(bbs && "Cannot open file\n"); + for(int i=0;i vBB; - getBBtrace(vBB, i, M); - //get total size of vector - int size=0; - bbs<<"Meth:"<::iterator VBI=vBB.begin(); VBI!=vBB.end(); - ++VBI){ - BasicBlock *BB=*VBI; - size+=BB->size(); - if(BB==M->front()) - size-=numPaths; - bbs<getName()<<"->"; - } - bbs<<"\n--------------\n"; - to<<"::::: "<::iterator VBI=vBB.begin(); VBI!=vBB.end(); + ++VBI){ + BasicBlock *BB=*VBI; + size+=BB->size(); + if(BB==M->front()) + size-=numPaths; + bbs<getName()<<"->"; } + bbs<<"\n--------------\n"; + to<<"::::: "<