File indexing completed on 2026-05-10 08:43:34
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #ifndef LLVM_CODEGEN_SCOREBOARDHAZARDRECOGNIZER_H
0016 #define LLVM_CODEGEN_SCOREBOARDHAZARDRECOGNIZER_H
0017
0018 #include "llvm/CodeGen/ScheduleHazardRecognizer.h"
0019 #include "llvm/MC/MCInstrItineraries.h"
0020 #include <cassert>
0021 #include <cstddef>
0022 #include <cstring>
0023
0024 namespace llvm {
0025
0026 class ScheduleDAG;
0027 class SUnit;
0028
0029 class ScoreboardHazardRecognizer : public ScheduleHazardRecognizer {
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039 class Scoreboard {
0040 InstrStage::FuncUnits *Data = nullptr;
0041
0042
0043
0044
0045 size_t Depth = 0;
0046
0047
0048 size_t Head = 0;
0049
0050 public:
0051 Scoreboard() = default;
0052 Scoreboard &operator=(const Scoreboard &other) = delete;
0053 Scoreboard(const Scoreboard &other) = delete;
0054 ~Scoreboard() {
0055 delete[] Data;
0056 }
0057
0058 size_t getDepth() const { return Depth; }
0059
0060 InstrStage::FuncUnits& operator[](size_t idx) const {
0061
0062 assert(Depth && !(Depth & (Depth - 1)) &&
0063 "Scoreboard was not initialized properly!");
0064
0065 return Data[(Head + idx) & (Depth-1)];
0066 }
0067
0068 void reset(size_t d = 1) {
0069 if (!Data) {
0070 Depth = d;
0071 Data = new InstrStage::FuncUnits[Depth];
0072 }
0073
0074 memset(Data, 0, Depth * sizeof(Data[0]));
0075 Head = 0;
0076 }
0077
0078 void advance() {
0079 Head = (Head + 1) & (Depth-1);
0080 }
0081
0082 void recede() {
0083 Head = (Head - 1) & (Depth-1);
0084 }
0085
0086
0087 void dump() const;
0088 };
0089
0090
0091
0092 const char *DebugType;
0093
0094
0095 const InstrItineraryData *ItinData;
0096
0097 const ScheduleDAG *DAG;
0098
0099
0100 unsigned IssueWidth = 0;
0101
0102
0103 unsigned IssueCount = 0;
0104
0105 Scoreboard ReservedScoreboard;
0106 Scoreboard RequiredScoreboard;
0107
0108 public:
0109 ScoreboardHazardRecognizer(const InstrItineraryData *II,
0110 const ScheduleDAG *DAG,
0111 const char *ParentDebugType = "");
0112
0113
0114
0115 bool atIssueLimit() const override;
0116
0117
0118
0119 HazardType getHazardType(SUnit *SU, int Stalls) override;
0120 void Reset() override;
0121 void EmitInstruction(SUnit *SU) override;
0122 void AdvanceCycle() override;
0123 void RecedeCycle() override;
0124 };
0125
0126 }
0127
0128 #endif