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