blob: 91c81a970fa5b0d832c559145547850097846f78 [file] [log] [blame]
David Goodwind94a4e52009-08-10 15:55:25 +00001//=- llvm/CodeGen/ExactHazardRecognizer.h - Scheduling Support -*- C++ -*-=//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
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.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_CODEGEN_EXACTHAZARDRECOGNIZER_H
17#define LLVM_CODEGEN_EXACTHAZARDRECOGNIZER_H
18
19#include "llvm/CodeGen/ScheduleHazardRecognizer.h"
20#include "llvm/CodeGen/ScheduleDAG.h"
21#include "llvm/Target/TargetInstrItineraries.h"
22
23namespace llvm {
24 class ExactHazardRecognizer : public ScheduleHazardRecognizer {
Anton Korobeynikov12989482010-04-07 18:19:24 +000025 // 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
29 // indicated by Head.
30 class ScoreBoard {
31 unsigned *Data;
32
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.
36 size_t Depth;
37 // Indices into the Scoreboard that represent the current cycle.
38 size_t Head;
39 public:
40 ScoreBoard():Data(NULL), Depth(0), Head(0) { }
41 ~ScoreBoard() {
42 delete[] Data;
43 }
44
45 size_t getDepth() const { return Depth; }
46 unsigned& operator[](size_t idx) const {
47 assert(Depth && "ScoreBoard was not initialized properly!");
48
49 return Data[(Head + idx) % Depth];
50 }
51
52 void reset(size_t d = 1) {
53 if (Data == NULL) {
54 Depth = d;
55 Data = new unsigned[Depth];
56 }
57
58 memset(Data, 0, Depth * sizeof(Data[0]));
59 Head = 0;
60 }
61
62 void advance() {
63 Head = (Head + 1) % Depth;
64 }
65
66 // Print the scoreboard.
67 void dump() const;
68 };
69
David Goodwind94a4e52009-08-10 15:55:25 +000070 // Itinerary data for the target.
71 const InstrItineraryData &ItinData;
72
Anton Korobeynikov96085a32010-04-07 18:19:32 +000073 ScoreBoard ReservedScoreboard;
74 ScoreBoard RequiredScoreboard;
David Goodwind94a4e52009-08-10 15:55:25 +000075
76 public:
77 ExactHazardRecognizer(const InstrItineraryData &ItinData);
Anton Korobeynikov12989482010-04-07 18:19:24 +000078
David Goodwind94a4e52009-08-10 15:55:25 +000079 virtual HazardType getHazardType(SUnit *SU);
80 virtual void Reset();
81 virtual void EmitInstruction(SUnit *SU);
82 virtual void AdvanceCycle();
83 };
84}
85
86#endif