1 //===--- HexagonHazardRecognizer.h - Hexagon Post RA Hazard Recognizer ----===//
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 //===----------------------------------------------------------------------===//
9 // This file defines the hazard recognizer for scheduling on Hexagon.
10 //===----------------------------------------------------------------------===//
12 #ifndef LLVM_LIB_TARGET_HEXAGON_HEXAGONPROFITRECOGNIZER_H
13 #define LLVM_LIB_TARGET_HEXAGON_HEXAGONPROFITRECOGNIZER_H
15 #include "HexagonInstrInfo.h"
16 #include "HexagonSubtarget.h"
17 #include "llvm/ADT/SmallSet.h"
18 #include "llvm/CodeGen/DFAPacketizer.h"
19 #include "llvm/CodeGen/ScheduleHazardRecognizer.h"
23 class HexagonHazardRecognizer : public ScheduleHazardRecognizer {
24 DFAPacketizer *Resources;
25 const HexagonInstrInfo *TII;
27 // If the packet contains a potential dot cur instruction. This is
28 // used for the scheduling priority function.
30 // The packet number when a dor cur is emitted. If its use is not generated
31 // in the same packet, then try to wait another cycle before emitting.
33 // The set of registers defined by instructions in the current packet.
34 SmallSet<unsigned, 8> RegDefs;
37 HexagonHazardRecognizer(const InstrItineraryData *II,
38 const HexagonInstrInfo *HII,
39 const HexagonSubtarget &ST)
40 : Resources(ST.createDFAPacketizer(II)), TII(HII), PacketNum(0),
41 UsesDotCur(nullptr), DotCurPNum(-1) { }
43 ~HexagonHazardRecognizer() override {
48 /// This callback is invoked when a new block of instructions is about to be
49 /// scheduled. The hazard state is set to an initialized state.
50 void Reset() override;
52 /// Return the hazard type of emitting this node. There are three
53 /// possible results. Either:
54 /// * NoHazard: it is legal to issue this instruction on this cycle.
55 /// * Hazard: issuing this instruction would stall the machine. If some
56 /// other instruction is available, issue it first.
57 HazardType getHazardType(SUnit *SU, int stalls) override;
59 /// This callback is invoked when an instruction is emitted to be scheduled,
60 /// to advance the hazard state.
61 void EmitInstruction(SUnit *) override;
63 /// This callback may be invoked if getHazardType returns NoHazard. If, even
64 /// though there is no hazard, it would be better to schedule another
65 /// available instruction, this callback should return true.
66 bool ShouldPreferAnother(SUnit *) override;
68 /// This callback is invoked whenever the next top-down instruction to be
69 /// scheduled cannot issue in the current cycle, either because of latency
70 /// or resource conflicts. This should increment the internal state of the
71 /// hazard recognizer so that previously "Hazard" instructions will now not
73 void AdvanceCycle() override;
76 } // end namespace llvm
78 #endif // LLVM_LIB_TARGET_HEXAGON_HEXAGONPROFITRECOGNIZER_H