summaryrefslogtreecommitdiffstats
path: root/contrib/llvm/lib/Target/Hexagon/HexagonHazardRecognizer.h
blob: 70efcb7a9f7630045c14b212e542bb85e95d651e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//===--- HexagonHazardRecognizer.h - Hexagon Post RA Hazard Recognizer ----===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// This file defines the hazard recognizer for scheduling on Hexagon.
//===----------------------------------------------------------------------===//

#ifndef LLVM_LIB_TARGET_HEXAGON_HEXAGONPROFITRECOGNIZER_H
#define LLVM_LIB_TARGET_HEXAGON_HEXAGONPROFITRECOGNIZER_H

#include "HexagonInstrInfo.h"
#include "HexagonSubtarget.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/CodeGen/DFAPacketizer.h"
#include "llvm/CodeGen/ScheduleHazardRecognizer.h"

namespace llvm {

class HexagonHazardRecognizer : public ScheduleHazardRecognizer {
  DFAPacketizer *Resources;
  const HexagonInstrInfo *TII;
  unsigned PacketNum;
  // If the packet contains a potential dot cur instruction. This is
  // used for the scheduling priority function.
  SUnit *UsesDotCur;
  // The packet number when a dor cur is emitted. If its use is not generated
  // in the same packet, then try to wait another cycle before emitting.
  int DotCurPNum;
  // The set of registers defined by instructions in the current packet.
  SmallSet<unsigned, 8> RegDefs;

public:
  HexagonHazardRecognizer(const InstrItineraryData *II,
                          const HexagonInstrInfo *HII,
                          const HexagonSubtarget &ST)
    : Resources(ST.createDFAPacketizer(II)), TII(HII), PacketNum(0),
    UsesDotCur(nullptr), DotCurPNum(-1) { }

  ~HexagonHazardRecognizer() override {
    if (Resources)
      delete Resources;
  }

  /// This callback is invoked when a new block of instructions is about to be
  /// scheduled. The hazard state is set to an initialized state.
  void Reset() override;

  /// Return the hazard type of emitting this node.  There are three
  /// possible results.  Either:
  ///  * NoHazard: it is legal to issue this instruction on this cycle.
  ///  * Hazard: issuing this instruction would stall the machine.  If some
  ///     other instruction is available, issue it first.
  HazardType getHazardType(SUnit *SU, int stalls) override;

  /// This callback is invoked when an instruction is emitted to be scheduled,
  /// to advance the hazard state.
  void EmitInstruction(SUnit *) override;

  /// This callback may be invoked if getHazardType returns NoHazard. If, even
  /// though there is no hazard, it would be better to schedule another
  /// available instruction, this callback should return true.
  bool ShouldPreferAnother(SUnit *) override;

  /// This callback is invoked whenever the next top-down instruction to be
  /// scheduled cannot issue in the current cycle, either because of latency
  /// or resource conflicts.  This should increment the internal state of the
  /// hazard recognizer so that previously "Hazard" instructions will now not
  /// be hazards.
  void AdvanceCycle() override;
};

} // end namespace llvm

#endif // LLVM_LIB_TARGET_HEXAGON_HEXAGONPROFITRECOGNIZER_H
OpenPOWER on IntegriCloud