blob: 7c0e80afe43888eecf1f1529088facb0648cf018 [file] [log] [blame]
Dan Gohman343f0c02008-11-19 23:18:57 +00001//==- 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 Gohman79ce2762009-01-15 19:20:50 +000019#include "llvm/Target/TargetRegisterInfo.h"
Dan Gohman343f0c02008-11-19 23:18:57 +000020
21namespace llvm {
Dan Gohman3f237442008-12-16 03:25:46 +000022 class MachineLoopInfo;
23 class MachineDominatorTree;
24
Dan Gohman343f0c02008-11-19 23:18:57 +000025 class ScheduleDAGInstrs : public ScheduleDAG {
Dan Gohman3f237442008-12-16 03:25:46 +000026 const MachineLoopInfo &MLI;
27 const MachineDominatorTree &MDT;
28
Dan Gohman79ce2762009-01-15 19:20:50 +000029 /// 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 Gohman343f0c02008-11-19 23:18:57 +000041 public:
Dan Gohman79ce2762009-01-15 19:20:50 +000042 explicit ScheduleDAGInstrs(MachineFunction &mf,
43 const MachineLoopInfo &mli,
44 const MachineDominatorTree &mdt);
Dan Gohman343f0c02008-11-19 23:18:57 +000045
46 virtual ~ScheduleDAGInstrs() {}
47
48 /// NewSUnit - Creates a new SUnit and return a ptr to it.
49 ///
50 SUnit *NewSUnit(MachineInstr *MI) {
Dan Gohman361c31d2008-12-22 21:08:08 +000051#ifndef NDEBUG
Duncan Sandsf90fb342009-01-20 09:05:19 +000052 const SUnit *Addr = SUnits.empty() ? 0 : &SUnits[0];
Dan Gohman361c31d2008-12-22 21:08:08 +000053#endif
Dan Gohman343f0c02008-11-19 23:18:57 +000054 SUnits.push_back(SUnit(MI, (unsigned)SUnits.size()));
Duncan Sandsf90fb342009-01-20 09:05:19 +000055 assert((Addr == 0 || Addr == &SUnits[0]) &&
56 "SUnits std::vector reallocated on the fly!");
Dan Gohman343f0c02008-11-19 23:18:57 +000057 SUnits.back().OrigNode = &SUnits.back();
58 return &SUnits.back();
59 }
60
Dan Gohmanc9a5b9e2008-12-23 18:36:58 +000061 /// BuildSchedGraph - Build SUnits from the MachineBasicBlock that we are
Dan Gohman343f0c02008-11-19 23:18:57 +000062 /// input.
Dan Gohmanc9a5b9e2008-12-23 18:36:58 +000063 virtual void BuildSchedGraph();
Dan Gohman343f0c02008-11-19 23:18:57 +000064
Dan Gohmanc8c28272008-11-21 00:12:10 +000065 /// ComputeLatency - Compute node latency.
66 ///
67 virtual void ComputeLatency(SUnit *SU);
68
Dan Gohman343f0c02008-11-19 23:18:57 +000069 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