Chris Lattner | 44d2c35 | 2003-10-13 03:32:08 +0000 | [diff] [blame] | 1 | //===- RetracePath.cpp ----------------------------------------------------===// |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 2 | // |
John Criswell | 482202a | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 7 | // |
John Criswell | 482202a | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 9 | // |
| 10 | // Retraces a path of BasicBlock, given a path number and a graph! |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 14 | #include "llvm/Module.h" |
Misha Brukman | 63b38bd | 2004-07-29 17:30:56 +0000 | [diff] [blame] | 15 | #include "llvm/Instructions.h" |
Chris Lattner | 2f04a0d | 2003-01-14 22:33:56 +0000 | [diff] [blame] | 16 | #include "llvm/Support/CFG.h" |
| 17 | #include "Graph.h" |
Reid Spencer | eb04d9b | 2004-07-04 12:19:56 +0000 | [diff] [blame] | 18 | #include <iostream> |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 19 | |
| 20 | using std::vector; |
| 21 | using std::map; |
| 22 | using std::cerr; |
| 23 | |
Brian Gaeke | 960707c | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 24 | namespace llvm { |
| 25 | |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 26 | //Routines to get the path trace! |
| 27 | |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 28 | void getPathFrmNode(Node *n, vector<BasicBlock*> &vBB, int pathNo, Graph &g, |
Jeff Cohen | 8263985 | 2005-04-23 21:38:35 +0000 | [diff] [blame] | 29 | vector<Edge> &stDummy, vector<Edge> &exDummy, |
| 30 | vector<Edge> &be, |
| 31 | double strand){ |
Anand Shukla | f8c09ee | 2003-02-14 20:41:53 +0000 | [diff] [blame] | 32 | Graph::nodeList &nlist = g.getNodeList(n); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 33 | |
Anand Shukla | f8c09ee | 2003-02-14 20:41:53 +0000 | [diff] [blame] | 34 | //printGraph(g); |
| 35 | //std::cerr<<"Path No: "<<pathNo<<"\n"; |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 36 | int maxCount=-9999999; |
| 37 | bool isStart=false; |
| 38 | |
| 39 | if(*n==*g.getRoot())//its root: so first node of path |
| 40 | isStart=true; |
| 41 | |
| 42 | double edgeRnd=0; |
| 43 | Node *nextRoot=n; |
Anand Shukla | f8c09ee | 2003-02-14 20:41:53 +0000 | [diff] [blame] | 44 | for(Graph::nodeList::iterator NLI = nlist.begin(), NLE=nlist.end(); NLI!=NLE; |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 45 | ++NLI){ |
| 46 | if(NLI->weight>maxCount && NLI->weight<=pathNo){ |
| 47 | maxCount=NLI->weight; |
| 48 | nextRoot=NLI->element; |
| 49 | edgeRnd=NLI->randId; |
| 50 | if(isStart) |
Jeff Cohen | 8263985 | 2005-04-23 21:38:35 +0000 | [diff] [blame] | 51 | strand=NLI->randId; |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 52 | } |
| 53 | } |
| 54 | |
| 55 | if(!isStart) |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 56 | assert(strand!=-1 && "strand not assigned!"); |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 57 | |
| 58 | assert(!(*nextRoot==*n && pathNo>0) && "No more BBs to go"); |
| 59 | assert(!(*nextRoot==*g.getExit() && pathNo-maxCount!=0) && "Reached exit"); |
| 60 | |
| 61 | vBB.push_back(n->getElement()); |
| 62 | |
| 63 | if(pathNo-maxCount==0 && *nextRoot==*g.getExit()){ |
| 64 | |
| 65 | //look for strnd and edgeRnd now: |
| 66 | bool has1=false, has2=false; |
| 67 | //check if exit has it |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 68 | for(vector<Edge>::iterator VI=exDummy.begin(), VE=exDummy.end(); VI!=VE; |
Jeff Cohen | 8263985 | 2005-04-23 21:38:35 +0000 | [diff] [blame] | 69 | ++VI){ |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 70 | if(VI->getRandId()==edgeRnd){ |
Jeff Cohen | 8263985 | 2005-04-23 21:38:35 +0000 | [diff] [blame] | 71 | has2=true; |
| 72 | break; |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 73 | } |
| 74 | } |
| 75 | |
| 76 | //check if start has it |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 77 | for(vector<Edge>::iterator VI=stDummy.begin(), VE=stDummy.end(); VI!=VE; |
Jeff Cohen | 8263985 | 2005-04-23 21:38:35 +0000 | [diff] [blame] | 78 | ++VI){ |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 79 | if(VI->getRandId()==strand){ |
Jeff Cohen | 8263985 | 2005-04-23 21:38:35 +0000 | [diff] [blame] | 80 | has1=true; |
| 81 | break; |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 82 | } |
| 83 | } |
| 84 | |
| 85 | if(has1){ |
| 86 | //find backedge with endpoint vBB[1] |
| 87 | for(vector<Edge>::iterator VI=be.begin(), VE=be.end(); VI!=VE; ++VI){ |
Jeff Cohen | 8263985 | 2005-04-23 21:38:35 +0000 | [diff] [blame] | 88 | assert(vBB.size()>0 && "vector too small"); |
| 89 | if( VI->getSecond()->getElement() == vBB[1] ){ |
| 90 | //vBB[0]=VI->getFirst()->getElement(); |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 91 | vBB.erase(vBB.begin()); |
Jeff Cohen | 8263985 | 2005-04-23 21:38:35 +0000 | [diff] [blame] | 92 | break; |
| 93 | } |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 94 | } |
| 95 | } |
| 96 | |
| 97 | if(has2){ |
| 98 | //find backedge with startpoint vBB[vBB.size()-1] |
| 99 | for(vector<Edge>::iterator VI=be.begin(), VE=be.end(); VI!=VE; ++VI){ |
Jeff Cohen | 8263985 | 2005-04-23 21:38:35 +0000 | [diff] [blame] | 100 | assert(vBB.size()>0 && "vector too small"); |
| 101 | if( VI->getFirst()->getElement() == vBB[vBB.size()-1] && |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 102 | VI->getSecond()->getElement() == vBB[0]){ |
Jeff Cohen | 8263985 | 2005-04-23 21:38:35 +0000 | [diff] [blame] | 103 | //vBB.push_back(VI->getSecond()->getElement()); |
| 104 | break; |
| 105 | } |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 106 | } |
| 107 | } |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 108 | else |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 109 | vBB.push_back(nextRoot->getElement()); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 110 | |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 111 | return; |
| 112 | } |
| 113 | |
| 114 | assert(pathNo-maxCount>=0); |
| 115 | |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 116 | return getPathFrmNode(nextRoot, vBB, pathNo-maxCount, g, stDummy, |
Jeff Cohen | 8263985 | 2005-04-23 21:38:35 +0000 | [diff] [blame] | 117 | exDummy, be, strand); |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | |
| 121 | static Node *findBB(std::vector<Node *> &st, BasicBlock *BB){ |
| 122 | for(std::vector<Node *>::iterator si=st.begin(); si!=st.end(); ++si){ |
| 123 | if(((*si)->getElement())==BB){ |
| 124 | return *si; |
| 125 | } |
| 126 | } |
| 127 | return NULL; |
| 128 | } |
| 129 | |
Anand Shukla | f8c09ee | 2003-02-14 20:41:53 +0000 | [diff] [blame] | 130 | void getBBtrace(vector<BasicBlock *> &vBB, int pathNo, Function *M){//, |
| 131 | // vector<Instruction *> &instToErase){ |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 132 | //step 1: create graph |
| 133 | //Transform the cfg s.t. we have just one exit node |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 134 | |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 135 | std::vector<Node *> nodes; |
| 136 | std::vector<Edge> edges; |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 137 | Node *exitNode=0, *startNode=0; |
Anand Shukla | f8c09ee | 2003-02-14 20:41:53 +0000 | [diff] [blame] | 138 | |
| 139 | //Creat cfg just once for each function! |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 140 | static std::map<Function *, Graph *> graphMap; |
Anand Shukla | f8c09ee | 2003-02-14 20:41:53 +0000 | [diff] [blame] | 141 | |
| 142 | //get backedges, exit and start edges for the graphs and store them |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 143 | static std::map<Function *, vector<Edge> > stMap, exMap, beMap; |
Anand Shukla | f8c09ee | 2003-02-14 20:41:53 +0000 | [diff] [blame] | 144 | static std::map<Function *, Value *> pathReg; //path register |
| 145 | |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 146 | |
| 147 | if(!graphMap[M]){ |
| 148 | BasicBlock *ExitNode = 0; |
| 149 | for (Function::iterator I = M->begin(), E = M->end(); I != E; ++I){ |
| 150 | if (isa<ReturnInst>(I->getTerminator())) { |
Chris Lattner | 889f620 | 2003-04-23 16:37:45 +0000 | [diff] [blame] | 151 | ExitNode = I; |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 152 | break; |
| 153 | } |
| 154 | } |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 155 | |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 156 | assert(ExitNode!=0 && "exitnode not found"); |
| 157 | |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 158 | //iterating over BBs and making graph |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 159 | //The nodes must be uniquely identified: |
| 160 | //That is, no two nodes must hav same BB* |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 161 | |
Anand Shukla | f8c09ee | 2003-02-14 20:41:53 +0000 | [diff] [blame] | 162 | //keep a map for trigger basicblocks! |
| 163 | std::map<BasicBlock *, unsigned char> triggerBBs; |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 164 | //First enter just nodes: later enter edges |
| 165 | for(Function::iterator BB = M->begin(), BE=M->end(); BB != BE; ++BB){ |
Anand Shukla | f8c09ee | 2003-02-14 20:41:53 +0000 | [diff] [blame] | 166 | bool cont = false; |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 167 | |
Anand Shukla | f8c09ee | 2003-02-14 20:41:53 +0000 | [diff] [blame] | 168 | if(BB->size()==3 || BB->size() ==2){ |
| 169 | for(BasicBlock::iterator II = BB->begin(), IE = BB->end(); |
| 170 | II != IE; ++II){ |
Chris Lattner | 889f620 | 2003-04-23 16:37:45 +0000 | [diff] [blame] | 171 | if(CallInst *callInst = dyn_cast<CallInst>(II)){ |
Anand Shukla | f8c09ee | 2003-02-14 20:41:53 +0000 | [diff] [blame] | 172 | //std::cerr<<*callInst; |
| 173 | Function *calledFunction = callInst->getCalledFunction(); |
| 174 | if(calledFunction && calledFunction->getName() == "trigger"){ |
| 175 | triggerBBs[BB] = 9; |
| 176 | cont = true; |
| 177 | //std::cerr<<"Found trigger!\n"; |
| 178 | break; |
| 179 | } |
| 180 | } |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 181 | } |
| 182 | } |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 183 | |
Anand Shukla | f8c09ee | 2003-02-14 20:41:53 +0000 | [diff] [blame] | 184 | if(cont) |
| 185 | continue; |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 186 | |
Anand Shukla | f8c09ee | 2003-02-14 20:41:53 +0000 | [diff] [blame] | 187 | // const Instruction *inst = BB->getInstList().begin(); |
| 188 | // if(isa<CallInst>(inst)){ |
| 189 | // Instruction *ii1 = BB->getInstList().begin(); |
| 190 | // CallInst *callInst = dyn_cast<CallInst>(ii1); |
| 191 | // if(callInst->getCalledFunction()->getName()=="trigger") |
| 192 | // continue; |
| 193 | // } |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 194 | |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 195 | Node *nd=new Node(BB); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 196 | nodes.push_back(nd); |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 197 | if(&*BB==ExitNode) |
| 198 | exitNode=nd; |
| 199 | if(&*BB==&M->front()) |
| 200 | startNode=nd; |
| 201 | } |
| 202 | |
| 203 | assert(exitNode!=0 && startNode!=0 && "Start or exit not found!"); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 204 | |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 205 | for (Function::iterator BB = M->begin(), BE=M->end(); BB != BE; ++BB){ |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 206 | if(triggerBBs[BB] == 9) |
Anand Shukla | f8c09ee | 2003-02-14 20:41:53 +0000 | [diff] [blame] | 207 | continue; |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 208 | |
Anand Shukla | f8c09ee | 2003-02-14 20:41:53 +0000 | [diff] [blame] | 209 | //if(BB->size()==3) |
Chris Lattner | 889f620 | 2003-04-23 16:37:45 +0000 | [diff] [blame] | 210 | //if(CallInst *callInst = dyn_cast<CallInst>(BB->getInstList().begin())) |
Anand Shukla | f8c09ee | 2003-02-14 20:41:53 +0000 | [diff] [blame] | 211 | //if(callInst->getCalledFunction()->getName() == "trigger") |
| 212 | //continue; |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 213 | |
Anand Shukla | f8c09ee | 2003-02-14 20:41:53 +0000 | [diff] [blame] | 214 | // if(BB->size()==2){ |
| 215 | // const Instruction *inst = BB->getInstList().begin(); |
| 216 | // if(isa<CallInst>(inst)){ |
| 217 | // Instruction *ii1 = BB->getInstList().begin(); |
| 218 | // CallInst *callInst = dyn_cast<CallInst>(ii1); |
| 219 | // if(callInst->getCalledFunction()->getName()=="trigger") |
| 220 | // continue; |
| 221 | // } |
| 222 | // } |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 223 | |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 224 | Node *nd=findBB(nodes, BB); |
| 225 | assert(nd && "No node for this edge!"); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 226 | |
Chris Lattner | a940095 | 2003-09-24 22:06:25 +0000 | [diff] [blame] | 227 | for(succ_iterator s=succ_begin(BB), se=succ_end(BB); s!=se; ++s){ |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 228 | |
Anand Shukla | f8c09ee | 2003-02-14 20:41:53 +0000 | [diff] [blame] | 229 | if(triggerBBs[*s] == 9){ |
| 230 | //if(!pathReg[M]){ //Get the path register for this! |
| 231 | //if(BB->size()>8) |
Chris Lattner | 889f620 | 2003-04-23 16:37:45 +0000 | [diff] [blame] | 232 | // if(LoadInst *ldInst = dyn_cast<LoadInst>(BB->getInstList().begin())) |
Anand Shukla | f8c09ee | 2003-02-14 20:41:53 +0000 | [diff] [blame] | 233 | // pathReg[M] = ldInst->getPointerOperand(); |
| 234 | //} |
| 235 | continue; |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 236 | } |
Anand Shukla | f8c09ee | 2003-02-14 20:41:53 +0000 | [diff] [blame] | 237 | //if((*s)->size()==3) |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 238 | //if(CallInst *callInst = |
Chris Lattner | 889f620 | 2003-04-23 16:37:45 +0000 | [diff] [blame] | 239 | // dyn_cast<CallInst>((*s)->getInstList().begin())) |
Anand Shukla | f8c09ee | 2003-02-14 20:41:53 +0000 | [diff] [blame] | 240 | // if(callInst->getCalledFunction()->getName() == "trigger") |
| 241 | // continue; |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 242 | |
Anand Shukla | f8c09ee | 2003-02-14 20:41:53 +0000 | [diff] [blame] | 243 | // if((*s)->size()==2){ |
| 244 | // const Instruction *inst = (*s)->getInstList().begin(); |
| 245 | // if(isa<CallInst>(inst)){ |
| 246 | // Instruction *ii1 = (*s)->getInstList().begin(); |
| 247 | // CallInst *callInst = dyn_cast<CallInst>(ii1); |
| 248 | // if(callInst->getCalledFunction()->getName()=="trigger") |
| 249 | // continue; |
| 250 | // } |
| 251 | // } |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 252 | |
Anand Shukla | f8c09ee | 2003-02-14 20:41:53 +0000 | [diff] [blame] | 253 | Node *nd2 = findBB(nodes,*s); |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 254 | assert(nd2 && "No node for this edge!"); |
| 255 | Edge ed(nd,nd2,0); |
| 256 | edges.push_back(ed); |
| 257 | } |
| 258 | } |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 259 | |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 260 | graphMap[M]= new Graph(nodes,edges, startNode, exitNode); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 261 | |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 262 | Graph *g = graphMap[M]; |
| 263 | |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 264 | if (M->size() <= 1) return; //uninstrumented |
| 265 | |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 266 | //step 2: getBackEdges |
| 267 | //vector<Edge> be; |
| 268 | std::map<Node *, int> nodePriority; |
| 269 | g->getBackEdges(beMap[M], nodePriority); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 270 | |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 271 | //step 3: add dummy edges |
| 272 | //vector<Edge> stDummy; |
| 273 | //vector<Edge> exDummy; |
| 274 | addDummyEdges(stMap[M], exMap[M], *g, beMap[M]); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 275 | |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 276 | //step 4: value assgn to edges |
| 277 | int numPaths = valueAssignmentToEdges(*g, nodePriority, beMap[M]); |
| 278 | } |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 279 | |
| 280 | |
| 281 | //step 5: now travel from root, select max(edge) < pathNo, |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 282 | //and go on until reach the exit |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 283 | getPathFrmNode(graphMap[M]->getRoot(), vBB, pathNo, *graphMap[M], |
Anand Shukla | f8c09ee | 2003-02-14 20:41:53 +0000 | [diff] [blame] | 284 | stMap[M], exMap[M], beMap[M], -1); |
Misha Brukman | b1c9317 | 2005-04-21 23:48:37 +0000 | [diff] [blame] | 285 | |
Anand Shukla | f8c09ee | 2003-02-14 20:41:53 +0000 | [diff] [blame] | 286 | |
| 287 | //post process vBB to locate instructions to be erased |
| 288 | /* |
| 289 | if(pathReg[M]){ |
| 290 | for(vector<BasicBlock *>::iterator VBI = vBB.begin(), VBE = vBB.end(); |
| 291 | VBI != VBE; ++VBI){ |
| 292 | for(BasicBlock::iterator BBI = (*VBI)->begin(), BBE = (*VBI)->end(); |
| 293 | BBI != BBE; ++BBI){ |
Chris Lattner | 889f620 | 2003-04-23 16:37:45 +0000 | [diff] [blame] | 294 | if(LoadInst *ldInst = dyn_cast<LoadInst>(BBI)){ |
Anand Shukla | f8c09ee | 2003-02-14 20:41:53 +0000 | [diff] [blame] | 295 | if(pathReg[M] == ldInst->getPointerOperand()) |
| 296 | instToErase.push_back(ldInst); |
| 297 | } |
Chris Lattner | 889f620 | 2003-04-23 16:37:45 +0000 | [diff] [blame] | 298 | else if(StoreInst *stInst = dyn_cast<StoreInst>(BBI)){ |
Anand Shukla | f8c09ee | 2003-02-14 20:41:53 +0000 | [diff] [blame] | 299 | if(pathReg[M] == stInst->getPointerOperand()) |
| 300 | instToErase.push_back(stInst); |
| 301 | } |
| 302 | } |
| 303 | } |
| 304 | } |
| 305 | */ |
Anand Shukla | ea77a49 | 2002-09-18 03:55:26 +0000 | [diff] [blame] | 306 | } |
Brian Gaeke | 960707c | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 307 | |
| 308 | } // End llvm namespace |