blob: b28b926ec300becd7feab1e8932abc034b1ab15f [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 {
10class HexagonPacketizerList : public VLIWPacketizerList {
11 // Vector of instructions assigned to the packet that has just been created.
12 std::vector<MachineInstr*> OldPacketMIs;
13
14 // Has the instruction been promoted to a dot-new instruction.
15 bool PromotedToDotNew;
16
17 // Has the instruction been glued to allocframe.
18 bool GlueAllocframeStore;
19
20 // Has the feeder instruction been glued to new value jump.
21 bool GlueToNewValueJump;
22
23 // Check if there is a dependence between some instruction already in this
24 // packet and this instruction.
25 bool Dependence;
26
27 // Only check for dependence if there are resources available to
28 // schedule this instruction.
29 bool FoundSequentialDependence;
30
31 // Track MIs with ignored dependence.
32 std::vector<MachineInstr*> IgnoreDepMIs;
33
34protected:
35 /// \brief A handle to the branch probability pass.
36 const MachineBranchProbabilityInfo *MBPI;
37 const MachineLoopInfo *MLI;
38
39private:
40 const HexagonInstrInfo *HII;
41 const HexagonRegisterInfo *HRI;
42
43public:
44 // Ctor.
45 HexagonPacketizerList(MachineFunction &MF, MachineLoopInfo &MLI,
46 AliasAnalysis *AA,
47 const MachineBranchProbabilityInfo *MBPI);
48
49 // initPacketizerState - initialize some internal flags.
50 void initPacketizerState() override;
51
52 // ignorePseudoInstruction - Ignore bundling of pseudo instructions.
Duncan P. N. Exon Smith57022872016-02-27 19:09:00 +000053 bool ignorePseudoInstruction(const MachineInstr &MI,
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000054 const MachineBasicBlock *MBB) override;
55
56 // isSoloInstruction - return true if instruction MI can not be packetized
57 // with any other instruction, which means that MI itself is a packet.
Duncan P. N. Exon Smith57022872016-02-27 19:09:00 +000058 bool isSoloInstruction(const MachineInstr &MI) override;
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000059
60 // isLegalToPacketizeTogether - Is it legal to packetize SUI and SUJ
61 // together.
62 bool isLegalToPacketizeTogether(SUnit *SUI, SUnit *SUJ) override;
63
64 // isLegalToPruneDependencies - Is it legal to prune dependece between SUI
65 // and SUJ.
66 bool isLegalToPruneDependencies(SUnit *SUI, SUnit *SUJ) override;
67
Duncan P. N. Exon Smith57022872016-02-27 19:09:00 +000068 MachineBasicBlock::iterator addToPacket(MachineInstr &MI) override;
69 void endPacket(MachineBasicBlock *MBB,
70 MachineBasicBlock::iterator MI) override;
71 bool shouldAddToPacket(const MachineInstr &MI) override;
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000072
73 void unpacketizeSoloInstrs(MachineFunction &MF);
74
75protected:
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +000076 bool isCallDependent(const MachineInstr &MI, SDep::Kind DepType,
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000077 unsigned DepReg);
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +000078 bool promoteToDotCur(MachineInstr &MI, SDep::Kind DepType,
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000079 MachineBasicBlock::iterator &MII,
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +000080 const TargetRegisterClass *RC);
81 bool canPromoteToDotCur(const MachineInstr &MI, const SUnit *PacketSU,
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000082 unsigned DepReg, MachineBasicBlock::iterator &MII,
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +000083 const TargetRegisterClass *RC);
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000084 void cleanUpDotCur();
85
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +000086 bool promoteToDotNew(MachineInstr &MI, SDep::Kind DepType,
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000087 MachineBasicBlock::iterator &MII,
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +000088 const TargetRegisterClass *RC);
89 bool canPromoteToDotNew(const MachineInstr &MI, const SUnit *PacketSU,
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000090 unsigned DepReg, MachineBasicBlock::iterator &MII,
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +000091 const TargetRegisterClass *RC);
92 bool canPromoteToNewValue(const MachineInstr &MI, const SUnit *PacketSU,
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000093 unsigned DepReg, MachineBasicBlock::iterator &MII);
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +000094 bool canPromoteToNewValueStore(const MachineInstr &MI,
95 const MachineInstr &PacketMI, unsigned DepReg);
96 bool demoteToDotOld(MachineInstr &MI);
97 bool useCallersSP(MachineInstr &MI);
98 void useCalleesSP(MachineInstr &MI);
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +000099 bool arePredicatesComplements(MachineInstr &MI1, MachineInstr &MI2);
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +0000100 bool restrictingDepExistInPacket(MachineInstr&, unsigned);
101 bool isNewifiable(const MachineInstr &MI, const TargetRegisterClass *NewRC);
102 bool isCurifiable(MachineInstr &MI);
103 bool cannotCoexist(const MachineInstr &MI, const MachineInstr &MJ);
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +0000104 inline bool isPromotedToDotNew() const {
105 return PromotedToDotNew;
106 }
107 bool tryAllocateResourcesForConstExt(bool Reserve);
108 bool canReserveResourcesForConstExt();
109 void reserveResourcesForConstExt();
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +0000110 bool hasDeadDependence(const MachineInstr &I, const MachineInstr &J);
111 bool hasControlDependence(const MachineInstr &I, const MachineInstr &J);
112 bool hasV4SpecificDependence(const MachineInstr &I, const MachineInstr &J);
113 bool producesStall(const MachineInstr &MI);
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +0000114};
115} // namespace llvm
116#endif // HEXAGONVLIWPACKETIZER_H
117