blob: 764d9ae9059a0588615a0a82c754af2d114326e4 [file] [log] [blame]
Eugene Zelenko3b873362017-09-28 22:27:31 +00001//===- HexagonPacketizer.h - VLIW packetizer --------------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LLVM_LIB_TARGET_HEXAGON_HEXAGONVLIWPACKETIZER_H
11#define LLVM_LIB_TARGET_HEXAGON_HEXAGONVLIWPACKETIZER_H
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000012
13#include "llvm/CodeGen/DFAPacketizer.h"
Eugene Zelenko3b873362017-09-28 22:27:31 +000014#include "llvm/CodeGen/MachineBasicBlock.h"
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000015#include "llvm/CodeGen/ScheduleDAG.h"
Eugene Zelenko3b873362017-09-28 22:27:31 +000016#include <vector>
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000017
18namespace llvm {
Eugene Zelenko3b873362017-09-28 22:27:31 +000019
Benjamin Kramer73564982017-01-30 14:55:33 +000020class HexagonInstrInfo;
21class HexagonRegisterInfo;
Eugene Zelenko3b873362017-09-28 22:27:31 +000022class MachineBranchProbabilityInfo;
23class MachineFunction;
24class MachineInstr;
25class MachineLoopInfo;
26class TargetRegisterClass;
Benjamin Kramer73564982017-01-30 14:55:33 +000027
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000028class HexagonPacketizerList : public VLIWPacketizerList {
29 // Vector of instructions assigned to the packet that has just been created.
Eugene Zelenko3b873362017-09-28 22:27:31 +000030 std::vector<MachineInstr *> OldPacketMIs;
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000031
32 // Has the instruction been promoted to a dot-new instruction.
33 bool PromotedToDotNew;
34
35 // Has the instruction been glued to allocframe.
36 bool GlueAllocframeStore;
37
38 // Has the feeder instruction been glued to new value jump.
39 bool GlueToNewValueJump;
40
Krzysztof Parzyszek8f174dd2017-10-11 15:51:44 +000041 // This holds the offset value, when pruning the dependences.
42 int64_t ChangedOffset;
43
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000044 // Check if there is a dependence between some instruction already in this
45 // packet and this instruction.
46 bool Dependence;
47
48 // Only check for dependence if there are resources available to
49 // schedule this instruction.
50 bool FoundSequentialDependence;
51
Krzysztof Parzyszeka8ab1b72017-12-11 18:57:54 +000052 bool MemShufDisabled = false;
53
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000054 // Track MIs with ignored dependence.
55 std::vector<MachineInstr*> IgnoreDepMIs;
56
Krzysztof Parzyszek9aaf9232017-05-02 18:12:19 +000057 // Set to true if the packet contains an instruction that stalls with an
58 // instruction from the previous packet.
Krzysztof Parzyszekfca6fae2017-05-02 18:29:49 +000059 bool PacketStalls = false;
Krzysztof Parzyszek9aaf9232017-05-02 18:12:19 +000060
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000061protected:
62 /// \brief A handle to the branch probability pass.
63 const MachineBranchProbabilityInfo *MBPI;
64 const MachineLoopInfo *MLI;
65
66private:
67 const HexagonInstrInfo *HII;
68 const HexagonRegisterInfo *HRI;
69
70public:
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000071 HexagonPacketizerList(MachineFunction &MF, MachineLoopInfo &MLI,
72 AliasAnalysis *AA,
73 const MachineBranchProbabilityInfo *MBPI);
74
75 // initPacketizerState - initialize some internal flags.
76 void initPacketizerState() override;
77
78 // ignorePseudoInstruction - Ignore bundling of pseudo instructions.
Duncan P. N. Exon Smith57022872016-02-27 19:09:00 +000079 bool ignorePseudoInstruction(const MachineInstr &MI,
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000080 const MachineBasicBlock *MBB) override;
81
82 // isSoloInstruction - return true if instruction MI can not be packetized
83 // with any other instruction, which means that MI itself is a packet.
Duncan P. N. Exon Smith57022872016-02-27 19:09:00 +000084 bool isSoloInstruction(const MachineInstr &MI) override;
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000085
86 // isLegalToPacketizeTogether - Is it legal to packetize SUI and SUJ
87 // together.
88 bool isLegalToPacketizeTogether(SUnit *SUI, SUnit *SUJ) override;
89
90 // isLegalToPruneDependencies - Is it legal to prune dependece between SUI
91 // and SUJ.
92 bool isLegalToPruneDependencies(SUnit *SUI, SUnit *SUJ) override;
93
Krzysztof Parzyszeka8ab1b72017-12-11 18:57:54 +000094 bool foundLSInPacket();
Duncan P. N. Exon Smith57022872016-02-27 19:09:00 +000095 MachineBasicBlock::iterator addToPacket(MachineInstr &MI) override;
96 void endPacket(MachineBasicBlock *MBB,
97 MachineBasicBlock::iterator MI) override;
98 bool shouldAddToPacket(const MachineInstr &MI) override;
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000099
100 void unpacketizeSoloInstrs(MachineFunction &MF);
101
102protected:
Krzysztof Parzyszeka8ab1b72017-12-11 18:57:54 +0000103 bool getmemShufDisabled() {
104 return MemShufDisabled;
105 };
106 void setmemShufDisabled(bool val) {
107 MemShufDisabled = val;
108 };
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +0000109 bool isCallDependent(const MachineInstr &MI, SDep::Kind DepType,
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +0000110 unsigned DepReg);
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +0000111 bool promoteToDotCur(MachineInstr &MI, SDep::Kind DepType,
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +0000112 MachineBasicBlock::iterator &MII,
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +0000113 const TargetRegisterClass *RC);
114 bool canPromoteToDotCur(const MachineInstr &MI, const SUnit *PacketSU,
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +0000115 unsigned DepReg, MachineBasicBlock::iterator &MII,
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +0000116 const TargetRegisterClass *RC);
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +0000117 void cleanUpDotCur();
118
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +0000119 bool promoteToDotNew(MachineInstr &MI, SDep::Kind DepType,
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +0000120 MachineBasicBlock::iterator &MII,
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +0000121 const TargetRegisterClass *RC);
122 bool canPromoteToDotNew(const MachineInstr &MI, const SUnit *PacketSU,
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +0000123 unsigned DepReg, MachineBasicBlock::iterator &MII,
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +0000124 const TargetRegisterClass *RC);
125 bool canPromoteToNewValue(const MachineInstr &MI, const SUnit *PacketSU,
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +0000126 unsigned DepReg, MachineBasicBlock::iterator &MII);
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +0000127 bool canPromoteToNewValueStore(const MachineInstr &MI,
128 const MachineInstr &PacketMI, unsigned DepReg);
129 bool demoteToDotOld(MachineInstr &MI);
130 bool useCallersSP(MachineInstr &MI);
131 void useCalleesSP(MachineInstr &MI);
Krzysztof Parzyszek8f174dd2017-10-11 15:51:44 +0000132 bool updateOffset(SUnit *SUI, SUnit *SUJ);
133 void undoChangedOffset(MachineInstr &MI);
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +0000134 bool arePredicatesComplements(MachineInstr &MI1, MachineInstr &MI2);
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +0000135 bool restrictingDepExistInPacket(MachineInstr&, unsigned);
136 bool isNewifiable(const MachineInstr &MI, const TargetRegisterClass *NewRC);
137 bool isCurifiable(MachineInstr &MI);
138 bool cannotCoexist(const MachineInstr &MI, const MachineInstr &MJ);
Eugene Zelenko3b873362017-09-28 22:27:31 +0000139
140 bool isPromotedToDotNew() const {
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +0000141 return PromotedToDotNew;
142 }
Eugene Zelenko3b873362017-09-28 22:27:31 +0000143
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +0000144 bool tryAllocateResourcesForConstExt(bool Reserve);
145 bool canReserveResourcesForConstExt();
146 void reserveResourcesForConstExt();
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +0000147 bool hasDeadDependence(const MachineInstr &I, const MachineInstr &J);
148 bool hasControlDependence(const MachineInstr &I, const MachineInstr &J);
Krzysztof Parzyszek1aaf41a2017-02-17 22:14:51 +0000149 bool hasRegMaskDependence(const MachineInstr &I, const MachineInstr &J);
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +0000150 bool hasV4SpecificDependence(const MachineInstr &I, const MachineInstr &J);
151 bool producesStall(const MachineInstr &MI);
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +0000152};
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +0000153
Eugene Zelenko3b873362017-09-28 22:27:31 +0000154} // end namespace llvm
155
156#endif // LLVM_LIB_TARGET_HEXAGON_HEXAGONVLIWPACKETIZER_H