blob: 6318c5ab46f3e9db8222cf0e42e0ae0eff2bf7cf [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
Tanya Lattner4f839cc2003-08-28 17:12:14 +000016ModuloSchedGraphNode::ModuloSchedGraphNode(unsigned id, int index,
17 const Instruction *inst,
18 const TargetMachine &targ)
19 : SchedGraphNodeCommon(id, index), Inst(inst), Target(targ) {
Guochun Shif1c154f2003-03-27 17:57:44 +000020}
Misha Brukman8baa01c2003-04-09 21:51:34 +000021
Tanya Lattner4f839cc2003-08-28 17:12:14 +000022void ModuloSchedGraphNode::print(std::ostream &os) const {
23 os << "Modulo Scheduling Node\n";
Guochun Shif1c154f2003-03-27 17:57:44 +000024}
25
Tanya Lattner4f839cc2003-08-28 17:12:14 +000026ModuloSchedGraph::ModuloSchedGraph(const BasicBlock *bb, const TargetMachine &targ)
27 : SchedGraphCommon(), BB(bb), Target(targ) {
Guochun Shi8f1d4ab2003-06-08 23:16:07 +000028
Tanya Lattner4f839cc2003-08-28 17:12:14 +000029 assert(BB != NULL && "Basic Block is null");
Guochun Shi8f1d4ab2003-06-08 23:16:07 +000030
Tanya Lattner4f839cc2003-08-28 17:12:14 +000031 //Builds nodes from each instruction in the basic block
32 buildNodesForBB();
33
34}
35
36void 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
49void ModuloSchedGraph::addNode(const Instruction *I,
50 ModuloSchedGraphNode *node) {
51 assert(node!= NULL && "New ModuloSchedGraphNode is null");
52 GraphMap[I] = node;
53}
54
55void 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 Shi8f1d4ab2003-06-08 23:16:07 +000065
Tanya Lattner4f839cc2003-08-28 17:12:14 +000066 //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 Lattner3b6b6ba2003-08-28 17:17:59 +000081 SchedGraphEdge *trueDep = new SchedGraphEdge(&*Src->second ,&*Sink->second,
82 &*I, SchedGraphEdge::TrueDep,
Tanya Lattner4f839cc2003-08-28 17:12:14 +000083 Src->second->getLatency());
84 //Determine the iteration difference
85 //FIXME: Will this ever happen?
86 }
87 }
Misha Brukman8baa01c2003-04-09 21:51:34 +000088 }
Guochun Shif1c154f2003-03-27 17:57:44 +000089 }
Guochun Shif3252612003-06-10 19:09:00 +000090
Guochun Shif1c154f2003-03-27 17:57:44 +000091 }
Guochun Shif3252612003-06-10 19:09:00 +000092
Guochun Shif3252612003-06-10 19:09:00 +000093
Guochun Shif1c154f2003-03-27 17:57:44 +000094}
Guochun Shif1c154f2003-03-27 17:57:44 +000095
Tanya Lattner4f839cc2003-08-28 17:12:14 +000096void ModuloSchedGraph::ASAP() {
Guochun Shif3252612003-06-10 19:09:00 +000097
Misha Brukman8baa01c2003-04-09 21:51:34 +000098
Guochun Shif1c154f2003-03-27 17:57:44 +000099}
100
Tanya Lattner4f839cc2003-08-28 17:12:14 +0000101void ModuloSchedGraph::ALAP() {
Guochun Shif1c154f2003-03-27 17:57:44 +0000102
103
Guochun Shif1c154f2003-03-27 17:57:44 +0000104}
Misha Brukman8baa01c2003-04-09 21:51:34 +0000105
Tanya Lattner4f839cc2003-08-28 17:12:14 +0000106void ModuloSchedGraph::MOB() {
Guochun Shi8f1d4ab2003-06-08 23:16:07 +0000107
108}
109
Tanya Lattner4f839cc2003-08-28 17:12:14 +0000110void ModuloSchedGraph::ComputeDepth() {
Guochun Shif3252612003-06-10 19:09:00 +0000111
Tanya Lattner4f839cc2003-08-28 17:12:14 +0000112}
113
114void ModuloSchedGraph::ComputeHeight() {
115
116}
117
118void ModuloSchedGraphSet::addGraph(ModuloSchedGraph *graph) {
119 assert(graph!=NULL && "Graph for BasicBlock is null");
120 Graphs.push_back(graph);
121}
122
123
124ModuloSchedGraphSet::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 Shi8f1d4ab2003-06-08 23:16:07 +0000132
133ModuloSchedGraphSet::~ModuloSchedGraphSet(){
134
135 //delete all the graphs
Guochun Shi8f1d4ab2003-06-08 23:16:07 +0000136}
137