David Goodwin | d94a4e5 | 2009-08-10 15:55:25 +0000 | [diff] [blame] | 1 | //=- llvm/CodeGen/ExactHazardRecognizer.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 ExactHazardRecognizer class, which |
| 11 | // implements hazard-avoidance heuristics for scheduling, based on the |
| 12 | // scheduling itineraries specified for the target. |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
| 16 | #ifndef LLVM_CODEGEN_EXACTHAZARDRECOGNIZER_H |
| 17 | #define LLVM_CODEGEN_EXACTHAZARDRECOGNIZER_H |
| 18 | |
| 19 | #include "llvm/CodeGen/ScheduleHazardRecognizer.h" |
| 20 | #include "llvm/CodeGen/ScheduleDAG.h" |
| 21 | #include "llvm/Target/TargetInstrItineraries.h" |
| 22 | |
| 23 | namespace llvm { |
| 24 | class ExactHazardRecognizer : public ScheduleHazardRecognizer { |
Anton Korobeynikov | 1298948 | 2010-04-07 18:19:24 +0000 | [diff] [blame] | 25 | // ScoreBoard to track function unit usage. ScoreBoard[0] is a |
| 26 | // mask of the FUs in use in the cycle currently being |
| 27 | // schedule. ScoreBoard[1] is a mask for the next cycle. The |
| 28 | // ScoreBoard is used as a circular buffer with the current cycle |
| 29 | // indicated by Head. |
| 30 | class ScoreBoard { |
| 31 | unsigned *Data; |
| 32 | |
| 33 | // The maximum number of cycles monitored by the Scoreboard. This |
| 34 | // value is determined based on the target itineraries to ensure |
| 35 | // that all hazards can be tracked. |
| 36 | size_t Depth; |
| 37 | // Indices into the Scoreboard that represent the current cycle. |
| 38 | size_t Head; |
| 39 | public: |
| 40 | ScoreBoard():Data(NULL), Depth(0), Head(0) { } |
| 41 | ~ScoreBoard() { |
| 42 | delete[] Data; |
| 43 | } |
| 44 | |
| 45 | size_t getDepth() const { return Depth; } |
| 46 | unsigned& operator[](size_t idx) const { |
| 47 | assert(Depth && "ScoreBoard was not initialized properly!"); |
| 48 | |
| 49 | return Data[(Head + idx) % Depth]; |
| 50 | } |
| 51 | |
| 52 | void reset(size_t d = 1) { |
| 53 | if (Data == NULL) { |
| 54 | Depth = d; |
| 55 | Data = new unsigned[Depth]; |
| 56 | } |
| 57 | |
| 58 | memset(Data, 0, Depth * sizeof(Data[0])); |
| 59 | Head = 0; |
| 60 | } |
| 61 | |
| 62 | void advance() { |
| 63 | Head = (Head + 1) % Depth; |
| 64 | } |
| 65 | |
| 66 | // Print the scoreboard. |
| 67 | void dump() const; |
| 68 | }; |
| 69 | |
David Goodwin | d94a4e5 | 2009-08-10 15:55:25 +0000 | [diff] [blame] | 70 | // Itinerary data for the target. |
| 71 | const InstrItineraryData &ItinData; |
| 72 | |
Anton Korobeynikov | 96085a3 | 2010-04-07 18:19:32 +0000 | [diff] [blame^] | 73 | ScoreBoard ReservedScoreboard; |
| 74 | ScoreBoard RequiredScoreboard; |
David Goodwin | d94a4e5 | 2009-08-10 15:55:25 +0000 | [diff] [blame] | 75 | |
| 76 | public: |
| 77 | ExactHazardRecognizer(const InstrItineraryData &ItinData); |
Anton Korobeynikov | 1298948 | 2010-04-07 18:19:24 +0000 | [diff] [blame] | 78 | |
David Goodwin | d94a4e5 | 2009-08-10 15:55:25 +0000 | [diff] [blame] | 79 | virtual HazardType getHazardType(SUnit *SU); |
| 80 | virtual void Reset(); |
| 81 | virtual void EmitInstruction(SUnit *SU); |
| 82 | virtual void AdvanceCycle(); |
| 83 | }; |
| 84 | } |
| 85 | |
| 86 | #endif |