blob: cf21316ec22dd4ebfdb9a1bc04a79a75c71e67f8 [file] [log] [blame]
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +00001//=- llvm/CodeGen/DFAPacketizer.cpp - DFA Packetizer for VLIW -*- 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// This class implements a deterministic finite automaton (DFA) based
10// packetizing mechanism for VLIW architectures. It provides APIs to
11// determine whether there exists a legal mapping of instructions to
12// functional unit assignments in a packet. The DFA is auto-generated from
13// the target's Schedule.td file.
14//
15// A DFA consists of 3 major elements: states, inputs, and transitions. For
16// the packetizing mechanism, the input is the set of instruction classes for
17// a target. The state models all possible combinations of functional unit
18// consumption for a given set of instructions in a packet. A transition
19// models the addition of an instruction to a packet. In the DFA constructed
20// by this class, if an instruction can be added to a packet, then a valid
21// transition exists from the corresponding state. Invalid transitions
22// indicate that the instruction cannot be added to the current packet.
23//
24//===----------------------------------------------------------------------===//
25
26#include "llvm/CodeGen/DFAPacketizer.h"
Eugene Zelenko6ac7a342017-06-07 23:53:32 +000027#include "llvm/CodeGen/MachineFunction.h"
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +000028#include "llvm/CodeGen/MachineInstr.h"
Andrew Trick7a35fae2012-02-15 18:55:14 +000029#include "llvm/CodeGen/MachineInstrBundle.h"
Eugene Zelenko6ac7a342017-06-07 23:53:32 +000030#include "llvm/CodeGen/ScheduleDAG.h"
Chandler Carruthed0881b2012-12-03 16:50:05 +000031#include "llvm/CodeGen/ScheduleDAGInstrs.h"
Eugene Zelenko6ac7a342017-06-07 23:53:32 +000032#include "llvm/MC/MCInstrDesc.h"
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +000033#include "llvm/MC/MCInstrItineraries.h"
Krzysztof Parzyszeke4582d42016-08-19 21:12:52 +000034#include "llvm/Support/CommandLine.h"
Eugene Zelenko6ac7a342017-06-07 23:53:32 +000035#include "llvm/Support/Debug.h"
36#include "llvm/Support/raw_ostream.h"
Chandler Carruth6bda14b2017-06-06 11:49:48 +000037#include "llvm/Target/TargetInstrInfo.h"
Eugene Zelenko6ac7a342017-06-07 23:53:32 +000038#include "llvm/Target/TargetSubtargetInfo.h"
39#include <algorithm>
40#include <cassert>
41#include <iterator>
42#include <memory>
43#include <vector>
Krzysztof Parzyszekc005e202016-01-14 21:17:04 +000044
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +000045using namespace llvm;
46
Eugene Zelenko6ac7a342017-06-07 23:53:32 +000047#define DEBUG_TYPE "packets"
48
Krzysztof Parzyszeke4582d42016-08-19 21:12:52 +000049static cl::opt<unsigned> InstrLimit("dfa-instr-limit", cl::Hidden,
50 cl::init(0), cl::desc("If present, stops packetizing after N instructions"));
Eugene Zelenko6ac7a342017-06-07 23:53:32 +000051
Krzysztof Parzyszeke4582d42016-08-19 21:12:52 +000052static unsigned InstrCount = 0;
53
Krzysztof Parzyszek6753f332015-11-22 15:20:19 +000054// --------------------------------------------------------------------
55// Definitions shared between DFAPacketizer.cpp and DFAPacketizerEmitter.cpp
56
Eugene Zelenko6ac7a342017-06-07 23:53:32 +000057static DFAInput addDFAFuncUnits(DFAInput Inp, unsigned FuncUnits) {
58 return (Inp << DFA_MAX_RESOURCES) | FuncUnits;
Krzysztof Parzyszek6753f332015-11-22 15:20:19 +000059}
Eugene Zelenko6ac7a342017-06-07 23:53:32 +000060
61/// Return the DFAInput for an instruction class input vector.
62/// This function is used in both DFAPacketizer.cpp and in
63/// DFAPacketizerEmitter.cpp.
64static DFAInput getDFAInsnInput(const std::vector<unsigned> &InsnClass) {
65 DFAInput InsnInput = 0;
66 assert((InsnClass.size() <= DFA_MAX_RESTERMS) &&
67 "Exceeded maximum number of DFA terms");
68 for (auto U : InsnClass)
69 InsnInput = addDFAFuncUnits(InsnInput, U);
70 return InsnInput;
71}
72
Krzysztof Parzyszek6753f332015-11-22 15:20:19 +000073// --------------------------------------------------------------------
74
Krzysztof Parzyszekb4655722015-11-21 20:00:45 +000075DFAPacketizer::DFAPacketizer(const InstrItineraryData *I,
76 const DFAStateInput (*SIT)[2],
Sebastian Popac35a4d2011-12-06 17:34:16 +000077 const unsigned *SET):
Eugene Zelenko6ac7a342017-06-07 23:53:32 +000078 InstrItins(I), DFAStateInputTable(SIT), DFAStateEntryTable(SET) {
Krzysztof Parzyszekb4655722015-11-21 20:00:45 +000079 // Make sure DFA types are large enough for the number of terms & resources.
Benjamin Kramer3e9a5d32016-05-27 11:36:04 +000080 static_assert((DFA_MAX_RESTERMS * DFA_MAX_RESOURCES) <=
81 (8 * sizeof(DFAInput)),
82 "(DFA_MAX_RESTERMS * DFA_MAX_RESOURCES) too big for DFAInput");
83 static_assert(
84 (DFA_MAX_RESTERMS * DFA_MAX_RESOURCES) <= (8 * sizeof(DFAStateInput)),
85 "(DFA_MAX_RESTERMS * DFA_MAX_RESOURCES) too big for DFAStateInput");
Krzysztof Parzyszekb4655722015-11-21 20:00:45 +000086}
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +000087
Krzysztof Parzyszekc005e202016-01-14 21:17:04 +000088// Read the DFA transition table and update CachedTable.
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +000089//
90// Format of the transition tables:
91// DFAStateInputTable[][2] = pairs of <Input, Transition> for all valid
92// transitions
93// DFAStateEntryTable[i] = Index of the first entry in DFAStateInputTable
94// for the ith state
95//
96void DFAPacketizer::ReadTable(unsigned int state) {
97 unsigned ThisState = DFAStateEntryTable[state];
98 unsigned NextStateInTable = DFAStateEntryTable[state+1];
99 // Early exit in case CachedTable has already contains this
Sebastian Pop9aa61372011-12-06 17:34:11 +0000100 // state's transitions.
Krzysztof Parzyszekc005e202016-01-14 21:17:04 +0000101 if (CachedTable.count(UnsignPair(state, DFAStateInputTable[ThisState][0])))
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +0000102 return;
103
104 for (unsigned i = ThisState; i < NextStateInTable; i++)
105 CachedTable[UnsignPair(state, DFAStateInputTable[i][0])] =
106 DFAStateInputTable[i][1];
107}
108
Krzysztof Parzyszekc005e202016-01-14 21:17:04 +0000109// Return the DFAInput for an instruction class.
Krzysztof Parzyszekb4655722015-11-21 20:00:45 +0000110DFAInput DFAPacketizer::getInsnInput(unsigned InsnClass) {
111 // Note: this logic must match that in DFAPacketizerDefs.h for input vectors.
112 DFAInput InsnInput = 0;
113 unsigned i = 0;
Krzysztof Parzyszekc005e202016-01-14 21:17:04 +0000114 (void)i;
Krzysztof Parzyszekb4655722015-11-21 20:00:45 +0000115 for (const InstrStage *IS = InstrItins->beginStage(InsnClass),
Krzysztof Parzyszekc005e202016-01-14 21:17:04 +0000116 *IE = InstrItins->endStage(InsnClass); IS != IE; ++IS) {
Krzysztof Parzyszekb4655722015-11-21 20:00:45 +0000117 InsnInput = addDFAFuncUnits(InsnInput, IS->getUnits());
Krzysztof Parzyszekc005e202016-01-14 21:17:04 +0000118 assert((i++ < DFA_MAX_RESTERMS) && "Exceeded maximum number of DFA inputs");
Krzysztof Parzyszekb4655722015-11-21 20:00:45 +0000119 }
120 return InsnInput;
121}
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +0000122
Krzysztof Parzyszekc005e202016-01-14 21:17:04 +0000123// Return the DFAInput for an instruction class input vector.
Krzysztof Parzyszek6753f332015-11-22 15:20:19 +0000124DFAInput DFAPacketizer::getInsnInput(const std::vector<unsigned> &InsnClass) {
125 return getDFAInsnInput(InsnClass);
126}
127
Krzysztof Parzyszekc005e202016-01-14 21:17:04 +0000128// Check if the resources occupied by a MCInstrDesc are available in the
129// current state.
Eugene Zelenko6ac7a342017-06-07 23:53:32 +0000130bool DFAPacketizer::canReserveResources(const MCInstrDesc *MID) {
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +0000131 unsigned InsnClass = MID->getSchedClass();
Krzysztof Parzyszekb4655722015-11-21 20:00:45 +0000132 DFAInput InsnInput = getInsnInput(InsnClass);
133 UnsignPair StateTrans = UnsignPair(CurrentState, InsnInput);
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +0000134 ReadTable(CurrentState);
Krzysztof Parzyszekc005e202016-01-14 21:17:04 +0000135 return CachedTable.count(StateTrans) != 0;
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +0000136}
137
Krzysztof Parzyszekc005e202016-01-14 21:17:04 +0000138// Reserve the resources occupied by a MCInstrDesc and change the current
139// state to reflect that change.
Eugene Zelenko6ac7a342017-06-07 23:53:32 +0000140void DFAPacketizer::reserveResources(const MCInstrDesc *MID) {
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +0000141 unsigned InsnClass = MID->getSchedClass();
Krzysztof Parzyszekb4655722015-11-21 20:00:45 +0000142 DFAInput InsnInput = getInsnInput(InsnClass);
143 UnsignPair StateTrans = UnsignPair(CurrentState, InsnInput);
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +0000144 ReadTable(CurrentState);
145 assert(CachedTable.count(StateTrans) != 0);
146 CurrentState = CachedTable[StateTrans];
147}
148
Krzysztof Parzyszekc005e202016-01-14 21:17:04 +0000149// Check if the resources occupied by a machine instruction are available
150// in the current state.
Eugene Zelenko6ac7a342017-06-07 23:53:32 +0000151bool DFAPacketizer::canReserveResources(MachineInstr &MI) {
152 const MCInstrDesc &MID = MI.getDesc();
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +0000153 return canReserveResources(&MID);
154}
155
Krzysztof Parzyszekc005e202016-01-14 21:17:04 +0000156// Reserve the resources occupied by a machine instruction and change the
157// current state to reflect that change.
Eugene Zelenko6ac7a342017-06-07 23:53:32 +0000158void DFAPacketizer::reserveResources(MachineInstr &MI) {
159 const MCInstrDesc &MID = MI.getDesc();
Anshuman Dasgupta08ebdc12011-12-01 21:10:21 +0000160 reserveResources(&MID);
161}
Andrew Trick7a35fae2012-02-15 18:55:14 +0000162
Sirish Pande94212162012-05-01 21:28:30 +0000163namespace llvm {
Eugene Zelenko6ac7a342017-06-07 23:53:32 +0000164
Krzysztof Parzyszekc005e202016-01-14 21:17:04 +0000165// This class extends ScheduleDAGInstrs and overrides the schedule method
166// to build the dependence graph.
Andrew Trick7a35fae2012-02-15 18:55:14 +0000167class DefaultVLIWScheduler : public ScheduleDAGInstrs {
Krzysztof Parzyszekdac71022015-12-14 20:35:13 +0000168private:
169 AliasAnalysis *AA;
Krzysztof Parzyszek1a1d78b2016-03-08 15:33:51 +0000170 /// Ordered list of DAG postprocessing steps.
171 std::vector<std::unique_ptr<ScheduleDAGMutation>> Mutations;
Eugene Zelenko6ac7a342017-06-07 23:53:32 +0000172
Andrew Trick7a35fae2012-02-15 18:55:14 +0000173public:
Krzysztof Parzyszekdac71022015-12-14 20:35:13 +0000174 DefaultVLIWScheduler(MachineFunction &MF, MachineLoopInfo &MLI,
175 AliasAnalysis *AA);
Eugene Zelenko6ac7a342017-06-07 23:53:32 +0000176
Krzysztof Parzyszekc005e202016-01-14 21:17:04 +0000177 // Actual scheduling work.
Craig Topper4584cd52014-03-07 09:26:03 +0000178 void schedule() override;
Krzysztof Parzyszek1a1d78b2016-03-08 15:33:51 +0000179
180 /// DefaultVLIWScheduler takes ownership of the Mutation object.
181 void addMutation(std::unique_ptr<ScheduleDAGMutation> Mutation) {
182 Mutations.push_back(std::move(Mutation));
183 }
Eugene Zelenko6ac7a342017-06-07 23:53:32 +0000184
Krzysztof Parzyszek1a1d78b2016-03-08 15:33:51 +0000185protected:
186 void postprocessDAG();
Andrew Trick7a35fae2012-02-15 18:55:14 +0000187};
Andrew Trick20349b82012-02-15 23:34:15 +0000188
Eugene Zelenko6ac7a342017-06-07 23:53:32 +0000189} // end namespace llvm
Krzysztof Parzyszekc005e202016-01-14 21:17:04 +0000190
Alexey Samsonovea0aee62014-08-20 20:57:26 +0000191DefaultVLIWScheduler::DefaultVLIWScheduler(MachineFunction &MF,
Krzysztof Parzyszekdac71022015-12-14 20:35:13 +0000192 MachineLoopInfo &MLI,
193 AliasAnalysis *AA)
194 : ScheduleDAGInstrs(MF, &MLI), AA(AA) {
Sirish Pande94212162012-05-01 21:28:30 +0000195 CanHandleTerminators = true;
Andrew Trick7a35fae2012-02-15 18:55:14 +0000196}
197
Krzysztof Parzyszek1a1d78b2016-03-08 15:33:51 +0000198/// Apply each ScheduleDAGMutation step in order.
199void DefaultVLIWScheduler::postprocessDAG() {
200 for (auto &M : Mutations)
201 M->apply(this);
202}
203
Andrew Trick52226d42012-03-07 23:00:49 +0000204void DefaultVLIWScheduler::schedule() {
Andrew Trick7a35fae2012-02-15 18:55:14 +0000205 // Build the scheduling graph.
Krzysztof Parzyszekdac71022015-12-14 20:35:13 +0000206 buildSchedGraph(AA);
Krzysztof Parzyszek1a1d78b2016-03-08 15:33:51 +0000207 postprocessDAG();
Andrew Trick7a35fae2012-02-15 18:55:14 +0000208}
209
Krzysztof Parzyszekc005e202016-01-14 21:17:04 +0000210VLIWPacketizerList::VLIWPacketizerList(MachineFunction &mf,
211 MachineLoopInfo &mli, AliasAnalysis *aa)
212 : MF(mf), TII(mf.getSubtarget().getInstrInfo()), AA(aa) {
Eric Christopher143f02c2014-10-09 01:59:35 +0000213 ResourceTracker = TII->CreateTargetScheduleState(MF.getSubtarget());
Krzysztof Parzyszekc005e202016-01-14 21:17:04 +0000214 VLIWScheduler = new DefaultVLIWScheduler(MF, mli, AA);
Andrew Trick7a35fae2012-02-15 18:55:14 +0000215}
216
Andrew Trick7a35fae2012-02-15 18:55:14 +0000217VLIWPacketizerList::~VLIWPacketizerList() {
Gabor Horvath43b72d52017-05-01 16:18:42 +0000218 delete VLIWScheduler;
219 delete ResourceTracker;
Andrew Trick7a35fae2012-02-15 18:55:14 +0000220}
221
Krzysztof Parzyszekc005e202016-01-14 21:17:04 +0000222// End the current packet, bundle packet instructions and reset DFA state.
Duncan P. N. Exon Smith57022872016-02-27 19:09:00 +0000223void VLIWPacketizerList::endPacket(MachineBasicBlock *MBB,
224 MachineBasicBlock::iterator MI) {
Krzysztof Parzyszeke4582d42016-08-19 21:12:52 +0000225 DEBUG({
226 if (!CurrentPacketMIs.empty()) {
227 dbgs() << "Finalizing packet:\n";
228 for (MachineInstr *MI : CurrentPacketMIs)
229 dbgs() << " * " << *MI;
230 }
231 });
Andrew Trick7a35fae2012-02-15 18:55:14 +0000232 if (CurrentPacketMIs.size() > 1) {
Duncan P. N. Exon Smith57022872016-02-27 19:09:00 +0000233 MachineInstr &MIFirst = *CurrentPacketMIs.front();
234 finalizeBundle(*MBB, MIFirst.getIterator(), MI.getInstrIterator());
Andrew Trick7a35fae2012-02-15 18:55:14 +0000235 }
236 CurrentPacketMIs.clear();
237 ResourceTracker->clearResources();
Krzysztof Parzyszek31ceba72016-07-14 19:04:26 +0000238 DEBUG(dbgs() << "End packet\n");
Andrew Trick7a35fae2012-02-15 18:55:14 +0000239}
240
Krzysztof Parzyszekc005e202016-01-14 21:17:04 +0000241// Bundle machine instructions into packets.
Andrew Trick7a35fae2012-02-15 18:55:14 +0000242void VLIWPacketizerList::PacketizeMIs(MachineBasicBlock *MBB,
243 MachineBasicBlock::iterator BeginItr,
244 MachineBasicBlock::iterator EndItr) {
Sirish Pande94212162012-05-01 21:28:30 +0000245 assert(VLIWScheduler && "VLIW Scheduler is not initialized!");
246 VLIWScheduler->startBlock(MBB);
Andrew Tricka53e1012013-08-23 17:48:33 +0000247 VLIWScheduler->enterRegion(MBB, BeginItr, EndItr,
248 std::distance(BeginItr, EndItr));
Sirish Pande94212162012-05-01 21:28:30 +0000249 VLIWScheduler->schedule();
Andrew Trick69b42042012-03-07 23:01:09 +0000250
Krzysztof Parzyszek31ceba72016-07-14 19:04:26 +0000251 DEBUG({
252 dbgs() << "Scheduling DAG of the packetize region\n";
253 for (SUnit &SU : VLIWScheduler->SUnits)
254 SU.dumpAll(VLIWScheduler);
255 });
256
Sirish Pande94212162012-05-01 21:28:30 +0000257 // Generate MI -> SU map.
258 MIToSUnit.clear();
Krzysztof Parzyszekc005e202016-01-14 21:17:04 +0000259 for (SUnit &SU : VLIWScheduler->SUnits)
260 MIToSUnit[SU.getInstr()] = &SU;
Andrew Trick7a35fae2012-02-15 18:55:14 +0000261
Krzysztof Parzyszeke4582d42016-08-19 21:12:52 +0000262 bool LimitPresent = InstrLimit.getPosition();
263
Andrew Trick7a35fae2012-02-15 18:55:14 +0000264 // The main packetizer loop.
265 for (; BeginItr != EndItr; ++BeginItr) {
Krzysztof Parzyszeke4582d42016-08-19 21:12:52 +0000266 if (LimitPresent) {
267 if (InstrCount >= InstrLimit) {
268 EndItr = BeginItr;
269 break;
270 }
271 InstrCount++;
272 }
Duncan P. N. Exon Smith57022872016-02-27 19:09:00 +0000273 MachineInstr &MI = *BeginItr;
Krzysztof Parzyszekc005e202016-01-14 21:17:04 +0000274 initPacketizerState();
Andrew Trick7a35fae2012-02-15 18:55:14 +0000275
276 // End the current packet if needed.
Krzysztof Parzyszekc005e202016-01-14 21:17:04 +0000277 if (isSoloInstruction(MI)) {
Andrew Trick7a35fae2012-02-15 18:55:14 +0000278 endPacket(MBB, MI);
279 continue;
280 }
281
Sirish Pande94212162012-05-01 21:28:30 +0000282 // Ignore pseudo instructions.
Krzysztof Parzyszekc005e202016-01-14 21:17:04 +0000283 if (ignorePseudoInstruction(MI, MBB))
Sirish Pande94212162012-05-01 21:28:30 +0000284 continue;
285
Duncan P. N. Exon Smith57022872016-02-27 19:09:00 +0000286 SUnit *SUI = MIToSUnit[&MI];
Andrew Trick7a35fae2012-02-15 18:55:14 +0000287 assert(SUI && "Missing SUnit Info!");
288
289 // Ask DFA if machine resource is available for MI.
Krzysztof Parzyszek31ceba72016-07-14 19:04:26 +0000290 DEBUG(dbgs() << "Checking resources for adding MI to packet " << MI);
291
Andrew Trick7a35fae2012-02-15 18:55:14 +0000292 bool ResourceAvail = ResourceTracker->canReserveResources(MI);
Krzysztof Parzyszek31ceba72016-07-14 19:04:26 +0000293 DEBUG({
294 if (ResourceAvail)
295 dbgs() << " Resources are available for adding MI to packet\n";
296 else
297 dbgs() << " Resources NOT available\n";
298 });
Krzysztof Parzyszek2005d7d2015-12-16 16:38:16 +0000299 if (ResourceAvail && shouldAddToPacket(MI)) {
Andrew Trick7a35fae2012-02-15 18:55:14 +0000300 // Dependency check for MI with instructions in CurrentPacketMIs.
Krzysztof Parzyszekc005e202016-01-14 21:17:04 +0000301 for (auto MJ : CurrentPacketMIs) {
Sirish Pande94212162012-05-01 21:28:30 +0000302 SUnit *SUJ = MIToSUnit[MJ];
Andrew Trick7a35fae2012-02-15 18:55:14 +0000303 assert(SUJ && "Missing SUnit Info!");
304
Krzysztof Parzyszek31ceba72016-07-14 19:04:26 +0000305 DEBUG(dbgs() << " Checking against MJ " << *MJ);
Andrew Trick7a35fae2012-02-15 18:55:14 +0000306 // Is it legal to packetize SUI and SUJ together.
Krzysztof Parzyszekc005e202016-01-14 21:17:04 +0000307 if (!isLegalToPacketizeTogether(SUI, SUJ)) {
Krzysztof Parzyszek31ceba72016-07-14 19:04:26 +0000308 DEBUG(dbgs() << " Not legal to add MI, try to prune\n");
Andrew Trick7a35fae2012-02-15 18:55:14 +0000309 // Allow packetization if dependency can be pruned.
Krzysztof Parzyszekc005e202016-01-14 21:17:04 +0000310 if (!isLegalToPruneDependencies(SUI, SUJ)) {
Andrew Trick7a35fae2012-02-15 18:55:14 +0000311 // End the packet if dependency cannot be pruned.
Krzysztof Parzyszek31ceba72016-07-14 19:04:26 +0000312 DEBUG(dbgs() << " Could not prune dependencies for adding MI\n");
Andrew Trick7a35fae2012-02-15 18:55:14 +0000313 endPacket(MBB, MI);
314 break;
Krzysztof Parzyszekc005e202016-01-14 21:17:04 +0000315 }
Krzysztof Parzyszek31ceba72016-07-14 19:04:26 +0000316 DEBUG(dbgs() << " Pruned dependence for adding MI\n");
Krzysztof Parzyszekc005e202016-01-14 21:17:04 +0000317 }
318 }
Andrew Trick7a35fae2012-02-15 18:55:14 +0000319 } else {
Krzysztof Parzyszek31ceba72016-07-14 19:04:26 +0000320 DEBUG(if (ResourceAvail)
321 dbgs() << "Resources are available, but instruction should not be "
322 "added to packet\n " << MI);
Krzysztof Parzyszek2005d7d2015-12-16 16:38:16 +0000323 // End the packet if resource is not available, or if the instruction
324 // shoud not be added to the current packet.
Andrew Trick7a35fae2012-02-15 18:55:14 +0000325 endPacket(MBB, MI);
326 }
327
328 // Add MI to the current packet.
Krzysztof Parzyszek31ceba72016-07-14 19:04:26 +0000329 DEBUG(dbgs() << "* Adding MI to packet " << MI << '\n');
Krzysztof Parzyszekc005e202016-01-14 21:17:04 +0000330 BeginItr = addToPacket(MI);
331 } // For all instructions in the packetization range.
Andrew Trick7a35fae2012-02-15 18:55:14 +0000332
333 // End any packet left behind.
334 endPacket(MBB, EndItr);
Sirish Pande94212162012-05-01 21:28:30 +0000335 VLIWScheduler->exitRegion();
336 VLIWScheduler->finishBlock();
Andrew Trick7a35fae2012-02-15 18:55:14 +0000337}
Krzysztof Parzyszek1a1d78b2016-03-08 15:33:51 +0000338
Krzysztof Parzyszek9d19c8c2017-10-20 22:08:40 +0000339bool VLIWPacketizerList::alias(const MachineMemOperand &Op1,
340 const MachineMemOperand &Op2,
341 bool UseTBAA) const {
342 if (!Op1.getValue() || !Op2.getValue())
343 return true;
344
345 int64_t MinOffset = std::min(Op1.getOffset(), Op2.getOffset());
346 int64_t Overlapa = Op1.getSize() + Op1.getOffset() - MinOffset;
347 int64_t Overlapb = Op2.getSize() + Op2.getOffset() - MinOffset;
348
349 AliasResult AAResult =
350 AA->alias(MemoryLocation(Op1.getValue(), Overlapa,
351 UseTBAA ? Op1.getAAInfo() : AAMDNodes()),
352 MemoryLocation(Op2.getValue(), Overlapb,
353 UseTBAA ? Op2.getAAInfo() : AAMDNodes()));
354
355 return AAResult != NoAlias;
356}
357
358bool VLIWPacketizerList::alias(const MachineInstr &MI1,
359 const MachineInstr &MI2,
360 bool UseTBAA) const {
361 if (MI1.memoperands_empty() || MI2.memoperands_empty())
362 return true;
363
364 for (const MachineMemOperand *Op1 : MI1.memoperands())
365 for (const MachineMemOperand *Op2 : MI2.memoperands())
366 if (alias(*Op1, *Op2, UseTBAA))
367 return true;
368 return false;
369}
370
Krzysztof Parzyszek1a1d78b2016-03-08 15:33:51 +0000371// Add a DAG mutation object to the ordered list.
372void VLIWPacketizerList::addMutation(
373 std::unique_ptr<ScheduleDAGMutation> Mutation) {
374 VLIWScheduler->addMutation(std::move(Mutation));
375}