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