Tanya Lattner | 4f839cc | 2003-08-28 17:12:14 +0000 | [diff] [blame] | 1 | //===- ModuloSchedGraph.cpp - Modulo Scheduling Graph and Set -*- C++ -*---===// |
| 2 | // |
| 3 | // Description here |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame] | 4 | //===----------------------------------------------------------------------===// |
| 5 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame] | 6 | #include "ModuloSchedGraph.h" |
Tanya Lattner | 4f839cc | 2003-08-28 17:12:14 +0000 | [diff] [blame] | 7 | #include "llvm/Type.h" |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 8 | |
Tanya Lattner | 4f839cc | 2003-08-28 17:12:14 +0000 | [diff] [blame] | 9 | ModuloSchedGraphNode::ModuloSchedGraphNode(unsigned id, int index, |
| 10 | const Instruction *inst, |
| 11 | const TargetMachine &targ) |
| 12 | : SchedGraphNodeCommon(id, index), Inst(inst), Target(targ) { |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 13 | } |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame] | 14 | |
Tanya Lattner | 4f839cc | 2003-08-28 17:12:14 +0000 | [diff] [blame] | 15 | void ModuloSchedGraphNode::print(std::ostream &os) const { |
| 16 | os << "Modulo Scheduling Node\n"; |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 17 | } |
| 18 | |
Tanya Lattner | 4f839cc | 2003-08-28 17:12:14 +0000 | [diff] [blame] | 19 | ModuloSchedGraph::ModuloSchedGraph(const BasicBlock *bb, const TargetMachine &targ) |
| 20 | : SchedGraphCommon(), BB(bb), Target(targ) { |
Guochun Shi | 8f1d4ab | 2003-06-08 23:16:07 +0000 | [diff] [blame] | 21 | |
Tanya Lattner | 4f839cc | 2003-08-28 17:12:14 +0000 | [diff] [blame] | 22 | assert(BB != NULL && "Basic Block is null"); |
Guochun Shi | 8f1d4ab | 2003-06-08 23:16:07 +0000 | [diff] [blame] | 23 | |
Tanya Lattner | 4f839cc | 2003-08-28 17:12:14 +0000 | [diff] [blame] | 24 | //Builds nodes from each instruction in the basic block |
| 25 | buildNodesForBB(); |
| 26 | |
| 27 | } |
| 28 | |
| 29 | void ModuloSchedGraph::buildNodesForBB() { |
| 30 | int count = 0; |
| 31 | for (BasicBlock::const_iterator i = BB->begin(), e = BB->end(); i != e; ++i) { |
| 32 | addNode(i,new ModuloSchedGraphNode(size(), count, i, Target)); |
| 33 | count++; |
| 34 | } |
| 35 | |
| 36 | //Get machine instruction(s) for the llvm instruction |
| 37 | //MachineCodeForInstruction &MC = MachineCodeForInstruction::get(Node->first); |
| 38 | |
| 39 | |
| 40 | } |
| 41 | |
| 42 | void ModuloSchedGraph::addNode(const Instruction *I, |
| 43 | ModuloSchedGraphNode *node) { |
| 44 | assert(node!= NULL && "New ModuloSchedGraphNode is null"); |
| 45 | GraphMap[I] = node; |
| 46 | } |
| 47 | |
| 48 | void ModuloSchedGraph::addDepEdges() { |
| 49 | |
| 50 | //Get Machine target information for calculating delay |
| 51 | const TargetInstrInfo &MTI = Target.getInstrInfo(); |
| 52 | |
| 53 | //Loop over instruction in BB and gather dependencies |
| 54 | for(BasicBlock::const_iterator I = BB->begin(), E = BB->end(); I != E; ++I) { |
| 55 | |
| 56 | //Ignore instructions of the void type |
| 57 | if(I->getType() != Type::VoidTy) { |
Guochun Shi | 8f1d4ab | 2003-06-08 23:16:07 +0000 | [diff] [blame] | 58 | |
Tanya Lattner | 4f839cc | 2003-08-28 17:12:14 +0000 | [diff] [blame] | 59 | //Iterate over def-use chain and add true dependencies |
| 60 | for (Value::use_const_iterator U = I->use_begin(), e = I->use_end(); U != e; |
| 61 | ++U) { |
| 62 | if (Instruction *Inst = dyn_cast<Instruction>(*U)) { |
| 63 | //Check if a node already exists for this instruction |
| 64 | ModuloSchedGraph::iterator Sink = find(Inst); |
| 65 | |
| 66 | //If the instruction is in our graph, add appropriate edges |
| 67 | if(Sink->second != NULL) { |
| 68 | //assert if self loop |
| 69 | assert(&*I == Sink->first && "Use edge to itself!"); |
| 70 | |
| 71 | //Create edge and set delay equal to node latency |
| 72 | //FIXME: Is it safe to do this? |
| 73 | ModuloSchedGraph::iterator Src = find(I); |
Tanya Lattner | 3b6b6ba | 2003-08-28 17:17:59 +0000 | [diff] [blame] | 74 | SchedGraphEdge *trueDep = new SchedGraphEdge(&*Src->second ,&*Sink->second, |
| 75 | &*I, SchedGraphEdge::TrueDep, |
Tanya Lattner | 4f839cc | 2003-08-28 17:12:14 +0000 | [diff] [blame] | 76 | Src->second->getLatency()); |
| 77 | //Determine the iteration difference |
| 78 | //FIXME: Will this ever happen? |
| 79 | } |
| 80 | } |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame] | 81 | } |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 82 | } |
Guochun Shi | f325261 | 2003-06-10 19:09:00 +0000 | [diff] [blame] | 83 | |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 84 | } |
Guochun Shi | f325261 | 2003-06-10 19:09:00 +0000 | [diff] [blame] | 85 | |
Guochun Shi | f325261 | 2003-06-10 19:09:00 +0000 | [diff] [blame] | 86 | |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 87 | } |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 88 | |
Tanya Lattner | 4f839cc | 2003-08-28 17:12:14 +0000 | [diff] [blame] | 89 | void ModuloSchedGraph::ASAP() { |
Guochun Shi | f325261 | 2003-06-10 19:09:00 +0000 | [diff] [blame] | 90 | |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame] | 91 | |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Tanya Lattner | 4f839cc | 2003-08-28 17:12:14 +0000 | [diff] [blame] | 94 | void ModuloSchedGraph::ALAP() { |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 95 | |
| 96 | |
Guochun Shi | f1c154f | 2003-03-27 17:57:44 +0000 | [diff] [blame] | 97 | } |
Misha Brukman | 8baa01c | 2003-04-09 21:51:34 +0000 | [diff] [blame] | 98 | |
Tanya Lattner | 4f839cc | 2003-08-28 17:12:14 +0000 | [diff] [blame] | 99 | void ModuloSchedGraph::MOB() { |
Guochun Shi | 8f1d4ab | 2003-06-08 23:16:07 +0000 | [diff] [blame] | 100 | |
| 101 | } |
| 102 | |
Tanya Lattner | 4f839cc | 2003-08-28 17:12:14 +0000 | [diff] [blame] | 103 | void ModuloSchedGraph::ComputeDepth() { |
Guochun Shi | f325261 | 2003-06-10 19:09:00 +0000 | [diff] [blame] | 104 | |
Tanya Lattner | 4f839cc | 2003-08-28 17:12:14 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | void ModuloSchedGraph::ComputeHeight() { |
| 108 | |
| 109 | } |
| 110 | |
| 111 | void ModuloSchedGraphSet::addGraph(ModuloSchedGraph *graph) { |
| 112 | assert(graph!=NULL && "Graph for BasicBlock is null"); |
| 113 | Graphs.push_back(graph); |
| 114 | } |
| 115 | |
| 116 | |
| 117 | ModuloSchedGraphSet::ModuloSchedGraphSet(const Function *F, |
| 118 | const TargetMachine &targ) |
| 119 | : function(F) { |
| 120 | |
| 121 | //Create graph for each BB in this function |
| 122 | for (Function::const_iterator BI = F->begin(); BI != F->end(); ++BI) |
| 123 | addGraph(new ModuloSchedGraph(BI, targ)); |
| 124 | } |
Guochun Shi | 8f1d4ab | 2003-06-08 23:16:07 +0000 | [diff] [blame] | 125 | |
| 126 | ModuloSchedGraphSet::~ModuloSchedGraphSet(){ |
| 127 | |
| 128 | //delete all the graphs |
Guochun Shi | 8f1d4ab | 2003-06-08 23:16:07 +0000 | [diff] [blame] | 129 | } |
| 130 | |