Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:34

0001 //=- llvm/CodeGen/ScoreboardHazardRecognizer.h - Schedule Support -*- C++ -*-=//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file defines the ScoreboardHazardRecognizer class, which
0010 // encapsulates hazard-avoidance heuristics for scheduling, based on the
0011 // scheduling itineraries specified for the target.
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   // Scoreboard to track function unit usage. Scoreboard[0] is a
0031   // mask of the FUs in use in the cycle currently being
0032   // schedule. Scoreboard[1] is a mask for the next cycle. The
0033   // Scoreboard is used as a circular buffer with the current cycle
0034   // indicated by Head.
0035   //
0036   // Scoreboard always counts cycles in forward execution order. If used by a
0037   // bottom-up scheduler, then the scoreboard cycles are the inverse of the
0038   // scheduler's cycles.
0039   class Scoreboard {
0040     InstrStage::FuncUnits *Data = nullptr;
0041 
0042     // The maximum number of cycles monitored by the Scoreboard. This
0043     // value is determined based on the target itineraries to ensure
0044     // that all hazards can be tracked.
0045     size_t Depth = 0;
0046 
0047     // Indices into the Scoreboard that represent the current cycle.
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       // Depth is expected to be a power-of-2.
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     // Print the scoreboard.
0087     void dump() const;
0088   };
0089 
0090   // Support for tracing ScoreboardHazardRecognizer as a component within
0091   // another module.
0092   const char *DebugType;
0093 
0094   // Itinerary data for the target.
0095   const InstrItineraryData *ItinData;
0096 
0097   const ScheduleDAG *DAG;
0098 
0099   /// IssueWidth - Max issue per cycle. 0=Unknown.
0100   unsigned IssueWidth = 0;
0101 
0102   /// IssueCount - Count instructions issued in this cycle.
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   /// atIssueLimit - Return true if no more instructions may be issued in this
0114   /// cycle.
0115   bool atIssueLimit() const override;
0116 
0117   // Stalls provides an cycle offset at which SU will be scheduled. It will be
0118   // negative for bottom-up scheduling.
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 } // end namespace llvm
0127 
0128 #endif // LLVM_CODEGEN_SCOREBOARDHAZARDRECOGNIZER_H