From e1fc2d965fc5b0e45d57f29ccfdf8e1964b88eee Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 22 May 2002 21:56:32 +0000 Subject: [PATCH] Convert code to use the DEBUG macro so that debug code can simply be enabled with the -debug command line option. llvm-svn: 2721 --- .../Instrumentation/ProfilePaths/EdgeCode.cpp | 15 +- .../Instrumentation/ProfilePaths/Graph.cpp | 36 ++--- .../ProfilePaths/GraphAuxiliary.cpp | 142 ++++++++---------- .../ProfilePaths/GraphAuxillary.cpp | 142 ++++++++---------- .../ProfilePaths/ProfilePaths.cpp | 9 +- 5 files changed, 147 insertions(+), 197 deletions(-) diff --git a/llvm/lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp b/llvm/lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp index 0b6d17d683dc..f8d761627edd 100644 --- a/llvm/lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp +++ b/llvm/lib/Transforms/Instrumentation/ProfilePaths/EdgeCode.cpp @@ -201,12 +201,9 @@ void insertBB(Edge ed, BasicBlock* BB1=ed.getFirst()->getElement(); BasicBlock* BB2=ed.getSecond()->getElement(); -#ifdef DEBUG_PATH_PROFILES - //debugging info - cerr<<"Edges with codes ######################\n"; - cerr<getName()<<"->"<getName()<<"\n"; - cerr<<"########################\n"; -#endif + DEBUG(cerr << "Edges with codes ######################\n"; + cerr << BB1->getName() << "->" << BB2->getName() << "\n"; + cerr << "########################\n"); //We need to insert a BB between BB1 and BB2 TerminatorInst *TI=BB1->getTerminator(); @@ -250,10 +247,8 @@ void insertBB(Edge ed, BB2Inst!=BBend; ++BB2Inst){ if(PHINode *phiInst=dyn_cast(*BB2Inst)){ -#ifdef DEBUG_PATH_PROFILES - cerr<<"YYYYYYYYYYYYYYYYY\n"; -#endif - + DEBUG(cerr<<"YYYYYYYYYYYYYYYYY\n"); + int bbIndex=phiInst->getBasicBlockIndex(BB1); if(bbIndex>=0) phiInst->setIncomingBlock(bbIndex, newBB); diff --git a/llvm/lib/Transforms/Instrumentation/ProfilePaths/Graph.cpp b/llvm/lib/Transforms/Instrumentation/ProfilePaths/Graph.cpp index 206af1f682d5..0e7bce06b4d0 100644 --- a/llvm/lib/Transforms/Instrumentation/ProfilePaths/Graph.cpp +++ b/llvm/lib/Transforms/Instrumentation/ProfilePaths/Graph.cpp @@ -239,17 +239,15 @@ Graph* Graph::getMaxSpanningTree(){ //keep pulling out vertex of min wt from vt while(!vt.empty()){ Node *u=*(min_element(vt.begin(), vt.end(), compare_nodes())); -#ifdef DEBUG_PATH_PROFILES - cerr<<"popped wt"<<(u)->getWeight()<<"\n"; - printNode(u); -#endif + DEBUG(cerr<<"popped wt"<<(u)->getWeight()<<"\n"; + printNode(u)); + if(parent[u]!=NULL){ //so not root Edge edge(parent[u],u, ed_weight[u]); //assign edge in spanning tree st->addEdge(edge,ed_weight[u]); -#ifdef DEBUG_PATH_PROFILES - cerr<<"added:\n"; - printEdge(edge); -#endif + + DEBUG(cerr<<"added:\n"; + printEdge(edge)); } //vt.erase(u); @@ -276,21 +274,19 @@ Graph* Graph::getMaxSpanningTree(){ break; } } -#ifdef DEBUG_PATH_PROFILES - cerr<<"wt:v->wt"<getWeight()<<"\n"; - printNode(v);cerr<<"node wt:"<<(*v).weight<<"\n"; -#endif + DEBUG(cerr<<"wt:v->wt"<getWeight()<<"\n"; + printNode(v);cerr<<"node wt:"<<(*v).weight<<"\n"); + //so if v in in vt, change wt(v) to wt(u->v) //only if wt(u->v)getWeight()){ parent[v]=u; ed_weight[v]=weight; v->setWeight(weight); -#ifdef DEBUG_PATH_PROFILES - cerr<getWeight()<<":Set weight------\n"; - printGraph(); - printEdge(Edge(u,v,weight)); -#endif + + DEBUG(cerr<getWeight()<<":Set weight------\n"; + printGraph(); + printEdge(Edge(u,v,weight))); } } } @@ -352,10 +348,8 @@ void Graph::makeUnDirectional(){ for(nodeList::iterator NLI=nl.begin(), NLE=nl.end(); NLI!=NLE; ++NLI){ Edge ed(NLI->element, *NI, NLI->weight); if(!hasEdgeAndWt(ed)){ -#ifdef DEBUG_PATH_PROFILES - cerr<<"######doesn't hv\n"; - printEdge(ed); -#endif + DEBUG(cerr<<"######doesn't hv\n"; + printEdge(ed)); addEdgeForce(ed); } } diff --git a/llvm/lib/Transforms/Instrumentation/ProfilePaths/GraphAuxiliary.cpp b/llvm/lib/Transforms/Instrumentation/ProfilePaths/GraphAuxiliary.cpp index 0dd4fcfb6c92..b2c5445c4506 100644 --- a/llvm/lib/Transforms/Instrumentation/ProfilePaths/GraphAuxiliary.cpp +++ b/llvm/lib/Transforms/Instrumentation/ProfilePaths/GraphAuxiliary.cpp @@ -355,19 +355,17 @@ static void moveDummyCode(const vector &stDummy, map &insertions){ typedef vector::const_iterator vec_iter; -#ifdef DEBUG_PATH_PROFILES - //print all back, st and ex dummy - cerr<<"BackEdges---------------\n"; - for(vec_iter VI=be.begin(); VI!=be.end(); ++VI) - printEdge(*VI); - cerr<<"StEdges---------------\n"; - for(vec_iter VI=stDummy.begin(); VI!=stDummy.end(); ++VI) - printEdge(*VI); - cerr<<"ExitEdges---------------\n"; - for(vec_iter VI=exDummy.begin(); VI!=exDummy.end(); ++VI) - printEdge(*VI); - cerr<<"------end all edges\n"; -#endif + DEBUG( //print all back, st and ex dummy + cerr<<"BackEdges---------------\n"; + for(vec_iter VI=be.begin(); VI!=be.end(); ++VI) + printEdge(*VI); + cerr<<"StEdges---------------\n"; + for(vec_iter VI=stDummy.begin(); VI!=stDummy.end(); ++VI) + printEdge(*VI); + cerr<<"ExitEdges---------------\n"; + for(vec_iter VI=exDummy.begin(); VI!=exDummy.end(); ++VI) + printEdge(*VI); + cerr<<"------end all edges\n"); std::vector toErase; for(map::iterator MI=insertions.begin(), @@ -375,17 +373,16 @@ static void moveDummyCode(const vector &stDummy, Edge ed=MI->first; getEdgeCode *edCd=MI->second; bool dummyHasIt=false; -#ifdef DEBUG_PATH_PROFILES - cerr<<"Current edge considered---\n"; - printEdge(ed); -#endif + + DEBUG(cerr<<"Current edge considered---\n"; + printEdge(ed)); + //now check if stDummy has ed for(vec_iter VI=stDummy.begin(), VE=stDummy.end(); VI!=VE && !dummyHasIt; ++VI){ if(*VI==ed){ -#ifdef DEBUG_PATH_PROFILES - cerr<<"Edge matched with stDummy\n"; -#endif + DEBUG(cerr<<"Edge matched with stDummy\n"); + dummyHasIt=true; bool dummyInBe=false; //dummy edge with code @@ -395,10 +392,9 @@ static void moveDummyCode(const vector &stDummy, Node *dm=ed.getSecond(); if(*dm==*st){ //so this is the back edge to use -#ifdef DEBUG_PATH_PROFILES - cerr<<"Moving to backedge\n"; - printEdge(backEdge); -#endif + DEBUG(cerr<<"Moving to backedge\n"; + printEdge(backEdge)); + getEdgeCode *ged=new getEdgeCode(); ged->setCdIn(edCd); toErase.push_back(ed); @@ -416,9 +412,7 @@ static void moveDummyCode(const vector &stDummy, ++VI){ if(*VI==ed){ inExDummy=true; -#ifdef DEBUG_PATH_PROFILES - cerr<<"Edge matched with exDummy\n"; -#endif + DEBUG(cerr<<"Edge matched with exDummy\n"); bool dummyInBe2=false; //dummy edge with code for(vec_iter BE=be.begin(), BEE=be.end(); BE!=BEE && !dummyInBe2; @@ -445,17 +439,13 @@ static void moveDummyCode(const vector &stDummy, } } -#ifdef DEBUG_PATH_PROFILES - cerr<<"size of deletions: "<::iterator vmi=toErase.begin(), vme=toErase.end(); vmi!=vme; ++vmi) insertions.erase(*vmi); -#ifdef DEBUG_PATH_PROFILES - cerr<<"SIZE OF INSERTIONS AFTER DEL "<root node //and re-add it with weight 0 //since infinite weight is kinda confusing @@ -555,10 +542,9 @@ void processGraph(Graph &g, t->addEdge(edNew,0); } -#ifdef DEBUG_PATH_PROFILES - printGraph(g); - printGraph(*t); -#endif + DEBUG(printGraph(g); + printGraph(*t)); + //step 5: Get edge increments //Now we select a subset of all edges @@ -566,14 +552,13 @@ void processGraph(Graph &g, //if we consider just this subset, it still represents //the path sum along any path in the graph map increment=getEdgeIncrements(g,*t); -#ifdef DEBUG_PATH_PROFILES - //print edge increments for debugging - for(map::iterator M_I=increment.begin(), M_E=increment.end(); - M_I!=M_E; ++M_I){ - printEdge(M_I->first); - cerr<<"Increment for above:"<second<<"\n"; - } -#endif + + DEBUG(//print edge increments for debugging + for(map::iterator MI=increment.begin(), ME = increment.end(); + MI != ME; ++MI) { + printEdge(MI->first); + cerr << "Increment for above:" << MI->second << "\n"; + }); //step 6: Get code insertions @@ -587,33 +572,30 @@ void processGraph(Graph &g, map codeInsertions; getCodeInsertions(g, codeInsertions, chords,increment); -#ifdef DEBUG_PATH_PROFILES - //print edges with code for debugging - cerr<<"Code inserted in following---------------\n"; - for(map::iterator cd_i=codeInsertions->begin(), - cd_e=codeInsertions->end(); cd_i!=cd_e; ++cd_i){ - printEdge(cd_i->first); - cerr<second->getCond()<<":"<second->getInc()<<"\n"; - } - cerr<<"-----end insertions\n"; -#endif + DEBUG (//print edges with code for debugging + cerr<<"Code inserted in following---------------\n"; + for(map::iterator cd_i=codeInsertions.begin(), + cd_e=codeInsertions.end(); cd_i!=cd_e; ++cd_i){ + printEdge(cd_i->first); + cerr<second->getCond()<<":"<second->getInc()<<"\n"; + } + cerr<<"-----end insertions\n"); + //step 7: move code on dummy edges over to the back edges //Move the incoming dummy edge code and outgoing dummy //edge code over to the corresponding back edge moveDummyCode(stDummy, exDummy, be, codeInsertions); -#ifdef DEBUG_PATH_PROFILES - //debugging info - cerr<<"After moving dummy code\n"; - for(map::iterator cd_i=codeInsertions.begin(), - cd_e=codeInsertions.end(); cd_i != cd_e; ++cd_i){ - printEdge(cd_i->first); - cerr<second->getCond()<<":" - <second->getInc()<<"\n"; - } - cerr<<"Dummy end------------\n"; -#endif + DEBUG(//debugging info + cerr<<"After moving dummy code\n"; + for(map::iterator cd_i=codeInsertions.begin(), + cd_e=codeInsertions.end(); cd_i != cd_e; ++cd_i){ + printEdge(cd_i->first); + cerr<second->getCond()<<":" + <second->getInc()<<"\n"; + } + cerr<<"Dummy end------------\n"); //see what it looks like... //now insert code along edges which have codes on them diff --git a/llvm/lib/Transforms/Instrumentation/ProfilePaths/GraphAuxillary.cpp b/llvm/lib/Transforms/Instrumentation/ProfilePaths/GraphAuxillary.cpp index 0dd4fcfb6c92..b2c5445c4506 100644 --- a/llvm/lib/Transforms/Instrumentation/ProfilePaths/GraphAuxillary.cpp +++ b/llvm/lib/Transforms/Instrumentation/ProfilePaths/GraphAuxillary.cpp @@ -355,19 +355,17 @@ static void moveDummyCode(const vector &stDummy, map &insertions){ typedef vector::const_iterator vec_iter; -#ifdef DEBUG_PATH_PROFILES - //print all back, st and ex dummy - cerr<<"BackEdges---------------\n"; - for(vec_iter VI=be.begin(); VI!=be.end(); ++VI) - printEdge(*VI); - cerr<<"StEdges---------------\n"; - for(vec_iter VI=stDummy.begin(); VI!=stDummy.end(); ++VI) - printEdge(*VI); - cerr<<"ExitEdges---------------\n"; - for(vec_iter VI=exDummy.begin(); VI!=exDummy.end(); ++VI) - printEdge(*VI); - cerr<<"------end all edges\n"; -#endif + DEBUG( //print all back, st and ex dummy + cerr<<"BackEdges---------------\n"; + for(vec_iter VI=be.begin(); VI!=be.end(); ++VI) + printEdge(*VI); + cerr<<"StEdges---------------\n"; + for(vec_iter VI=stDummy.begin(); VI!=stDummy.end(); ++VI) + printEdge(*VI); + cerr<<"ExitEdges---------------\n"; + for(vec_iter VI=exDummy.begin(); VI!=exDummy.end(); ++VI) + printEdge(*VI); + cerr<<"------end all edges\n"); std::vector toErase; for(map::iterator MI=insertions.begin(), @@ -375,17 +373,16 @@ static void moveDummyCode(const vector &stDummy, Edge ed=MI->first; getEdgeCode *edCd=MI->second; bool dummyHasIt=false; -#ifdef DEBUG_PATH_PROFILES - cerr<<"Current edge considered---\n"; - printEdge(ed); -#endif + + DEBUG(cerr<<"Current edge considered---\n"; + printEdge(ed)); + //now check if stDummy has ed for(vec_iter VI=stDummy.begin(), VE=stDummy.end(); VI!=VE && !dummyHasIt; ++VI){ if(*VI==ed){ -#ifdef DEBUG_PATH_PROFILES - cerr<<"Edge matched with stDummy\n"; -#endif + DEBUG(cerr<<"Edge matched with stDummy\n"); + dummyHasIt=true; bool dummyInBe=false; //dummy edge with code @@ -395,10 +392,9 @@ static void moveDummyCode(const vector &stDummy, Node *dm=ed.getSecond(); if(*dm==*st){ //so this is the back edge to use -#ifdef DEBUG_PATH_PROFILES - cerr<<"Moving to backedge\n"; - printEdge(backEdge); -#endif + DEBUG(cerr<<"Moving to backedge\n"; + printEdge(backEdge)); + getEdgeCode *ged=new getEdgeCode(); ged->setCdIn(edCd); toErase.push_back(ed); @@ -416,9 +412,7 @@ static void moveDummyCode(const vector &stDummy, ++VI){ if(*VI==ed){ inExDummy=true; -#ifdef DEBUG_PATH_PROFILES - cerr<<"Edge matched with exDummy\n"; -#endif + DEBUG(cerr<<"Edge matched with exDummy\n"); bool dummyInBe2=false; //dummy edge with code for(vec_iter BE=be.begin(), BEE=be.end(); BE!=BEE && !dummyInBe2; @@ -445,17 +439,13 @@ static void moveDummyCode(const vector &stDummy, } } -#ifdef DEBUG_PATH_PROFILES - cerr<<"size of deletions: "<::iterator vmi=toErase.begin(), vme=toErase.end(); vmi!=vme; ++vmi) insertions.erase(*vmi); -#ifdef DEBUG_PATH_PROFILES - cerr<<"SIZE OF INSERTIONS AFTER DEL "<root node //and re-add it with weight 0 //since infinite weight is kinda confusing @@ -555,10 +542,9 @@ void processGraph(Graph &g, t->addEdge(edNew,0); } -#ifdef DEBUG_PATH_PROFILES - printGraph(g); - printGraph(*t); -#endif + DEBUG(printGraph(g); + printGraph(*t)); + //step 5: Get edge increments //Now we select a subset of all edges @@ -566,14 +552,13 @@ void processGraph(Graph &g, //if we consider just this subset, it still represents //the path sum along any path in the graph map increment=getEdgeIncrements(g,*t); -#ifdef DEBUG_PATH_PROFILES - //print edge increments for debugging - for(map::iterator M_I=increment.begin(), M_E=increment.end(); - M_I!=M_E; ++M_I){ - printEdge(M_I->first); - cerr<<"Increment for above:"<second<<"\n"; - } -#endif + + DEBUG(//print edge increments for debugging + for(map::iterator MI=increment.begin(), ME = increment.end(); + MI != ME; ++MI) { + printEdge(MI->first); + cerr << "Increment for above:" << MI->second << "\n"; + }); //step 6: Get code insertions @@ -587,33 +572,30 @@ void processGraph(Graph &g, map codeInsertions; getCodeInsertions(g, codeInsertions, chords,increment); -#ifdef DEBUG_PATH_PROFILES - //print edges with code for debugging - cerr<<"Code inserted in following---------------\n"; - for(map::iterator cd_i=codeInsertions->begin(), - cd_e=codeInsertions->end(); cd_i!=cd_e; ++cd_i){ - printEdge(cd_i->first); - cerr<second->getCond()<<":"<second->getInc()<<"\n"; - } - cerr<<"-----end insertions\n"; -#endif + DEBUG (//print edges with code for debugging + cerr<<"Code inserted in following---------------\n"; + for(map::iterator cd_i=codeInsertions.begin(), + cd_e=codeInsertions.end(); cd_i!=cd_e; ++cd_i){ + printEdge(cd_i->first); + cerr<second->getCond()<<":"<second->getInc()<<"\n"; + } + cerr<<"-----end insertions\n"); + //step 7: move code on dummy edges over to the back edges //Move the incoming dummy edge code and outgoing dummy //edge code over to the corresponding back edge moveDummyCode(stDummy, exDummy, be, codeInsertions); -#ifdef DEBUG_PATH_PROFILES - //debugging info - cerr<<"After moving dummy code\n"; - for(map::iterator cd_i=codeInsertions.begin(), - cd_e=codeInsertions.end(); cd_i != cd_e; ++cd_i){ - printEdge(cd_i->first); - cerr<second->getCond()<<":" - <second->getInc()<<"\n"; - } - cerr<<"Dummy end------------\n"; -#endif + DEBUG(//debugging info + cerr<<"After moving dummy code\n"; + for(map::iterator cd_i=codeInsertions.begin(), + cd_e=codeInsertions.end(); cd_i != cd_e; ++cd_i){ + printEdge(cd_i->first); + cerr<second->getCond()<<":" + <second->getInc()<<"\n"; + } + cerr<<"Dummy end------------\n"); //see what it looks like... //now insert code along edges which have codes on them diff --git a/llvm/lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp b/llvm/lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp index d4a20867c939..dcab1368000e 100644 --- a/llvm/lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp +++ b/llvm/lib/Transforms/Instrumentation/ProfilePaths/ProfilePaths.cpp @@ -102,9 +102,7 @@ bool ProfilePaths::runOnFunction(Function *M){ Graph g(nodes,edges, startNode, exitNode); -#ifdef DEBUG_PATH_PROFILES - printGraph(g); -#endif + DEBUG(printGraph(g)); BasicBlock *fr=M->front(); @@ -114,9 +112,8 @@ bool ProfilePaths::runOnFunction(Function *M){ // by removing back edges for now, and adding them later on vector be; g.getBackEdges(be); -#ifdef DEBUG_PATH_PROFILES - cerr<<"Backedges:"<b is a back edge