blob: daa86b6f53933d47e6e1b964b30af577578d708c [file] [log] [blame]
Eugene Zelenko3b873362017-09-28 22:27:31 +00001//===- HexagonPacketizer.h - VLIW packetizer --------------------*- C++ -*-===//
2//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Eugene Zelenko3b873362017-09-28 22:27:31 +00006//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIB_TARGET_HEXAGON_HEXAGONVLIWPACKETIZER_H
10#define LLVM_LIB_TARGET_HEXAGON_HEXAGONVLIWPACKETIZER_H
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000011
12#include "llvm/CodeGen/DFAPacketizer.h"
Eugene Zelenko3b873362017-09-28 22:27:31 +000013#include "llvm/CodeGen/MachineBasicBlock.h"
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000014#include "llvm/CodeGen/ScheduleDAG.h"
Eugene Zelenko3b873362017-09-28 22:27:31 +000015#include <vector>
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000016
17namespace llvm {
Eugene Zelenko3b873362017-09-28 22:27:31 +000018
Benjamin Kramer73564982017-01-30 14:55:33 +000019class HexagonInstrInfo;
20class HexagonRegisterInfo;
Eugene Zelenko3b873362017-09-28 22:27:31 +000021class MachineBranchProbabilityInfo;
22class MachineFunction;
23class MachineInstr;
24class MachineLoopInfo;
25class TargetRegisterClass;
Benjamin Kramer73564982017-01-30 14:55:33 +000026
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000027class HexagonPacketizerList : public VLIWPacketizerList {
28 // Vector of instructions assigned to the packet that has just been created.
Eugene Zelenko3b873362017-09-28 22:27:31 +000029 std::vector<MachineInstr *> OldPacketMIs;
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000030
31 // Has the instruction been promoted to a dot-new instruction.
32 bool PromotedToDotNew;
33
34 // Has the instruction been glued to allocframe.
35 bool GlueAllocframeStore;
36
37 // Has the feeder instruction been glued to new value jump.
38 bool GlueToNewValueJump;
39
Krzysztof Parzyszek8f174dd2017-10-11 15:51:44 +000040 // This holds the offset value, when pruning the dependences.
41 int64_t ChangedOffset;
42
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000043 // Check if there is a dependence between some instruction already in this
44 // packet and this instruction.
45 bool Dependence;
46
47 // Only check for dependence if there are resources available to
48 // schedule this instruction.
49 bool FoundSequentialDependence;
50
Krzysztof Parzyszeka8ab1b72017-12-11 18:57:54 +000051 bool MemShufDisabled = false;
52
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000053 // Track MIs with ignored dependence.
54 std::vector<MachineInstr*> IgnoreDepMIs;
55
Krzysztof Parzyszek9aaf9232017-05-02 18:12:19 +000056 // Set to true if the packet contains an instruction that stalls with an
57 // instruction from the previous packet.
Krzysztof Parzyszekfca6fae2017-05-02 18:29:49 +000058 bool PacketStalls = false;
Krzysztof Parzyszek9aaf9232017-05-02 18:12:19 +000059
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000060protected:
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000061 /// A handle to the branch probability pass.
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000062 const MachineBranchProbabilityInfo *MBPI;
63 const MachineLoopInfo *MLI;
64
65private:
66 const HexagonInstrInfo *HII;
67 const HexagonRegisterInfo *HRI;
Krzysztof Parzyszek39a979c2018-08-17 14:24:24 +000068 const bool Minimal;
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000069
70public:
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000071 HexagonPacketizerList(MachineFunction &MF, MachineLoopInfo &MLI,
72 AliasAnalysis *AA,
Krzysztof Parzyszek39a979c2018-08-17 14:24:24 +000073 const MachineBranchProbabilityInfo *MBPI,
74 bool Minimal);
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000075
76 // initPacketizerState - initialize some internal flags.
77 void initPacketizerState() override;
78
79 // ignorePseudoInstruction - Ignore bundling of pseudo instructions.
Duncan P. N. Exon Smith57022872016-02-27 19:09:00 +000080 bool ignorePseudoInstruction(const MachineInstr &MI,
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000081 const MachineBasicBlock *MBB) override;
82
83 // isSoloInstruction - return true if instruction MI can not be packetized
84 // with any other instruction, which means that MI itself is a packet.
Duncan P. N. Exon Smith57022872016-02-27 19:09:00 +000085 bool isSoloInstruction(const MachineInstr &MI) override;
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +000086
87 // isLegalToPacketizeTogether - Is it legal to packetize SUI and SUJ
88 // together.
89 bool isLegalToPacketizeTogether(SUnit *SUI, SUnit *SUJ) override;
90
91 // isLegalToPruneDependencies - Is it legal to prune dependece between SUI
92 // and SUJ.
93 bool isLegalToPruneDependencies(SUnit *SUI, SUnit *SUJ) override;
94
Krzysztof Parzyszeka8ab1b72017-12-11 18:57:54 +000095 bool foundLSInPacket();
Duncan P. N. Exon Smith57022872016-02-27 19:09:00 +000096 MachineBasicBlock::iterator addToPacket(MachineInstr &MI) override;
97 void endPacket(MachineBasicBlock *MBB,
98 MachineBasicBlock::iterator MI) override;
99 bool shouldAddToPacket(const MachineInstr &MI) override;
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +0000100
101 void unpacketizeSoloInstrs(MachineFunction &MF);
102
103protected:
Krzysztof Parzyszeka8ab1b72017-12-11 18:57:54 +0000104 bool getmemShufDisabled() {
105 return MemShufDisabled;
106 };
107 void setmemShufDisabled(bool val) {
108 MemShufDisabled = val;
109 };
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +0000110 bool isCallDependent(const MachineInstr &MI, SDep::Kind DepType,
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +0000111 unsigned DepReg);
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +0000112 bool promoteToDotCur(MachineInstr &MI, SDep::Kind DepType,
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +0000113 MachineBasicBlock::iterator &MII,
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +0000114 const TargetRegisterClass *RC);
115 bool canPromoteToDotCur(const MachineInstr &MI, const SUnit *PacketSU,
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +0000116 unsigned DepReg, MachineBasicBlock::iterator &MII,
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +0000117 const TargetRegisterClass *RC);
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +0000118 void cleanUpDotCur();
119
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +0000120 bool promoteToDotNew(MachineInstr &MI, SDep::Kind DepType,
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +0000121 MachineBasicBlock::iterator &MII,
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +0000122 const TargetRegisterClass *RC);
123 bool canPromoteToDotNew(const MachineInstr &MI, const SUnit *PacketSU,
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +0000124 unsigned DepReg, MachineBasicBlock::iterator &MII,
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +0000125 const TargetRegisterClass *RC);
126 bool canPromoteToNewValue(const MachineInstr &MI, const SUnit *PacketSU,
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +0000127 unsigned DepReg, MachineBasicBlock::iterator &MII);
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +0000128 bool canPromoteToNewValueStore(const MachineInstr &MI,
129 const MachineInstr &PacketMI, unsigned DepReg);
130 bool demoteToDotOld(MachineInstr &MI);
131 bool useCallersSP(MachineInstr &MI);
132 void useCalleesSP(MachineInstr &MI);
Krzysztof Parzyszek8f174dd2017-10-11 15:51:44 +0000133 bool updateOffset(SUnit *SUI, SUnit *SUJ);
134 void undoChangedOffset(MachineInstr &MI);
Duncan P. N. Exon Smith6307eb52016-02-23 02:46:52 +0000135 bool arePredicatesComplements(MachineInstr &MI1, MachineInstr &MI2);
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +0000136 bool restrictingDepExistInPacket(MachineInstr&, unsigned);
137 bool isNewifiable(const MachineInstr &MI, const TargetRegisterClass *NewRC);
138 bool isCurifiable(MachineInstr &MI);
139 bool cannotCoexist(const MachineInstr &MI, const MachineInstr &MJ);
Eugene Zelenko3b873362017-09-28 22:27:31 +0000140
141 bool isPromotedToDotNew() const {
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +0000142 return PromotedToDotNew;
143 }
Eugene Zelenko3b873362017-09-28 22:27:31 +0000144
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +0000145 bool tryAllocateResourcesForConstExt(bool Reserve);
146 bool canReserveResourcesForConstExt();
147 void reserveResourcesForConstExt();
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +0000148 bool hasDeadDependence(const MachineInstr &I, const MachineInstr &J);
149 bool hasControlDependence(const MachineInstr &I, const MachineInstr &J);
Krzysztof Parzyszek1aaf41a2017-02-17 22:14:51 +0000150 bool hasRegMaskDependence(const MachineInstr &I, const MachineInstr &J);
Krzysztof Parzyszek6bfc6572018-10-19 17:31:11 +0000151 bool hasDualStoreDependence(const MachineInstr &I, const MachineInstr &J);
Krzysztof Parzyszekf0b34a52016-07-29 21:49:42 +0000152 bool producesStall(const MachineInstr &MI);
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +0000153};
Krzysztof Parzyszek56bbf542015-12-16 19:36:12 +0000154
Eugene Zelenko3b873362017-09-28 22:27:31 +0000155} // end namespace llvm
156
157#endif // LLVM_LIB_TARGET_HEXAGON_HEXAGONVLIWPACKETIZER_H