xref: /aosp_15_r20/external/llvm/lib/Target/Hexagon/HexagonVLIWPacketizer.h (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker #ifndef HEXAGONVLIWPACKETIZER_H
2*9880d681SAndroid Build Coastguard Worker #define HEXAGONVLIWPACKETIZER_H
3*9880d681SAndroid Build Coastguard Worker 
4*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/DFAPacketizer.h"
5*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
6*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/ScheduleDAG.h"
7*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/ScheduleDAGInstrs.h"
8*9880d681SAndroid Build Coastguard Worker 
9*9880d681SAndroid Build Coastguard Worker namespace llvm {
10*9880d681SAndroid Build Coastguard Worker class HexagonPacketizerList : public VLIWPacketizerList {
11*9880d681SAndroid Build Coastguard Worker   // Vector of instructions assigned to the packet that has just been created.
12*9880d681SAndroid Build Coastguard Worker   std::vector<MachineInstr*> OldPacketMIs;
13*9880d681SAndroid Build Coastguard Worker 
14*9880d681SAndroid Build Coastguard Worker   // Has the instruction been promoted to a dot-new instruction.
15*9880d681SAndroid Build Coastguard Worker   bool PromotedToDotNew;
16*9880d681SAndroid Build Coastguard Worker 
17*9880d681SAndroid Build Coastguard Worker   // Has the instruction been glued to allocframe.
18*9880d681SAndroid Build Coastguard Worker   bool GlueAllocframeStore;
19*9880d681SAndroid Build Coastguard Worker 
20*9880d681SAndroid Build Coastguard Worker   // Has the feeder instruction been glued to new value jump.
21*9880d681SAndroid Build Coastguard Worker   bool GlueToNewValueJump;
22*9880d681SAndroid Build Coastguard Worker 
23*9880d681SAndroid Build Coastguard Worker   // Check if there is a dependence between some instruction already in this
24*9880d681SAndroid Build Coastguard Worker   // packet and this instruction.
25*9880d681SAndroid Build Coastguard Worker   bool Dependence;
26*9880d681SAndroid Build Coastguard Worker 
27*9880d681SAndroid Build Coastguard Worker   // Only check for dependence if there are resources available to
28*9880d681SAndroid Build Coastguard Worker   // schedule this instruction.
29*9880d681SAndroid Build Coastguard Worker   bool FoundSequentialDependence;
30*9880d681SAndroid Build Coastguard Worker 
31*9880d681SAndroid Build Coastguard Worker   // Track MIs with ignored dependence.
32*9880d681SAndroid Build Coastguard Worker   std::vector<MachineInstr*> IgnoreDepMIs;
33*9880d681SAndroid Build Coastguard Worker 
34*9880d681SAndroid Build Coastguard Worker protected:
35*9880d681SAndroid Build Coastguard Worker   /// \brief A handle to the branch probability pass.
36*9880d681SAndroid Build Coastguard Worker   const MachineBranchProbabilityInfo *MBPI;
37*9880d681SAndroid Build Coastguard Worker   const MachineLoopInfo *MLI;
38*9880d681SAndroid Build Coastguard Worker 
39*9880d681SAndroid Build Coastguard Worker private:
40*9880d681SAndroid Build Coastguard Worker   const HexagonInstrInfo *HII;
41*9880d681SAndroid Build Coastguard Worker   const HexagonRegisterInfo *HRI;
42*9880d681SAndroid Build Coastguard Worker 
43*9880d681SAndroid Build Coastguard Worker public:
44*9880d681SAndroid Build Coastguard Worker   // Ctor.
45*9880d681SAndroid Build Coastguard Worker   HexagonPacketizerList(MachineFunction &MF, MachineLoopInfo &MLI,
46*9880d681SAndroid Build Coastguard Worker                         AliasAnalysis *AA,
47*9880d681SAndroid Build Coastguard Worker                         const MachineBranchProbabilityInfo *MBPI);
48*9880d681SAndroid Build Coastguard Worker 
49*9880d681SAndroid Build Coastguard Worker   // initPacketizerState - initialize some internal flags.
50*9880d681SAndroid Build Coastguard Worker   void initPacketizerState() override;
51*9880d681SAndroid Build Coastguard Worker 
52*9880d681SAndroid Build Coastguard Worker   // ignorePseudoInstruction - Ignore bundling of pseudo instructions.
53*9880d681SAndroid Build Coastguard Worker   bool ignorePseudoInstruction(const MachineInstr &MI,
54*9880d681SAndroid Build Coastguard Worker                                const MachineBasicBlock *MBB) override;
55*9880d681SAndroid Build Coastguard Worker 
56*9880d681SAndroid Build Coastguard Worker   // isSoloInstruction - return true if instruction MI can not be packetized
57*9880d681SAndroid Build Coastguard Worker   // with any other instruction, which means that MI itself is a packet.
58*9880d681SAndroid Build Coastguard Worker   bool isSoloInstruction(const MachineInstr &MI) override;
59*9880d681SAndroid Build Coastguard Worker 
60*9880d681SAndroid Build Coastguard Worker   // isLegalToPacketizeTogether - Is it legal to packetize SUI and SUJ
61*9880d681SAndroid Build Coastguard Worker   // together.
62*9880d681SAndroid Build Coastguard Worker   bool isLegalToPacketizeTogether(SUnit *SUI, SUnit *SUJ) override;
63*9880d681SAndroid Build Coastguard Worker 
64*9880d681SAndroid Build Coastguard Worker   // isLegalToPruneDependencies - Is it legal to prune dependece between SUI
65*9880d681SAndroid Build Coastguard Worker   // and SUJ.
66*9880d681SAndroid Build Coastguard Worker   bool isLegalToPruneDependencies(SUnit *SUI, SUnit *SUJ) override;
67*9880d681SAndroid Build Coastguard Worker 
68*9880d681SAndroid Build Coastguard Worker   MachineBasicBlock::iterator addToPacket(MachineInstr &MI) override;
69*9880d681SAndroid Build Coastguard Worker   void endPacket(MachineBasicBlock *MBB,
70*9880d681SAndroid Build Coastguard Worker                  MachineBasicBlock::iterator MI) override;
71*9880d681SAndroid Build Coastguard Worker   bool shouldAddToPacket(const MachineInstr &MI) override;
72*9880d681SAndroid Build Coastguard Worker 
73*9880d681SAndroid Build Coastguard Worker   void unpacketizeSoloInstrs(MachineFunction &MF);
74*9880d681SAndroid Build Coastguard Worker 
75*9880d681SAndroid Build Coastguard Worker protected:
76*9880d681SAndroid Build Coastguard Worker   bool isCallDependent(const MachineInstr* MI, SDep::Kind DepType,
77*9880d681SAndroid Build Coastguard Worker                        unsigned DepReg);
78*9880d681SAndroid Build Coastguard Worker   bool promoteToDotCur(MachineInstr* MI, SDep::Kind DepType,
79*9880d681SAndroid Build Coastguard Worker                        MachineBasicBlock::iterator &MII,
80*9880d681SAndroid Build Coastguard Worker                        const TargetRegisterClass* RC);
81*9880d681SAndroid Build Coastguard Worker   bool canPromoteToDotCur(const MachineInstr* MI, const SUnit* PacketSU,
82*9880d681SAndroid Build Coastguard Worker                           unsigned DepReg, MachineBasicBlock::iterator &MII,
83*9880d681SAndroid Build Coastguard Worker                           const TargetRegisterClass* RC);
84*9880d681SAndroid Build Coastguard Worker   void cleanUpDotCur();
85*9880d681SAndroid Build Coastguard Worker 
86*9880d681SAndroid Build Coastguard Worker   bool promoteToDotNew(MachineInstr* MI, SDep::Kind DepType,
87*9880d681SAndroid Build Coastguard Worker                        MachineBasicBlock::iterator &MII,
88*9880d681SAndroid Build Coastguard Worker                        const TargetRegisterClass* RC);
89*9880d681SAndroid Build Coastguard Worker   bool canPromoteToDotNew(const MachineInstr* MI, const SUnit* PacketSU,
90*9880d681SAndroid Build Coastguard Worker                           unsigned DepReg, MachineBasicBlock::iterator &MII,
91*9880d681SAndroid Build Coastguard Worker                           const TargetRegisterClass* RC);
92*9880d681SAndroid Build Coastguard Worker   bool canPromoteToNewValue(const MachineInstr* MI, const SUnit* PacketSU,
93*9880d681SAndroid Build Coastguard Worker                             unsigned DepReg, MachineBasicBlock::iterator &MII);
94*9880d681SAndroid Build Coastguard Worker   bool canPromoteToNewValueStore(const MachineInstr* MI,
95*9880d681SAndroid Build Coastguard Worker                                  const MachineInstr* PacketMI, unsigned DepReg);
96*9880d681SAndroid Build Coastguard Worker   bool demoteToDotOld(MachineInstr* MI);
97*9880d681SAndroid Build Coastguard Worker   bool arePredicatesComplements(MachineInstr &MI1, MachineInstr &MI2);
98*9880d681SAndroid Build Coastguard Worker   bool restrictingDepExistInPacket(MachineInstr*, unsigned);
99*9880d681SAndroid Build Coastguard Worker   bool isNewifiable(const MachineInstr *MI);
100*9880d681SAndroid Build Coastguard Worker   bool isCurifiable(MachineInstr* MI);
101*9880d681SAndroid Build Coastguard Worker   bool cannotCoexist(const MachineInstr *MI, const MachineInstr *MJ);
isPromotedToDotNew()102*9880d681SAndroid Build Coastguard Worker   inline bool isPromotedToDotNew() const {
103*9880d681SAndroid Build Coastguard Worker     return PromotedToDotNew;
104*9880d681SAndroid Build Coastguard Worker   }
105*9880d681SAndroid Build Coastguard Worker   bool tryAllocateResourcesForConstExt(bool Reserve);
106*9880d681SAndroid Build Coastguard Worker   bool canReserveResourcesForConstExt();
107*9880d681SAndroid Build Coastguard Worker   void reserveResourcesForConstExt();
108*9880d681SAndroid Build Coastguard Worker   bool hasDeadDependence(const MachineInstr *I, const MachineInstr *J);
109*9880d681SAndroid Build Coastguard Worker   bool hasControlDependence(const MachineInstr *I, const MachineInstr *J);
110*9880d681SAndroid Build Coastguard Worker   bool hasV4SpecificDependence(const MachineInstr *I, const MachineInstr *J);
111*9880d681SAndroid Build Coastguard Worker   bool producesStall(const MachineInstr *MI);
112*9880d681SAndroid Build Coastguard Worker };
113*9880d681SAndroid Build Coastguard Worker } // namespace llvm
114*9880d681SAndroid Build Coastguard Worker #endif // HEXAGONVLIWPACKETIZER_H
115*9880d681SAndroid Build Coastguard Worker 
116