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