aboutsummaryrefslogtreecommitdiff
path: root/lib/Target/SparcV9/ModuloScheduling/MSSchedule.h
blob: d9f42a25b4afb53546f8cfdf4b24a6b6c18572d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
//===-- MSSchedule.h - Schedule ------- -------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file was developed by the LLVM research group and is distributed under
// the University of Illinois Open Source License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// The schedule generated by a scheduling algorithm
//
//===----------------------------------------------------------------------===//

#ifndef LLVM_MSSCHEDULE_H
#define LLVM_MSSCHEDULE_H

#include "MSchedGraph.h"
#include <vector>
#include <set>

namespace llvm {

  class MSSchedule {
    std::map<int, std::vector<MSchedGraphNode*> > schedule;
    unsigned numIssue;

    //Internal map to keep track of explicit resources
    std::map<int, std::map<int, int> > resourceNumPerCycle;

    //Check if all resources are free
    bool resourcesFree(MSchedGraphNode*, int);

    //Resulting kernel
    std::vector<std::pair<MachineInstr*, int> > kernel;

    //Max stage count
    int maxStage;

    //add at the right spot in the schedule
    void addToSchedule(int, MSchedGraphNode*);

  public:
    MSSchedule(int num) : numIssue(num) {}
    MSSchedule() : numIssue(4) {}
    bool insert(MSchedGraphNode *node, int cycle);
    int getStartCycle(MSchedGraphNode *node);
    void clear() { schedule.clear(); resourceNumPerCycle.clear(); kernel.clear(); }
    std::vector<std::pair<MachineInstr*, int> >* getKernel() { return &kernel; }
    bool constructKernel(int II, std::vector<MSchedGraphNode*> &branches, std::map<const MachineInstr*, unsigned> &indVar);
    int getMaxStage() { return maxStage; }


    //iterators
    typedef std::map<int, std::vector<MSchedGraphNode*> >::iterator schedule_iterator;
    typedef std::map<int, std::vector<MSchedGraphNode*> >::const_iterator schedule_const_iterator;
    schedule_iterator begin() { return schedule.begin(); };
    schedule_iterator end() { return schedule.end(); };
    void print(std::ostream &os) const;

    typedef std::vector<std::pair<MachineInstr*, int> >::iterator kernel_iterator;
    typedef std::vector<std::pair<MachineInstr*, int> >::const_iterator kernel_const_iterator;
    kernel_iterator kernel_begin() { return kernel.begin(); }
    kernel_iterator kernel_end() { return kernel.end(); }

  };

}


#endif