1 //=- llvm/CodeGen/ScoreboardHazardRecognizer.h - Schedule Support -*- C++ -*-=//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the ScoreboardHazardRecognizer class, which
11 // encapsulates hazard-avoidance heuristics for scheduling, based on the
12 // scheduling itineraries specified for the target.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_CODEGEN_SCOREBOARDHAZARDRECOGNIZER_H
17 #define LLVM_CODEGEN_SCOREBOARDHAZARDRECOGNIZER_H
19 #include "llvm/CodeGen/ScheduleHazardRecognizer.h"
20 #include "llvm/Support/DataTypes.h"
28 class InstrItineraryData;
31 class ScoreboardHazardRecognizer : public ScheduleHazardRecognizer {
32 // Scoreboard to track function unit usage. Scoreboard[0] is a
33 // mask of the FUs in use in the cycle currently being
34 // schedule. Scoreboard[1] is a mask for the next cycle. The
35 // Scoreboard is used as a circular buffer with the current cycle
38 // Scoreboard always counts cycles in forward execution order. If used by a
39 // bottom-up scheduler, then the scoreboard cycles are the inverse of the
40 // scheduler's cycles.
44 // The maximum number of cycles monitored by the Scoreboard. This
45 // value is determined based on the target itineraries to ensure
46 // that all hazards can be tracked.
48 // Indices into the Scoreboard that represent the current cycle.
51 Scoreboard():Data(NULL), Depth(0), Head(0) { }
56 size_t getDepth() const { return Depth; }
57 unsigned& operator[](size_t idx) const {
58 // Depth is expected to be a power-of-2.
59 assert(Depth && !(Depth & (Depth - 1)) &&
60 "Scoreboard was not initialized properly!");
62 return Data[(Head + idx) & (Depth-1)];
65 void reset(size_t d = 1) {
68 Data = new unsigned[Depth];
71 memset(Data, 0, Depth * sizeof(Data[0]));
76 Head = (Head + 1) & (Depth-1);
80 Head = (Head - 1) & (Depth-1);
83 // Print the scoreboard.
87 // Itinerary data for the target.
88 const InstrItineraryData *ItinData;
90 Scoreboard ReservedScoreboard;
91 Scoreboard RequiredScoreboard;
94 ScoreboardHazardRecognizer(const InstrItineraryData *ItinData);
96 virtual HazardType getHazardType(SUnit *SU);
98 virtual void EmitInstruction(SUnit *SU);
99 virtual void AdvanceCycle();
100 virtual void RecedeCycle();
105 #endif //!LLVM_CODEGEN_SCOREBOARDHAZARDRECOGNIZER_H