Coverage Report

Created: 2018-09-19 08:35

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/CodeGen/ScoreboardHazardRecognizer.h
Line
Count
Source
1
//=- llvm/CodeGen/ScoreboardHazardRecognizer.h - Schedule 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 defines the ScoreboardHazardRecognizer class, which
11
// encapsulates hazard-avoidance heuristics for scheduling, based on the
12
// scheduling itineraries specified for the target.
13
//
14
//===----------------------------------------------------------------------===//
15
16
#ifndef LLVM_CODEGEN_SCOREBOARDHAZARDRECOGNIZER_H
17
#define LLVM_CODEGEN_SCOREBOARDHAZARDRECOGNIZER_H
18
19
#include "llvm/CodeGen/ScheduleHazardRecognizer.h"
20
#include <cassert>
21
#include <cstddef>
22
#include <cstring>
23
24
namespace llvm {
25
26
class InstrItineraryData;
27
class ScheduleDAG;
28
class SUnit;
29
30
class ScoreboardHazardRecognizer : public ScheduleHazardRecognizer {
31
  // Scoreboard to track function unit usage. Scoreboard[0] is a
32
  // mask of the FUs in use in the cycle currently being
33
  // schedule. Scoreboard[1] is a mask for the next cycle. The
34
  // Scoreboard is used as a circular buffer with the current cycle
35
  // indicated by Head.
36
  //
37
  // Scoreboard always counts cycles in forward execution order. If used by a
38
  // bottom-up scheduler, then the scoreboard cycles are the inverse of the
39
  // scheduler's cycles.
40
  class Scoreboard {
41
    unsigned *Data = nullptr;
42
43
    // The maximum number of cycles monitored by the Scoreboard. This
44
    // value is determined based on the target itineraries to ensure
45
    // that all hazards can be tracked.
46
    size_t Depth = 0;
47
48
    // Indices into the Scoreboard that represent the current cycle.
49
    size_t Head = 0;
50
51
  public:
52
1.80M
    Scoreboard() = default;
53
54
1.80M
    ~Scoreboard() {
55
1.80M
      delete[] Data;
56
1.80M
    }
57
58
3.53M
    size_t getDepth() const { return Depth; }
59
60
10.4M
    unsigned& operator[](size_t idx) const {
61
10.4M
      // Depth is expected to be a power-of-2.
62
10.4M
      assert(Depth && !(Depth & (Depth - 1)) &&
63
10.4M
             "Scoreboard was not initialized properly!");
64
10.4M
65
10.4M
      return Data[(Head + idx) & (Depth-1)];
66
10.4M
    }
67
68
2.66M
    void reset(size_t d = 1) {
69
2.66M
      if (!Data) {
70
1.80M
        Depth = d;
71
1.80M
        Data = new unsigned[Depth];
72
1.80M
      }
73
2.66M
74
2.66M
      memset(Data, 0, Depth * sizeof(Data[0]));
75
2.66M
      Head = 0;
76
2.66M
    }
77
78
726k
    void advance() {
79
726k
      Head = (Head + 1) & (Depth-1);
80
726k
    }
81
82
1.04M
    void recede() {
83
1.04M
      Head = (Head - 1) & (Depth-1);
84
1.04M
    }
85
86
    // Print the scoreboard.
87
    void dump() const;
88
  };
89
90
  // Support for tracing ScoreboardHazardRecognizer as a component within
91
  // another module.
92
  const char *DebugType;
93
94
  // Itinerary data for the target.
95
  const InstrItineraryData *ItinData;
96
97
  const ScheduleDAG *DAG;
98
99
  /// IssueWidth - Max issue per cycle. 0=Unknown.
100
  unsigned IssueWidth = 0;
101
102
  /// IssueCount - Count instructions issued in this cycle.
103
  unsigned IssueCount = 0;
104
105
  Scoreboard ReservedScoreboard;
106
  Scoreboard RequiredScoreboard;
107
108
public:
109
  ScoreboardHazardRecognizer(const InstrItineraryData *II,
110
                             const ScheduleDAG *DAG,
111
                             const char *ParentDebugType = "");
112
113
  /// atIssueLimit - Return true if no more instructions may be issued in this
114
  /// cycle.
115
  bool atIssueLimit() const override;
116
117
  // Stalls provides an cycle offset at which SU will be scheduled. It will be
118
  // negative for bottom-up scheduling.
119
  HazardType getHazardType(SUnit *SU, int Stalls) override;
120
  void Reset() override;
121
  void EmitInstruction(SUnit *SU) override;
122
  void AdvanceCycle() override;
123
  void RecedeCycle() override;
124
};
125
126
} // end namespace llvm
127
128
#endif // LLVM_CODEGEN_SCOREBOARDHAZARDRECOGNIZER_H