Tom Stellard | cb6ba62 | 2016-04-30 00:23:06 +0000 | [diff] [blame] | 1 | //===-- 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 Arsenault | 03c67d1 | 2017-11-17 04:18:24 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/BitVector.h" |
Benjamin Kramer | d3f4c05 | 2016-06-12 16:13:55 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/STLExtras.h" |
Tom Stellard | cb6ba62 | 2016-04-30 00:23:06 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/ScheduleHazardRecognizer.h" |
Tom Stellard | cb6ba62 | 2016-04-30 00:23:06 +0000 | [diff] [blame] | 20 | #include <list> |
| 21 | |
| 22 | namespace llvm { |
| 23 | |
| 24 | class MachineFunction; |
| 25 | class MachineInstr; |
| 26 | class ScheduleDAG; |
| 27 | class SIInstrInfo; |
Matt Arsenault | 03c67d1 | 2017-11-17 04:18:24 +0000 | [diff] [blame] | 28 | class SIRegisterInfo; |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 29 | class SISubtarget; |
Tom Stellard | cb6ba62 | 2016-04-30 00:23:06 +0000 | [diff] [blame] | 30 | |
| 31 | class GCNHazardRecognizer final : public ScheduleHazardRecognizer { |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 32 | // This variable stores the instruction that has been emitted this cycle. It |
| 33 | // will be added to EmittedInstrs, when AdvanceCycle() or RecedeCycle() is |
Tom Stellard | cb6ba62 | 2016-04-30 00:23:06 +0000 | [diff] [blame] | 34 | // called. |
| 35 | MachineInstr *CurrCycleInstr; |
| 36 | std::list<MachineInstr*> EmittedInstrs; |
| 37 | const MachineFunction &MF; |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 38 | const SISubtarget &ST; |
Matt Arsenault | 59ece95 | 2017-03-17 21:36:28 +0000 | [diff] [blame] | 39 | const SIInstrInfo &TII; |
Matt Arsenault | 03c67d1 | 2017-11-17 04:18:24 +0000 | [diff] [blame] | 40 | const SIRegisterInfo &TRI; |
| 41 | |
| 42 | /// RegUnits of uses in the current soft memory clause. |
| 43 | BitVector ClauseUses; |
| 44 | |
| 45 | /// RegUnits of defs in the current soft memory clause. |
| 46 | BitVector ClauseDefs; |
| 47 | |
| 48 | void resetClause() { |
| 49 | ClauseUses.reset(); |
| 50 | ClauseDefs.reset(); |
| 51 | } |
| 52 | |
| 53 | void addClauseInst(const MachineInstr &MI); |
Tom Stellard | cb6ba62 | 2016-04-30 00:23:06 +0000 | [diff] [blame] | 54 | |
Tom Stellard | b133fbb | 2016-10-27 23:05:31 +0000 | [diff] [blame] | 55 | int getWaitStatesSince(function_ref<bool(MachineInstr *)> IsHazard); |
Tom Stellard | cb6ba62 | 2016-04-30 00:23:06 +0000 | [diff] [blame] | 56 | int getWaitStatesSinceDef(unsigned Reg, |
Benjamin Kramer | d3f4c05 | 2016-06-12 16:13:55 +0000 | [diff] [blame] | 57 | function_ref<bool(MachineInstr *)> IsHazardDef = |
| 58 | [](MachineInstr *) { return true; }); |
Tom Stellard | 961811c | 2016-10-15 00:58:14 +0000 | [diff] [blame] | 59 | int getWaitStatesSinceSetReg(function_ref<bool(MachineInstr *)> IsHazard); |
Tom Stellard | cb6ba62 | 2016-04-30 00:23:06 +0000 | [diff] [blame] | 60 | |
Matt Arsenault | a41351e | 2017-11-17 21:35:32 +0000 | [diff] [blame] | 61 | int checkSoftClauseHazards(MachineInstr *SMEM); |
Tom Stellard | cb6ba62 | 2016-04-30 00:23:06 +0000 | [diff] [blame] | 62 | int checkSMRDHazards(MachineInstr *SMRD); |
| 63 | int checkVMEMHazards(MachineInstr* VMEM); |
Tom Stellard | a27007e | 2016-05-02 16:23:09 +0000 | [diff] [blame] | 64 | int checkDPPHazards(MachineInstr *DPP); |
Tom Stellard | 5ab6154 | 2016-10-07 23:42:48 +0000 | [diff] [blame] | 65 | int checkDivFMasHazards(MachineInstr *DivFMas); |
Tom Stellard | 961811c | 2016-10-15 00:58:14 +0000 | [diff] [blame] | 66 | int checkGetRegHazards(MachineInstr *GetRegInstr); |
Tom Stellard | 30d3082 | 2016-10-27 20:39:09 +0000 | [diff] [blame] | 67 | int checkSetRegHazards(MachineInstr *SetRegInstr); |
Tom Stellard | b133fbb | 2016-10-27 23:05:31 +0000 | [diff] [blame] | 68 | int createsVALUHazard(const MachineInstr &MI); |
| 69 | int checkVALUHazards(MachineInstr *VALU); |
Tom Stellard | 04051b5 | 2016-10-27 23:42:29 +0000 | [diff] [blame] | 70 | int checkRWLaneHazards(MachineInstr *RWLane); |
Tom Stellard | aea899e | 2016-10-27 23:50:21 +0000 | [diff] [blame] | 71 | int checkRFEHazards(MachineInstr *RFE); |
Matt Arsenault | e823d92 | 2017-02-18 18:29:53 +0000 | [diff] [blame] | 72 | int checkAnyInstHazards(MachineInstr *MI); |
| 73 | int checkReadM0Hazards(MachineInstr *SMovRel); |
Tom Stellard | cb6ba62 | 2016-04-30 00:23:06 +0000 | [diff] [blame] | 74 | public: |
| 75 | GCNHazardRecognizer(const MachineFunction &MF); |
| 76 | // We can only issue one instruction per cycle. |
| 77 | bool atIssueLimit() const override { return true; } |
| 78 | void EmitInstruction(SUnit *SU) override; |
| 79 | void EmitInstruction(MachineInstr *MI) override; |
| 80 | HazardType getHazardType(SUnit *SU, int Stalls) override; |
| 81 | void EmitNoop() override; |
| 82 | unsigned PreEmitNoops(SUnit *SU) override; |
| 83 | unsigned PreEmitNoops(MachineInstr *) override; |
| 84 | void AdvanceCycle() override; |
| 85 | void RecedeCycle() override; |
| 86 | }; |
| 87 | |
| 88 | } // end namespace llvm |
| 89 | |
| 90 | #endif //LLVM_LIB_TARGET_AMDGPUHAZARDRECOGNIZERS_H |