blob: 34a37db8b650b12e560b136466400ef92359fa1f [file] [log] [blame]
Tanya Lattner642685a2004-05-26 06:27:36 +00001//===-- MSSchedule.h - Schedule ------- -------------------------*- C++ -*-===//
2//
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//
10// The schedule generated by a scheduling algorithm
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_MSSCHEDULE_H
15#define LLVM_MSSCHEDULE_H
16
17#include "MSchedGraph.h"
18#include <vector>
Tanya Lattner13417b52005-03-23 01:47:20 +000019#include <set>
Tanya Lattner642685a2004-05-26 06:27:36 +000020
21namespace llvm {
22
23 class MSSchedule {
24 std::map<int, std::vector<MSchedGraphNode*> > schedule;
25 unsigned numIssue;
Misha Brukmanb4402432005-04-21 23:30:14 +000026
Tanya Lattner642685a2004-05-26 06:27:36 +000027 //Internal map to keep track of explicit resources
28 std::map<int, std::map<int, int> > resourceNumPerCycle;
29
30 //Check if all resources are free
Jeff Cohen33a030e2005-07-27 05:53:44 +000031 bool resourcesFree(MSchedGraphNode*, int, int II);
Tanya Lattner8bf63742005-06-17 04:00:57 +000032 bool resourceAvailable(int resourceNum, int cycle);
33 void useResource(int resourceNum, int cycle);
Tanya Lattner642685a2004-05-26 06:27:36 +000034
35 //Resulting kernel
Tanya Lattner13417b52005-03-23 01:47:20 +000036 std::vector<std::pair<MachineInstr*, int> > kernel;
Tanya Lattner642685a2004-05-26 06:27:36 +000037
Tanya Lattnerdbac0cb2004-10-10 22:44:35 +000038 //Max stage count
39 int maxStage;
40
Tanya Lattner341828e2004-11-28 23:36:15 +000041 //add at the right spot in the schedule
42 void addToSchedule(int, MSchedGraphNode*);
43
Tanya Lattner642685a2004-05-26 06:27:36 +000044 public:
45 MSSchedule(int num) : numIssue(num) {}
46 MSSchedule() : numIssue(4) {}
Tanya Lattner8bf63742005-06-17 04:00:57 +000047 bool insert(MSchedGraphNode *node, int cycle, int II);
Tanya Lattner642685a2004-05-26 06:27:36 +000048 int getStartCycle(MSchedGraphNode *node);
49 void clear() { schedule.clear(); resourceNumPerCycle.clear(); kernel.clear(); }
Tanya Lattner13417b52005-03-23 01:47:20 +000050 std::vector<std::pair<MachineInstr*, int> >* getKernel() { return &kernel; }
51 bool constructKernel(int II, std::vector<MSchedGraphNode*> &branches, std::map<const MachineInstr*, unsigned> &indVar);
Tanya Lattnerdbac0cb2004-10-10 22:44:35 +000052 int getMaxStage() { return maxStage; }
Tanya Lattner8bf63742005-06-17 04:00:57 +000053 bool defPreviousStage(Value *def, int stage);
Misha Brukmanb4402432005-04-21 23:30:14 +000054
Tanya Lattner642685a2004-05-26 06:27:36 +000055 //iterators
56 typedef std::map<int, std::vector<MSchedGraphNode*> >::iterator schedule_iterator;
57 typedef std::map<int, std::vector<MSchedGraphNode*> >::const_iterator schedule_const_iterator;
58 schedule_iterator begin() { return schedule.begin(); };
59 schedule_iterator end() { return schedule.end(); };
60 void print(std::ostream &os) const;
61
Tanya Lattner13417b52005-03-23 01:47:20 +000062 typedef std::vector<std::pair<MachineInstr*, int> >::iterator kernel_iterator;
63 typedef std::vector<std::pair<MachineInstr*, int> >::const_iterator kernel_const_iterator;
Tanya Lattner642685a2004-05-26 06:27:36 +000064 kernel_iterator kernel_begin() { return kernel.begin(); }
65 kernel_iterator kernel_end() { return kernel.end(); }
Misha Brukmanb4402432005-04-21 23:30:14 +000066
Tanya Lattner642685a2004-05-26 06:27:36 +000067 };
68
69}
70
71
72#endif