Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1 | //===- ModuloSchedGraph.cpp - Graph datastructure for Modulo Scheduling ---===// |
| 2 | // |
| 3 | // |
| 4 | //===----------------------------------------------------------------------===// |
| 5 | |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 6 | #include "llvm/CodeGen/InstrSelection.h" |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 7 | #include "llvm/Function.h" |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 8 | #include "llvm/Instructions.h" |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 9 | #include "llvm/Type.h" |
| 10 | #include "llvm/CodeGen/MachineCodeForInstruction.h" |
| 11 | #include "llvm/CodeGen/MachineInstr.h" |
Guochun Shi | 6fbe5fb | 2003-04-06 23:56:19 +0000 | [diff] [blame] | 12 | #include "llvm/Target/TargetSchedInfo.h" |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 13 | #include "Support/StringExtras.h" |
| 14 | #include "Support/STLExtras.h" |
| 15 | #include "ModuloSchedGraph.h" |
| 16 | #include <algorithm> |
| 17 | #include <math.h> |
| 18 | //#include <swig.h> |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 19 | |
| 20 | #define UNIDELAY 1 |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 21 | |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 22 | extern std::ostream modSched_os; |
| 23 | extern ModuloSchedDebugLevel_t ModuloSchedDebugLevel; |
| 24 | //*********************** Internal Data Structures *************************/ |
| 25 | |
| 26 | // The following two types need to be classes, not typedefs, so we can use |
| 27 | // opaque declarations in SchedGraph.h |
| 28 | // |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 29 | struct RefVec:public std::vector < std::pair < ModuloSchedGraphNode *, int >> { |
| 30 | typedef std::vector<std::pair<ModuloSchedGraphNode*, |
| 31 | int> >::iterator iterator; |
| 32 | typedef std::vector<std::pair<ModuloSchedGraphNode*, |
| 33 | int> >::const_iterator const_iterator; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 34 | }; |
| 35 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 36 | struct RegToRefVecMap:public std::hash_map < int, RefVec > { |
| 37 | typedef std::hash_map<int,RefVec>::iterator iterator; |
| 38 | typedef std::hash_map<int,RefVec>::const_iterator const_iterator; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 39 | }; |
| 40 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 41 | struct ValueToDefVecMap:public std::hash_map < const Instruction *, RefVec > { |
| 42 | typedef std::hash_map<const Instruction*, RefVec>::iterator iterator; |
| 43 | typedef std::hash_map<const Instruction*, |
| 44 | RefVec>::const_iterator const_iterator; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 45 | }; |
| 46 | |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 47 | // class Modulo SchedGraphNode |
| 48 | |
| 49 | /*ctor*/ |
| 50 | ModuloSchedGraphNode::ModuloSchedGraphNode(unsigned int _nodeId, |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 51 | const BasicBlock * _bb, |
| 52 | const Instruction * _inst, |
| 53 | int indexInBB, |
| 54 | const TargetMachine & target) |
| 55 | :SchedGraphNodeCommon(_nodeId, _bb, indexInBB), inst(_inst) |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 56 | { |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 57 | if (inst) { |
| 58 | //FIXME: find the latency |
| 59 | //currently setthe latency to zero |
| 60 | latency = 0; |
| 61 | } |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 62 | } |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 63 | |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 64 | //class ModuloScheGraph |
| 65 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 66 | void ModuloSchedGraph::addDummyEdges() |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 67 | { |
| 68 | assert(graphRoot->outEdges.size() == 0); |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 69 | |
| 70 | for (const_iterator I = begin(); I != end(); ++I) { |
| 71 | ModuloSchedGraphNode *node = (ModuloSchedGraphNode *) ((*I).second); |
| 72 | assert(node != graphRoot && node != graphLeaf); |
| 73 | if (node->beginInEdges() == node->endInEdges()) |
| 74 | (void) new SchedGraphEdge(graphRoot, node, SchedGraphEdge::CtrlDep, |
| 75 | SchedGraphEdge::NonDataDep, 0); |
| 76 | if (node->beginOutEdges() == node->endOutEdges()) |
| 77 | (void) new SchedGraphEdge(node, graphLeaf, SchedGraphEdge::CtrlDep, |
| 78 | SchedGraphEdge::NonDataDep, 0); |
| 79 | } |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 82 | bool isDefinition(const Instruction *I) |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 83 | { |
| 84 | //if(TerminatorInst::classof(I)||FreeInst::classof(I) || StoreInst::classof(I) || CallInst::classof(I)) |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 85 | if (!I->hasName()) |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 86 | return false; |
| 87 | else |
| 88 | return true; |
| 89 | } |
| 90 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 91 | void ModuloSchedGraph::addDefUseEdges(const BasicBlock *bb) |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 92 | { |
| 93 | //collect def instructions, store them in vector |
Guochun Shi | 6fbe5fb | 2003-04-06 23:56:19 +0000 | [diff] [blame] | 94 | // const TargetInstrInfo& mii = target.getInstrInfo(); |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 95 | const TargetInstrInfo & mii = target.getInstrInfo(); |
| 96 | |
| 97 | typedef std::vector < ModuloSchedGraphNode * >DefVec; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 98 | DefVec defVec; |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 99 | |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 100 | //find those def instructions |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 101 | for (BasicBlock::const_iterator I = bb->begin(), E = bb->end(); I != E; ++I) { |
| 102 | if (I->getType() != Type::VoidTy) { |
| 103 | defVec.push_back(this->getGraphNodeForInst(I)); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | for (unsigned int i = 0; i < defVec.size(); i++) { |
| 108 | for (Value::use_const_iterator I = defVec[i]->getInst()->use_begin(); |
| 109 | I != defVec[i]->getInst()->use_end(); I++) { |
| 110 | //for each use of a def, add a flow edge from the def instruction to the ref instruction |
| 111 | |
| 112 | |
| 113 | const Instruction *value = defVec[i]->getInst(); |
| 114 | Instruction *inst = (Instruction *) (*I); |
| 115 | ModuloSchedGraphNode *node = NULL; |
| 116 | |
| 117 | for (BasicBlock::const_iterator I = bb->begin(), E = bb->end(); |
| 118 | I != E; ++I) |
| 119 | if ((const Instruction *) I == inst) { |
| 120 | node = (*this)[inst]; |
| 121 | break; |
| 122 | } |
| 123 | |
| 124 | assert(inst != NULL && " Use not an Instruction ?"); |
| 125 | |
| 126 | if (node == NULL) //inst is not an instruction in this block |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 127 | { |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 128 | } else { |
| 129 | // Add a flow edge from the def instruction to the ref instruction |
| 130 | |
| 131 | // self loop will not happen in SSA form |
| 132 | assert(defVec[i] != node && "same node?"); |
| 133 | |
| 134 | // This is a true dependence, so the delay is equal to the delay of the |
| 135 | // pred node. |
| 136 | int delay = 0; |
| 137 | MachineCodeForInstruction & tempMvec = |
| 138 | MachineCodeForInstruction::get(value); |
| 139 | for (unsigned j = 0; j < tempMvec.size(); j++) { |
| 140 | MachineInstr *temp = tempMvec[j]; |
| 141 | //delay +=mii.minLatency(temp->getOpCode()); |
| 142 | delay = std::max(delay, mii.minLatency(temp->getOpCode())); |
| 143 | } |
| 144 | |
| 145 | SchedGraphEdge *trueEdge = |
| 146 | new SchedGraphEdge(defVec[i], node, value, |
| 147 | SchedGraphEdge::TrueDep, delay); |
| 148 | |
| 149 | // if the ref instruction is before the def instrution |
| 150 | // then the def instruction must be a phi instruction |
| 151 | // add an anti-dependence edge to from the ref instruction to the def |
| 152 | // instruction |
| 153 | if (node->getOrigIndexInBB() < defVec[i]->getOrigIndexInBB()) { |
| 154 | assert(PHINode::classof(inst) |
| 155 | && "the ref instruction befre def is not PHINode?"); |
| 156 | trueEdge->setIteDiff(1); |
| 157 | } |
| 158 | |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 159 | } |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 160 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 161 | } |
| 162 | } |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 163 | } |
| 164 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 165 | void ModuloSchedGraph::addCDEdges(const BasicBlock * bb) { |
| 166 | // find the last instruction in the basic block |
| 167 | // see if it is an branch instruction. |
| 168 | // If yes, then add an edge from each node expcept the last node to the last |
| 169 | // node |
| 170 | const Instruction *inst = &(bb->back()); |
| 171 | ModuloSchedGraphNode *lastNode = (*this)[inst]; |
| 172 | if (TerminatorInst::classof(inst)) |
| 173 | for (BasicBlock::const_iterator I = bb->begin(), E = bb->end(); I != E; |
| 174 | I++) { |
| 175 | if (inst != I) { |
| 176 | ModuloSchedGraphNode *node = (*this)[I]; |
| 177 | //use latency of 0 |
| 178 | (void) new SchedGraphEdge(node, lastNode, SchedGraphEdge::CtrlDep, |
| 179 | SchedGraphEdge::NonDataDep, 0); |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 180 | } |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 181 | |
| 182 | } |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 185 | static const int SG_LOAD_REF = 0; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 186 | static const int SG_STORE_REF = 1; |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 187 | static const int SG_CALL_REF = 2; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 188 | |
| 189 | static const unsigned int SG_DepOrderArray[][3] = { |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 190 | {SchedGraphEdge::NonDataDep, |
| 191 | SchedGraphEdge::AntiDep, |
| 192 | SchedGraphEdge::AntiDep}, |
| 193 | {SchedGraphEdge::TrueDep, |
| 194 | SchedGraphEdge::OutputDep, |
| 195 | SchedGraphEdge::TrueDep | SchedGraphEdge::OutputDep}, |
| 196 | {SchedGraphEdge::TrueDep, |
| 197 | SchedGraphEdge::AntiDep | SchedGraphEdge::OutputDep, |
| 198 | SchedGraphEdge::TrueDep | SchedGraphEdge::AntiDep |
| 199 | | SchedGraphEdge::OutputDep} |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 200 | }; |
| 201 | |
| 202 | |
| 203 | // Add a dependence edge between every pair of machine load/store/call |
| 204 | // instructions, where at least one is a store or a call. |
| 205 | // Use latency 1 just to ensure that memory operations are ordered; |
| 206 | // latency does not otherwise matter (true dependences enforce that). |
| 207 | // |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 208 | void ModuloSchedGraph::addMemEdges(const BasicBlock * bb) { |
| 209 | |
| 210 | std::vector<ModuloSchedGraphNode*> memNodeVec; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 211 | |
| 212 | //construct the memNodeVec |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 213 | for (BasicBlock::const_iterator I = bb->begin(), E = bb->end(); I != E; ++I) { |
| 214 | if (LoadInst::classof(I) || StoreInst::classof(I) |
| 215 | || CallInst::classof(I)) { |
| 216 | ModuloSchedGraphNode *node = (*this)[(const Instruction *) I]; |
| 217 | memNodeVec.push_back(node); |
| 218 | } |
| 219 | } |
| 220 | |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 221 | // Instructions in memNodeVec are in execution order within the basic block, |
| 222 | // so simply look at all pairs <memNodeVec[i], memNodeVec[j: j > i]>. |
| 223 | // |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 224 | for (unsigned im = 0, NM = memNodeVec.size(); im < NM; im++) { |
| 225 | const Instruction *fromInst = memNodeVec[im]->getInst(); |
| 226 | int fromType = CallInst::classof(fromInst) ? SG_CALL_REF |
| 227 | : LoadInst::classof(fromInst) ? SG_LOAD_REF : SG_STORE_REF; |
| 228 | for (unsigned jm = im + 1; jm < NM; jm++) { |
| 229 | const Instruction *toInst = memNodeVec[jm]->getInst(); |
| 230 | int toType = CallInst::classof(toInst) ? SG_CALL_REF |
| 231 | : LoadInst::classof(toInst) ? SG_LOAD_REF : SG_STORE_REF; |
| 232 | if (fromType != SG_LOAD_REF || toType != SG_LOAD_REF) { |
| 233 | (void) new SchedGraphEdge(memNodeVec[im], memNodeVec[jm], |
| 234 | SchedGraphEdge::MemoryDep, |
| 235 | SG_DepOrderArray[fromType][toType], 1); |
| 236 | |
| 237 | SchedGraphEdge *edge = |
| 238 | new SchedGraphEdge(memNodeVec[jm], memNodeVec[im], |
| 239 | SchedGraphEdge::MemoryDep, |
| 240 | SG_DepOrderArray[toType][fromType], 1); |
| 241 | edge->setIteDiff(1); |
| 242 | |
| 243 | } |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 244 | } |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 245 | } |
| 246 | } |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 247 | |
| 248 | |
| 249 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 250 | void ModuloSchedGraph::buildNodesforBB(const TargetMachine &target, |
| 251 | const BasicBlock *bb, |
| 252 | std::vector<ModuloSchedGraphNode*> &memNode, |
| 253 | RegToRefVecMap ®ToRefVecMap, |
| 254 | ValueToDefVecMap &valueToDefVecMap) |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 255 | { |
Guochun Shi | 6fbe5fb | 2003-04-06 23:56:19 +0000 | [diff] [blame] | 256 | //const TargetInstrInfo& mii=target.getInstrInfo(); |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 257 | |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 258 | //Build graph nodes for each LLVM instruction and gather def/use info. |
| 259 | //Do both together in a single pass over all machine instructions. |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 260 | |
| 261 | int i = 0; |
| 262 | for (BasicBlock::const_iterator I = bb->begin(), E = bb->end(); I != E; |
| 263 | ++I) { |
| 264 | ModuloSchedGraphNode *node = |
| 265 | new ModuloSchedGraphNode(getNumNodes(), bb, I, i, target); |
| 266 | i++; |
| 267 | this->noteModuloSchedGraphNodeForInst(I, node); |
| 268 | } |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 269 | |
| 270 | //this function finds some info about instruction in basic block for later use |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 271 | //findDefUseInfoAtInstr(target, node, |
| 272 | //memNode,regToRefVecMap,valueToDefVecMap); |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 276 | bool ModuloSchedGraph::isLoop(const BasicBlock *bb) { |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 277 | //only if the last instruction in the basicblock is branch instruction and |
| 278 | //there is at least an option to branch itself |
| 279 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 280 | const Instruction *inst = &(bb->back()); |
| 281 | if (BranchInst::classof(inst)) { |
| 282 | for (unsigned i = 0; i < ((BranchInst *) inst)->getNumSuccessors(); |
| 283 | i++) { |
| 284 | BasicBlock *sb = ((BranchInst *) inst)->getSuccessor(i); |
| 285 | if (sb == bb) |
| 286 | return true; |
| 287 | } |
| 288 | } |
| 289 | |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 290 | return false; |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 291 | |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 292 | } |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 293 | |
| 294 | bool ModuloSchedGraph::isLoop() { |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 295 | //only if the last instruction in the basicblock is branch instruction and |
| 296 | //there is at least an option to branch itself |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 297 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 298 | assert(bbVec.size() == 1 && "only 1 basicblock in a graph"); |
| 299 | const BasicBlock *bb = bbVec[0]; |
| 300 | const Instruction *inst = &(bb->back()); |
| 301 | if (BranchInst::classof(inst)) |
| 302 | for (unsigned i = 0; i < ((BranchInst *) inst)->getNumSuccessors(); |
| 303 | i++) { |
| 304 | BasicBlock *sb = ((BranchInst *) inst)->getSuccessor(i); |
| 305 | if (sb == bb) |
| 306 | return true; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 307 | } |
| 308 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 309 | return false; |
| 310 | |
| 311 | } |
| 312 | |
| 313 | void ModuloSchedGraph::computeNodeASAP(const BasicBlock *bb) { |
| 314 | |
| 315 | //FIXME: now assume the only backward edges come from the edges from other |
| 316 | //nodes to the phi Node so i will ignore all edges to the phi node; after |
| 317 | //this, there shall be no recurrence. |
| 318 | |
| 319 | unsigned numNodes = bb->size(); |
| 320 | for (unsigned i = 2; i < numNodes + 2; i++) { |
| 321 | ModuloSchedGraphNode *node = getNode(i); |
| 322 | node->setPropertyComputed(false); |
| 323 | } |
| 324 | |
| 325 | for (unsigned i = 2; i < numNodes + 2; i++) { |
| 326 | ModuloSchedGraphNode *node = getNode(i); |
| 327 | node->ASAP = 0; |
| 328 | if (i == 2 || node->getNumInEdges() == 0) { |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 329 | node->setPropertyComputed(true); |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 330 | continue; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 331 | } |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 332 | for (ModuloSchedGraphNode::const_iterator I = node->beginInEdges(), E = |
| 333 | node->endInEdges(); I != E; I++) { |
| 334 | SchedGraphEdge *edge = *I; |
| 335 | ModuloSchedGraphNode *pred = |
| 336 | (ModuloSchedGraphNode *) (edge->getSrc()); |
| 337 | assert(pred->getPropertyComputed() |
| 338 | && "pred node property is not computed!"); |
| 339 | int temp = |
| 340 | pred->ASAP + edge->getMinDelay() - |
| 341 | edge->getIteDiff() * this->MII; |
| 342 | node->ASAP = std::max(node->ASAP, temp); |
| 343 | } |
| 344 | node->setPropertyComputed(true); |
| 345 | } |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 346 | } |
| 347 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 348 | void ModuloSchedGraph::computeNodeALAP(const BasicBlock *bb) { |
| 349 | unsigned numNodes = bb->size(); |
| 350 | int maxASAP = 0; |
| 351 | for (unsigned i = numNodes + 1; i >= 2; i--) { |
| 352 | ModuloSchedGraphNode *node = getNode(i); |
| 353 | node->setPropertyComputed(false); |
| 354 | //cerr<< " maxASAP= " <<maxASAP<<" node->ASAP= "<< node->ASAP<<"\n"; |
| 355 | maxASAP = std::max(maxASAP, node->ASAP); |
| 356 | } |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 357 | |
| 358 | //cerr<<"maxASAP is "<<maxASAP<<"\n"; |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 359 | |
| 360 | for (unsigned i = numNodes + 1; i >= 2; i--) { |
| 361 | ModuloSchedGraphNode *node = getNode(i); |
| 362 | node->ALAP = maxASAP; |
| 363 | for (ModuloSchedGraphNode::const_iterator I = |
| 364 | node->beginOutEdges(), E = node->endOutEdges(); I != E; I++) { |
| 365 | SchedGraphEdge *edge = *I; |
| 366 | ModuloSchedGraphNode *succ = |
| 367 | (ModuloSchedGraphNode *) (edge->getSink()); |
| 368 | if (PHINode::classof(succ->getInst())) |
| 369 | continue; |
| 370 | assert(succ->getPropertyComputed() |
| 371 | && "succ node property is not computed!"); |
| 372 | int temp = |
| 373 | succ->ALAP - edge->getMinDelay() + |
| 374 | edge->getIteDiff() * this->MII; |
| 375 | node->ALAP = std::min(node->ALAP, temp); |
| 376 | } |
| 377 | node->setPropertyComputed(true); |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | void ModuloSchedGraph::computeNodeMov(const BasicBlock *bb) |
| 382 | { |
| 383 | unsigned numNodes = bb->size(); |
| 384 | for (unsigned i = 2; i < numNodes + 2; i++) { |
| 385 | ModuloSchedGraphNode *node = getNode(i); |
| 386 | node->mov = node->ALAP - node->ASAP; |
| 387 | assert(node->mov >= 0 |
| 388 | && "move freedom for this node is less than zero? "); |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | |
| 393 | void ModuloSchedGraph::computeNodeDepth(const BasicBlock * bb) |
| 394 | { |
| 395 | |
| 396 | unsigned numNodes = bb->size(); |
| 397 | for (unsigned i = 2; i < numNodes + 2; i++) { |
| 398 | ModuloSchedGraphNode *node = getNode(i); |
| 399 | node->setPropertyComputed(false); |
| 400 | } |
| 401 | |
| 402 | for (unsigned i = 2; i < numNodes + 2; i++) { |
| 403 | ModuloSchedGraphNode *node = getNode(i); |
| 404 | node->depth = 0; |
| 405 | if (i == 2 || node->getNumInEdges() == 0) { |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 406 | node->setPropertyComputed(true); |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 407 | continue; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 408 | } |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 409 | for (ModuloSchedGraphNode::const_iterator I = node->beginInEdges(), E = |
| 410 | node->endInEdges(); I != E; I++) { |
| 411 | SchedGraphEdge *edge = *I; |
| 412 | ModuloSchedGraphNode *pred = |
| 413 | (ModuloSchedGraphNode *) (edge->getSrc()); |
| 414 | assert(pred->getPropertyComputed() |
| 415 | && "pred node property is not computed!"); |
| 416 | int temp = pred->depth + edge->getMinDelay(); |
| 417 | node->depth = std::max(node->depth, temp); |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 418 | } |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 419 | node->setPropertyComputed(true); |
| 420 | } |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 421 | |
| 422 | } |
| 423 | |
| 424 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 425 | void ModuloSchedGraph::computeNodeHeight(const BasicBlock *bb) |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 426 | { |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 427 | unsigned numNodes = bb->size(); |
| 428 | for (unsigned i = numNodes + 1; i >= 2; i--) { |
| 429 | ModuloSchedGraphNode *node = getNode(i); |
| 430 | node->setPropertyComputed(false); |
| 431 | } |
| 432 | |
| 433 | for (unsigned i = numNodes + 1; i >= 2; i--) { |
| 434 | ModuloSchedGraphNode *node = getNode(i); |
| 435 | node->height = 0; |
| 436 | for (ModuloSchedGraphNode::const_iterator I = |
| 437 | node->beginOutEdges(), E = node->endOutEdges(); I != E; ++I) { |
| 438 | SchedGraphEdge *edge = *I; |
| 439 | ModuloSchedGraphNode *succ = |
| 440 | (ModuloSchedGraphNode *) (edge->getSink()); |
| 441 | if (PHINode::classof(succ->getInst())) |
| 442 | continue; |
| 443 | assert(succ->getPropertyComputed() |
| 444 | && "succ node property is not computed!"); |
| 445 | node->height = std::max(node->height, succ->height + edge->getMinDelay()); |
| 446 | |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 447 | } |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 448 | node->setPropertyComputed(true); |
| 449 | |
| 450 | } |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 451 | |
| 452 | } |
| 453 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 454 | void ModuloSchedGraph::computeNodeProperty(const BasicBlock * bb) |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 455 | { |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 456 | //FIXME: now assume the only backward edges come from the edges from other |
| 457 | //nodes to the phi Node so i will ignore all edges to the phi node; after |
| 458 | //this, there shall be no recurrence. |
| 459 | |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 460 | this->computeNodeASAP(bb); |
| 461 | this->computeNodeALAP(bb); |
| 462 | this->computeNodeMov(bb); |
| 463 | this->computeNodeDepth(bb); |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 464 | this->computeNodeHeight(bb); |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | |
| 468 | //do not consider the backedge in these two functions: |
| 469 | // i.e. don't consider the edge with destination in phi node |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 470 | std::vector<ModuloSchedGraphNode*> |
| 471 | ModuloSchedGraph::predSet(std::vector<ModuloSchedGraphNode*> set, |
| 472 | unsigned backEdgeSrc, |
| 473 | unsigned |
| 474 | backEdgeSink) |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 475 | { |
| 476 | std::vector<ModuloSchedGraphNode*> predS; |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 477 | for (unsigned i = 0; i < set.size(); i++) { |
| 478 | ModuloSchedGraphNode *node = set[i]; |
| 479 | for (ModuloSchedGraphNode::const_iterator I = node->beginInEdges(), E = |
| 480 | node->endInEdges(); I != E; I++) { |
| 481 | SchedGraphEdge *edge = *I; |
| 482 | if (edge->getSrc()->getNodeId() == backEdgeSrc |
| 483 | && edge->getSink()->getNodeId() == backEdgeSink) |
| 484 | continue; |
| 485 | ModuloSchedGraphNode *pred = |
| 486 | (ModuloSchedGraphNode *) (edge->getSrc()); |
| 487 | //if pred is not in the predSet, push it in vector |
| 488 | bool alreadyInset = false; |
| 489 | for (unsigned j = 0; j < predS.size(); ++j) |
| 490 | if (predS[j]->getNodeId() == pred->getNodeId()) { |
| 491 | alreadyInset = true; |
| 492 | break; |
| 493 | } |
| 494 | |
| 495 | for (unsigned j = 0; j < set.size(); ++j) |
| 496 | if (set[j]->getNodeId() == pred->getNodeId()) { |
| 497 | alreadyInset = true; |
| 498 | break; |
| 499 | } |
| 500 | |
| 501 | if (!alreadyInset) |
| 502 | predS.push_back(pred); |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 503 | } |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 504 | } |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 505 | return predS; |
| 506 | } |
| 507 | |
| 508 | ModuloSchedGraph::NodeVec ModuloSchedGraph::predSet(NodeVec set) |
| 509 | { |
| 510 | //node number increases from 2 |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 511 | return predSet(set, 0, 0); |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 512 | } |
| 513 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 514 | std::vector <ModuloSchedGraphNode*> |
| 515 | ModuloSchedGraph::predSet(ModuloSchedGraphNode *_node, |
| 516 | unsigned backEdgeSrc, unsigned backEdgeSink) |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 517 | { |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 518 | std::vector<ModuloSchedGraphNode*> set; |
| 519 | set.push_back(_node); |
| 520 | return predSet(set, backEdgeSrc, backEdgeSink); |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 521 | } |
| 522 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 523 | std::vector <ModuloSchedGraphNode*> |
| 524 | ModuloSchedGraph::predSet(ModuloSchedGraphNode * _node) |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 525 | { |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 526 | return predSet(_node, 0, 0); |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 527 | } |
| 528 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 529 | std::vector<ModuloSchedGraphNode*> |
| 530 | ModuloSchedGraph::succSet(std::vector<ModuloSchedGraphNode*> set, |
| 531 | unsigned src, unsigned sink) |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 532 | { |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 533 | std::vector<ModuloSchedGraphNode*> succS; |
| 534 | for (unsigned i = 0; i < set.size(); i++) { |
| 535 | ModuloSchedGraphNode *node = set[i]; |
| 536 | for (ModuloSchedGraphNode::const_iterator I = |
| 537 | node->beginOutEdges(), E = node->endOutEdges(); I != E; I++) { |
| 538 | SchedGraphEdge *edge = *I; |
| 539 | if (edge->getSrc()->getNodeId() == src |
| 540 | && edge->getSink()->getNodeId() == sink) |
| 541 | continue; |
| 542 | ModuloSchedGraphNode *succ = |
| 543 | (ModuloSchedGraphNode *) (edge->getSink()); |
| 544 | //if pred is not in the predSet, push it in vector |
| 545 | bool alreadyInset = false; |
| 546 | for (unsigned j = 0; j < succS.size(); j++) |
| 547 | if (succS[j]->getNodeId() == succ->getNodeId()) { |
| 548 | alreadyInset = true; |
| 549 | break; |
| 550 | } |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 551 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 552 | for (unsigned j = 0; j < set.size(); j++) |
| 553 | if (set[j]->getNodeId() == succ->getNodeId()) { |
| 554 | alreadyInset = true; |
| 555 | break; |
| 556 | } |
| 557 | if (!alreadyInset) |
| 558 | succS.push_back(succ); |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 559 | } |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 560 | } |
| 561 | return succS; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | ModuloSchedGraph::NodeVec ModuloSchedGraph::succSet(NodeVec set) |
| 565 | { |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 566 | return succSet(set, 0, 0); |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 570 | std::vector<ModuloSchedGraphNode*> |
| 571 | ModuloSchedGraph::succSet(ModuloSchedGraphNode *_node, |
| 572 | unsigned src, unsigned sink) |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 573 | { |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 574 | std::vector<ModuloSchedGraphNode*>set; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 575 | set.push_back(_node); |
| 576 | return succSet(set, src, sink); |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 577 | } |
| 578 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 579 | std::vector<ModuloSchedGraphNode*> |
| 580 | ModuloSchedGraph::succSet(ModuloSchedGraphNode * _node) |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 581 | { |
| 582 | return succSet(_node, 0, 0); |
| 583 | } |
| 584 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 585 | SchedGraphEdge *ModuloSchedGraph::getMaxDelayEdge(unsigned srcId, |
| 586 | unsigned sinkId) |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 587 | { |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 588 | ModuloSchedGraphNode *node = getNode(srcId); |
| 589 | SchedGraphEdge *maxDelayEdge = NULL; |
| 590 | int maxDelay = -1; |
| 591 | for (ModuloSchedGraphNode::const_iterator I = node->beginOutEdges(), E = |
| 592 | node->endOutEdges(); I != E; I++) { |
| 593 | SchedGraphEdge *edge = *I; |
| 594 | if (edge->getSink()->getNodeId() == sinkId) |
| 595 | if (edge->getMinDelay() > maxDelay) { |
| 596 | maxDelayEdge = edge; |
| 597 | maxDelay = edge->getMinDelay(); |
| 598 | } |
| 599 | } |
| 600 | assert(maxDelayEdge != NULL && "no edge between the srcId and sinkId?"); |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 601 | return maxDelayEdge; |
| 602 | } |
| 603 | |
| 604 | void ModuloSchedGraph::dumpCircuits() |
| 605 | { |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 606 | modSched_os << "dumping circuits for graph: " << "\n"; |
| 607 | int j = -1; |
| 608 | while (circuits[++j][0] != 0) { |
| 609 | int k = -1; |
| 610 | while (circuits[j][++k] != 0) |
| 611 | modSched_os << circuits[j][k] << "\t"; |
| 612 | modSched_os << "\n"; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 613 | } |
| 614 | } |
| 615 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 616 | void ModuloSchedGraph::dumpSet(std::vector < ModuloSchedGraphNode * >set) |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 617 | { |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 618 | for (unsigned i = 0; i < set.size(); i++) |
| 619 | modSched_os << set[i]->getNodeId() << "\t"; |
| 620 | modSched_os << "\n"; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 621 | } |
| 622 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 623 | std::vector<ModuloSchedGraphNode*> |
| 624 | ModuloSchedGraph::vectorUnion(std::vector<ModuloSchedGraphNode*> set1, |
| 625 | std::vector<ModuloSchedGraphNode*> set2) |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 626 | { |
| 627 | std::vector<ModuloSchedGraphNode*> unionVec; |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 628 | for (unsigned i = 0; i < set1.size(); i++) |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 629 | unionVec.push_back(set1[i]); |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 630 | for (unsigned j = 0; j < set2.size(); j++) { |
| 631 | bool inset = false; |
| 632 | for (unsigned i = 0; i < unionVec.size(); i++) |
| 633 | if (set2[j] == unionVec[i]) |
| 634 | inset = true; |
| 635 | if (!inset) |
| 636 | unionVec.push_back(set2[j]); |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 637 | } |
| 638 | return unionVec; |
| 639 | } |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 640 | |
| 641 | std::vector<ModuloSchedGraphNode*> |
| 642 | ModuloSchedGraph::vectorConj(std::vector<ModuloSchedGraphNode*> set1, |
| 643 | std::vector<ModuloSchedGraphNode*> set2) |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 644 | { |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 645 | std::vector<ModuloSchedGraphNode*> conjVec; |
| 646 | for (unsigned i = 0; i < set1.size(); i++) |
| 647 | for (unsigned j = 0; j < set2.size(); j++) |
| 648 | if (set1[i] == set2[j]) |
| 649 | conjVec.push_back(set1[i]); |
| 650 | return conjVec; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 651 | } |
| 652 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 653 | ModuloSchedGraph::NodeVec ModuloSchedGraph::vectorSub(NodeVec set1, |
| 654 | NodeVec set2) |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 655 | { |
| 656 | NodeVec newVec; |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 657 | for (NodeVec::iterator I = set1.begin(); I != set1.end(); I++) { |
| 658 | bool inset = false; |
| 659 | for (NodeVec::iterator II = set2.begin(); II != set2.end(); II++) |
| 660 | if ((*I)->getNodeId() == (*II)->getNodeId()) { |
| 661 | inset = true; |
| 662 | break; |
| 663 | } |
| 664 | if (!inset) |
| 665 | newVec.push_back(*I); |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 666 | } |
| 667 | return newVec; |
| 668 | } |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 669 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 670 | void ModuloSchedGraph::orderNodes() { |
| 671 | oNodes.clear(); |
| 672 | |
| 673 | std::vector < ModuloSchedGraphNode * >set; |
| 674 | const BasicBlock *bb = bbVec[0]; |
| 675 | unsigned numNodes = bb->size(); |
| 676 | |
| 677 | //first order all the sets |
| 678 | int j = -1; |
| 679 | int totalDelay = -1; |
| 680 | int preDelay = -1; |
| 681 | while (circuits[++j][0] != 0) { |
| 682 | int k = -1; |
| 683 | preDelay = totalDelay; |
| 684 | |
| 685 | while (circuits[j][++k] != 0) { |
| 686 | ModuloSchedGraphNode *node = getNode(circuits[j][k]); |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 687 | unsigned nextNodeId; |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 688 | nextNodeId = |
| 689 | circuits[j][k + 1] != 0 ? circuits[j][k + 1] : circuits[j][0]; |
| 690 | SchedGraphEdge *edge = getMaxDelayEdge(circuits[j][k], nextNodeId); |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 691 | totalDelay += edge->getMinDelay(); |
| 692 | } |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 693 | if (preDelay != -1 && totalDelay > preDelay) { |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 694 | //swap circuits[j][] and cuicuits[j-1][] |
| 695 | unsigned temp[MAXNODE]; |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 696 | for (int k = 0; k < MAXNODE; k++) { |
| 697 | temp[k] = circuits[j - 1][k]; |
| 698 | circuits[j - 1][k] = circuits[j][k]; |
| 699 | circuits[j][k] = temp[k]; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 700 | } |
| 701 | //restart |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 702 | j = -1; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 703 | } |
| 704 | } |
| 705 | |
| 706 | //build the first set |
| 707 | int backEdgeSrc; |
| 708 | int backEdgeSink; |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 709 | if (ModuloSchedDebugLevel >= ModuloSched_PrintScheduleProcess) |
| 710 | modSched_os << "building the first set" << "\n"; |
| 711 | int setSeq = -1; |
| 712 | int k = -1; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 713 | setSeq++; |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 714 | while (circuits[setSeq][++k] != 0) |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 715 | set.push_back(getNode(circuits[setSeq][k])); |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 716 | if (circuits[setSeq][0] != 0) { |
| 717 | backEdgeSrc = circuits[setSeq][k - 1]; |
| 718 | backEdgeSink = circuits[setSeq][0]; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 719 | } |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 720 | if (ModuloSchedDebugLevel >= ModuloSched_PrintScheduleProcess) { |
| 721 | modSched_os << "the first set is:"; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 722 | dumpSet(set); |
| 723 | } |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 724 | //implement the ordering algorithm |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 725 | enum OrderSeq { bottom_up, top_down }; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 726 | OrderSeq order; |
| 727 | std::vector<ModuloSchedGraphNode*> R; |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 728 | while (!set.empty()) { |
| 729 | std::vector < ModuloSchedGraphNode * >pset = predSet(oNodes); |
| 730 | std::vector < ModuloSchedGraphNode * >sset = succSet(oNodes); |
| 731 | |
| 732 | if (!pset.empty() && !vectorConj(pset, set).empty()) { |
| 733 | R = vectorConj(pset, set); |
| 734 | order = bottom_up; |
| 735 | } else if (!sset.empty() && !vectorConj(sset, set).empty()) { |
| 736 | R = vectorConj(sset, set); |
| 737 | order = top_down; |
| 738 | } else { |
| 739 | int maxASAP = -1; |
| 740 | int position = -1; |
| 741 | for (unsigned i = 0; i < set.size(); i++) { |
| 742 | int temp = set[i]->getASAP(); |
| 743 | if (temp > maxASAP) { |
| 744 | maxASAP = temp; |
| 745 | position = i; |
| 746 | } |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 747 | } |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 748 | R.push_back(set[position]); |
| 749 | order = bottom_up; |
| 750 | } |
| 751 | |
| 752 | while (!R.empty()) { |
| 753 | if (order == top_down) { |
| 754 | if (ModuloSchedDebugLevel >= ModuloSched_PrintScheduleProcess) |
| 755 | modSched_os << "in top_down round" << "\n"; |
| 756 | while (!R.empty()) { |
| 757 | int maxHeight = -1; |
| 758 | NodeVec::iterator chosenI; |
| 759 | for (NodeVec::iterator I = R.begin(); I != R.end(); I++) { |
| 760 | int temp = (*I)->height; |
| 761 | if ((temp > maxHeight) |
| 762 | || (temp == maxHeight && (*I)->mov <= (*chosenI)->mov)) { |
| 763 | |
| 764 | if ((temp > maxHeight) |
| 765 | || (temp == maxHeight && (*I)->mov < (*chosenI)->mov)) { |
| 766 | maxHeight = temp; |
| 767 | chosenI = I; |
| 768 | continue; |
| 769 | } |
| 770 | //possible case: instruction A and B has the same height and mov, |
| 771 | //but A has dependence to B e.g B is the branch instruction in the |
| 772 | //end, or A is the phi instruction at the beginning |
| 773 | if ((*I)->mov == (*chosenI)->mov) |
| 774 | for (ModuloSchedGraphNode::const_iterator oe = |
| 775 | (*I)->beginOutEdges(), end = (*I)->endOutEdges(); |
| 776 | oe != end; oe++) { |
| 777 | if ((*oe)->getSink() == (*chosenI)) { |
| 778 | maxHeight = temp; |
| 779 | chosenI = I; |
| 780 | continue; |
| 781 | } |
| 782 | } |
| 783 | } |
| 784 | } |
| 785 | ModuloSchedGraphNode *mu = *chosenI; |
| 786 | oNodes.push_back(mu); |
| 787 | R.erase(chosenI); |
| 788 | std::vector<ModuloSchedGraphNode*> succ_mu = |
| 789 | succSet(mu, backEdgeSrc, backEdgeSink); |
| 790 | std::vector<ModuloSchedGraphNode*> comm = |
| 791 | vectorConj(succ_mu, set); |
| 792 | comm = vectorSub(comm, oNodes); |
| 793 | R = vectorUnion(comm, R); |
| 794 | } |
| 795 | order = bottom_up; |
| 796 | R = vectorConj(predSet(oNodes), set); |
| 797 | } else { |
| 798 | if (ModuloSchedDebugLevel >= ModuloSched_PrintScheduleProcess) |
| 799 | modSched_os << "in bottom up round" << "\n"; |
| 800 | while (!R.empty()) { |
| 801 | int maxDepth = -1; |
| 802 | NodeVec::iterator chosenI; |
| 803 | for (NodeVec::iterator I = R.begin(); I != R.end(); I++) { |
| 804 | int temp = (*I)->depth; |
| 805 | if ((temp > maxDepth) |
| 806 | || (temp == maxDepth && (*I)->mov < (*chosenI)->mov)) { |
| 807 | maxDepth = temp; |
| 808 | chosenI = I; |
| 809 | } |
| 810 | } |
| 811 | ModuloSchedGraphNode *mu = *chosenI; |
| 812 | oNodes.push_back(mu); |
| 813 | R.erase(chosenI); |
| 814 | std::vector<ModuloSchedGraphNode*> pred_mu = |
| 815 | predSet(mu, backEdgeSrc, backEdgeSink); |
| 816 | std::vector<ModuloSchedGraphNode*> comm = |
| 817 | vectorConj(pred_mu, set); |
| 818 | comm = vectorSub(comm, oNodes); |
| 819 | R = vectorUnion(comm, R); |
| 820 | } |
| 821 | order = top_down; |
| 822 | R = vectorConj(succSet(oNodes), set); |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 823 | } |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 824 | } |
| 825 | if (ModuloSchedDebugLevel >= ModuloSched_PrintScheduleProcess) { |
| 826 | modSched_os << "order finished" << "\n"; |
| 827 | modSched_os << "dumping the ordered nodes: " << "\n"; |
| 828 | dumpSet(oNodes); |
| 829 | dumpCircuits(); |
| 830 | } |
| 831 | //create a new set |
| 832 | //FIXME: the nodes between onodes and this circuit should also be include in |
| 833 | //this set |
| 834 | if (ModuloSchedDebugLevel >= ModuloSched_PrintScheduleProcess) |
| 835 | modSched_os << "building the next set" << "\n"; |
| 836 | set.clear(); |
| 837 | int k = -1; |
| 838 | setSeq++; |
| 839 | while (circuits[setSeq][++k] != 0) |
| 840 | set.push_back(getNode(circuits[setSeq][k])); |
| 841 | if (circuits[setSeq][0] != 0) { |
| 842 | backEdgeSrc = circuits[setSeq][k - 1]; |
| 843 | backEdgeSink = circuits[setSeq][0]; |
| 844 | } |
| 845 | if (set.empty()) { |
| 846 | //no circuits any more |
| 847 | //collect all other nodes |
| 848 | if (ModuloSchedDebugLevel >= ModuloSched_PrintScheduleProcess) |
| 849 | modSched_os << "no circuits any more, collect the rest nodes" << |
| 850 | "\n"; |
| 851 | for (unsigned i = 2; i < numNodes + 2; i++) { |
| 852 | bool inset = false; |
| 853 | for (unsigned j = 0; j < oNodes.size(); j++) |
| 854 | if (oNodes[j]->getNodeId() == i) { |
| 855 | inset = true; |
| 856 | break; |
| 857 | } |
| 858 | if (!inset) |
| 859 | set.push_back(getNode(i)); |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 860 | } |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 861 | } |
| 862 | if (ModuloSchedDebugLevel >= ModuloSched_PrintScheduleProcess) { |
| 863 | modSched_os << "next set is: " << "\n"; |
| 864 | dumpSet(set); |
| 865 | } |
| 866 | } //while(!set.empty()) |
| 867 | |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | |
| 871 | |
| 872 | |
| 873 | |
| 874 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 875 | void ModuloSchedGraph::buildGraph(const TargetMachine & target) |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 876 | { |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 877 | const BasicBlock *bb = bbVec[0]; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 878 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 879 | assert(bbVec.size() == 1 && "only handling a single basic block here"); |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 880 | |
| 881 | // Use this data structure to note all machine operands that compute |
| 882 | // ordinary LLVM values. These must be computed defs (i.e., instructions). |
| 883 | // Note that there may be multiple machine instructions that define |
| 884 | // each Value. |
| 885 | ValueToDefVecMap valueToDefVecMap; |
| 886 | |
| 887 | // Use this data structure to note all memory instructions. |
| 888 | // We use this to add memory dependence edges without a second full walk. |
| 889 | // |
| 890 | // vector<const Instruction*> memVec; |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 891 | std::vector < ModuloSchedGraphNode * >memNodeVec; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 892 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 893 | // Use this data structure to note any uses or definitions of |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 894 | // machine registers so we can add edges for those later without |
| 895 | // extra passes over the nodes. |
| 896 | // The vector holds an ordered list of references to the machine reg, |
| 897 | // ordered according to control-flow order. This only works for a |
| 898 | // single basic block, hence the assertion. Each reference is identified |
| 899 | // by the pair: <node, operand-number>. |
| 900 | // |
| 901 | RegToRefVecMap regToRefVecMap; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 902 | |
| 903 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 904 | |
| 905 | // Make a dummy root node. We'll add edges to the real roots later. |
| 906 | graphRoot = new ModuloSchedGraphNode(0, NULL, NULL, -1, target); |
| 907 | graphLeaf = new ModuloSchedGraphNode(1, NULL, NULL, -1, target); |
| 908 | |
| 909 | //---------------------------------------------------------------- |
| 910 | // First add nodes for all the LLVM instructions in the basic block because |
| 911 | // this greatly simplifies identifying which edges to add. Do this one VM |
| 912 | // instruction at a time since the ModuloSchedGraphNode needs that. |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 913 | // Also, remember the load/store instructions to add memory deps later. |
| 914 | //---------------------------------------------------------------- |
| 915 | |
| 916 | //FIXME:if there is call instruction, then we shall quit somewhere |
| 917 | // currently we leave call instruction and continue construct graph |
| 918 | |
| 919 | //dump only the blocks which are from loops |
| 920 | |
| 921 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 922 | if (ModuloSchedDebugLevel >= ModuloSched_PrintScheduleProcess) |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 923 | this->dump(bb); |
| 924 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 925 | if (!isLoop(bb)) { |
| 926 | modSched_os << " dumping non-loop BB:\n"; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 927 | dump(bb); |
| 928 | } |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 929 | if (isLoop(bb)) { |
| 930 | buildNodesforBB(target, bb, memNodeVec, regToRefVecMap, |
| 931 | valueToDefVecMap); |
| 932 | |
| 933 | this->addDefUseEdges(bb); |
| 934 | this->addCDEdges(bb); |
| 935 | this->addMemEdges(bb); |
| 936 | |
| 937 | //this->dump(); |
| 938 | |
| 939 | int ResII = this->computeResII(bb); |
| 940 | if (ModuloSchedDebugLevel >= ModuloSched_PrintScheduleProcess) |
| 941 | modSched_os << "ResII is " << ResII << "\n";; |
| 942 | int RecII = this->computeRecII(bb); |
| 943 | if (ModuloSchedDebugLevel >= ModuloSched_PrintScheduleProcess) |
| 944 | modSched_os << "RecII is " << RecII << "\n"; |
| 945 | |
| 946 | this->MII = std::max(ResII, RecII); |
| 947 | |
| 948 | this->computeNodeProperty(bb); |
| 949 | if (ModuloSchedDebugLevel >= ModuloSched_PrintScheduleProcess) |
| 950 | this->dumpNodeProperty(); |
| 951 | |
| 952 | this->orderNodes(); |
| 953 | |
| 954 | if (ModuloSchedDebugLevel >= ModuloSched_PrintScheduleProcess) |
| 955 | this->dump(); |
| 956 | //this->instrScheduling(); |
| 957 | |
| 958 | //this->dumpScheduling(); |
| 959 | } |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 960 | } |
| 961 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 962 | ModuloSchedGraphNode *ModuloSchedGraph::getNode(const unsigned nodeId) const |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 963 | { |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 964 | for (const_iterator I = begin(), E = end(); I != E; I++) |
| 965 | if ((*I).second->getNodeId() == nodeId) |
| 966 | return (ModuloSchedGraphNode *) (*I).second; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 967 | return NULL; |
| 968 | } |
| 969 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 970 | int ModuloSchedGraph::computeRecII(const BasicBlock *bb) |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 971 | { |
| 972 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 973 | int RecII = 0; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 974 | |
| 975 | //os<<"begining computerRecII()"<<"\n"; |
| 976 | |
| 977 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 978 | //FIXME: only deal with circuits starting at the first node: the phi node |
| 979 | //nodeId=2; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 980 | |
| 981 | //search all elementary circuits in the dependance graph |
| 982 | //assume maximum number of nodes is MAXNODE |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 983 | |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 984 | unsigned path[MAXNODE]; |
| 985 | unsigned stack[MAXNODE][MAXNODE]; |
| 986 | |
| 987 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 988 | for (int j = 0; j < MAXNODE; j++) { |
| 989 | path[j] = 0; |
| 990 | for (int k = 0; k < MAXNODE; k++) |
| 991 | stack[j][k] = 0; |
| 992 | } |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 993 | //in our graph, the node number starts at 2 |
| 994 | |
| 995 | //number of nodes, because each instruction will result in one node |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 996 | const unsigned numNodes = bb->size(); |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 997 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 998 | int i = 0; |
| 999 | path[i] = 2; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1000 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1001 | ModuloSchedGraphNode *initNode = getNode(path[0]); |
| 1002 | unsigned initNodeId = initNode->getNodeId(); |
| 1003 | ModuloSchedGraphNode *currentNode = initNode; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1004 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1005 | while (currentNode != NULL) { |
| 1006 | unsigned currentNodeId = currentNode->getNodeId(); |
| 1007 | // modSched_os<<"current node is "<<currentNodeId<<"\n"; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1008 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1009 | ModuloSchedGraphNode *nextNode = NULL; |
| 1010 | for (ModuloSchedGraphNode::const_iterator I = |
| 1011 | currentNode->beginOutEdges(), E = currentNode->endOutEdges(); |
| 1012 | I != E; I++) { |
| 1013 | //modSched_os <<" searching in outgoint edges of node |
| 1014 | //"<<currentNodeId<<"\n"; |
| 1015 | unsigned nodeId = ((SchedGraphEdge *) * I)->getSink()->getNodeId(); |
| 1016 | bool inpath = false, instack = false; |
| 1017 | int k; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1018 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1019 | //modSched_os<<"nodeId is "<<nodeId<<"\n"; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1020 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1021 | k = -1; |
| 1022 | while (path[++k] != 0) |
| 1023 | if (nodeId == path[k]) { |
| 1024 | inpath = true; |
| 1025 | break; |
| 1026 | } |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1027 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1028 | k = -1; |
| 1029 | while (stack[i][++k] != 0) |
| 1030 | if (nodeId == stack[i][k]) { |
| 1031 | instack = true; |
| 1032 | break; |
| 1033 | } |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1034 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1035 | if (nodeId > currentNodeId && !inpath && !instack) { |
| 1036 | nextNode = |
| 1037 | (ModuloSchedGraphNode *) ((SchedGraphEdge *) * I)->getSink(); |
| 1038 | break; |
| 1039 | } |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1040 | } |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1041 | |
| 1042 | if (nextNode != NULL) { |
| 1043 | //modSched_os<<"find the next Node "<<nextNode->getNodeId()<<"\n"; |
| 1044 | |
| 1045 | int j = 0; |
| 1046 | while (stack[i][j] != 0) |
| 1047 | j++; |
| 1048 | stack[i][j] = nextNode->getNodeId(); |
| 1049 | |
| 1050 | i++; |
| 1051 | path[i] = nextNode->getNodeId(); |
| 1052 | currentNode = nextNode; |
| 1053 | } else { |
| 1054 | //modSched_os<<"no expansion any more"<<"\n"; |
| 1055 | //confirmCircuit(); |
| 1056 | for (ModuloSchedGraphNode::const_iterator I = |
| 1057 | currentNode->beginOutEdges(), E = currentNode->endOutEdges(); |
| 1058 | I != E; I++) { |
| 1059 | unsigned nodeId = ((SchedGraphEdge *) * I)->getSink()->getNodeId(); |
| 1060 | if (nodeId == initNodeId) { |
| 1061 | |
| 1062 | int j = -1; |
| 1063 | while (circuits[++j][0] != 0); |
| 1064 | for (int k = 0; k < MAXNODE; k++) |
| 1065 | circuits[j][k] = path[k]; |
| 1066 | |
| 1067 | } |
| 1068 | } |
| 1069 | //remove this node in the path and clear the corresponding entries in the |
| 1070 | //stack |
| 1071 | path[i] = 0; |
| 1072 | int j = 0; |
| 1073 | for (j = 0; j < MAXNODE; j++) |
| 1074 | stack[i][j] = 0; |
| 1075 | i--; |
| 1076 | currentNode = getNode(path[i]); |
| 1077 | } |
| 1078 | if (i == 0) { |
| 1079 | |
| 1080 | if (ModuloSchedDebugLevel >= ModuloSched_PrintScheduleProcess) |
| 1081 | modSched_os << "circuits found are: " << "\n"; |
| 1082 | int j = -1; |
| 1083 | while (circuits[++j][0] != 0) { |
| 1084 | int k = -1; |
| 1085 | while (circuits[j][++k] != 0) |
| 1086 | if (ModuloSchedDebugLevel >= ModuloSched_PrintScheduleProcess) |
| 1087 | modSched_os << circuits[j][k] << "\t"; |
| 1088 | if (ModuloSchedDebugLevel >= ModuloSched_PrintScheduleProcess) |
| 1089 | modSched_os << "\n"; |
| 1090 | |
| 1091 | //for this circuit, compute the sum of all edge delay |
| 1092 | int sumDelay = 0; |
| 1093 | k = -1; |
| 1094 | while (circuits[j][++k] != 0) { |
| 1095 | //ModuloSchedGraphNode* node =getNode(circuits[j][k]); |
| 1096 | unsigned nextNodeId; |
| 1097 | nextNodeId = |
| 1098 | circuits[j][k + 1] != |
| 1099 | 0 ? circuits[j][k + 1] : circuits[j][0]; |
| 1100 | |
| 1101 | /* |
| 1102 | for(ModuloSchedGraphNode::const_iterator I=node->beginOutEdges(), |
| 1103 | E=node->endOutEdges();I !=E; I++) |
| 1104 | { |
| 1105 | SchedGraphEdge* edge= *I; |
| 1106 | if(edge->getSink()->getNodeId() == nextNodeId) |
| 1107 | {sumDelay += edge->getMinDelay();break;} |
| 1108 | } |
| 1109 | */ |
| 1110 | |
| 1111 | sumDelay += |
| 1112 | getMaxDelayEdge(circuits[j][k], nextNodeId)->getMinDelay(); |
| 1113 | |
| 1114 | } |
| 1115 | // assume we have distance 1, in this case the sumDelay is RecII |
| 1116 | // this is correct for SSA form only |
| 1117 | // |
| 1118 | if (ModuloSchedDebugLevel >= ModuloSched_PrintScheduleProcess) |
| 1119 | modSched_os << "The total Delay in the circuit is " << sumDelay |
| 1120 | << "\n"; |
| 1121 | |
| 1122 | RecII = RecII > sumDelay ? RecII : sumDelay; |
| 1123 | |
| 1124 | } |
| 1125 | return RecII; |
| 1126 | } |
| 1127 | |
| 1128 | } |
| 1129 | |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1130 | return -1; |
| 1131 | } |
| 1132 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1133 | void ModuloSchedGraph::addResourceUsage(std::vector<std::pair<int,int> > &ruVec, |
| 1134 | int rid) |
| 1135 | { |
| 1136 | //modSched_os<<"\nadding a resouce , current resouceUsage vector size is |
| 1137 | //"<<ruVec.size()<<"\n"; |
| 1138 | bool alreadyExists = false; |
| 1139 | for (unsigned i = 0; i < ruVec.size(); i++) { |
| 1140 | if (rid == ruVec[i].first) { |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1141 | ruVec[i].second++; |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1142 | alreadyExists = true; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1143 | break; |
| 1144 | } |
| 1145 | } |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1146 | if (!alreadyExists) |
| 1147 | ruVec.push_back(std::make_pair(rid, 1)); |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1148 | //modSched_os<<"current resouceUsage vector size is "<<ruVec.size()<<"\n"; |
| 1149 | |
| 1150 | } |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1151 | void ModuloSchedGraph::dumpResourceUsage(std::vector<std::pair<int,int> > &ru) |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1152 | { |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1153 | TargetSchedInfo & msi = (TargetSchedInfo &) target.getSchedInfo(); |
| 1154 | |
| 1155 | std::vector<std::pair<int,int>> resourceNumVector = msi.resourceNumVector; |
| 1156 | modSched_os << "resourceID\t" << "resourceNum" << "\n"; |
| 1157 | for (unsigned i = 0; i < resourceNumVector.size(); i++) |
| 1158 | modSched_os << resourceNumVector[i]. |
| 1159 | first << "\t" << resourceNumVector[i].second << "\n"; |
| 1160 | |
| 1161 | modSched_os << " maxNumIssueTotal(issue slot in one cycle) = " << msi. |
| 1162 | maxNumIssueTotal << "\n"; |
| 1163 | modSched_os << "resourceID\t resourceUsage\t ResourceNum" << "\n"; |
| 1164 | for (unsigned i = 0; i < ru.size(); i++) { |
| 1165 | modSched_os << ru[i].first << "\t" << ru[i].second; |
| 1166 | const unsigned resNum = msi.getCPUResourceNum(ru[i].first); |
| 1167 | modSched_os << "\t" << resNum << "\n"; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1168 | } |
| 1169 | } |
| 1170 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1171 | int ModuloSchedGraph::computeResII(const BasicBlock * bb) |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1172 | { |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1173 | |
| 1174 | const TargetInstrInfo & mii = target.getInstrInfo(); |
| 1175 | const TargetSchedInfo & msi = target.getSchedInfo(); |
| 1176 | |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1177 | int ResII; |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1178 | std::vector<std::pair<int,int>> resourceUsage; |
| 1179 | //pair<int resourceid, int resourceUsageTimes_in_the_whole_block> |
| 1180 | |
| 1181 | //FIXME: number of functional units the target machine can provide should be |
| 1182 | //get from Target here I temporary hardcode it |
| 1183 | |
| 1184 | for (BasicBlock::const_iterator I = bb->begin(), E = bb->end(); I != E; |
| 1185 | I++) { |
| 1186 | if (ModuloSchedDebugLevel >= ModuloSched_PrintScheduleProcess) { |
| 1187 | modSched_os << "machine instruction for llvm instruction( node " << |
| 1188 | getGraphNodeForInst(I)->getNodeId() << ")" << "\n"; |
| 1189 | modSched_os << "\t" << *I; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1190 | } |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1191 | MachineCodeForInstruction & tempMvec = |
| 1192 | MachineCodeForInstruction::get(I); |
| 1193 | if (ModuloSchedDebugLevel >= ModuloSched_PrintScheduleProcess) |
| 1194 | modSched_os << "size =" << tempMvec.size() << "\n"; |
| 1195 | for (unsigned i = 0; i < tempMvec.size(); i++) { |
| 1196 | MachineInstr *minstr = tempMvec[i]; |
| 1197 | |
| 1198 | unsigned minDelay = mii.minLatency(minstr->getOpCode()); |
| 1199 | InstrRUsage rUsage = msi.getInstrRUsage(minstr->getOpCode()); |
| 1200 | InstrClassRUsage classRUsage = |
| 1201 | msi.getClassRUsage(mii.getSchedClass(minstr->getOpCode())); |
| 1202 | unsigned totCycles = classRUsage.totCycles; |
| 1203 | |
| 1204 | std::vector<std::vector<resourceId_t>> resources =rUsage.resourcesByCycle; |
| 1205 | assert(totCycles == resources.size()); |
| 1206 | if (ModuloSchedDebugLevel >= ModuloSched_PrintScheduleProcess) |
| 1207 | modSched_os << "resources Usage for this Instr(totCycles=" << |
| 1208 | totCycles << ",mindLatency=" << mii.minLatency(minstr-> |
| 1209 | getOpCode()) << |
| 1210 | "): " << *minstr << "\n"; |
| 1211 | for (unsigned j = 0; j < resources.size(); j++) { |
| 1212 | if (ModuloSchedDebugLevel >= ModuloSched_PrintScheduleProcess) |
| 1213 | modSched_os << "cycle " << j << ": "; |
| 1214 | for (unsigned k = 0; k < resources[j].size(); k++) { |
| 1215 | if (ModuloSchedDebugLevel >= ModuloSched_PrintScheduleProcess) |
| 1216 | modSched_os << "\t" << resources[j][k]; |
| 1217 | addResourceUsage(resourceUsage, resources[j][k]); |
| 1218 | } |
| 1219 | if (ModuloSchedDebugLevel >= ModuloSched_PrintScheduleProcess) |
| 1220 | modSched_os << "\n"; |
| 1221 | } |
| 1222 | } |
| 1223 | } |
| 1224 | if (ModuloSchedDebugLevel >= ModuloSched_PrintScheduleProcess) |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1225 | this->dumpResourceUsage(resourceUsage); |
| 1226 | |
| 1227 | //compute ResII |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1228 | ResII = 0; |
| 1229 | int issueSlots = msi.maxNumIssueTotal; |
| 1230 | for (unsigned i = 0; i < resourceUsage.size(); i++) { |
| 1231 | int resourceNum = msi.getCPUResourceNum(resourceUsage[i].first); |
| 1232 | int useNum = resourceUsage[i].second; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1233 | double tempII; |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1234 | if (resourceNum <= issueSlots) |
| 1235 | tempII = ceil(1.0 * useNum / resourceNum); |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1236 | else |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1237 | tempII = ceil(1.0 * useNum / issueSlots); |
| 1238 | ResII = std::max((int) tempII, ResII); |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1239 | } |
| 1240 | return ResII; |
| 1241 | } |
| 1242 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1243 | ModuloSchedGraphSet::ModuloSchedGraphSet(const Function * function, |
| 1244 | const TargetMachine & target) |
| 1245 | : method(function) |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1246 | { |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1247 | buildGraphsForMethod(method, target); |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1248 | } |
| 1249 | |
| 1250 | |
| 1251 | ModuloSchedGraphSet::~ModuloSchedGraphSet() |
| 1252 | { |
| 1253 | //delete all the graphs |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1254 | for (iterator I = begin(), E = end(); I != E; ++I) |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1255 | delete *I; |
| 1256 | } |
| 1257 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1258 | void ModuloSchedGraphSet::dump() const |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1259 | { |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1260 | modSched_os << " ====== ModuloSched graphs for function `" << |
| 1261 | method->getName() << "' =========\n\n"; |
| 1262 | for (const_iterator I = begin(); I != end(); ++I) |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1263 | (*I)->dump(); |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1264 | |
| 1265 | modSched_os << "\n=========End graphs for funtion` " << method->getName() |
| 1266 | << "' ==========\n\n"; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1267 | } |
| 1268 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1269 | void ModuloSchedGraph::dump(const BasicBlock * bb) |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1270 | { |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1271 | modSched_os << "dumping basic block:"; |
| 1272 | modSched_os << (bb->hasName()? bb->getName() : "block") |
| 1273 | << " (" << bb << ")" << "\n"; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1274 | |
| 1275 | } |
| 1276 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1277 | void ModuloSchedGraph::dump(const BasicBlock * bb, std::ostream & os) |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1278 | { |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1279 | os << "dumping basic block:"; |
| 1280 | os << (bb->hasName()? bb->getName() : "block") |
| 1281 | << " (" << bb << ")" << "\n"; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1282 | } |
| 1283 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1284 | void ModuloSchedGraph::dump() const |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1285 | { |
| 1286 | modSched_os << " ModuloSchedGraph for basic Blocks:"; |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1287 | for (unsigned i = 0, N = bbVec.size(); i < N; i++) { |
| 1288 | modSched_os << (bbVec[i]->hasName()? bbVec[i]->getName() : "block") |
| 1289 | << " (" << bbVec[i] << ")" << ((i == N - 1) ? "" : ", "); |
| 1290 | } |
| 1291 | |
| 1292 | modSched_os << "\n\n Actual Root nodes : "; |
| 1293 | for (unsigned i = 0, N = graphRoot->outEdges.size(); i < N; i++) |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1294 | modSched_os << graphRoot->outEdges[i]->getSink()->getNodeId() |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1295 | << ((i == N - 1) ? "" : ", "); |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1296 | |
| 1297 | modSched_os << "\n Graph Nodes:\n"; |
| 1298 | //for (const_iterator I=begin(); I != end(); ++I) |
| 1299 | //modSched_os << "\n" << *I->second; |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1300 | unsigned numNodes = bbVec[0]->size(); |
| 1301 | for (unsigned i = 2; i < numNodes + 2; i++) { |
| 1302 | ModuloSchedGraphNode *node = getNode(i); |
| 1303 | modSched_os << "\n" << *node; |
| 1304 | } |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1305 | |
| 1306 | modSched_os << "\n"; |
| 1307 | } |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1308 | |
| 1309 | void ModuloSchedGraph::dumpNodeProperty() const |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1310 | { |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1311 | const BasicBlock *bb = bbVec[0]; |
| 1312 | unsigned numNodes = bb->size(); |
| 1313 | for (unsigned i = 2; i < numNodes + 2; i++) { |
| 1314 | ModuloSchedGraphNode *node = getNode(i); |
| 1315 | modSched_os << "NodeId " << node->getNodeId() << "\t"; |
| 1316 | modSched_os << "ASAP " << node->getASAP() << "\t"; |
| 1317 | modSched_os << "ALAP " << node->getALAP() << "\t"; |
| 1318 | modSched_os << "mov " << node->getMov() << "\t"; |
| 1319 | modSched_os << "depth " << node->getDepth() << "\t"; |
| 1320 | modSched_os << "height " << node->getHeight() << "\t"; |
| 1321 | modSched_os << "\n"; |
| 1322 | } |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1323 | } |
| 1324 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1325 | void ModuloSchedGraphSet::buildGraphsForMethod(const Function * F, |
| 1326 | const TargetMachine & |
| 1327 | target) |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1328 | { |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1329 | for (Function::const_iterator BI = F->begin(); BI != F->end(); ++BI) |
| 1330 | addGraph(new ModuloSchedGraph(BI, target)); |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1331 | } |
| 1332 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1333 | std::ostream & operator<<(std::ostream & os, |
| 1334 | const ModuloSchedGraphNode & node) |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1335 | { |
| 1336 | os << std::string(8, ' ') |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1337 | << "Node " << node.nodeId << " : " |
| 1338 | << "latency = " << node.latency << "\n" << std::string(12, ' '); |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1339 | |
| 1340 | if (node.getInst() == NULL) |
| 1341 | os << "(Dummy node)\n"; |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame^] | 1342 | else { |
| 1343 | os << *node.getInst() << "\n" << std::string(12, ' '); |
| 1344 | os << node.inEdges.size() << " Incoming Edges:\n"; |
| 1345 | for (unsigned i = 0, N = node.inEdges.size(); i < N; i++) |
| 1346 | os << std::string(16, ' ') << *node.inEdges[i]; |
| 1347 | |
| 1348 | os << std::string(12, ' ') << node.outEdges.size() |
| 1349 | << " Outgoing Edges:\n"; |
| 1350 | for (unsigned i = 0, N = node.outEdges.size(); i < N; i++) |
| 1351 | os << std::string(16, ' ') << *node.outEdges[i]; |
| 1352 | } |
| 1353 | |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 1354 | |
| 1355 | return os; |
| 1356 | } |