blob: 8aaaa2b6b5cfce483700abb63fa71230d15b3532 [file] [log] [blame]
Tanya Lattner4f839cc2003-08-28 17:12:14 +00001//===- ModuloSchedGraph.cpp - Modulo Scheduling Graph and Set -*- C++ -*---===//
2//
John Criswellb576c942003-10-20 19:43:21 +00003// 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 Lattner4f839cc2003-08-28 17:12:14 +000010// Description here
Misha Brukman8baa01c2003-04-09 21:51:34 +000011//===----------------------------------------------------------------------===//
12
Misha Brukman8baa01c2003-04-09 21:51:34 +000013#include "ModuloSchedGraph.h"
Tanya Lattner4f839cc2003-08-28 17:12:14 +000014#include "llvm/Type.h"
Guochun Shif1c154f2003-03-27 17:57:44 +000015
Brian Gaeked0fde302003-11-11 22:41:34 +000016namespace llvm {
17
Tanya Lattner4f839cc2003-08-28 17:12:14 +000018ModuloSchedGraphNode::ModuloSchedGraphNode(unsigned id, int index,
19 const Instruction *inst,
20 const TargetMachine &targ)
21 : SchedGraphNodeCommon(id, index), Inst(inst), Target(targ) {
Guochun Shif1c154f2003-03-27 17:57:44 +000022}
Misha Brukman8baa01c2003-04-09 21:51:34 +000023
Tanya Lattner4f839cc2003-08-28 17:12:14 +000024void ModuloSchedGraphNode::print(std::ostream &os) const {
25 os << "Modulo Scheduling Node\n";
Guochun Shif1c154f2003-03-27 17:57:44 +000026}
27
Tanya Lattner4f839cc2003-08-28 17:12:14 +000028ModuloSchedGraph::ModuloSchedGraph(const BasicBlock *bb, const TargetMachine &targ)
29 : SchedGraphCommon(), BB(bb), Target(targ) {
Guochun Shi8f1d4ab2003-06-08 23:16:07 +000030
Tanya Lattner4f839cc2003-08-28 17:12:14 +000031 assert(BB != NULL && "Basic Block is null");
Guochun Shi8f1d4ab2003-06-08 23:16:07 +000032
Tanya Lattner4f839cc2003-08-28 17:12:14 +000033 //Builds nodes from each instruction in the basic block
34 buildNodesForBB();
35
36}
37
38void 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
51void ModuloSchedGraph::addNode(const Instruction *I,
52 ModuloSchedGraphNode *node) {
53 assert(node!= NULL && "New ModuloSchedGraphNode is null");
54 GraphMap[I] = node;
55}
56
57void 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 Shi8f1d4ab2003-06-08 23:16:07 +000067
Tanya Lattner4f839cc2003-08-28 17:12:14 +000068 //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 Lattner3b6b6ba2003-08-28 17:17:59 +000083 SchedGraphEdge *trueDep = new SchedGraphEdge(&*Src->second ,&*Sink->second,
84 &*I, SchedGraphEdge::TrueDep,
Tanya Lattner4f839cc2003-08-28 17:12:14 +000085 Src->second->getLatency());
86 //Determine the iteration difference
87 //FIXME: Will this ever happen?
88 }
89 }
Misha Brukman8baa01c2003-04-09 21:51:34 +000090 }
Guochun Shif1c154f2003-03-27 17:57:44 +000091 }
Guochun Shif3252612003-06-10 19:09:00 +000092
Guochun Shif1c154f2003-03-27 17:57:44 +000093 }
Guochun Shif3252612003-06-10 19:09:00 +000094
Guochun Shif3252612003-06-10 19:09:00 +000095
Guochun Shif1c154f2003-03-27 17:57:44 +000096}
Guochun Shif1c154f2003-03-27 17:57:44 +000097
Tanya Lattner4f839cc2003-08-28 17:12:14 +000098void ModuloSchedGraph::ASAP() {
Guochun Shif3252612003-06-10 19:09:00 +000099
Misha Brukman8baa01c2003-04-09 21:51:34 +0000100
Guochun Shif1c154f2003-03-27 17:57:44 +0000101}
102
Tanya Lattner4f839cc2003-08-28 17:12:14 +0000103void ModuloSchedGraph::ALAP() {
Guochun Shif1c154f2003-03-27 17:57:44 +0000104
105
Guochun Shif1c154f2003-03-27 17:57:44 +0000106}
Misha Brukman8baa01c2003-04-09 21:51:34 +0000107
Tanya Lattner4f839cc2003-08-28 17:12:14 +0000108void ModuloSchedGraph::MOB() {
Guochun Shi8f1d4ab2003-06-08 23:16:07 +0000109
110}
111
Tanya Lattner4f839cc2003-08-28 17:12:14 +0000112void ModuloSchedGraph::ComputeDepth() {
Guochun Shif3252612003-06-10 19:09:00 +0000113
Tanya Lattner4f839cc2003-08-28 17:12:14 +0000114}
115
116void ModuloSchedGraph::ComputeHeight() {
117
118}
119
120void ModuloSchedGraphSet::addGraph(ModuloSchedGraph *graph) {
121 assert(graph!=NULL && "Graph for BasicBlock is null");
122 Graphs.push_back(graph);
123}
124
125
126ModuloSchedGraphSet::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 Shi8f1d4ab2003-06-08 23:16:07 +0000134
135ModuloSchedGraphSet::~ModuloSchedGraphSet(){
136
137 //delete all the graphs
Guochun Shi8f1d4ab2003-06-08 23:16:07 +0000138}
139
Brian Gaeked0fde302003-11-11 22:41:34 +0000140} // End llvm namespace