blob: bc3eafe31f94de51235684ebadd5e03e82104a1d [file] [log] [blame]
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +00001//===-- R600MachineScheduler.h - R600 Scheduler Interface -*- 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/// \file
11/// \brief R600 Machine Scheduler interface
12//
13//===----------------------------------------------------------------------===//
14
Matt Arsenault6b6a2c32016-03-11 08:00:27 +000015#ifndef LLVM_LIB_TARGET_AMDGPU_R600MACHINESCHEDULER_H
16#define LLVM_LIB_TARGET_AMDGPU_R600MACHINESCHEDULER_H
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +000017
18#include "R600InstrInfo.h"
19#include "llvm/CodeGen/MachineScheduler.h"
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +000020
21using namespace llvm;
22
23namespace llvm {
24
Matt Arsenault6b6a2c32016-03-11 08:00:27 +000025class R600SchedStrategy final : public MachineSchedStrategy {
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +000026
Andrew Trickd7f890e2013-12-28 21:56:47 +000027 const ScheduleDAGMILive *DAG;
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +000028 const R600InstrInfo *TII;
29 const R600RegisterInfo *TRI;
30 MachineRegisterInfo *MRI;
31
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +000032 enum InstKind {
33 IDAlu,
34 IDFetch,
35 IDOther,
36 IDLast
37 };
38
39 enum AluKind {
40 AluAny,
41 AluT_X,
42 AluT_Y,
43 AluT_Z,
44 AluT_W,
45 AluT_XYZW,
Vincent Lejeune3d5118c2013-05-17 16:50:56 +000046 AluPredX,
Vincent Lejeune77a83522013-06-29 19:32:43 +000047 AluTrans,
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +000048 AluDiscarded, // LLVM Instructions that are going to be eliminated
49 AluLast
50 };
51
Vincent Lejeune4c81d4d2013-05-17 16:50:44 +000052 std::vector<SUnit *> Available[IDLast], Pending[IDLast];
53 std::vector<SUnit *> AvailableAlus[AluLast];
Vincent Lejeune4b5b8492013-06-05 20:27:35 +000054 std::vector<SUnit *> PhysicalRegCopy;
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +000055
56 InstKind CurInstKind;
57 int CurEmitted;
58 InstKind NextInstKind;
59
Vincent Lejeuned1a9d182013-06-07 23:30:34 +000060 unsigned AluInstCount;
61 unsigned FetchInstCount;
62
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +000063 int InstKindLimit[IDLast];
64
65 int OccupedSlotsMask;
66
67public:
68 R600SchedStrategy() :
Craig Toppere73658d2014-04-28 04:05:08 +000069 DAG(nullptr), TII(nullptr), TRI(nullptr), MRI(nullptr) {
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +000070 }
71
Craig Topper5656db42014-04-29 07:57:24 +000072 virtual ~R600SchedStrategy() {}
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +000073
Craig Topper5656db42014-04-29 07:57:24 +000074 void initialize(ScheduleDAGMI *dag) override;
75 SUnit *pickNode(bool &IsTopNode) override;
76 void schedNode(SUnit *SU, bool IsTopNode) override;
77 void releaseTopNode(SUnit *SU) override;
78 void releaseBottomNode(SUnit *SU) override;
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +000079
80private:
Vincent Lejeune0a22bc42013-03-14 15:50:45 +000081 std::vector<MachineInstr *> InstructionsGroupCandidate;
Vincent Lejeune7e2c8322013-09-04 19:53:46 +000082 bool VLIW5;
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +000083
84 int getInstKind(SUnit *SU);
85 bool regBelongsToClass(unsigned Reg, const TargetRegisterClass *RC) const;
86 AluKind getAluKind(SUnit *SU) const;
87 void LoadAlu();
Vincent Lejeuned1a9d182013-06-07 23:30:34 +000088 unsigned AvailablesAluCount() const;
Vincent Lejeune7e2c8322013-09-04 19:53:46 +000089 SUnit *AttemptFillSlot (unsigned Slot, bool AnyAlu);
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +000090 void PrepareNextSlot();
Vincent Lejeune7e2c8322013-09-04 19:53:46 +000091 SUnit *PopInst(std::vector<SUnit*> &Q, bool AnyALU);
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +000092
93 void AssignSlot(MachineInstr *MI, unsigned Slot);
94 SUnit* pickAlu();
95 SUnit* pickOther(int QID);
Vincent Lejeune4c81d4d2013-05-17 16:50:44 +000096 void MoveUnits(std::vector<SUnit *> &QSrc, std::vector<SUnit *> &QDst);
Vincent Lejeune68b6b6d2013-03-05 18:41:32 +000097};
98
99} // namespace llvm
100
101#endif /* R600MACHINESCHEDULER_H_ */