| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#ifndef LLVM_CODEGEN_SCOREBOARDHAZARDRECOGNIZER_H |
| 16 |
#define LLVM_CODEGEN_SCOREBOARDHAZARDRECOGNIZER_H |
| 17 |
|
| 18 |
#include "llvm/CodeGen/ScheduleHazardRecognizer.h" |
| 19 |
#include "llvm/MC/MCInstrItineraries.h" |
| 20 |
#include <cassert> |
| 21 |
#include <cstddef> |
| 22 |
#include <cstring> |
| 23 |
|
| 24 |
namespace llvm { |
| 25 |
|
| 26 |
class ScheduleDAG; |
| 27 |
class SUnit; |
| 28 |
|
| 29 |
class ScoreboardHazardRecognizer : public ScheduleHazardRecognizer { |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
class Scoreboard { |
| 40 |
InstrStage::FuncUnits *Data = nullptr; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
size_t Depth = 0; |
| 46 |
|
| 47 |
|
| 48 |
size_t Head = 0; |
| 49 |
|
| 50 |
public: |
| 51 |
Scoreboard() = default; |
| 52 |
|
| 53 |
~Scoreboard() { |
| 54 |
delete[] Data; |
| 55 |
} |
| 56 |
|
| 57 |
size_t getDepth() const { return Depth; } |
| 58 |
|
| 59 |
InstrStage::FuncUnits& operator[](size_t idx) const { |
| 60 |
|
| 61 |
assert(Depth && !(Depth & (Depth - 1)) && |
| 62 |
"Scoreboard was not initialized properly!"); |
| 63 |
|
| 64 |
return Data[(Head + idx) & (Depth-1)]; |
| 65 |
} |
| 66 |
|
| 67 |
void reset(size_t d = 1) { |
| 68 |
if (!Data) { |
| 69 |
Depth = d; |
| 70 |
Data = new InstrStage::FuncUnits[Depth]; |
| 71 |
} |
| 72 |
|
| 73 |
memset(Data, 0, Depth * sizeof(Data[0])); |
| 74 |
Head = 0; |
| 75 |
} |
| 76 |
|
| 77 |
void advance() { |
| 78 |
Head = (Head + 1) & (Depth-1); |
| 79 |
} |
| 80 |
|
| 81 |
void recede() { |
| 82 |
Head = (Head - 1) & (Depth-1); |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
void dump() const; |
| 87 |
}; |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
const char *DebugType; |
| 92 |
|
| 93 |
|
| 94 |
const InstrItineraryData *ItinData; |
| 95 |
|
| 96 |
const ScheduleDAG *DAG; |
| 97 |
|
| 98 |
|
| 99 |
unsigned IssueWidth = 0; |
| 100 |
|
| 101 |
|
| 102 |
unsigned IssueCount = 0; |
| 103 |
|
| 104 |
Scoreboard ReservedScoreboard; |
| 105 |
Scoreboard RequiredScoreboard; |
| 106 |
|
| 107 |
public: |
| 108 |
ScoreboardHazardRecognizer(const InstrItineraryData *II, |
| 109 |
const ScheduleDAG *DAG, |
| 110 |
const char *ParentDebugType = ""); |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
bool atIssueLimit() const override; |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
HazardType getHazardType(SUnit *SU, int Stalls) override; |
| 119 |
void Reset() override; |
| 120 |
void EmitInstruction(SUnit *SU) override; |
| 121 |
void AdvanceCycle() override; |
| 122 |
void RecedeCycle() override; |
| 123 |
}; |
| 124 |
|
| 125 |
} |
| 126 |
|
| 127 |
#endif |