Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 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" |
Dan Gohman | 79ce276 | 2009-01-15 19:20:50 +0000 | [diff] [blame] | 19 | #include "llvm/Target/TargetRegisterInfo.h" |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 20 | |
| 21 | namespace llvm { |
Dan Gohman | 3f23744 | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 22 | class MachineLoopInfo; |
| 23 | class MachineDominatorTree; |
| 24 | |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 25 | class ScheduleDAGInstrs : public ScheduleDAG { |
Dan Gohman | 3f23744 | 2008-12-16 03:25:46 +0000 | [diff] [blame] | 26 | const MachineLoopInfo &MLI; |
| 27 | const MachineDominatorTree &MDT; |
| 28 | |
Dan Gohman | 79ce276 | 2009-01-15 19:20:50 +0000 | [diff] [blame] | 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 | |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 41 | public: |
Dan Gohman | 79ce276 | 2009-01-15 19:20:50 +0000 | [diff] [blame] | 42 | explicit ScheduleDAGInstrs(MachineFunction &mf, |
| 43 | const MachineLoopInfo &mli, |
| 44 | const MachineDominatorTree &mdt); |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 45 | |
| 46 | virtual ~ScheduleDAGInstrs() {} |
| 47 | |
| 48 | /// NewSUnit - Creates a new SUnit and return a ptr to it. |
| 49 | /// |
| 50 | SUnit *NewSUnit(MachineInstr *MI) { |
Dan Gohman | 361c31d | 2008-12-22 21:08:08 +0000 | [diff] [blame] | 51 | #ifndef NDEBUG |
Duncan Sands | f90fb34 | 2009-01-20 09:05:19 +0000 | [diff] [blame^] | 52 | const SUnit *Addr = SUnits.empty() ? 0 : &SUnits[0]; |
Dan Gohman | 361c31d | 2008-12-22 21:08:08 +0000 | [diff] [blame] | 53 | #endif |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 54 | SUnits.push_back(SUnit(MI, (unsigned)SUnits.size())); |
Duncan Sands | f90fb34 | 2009-01-20 09:05:19 +0000 | [diff] [blame^] | 55 | assert((Addr == 0 || Addr == &SUnits[0]) && |
| 56 | "SUnits std::vector reallocated on the fly!"); |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 57 | SUnits.back().OrigNode = &SUnits.back(); |
| 58 | return &SUnits.back(); |
| 59 | } |
| 60 | |
Dan Gohman | c9a5b9e | 2008-12-23 18:36:58 +0000 | [diff] [blame] | 61 | /// BuildSchedGraph - Build SUnits from the MachineBasicBlock that we are |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 62 | /// input. |
Dan Gohman | c9a5b9e | 2008-12-23 18:36:58 +0000 | [diff] [blame] | 63 | virtual void BuildSchedGraph(); |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 64 | |
Dan Gohman | c8c2827 | 2008-11-21 00:12:10 +0000 | [diff] [blame] | 65 | /// ComputeLatency - Compute node latency. |
| 66 | /// |
| 67 | virtual void ComputeLatency(SUnit *SU); |
| 68 | |
Dan Gohman | 343f0c0 | 2008-11-19 23:18:57 +0000 | [diff] [blame] | 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 |