blob: 68b8ee39d5297a9e0ab8d0af2054d993efe4d569 [file] [log] [blame]
Tanya Lattner4f839cc2003-08-28 17:12:14 +00001//===- ModuloSchedGraph.cpp - Modulo Scheduling Graph and Set -*- C++ -*---===//
2//
3// Description here
Misha Brukman8baa01c2003-04-09 21:51:34 +00004//===----------------------------------------------------------------------===//
5
Misha Brukman8baa01c2003-04-09 21:51:34 +00006#include "ModuloSchedGraph.h"
Tanya Lattner4f839cc2003-08-28 17:12:14 +00007#include "llvm/Type.h"
Guochun Shif1c154f2003-03-27 17:57:44 +00008
Tanya Lattner4f839cc2003-08-28 17:12:14 +00009ModuloSchedGraphNode::ModuloSchedGraphNode(unsigned id, int index,
10 const Instruction *inst,
11 const TargetMachine &targ)
12 : SchedGraphNodeCommon(id, index), Inst(inst), Target(targ) {
Guochun Shif1c154f2003-03-27 17:57:44 +000013}
Misha Brukman8baa01c2003-04-09 21:51:34 +000014
Tanya Lattner4f839cc2003-08-28 17:12:14 +000015void ModuloSchedGraphNode::print(std::ostream &os) const {
16 os << "Modulo Scheduling Node\n";
Guochun Shif1c154f2003-03-27 17:57:44 +000017}
18
Tanya Lattner4f839cc2003-08-28 17:12:14 +000019ModuloSchedGraph::ModuloSchedGraph(const BasicBlock *bb, const TargetMachine &targ)
20 : SchedGraphCommon(), BB(bb), Target(targ) {
Guochun Shi8f1d4ab2003-06-08 23:16:07 +000021
Tanya Lattner4f839cc2003-08-28 17:12:14 +000022 assert(BB != NULL && "Basic Block is null");
Guochun Shi8f1d4ab2003-06-08 23:16:07 +000023
Tanya Lattner4f839cc2003-08-28 17:12:14 +000024 //Builds nodes from each instruction in the basic block
25 buildNodesForBB();
26
27}
28
29void 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
42void ModuloSchedGraph::addNode(const Instruction *I,
43 ModuloSchedGraphNode *node) {
44 assert(node!= NULL && "New ModuloSchedGraphNode is null");
45 GraphMap[I] = node;
46}
47
48void 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 Shi8f1d4ab2003-06-08 23:16:07 +000058
Tanya Lattner4f839cc2003-08-28 17:12:14 +000059 //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 Lattner3b6b6ba2003-08-28 17:17:59 +000074 SchedGraphEdge *trueDep = new SchedGraphEdge(&*Src->second ,&*Sink->second,
75 &*I, SchedGraphEdge::TrueDep,
Tanya Lattner4f839cc2003-08-28 17:12:14 +000076 Src->second->getLatency());
77 //Determine the iteration difference
78 //FIXME: Will this ever happen?
79 }
80 }
Misha Brukman8baa01c2003-04-09 21:51:34 +000081 }
Guochun Shif1c154f2003-03-27 17:57:44 +000082 }
Guochun Shif3252612003-06-10 19:09:00 +000083
Guochun Shif1c154f2003-03-27 17:57:44 +000084 }
Guochun Shif3252612003-06-10 19:09:00 +000085
Guochun Shif3252612003-06-10 19:09:00 +000086
Guochun Shif1c154f2003-03-27 17:57:44 +000087}
Guochun Shif1c154f2003-03-27 17:57:44 +000088
Tanya Lattner4f839cc2003-08-28 17:12:14 +000089void ModuloSchedGraph::ASAP() {
Guochun Shif3252612003-06-10 19:09:00 +000090
Misha Brukman8baa01c2003-04-09 21:51:34 +000091
Guochun Shif1c154f2003-03-27 17:57:44 +000092}
93
Tanya Lattner4f839cc2003-08-28 17:12:14 +000094void ModuloSchedGraph::ALAP() {
Guochun Shif1c154f2003-03-27 17:57:44 +000095
96
Guochun Shif1c154f2003-03-27 17:57:44 +000097}
Misha Brukman8baa01c2003-04-09 21:51:34 +000098
Tanya Lattner4f839cc2003-08-28 17:12:14 +000099void ModuloSchedGraph::MOB() {
Guochun Shi8f1d4ab2003-06-08 23:16:07 +0000100
101}
102
Tanya Lattner4f839cc2003-08-28 17:12:14 +0000103void ModuloSchedGraph::ComputeDepth() {
Guochun Shif3252612003-06-10 19:09:00 +0000104
Tanya Lattner4f839cc2003-08-28 17:12:14 +0000105}
106
107void ModuloSchedGraph::ComputeHeight() {
108
109}
110
111void ModuloSchedGraphSet::addGraph(ModuloSchedGraph *graph) {
112 assert(graph!=NULL && "Graph for BasicBlock is null");
113 Graphs.push_back(graph);
114}
115
116
117ModuloSchedGraphSet::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 Shi8f1d4ab2003-06-08 23:16:07 +0000125
126ModuloSchedGraphSet::~ModuloSchedGraphSet(){
127
128 //delete all the graphs
Guochun Shi8f1d4ab2003-06-08 23:16:07 +0000129}
130