blob: 8f051380ba3b2e5964d06e553328ec00650553fd [file] [log] [blame]
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +00001//===--------------------- Scheduler.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//
10// A scheduler for processor resource units and processor resource groups.
11//
12//===----------------------------------------------------------------------===//
13
Andrea Di Biagio51dba7d2018-03-23 17:36:07 +000014#include "Scheduler.h"
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000015#include "Backend.h"
Clement Courbet844f22d2018-03-13 13:11:01 +000016#include "HWEventListener.h"
Andrea Di Biagio4704f032018-03-20 12:25:54 +000017#include "Support.h"
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000018#include "llvm/Support/Debug.h"
19#include "llvm/Support/raw_ostream.h"
20
21#define DEBUG_TYPE "llvm-mca"
22
23namespace mca {
24
25using namespace llvm;
26
27uint64_t ResourceState::selectNextInSequence() {
28 assert(isReady());
29 uint64_t Next = getNextInSequence();
30 while (!isSubResourceReady(Next)) {
31 updateNextInSequence();
32 Next = getNextInSequence();
33 }
34 return Next;
35}
36
37#ifndef NDEBUG
38void ResourceState::dump() const {
39 dbgs() << "MASK: " << ResourceMask << ", SIZE_MASK: " << ResourceSizeMask
40 << ", NEXT: " << NextInSequenceMask << ", RDYMASK: " << ReadyMask
41 << ", BufferSize=" << BufferSize
42 << ", AvailableSlots=" << AvailableSlots
43 << ", Reserved=" << Unavailable << '\n';
44}
45#endif
46
Andrea Di Biagio4704f032018-03-20 12:25:54 +000047void ResourceManager::initialize(const llvm::MCSchedModel &SM) {
48 computeProcResourceMasks(SM, ProcResID2Mask);
49 for (unsigned I = 0, E = SM.getNumProcResourceKinds(); I < E; ++I)
50 addResource(*SM.getProcResource(I), I, ProcResID2Mask[I]);
51}
52
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000053// Adds a new resource state in Resources, as well as a new descriptor in
54// ResourceDescriptor. Map 'Resources' allows to quickly obtain ResourceState
55// objects from resource mask identifiers.
56void ResourceManager::addResource(const MCProcResourceDesc &Desc,
Andrea Di Biagioe1a1da12018-03-13 13:58:02 +000057 unsigned Index, uint64_t Mask) {
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000058 assert(Resources.find(Mask) == Resources.end() && "Resource already added!");
Andrea Di Biagio0c541292018-03-10 16:55:07 +000059 Resources[Mask] = llvm::make_unique<ResourceState>(Desc, Index, Mask);
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000060}
61
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +000062// Returns the actual resource consumed by this Use.
63// First, is the primary resource ID.
64// Second, is the specific sub-resource ID.
65std::pair<uint64_t, uint64_t> ResourceManager::selectPipe(uint64_t ResourceID) {
66 ResourceState &RS = *Resources[ResourceID];
67 uint64_t SubResourceID = RS.selectNextInSequence();
68 if (RS.isAResourceGroup())
69 return selectPipe(SubResourceID);
70 return std::pair<uint64_t, uint64_t>(ResourceID, SubResourceID);
71}
72
73void ResourceState::removeFromNextInSequence(uint64_t ID) {
74 assert(NextInSequenceMask);
75 assert(countPopulation(ID) == 1);
76 if (ID > getNextInSequence())
77 RemovedFromNextInSequence |= ID;
78 NextInSequenceMask = NextInSequenceMask & (~ID);
79 if (!NextInSequenceMask) {
80 NextInSequenceMask = ResourceSizeMask;
81 assert(NextInSequenceMask != RemovedFromNextInSequence);
82 NextInSequenceMask ^= RemovedFromNextInSequence;
83 RemovedFromNextInSequence = 0;
84 }
85}
86
87void ResourceManager::use(ResourceRef RR) {
88 // Mark the sub-resource referenced by RR as used.
89 ResourceState &RS = *Resources[RR.first];
90 RS.markSubResourceAsUsed(RR.second);
91 // If there are still available units in RR.first,
92 // then we are done.
93 if (RS.isReady())
94 return;
95
96 // Notify to other resources that RR.first is no longer available.
97 for (const std::pair<uint64_t, UniqueResourceState> &Res : Resources) {
98 ResourceState &Current = *Res.second.get();
99 if (!Current.isAResourceGroup() || Current.getResourceMask() == RR.first)
100 continue;
101
102 if (Current.containsResource(RR.first)) {
103 Current.markSubResourceAsUsed(RR.first);
104 Current.removeFromNextInSequence(RR.first);
105 }
106 }
107}
108
109void ResourceManager::release(ResourceRef RR) {
110 ResourceState &RS = *Resources[RR.first];
111 bool WasFullyUsed = !RS.isReady();
112 RS.releaseSubResource(RR.second);
113 if (!WasFullyUsed)
114 return;
115
116 for (const std::pair<uint64_t, UniqueResourceState> &Res : Resources) {
117 ResourceState &Current = *Res.second.get();
118 if (!Current.isAResourceGroup() || Current.getResourceMask() == RR.first)
119 continue;
120
121 if (Current.containsResource(RR.first))
122 Current.releaseSubResource(RR.first);
123 }
124}
125
Andrea Di Biagio44bfcd22018-03-19 19:09:38 +0000126ResourceStateEvent
Andrea Di Biagio847accd2018-03-20 19:06:34 +0000127ResourceManager::canBeDispatched(ArrayRef<uint64_t> Buffers) const {
Andrea Di Biagio44bfcd22018-03-19 19:09:38 +0000128 ResourceStateEvent Result = ResourceStateEvent::RS_BUFFER_AVAILABLE;
129 for (uint64_t Buffer : Buffers) {
130 Result = isBufferAvailable(Buffer);
131 if (Result != ResourceStateEvent::RS_BUFFER_AVAILABLE)
132 break;
133 }
134 return Result;
135}
136
Andrea Di Biagio847accd2018-03-20 19:06:34 +0000137void ResourceManager::reserveBuffers(ArrayRef<uint64_t> Buffers) {
Andrea Di Biagioe1a1da12018-03-13 13:58:02 +0000138 for (const uint64_t R : Buffers) {
Andrea Di Biagio44bfcd22018-03-19 19:09:38 +0000139 reserveBuffer(R);
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000140 ResourceState &Resource = *Resources[R];
141 if (Resource.isADispatchHazard()) {
142 assert(!Resource.isReserved());
143 Resource.setReserved();
144 }
145 }
146}
147
Andrea Di Biagio847accd2018-03-20 19:06:34 +0000148void ResourceManager::releaseBuffers(ArrayRef<uint64_t> Buffers) {
Andrea Di Biagio44bfcd22018-03-19 19:09:38 +0000149 for (const uint64_t R : Buffers)
150 releaseBuffer(R);
151}
152
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000153bool ResourceManager::canBeIssued(const InstrDesc &Desc) const {
154 return std::all_of(Desc.Resources.begin(), Desc.Resources.end(),
155 [&](const std::pair<uint64_t, const ResourceUsage> &E) {
156 unsigned NumUnits =
157 E.second.isReserved() ? 0U : E.second.NumUnits;
158 return isReady(E.first, NumUnits);
159 });
160}
161
162// Returns true if all resources are in-order, and there is at least one
163// resource which is a dispatch hazard (BufferSize = 0).
164bool ResourceManager::mustIssueImmediately(const InstrDesc &Desc) {
165 if (!canBeIssued(Desc))
166 return false;
167 bool AllInOrderResources = std::all_of(
168 Desc.Buffers.begin(), Desc.Buffers.end(), [&](const unsigned BufferMask) {
169 const ResourceState &Resource = *Resources[BufferMask];
170 return Resource.isInOrder() || Resource.isADispatchHazard();
171 });
172 if (!AllInOrderResources)
173 return false;
174
175 return std::any_of(Desc.Buffers.begin(), Desc.Buffers.end(),
176 [&](const unsigned BufferMask) {
177 return Resources[BufferMask]->isADispatchHazard();
178 });
179}
180
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000181void ResourceManager::issueInstruction(
182 unsigned Index, const InstrDesc &Desc,
Andrea Di Biagio51dba7d2018-03-23 17:36:07 +0000183 SmallVectorImpl<std::pair<ResourceRef, double>> &Pipes) {
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000184 for (const std::pair<uint64_t, ResourceUsage> &R : Desc.Resources) {
185 const CycleSegment &CS = R.second.CS;
186 if (!CS.size()) {
187 releaseResource(R.first);
188 continue;
189 }
190
191 assert(CS.begin() == 0 && "Invalid {Start, End} cycles!");
192 if (!R.second.isReserved()) {
193 ResourceRef Pipe = selectPipe(R.first);
194 use(Pipe);
195 BusyResources[Pipe] += CS.size();
Andrea Di Biagio0c541292018-03-10 16:55:07 +0000196 // Replace the resource mask with a valid processor resource index.
197 const ResourceState &RS = *Resources[Pipe.first];
198 Pipe.first = RS.getProcResourceID();
Andrea Di Biagio51dba7d2018-03-23 17:36:07 +0000199 Pipes.emplace_back(
200 std::pair<ResourceRef, double>(Pipe, static_cast<double>(CS.size())));
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000201 } else {
202 assert((countPopulation(R.first) > 1) && "Expected a group!");
203 // Mark this group as reserved.
204 assert(R.second.isReserved());
205 reserveResource(R.first);
206 BusyResources[ResourceRef(R.first, R.first)] += CS.size();
207 }
208 }
209}
210
211void ResourceManager::cycleEvent(SmallVectorImpl<ResourceRef> &ResourcesFreed) {
212 for (std::pair<ResourceRef, unsigned> &BR : BusyResources) {
213 if (BR.second)
214 BR.second--;
215 if (!BR.second) {
216 // Release this resource.
217 const ResourceRef &RR = BR.first;
218
219 if (countPopulation(RR.first) == 1)
220 release(RR);
221
222 releaseResource(RR.first);
223 ResourcesFreed.push_back(RR);
224 }
225 }
226
227 for (const ResourceRef &RF : ResourcesFreed)
228 BusyResources.erase(RF);
229}
230
Andrea Di Biagio44bfcd22018-03-19 19:09:38 +0000231void Scheduler::scheduleInstruction(unsigned Idx, Instruction &MCIS) {
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000232 assert(WaitQueue.find(Idx) == WaitQueue.end());
233 assert(ReadyQueue.find(Idx) == ReadyQueue.end());
234 assert(IssuedQueue.find(Idx) == IssuedQueue.end());
235
236 // Special case where MCIS is a zero-latency instruction. A zero-latency
237 // instruction doesn't consume any scheduler resources. That is because it
238 // doesn't need to be executed. Most of the times, zero latency instructions
239 // are removed at register renaming stage. For example, register-register
240 // moves can be removed at register renaming stage by creating new aliases.
241 // Zero-idiom instruction (for example: a `xor reg, reg`) can also be
242 // eliminated at register renaming stage, since we know in advance that those
243 // clear their output register.
Andrea Di Biagio44bfcd22018-03-19 19:09:38 +0000244 if (MCIS.isZeroLatency()) {
Andrea Di Biagio09ea09e2018-03-22 11:39:34 +0000245 assert(MCIS.isReady() && "data dependent zero-latency instruction?");
Andrea Di Biagio373c38a2018-03-08 20:21:55 +0000246 notifyInstructionReady(Idx);
Andrea Di Biagio09ea09e2018-03-22 11:39:34 +0000247 MCIS.execute();
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000248 notifyInstructionIssued(Idx, {});
Andrea Di Biagio09ea09e2018-03-22 11:39:34 +0000249 assert(MCIS.isExecuted() && "Unexpected non-zero latency!");
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000250 notifyInstructionExecuted(Idx);
Andrea Di Biagio44bfcd22018-03-19 19:09:38 +0000251 return;
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000252 }
253
Andrea Di Biagio44bfcd22018-03-19 19:09:38 +0000254 const InstrDesc &Desc = MCIS.getDesc();
Andrea Di Biagioa3f2e482018-03-20 18:20:39 +0000255 if (!Desc.Buffers.empty()) {
256 // Reserve a slot in each buffered resource. Also, mark units with
257 // BufferSize=0 as reserved. Resources with a buffer size of zero will only
258 // be released after MCIS is issued, and all the ResourceCycles for those
259 // units have been consumed.
260 Resources->reserveBuffers(Desc.Buffers);
261 notifyReservedBuffers(Desc.Buffers);
262 }
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000263
Andrea Di Biagio2dee62b2018-03-22 14:14:49 +0000264 // If necessary, reserve queue entries in the load-store unit (LSU).
265 bool Reserved = LSU->reserve(Idx, Desc);
266 if (!MCIS.isReady() || (Reserved && !LSU->isReady(Idx))) {
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000267 DEBUG(dbgs() << "[SCHEDULER] Adding " << Idx << " to the Wait Queue\n");
Andrea Di Biagio44bfcd22018-03-19 19:09:38 +0000268 WaitQueue[Idx] = &MCIS;
269 return;
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000270 }
271 notifyInstructionReady(Idx);
272
273 // Special case where the instruction is ready, and it uses an in-order
274 // dispatch/issue processor resource. The instruction is issued immediately to
275 // the pipelines. Any other in-order buffered resources (i.e. BufferSize=1)
276 // are consumed.
277 if (Resources->mustIssueImmediately(Desc)) {
278 DEBUG(dbgs() << "[SCHEDULER] Instruction " << Idx
279 << " issued immediately\n");
Andrea Di Biagio44bfcd22018-03-19 19:09:38 +0000280 return issueInstruction(MCIS, Idx);
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000281 }
282
283 DEBUG(dbgs() << "[SCHEDULER] Adding " << Idx << " to the Ready Queue\n");
Andrea Di Biagio44bfcd22018-03-19 19:09:38 +0000284 ReadyQueue[Idx] = &MCIS;
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000285}
286
Andrea Di Biagio3e646442018-04-12 10:49:40 +0000287void Scheduler::cycleEvent() {
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000288 SmallVector<ResourceRef, 8> ResourcesFreed;
289 Resources->cycleEvent(ResourcesFreed);
290
291 for (const ResourceRef &RR : ResourcesFreed)
292 notifyResourceAvailable(RR);
293
294 updateIssuedQueue();
295 updatePendingQueue();
Andrea Di Biagio0a837ef2018-03-29 14:26:56 +0000296 bool InstructionsWerePromoted = false;
297 do {
298 InstructionsWerePromoted = issue();
299 } while(InstructionsWerePromoted);
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000300}
301
302#ifndef NDEBUG
303void Scheduler::dump() const {
304 dbgs() << "[SCHEDULER]: WaitQueue size is: " << WaitQueue.size() << '\n';
305 dbgs() << "[SCHEDULER]: ReadyQueue size is: " << ReadyQueue.size() << '\n';
306 dbgs() << "[SCHEDULER]: IssuedQueue size is: " << IssuedQueue.size() << '\n';
307 Resources->dump();
308}
309#endif
310
Andrea Di Biagiob24953b2018-04-11 18:05:23 +0000311bool Scheduler::canBeDispatched(unsigned Index, const InstrDesc &Desc) const {
312 HWStallEvent::GenericEventType Type = HWStallEvent::Invalid;
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000313
Andrea Di Biagiob24953b2018-04-11 18:05:23 +0000314 if (Desc.MayLoad && LSU->isLQFull())
315 Type = HWStallEvent::LoadQueueFull;
316 else if (Desc.MayStore && LSU->isSQFull())
317 Type = HWStallEvent::StoreQueueFull;
318 else {
319 switch (Resources->canBeDispatched(Desc.Buffers)) {
320 default: return true;
321 case ResourceStateEvent::RS_BUFFER_UNAVAILABLE:
322 Type = HWStallEvent::SchedulerQueueFull;
323 break;
324 case ResourceStateEvent::RS_RESERVED:
325 Type = HWStallEvent::DispatchGroupStall;
326 }
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000327 }
Andrea Di Biagiob24953b2018-04-11 18:05:23 +0000328
329 Owner->notifyStallEvent(HWStallEvent(Type, Index));
330 return false;
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000331}
332
Andrea Di Biagio44bfcd22018-03-19 19:09:38 +0000333void Scheduler::issueInstruction(Instruction &IS, unsigned InstrIndex) {
Andrea Di Biagioa3f2e482018-03-20 18:20:39 +0000334 const InstrDesc &D = IS.getDesc();
335
336 if (!D.Buffers.empty()) {
337 Resources->releaseBuffers(D.Buffers);
338 notifyReleasedBuffers(D.Buffers);
339 }
340
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000341 // Issue the instruction and collect all the consumed resources
342 // into a vector. That vector is then used to notify the listener.
343 // Most instructions consume very few resurces (typically one or
344 // two resources). We use a small vector here, and conservatively
345 // initialize its capacity to 4. This should address the majority of
346 // the cases.
Andrea Di Biagio51dba7d2018-03-23 17:36:07 +0000347 SmallVector<std::pair<ResourceRef, double>, 4> UsedResources;
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000348 Resources->issueInstruction(InstrIndex, D, UsedResources);
349 // Notify the instruction that it started executing.
350 // This updates the internal state of each write.
Andrea Di Biagio44bfcd22018-03-19 19:09:38 +0000351 IS.execute();
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000352
Andrea Di Biagio35622482018-03-22 10:19:20 +0000353 notifyInstructionIssued(InstrIndex, UsedResources);
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000354 if (D.MaxLatency) {
Andrea Di Biagio35622482018-03-22 10:19:20 +0000355 assert(IS.isExecuting() && "A zero latency instruction?");
Andrea Di Biagio44bfcd22018-03-19 19:09:38 +0000356 IssuedQueue[InstrIndex] = &IS;
Andrea Di Biagio35622482018-03-22 10:19:20 +0000357 return;
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000358 }
Andrea Di Biagio35622482018-03-22 10:19:20 +0000359
360 // A zero latency instruction which reads and/or updates registers.
361 assert(IS.isExecuted() && "Instruction still executing!");
362 notifyInstructionExecuted(InstrIndex);
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000363}
364
Andrea Di Biagio0a837ef2018-03-29 14:26:56 +0000365bool Scheduler::promoteToReadyQueue() {
366 // Scan the set of waiting instructions and promote them to the
367 // ready queue if operands are all ready.
368 bool InstructionsWerePromoted = false;
369 for (auto I = WaitQueue.begin(), E = WaitQueue.end(); I != E;) {
370 const QueueEntryTy &Entry = *I;
371
372 // Check if this instruction is now ready. In case, force
373 // a transition in state using method 'update()'.
374 Entry.second->update();
375 bool IsReady = Entry.second->isReady();
376
377 const InstrDesc &Desc = Entry.second->getDesc();
378 bool IsMemOp = Desc.MayLoad || Desc.MayStore;
379 if (IsReady && IsMemOp)
380 IsReady &= LSU->isReady(Entry.first);
381
382 if (IsReady) {
383 notifyInstructionReady(Entry.first);
384 ReadyQueue[Entry.first] = Entry.second;
385 auto ToRemove = I;
386 ++I;
387 WaitQueue.erase(ToRemove);
388 InstructionsWerePromoted = true;
389 } else {
390 ++I;
391 }
392 }
393
394 return InstructionsWerePromoted;
395}
396
397
398bool Scheduler::issue() {
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000399 std::vector<unsigned> ToRemove;
400 for (const QueueEntryTy QueueEntry : ReadyQueue) {
401 // Give priority to older instructions in ReadyQueue. The ready queue is
402 // ordered by key, and therefore older instructions are visited first.
Andrea Di Biagio44bfcd22018-03-19 19:09:38 +0000403 Instruction &IS = *QueueEntry.second;
404 const InstrDesc &D = IS.getDesc();
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000405 if (!Resources->canBeIssued(D))
406 continue;
407 unsigned InstrIndex = QueueEntry.first;
408 issueInstruction(IS, InstrIndex);
409 ToRemove.emplace_back(InstrIndex);
410 }
411
Andrea Di Biagio0a837ef2018-03-29 14:26:56 +0000412 if (ToRemove.empty())
413 return false;
414
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000415 for (const unsigned InstrIndex : ToRemove)
416 ReadyQueue.erase(InstrIndex);
Andrea Di Biagio0a837ef2018-03-29 14:26:56 +0000417
418 // Instructions that have been issued during this cycle might have unblocked
419 // other dependent instructions. Dependent instructions
420 // may be issued during this same cycle if operands have ReadAdvance entries.
421 // Promote those instructions to the ReadyQueue and tell to the caller that
422 // we need another round of 'issue()'.
423 return promoteToReadyQueue();
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000424}
425
426void Scheduler::updatePendingQueue() {
Andrea Di Biagio0a837ef2018-03-29 14:26:56 +0000427 // Notify to instructions in the pending queue that a new cycle just
428 // started.
429 for (QueueEntryTy Entry : WaitQueue)
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000430 Entry.second->cycleEvent();
431
Andrea Di Biagio0a837ef2018-03-29 14:26:56 +0000432 promoteToReadyQueue();
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000433}
434
435void Scheduler::updateIssuedQueue() {
436 for (auto I = IssuedQueue.begin(), E = IssuedQueue.end(); I != E;) {
437 const QueueEntryTy Entry = *I;
438 Entry.second->cycleEvent();
439 if (Entry.second->isExecuted()) {
440 notifyInstructionExecuted(Entry.first);
441 auto ToRemove = I;
442 ++I;
443 IssuedQueue.erase(ToRemove);
444 } else {
445 DEBUG(dbgs() << "[SCHEDULER]: Instruction " << Entry.first
446 << " is still executing.\n");
447 ++I;
448 }
449 }
450}
451
452void Scheduler::notifyInstructionIssued(
Andrea Di Biagio51dba7d2018-03-23 17:36:07 +0000453 unsigned Index, ArrayRef<std::pair<ResourceRef, double>> Used) {
Andrea Di Biagioa3f2e482018-03-20 18:20:39 +0000454 DEBUG({
455 dbgs() << "[E] Instruction Issued: " << Index << '\n';
456 for (const std::pair<ResourceRef, unsigned> &Resource : Used) {
457 dbgs() << "[E] Resource Used: [" << Resource.first.first << '.'
458 << Resource.first.second << "]\n";
459 dbgs() << " cycles: " << Resource.second << '\n';
460 }
461 });
Clement Courbet844f22d2018-03-13 13:11:01 +0000462 Owner->notifyInstructionEvent(HWInstructionIssuedEvent(Index, Used));
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000463}
464
465void Scheduler::notifyInstructionExecuted(unsigned Index) {
466 LSU->onInstructionExecuted(Index);
Clement Courbet844f22d2018-03-13 13:11:01 +0000467 DEBUG(dbgs() << "[E] Instruction Executed: " << Index << '\n');
468 Owner->notifyInstructionEvent(
469 HWInstructionEvent(HWInstructionEvent::Executed, Index));
470
471 const Instruction &IS = Owner->getInstruction(Index);
472 DU->onInstructionExecuted(IS.getRCUTokenID());
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000473}
474
475void Scheduler::notifyInstructionReady(unsigned Index) {
Clement Courbet844f22d2018-03-13 13:11:01 +0000476 DEBUG(dbgs() << "[E] Instruction Ready: " << Index << '\n');
477 Owner->notifyInstructionEvent(
478 HWInstructionEvent(HWInstructionEvent::Ready, Index));
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000479}
480
481void Scheduler::notifyResourceAvailable(const ResourceRef &RR) {
482 Owner->notifyResourceAvailable(RR);
483}
Andrea Di Biagioa3f2e482018-03-20 18:20:39 +0000484
485void Scheduler::notifyReservedBuffers(ArrayRef<uint64_t> Buffers) {
486 SmallVector<unsigned, 4> BufferIDs(Buffers.begin(), Buffers.end());
487 std::transform(
488 Buffers.begin(), Buffers.end(), BufferIDs.begin(),
489 [&](uint64_t Op) { return Resources->resolveResourceMask(Op); });
490 Owner->notifyReservedBuffers(BufferIDs);
491}
492
493void Scheduler::notifyReleasedBuffers(ArrayRef<uint64_t> Buffers) {
494 SmallVector<unsigned, 4> BufferIDs(Buffers.begin(), Buffers.end());
495 std::transform(
496 Buffers.begin(), Buffers.end(), BufferIDs.begin(),
497 [&](uint64_t Op) { return Resources->resolveResourceMask(Op); });
498 Owner->notifyReleasedBuffers(BufferIDs);
499}
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000500} // namespace mca