1 //=- llvm/CodeGen/ScheduleHazardRecognizer.h - Scheduling Support -*- 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 ScheduleHazardRecognizer class, which implements 11 // hazard-avoidance heuristics for scheduling. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #ifndef LLVM_CODEGEN_SCHEDULEHAZARDRECOGNIZER_H 16 #define LLVM_CODEGEN_SCHEDULEHAZARDRECOGNIZER_H 17 18 namespace llvm { 19 20 class SUnit; 21 22 /// HazardRecognizer - This determines whether or not an instruction can be 23 /// issued this cycle, and whether or not a noop needs to be inserted to handle 24 /// the hazard. 25 class ScheduleHazardRecognizer { 26 protected: 27 /// MaxLookAhead - Indicate the number of cycles in the scoreboard 28 /// state. Important to restore the state after backtracking. Additionally, 29 /// MaxLookAhead=0 identifies a fake recognizer, allowing the client to 30 /// bypass virtual calls. Currently the PostRA scheduler ignores it. 31 unsigned MaxLookAhead; 32 33 public: ScheduleHazardRecognizer()34 ScheduleHazardRecognizer(): MaxLookAhead(0) {} 35 virtual ~ScheduleHazardRecognizer(); 36 37 enum HazardType { 38 NoHazard, // This instruction can be emitted at this cycle. 39 Hazard, // This instruction can't be emitted at this cycle. 40 NoopHazard // This instruction can't be emitted, and needs noops. 41 }; 42 getMaxLookAhead()43 unsigned getMaxLookAhead() const { return MaxLookAhead; } 44 isEnabled()45 bool isEnabled() const { return MaxLookAhead != 0; } 46 47 /// atIssueLimit - Return true if no more instructions may be issued in this 48 /// cycle. atIssueLimit()49 virtual bool atIssueLimit() const { return false; } 50 51 /// getHazardType - Return the hazard type of emitting this node. There are 52 /// three possible results. Either: 53 /// * NoHazard: it is legal to issue this instruction on this cycle. 54 /// * Hazard: issuing this instruction would stall the machine. If some 55 /// other instruction is available, issue it first. 56 /// * NoopHazard: issuing this instruction would break the program. If 57 /// some other instruction can be issued, do so, otherwise issue a noop. getHazardType(SUnit * m,int Stalls)58 virtual HazardType getHazardType(SUnit *m, int Stalls) { 59 return NoHazard; 60 } 61 62 /// Reset - This callback is invoked when a new block of 63 /// instructions is about to be schedule. The hazard state should be 64 /// set to an initialized state. Reset()65 virtual void Reset() {} 66 67 /// EmitInstruction - This callback is invoked when an instruction is 68 /// emitted, to advance the hazard state. EmitInstruction(SUnit *)69 virtual void EmitInstruction(SUnit *) {} 70 71 /// AdvanceCycle - This callback is invoked whenever the next top-down 72 /// instruction to be scheduled cannot issue in the current cycle, either 73 /// because of latency or resource conflicts. This should increment the 74 /// internal state of the hazard recognizer so that previously "Hazard" 75 /// instructions will now not be hazards. AdvanceCycle()76 virtual void AdvanceCycle() {} 77 78 /// RecedeCycle - This callback is invoked whenever the next bottom-up 79 /// instruction to be scheduled cannot issue in the current cycle, either 80 /// because of latency or resource conflicts. RecedeCycle()81 virtual void RecedeCycle() {} 82 83 /// EmitNoop - This callback is invoked when a noop was added to the 84 /// instruction stream. EmitNoop()85 virtual void EmitNoop() { 86 // Default implementation: count it as a cycle. 87 AdvanceCycle(); 88 } 89 }; 90 91 } 92 93 #endif 94