Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 1 | //===-- GrapAuxillary.cpp- Auxillary functions on graph ----------*- C++ -*--=// |
| 2 | // |
| 3 | //auxillary function associated with graph: they |
| 4 | //all operate on graph, and help in inserting |
| 5 | //instrumentation for trace generation |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 9 | #include "llvm/Transforms/Utils/UnifyFunctionExitNodes.h" |
| 10 | #include "llvm/Function.h" |
| 11 | #include "llvm/Pass.h" |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 12 | #include "llvm/BasicBlock.h" |
Anand Shukla | 2d3d20b | 2002-07-08 19:37:06 +0000 | [diff] [blame] | 13 | #include "llvm/InstrTypes.h" |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 14 | #include "llvm/Transforms/Instrumentation/Graph.h" |
Anand Shukla | fd61c60 | 2002-07-18 20:56:47 +0000 | [diff] [blame] | 15 | #include "llvm/iTerminators.h" |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 16 | #include <algorithm> |
Chris Lattner | 5328c6f | 2002-02-26 19:40:28 +0000 | [diff] [blame] | 17 | #include <iostream> |
Anand Shukla | 2d3d20b | 2002-07-08 19:37:06 +0000 | [diff] [blame] | 18 | #include <sstream> |
| 19 | #include <string> |
Chris Lattner | 5328c6f | 2002-02-26 19:40:28 +0000 | [diff] [blame] | 20 | |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 21 | //using std::list; |
Chris Lattner | 5328c6f | 2002-02-26 19:40:28 +0000 | [diff] [blame] | 22 | using std::map; |
| 23 | using std::vector; |
| 24 | using std::cerr; |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 25 | |
| 26 | //check if 2 edges are equal (same endpoints and same weight) |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 27 | static bool edgesEqual(Edge ed1, Edge ed2){ |
| 28 | return ((ed1==ed2) && ed1.getWeight()==ed2.getWeight()); |
| 29 | } |
| 30 | |
| 31 | //Get the vector of edges that are to be instrumented in the graph |
Chris Lattner | 570b8e1 | 2002-02-26 19:49:45 +0000 | [diff] [blame] | 32 | static void getChords(vector<Edge > &chords, Graph &g, Graph st){ |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 33 | //make sure the spanning tree is directional |
| 34 | //iterate over ALL the edges of the graph |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 35 | vector<Node *> allNodes=g.getAllNodes(); |
| 36 | for(vector<Node *>::iterator NI=allNodes.begin(), NE=allNodes.end(); NI!=NE; |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 37 | ++NI){ |
| 38 | Graph::nodeList node_list=g.getNodeList(*NI); |
| 39 | for(Graph::nodeList::iterator NLI=node_list.begin(), NLE=node_list.end(); |
| 40 | NLI!=NLE; ++NLI){ |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 41 | Edge f(*NI, NLI->element,NLI->weight, NLI->randId); |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 42 | if(!(st.hasEdgeAndWt(f)))//addnl |
| 43 | chords.push_back(f); |
| 44 | } |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | //Given a tree t, and a "directed graph" g |
| 49 | //replace the edges in the tree t with edges that exist in graph |
| 50 | //The tree is formed from "undirectional" copy of graph |
| 51 | //So whatever edges the tree has, the undirectional graph |
| 52 | //would have too. This function corrects some of the directions in |
| 53 | //the tree so that now, all edge directions in the tree match |
| 54 | //the edge directions of corresponding edges in the directed graph |
Chris Lattner | 570b8e1 | 2002-02-26 19:49:45 +0000 | [diff] [blame] | 55 | static void removeTreeEdges(Graph &g, Graph& t){ |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 56 | vector<Node* > allNodes=t.getAllNodes(); |
| 57 | for(vector<Node *>::iterator NI=allNodes.begin(), NE=allNodes.end(); NI!=NE; |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 58 | ++NI){ |
| 59 | Graph::nodeList nl=t.getNodeList(*NI); |
| 60 | for(Graph::nodeList::iterator NLI=nl.begin(), NLE=nl.end(); NLI!=NLE;++NLI){ |
| 61 | Edge ed(NLI->element, *NI, NLI->weight); |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 62 | if(!g.hasEdgeAndWt(ed)) t.removeEdge(ed);//tree has only one edge |
| 63 | //between any pair of vertices, so no need to delete by edge wt |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | //Assign a value to all the edges in the graph |
| 69 | //such that if we traverse along any path from root to exit, and |
| 70 | //add up the edge values, we get a path number that uniquely |
| 71 | //refers to the path we travelled |
Anand Shukla | fd61c60 | 2002-07-18 20:56:47 +0000 | [diff] [blame] | 72 | int valueAssignmentToEdges(Graph& g, map<Node *, int> nodePriority){ |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 73 | vector<Node *> revtop=g.reverseTopologicalSort(); |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 74 | map<Node *,int > NumPaths; |
Anand Shukla | 2d3d20b | 2002-07-08 19:37:06 +0000 | [diff] [blame] | 75 | for(vector<Node *>::iterator RI=revtop.begin(), RE=revtop.end(); |
| 76 | RI!=RE; ++RI){ |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 77 | if(g.isLeaf(*RI)) |
| 78 | NumPaths[*RI]=1; |
| 79 | else{ |
| 80 | NumPaths[*RI]=0; |
Anand Shukla | 2d3d20b | 2002-07-08 19:37:06 +0000 | [diff] [blame] | 81 | |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 82 | Graph::nodeList &nlist=g.getNodeList(*RI); |
| 83 | //sort nodelist by increasing order of numpaths |
| 84 | |
| 85 | int sz=nlist.size(); |
Anand Shukla | 2d3d20b | 2002-07-08 19:37:06 +0000 | [diff] [blame] | 86 | |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 87 | for(int i=0;i<sz-1; i++){ |
| 88 | int min=i; |
Anand Shukla | 2d3d20b | 2002-07-08 19:37:06 +0000 | [diff] [blame] | 89 | for(int j=i+1; j<sz; j++){ |
| 90 | BasicBlock *bb1 = nlist[j].element->getElement(); |
| 91 | BasicBlock *bb2 = nlist[min].element->getElement(); |
Anand Shukla | fd61c60 | 2002-07-18 20:56:47 +0000 | [diff] [blame] | 92 | |
| 93 | if(bb1 == bb2) continue; |
| 94 | |
| 95 | if(*RI == g.getRoot()){ |
| 96 | assert(nodePriority[nlist[min].element]!= |
| 97 | nodePriority[nlist[j].element] |
| 98 | && "priorities can't be same!"); |
| 99 | |
| 100 | if(nodePriority[nlist[j].element] < |
| 101 | nodePriority[nlist[min].element]) |
| 102 | min = j; |
| 103 | } |
Anand Shukla | 2d3d20b | 2002-07-08 19:37:06 +0000 | [diff] [blame] | 104 | |
Anand Shukla | fd61c60 | 2002-07-18 20:56:47 +0000 | [diff] [blame] | 105 | else{ |
| 106 | TerminatorInst *tti = (*RI)->getElement()->getTerminator(); |
| 107 | //std::cerr<<*tti<<std::endl; |
| 108 | BranchInst *ti = cast<BranchInst>(tti); |
| 109 | assert(ti && "not a branch"); |
| 110 | assert(ti->getNumSuccessors()==2 && "less successors!"); |
| 111 | |
| 112 | BasicBlock *tB = ti->getSuccessor(0); |
| 113 | BasicBlock *fB = ti->getSuccessor(1); |
| 114 | |
| 115 | if(tB == bb1 || fB == bb2) |
Anand Shukla | 2d3d20b | 2002-07-08 19:37:06 +0000 | [diff] [blame] | 116 | min = j; |
Anand Shukla | 2d3d20b | 2002-07-08 19:37:06 +0000 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | } |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 120 | graphListElement tempEl=nlist[min]; |
| 121 | nlist[min]=nlist[i]; |
| 122 | nlist[i]=tempEl; |
| 123 | } |
Anand Shukla | 2d3d20b | 2002-07-08 19:37:06 +0000 | [diff] [blame] | 124 | |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 125 | //sorted now! |
Anand Shukla | fd61c60 | 2002-07-18 20:56:47 +0000 | [diff] [blame] | 126 | //std::cerr<<"Considering Order-----\n"; |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 127 | for(Graph::nodeList::iterator GLI=nlist.begin(), GLE=nlist.end(); |
| 128 | GLI!=GLE; ++GLI){ |
Anand Shukla | fd61c60 | 2002-07-18 20:56:47 +0000 | [diff] [blame] | 129 | //std::cerr<<GLI->element->getElement()->getName()<<"->"; |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 130 | GLI->weight=NumPaths[*RI]; |
| 131 | NumPaths[*RI]+=NumPaths[GLI->element]; |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 132 | } |
Anand Shukla | fd61c60 | 2002-07-18 20:56:47 +0000 | [diff] [blame] | 133 | //std::cerr<<"\nend order $$$$$$$$$$$$$$$$$$$$$$$$\n"; |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 134 | } |
| 135 | } |
| 136 | return NumPaths[g.getRoot()]; |
| 137 | } |
| 138 | |
| 139 | //This is a helper function to get the edge increments |
| 140 | //This is used in conjuntion with inc_DFS |
| 141 | //to get the edge increments |
| 142 | //Edge increment implies assigning a value to all the edges in the graph |
| 143 | //such that if we traverse along any path from root to exit, and |
| 144 | //add up the edge values, we get a path number that uniquely |
| 145 | //refers to the path we travelled |
| 146 | //inc_Dir tells whether 2 edges are in same, or in different directions |
| 147 | //if same direction, return 1, else -1 |
Chris Lattner | 570b8e1 | 2002-02-26 19:49:45 +0000 | [diff] [blame] | 148 | static int inc_Dir(Edge e, Edge f){ |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 149 | if(e.isNull()) |
| 150 | return 1; |
| 151 | |
| 152 | //check that the edges must have atleast one common endpoint |
| 153 | assert(*(e.getFirst())==*(f.getFirst()) || |
| 154 | *(e.getFirst())==*(f.getSecond()) || |
| 155 | *(e.getSecond())==*(f.getFirst()) || |
| 156 | *(e.getSecond())==*(f.getSecond())); |
| 157 | |
| 158 | if(*(e.getFirst())==*(f.getSecond()) || |
| 159 | *(e.getSecond())==*(f.getFirst())) |
| 160 | return 1; |
| 161 | |
| 162 | return -1; |
| 163 | } |
| 164 | |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 165 | |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 166 | //used for getting edge increments (read comments above in inc_Dir) |
| 167 | //inc_DFS is a modification of DFS |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 168 | static void inc_DFS(Graph& g,Graph& t,map<Edge, int, EdgeCompare>& Increment, |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 169 | int events, Node *v, Edge e){ |
| 170 | |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 171 | vector<Node *> allNodes=t.getAllNodes(); |
| 172 | |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 173 | for(vector<Node *>::iterator NI=allNodes.begin(), NE=allNodes.end(); NI!=NE; |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 174 | ++NI){ |
| 175 | Graph::nodeList node_list=t.getNodeList(*NI); |
| 176 | for(Graph::nodeList::iterator NLI=node_list.begin(), NLE=node_list.end(); |
| 177 | NLI!= NLE; ++NLI){ |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 178 | Edge f(*NI, NLI->element,NLI->weight, NLI->randId); |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 179 | if(!edgesEqual(f,e) && *v==*(f.getSecond())){ |
| 180 | int dir_count=inc_Dir(e,f); |
| 181 | int wt=1*f.getWeight(); |
| 182 | inc_DFS(g,t, Increment, dir_count*events+wt, f.getFirst(), f); |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 187 | for(vector<Node *>::iterator NI=allNodes.begin(), NE=allNodes.end(); NI!=NE; |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 188 | ++NI){ |
| 189 | Graph::nodeList node_list=t.getNodeList(*NI); |
| 190 | for(Graph::nodeList::iterator NLI=node_list.begin(), NLE=node_list.end(); |
| 191 | NLI!=NLE; ++NLI){ |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 192 | Edge f(*NI, NLI->element,NLI->weight, NLI->randId); |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 193 | if(!edgesEqual(f,e) && *v==*(f.getFirst())){ |
| 194 | int dir_count=inc_Dir(e,f); |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 195 | int wt=f.getWeight(); |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 196 | inc_DFS(g,t, Increment, dir_count*events+wt, |
| 197 | f.getSecond(), f); |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | |
| 202 | allNodes=g.getAllNodes(); |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 203 | for(vector<Node *>::iterator NI=allNodes.begin(), NE=allNodes.end(); NI!=NE; |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 204 | ++NI){ |
| 205 | Graph::nodeList node_list=g.getNodeList(*NI); |
| 206 | for(Graph::nodeList::iterator NLI=node_list.begin(), NLE=node_list.end(); |
| 207 | NLI!=NLE; ++NLI){ |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 208 | Edge f(*NI, NLI->element,NLI->weight, NLI->randId); |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 209 | if(!(t.hasEdgeAndWt(f)) && (*v==*(f.getSecond()) || |
| 210 | *v==*(f.getFirst()))){ |
| 211 | int dir_count=inc_Dir(e,f); |
| 212 | Increment[f]+=dir_count*events; |
| 213 | } |
| 214 | } |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | //Now we select a subset of all edges |
| 219 | //and assign them some values such that |
| 220 | //if we consider just this subset, it still represents |
| 221 | //the path sum along any path in the graph |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 222 | static map<Edge, int, EdgeCompare> getEdgeIncrements(Graph& g, Graph& t){ |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 223 | //get all edges in g-t |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 224 | map<Edge, int, EdgeCompare> Increment; |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 225 | |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 226 | vector<Node *> allNodes=g.getAllNodes(); |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 227 | |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 228 | for(vector<Node *>::iterator NI=allNodes.begin(), NE=allNodes.end(); NI!=NE; |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 229 | ++NI){ |
| 230 | Graph::nodeList node_list=g.getNodeList(*NI); |
| 231 | for(Graph::nodeList::iterator NLI=node_list.begin(), NLE=node_list.end(); |
| 232 | NLI!=NLE; ++NLI){ |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 233 | Edge ed(*NI, NLI->element,NLI->weight,NLI->randId); |
| 234 | if(!(t.hasEdgeAndWt(ed))){ |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 235 | Increment[ed]=0;; |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | Edge *ed=new Edge(); |
| 241 | inc_DFS(g,t,Increment, 0, g.getRoot(), *ed); |
| 242 | |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 243 | for(vector<Node *>::iterator NI=allNodes.begin(), NE=allNodes.end(); NI!=NE; |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 244 | ++NI){ |
| 245 | Graph::nodeList node_list=g.getNodeList(*NI); |
| 246 | for(Graph::nodeList::iterator NLI=node_list.begin(), NLE=node_list.end(); |
| 247 | NLI!=NLE; ++NLI){ |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 248 | Edge ed(*NI, NLI->element,NLI->weight, NLI->randId); |
| 249 | if(!(t.hasEdgeAndWt(ed))){ |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 250 | int wt=ed.getWeight(); |
| 251 | Increment[ed]+=wt; |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | return Increment; |
| 257 | } |
| 258 | |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 259 | //push it up: TODO |
| 260 | const graphListElement *findNodeInList(const Graph::nodeList &NL, |
| 261 | Node *N); |
| 262 | |
| 263 | graphListElement *findNodeInList(Graph::nodeList &NL, Node *N); |
| 264 | //end TODO |
| 265 | |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 266 | //Based on edgeIncrements (above), now obtain |
| 267 | //the kind of code to be inserted along an edge |
| 268 | //The idea here is to minimize the computation |
| 269 | //by inserting only the needed code |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 270 | static void getCodeInsertions(Graph &g, map<Edge, getEdgeCode *, EdgeCompare> &instr, |
Chris Lattner | 5328c6f | 2002-02-26 19:40:28 +0000 | [diff] [blame] | 271 | vector<Edge > &chords, |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 272 | map<Edge,int, EdgeCompare> &edIncrements){ |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 273 | |
| 274 | //Register initialization code |
| 275 | vector<Node *> ws; |
| 276 | ws.push_back(g.getRoot()); |
| 277 | while(ws.size()>0){ |
Chris Lattner | 5328c6f | 2002-02-26 19:40:28 +0000 | [diff] [blame] | 278 | Node *v=ws.back(); |
| 279 | ws.pop_back(); |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 280 | //for each edge v->w |
| 281 | Graph::nodeList succs=g.getNodeList(v); |
| 282 | |
| 283 | for(Graph::nodeList::iterator nl=succs.begin(), ne=succs.end(); |
| 284 | nl!=ne; ++nl){ |
| 285 | int edgeWt=nl->weight; |
| 286 | Node *w=nl->element; |
| 287 | //if chords has v->w |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 288 | Edge ed(v,w, edgeWt, nl->randId); |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 289 | bool hasEdge=false; |
| 290 | for(vector<Edge>::iterator CI=chords.begin(), CE=chords.end(); |
| 291 | CI!=CE && !hasEdge;++CI){ |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 292 | if(*CI==ed && CI->getWeight()==edgeWt){//modf |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 293 | hasEdge=true; |
| 294 | } |
| 295 | } |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 296 | |
| 297 | if(hasEdge){//so its a chord edge |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 298 | getEdgeCode *edCd=new getEdgeCode(); |
| 299 | edCd->setCond(1); |
| 300 | edCd->setInc(edIncrements[ed]); |
Chris Lattner | 5328c6f | 2002-02-26 19:40:28 +0000 | [diff] [blame] | 301 | instr[ed]=edCd; |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 302 | } |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 303 | else if(g.getNumberOfIncomingEdges(w)==1){ |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 304 | ws.push_back(w); |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 305 | //std::cerr<<"Added w\n"; |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 306 | } |
| 307 | else{ |
| 308 | getEdgeCode *edCd=new getEdgeCode(); |
| 309 | edCd->setCond(2); |
| 310 | edCd->setInc(0); |
Chris Lattner | 5328c6f | 2002-02-26 19:40:28 +0000 | [diff] [blame] | 311 | instr[ed]=edCd; |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 312 | //std::cerr<<"Case 2\n"; |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 313 | } |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | /////Memory increment code |
| 318 | ws.push_back(g.getExit()); |
| 319 | |
Chris Lattner | 5328c6f | 2002-02-26 19:40:28 +0000 | [diff] [blame] | 320 | while(!ws.empty()) { |
| 321 | Node *w=ws.back(); |
| 322 | ws.pop_back(); |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 323 | |
| 324 | |
| 325 | /////// |
| 326 | //vector<Node *> lt; |
| 327 | vector<Node *> lllt=g.getAllNodes(); |
| 328 | for(vector<Node *>::iterator EII=lllt.begin(); EII!=lllt.end() ;++EII){ |
| 329 | Node *lnode=*EII; |
| 330 | Graph::nodeList &nl = g.getNodeList(lnode); |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 331 | graphListElement *N = findNodeInList(nl, w); |
Anand Shukla | 2d3d20b | 2002-07-08 19:37:06 +0000 | [diff] [blame] | 332 | if (N){ |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 333 | Node *v=lnode; |
Anand Shukla | 2d3d20b | 2002-07-08 19:37:06 +0000 | [diff] [blame] | 334 | |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 335 | //if chords has v->w |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 336 | Edge ed(v,w, N->weight, N->randId); |
| 337 | getEdgeCode *edCd=new getEdgeCode(); |
| 338 | bool hasEdge=false; |
| 339 | for(vector<Edge>::iterator CI=chords.begin(), CE=chords.end(); CI!=CE; |
| 340 | ++CI){ |
| 341 | if(*CI==ed && CI->getWeight()==N->weight){ |
| 342 | hasEdge=true; |
| 343 | break; |
| 344 | } |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 345 | } |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 346 | if(hasEdge){ |
| 347 | char str[100]; |
| 348 | if(instr[ed]!=NULL && instr[ed]->getCond()==1){ |
| 349 | instr[ed]->setCond(4); |
| 350 | } |
| 351 | else{ |
| 352 | edCd->setCond(5); |
| 353 | edCd->setInc(edIncrements[ed]); |
| 354 | instr[ed]=edCd; |
| 355 | } |
| 356 | |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 357 | } |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 358 | else if(g.getNumberOfOutgoingEdges(v)==1) |
| 359 | ws.push_back(v); |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 360 | else{ |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 361 | edCd->setCond(6); |
Chris Lattner | 5328c6f | 2002-02-26 19:40:28 +0000 | [diff] [blame] | 362 | instr[ed]=edCd; |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 363 | } |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 364 | } |
| 365 | } |
| 366 | } |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 367 | ///// Register increment code |
| 368 | for(vector<Edge>::iterator CI=chords.begin(), CE=chords.end(); CI!=CE; ++CI){ |
| 369 | getEdgeCode *edCd=new getEdgeCode(); |
Chris Lattner | 5328c6f | 2002-02-26 19:40:28 +0000 | [diff] [blame] | 370 | if(instr[*CI]==NULL){ |
| 371 | edCd->setCond(3); |
| 372 | edCd->setInc(edIncrements[*CI]); |
| 373 | instr[*CI]=edCd; |
| 374 | } |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 375 | } |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | //Add dummy edges corresponding to the back edges |
| 379 | //If a->b is a backedge |
| 380 | //then incoming dummy edge is root->b |
| 381 | //and outgoing dummy edge is a->exit |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 382 | //changed |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 383 | void addDummyEdges(vector<Edge > &stDummy, |
| 384 | vector<Edge > &exDummy, |
Chris Lattner | 5328c6f | 2002-02-26 19:40:28 +0000 | [diff] [blame] | 385 | Graph &g, vector<Edge> &be){ |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 386 | for(vector<Edge >::iterator VI=be.begin(), VE=be.end(); VI!=VE; ++VI){ |
| 387 | Edge ed=*VI; |
| 388 | Node *first=ed.getFirst(); |
| 389 | Node *second=ed.getSecond(); |
| 390 | g.removeEdge(ed); |
| 391 | |
| 392 | if(!(*second==*(g.getRoot()))){ |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 393 | Edge *st=new Edge(g.getRoot(), second, ed.getWeight(), ed.getRandId()); |
| 394 | stDummy.push_back(*st); |
Chris Lattner | 5328c6f | 2002-02-26 19:40:28 +0000 | [diff] [blame] | 395 | g.addEdgeForce(*st); |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | if(!(*first==*(g.getExit()))){ |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 399 | Edge *ex=new Edge(first, g.getExit(), ed.getWeight(), ed.getRandId()); |
| 400 | exDummy.push_back(*ex); |
| 401 | g.addEdgeForce(*ex); |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 402 | } |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | //print a given edge in the form BB1Label->BB2Label |
| 407 | void printEdge(Edge ed){ |
| 408 | cerr<<((ed.getFirst())->getElement()) |
| 409 | ->getName()<<"->"<<((ed.getSecond()) |
| 410 | ->getElement())->getName()<< |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 411 | ":"<<ed.getWeight()<<" rndId::"<<ed.getRandId()<<"\n"; |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | //Move the incoming dummy edge code and outgoing dummy |
| 415 | //edge code over to the corresponding back edge |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 416 | static void moveDummyCode(vector<Edge> &stDummy, |
| 417 | vector<Edge> &exDummy, |
| 418 | vector<Edge> &be, |
| 419 | map<Edge, getEdgeCode *, EdgeCompare> &insertions, |
| 420 | Graph &g){ |
| 421 | typedef vector<Edge >::iterator vec_iter; |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 422 | |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 423 | map<Edge,getEdgeCode *, EdgeCompare> temp; |
| 424 | //iterate over edges with code |
Chris Lattner | 5328c6f | 2002-02-26 19:40:28 +0000 | [diff] [blame] | 425 | std::vector<Edge> toErase; |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 426 | for(map<Edge,getEdgeCode *, EdgeCompare>::iterator MI=insertions.begin(), |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 427 | ME=insertions.end(); MI!=ME; ++MI){ |
| 428 | Edge ed=MI->first; |
| 429 | getEdgeCode *edCd=MI->second; |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 430 | |
| 431 | ///---new code |
| 432 | //iterate over be, and check if its starts and end vertices hv code |
| 433 | for(vector<Edge>::iterator BEI=be.begin(), BEE=be.end(); BEI!=BEE; ++BEI){ |
| 434 | if(ed.getRandId()==BEI->getRandId()){ |
| 435 | |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 436 | if(temp[*BEI]==0) |
| 437 | temp[*BEI]=new getEdgeCode(); |
| 438 | |
| 439 | //so ed is either in st, or ex! |
| 440 | if(ed.getFirst()==g.getRoot()){ |
Anand Shukla | 2d3d20b | 2002-07-08 19:37:06 +0000 | [diff] [blame] | 441 | |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 442 | //so its in stDummy |
| 443 | temp[*BEI]->setCdIn(edCd); |
| 444 | toErase.push_back(ed); |
| 445 | } |
| 446 | else if(ed.getSecond()==g.getExit()){ |
Anand Shukla | 2d3d20b | 2002-07-08 19:37:06 +0000 | [diff] [blame] | 447 | |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 448 | //so its in exDummy |
| 449 | toErase.push_back(ed); |
| 450 | temp[*BEI]->setCdOut(edCd); |
| 451 | } |
| 452 | else{ |
| 453 | assert(false && "Not found in either start or end! Rand failed?"); |
| 454 | } |
| 455 | } |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | for(vector<Edge >::iterator vmi=toErase.begin(), vme=toErase.end(); vmi!=vme; |
| 460 | ++vmi){ |
| 461 | insertions.erase(*vmi); |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 462 | g.removeEdgeWithWt(*vmi); |
| 463 | } |
| 464 | |
| 465 | for(map<Edge,getEdgeCode *, EdgeCompare>::iterator MI=temp.begin(), |
| 466 | ME=temp.end(); MI!=ME; ++MI){ |
| 467 | insertions[MI->first]=MI->second; |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 468 | } |
Anand Shukla | 2d3d20b | 2002-07-08 19:37:06 +0000 | [diff] [blame] | 469 | |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 470 | #ifdef DEBUG_PATH_PROFILES |
| 471 | cerr<<"size of deletions: "<<toErase.size()<<"\n"; |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 472 | cerr<<"SIZE OF INSERTIONS AFTER DEL "<<insertions.size()<<"\n"; |
| 473 | #endif |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 474 | |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 475 | } |
| 476 | |
Chris Lattner | 18ff945 | 2002-02-26 19:43:49 +0000 | [diff] [blame] | 477 | //Do graph processing: to determine minimal edge increments, |
| 478 | //appropriate code insertions etc and insert the code at |
| 479 | //appropriate locations |
| 480 | void processGraph(Graph &g, |
| 481 | Instruction *rInst, |
| 482 | Instruction *countInst, |
| 483 | vector<Edge >& be, |
| 484 | vector<Edge >& stDummy, |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 485 | vector<Edge >& exDummy, |
Anand Shukla | fd61c60 | 2002-07-18 20:56:47 +0000 | [diff] [blame] | 486 | int numPaths, int MethNo){ |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 487 | |
Chris Lattner | 18ff945 | 2002-02-26 19:43:49 +0000 | [diff] [blame] | 488 | //Given a graph: with exit->root edge, do the following in seq: |
| 489 | //1. get back edges |
| 490 | //2. insert dummy edges and remove back edges |
| 491 | //3. get edge assignments |
| 492 | //4. Get Max spanning tree of graph: |
| 493 | // -Make graph g2=g undirectional |
| 494 | // -Get Max spanning tree t |
| 495 | // -Make t undirectional |
| 496 | // -remove edges from t not in graph g |
| 497 | //5. Get edge increments |
| 498 | //6. Get code insertions |
| 499 | //7. move code on dummy edges over to the back edges |
| 500 | |
| 501 | |
| 502 | //This is used as maximum "weight" for |
| 503 | //priority queue |
| 504 | //This would hold all |
| 505 | //right as long as number of paths in the graph |
| 506 | //is less than this |
| 507 | const int INFINITY=99999999; |
| 508 | |
| 509 | |
| 510 | //step 1-3 are already done on the graph when this function is called |
Chris Lattner | e1fc2d9 | 2002-05-22 21:56:32 +0000 | [diff] [blame] | 511 | DEBUG(printGraph(g)); |
| 512 | |
Chris Lattner | 18ff945 | 2002-02-26 19:43:49 +0000 | [diff] [blame] | 513 | //step 4: Get Max spanning tree of graph |
| 514 | |
| 515 | //now insert exit to root edge |
| 516 | //if its there earlier, remove it! |
| 517 | //assign it weight INFINITY |
| 518 | //so that this edge IS ALWAYS IN spanning tree |
| 519 | //Note than edges in spanning tree do not get |
| 520 | //instrumented: and we do not want the |
| 521 | //edge exit->root to get instrumented |
| 522 | //as it MAY BE a dummy edge |
| 523 | Edge ed(g.getExit(),g.getRoot(),INFINITY); |
| 524 | g.addEdge(ed,INFINITY); |
| 525 | Graph g2=g; |
| 526 | |
| 527 | //make g2 undirectional: this gives a better |
| 528 | //maximal spanning tree |
| 529 | g2.makeUnDirectional(); |
Chris Lattner | e1fc2d9 | 2002-05-22 21:56:32 +0000 | [diff] [blame] | 530 | DEBUG(printGraph(g2)); |
| 531 | |
Chris Lattner | 18ff945 | 2002-02-26 19:43:49 +0000 | [diff] [blame] | 532 | Graph *t=g2.getMaxSpanningTree(); |
Anand Shukla | 2d3d20b | 2002-07-08 19:37:06 +0000 | [diff] [blame] | 533 | #ifdef DEBUG_PATH_PROFILES |
| 534 | std::cerr<<"Original maxspanning tree\n"; |
| 535 | printGraph(*t); |
| 536 | #endif |
Chris Lattner | 18ff945 | 2002-02-26 19:43:49 +0000 | [diff] [blame] | 537 | //now edges of tree t have weights reversed |
| 538 | //(negative) because the algorithm used |
| 539 | //to find max spanning tree is |
| 540 | //actually for finding min spanning tree |
| 541 | //so get back the original weights |
| 542 | t->reverseWts(); |
| 543 | |
| 544 | //Ordinarily, the graph is directional |
| 545 | //lets converts the graph into an |
| 546 | //undirectional graph |
| 547 | //This is done by adding an edge |
| 548 | //v->u for all existing edges u->v |
| 549 | t->makeUnDirectional(); |
| 550 | |
| 551 | //Given a tree t, and a "directed graph" g |
| 552 | //replace the edges in the tree t with edges that exist in graph |
| 553 | //The tree is formed from "undirectional" copy of graph |
| 554 | //So whatever edges the tree has, the undirectional graph |
| 555 | //would have too. This function corrects some of the directions in |
| 556 | //the tree so that now, all edge directions in the tree match |
| 557 | //the edge directions of corresponding edges in the directed graph |
| 558 | removeTreeEdges(g, *t); |
Chris Lattner | e1fc2d9 | 2002-05-22 21:56:32 +0000 | [diff] [blame] | 559 | |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 560 | #ifdef DEBUG_PATH_PROFILES |
| 561 | cerr<<"Final Spanning tree---------\n"; |
| 562 | printGraph(*t); |
| 563 | cerr<<"-------end spanning tree\n"; |
| 564 | #endif |
Chris Lattner | e1fc2d9 | 2002-05-22 21:56:32 +0000 | [diff] [blame] | 565 | |
Chris Lattner | 18ff945 | 2002-02-26 19:43:49 +0000 | [diff] [blame] | 566 | //now remove the exit->root node |
| 567 | //and re-add it with weight 0 |
| 568 | //since infinite weight is kinda confusing |
| 569 | g.removeEdge(ed); |
| 570 | Edge edNew(g.getExit(), g.getRoot(),0); |
| 571 | g.addEdge(edNew,0); |
| 572 | if(t->hasEdge(ed)){ |
| 573 | t->removeEdge(ed); |
| 574 | t->addEdge(edNew,0); |
| 575 | } |
| 576 | |
Chris Lattner | e1fc2d9 | 2002-05-22 21:56:32 +0000 | [diff] [blame] | 577 | DEBUG(printGraph(g); |
| 578 | printGraph(*t)); |
| 579 | |
Chris Lattner | 18ff945 | 2002-02-26 19:43:49 +0000 | [diff] [blame] | 580 | //step 5: Get edge increments |
| 581 | |
| 582 | //Now we select a subset of all edges |
| 583 | //and assign them some values such that |
| 584 | //if we consider just this subset, it still represents |
| 585 | //the path sum along any path in the graph |
Chris Lattner | e1fc2d9 | 2002-05-22 21:56:32 +0000 | [diff] [blame] | 586 | |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 587 | map<Edge, int, EdgeCompare> increment=getEdgeIncrements(g,*t); |
| 588 | #ifdef DEBUG_PATH_PROFILES |
| 589 | //print edge increments for debugging |
| 590 | |
| 591 | for(map<Edge, int, EdgeCompare>::iterator M_I=increment.begin(), M_E=increment.end(); |
| 592 | M_I!=M_E; ++M_I){ |
| 593 | printEdge(M_I->first); |
| 594 | cerr<<"Increment for above:"<<M_I->second<<"\n"; |
| 595 | } |
| 596 | #endif |
| 597 | |
Chris Lattner | 18ff945 | 2002-02-26 19:43:49 +0000 | [diff] [blame] | 598 | |
| 599 | //step 6: Get code insertions |
| 600 | |
| 601 | //Based on edgeIncrements (above), now obtain |
| 602 | //the kind of code to be inserted along an edge |
| 603 | //The idea here is to minimize the computation |
| 604 | //by inserting only the needed code |
| 605 | vector<Edge> chords; |
| 606 | getChords(chords, g, *t); |
| 607 | |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 608 | |
| 609 | //cerr<<"Graph before getCodeInsertion:\n"; |
| 610 | //printGraph(g); |
| 611 | map<Edge, getEdgeCode *, EdgeCompare> codeInsertions; |
Chris Lattner | 18ff945 | 2002-02-26 19:43:49 +0000 | [diff] [blame] | 612 | getCodeInsertions(g, codeInsertions, chords,increment); |
| 613 | |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 614 | #ifdef DEBUG_PATH_PROFILES |
| 615 | //print edges with code for debugging |
| 616 | cerr<<"Code inserted in following---------------\n"; |
| 617 | for(map<Edge, getEdgeCode *>::iterator cd_i=codeInsertions.begin(), |
| 618 | cd_e=codeInsertions.end(); cd_i!=cd_e; ++cd_i){ |
| 619 | printEdge(cd_i->first); |
| 620 | cerr<<cd_i->second->getCond()<<":"<<cd_i->second->getInc()<<"\n"; |
| 621 | } |
| 622 | cerr<<"-----end insertions\n"; |
| 623 | #endif |
Chris Lattner | e1fc2d9 | 2002-05-22 21:56:32 +0000 | [diff] [blame] | 624 | |
Chris Lattner | 18ff945 | 2002-02-26 19:43:49 +0000 | [diff] [blame] | 625 | //step 7: move code on dummy edges over to the back edges |
| 626 | |
| 627 | //Move the incoming dummy edge code and outgoing dummy |
| 628 | //edge code over to the corresponding back edge |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 629 | |
| 630 | moveDummyCode(stDummy, exDummy, be, codeInsertions, g); |
Anand Shukla | 2d3d20b | 2002-07-08 19:37:06 +0000 | [diff] [blame] | 631 | |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 632 | #ifdef DEBUG_PATH_PROFILES |
| 633 | //debugging info |
| 634 | cerr<<"After moving dummy code\n"; |
| 635 | for(map<Edge, getEdgeCode *>::iterator cd_i=codeInsertions.begin(), |
| 636 | cd_e=codeInsertions.end(); cd_i != cd_e; ++cd_i){ |
| 637 | printEdge(cd_i->first); |
| 638 | cerr<<cd_i->second->getCond()<<":" |
| 639 | <<cd_i->second->getInc()<<"\n"; |
| 640 | } |
| 641 | cerr<<"Dummy end------------\n"; |
| 642 | #endif |
| 643 | |
Chris Lattner | 18ff945 | 2002-02-26 19:43:49 +0000 | [diff] [blame] | 644 | |
| 645 | //see what it looks like... |
| 646 | //now insert code along edges which have codes on them |
| 647 | for(map<Edge, getEdgeCode *>::iterator MI=codeInsertions.begin(), |
| 648 | ME=codeInsertions.end(); MI!=ME; ++MI){ |
| 649 | Edge ed=MI->first; |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 650 | insertBB(ed, MI->second, rInst, countInst, numPaths, MethNo); |
Chris Lattner | 18ff945 | 2002-02-26 19:43:49 +0000 | [diff] [blame] | 651 | } |
| 652 | } |
| 653 | |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 654 | //print the graph (for debugging) |
Chris Lattner | 570b8e1 | 2002-02-26 19:49:45 +0000 | [diff] [blame] | 655 | void printGraph(Graph &g){ |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 656 | vector<Node *> lt=g.getAllNodes(); |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 657 | cerr<<"Graph---------------------\n"; |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 658 | for(vector<Node *>::iterator LI=lt.begin(); |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 659 | LI!=lt.end(); ++LI){ |
| 660 | cerr<<((*LI)->getElement())->getName()<<"->"; |
| 661 | Graph::nodeList nl=g.getNodeList(*LI); |
| 662 | for(Graph::nodeList::iterator NI=nl.begin(); |
| 663 | NI!=nl.end(); ++NI){ |
| 664 | cerr<<":"<<"("<<(NI->element->getElement()) |
Anand Shukla | 2190689 | 2002-06-25 21:14:58 +0000 | [diff] [blame] | 665 | ->getName()<<":"<<NI->element->getWeight()<<","<<NI->weight<<"," |
| 666 | <<NI->randId<<")"; |
Anand Shukla | 854c302 | 2002-02-26 19:02:16 +0000 | [diff] [blame] | 667 | } |
| 668 | cerr<<"\n"; |
| 669 | } |
| 670 | cerr<<"--------------------Graph\n"; |
| 671 | } |