1 //=- llvm/CodeGen/ScoreboardHazardRecognizer.h - Schedule Support -*- C++ -*-=//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file defines the ScoreboardHazardRecognizer class, which
10 // encapsulates hazard-avoidance heuristics for scheduling, based on the
11 // scheduling itineraries specified for the target.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CODEGEN_SCOREBOARDHAZARDRECOGNIZER_H
16 #define LLVM_CODEGEN_SCOREBOARDHAZARDRECOGNIZER_H
18 #include "llvm/CodeGen/ScheduleHazardRecognizer.h"
25 class InstrItineraryData
;
29 class ScoreboardHazardRecognizer
: public ScheduleHazardRecognizer
{
30 // Scoreboard to track function unit usage. Scoreboard[0] is a
31 // mask of the FUs in use in the cycle currently being
32 // schedule. Scoreboard[1] is a mask for the next cycle. The
33 // Scoreboard is used as a circular buffer with the current cycle
36 // Scoreboard always counts cycles in forward execution order. If used by a
37 // bottom-up scheduler, then the scoreboard cycles are the inverse of the
38 // scheduler's cycles.
40 unsigned *Data
= nullptr;
42 // The maximum number of cycles monitored by the Scoreboard. This
43 // value is determined based on the target itineraries to ensure
44 // that all hazards can be tracked.
47 // Indices into the Scoreboard that represent the current cycle.
51 Scoreboard() = default;
57 size_t getDepth() const { return Depth
; }
59 unsigned& operator[](size_t idx
) const {
60 // Depth is expected to be a power-of-2.
61 assert(Depth
&& !(Depth
& (Depth
- 1)) &&
62 "Scoreboard was not initialized properly!");
64 return Data
[(Head
+ idx
) & (Depth
-1)];
67 void reset(size_t d
= 1) {
70 Data
= new unsigned[Depth
];
73 memset(Data
, 0, Depth
* sizeof(Data
[0]));
78 Head
= (Head
+ 1) & (Depth
-1);
82 Head
= (Head
- 1) & (Depth
-1);
85 // Print the scoreboard.
89 // Support for tracing ScoreboardHazardRecognizer as a component within
91 const char *DebugType
;
93 // Itinerary data for the target.
94 const InstrItineraryData
*ItinData
;
96 const ScheduleDAG
*DAG
;
98 /// IssueWidth - Max issue per cycle. 0=Unknown.
99 unsigned IssueWidth
= 0;
101 /// IssueCount - Count instructions issued in this cycle.
102 unsigned IssueCount
= 0;
104 Scoreboard ReservedScoreboard
;
105 Scoreboard RequiredScoreboard
;
108 ScoreboardHazardRecognizer(const InstrItineraryData
*II
,
109 const ScheduleDAG
*DAG
,
110 const char *ParentDebugType
= "");
112 /// atIssueLimit - Return true if no more instructions may be issued in this
114 bool atIssueLimit() const override
;
116 // Stalls provides an cycle offset at which SU will be scheduled. It will be
117 // negative for bottom-up scheduling.
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
;
125 } // end namespace llvm
127 #endif // LLVM_CODEGEN_SCOREBOARDHAZARDRECOGNIZER_H