If a vector is empty, you're not allowed to access any
[oota-llvm.git] / include / llvm / CodeGen / ScheduleDAGInstrs.h
1 //==- llvm/CodeGen/ScheduleDAGInstrs.h - MachineInstr Scheduling -*- C++ -*-==//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements the ScheduleDAGInstrs class, which implements
11 // scheduling for a MachineInstr-based dependency graph.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_CODEGEN_SCHEDULEDAGINSTRS_H
16 #define LLVM_CODEGEN_SCHEDULEDAGINSTRS_H
17
18 #include "llvm/CodeGen/ScheduleDAG.h"
19 #include "llvm/Target/TargetRegisterInfo.h"
20
21 namespace llvm {
22   class MachineLoopInfo;
23   class MachineDominatorTree;
24
25   class ScheduleDAGInstrs : public ScheduleDAG {
26     const MachineLoopInfo &MLI;
27     const MachineDominatorTree &MDT;
28
29     /// Defs, Uses - Remember where defs and uses of each physical register
30     /// are as we iterate upward through the instructions. This is allocated
31     /// here instead of inside BuildSchedGraph to avoid the need for it to be
32     /// initialized and destructed for each block.
33     std::vector<SUnit *> Defs[TargetRegisterInfo::FirstVirtualRegister];
34     std::vector<SUnit *> Uses[TargetRegisterInfo::FirstVirtualRegister];
35
36     /// PendingLoads - Remember where unknown loads are after the most recent
37     /// unknown store, as we iterate. As with Defs and Uses, this is here
38     /// to minimize construction/destruction.
39     std::vector<SUnit *> PendingLoads;
40
41   public:
42     explicit ScheduleDAGInstrs(MachineFunction &mf,
43                                const MachineLoopInfo &mli,
44                                const MachineDominatorTree &mdt);
45
46     virtual ~ScheduleDAGInstrs() {}
47
48     /// NewSUnit - Creates a new SUnit and return a ptr to it.
49     ///
50     SUnit *NewSUnit(MachineInstr *MI) {
51 #ifndef NDEBUG
52       const SUnit *Addr = SUnits.empty() ? 0 : &SUnits[0];
53 #endif
54       SUnits.push_back(SUnit(MI, (unsigned)SUnits.size()));
55       assert((Addr == 0 || Addr == &SUnits[0]) &&
56              "SUnits std::vector reallocated on the fly!");
57       SUnits.back().OrigNode = &SUnits.back();
58       return &SUnits.back();
59     }
60
61     /// BuildSchedGraph - Build SUnits from the MachineBasicBlock that we are
62     /// input.
63     virtual void BuildSchedGraph();
64
65     /// ComputeLatency - Compute node latency.
66     ///
67     virtual void ComputeLatency(SUnit *SU);
68
69     virtual MachineBasicBlock *EmitSchedule();
70
71     /// Schedule - Order nodes according to selected style, filling
72     /// in the Sequence member.
73     ///
74     virtual void Schedule() = 0;
75
76     virtual void dumpNode(const SUnit *SU) const;
77
78     virtual std::string getGraphNodeLabel(const SUnit *SU) const;
79   };
80 }
81
82 #endif