Tom Stellard | cb6ba62 | 2016-04-30 00:23:06 +0000 | [diff] [blame] | 1 | //===-- GCNHazardRecognizers.h - GCN Hazard Recognizers ---------*- C++ -*-===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Tom Stellard | cb6ba62 | 2016-04-30 00:23:06 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file defines hazard recognizers for scheduling on GCN processors. |
| 10 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #ifndef LLVM_LIB_TARGET_AMDGPUHAZARDRECOGNIZERS_H |
| 14 | #define LLVM_LIB_TARGET_AMDGPUHAZARDRECOGNIZERS_H |
| 15 | |
Matt Arsenault | 03c67d1 | 2017-11-17 04:18:24 +0000 | [diff] [blame] | 16 | #include "llvm/ADT/BitVector.h" |
Benjamin Kramer | d3f4c05 | 2016-06-12 16:13:55 +0000 | [diff] [blame] | 17 | #include "llvm/ADT/STLExtras.h" |
Tom Stellard | cb6ba62 | 2016-04-30 00:23:06 +0000 | [diff] [blame] | 18 | #include "llvm/CodeGen/ScheduleHazardRecognizer.h" |
Stanislav Mekhanoshin | 7d2019b | 2019-07-11 21:30:34 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/TargetSchedule.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; |
Mark Searles | d29f24a | 2017-12-07 20:34:25 +0000 | [diff] [blame] | 26 | class MachineOperand; |
| 27 | class MachineRegisterInfo; |
Tom Stellard | cb6ba62 | 2016-04-30 00:23:06 +0000 | [diff] [blame] | 28 | class ScheduleDAG; |
| 29 | class SIInstrInfo; |
Matt Arsenault | 03c67d1 | 2017-11-17 04:18:24 +0000 | [diff] [blame] | 30 | class SIRegisterInfo; |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 31 | class GCNSubtarget; |
Tom Stellard | cb6ba62 | 2016-04-30 00:23:06 +0000 | [diff] [blame] | 32 | |
| 33 | class GCNHazardRecognizer final : public ScheduleHazardRecognizer { |
Stanislav Mekhanoshin | f92ed69 | 2019-01-21 19:11:26 +0000 | [diff] [blame] | 34 | public: |
| 35 | typedef function_ref<bool(MachineInstr *)> IsHazardFn; |
| 36 | |
| 37 | private: |
| 38 | // Distinguish if we are called from scheduler or hazard recognizer |
| 39 | bool IsHazardRecognizerMode; |
| 40 | |
Matt Arsenault | 43e92fe | 2016-06-24 06:30:11 +0000 | [diff] [blame] | 41 | // This variable stores the instruction that has been emitted this cycle. It |
| 42 | // will be added to EmittedInstrs, when AdvanceCycle() or RecedeCycle() is |
Tom Stellard | cb6ba62 | 2016-04-30 00:23:06 +0000 | [diff] [blame] | 43 | // called. |
| 44 | MachineInstr *CurrCycleInstr; |
| 45 | std::list<MachineInstr*> EmittedInstrs; |
| 46 | const MachineFunction &MF; |
Tom Stellard | 5bfbae5 | 2018-07-11 20:59:01 +0000 | [diff] [blame] | 47 | const GCNSubtarget &ST; |
Matt Arsenault | 59ece95 | 2017-03-17 21:36:28 +0000 | [diff] [blame] | 48 | const SIInstrInfo &TII; |
Matt Arsenault | 03c67d1 | 2017-11-17 04:18:24 +0000 | [diff] [blame] | 49 | const SIRegisterInfo &TRI; |
Stanislav Mekhanoshin | 7d2019b | 2019-07-11 21:30:34 +0000 | [diff] [blame] | 50 | TargetSchedModel TSchedModel; |
Matt Arsenault | 03c67d1 | 2017-11-17 04:18:24 +0000 | [diff] [blame] | 51 | |
| 52 | /// RegUnits of uses in the current soft memory clause. |
| 53 | BitVector ClauseUses; |
| 54 | |
| 55 | /// RegUnits of defs in the current soft memory clause. |
| 56 | BitVector ClauseDefs; |
| 57 | |
| 58 | void resetClause() { |
| 59 | ClauseUses.reset(); |
| 60 | ClauseDefs.reset(); |
| 61 | } |
| 62 | |
| 63 | void addClauseInst(const MachineInstr &MI); |
Tom Stellard | cb6ba62 | 2016-04-30 00:23:06 +0000 | [diff] [blame] | 64 | |
Austin Kerbow | 8a3d3a9 | 2019-05-07 22:12:15 +0000 | [diff] [blame] | 65 | // Advance over a MachineInstr bundle. Look for hazards in the bundled |
| 66 | // instructions. |
| 67 | void processBundle(); |
| 68 | |
Stanislav Mekhanoshin | f92ed69 | 2019-01-21 19:11:26 +0000 | [diff] [blame] | 69 | int getWaitStatesSince(IsHazardFn IsHazard, int Limit); |
| 70 | int getWaitStatesSinceDef(unsigned Reg, IsHazardFn IsHazardDef, int Limit); |
| 71 | int getWaitStatesSinceSetReg(IsHazardFn IsHazard, int Limit); |
Tom Stellard | cb6ba62 | 2016-04-30 00:23:06 +0000 | [diff] [blame] | 72 | |
Matt Arsenault | a41351e | 2017-11-17 21:35:32 +0000 | [diff] [blame] | 73 | int checkSoftClauseHazards(MachineInstr *SMEM); |
Tom Stellard | cb6ba62 | 2016-04-30 00:23:06 +0000 | [diff] [blame] | 74 | int checkSMRDHazards(MachineInstr *SMRD); |
| 75 | int checkVMEMHazards(MachineInstr* VMEM); |
Tom Stellard | a27007e | 2016-05-02 16:23:09 +0000 | [diff] [blame] | 76 | int checkDPPHazards(MachineInstr *DPP); |
Tom Stellard | 5ab6154 | 2016-10-07 23:42:48 +0000 | [diff] [blame] | 77 | int checkDivFMasHazards(MachineInstr *DivFMas); |
Tom Stellard | 961811c | 2016-10-15 00:58:14 +0000 | [diff] [blame] | 78 | int checkGetRegHazards(MachineInstr *GetRegInstr); |
Tom Stellard | 30d3082 | 2016-10-27 20:39:09 +0000 | [diff] [blame] | 79 | int checkSetRegHazards(MachineInstr *SetRegInstr); |
Tom Stellard | b133fbb | 2016-10-27 23:05:31 +0000 | [diff] [blame] | 80 | int createsVALUHazard(const MachineInstr &MI); |
| 81 | int checkVALUHazards(MachineInstr *VALU); |
Mark Searles | d29f24a | 2017-12-07 20:34:25 +0000 | [diff] [blame] | 82 | int checkVALUHazardsHelper(const MachineOperand &Def, const MachineRegisterInfo &MRI); |
Tom Stellard | 04051b5 | 2016-10-27 23:42:29 +0000 | [diff] [blame] | 83 | int checkRWLaneHazards(MachineInstr *RWLane); |
Tom Stellard | aea899e | 2016-10-27 23:50:21 +0000 | [diff] [blame] | 84 | int checkRFEHazards(MachineInstr *RFE); |
Mark Searles | d29f24a | 2017-12-07 20:34:25 +0000 | [diff] [blame] | 85 | int checkInlineAsmHazards(MachineInstr *IA); |
Matt Arsenault | e823d92 | 2017-02-18 18:29:53 +0000 | [diff] [blame] | 86 | int checkAnyInstHazards(MachineInstr *MI); |
| 87 | int checkReadM0Hazards(MachineInstr *SMovRel); |
Stanislav Mekhanoshin | 51d1415 | 2019-05-04 04:30:57 +0000 | [diff] [blame] | 88 | int checkNSAtoVMEMHazard(MachineInstr *MI); |
Stanislav Mekhanoshin | bdf7f81 | 2019-06-21 16:30:14 +0000 | [diff] [blame] | 89 | int checkFPAtomicToDenormModeHazard(MachineInstr *MI); |
Austin Kerbow | 8a3d3a9 | 2019-05-07 22:12:15 +0000 | [diff] [blame] | 90 | void fixHazards(MachineInstr *MI); |
Stanislav Mekhanoshin | 5f581c9 | 2019-06-12 17:52:51 +0000 | [diff] [blame] | 91 | bool fixVcmpxPermlaneHazards(MachineInstr *MI); |
Stanislav Mekhanoshin | 51d1415 | 2019-05-04 04:30:57 +0000 | [diff] [blame] | 92 | bool fixVMEMtoScalarWriteHazards(MachineInstr *MI); |
| 93 | bool fixSMEMtoVectorWriteHazards(MachineInstr *MI); |
| 94 | bool fixVcmpxExecWARHazard(MachineInstr *MI); |
| 95 | bool fixLdsBranchVmemWARHazard(MachineInstr *MI); |
| 96 | |
Stanislav Mekhanoshin | 7d2019b | 2019-07-11 21:30:34 +0000 | [diff] [blame] | 97 | int checkMAIHazards(MachineInstr *MI); |
| 98 | int checkMAILdStHazards(MachineInstr *MI); |
| 99 | |
Tom Stellard | cb6ba62 | 2016-04-30 00:23:06 +0000 | [diff] [blame] | 100 | public: |
| 101 | GCNHazardRecognizer(const MachineFunction &MF); |
| 102 | // We can only issue one instruction per cycle. |
| 103 | bool atIssueLimit() const override { return true; } |
| 104 | void EmitInstruction(SUnit *SU) override; |
| 105 | void EmitInstruction(MachineInstr *MI) override; |
| 106 | HazardType getHazardType(SUnit *SU, int Stalls) override; |
| 107 | void EmitNoop() override; |
| 108 | unsigned PreEmitNoops(SUnit *SU) override; |
| 109 | unsigned PreEmitNoops(MachineInstr *) override; |
Stanislav Mekhanoshin | f92ed69 | 2019-01-21 19:11:26 +0000 | [diff] [blame] | 110 | unsigned PreEmitNoopsCommon(MachineInstr *); |
Tom Stellard | cb6ba62 | 2016-04-30 00:23:06 +0000 | [diff] [blame] | 111 | void AdvanceCycle() override; |
| 112 | void RecedeCycle() override; |
| 113 | }; |
| 114 | |
| 115 | } // end namespace llvm |
| 116 | |
| 117 | #endif //LLVM_LIB_TARGET_AMDGPUHAZARDRECOGNIZERS_H |