blob: 7a4a9d443e5ec869c8fce96ace2c9a1599f483ea [file] [log] [blame]
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +00001//===--------------------- Dispatch.cpp -------------------------*- 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/// \file
10///
11/// This file implements methods declared by class RegisterFile, DispatchUnit
12/// and RetireControlUnit.
13///
14//===----------------------------------------------------------------------===//
15
16#include "Dispatch.h"
17#include "Backend.h"
Clement Courbet844f22d2018-03-13 13:11:01 +000018#include "HWEventListener.h"
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000019#include "Scheduler.h"
20#include "llvm/Support/Debug.h"
21
22using namespace llvm;
23
24#define DEBUG_TYPE "llvm-mca"
25
26namespace mca {
27
Andrea Di Biagio9da4d6d2018-04-03 13:36:24 +000028void RegisterFile::initialize(const MCSchedModel &SM, unsigned NumRegs) {
29 // Create a default register file that "sees" all the machine registers
30 // declared by the target. The number of physical registers in the default
31 // register file is set equal to `NumRegs`. A value of zero for `NumRegs`
32 // means: this register file has an unbounded number of physical registers.
33 addRegisterFile({} /* all registers */, NumRegs);
34 if (!SM.hasExtraProcessorInfo())
35 return;
Andrea Di Biagioe64f3b12018-03-18 15:33:27 +000036
Andrea Di Biagio9da4d6d2018-04-03 13:36:24 +000037 // For each user defined register file, allocate a RegisterMappingTracker
38 // object. The size of every register file, as well as the mapping between
39 // register files and register classes is specified via tablegen.
40 const MCExtraProcessorInfo &Info = SM.getExtraProcessorInfo();
41 for (unsigned I = 0, E = Info.NumRegisterFiles; I < E; ++I) {
42 const MCRegisterFileDesc &RF = Info.RegisterFiles[I];
43 // Skip invalid register files with zero physical registers.
44 unsigned Length = RF.NumRegisterCostEntries;
45 if (!RF.NumPhysRegs)
46 continue;
47 // The cost of a register definition is equivalent to the number of
48 // physical registers that are allocated at register renaming stage.
49 const MCRegisterCostEntry *FirstElt =
50 &Info.RegisterCostTable[RF.RegisterCostEntryIdx];
51 addRegisterFile(ArrayRef<MCRegisterCostEntry>(FirstElt, Length),
52 RF.NumPhysRegs);
53 }
54}
55
56void RegisterFile::addRegisterFile(ArrayRef<MCRegisterCostEntry> Entries,
57 unsigned NumPhysRegs) {
58 // A default register file is always allocated at index #0. That register file
59 // is mainly used to count the total number of mappings created by all
60 // register files at runtime. Users can limit the number of available physical
61 // registers in register file #0 through the command line flag
62 // `-register-file-size`.
63 unsigned RegisterFileIndex = RegisterFiles.size();
64 RegisterFiles.emplace_back(NumPhysRegs);
65
66 // Special case where there is no register class identifier in the set.
67 // An empty set of register classes means: this register file contains all
68 // the physical registers specified by the target.
69 if (Entries.empty()) {
70 for (std::pair<WriteState *, IndexPlusCostPairTy> &Mapping : RegisterMappings)
71 Mapping.second = std::make_pair(RegisterFileIndex, 1U);
72 return;
73 }
74
75 // Now update the cost of individual registers.
76 for (const MCRegisterCostEntry &RCE : Entries) {
77 const MCRegisterClass &RC = MRI.getRegClass(RCE.RegisterClassID);
78 for (const MCPhysReg Reg : RC) {
79 IndexPlusCostPairTy &Entry = RegisterMappings[Reg].second;
80 if (Entry.first) {
81 // The only register file that is allowed to overlap is the default
82 // register file at index #0. The analysis is inaccurate if register
83 // files overlap.
84 errs() << "warning: register " << MRI.getName(Reg)
85 << " defined in multiple register files.";
86 }
87 Entry.first = RegisterFileIndex;
88 Entry.second = RCE.Cost;
Andrea Di Biagioe64f3b12018-03-18 15:33:27 +000089 }
90 }
91}
92
Andrea Di Biagio9da4d6d2018-04-03 13:36:24 +000093void RegisterFile::createNewMappings(IndexPlusCostPairTy Entry,
Andrea Di Biagio12ef5262018-03-21 18:11:05 +000094 MutableArrayRef<unsigned> UsedPhysRegs) {
Andrea Di Biagio9da4d6d2018-04-03 13:36:24 +000095 unsigned RegisterFileIndex = Entry.first;
96 unsigned Cost = Entry.second;
97 if (RegisterFileIndex) {
Andrea Di Biagioe64f3b12018-03-18 15:33:27 +000098 RegisterMappingTracker &RMT = RegisterFiles[RegisterFileIndex];
Andrea Di Biagio9da4d6d2018-04-03 13:36:24 +000099 RMT.NumUsedMappings += Cost;
100 UsedPhysRegs[RegisterFileIndex] += Cost;
101 }
102
103 // Now update the default register mapping tracker.
104 RegisterFiles[0].NumUsedMappings += Cost;
105 UsedPhysRegs[0] += Cost;
Andrea Di Biagioe64f3b12018-03-18 15:33:27 +0000106}
107
Andrea Di Biagio9da4d6d2018-04-03 13:36:24 +0000108void RegisterFile::removeMappings(IndexPlusCostPairTy Entry,
Andrea Di Biagio12ef5262018-03-21 18:11:05 +0000109 MutableArrayRef<unsigned> FreedPhysRegs) {
Andrea Di Biagio9da4d6d2018-04-03 13:36:24 +0000110 unsigned RegisterFileIndex = Entry.first;
111 unsigned Cost = Entry.second;
112 if (RegisterFileIndex) {
Andrea Di Biagioe64f3b12018-03-18 15:33:27 +0000113 RegisterMappingTracker &RMT = RegisterFiles[RegisterFileIndex];
Andrea Di Biagio9da4d6d2018-04-03 13:36:24 +0000114 RMT.NumUsedMappings -= Cost;
115 FreedPhysRegs[RegisterFileIndex] += Cost;
116 }
117
118 // Now update the default register mapping tracker.
119 RegisterFiles[0].NumUsedMappings -= Cost;
120 FreedPhysRegs[0] += Cost;
Andrea Di Biagioe64f3b12018-03-18 15:33:27 +0000121}
122
Andrea Di Biagio12ef5262018-03-21 18:11:05 +0000123void RegisterFile::addRegisterMapping(WriteState &WS,
124 MutableArrayRef<unsigned> UsedPhysRegs) {
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000125 unsigned RegID = WS.getRegisterID();
126 assert(RegID && "Adding an invalid register definition?");
127
Andrea Di Biagioe64f3b12018-03-18 15:33:27 +0000128 RegisterMapping &Mapping = RegisterMappings[RegID];
129 Mapping.first = &WS;
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000130 for (MCSubRegIterator I(RegID, &MRI); I.isValid(); ++I)
Andrea Di Biagioe64f3b12018-03-18 15:33:27 +0000131 RegisterMappings[*I].first = &WS;
132
Andrea Di Biagio12ef5262018-03-21 18:11:05 +0000133 createNewMappings(Mapping.second, UsedPhysRegs);
134
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000135 // If this is a partial update, then we are done.
136 if (!WS.fullyUpdatesSuperRegs())
137 return;
138
139 for (MCSuperRegIterator I(RegID, &MRI); I.isValid(); ++I)
Andrea Di Biagioe64f3b12018-03-18 15:33:27 +0000140 RegisterMappings[*I].first = &WS;
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000141}
142
Andrea Di Biagio12ef5262018-03-21 18:11:05 +0000143void RegisterFile::invalidateRegisterMapping(
144 const WriteState &WS, MutableArrayRef<unsigned> FreedPhysRegs) {
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000145 unsigned RegID = WS.getRegisterID();
146 bool ShouldInvalidateSuperRegs = WS.fullyUpdatesSuperRegs();
147
148 assert(RegID != 0 && "Invalidating an already invalid register?");
149 assert(WS.getCyclesLeft() != -512 &&
150 "Invalidating a write of unknown cycles!");
151 assert(WS.getCyclesLeft() <= 0 && "Invalid cycles left for this write!");
Andrea Di Biagioe64f3b12018-03-18 15:33:27 +0000152 RegisterMapping &Mapping = RegisterMappings[RegID];
153 if (!Mapping.first)
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000154 return;
155
Andrea Di Biagio12ef5262018-03-21 18:11:05 +0000156 removeMappings(Mapping.second, FreedPhysRegs);
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000157
Andrea Di Biagioe64f3b12018-03-18 15:33:27 +0000158 if (Mapping.first == &WS)
159 Mapping.first = nullptr;
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000160
161 for (MCSubRegIterator I(RegID, &MRI); I.isValid(); ++I)
Andrea Di Biagioe64f3b12018-03-18 15:33:27 +0000162 if (RegisterMappings[*I].first == &WS)
163 RegisterMappings[*I].first = nullptr;
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000164
165 if (!ShouldInvalidateSuperRegs)
166 return;
167
168 for (MCSuperRegIterator I(RegID, &MRI); I.isValid(); ++I)
Andrea Di Biagioe64f3b12018-03-18 15:33:27 +0000169 if (RegisterMappings[*I].first == &WS)
170 RegisterMappings[*I].first = nullptr;
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000171}
172
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000173void RegisterFile::collectWrites(SmallVectorImpl<WriteState *> &Writes,
174 unsigned RegID) const {
175 assert(RegID && RegID < RegisterMappings.size());
Andrea Di Biagioe64f3b12018-03-18 15:33:27 +0000176 WriteState *WS = RegisterMappings[RegID].first;
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000177 if (WS) {
178 DEBUG(dbgs() << "Found a dependent use of RegID=" << RegID << '\n');
179 Writes.push_back(WS);
180 }
181
182 // Handle potential partial register updates.
183 for (MCSubRegIterator I(RegID, &MRI); I.isValid(); ++I) {
Andrea Di Biagioe64f3b12018-03-18 15:33:27 +0000184 WS = RegisterMappings[*I].first;
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000185 if (WS && std::find(Writes.begin(), Writes.end(), WS) == Writes.end()) {
186 DEBUG(dbgs() << "Found a dependent use of subReg " << *I << " (part of "
187 << RegID << ")\n");
188 Writes.push_back(WS);
189 }
190 }
191}
192
Andrea Di Biagio847accd2018-03-20 19:06:34 +0000193unsigned RegisterFile::isAvailable(ArrayRef<unsigned> Regs) const {
Andrea Di Biagio9da4d6d2018-04-03 13:36:24 +0000194 SmallVector<unsigned, 4> NumPhysRegs(getNumRegisterFiles());
Andrea Di Biagioe64f3b12018-03-18 15:33:27 +0000195
196 // Find how many new mappings must be created for each register file.
197 for (const unsigned RegID : Regs) {
Andrea Di Biagio9da4d6d2018-04-03 13:36:24 +0000198 const IndexPlusCostPairTy &Entry = RegisterMappings[RegID].second;
199 if (Entry.first)
200 NumPhysRegs[Entry.first] += Entry.second;
201 NumPhysRegs[0] += Entry.second;
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000202 }
203
Andrea Di Biagioe64f3b12018-03-18 15:33:27 +0000204 unsigned Response = 0;
205 for (unsigned I = 0, E = getNumRegisterFiles(); I < E; ++I) {
Andrea Di Biagio9da4d6d2018-04-03 13:36:24 +0000206 unsigned NumRegs = NumPhysRegs[I];
207 if (!NumRegs)
Andrea Di Biagioe64f3b12018-03-18 15:33:27 +0000208 continue;
209
210 const RegisterMappingTracker &RMT = RegisterFiles[I];
211 if (!RMT.TotalMappings) {
Andrea Di Biagio9da4d6d2018-04-03 13:36:24 +0000212 // The register file has an unbounded number of microarchitectural
Andrea Di Biagioe64f3b12018-03-18 15:33:27 +0000213 // registers.
214 continue;
215 }
216
Andrea Di Biagio9da4d6d2018-04-03 13:36:24 +0000217 if (RMT.TotalMappings < NumRegs) {
Andrea Di Biagioe64f3b12018-03-18 15:33:27 +0000218 // The current register file is too small. This may occur if the number of
219 // microarchitectural registers in register file #0 was changed by the
220 // users via flag -reg-file-size. Alternatively, the scheduling model
221 // specified a too small number of registers for this register file.
222 report_fatal_error(
223 "Not enough microarchitectural registers in the register file");
224 }
225
Andrea Di Biagio9da4d6d2018-04-03 13:36:24 +0000226 if (RMT.TotalMappings < (RMT.NumUsedMappings + NumRegs))
Andrea Di Biagioe64f3b12018-03-18 15:33:27 +0000227 Response |= (1U << I);
228 }
229
230 return Response;
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000231}
232
233#ifndef NDEBUG
234void RegisterFile::dump() const {
Andrea Di Biagioe64f3b12018-03-18 15:33:27 +0000235 for (unsigned I = 0, E = MRI.getNumRegs(); I < E; ++I) {
236 const RegisterMapping &RM = RegisterMappings[I];
Andrea Di Biagio9da4d6d2018-04-03 13:36:24 +0000237 dbgs() << MRI.getName(I) << ", " << I << ", Map=" << RM.second.first
238 << ", ";
Andrea Di Biagioe64f3b12018-03-18 15:33:27 +0000239 if (RM.first)
240 RM.first->dump();
241 else
242 dbgs() << "(null)\n";
243 }
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000244
Andrea Di Biagioe64f3b12018-03-18 15:33:27 +0000245 for (unsigned I = 0, E = getNumRegisterFiles(); I < E; ++I) {
246 dbgs() << "Register File #" << I;
247 const RegisterMappingTracker &RMT = RegisterFiles[I];
248 dbgs() << "\n TotalMappings: " << RMT.TotalMappings
Andrea Di Biagioe64f3b12018-03-18 15:33:27 +0000249 << "\n NumUsedMappings: " << RMT.NumUsedMappings << '\n';
250 }
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000251}
252#endif
253
Andrea Di Biagioc74ad502018-04-05 15:41:41 +0000254RetireControlUnit::RetireControlUnit(const llvm::MCSchedModel &SM,
255 DispatchUnit *DU)
256 : NextAvailableSlotIdx(0), CurrentInstructionSlotIdx(0),
257 AvailableSlots(SM.MicroOpBufferSize), MaxRetirePerCycle(0), Owner(DU) {
258 // Check if the scheduling model provides extra information about the machine
259 // processor. If so, then use that information to set the reorder buffer size
260 // and the maximum number of instructions retired per cycle.
261 if (SM.hasExtraProcessorInfo()) {
262 const MCExtraProcessorInfo &EPI = SM.getExtraProcessorInfo();
263 if (EPI.ReorderBufferSize)
264 AvailableSlots = EPI.ReorderBufferSize;
265 MaxRetirePerCycle = EPI.MaxRetirePerCycle;
266 }
267
268 assert(AvailableSlots && "Invalid reorder buffer size!");
269 Queue.resize(AvailableSlots);
270}
271
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000272// Reserves a number of slots, and returns a new token.
273unsigned RetireControlUnit::reserveSlot(unsigned Index, unsigned NumMicroOps) {
274 assert(isAvailable(NumMicroOps));
275 unsigned NormalizedQuantity =
276 std::min(NumMicroOps, static_cast<unsigned>(Queue.size()));
277 // Zero latency instructions may have zero mOps. Artificially bump this
278 // value to 1. Although zero latency instructions don't consume scheduler
279 // resources, they still consume one slot in the retire queue.
280 NormalizedQuantity = std::max(NormalizedQuantity, 1U);
281 unsigned TokenID = NextAvailableSlotIdx;
282 Queue[NextAvailableSlotIdx] = {Index, NormalizedQuantity, false};
283 NextAvailableSlotIdx += NormalizedQuantity;
284 NextAvailableSlotIdx %= Queue.size();
285 AvailableSlots -= NormalizedQuantity;
286 return TokenID;
287}
288
Andrea Di Biagio94fafdf2018-03-24 16:05:36 +0000289void DispatchUnit::notifyInstructionDispatched(unsigned Index,
290 ArrayRef<unsigned> UsedRegs) {
Clement Courbet844f22d2018-03-13 13:11:01 +0000291 DEBUG(dbgs() << "[E] Instruction Dispatched: " << Index << '\n');
Andrea Di Biagio12ef5262018-03-21 18:11:05 +0000292 Owner->notifyInstructionEvent(HWInstructionDispatchedEvent(Index, UsedRegs));
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000293}
294
295void DispatchUnit::notifyInstructionRetired(unsigned Index) {
Clement Courbet844f22d2018-03-13 13:11:01 +0000296 DEBUG(dbgs() << "[E] Instruction Retired: " << Index << '\n');
Clement Courbet844f22d2018-03-13 13:11:01 +0000297 const Instruction &IS = Owner->getInstruction(Index);
Andrea Di Biagio12ef5262018-03-21 18:11:05 +0000298 SmallVector<unsigned, 4> FreedRegs(RAT->getNumRegisterFiles());
Andrea Di Biagio43e8f7d2018-03-21 12:49:07 +0000299 for (const std::unique_ptr<WriteState> &WS : IS.getDefs())
Andrea Di Biagio12ef5262018-03-21 18:11:05 +0000300 RAT->invalidateRegisterMapping(*WS.get(), FreedRegs);
Andrea Di Biagio43e8f7d2018-03-21 12:49:07 +0000301
Andrea Di Biagio12ef5262018-03-21 18:11:05 +0000302 Owner->notifyInstructionEvent(HWInstructionRetiredEvent(Index, FreedRegs));
Clement Courbet844f22d2018-03-13 13:11:01 +0000303 Owner->eraseInstruction(Index);
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000304}
305
306void RetireControlUnit::cycleEvent() {
307 if (isEmpty())
308 return;
309
310 unsigned NumRetired = 0;
311 while (!isEmpty()) {
312 if (MaxRetirePerCycle != 0 && NumRetired == MaxRetirePerCycle)
313 break;
314 RUToken &Current = Queue[CurrentInstructionSlotIdx];
315 assert(Current.NumSlots && "Reserved zero slots?");
316 if (!Current.Executed)
317 break;
318 Owner->notifyInstructionRetired(Current.Index);
319 CurrentInstructionSlotIdx += Current.NumSlots;
320 CurrentInstructionSlotIdx %= Queue.size();
321 AvailableSlots += Current.NumSlots;
322 NumRetired++;
323 }
324}
325
326void RetireControlUnit::onInstructionExecuted(unsigned TokenID) {
327 assert(Queue.size() > TokenID);
328 assert(Queue[TokenID].Executed == false && Queue[TokenID].Index != ~0U);
329 Queue[TokenID].Executed = true;
330}
331
332#ifndef NDEBUG
333void RetireControlUnit::dump() const {
334 dbgs() << "Retire Unit: { Total Slots=" << Queue.size()
335 << ", Available Slots=" << AvailableSlots << " }\n";
336}
337#endif
338
Andrea Di Biagio91ab2ee2018-03-19 13:23:07 +0000339bool DispatchUnit::checkRAT(unsigned Index, const Instruction &Instr) {
Andrea Di Biagio9ecb4012018-03-27 15:23:41 +0000340 SmallVector<unsigned, 4> RegDefs;
341 for (const std::unique_ptr<WriteState> &RegDef : Instr.getDefs())
342 RegDefs.emplace_back(RegDef->getRegisterID());
343
344 unsigned RegisterMask = RAT->isAvailable(RegDefs);
Andrea Di Biagioe64f3b12018-03-18 15:33:27 +0000345 // A mask with all zeroes means: register files are available.
346 if (RegisterMask) {
Andrea Di Biagio91ab2ee2018-03-19 13:23:07 +0000347 Owner->notifyStallEvent(
348 HWStallEvent(HWStallEvent::RegisterFileStall, Index));
Andrea Di Biagioe64f3b12018-03-18 15:33:27 +0000349 return false;
350 }
351
352 return true;
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000353}
354
Andrea Di Biagio91ab2ee2018-03-19 13:23:07 +0000355bool DispatchUnit::checkRCU(unsigned Index, const InstrDesc &Desc) {
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000356 unsigned NumMicroOps = Desc.NumMicroOps;
357 if (RCU->isAvailable(NumMicroOps))
358 return true;
Andrea Di Biagio91ab2ee2018-03-19 13:23:07 +0000359 Owner->notifyStallEvent(
360 HWStallEvent(HWStallEvent::RetireControlUnitStall, Index));
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000361 return false;
362}
363
Andrea Di Biagio91ab2ee2018-03-19 13:23:07 +0000364bool DispatchUnit::checkScheduler(unsigned Index, const InstrDesc &Desc) {
Andrea Di Biagiob24953b2018-04-11 18:05:23 +0000365 return SC->canBeDispatched(Index, Desc);
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000366}
367
Andrea Di Biagio4732d43ca2018-03-14 14:57:23 +0000368void DispatchUnit::updateRAWDependencies(ReadState &RS,
369 const MCSubtargetInfo &STI) {
370 SmallVector<WriteState *, 4> DependentWrites;
371
372 collectWrites(DependentWrites, RS.getRegisterID());
373 RS.setDependentWrites(DependentWrites.size());
374 DEBUG(dbgs() << "Found " << DependentWrites.size() << " dependent writes\n");
375 // We know that this read depends on all the writes in DependentWrites.
376 // For each write, check if we have ReadAdvance information, and use it
377 // to figure out in how many cycles this read becomes available.
378 const ReadDescriptor &RD = RS.getDescriptor();
379 if (!RD.HasReadAdvanceEntries) {
380 for (WriteState *WS : DependentWrites)
381 WS->addUser(&RS, /* ReadAdvance */ 0);
382 return;
383 }
384
385 const MCSchedModel &SM = STI.getSchedModel();
386 const MCSchedClassDesc *SC = SM.getSchedClassDesc(RD.SchedClassID);
387 for (WriteState *WS : DependentWrites) {
388 unsigned WriteResID = WS->getWriteResourceID();
Andrea Di Biagio0a837ef2018-03-29 14:26:56 +0000389 int ReadAdvance = STI.getReadAdvanceCycles(SC, RD.UseIndex, WriteResID);
Andrea Di Biagio4732d43ca2018-03-14 14:57:23 +0000390 WS->addUser(&RS, ReadAdvance);
391 }
392 // Prepare the set for another round.
393 DependentWrites.clear();
394}
395
Andrea Di Biagio09ea09e2018-03-22 11:39:34 +0000396void DispatchUnit::dispatch(unsigned IID, Instruction *NewInst,
397 const MCSubtargetInfo &STI) {
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000398 assert(!CarryOver && "Cannot dispatch another instruction!");
399 unsigned NumMicroOps = NewInst->getDesc().NumMicroOps;
400 if (NumMicroOps > DispatchWidth) {
401 assert(AvailableEntries == DispatchWidth);
402 AvailableEntries = 0;
403 CarryOver = NumMicroOps - DispatchWidth;
404 } else {
405 assert(AvailableEntries >= NumMicroOps);
406 AvailableEntries -= NumMicroOps;
407 }
408
Andrea Di Biagiodb66efc2018-04-25 09:38:58 +0000409 // Update RAW dependencies if this instruction is not a zero-latency
410 // instruction. The assumption is that a zero-latency instruction doesn't
411 // require to be issued to the scheduler for execution. More importantly, it
412 // doesn't have to wait on the register input operands.
413 if (NewInst->getDesc().MaxLatency)
414 for (std::unique_ptr<ReadState> &RS : NewInst->getUses())
415 updateRAWDependencies(*RS, STI);
Andrea Di Biagio4732d43ca2018-03-14 14:57:23 +0000416
Andrea Di Biagioe64f3b12018-03-18 15:33:27 +0000417 // Allocate new mappings.
Andrea Di Biagio12ef5262018-03-21 18:11:05 +0000418 SmallVector<unsigned, 4> RegisterFiles(RAT->getNumRegisterFiles());
Andrea Di Biagio4732d43ca2018-03-14 14:57:23 +0000419 for (std::unique_ptr<WriteState> &WS : NewInst->getDefs())
Andrea Di Biagio12ef5262018-03-21 18:11:05 +0000420 RAT->addRegisterMapping(*WS, RegisterFiles);
Andrea Di Biagio4732d43ca2018-03-14 14:57:23 +0000421
Andrea Di Biagio09ea09e2018-03-22 11:39:34 +0000422 // Reserve slots in the RCU, and notify the instruction that it has been
423 // dispatched to the schedulers for execution.
424 NewInst->dispatch(RCU->reserveSlot(IID, NumMicroOps));
Andrea Di Biagio4732d43ca2018-03-14 14:57:23 +0000425
Andrea Di Biagio09ea09e2018-03-22 11:39:34 +0000426 // Notify listeners of the "instruction dispatched" event.
Andrea Di Biagio12ef5262018-03-21 18:11:05 +0000427 notifyInstructionDispatched(IID, RegisterFiles);
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000428
Andrea Di Biagio09ea09e2018-03-22 11:39:34 +0000429 // Now move the instruction into the scheduler's queue.
430 // The scheduler is responsible for checking if this is a zero-latency
431 // instruction that doesn't consume pipeline/scheduler resources.
Andrea Di Biagio44bfcd22018-03-19 19:09:38 +0000432 SC->scheduleInstruction(IID, *NewInst);
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000433}
434
435#ifndef NDEBUG
436void DispatchUnit::dump() const {
437 RAT->dump();
438 RCU->dump();
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000439}
440#endif
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000441} // namespace mca