1 //=- llvm/CodeGen/ExactHazardRecognizer.h - Scheduling 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 implements the ExactHazardRecognizer class, which
11 // implements hazard-avoidance heuristics for scheduling, based on the
12 // scheduling itineraries specified for the target.
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_CODEGEN_EXACTHAZARDRECOGNIZER_H
17 #define LLVM_CODEGEN_EXACTHAZARDRECOGNIZER_H
19 #include "llvm/CodeGen/ScheduleHazardRecognizer.h"
20 #include "llvm/CodeGen/ScheduleDAG.h"
21 #include "llvm/Target/TargetInstrItineraries.h"
24 class ExactHazardRecognizer : public ScheduleHazardRecognizer {
25 // ScoreBoard to track function unit usage. ScoreBoard[0] is a
26 // mask of the FUs in use in the cycle currently being
27 // schedule. ScoreBoard[1] is a mask for the next cycle. The
28 // ScoreBoard is used as a circular buffer with the current cycle
33 // The maximum number of cycles monitored by the Scoreboard. This
34 // value is determined based on the target itineraries to ensure
35 // that all hazards can be tracked.
37 // Indices into the Scoreboard that represent the current cycle.
40 ScoreBoard():Data(NULL), Depth(0), Head(0) { }
45 size_t getDepth() const { return Depth; }
46 unsigned& operator[](size_t idx) const {
47 assert(Depth && "ScoreBoard was not initialized properly!");
49 return Data[(Head + idx) % Depth];
52 void reset(size_t d = 1) {
55 Data = new unsigned[Depth];
58 memset(Data, 0, Depth * sizeof(Data[0]));
63 Head = (Head + 1) % Depth;
66 // Print the scoreboard.
70 // Itinerary data for the target.
71 const InstrItineraryData &ItinData;
73 ScoreBoard ReservedScoreboard;
74 ScoreBoard RequiredScoreboard;
77 ExactHazardRecognizer(const InstrItineraryData &ItinData);
79 virtual HazardType getHazardType(SUnit *SU);
81 virtual void EmitInstruction(SUnit *SU);
82 virtual void AdvanceCycle();