blob: c77d4b81968017311124f3cb00e4f5d03ff62c83 [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
287void Scheduler::cycleEvent(unsigned /* unused */) {
288 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
311Scheduler::Event Scheduler::canBeDispatched(const InstrDesc &Desc) const {
312 if (Desc.MayLoad && LSU->isLQFull())
313 return HWS_LD_QUEUE_UNAVAILABLE;
314 if (Desc.MayStore && LSU->isSQFull())
315 return HWS_ST_QUEUE_UNAVAILABLE;
316
317 Scheduler::Event Event;
Andrea Di Biagioe1a1da12018-03-13 13:58:02 +0000318 switch (Resources->canBeDispatched(Desc.Buffers)) {
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000319 case ResourceStateEvent::RS_BUFFER_AVAILABLE:
320 Event = HWS_AVAILABLE;
321 break;
322 case ResourceStateEvent::RS_BUFFER_UNAVAILABLE:
323 Event = HWS_QUEUE_UNAVAILABLE;
324 break;
325 case ResourceStateEvent::RS_RESERVED:
326 Event = HWS_DISPATCH_GROUP_RESTRICTION;
327 }
328 return Event;
329}
330
Andrea Di Biagio44bfcd22018-03-19 19:09:38 +0000331void Scheduler::issueInstruction(Instruction &IS, unsigned InstrIndex) {
Andrea Di Biagioa3f2e482018-03-20 18:20:39 +0000332 const InstrDesc &D = IS.getDesc();
333
334 if (!D.Buffers.empty()) {
335 Resources->releaseBuffers(D.Buffers);
336 notifyReleasedBuffers(D.Buffers);
337 }
338
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000339 // Issue the instruction and collect all the consumed resources
340 // into a vector. That vector is then used to notify the listener.
341 // Most instructions consume very few resurces (typically one or
342 // two resources). We use a small vector here, and conservatively
343 // initialize its capacity to 4. This should address the majority of
344 // the cases.
Andrea Di Biagio51dba7d2018-03-23 17:36:07 +0000345 SmallVector<std::pair<ResourceRef, double>, 4> UsedResources;
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000346 Resources->issueInstruction(InstrIndex, D, UsedResources);
347 // Notify the instruction that it started executing.
348 // This updates the internal state of each write.
Andrea Di Biagio44bfcd22018-03-19 19:09:38 +0000349 IS.execute();
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000350
Andrea Di Biagio35622482018-03-22 10:19:20 +0000351 notifyInstructionIssued(InstrIndex, UsedResources);
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000352 if (D.MaxLatency) {
Andrea Di Biagio35622482018-03-22 10:19:20 +0000353 assert(IS.isExecuting() && "A zero latency instruction?");
Andrea Di Biagio44bfcd22018-03-19 19:09:38 +0000354 IssuedQueue[InstrIndex] = &IS;
Andrea Di Biagio35622482018-03-22 10:19:20 +0000355 return;
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000356 }
Andrea Di Biagio35622482018-03-22 10:19:20 +0000357
358 // A zero latency instruction which reads and/or updates registers.
359 assert(IS.isExecuted() && "Instruction still executing!");
360 notifyInstructionExecuted(InstrIndex);
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000361}
362
Andrea Di Biagio0a837ef2018-03-29 14:26:56 +0000363bool Scheduler::promoteToReadyQueue() {
364 // Scan the set of waiting instructions and promote them to the
365 // ready queue if operands are all ready.
366 bool InstructionsWerePromoted = false;
367 for (auto I = WaitQueue.begin(), E = WaitQueue.end(); I != E;) {
368 const QueueEntryTy &Entry = *I;
369
370 // Check if this instruction is now ready. In case, force
371 // a transition in state using method 'update()'.
372 Entry.second->update();
373 bool IsReady = Entry.second->isReady();
374
375 const InstrDesc &Desc = Entry.second->getDesc();
376 bool IsMemOp = Desc.MayLoad || Desc.MayStore;
377 if (IsReady && IsMemOp)
378 IsReady &= LSU->isReady(Entry.first);
379
380 if (IsReady) {
381 notifyInstructionReady(Entry.first);
382 ReadyQueue[Entry.first] = Entry.second;
383 auto ToRemove = I;
384 ++I;
385 WaitQueue.erase(ToRemove);
386 InstructionsWerePromoted = true;
387 } else {
388 ++I;
389 }
390 }
391
392 return InstructionsWerePromoted;
393}
394
395
396bool Scheduler::issue() {
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000397 std::vector<unsigned> ToRemove;
398 for (const QueueEntryTy QueueEntry : ReadyQueue) {
399 // Give priority to older instructions in ReadyQueue. The ready queue is
400 // ordered by key, and therefore older instructions are visited first.
Andrea Di Biagio44bfcd22018-03-19 19:09:38 +0000401 Instruction &IS = *QueueEntry.second;
402 const InstrDesc &D = IS.getDesc();
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000403 if (!Resources->canBeIssued(D))
404 continue;
405 unsigned InstrIndex = QueueEntry.first;
406 issueInstruction(IS, InstrIndex);
407 ToRemove.emplace_back(InstrIndex);
408 }
409
Andrea Di Biagio0a837ef2018-03-29 14:26:56 +0000410 if (ToRemove.empty())
411 return false;
412
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000413 for (const unsigned InstrIndex : ToRemove)
414 ReadyQueue.erase(InstrIndex);
Andrea Di Biagio0a837ef2018-03-29 14:26:56 +0000415
416 // Instructions that have been issued during this cycle might have unblocked
417 // other dependent instructions. Dependent instructions
418 // may be issued during this same cycle if operands have ReadAdvance entries.
419 // Promote those instructions to the ReadyQueue and tell to the caller that
420 // we need another round of 'issue()'.
421 return promoteToReadyQueue();
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000422}
423
424void Scheduler::updatePendingQueue() {
Andrea Di Biagio0a837ef2018-03-29 14:26:56 +0000425 // Notify to instructions in the pending queue that a new cycle just
426 // started.
427 for (QueueEntryTy Entry : WaitQueue)
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000428 Entry.second->cycleEvent();
429
Andrea Di Biagio0a837ef2018-03-29 14:26:56 +0000430 promoteToReadyQueue();
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000431}
432
433void Scheduler::updateIssuedQueue() {
434 for (auto I = IssuedQueue.begin(), E = IssuedQueue.end(); I != E;) {
435 const QueueEntryTy Entry = *I;
436 Entry.second->cycleEvent();
437 if (Entry.second->isExecuted()) {
438 notifyInstructionExecuted(Entry.first);
439 auto ToRemove = I;
440 ++I;
441 IssuedQueue.erase(ToRemove);
442 } else {
443 DEBUG(dbgs() << "[SCHEDULER]: Instruction " << Entry.first
444 << " is still executing.\n");
445 ++I;
446 }
447 }
448}
449
450void Scheduler::notifyInstructionIssued(
Andrea Di Biagio51dba7d2018-03-23 17:36:07 +0000451 unsigned Index, ArrayRef<std::pair<ResourceRef, double>> Used) {
Andrea Di Biagioa3f2e482018-03-20 18:20:39 +0000452 DEBUG({
453 dbgs() << "[E] Instruction Issued: " << Index << '\n';
454 for (const std::pair<ResourceRef, unsigned> &Resource : Used) {
455 dbgs() << "[E] Resource Used: [" << Resource.first.first << '.'
456 << Resource.first.second << "]\n";
457 dbgs() << " cycles: " << Resource.second << '\n';
458 }
459 });
Clement Courbet844f22d2018-03-13 13:11:01 +0000460 Owner->notifyInstructionEvent(HWInstructionIssuedEvent(Index, Used));
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000461}
462
463void Scheduler::notifyInstructionExecuted(unsigned Index) {
464 LSU->onInstructionExecuted(Index);
Clement Courbet844f22d2018-03-13 13:11:01 +0000465 DEBUG(dbgs() << "[E] Instruction Executed: " << Index << '\n');
466 Owner->notifyInstructionEvent(
467 HWInstructionEvent(HWInstructionEvent::Executed, Index));
468
469 const Instruction &IS = Owner->getInstruction(Index);
470 DU->onInstructionExecuted(IS.getRCUTokenID());
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000471}
472
473void Scheduler::notifyInstructionReady(unsigned Index) {
Clement Courbet844f22d2018-03-13 13:11:01 +0000474 DEBUG(dbgs() << "[E] Instruction Ready: " << Index << '\n');
475 Owner->notifyInstructionEvent(
476 HWInstructionEvent(HWInstructionEvent::Ready, Index));
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000477}
478
479void Scheduler::notifyResourceAvailable(const ResourceRef &RR) {
480 Owner->notifyResourceAvailable(RR);
481}
Andrea Di Biagioa3f2e482018-03-20 18:20:39 +0000482
483void Scheduler::notifyReservedBuffers(ArrayRef<uint64_t> Buffers) {
484 SmallVector<unsigned, 4> BufferIDs(Buffers.begin(), Buffers.end());
485 std::transform(
486 Buffers.begin(), Buffers.end(), BufferIDs.begin(),
487 [&](uint64_t Op) { return Resources->resolveResourceMask(Op); });
488 Owner->notifyReservedBuffers(BufferIDs);
489}
490
491void Scheduler::notifyReleasedBuffers(ArrayRef<uint64_t> Buffers) {
492 SmallVector<unsigned, 4> BufferIDs(Buffers.begin(), Buffers.end());
493 std::transform(
494 Buffers.begin(), Buffers.end(), BufferIDs.begin(),
495 [&](uint64_t Op) { return Resources->resolveResourceMask(Op); });
496 Owner->notifyReleasedBuffers(BufferIDs);
497}
Andrea Di Biagio3a6b0922018-03-08 13:05:02 +0000498} // namespace mca