blob: 3a2d777c2749134c4bf6d3097a00e33abde7f84c [file] [log] [blame]
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +00001#ifndef HEXAGONVLIWPACKETIZER_H
2#define HEXAGONVLIWPACKETIZER_H
3
4#include "llvm/CodeGen/DFAPacketizer.h"
5#include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
6#include "llvm/CodeGen/ScheduleDAG.h"
7#include "llvm/CodeGen/ScheduleDAGInstrs.h"
8
9namespace llvm {
Benjamin Kramer73564982017-01-30 14:55:33 +000010class HexagonInstrInfo;
11class HexagonRegisterInfo;
12
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000013class HexagonPacketizerList : public VLIWPacketizerList {
14 // Vector of instructions assigned to the packet that has just been created.
15 std::vector<MachineInstr*> OldPacketMIs;
16
17 // Has the instruction been promoted to a dot-new instruction.
18 bool PromotedToDotNew;
19
20 // Has the instruction been glued to allocframe.
21 bool GlueAllocframeStore;
22
23 // Has the feeder instruction been glued to new value jump.
24 bool GlueToNewValueJump;
25
26 // Check if there is a dependence between some instruction already in this
27 // packet and this instruction.
28 bool Dependence;
29
30 // Only check for dependence if there are resources available to
31 // schedule this instruction.
32 bool FoundSequentialDependence;
33
34 // Track MIs with ignored dependence.
35 std::vector<MachineInstr*> IgnoreDepMIs;
36
Krzysztof Parzyszek9aaf9232017-05-02 18:12:19 +000037 // Set to true if the packet contains an instruction that stalls with an
38 // instruction from the previous packet.
39 bool PacketStalls;
40
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000041protected:
42 /// \brief A handle to the branch probability pass.
43 const MachineBranchProbabilityInfo *MBPI;
44 const MachineLoopInfo *MLI;
45
46private:
47 const HexagonInstrInfo *HII;
48 const HexagonRegisterInfo *HRI;
49
50public:
51 // Ctor.
52 HexagonPacketizerList(MachineFunction &MF, MachineLoopInfo &MLI,
53 AliasAnalysis *AA,
54 const MachineBranchProbabilityInfo *MBPI);
55
56 // initPacketizerState - initialize some internal flags.
57 void initPacketizerState() override;
58
59 // ignorePseudoInstruction - Ignore bundling of pseudo instructions.
Duncan P. N. Exon Smith57022872016-02-27 19:09:00 +000060 bool ignorePseudoInstruction(const MachineInstr &MI,
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000061 const MachineBasicBlock *MBB) override;
62
63 // isSoloInstruction - return true if instruction MI can not be packetized
64 // with any other instruction, which means that MI itself is a packet.
Duncan P. N. Exon Smith57022872016-02-27 19:09:00 +000065 bool isSoloInstruction(const MachineInstr &MI) override;
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000066
67 // isLegalToPacketizeTogether - Is it legal to packetize SUI and SUJ
68 // together.
69 bool isLegalToPacketizeTogether(SUnit *SUI, SUnit *SUJ) override;
70
71 // isLegalToPruneDependencies - Is it legal to prune dependece between SUI
72 // and SUJ.
73 bool isLegalToPruneDependencies(SUnit *SUI, SUnit *SUJ) override;
74
Duncan P. N. Exon Smith57022872016-02-27 19:09:00 +000075 MachineBasicBlock::iterator addToPacket(MachineInstr &MI) override;
76 void endPacket(MachineBasicBlock *MBB,
77 MachineBasicBlock::iterator MI) override;
78 bool shouldAddToPacket(const MachineInstr &MI) override;
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000079
80 void unpacketizeSoloInstrs(MachineFunction &MF);
81
82protected:
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +000083 bool isCallDependent(const MachineInstr &MI, SDep::Kind DepType,
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000084 unsigned DepReg);
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +000085 bool promoteToDotCur(MachineInstr &MI, SDep::Kind DepType,
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000086 MachineBasicBlock::iterator &MII,
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +000087 const TargetRegisterClass *RC);
88 bool canPromoteToDotCur(const MachineInstr &MI, const SUnit *PacketSU,
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000089 unsigned DepReg, MachineBasicBlock::iterator &MII,
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +000090 const TargetRegisterClass *RC);
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000091 void cleanUpDotCur();
92
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +000093 bool promoteToDotNew(MachineInstr &MI, SDep::Kind DepType,
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000094 MachineBasicBlock::iterator &MII,
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +000095 const TargetRegisterClass *RC);
96 bool canPromoteToDotNew(const MachineInstr &MI, const SUnit *PacketSU,
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000097 unsigned DepReg, MachineBasicBlock::iterator &MII,
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +000098 const TargetRegisterClass *RC);
99 bool canPromoteToNewValue(const MachineInstr &MI, const SUnit *PacketSU,
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +0000100 unsigned DepReg, MachineBasicBlock::iterator &MII);
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +0000101 bool canPromoteToNewValueStore(const MachineInstr &MI,
102 const MachineInstr &PacketMI, unsigned DepReg);
103 bool demoteToDotOld(MachineInstr &MI);
104 bool useCallersSP(MachineInstr &MI);
105 void useCalleesSP(MachineInstr &MI);
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +0000106 bool arePredicatesComplements(MachineInstr &MI1, MachineInstr &MI2);
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +0000107 bool restrictingDepExistInPacket(MachineInstr&, unsigned);
108 bool isNewifiable(const MachineInstr &MI, const TargetRegisterClass *NewRC);
109 bool isCurifiable(MachineInstr &MI);
110 bool cannotCoexist(const MachineInstr &MI, const MachineInstr &MJ);
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +0000111 inline bool isPromotedToDotNew() const {
112 return PromotedToDotNew;
113 }
114 bool tryAllocateResourcesForConstExt(bool Reserve);
115 bool canReserveResourcesForConstExt();
116 void reserveResourcesForConstExt();
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +0000117 bool hasDeadDependence(const MachineInstr &I, const MachineInstr &J);
118 bool hasControlDependence(const MachineInstr &I, const MachineInstr &J);
Krzysztof Parzyszek1aaf41a2017-02-17 22:14:51 +0000119 bool hasRegMaskDependence(const MachineInstr &I, const MachineInstr &J);
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +0000120 bool hasV4SpecificDependence(const MachineInstr &I, const MachineInstr &J);
121 bool producesStall(const MachineInstr &MI);
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +0000122};
123} // namespace llvm
124#endif // HEXAGONVLIWPACKETIZER_H
125