Move the search for the appropriate AND instruction
[oota-llvm.git] / include / llvm / CodeGen / PostRAHazardRecognizer.h
1 //=- llvm/CodeGen/PostRAHazardRecognizer.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 PostRAHazardRecognizer 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/System/DataTypes.h"
21
22 #include <cassert>
23 #include <cstring>
24 #include <string>
25
26 namespace llvm {
27
28 class InstrItineraryData;
29 class SUnit;
30
31 class PostRAHazardRecognizer : 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
36   // indicated by Head.
37   class ScoreBoard {
38     unsigned *Data;
39
40     // The maximum number of cycles monitored by the Scoreboard. This
41     // value is determined based on the target itineraries to ensure
42     // that all hazards can be tracked.
43     size_t Depth;
44     // Indices into the Scoreboard that represent the current cycle.
45     size_t Head;
46   public:
47     ScoreBoard():Data(NULL), Depth(0), Head(0) { }
48     ~ScoreBoard() {
49       delete[] Data;
50     }
51
52     size_t getDepth() const { return Depth; }
53     unsigned& operator[](size_t idx) const {
54       assert(Depth && "ScoreBoard was not initialized properly!");
55
56       return Data[(Head + idx) % Depth];
57     }
58
59     void reset(size_t d = 1) {
60       if (Data == NULL) {
61         Depth = d;
62         Data = new unsigned[Depth];
63       }
64
65       memset(Data, 0, Depth * sizeof(Data[0]));
66       Head = 0;
67     }
68
69     void advance() {
70       Head = (Head + 1) % Depth;
71     }
72
73     // Print the scoreboard.
74     void dump() const;
75   };
76
77   // Itinerary data for the target.
78   const InstrItineraryData *ItinData;
79
80   ScoreBoard ReservedScoreboard;
81   ScoreBoard RequiredScoreboard;
82
83 public:
84   PostRAHazardRecognizer(const InstrItineraryData *ItinData);
85
86   virtual HazardType getHazardType(SUnit *SU);
87   virtual void Reset();
88   virtual void EmitInstruction(SUnit *SU);
89   virtual void AdvanceCycle();
90 };
91
92 }
93
94 #endif