xref: /freebsd/contrib/llvm-project/llvm/lib/Target/Hexagon/HexagonHazardRecognizer.h (revision 0b57cec536236d46e3dba9bd041533462f33dbb7)
1*0b57cec5SDimitry Andric //===--- HexagonHazardRecognizer.h - Hexagon Post RA Hazard Recognizer ----===//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric // This file defines the hazard recognizer for scheduling on Hexagon.
9*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
10*0b57cec5SDimitry Andric 
11*0b57cec5SDimitry Andric #ifndef LLVM_LIB_TARGET_HEXAGON_HEXAGONPROFITRECOGNIZER_H
12*0b57cec5SDimitry Andric #define LLVM_LIB_TARGET_HEXAGON_HEXAGONPROFITRECOGNIZER_H
13*0b57cec5SDimitry Andric 
14*0b57cec5SDimitry Andric #include "HexagonInstrInfo.h"
15*0b57cec5SDimitry Andric #include "HexagonSubtarget.h"
16*0b57cec5SDimitry Andric #include "llvm/ADT/SmallSet.h"
17*0b57cec5SDimitry Andric #include "llvm/CodeGen/DFAPacketizer.h"
18*0b57cec5SDimitry Andric #include "llvm/CodeGen/ScheduleHazardRecognizer.h"
19*0b57cec5SDimitry Andric 
20*0b57cec5SDimitry Andric namespace llvm {
21*0b57cec5SDimitry Andric 
22*0b57cec5SDimitry Andric class HexagonHazardRecognizer : public ScheduleHazardRecognizer {
23*0b57cec5SDimitry Andric   DFAPacketizer *Resources;
24*0b57cec5SDimitry Andric   const HexagonInstrInfo *TII;
25*0b57cec5SDimitry Andric   unsigned PacketNum = 0;
26*0b57cec5SDimitry Andric   // If the packet contains a potential dot cur instruction. This is
27*0b57cec5SDimitry Andric   // used for the scheduling priority function.
28*0b57cec5SDimitry Andric   SUnit *UsesDotCur = nullptr;
29*0b57cec5SDimitry Andric   // The packet number when a dor cur is emitted. If its use is not generated
30*0b57cec5SDimitry Andric   // in the same packet, then try to wait another cycle before emitting.
31*0b57cec5SDimitry Andric   int DotCurPNum = -1;
32*0b57cec5SDimitry Andric   // Does the packet contain a load. Used to restrict another load, if possible.
33*0b57cec5SDimitry Andric   bool UsesLoad = false;
34*0b57cec5SDimitry Andric   // Check if we should prefer a vector store that will become a .new version.
35*0b57cec5SDimitry Andric   // The .new store uses different resources than a normal store, and the
36*0b57cec5SDimitry Andric   // packetizer will not generate the .new if the regular store does not have
37*0b57cec5SDimitry Andric   // resources available (even if the .new version does). To help, the schedule
38*0b57cec5SDimitry Andric   // attempts to schedule the .new as soon as possible in the packet.
39*0b57cec5SDimitry Andric   SUnit *PrefVectorStoreNew = nullptr;
40*0b57cec5SDimitry Andric   // The set of registers defined by instructions in the current packet.
41*0b57cec5SDimitry Andric   SmallSet<unsigned, 8> RegDefs;
42*0b57cec5SDimitry Andric 
43*0b57cec5SDimitry Andric public:
44*0b57cec5SDimitry Andric   HexagonHazardRecognizer(const InstrItineraryData *II,
45*0b57cec5SDimitry Andric                           const HexagonInstrInfo *HII,
46*0b57cec5SDimitry Andric                           const HexagonSubtarget &ST)
47*0b57cec5SDimitry Andric     : Resources(ST.createDFAPacketizer(II)), TII(HII) { }
48*0b57cec5SDimitry Andric 
49*0b57cec5SDimitry Andric   ~HexagonHazardRecognizer() override {
50*0b57cec5SDimitry Andric     if (Resources)
51*0b57cec5SDimitry Andric       delete Resources;
52*0b57cec5SDimitry Andric   }
53*0b57cec5SDimitry Andric 
54*0b57cec5SDimitry Andric   /// This callback is invoked when a new block of instructions is about to be
55*0b57cec5SDimitry Andric   /// scheduled. The hazard state is set to an initialized state.
56*0b57cec5SDimitry Andric   void Reset() override;
57*0b57cec5SDimitry Andric 
58*0b57cec5SDimitry Andric   /// Return the hazard type of emitting this node.  There are three
59*0b57cec5SDimitry Andric   /// possible results.  Either:
60*0b57cec5SDimitry Andric   ///  * NoHazard: it is legal to issue this instruction on this cycle.
61*0b57cec5SDimitry Andric   ///  * Hazard: issuing this instruction would stall the machine.  If some
62*0b57cec5SDimitry Andric   ///     other instruction is available, issue it first.
63*0b57cec5SDimitry Andric   HazardType getHazardType(SUnit *SU, int stalls) override;
64*0b57cec5SDimitry Andric 
65*0b57cec5SDimitry Andric   /// This callback is invoked when an instruction is emitted to be scheduled,
66*0b57cec5SDimitry Andric   /// to advance the hazard state.
67*0b57cec5SDimitry Andric   void EmitInstruction(SUnit *) override;
68*0b57cec5SDimitry Andric 
69*0b57cec5SDimitry Andric   /// This callback may be invoked if getHazardType returns NoHazard. If, even
70*0b57cec5SDimitry Andric   /// though there is no hazard, it would be better to schedule another
71*0b57cec5SDimitry Andric   /// available instruction, this callback should return true.
72*0b57cec5SDimitry Andric   bool ShouldPreferAnother(SUnit *) override;
73*0b57cec5SDimitry Andric 
74*0b57cec5SDimitry Andric   /// This callback is invoked whenever the next top-down instruction to be
75*0b57cec5SDimitry Andric   /// scheduled cannot issue in the current cycle, either because of latency
76*0b57cec5SDimitry Andric   /// or resource conflicts.  This should increment the internal state of the
77*0b57cec5SDimitry Andric   /// hazard recognizer so that previously "Hazard" instructions will now not
78*0b57cec5SDimitry Andric   /// be hazards.
79*0b57cec5SDimitry Andric   void AdvanceCycle() override;
80*0b57cec5SDimitry Andric };
81*0b57cec5SDimitry Andric 
82*0b57cec5SDimitry Andric } // end namespace llvm
83*0b57cec5SDimitry Andric 
84*0b57cec5SDimitry Andric #endif // LLVM_LIB_TARGET_HEXAGON_HEXAGONPROFITRECOGNIZER_H
85