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