blob: f9a6e395a454fbf81cef35beaae550e0bb81372f [file] [log] [blame]
Tom Stellardcb6ba622016-04-30 00:23:06 +00001//===-- GCNHazardRecognizers.h - GCN Hazard Recognizers ---------*- 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 defines hazard recognizers for scheduling on GCN processors.
11//
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_LIB_TARGET_AMDGPUHAZARDRECOGNIZERS_H
15#define LLVM_LIB_TARGET_AMDGPUHAZARDRECOGNIZERS_H
16
Matt Arsenault03c67d12017-11-17 04:18:24 +000017#include "llvm/ADT/BitVector.h"
Benjamin Kramerd3f4c052016-06-12 16:13:55 +000018#include "llvm/ADT/STLExtras.h"
Tom Stellardcb6ba622016-04-30 00:23:06 +000019#include "llvm/CodeGen/ScheduleHazardRecognizer.h"
Tom Stellardcb6ba622016-04-30 00:23:06 +000020#include <list>
21
22namespace llvm {
23
24class MachineFunction;
25class MachineInstr;
Mark Searlesd29f24a2017-12-07 20:34:25 +000026class MachineOperand;
27class MachineRegisterInfo;
Tom Stellardcb6ba622016-04-30 00:23:06 +000028class ScheduleDAG;
29class SIInstrInfo;
Matt Arsenault03c67d12017-11-17 04:18:24 +000030class SIRegisterInfo;
Matt Arsenault43e92fe2016-06-24 06:30:11 +000031class SISubtarget;
Tom Stellardcb6ba622016-04-30 00:23:06 +000032
33class GCNHazardRecognizer final : public ScheduleHazardRecognizer {
Matt Arsenault43e92fe2016-06-24 06:30:11 +000034 // This variable stores the instruction that has been emitted this cycle. It
35 // will be added to EmittedInstrs, when AdvanceCycle() or RecedeCycle() is
Tom Stellardcb6ba622016-04-30 00:23:06 +000036 // called.
37 MachineInstr *CurrCycleInstr;
38 std::list<MachineInstr*> EmittedInstrs;
39 const MachineFunction &MF;
Matt Arsenault43e92fe2016-06-24 06:30:11 +000040 const SISubtarget &ST;
Matt Arsenault59ece952017-03-17 21:36:28 +000041 const SIInstrInfo &TII;
Matt Arsenault03c67d12017-11-17 04:18:24 +000042 const SIRegisterInfo &TRI;
43
44 /// RegUnits of uses in the current soft memory clause.
45 BitVector ClauseUses;
46
47 /// RegUnits of defs in the current soft memory clause.
48 BitVector ClauseDefs;
49
50 void resetClause() {
51 ClauseUses.reset();
52 ClauseDefs.reset();
53 }
54
55 void addClauseInst(const MachineInstr &MI);
Tom Stellardcb6ba622016-04-30 00:23:06 +000056
Tom Stellardb133fbb2016-10-27 23:05:31 +000057 int getWaitStatesSince(function_ref<bool(MachineInstr *)> IsHazard);
Tom Stellardcb6ba622016-04-30 00:23:06 +000058 int getWaitStatesSinceDef(unsigned Reg,
Benjamin Kramerd3f4c052016-06-12 16:13:55 +000059 function_ref<bool(MachineInstr *)> IsHazardDef =
60 [](MachineInstr *) { return true; });
Tom Stellard961811c2016-10-15 00:58:14 +000061 int getWaitStatesSinceSetReg(function_ref<bool(MachineInstr *)> IsHazard);
Tom Stellardcb6ba622016-04-30 00:23:06 +000062
Matt Arsenaulta41351e2017-11-17 21:35:32 +000063 int checkSoftClauseHazards(MachineInstr *SMEM);
Tom Stellardcb6ba622016-04-30 00:23:06 +000064 int checkSMRDHazards(MachineInstr *SMRD);
65 int checkVMEMHazards(MachineInstr* VMEM);
Tom Stellarda27007e2016-05-02 16:23:09 +000066 int checkDPPHazards(MachineInstr *DPP);
Tom Stellard5ab61542016-10-07 23:42:48 +000067 int checkDivFMasHazards(MachineInstr *DivFMas);
Tom Stellard961811c2016-10-15 00:58:14 +000068 int checkGetRegHazards(MachineInstr *GetRegInstr);
Tom Stellard30d30822016-10-27 20:39:09 +000069 int checkSetRegHazards(MachineInstr *SetRegInstr);
Tom Stellardb133fbb2016-10-27 23:05:31 +000070 int createsVALUHazard(const MachineInstr &MI);
71 int checkVALUHazards(MachineInstr *VALU);
Mark Searlesd29f24a2017-12-07 20:34:25 +000072 int checkVALUHazardsHelper(const MachineOperand &Def, const MachineRegisterInfo &MRI);
Tom Stellard04051b52016-10-27 23:42:29 +000073 int checkRWLaneHazards(MachineInstr *RWLane);
Tom Stellardaea899e2016-10-27 23:50:21 +000074 int checkRFEHazards(MachineInstr *RFE);
Mark Searlesd29f24a2017-12-07 20:34:25 +000075 int checkInlineAsmHazards(MachineInstr *IA);
Matt Arsenaulte823d922017-02-18 18:29:53 +000076 int checkAnyInstHazards(MachineInstr *MI);
77 int checkReadM0Hazards(MachineInstr *SMovRel);
Tom Stellardcb6ba622016-04-30 00:23:06 +000078public:
79 GCNHazardRecognizer(const MachineFunction &MF);
80 // We can only issue one instruction per cycle.
81 bool atIssueLimit() const override { return true; }
82 void EmitInstruction(SUnit *SU) override;
83 void EmitInstruction(MachineInstr *MI) override;
84 HazardType getHazardType(SUnit *SU, int Stalls) override;
85 void EmitNoop() override;
86 unsigned PreEmitNoops(SUnit *SU) override;
87 unsigned PreEmitNoops(MachineInstr *) override;
88 void AdvanceCycle() override;
89 void RecedeCycle() override;
90};
91
92} // end namespace llvm
93
94#endif //LLVM_LIB_TARGET_AMDGPUHAZARDRECOGNIZERS_H