ScheduleHazardRecognizer.h 4.2 KB

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