LLVM 23.0.0git
ScoreboardHazardRecognizer.h
Go to the documentation of this file.
1//=- llvm/CodeGen/ScoreboardHazardRecognizer.h - Schedule Support -*- C++ -*-=//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
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.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CODEGEN_SCOREBOARDHAZARDRECOGNIZER_H
16#define LLVM_CODEGEN_SCOREBOARDHAZARDRECOGNIZER_H
17
18#include "llvm/ADT/bit.h"
21#include <cassert>
22#include <cstddef>
23#include <cstring>
24
25namespace llvm {
26
27class ScheduleDAG;
28class SUnit;
29
31 // Scoreboard to track function unit usage. Scoreboard[0] is a
32 // mask of the FUs in use in the cycle currently being
33 // schedule. Scoreboard[1] is a mask for the next cycle. The
34 // Scoreboard is used as a circular buffer with the current cycle
35 // indicated by Head.
36 //
37 // Scoreboard always counts cycles in forward execution order. If used by a
38 // bottom-up scheduler, then the scoreboard cycles are the inverse of the
39 // scheduler's cycles.
40 class Scoreboard {
41 InstrStage::FuncUnits *Data = nullptr;
42
43 // The maximum number of cycles monitored by the Scoreboard. This
44 // value is determined based on the target itineraries to ensure
45 // that all hazards can be tracked.
46 size_t Depth = 0;
47
48 // Indices into the Scoreboard that represent the current cycle.
49 size_t Head = 0;
50
51 public:
52 Scoreboard() = default;
53 Scoreboard &operator=(const Scoreboard &other) = delete;
54 Scoreboard(const Scoreboard &other) = delete;
55 ~Scoreboard() {
56 delete[] Data;
57 }
58
59 size_t getDepth() const { return Depth; }
60
61 InstrStage::FuncUnits& operator[](size_t idx) const {
62 // Depth is expected to be a power-of-2.
64 "Scoreboard was not initialized properly!");
65
66 return Data[(Head + idx) & (Depth-1)];
67 }
68
69 void reset(size_t d = 1) {
70 if (!Data) {
71 Depth = d;
73 }
74
75 memset(Data, 0, Depth * sizeof(Data[0]));
76 Head = 0;
77 }
78
79 void advance() {
80 Head = (Head + 1) & (Depth-1);
81 }
82
83 void recede() {
84 Head = (Head - 1) & (Depth-1);
85 }
86
87 // Print the scoreboard.
88 void dump() const;
89 };
90
91 // Support for tracing ScoreboardHazardRecognizer as a component within
92 // another module.
93 const char *DebugType;
94
95 // Itinerary data for the target.
96 const InstrItineraryData *ItinData;
97
98 const ScheduleDAG *DAG;
99
100 /// IssueWidth - Max issue per cycle. 0=Unknown.
101 unsigned IssueWidth = 0;
102
103 /// IssueCount - Count instructions issued in this cycle.
104 unsigned IssueCount = 0;
105
106 Scoreboard ReservedScoreboard;
107 Scoreboard RequiredScoreboard;
108
109public:
111 const ScheduleDAG *DAG,
112 const char *ParentDebugType = "");
113
114 /// atIssueLimit - Return true if no more instructions may be issued in this
115 /// cycle.
116 bool atIssueLimit() const override;
117
118 // Stalls provides an cycle offset at which SU will be scheduled. It will be
119 // negative for bottom-up scheduling.
120 HazardType getHazardType(SUnit *SU, int Stalls) override;
121 void Reset() override;
122 void EmitInstruction(SUnit *SU) override;
123 void AdvanceCycle() override;
124 void RecedeCycle() override;
125};
126
127} // end namespace llvm
128
129#endif // LLVM_CODEGEN_SCOREBOARDHAZARDRECOGNIZER_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
uint64_t IntrinsicInst * II
This file implements the C++20 <bit> header.
Itinerary data supplied by a subtarget to be used by a target.
Scheduling unit. This is a node in the scheduling DAG.
void Reset() override
Reset - This callback is invoked when a new block of instructions is about to be schedule.
void EmitInstruction(SUnit *SU) override
EmitInstruction - This callback is invoked when an instruction is emitted, to advance the hazard stat...
void RecedeCycle() override
RecedeCycle - This callback is invoked whenever the next bottom-up instruction to be scheduled cannot...
HazardType getHazardType(SUnit *SU, int Stalls) override
getHazardType - Return the hazard type of emitting this node.
ScoreboardHazardRecognizer(const InstrItineraryData *II, const ScheduleDAG *DAG, const char *ParentDebugType="")
bool atIssueLimit() const override
atIssueLimit - Return true if no more instructions may be issued in this cycle.
void AdvanceCycle() override
AdvanceCycle - This callback is invoked whenever the next top-down instruction to be scheduled cannot...
This is an optimization pass for GlobalISel generic memory operations.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
constexpr bool has_single_bit(T Value) noexcept
Definition bit.h:149
FunctionAddr VTableAddr uintptr_t uintptr_t Data
Definition InstrProf.h:221
uint64_t FuncUnits
Bitmask representing a set of functional units.