Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 1 | //===--------------------- 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 | |
| 14 | #include "Scheduler.h" |
| 15 | #include "Backend.h" |
Clement Courbet | 844f22d | 2018-03-13 13:11:01 +0000 | [diff] [blame] | 16 | #include "HWEventListener.h" |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 17 | #include "llvm/Support/Debug.h" |
| 18 | #include "llvm/Support/raw_ostream.h" |
| 19 | |
| 20 | #define DEBUG_TYPE "llvm-mca" |
| 21 | |
| 22 | namespace mca { |
| 23 | |
| 24 | using namespace llvm; |
| 25 | |
| 26 | uint64_t ResourceState::selectNextInSequence() { |
| 27 | assert(isReady()); |
| 28 | uint64_t Next = getNextInSequence(); |
| 29 | while (!isSubResourceReady(Next)) { |
| 30 | updateNextInSequence(); |
| 31 | Next = getNextInSequence(); |
| 32 | } |
| 33 | return Next; |
| 34 | } |
| 35 | |
| 36 | #ifndef NDEBUG |
| 37 | void ResourceState::dump() const { |
| 38 | dbgs() << "MASK: " << ResourceMask << ", SIZE_MASK: " << ResourceSizeMask |
| 39 | << ", NEXT: " << NextInSequenceMask << ", RDYMASK: " << ReadyMask |
| 40 | << ", BufferSize=" << BufferSize |
| 41 | << ", AvailableSlots=" << AvailableSlots |
| 42 | << ", Reserved=" << Unavailable << '\n'; |
| 43 | } |
| 44 | #endif |
| 45 | |
| 46 | // Adds a new resource state in Resources, as well as a new descriptor in |
| 47 | // ResourceDescriptor. Map 'Resources' allows to quickly obtain ResourceState |
| 48 | // objects from resource mask identifiers. |
| 49 | void ResourceManager::addResource(const MCProcResourceDesc &Desc, |
Andrea Di Biagio | e1a1da1 | 2018-03-13 13:58:02 +0000 | [diff] [blame^] | 50 | unsigned Index, uint64_t Mask) { |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 51 | assert(Resources.find(Mask) == Resources.end() && "Resource already added!"); |
Andrea Di Biagio | 0c54129 | 2018-03-10 16:55:07 +0000 | [diff] [blame] | 52 | Resources[Mask] = llvm::make_unique<ResourceState>(Desc, Index, Mask); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | // Populate vector ProcResID2Mask with resource masks. One per each processor |
| 56 | // resource declared by the scheduling model. |
| 57 | void ResourceManager::computeProcResourceMasks(const MCSchedModel &SM) { |
| 58 | unsigned ProcResourceID = 0; |
| 59 | |
| 60 | // Create a unique bitmask for every processor resource unit. |
| 61 | // Skip resource at index 0, since it always references 'InvalidUnit'. |
| 62 | ProcResID2Mask.resize(SM.getNumProcResourceKinds()); |
| 63 | for (unsigned I = 1, E = SM.getNumProcResourceKinds(); I < E; ++I) { |
| 64 | const MCProcResourceDesc &Desc = *SM.getProcResource(I); |
| 65 | if (Desc.SubUnitsIdxBegin) |
| 66 | continue; |
| 67 | ProcResID2Mask[I] = 1ULL << ProcResourceID; |
| 68 | ProcResourceID++; |
| 69 | } |
| 70 | |
| 71 | // Create a unique bitmask for every processor resource group. |
| 72 | for (unsigned I = 1, E = SM.getNumProcResourceKinds(); I < E; ++I) { |
| 73 | const MCProcResourceDesc &Desc = *SM.getProcResource(I); |
| 74 | if (!Desc.SubUnitsIdxBegin) |
| 75 | continue; |
| 76 | ProcResID2Mask[I] |= 1ULL << ProcResourceID; |
| 77 | for (unsigned U = 0; U < Desc.NumUnits; ++U) { |
| 78 | uint64_t OtherMask = ProcResID2Mask[Desc.SubUnitsIdxBegin[U]]; |
| 79 | ProcResID2Mask[I] |= OtherMask; |
| 80 | } |
| 81 | ProcResourceID++; |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | // Returns the actual resource consumed by this Use. |
| 86 | // First, is the primary resource ID. |
| 87 | // Second, is the specific sub-resource ID. |
| 88 | std::pair<uint64_t, uint64_t> ResourceManager::selectPipe(uint64_t ResourceID) { |
| 89 | ResourceState &RS = *Resources[ResourceID]; |
| 90 | uint64_t SubResourceID = RS.selectNextInSequence(); |
| 91 | if (RS.isAResourceGroup()) |
| 92 | return selectPipe(SubResourceID); |
| 93 | return std::pair<uint64_t, uint64_t>(ResourceID, SubResourceID); |
| 94 | } |
| 95 | |
| 96 | void ResourceState::removeFromNextInSequence(uint64_t ID) { |
| 97 | assert(NextInSequenceMask); |
| 98 | assert(countPopulation(ID) == 1); |
| 99 | if (ID > getNextInSequence()) |
| 100 | RemovedFromNextInSequence |= ID; |
| 101 | NextInSequenceMask = NextInSequenceMask & (~ID); |
| 102 | if (!NextInSequenceMask) { |
| 103 | NextInSequenceMask = ResourceSizeMask; |
| 104 | assert(NextInSequenceMask != RemovedFromNextInSequence); |
| 105 | NextInSequenceMask ^= RemovedFromNextInSequence; |
| 106 | RemovedFromNextInSequence = 0; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | void ResourceManager::use(ResourceRef RR) { |
| 111 | // Mark the sub-resource referenced by RR as used. |
| 112 | ResourceState &RS = *Resources[RR.first]; |
| 113 | RS.markSubResourceAsUsed(RR.second); |
| 114 | // If there are still available units in RR.first, |
| 115 | // then we are done. |
| 116 | if (RS.isReady()) |
| 117 | return; |
| 118 | |
| 119 | // Notify to other resources that RR.first is no longer available. |
| 120 | for (const std::pair<uint64_t, UniqueResourceState> &Res : Resources) { |
| 121 | ResourceState &Current = *Res.second.get(); |
| 122 | if (!Current.isAResourceGroup() || Current.getResourceMask() == RR.first) |
| 123 | continue; |
| 124 | |
| 125 | if (Current.containsResource(RR.first)) { |
| 126 | Current.markSubResourceAsUsed(RR.first); |
| 127 | Current.removeFromNextInSequence(RR.first); |
| 128 | } |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | void ResourceManager::release(ResourceRef RR) { |
| 133 | ResourceState &RS = *Resources[RR.first]; |
| 134 | bool WasFullyUsed = !RS.isReady(); |
| 135 | RS.releaseSubResource(RR.second); |
| 136 | if (!WasFullyUsed) |
| 137 | return; |
| 138 | |
| 139 | for (const std::pair<uint64_t, UniqueResourceState> &Res : Resources) { |
| 140 | ResourceState &Current = *Res.second.get(); |
| 141 | if (!Current.isAResourceGroup() || Current.getResourceMask() == RR.first) |
| 142 | continue; |
| 143 | |
| 144 | if (Current.containsResource(RR.first)) |
| 145 | Current.releaseSubResource(RR.first); |
| 146 | } |
| 147 | } |
| 148 | |
Andrea Di Biagio | e1a1da1 | 2018-03-13 13:58:02 +0000 | [diff] [blame^] | 149 | void ResourceManager::reserveDispatchHazardResources( |
| 150 | const ArrayRef<uint64_t> Buffers) { |
| 151 | for (const uint64_t R : Buffers) { |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 152 | ResourceState &Resource = *Resources[R]; |
| 153 | if (Resource.isADispatchHazard()) { |
| 154 | assert(!Resource.isReserved()); |
| 155 | Resource.setReserved(); |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | bool ResourceManager::canBeIssued(const InstrDesc &Desc) const { |
| 161 | return std::all_of(Desc.Resources.begin(), Desc.Resources.end(), |
| 162 | [&](const std::pair<uint64_t, const ResourceUsage> &E) { |
| 163 | unsigned NumUnits = |
| 164 | E.second.isReserved() ? 0U : E.second.NumUnits; |
| 165 | return isReady(E.first, NumUnits); |
| 166 | }); |
| 167 | } |
| 168 | |
| 169 | // Returns true if all resources are in-order, and there is at least one |
| 170 | // resource which is a dispatch hazard (BufferSize = 0). |
| 171 | bool ResourceManager::mustIssueImmediately(const InstrDesc &Desc) { |
| 172 | if (!canBeIssued(Desc)) |
| 173 | return false; |
| 174 | bool AllInOrderResources = std::all_of( |
| 175 | Desc.Buffers.begin(), Desc.Buffers.end(), [&](const unsigned BufferMask) { |
| 176 | const ResourceState &Resource = *Resources[BufferMask]; |
| 177 | return Resource.isInOrder() || Resource.isADispatchHazard(); |
| 178 | }); |
| 179 | if (!AllInOrderResources) |
| 180 | return false; |
| 181 | |
| 182 | return std::any_of(Desc.Buffers.begin(), Desc.Buffers.end(), |
| 183 | [&](const unsigned BufferMask) { |
| 184 | return Resources[BufferMask]->isADispatchHazard(); |
| 185 | }); |
| 186 | } |
| 187 | |
| 188 | double ResourceManager::getRThroughput(const InstrDesc &ID) const { |
| 189 | double RThroughput = 0; |
| 190 | for (const std::pair<uint64_t, ResourceUsage> &Usage : ID.Resources) { |
| 191 | const CycleSegment &CS = Usage.second.CS; |
| 192 | assert(CS.begin() == 0); |
| 193 | |
| 194 | if (Usage.second.isReserved()) { |
| 195 | RThroughput = std::max(RThroughput, (double)CS.size()); |
| 196 | continue; |
| 197 | } |
| 198 | |
| 199 | unsigned Population = std::max(1U, countPopulation(Usage.first) - 1); |
| 200 | unsigned NumUnits = Population * getNumUnits(Usage.first); |
| 201 | NumUnits -= Usage.second.NumUnits - 1; |
| 202 | unsigned Cycles = CS.size(); |
| 203 | RThroughput = std::max(RThroughput, (double)Cycles / NumUnits); |
| 204 | } |
| 205 | return RThroughput; |
| 206 | } |
| 207 | |
| 208 | void ResourceManager::issueInstruction( |
| 209 | unsigned Index, const InstrDesc &Desc, |
| 210 | SmallVectorImpl<std::pair<ResourceRef, unsigned>> &Pipes) { |
Andrea Di Biagio | e1a1da1 | 2018-03-13 13:58:02 +0000 | [diff] [blame^] | 211 | releaseBuffers(Desc.Buffers); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 212 | for (const std::pair<uint64_t, ResourceUsage> &R : Desc.Resources) { |
| 213 | const CycleSegment &CS = R.second.CS; |
| 214 | if (!CS.size()) { |
| 215 | releaseResource(R.first); |
| 216 | continue; |
| 217 | } |
| 218 | |
| 219 | assert(CS.begin() == 0 && "Invalid {Start, End} cycles!"); |
| 220 | if (!R.second.isReserved()) { |
| 221 | ResourceRef Pipe = selectPipe(R.first); |
| 222 | use(Pipe); |
| 223 | BusyResources[Pipe] += CS.size(); |
Andrea Di Biagio | 0c54129 | 2018-03-10 16:55:07 +0000 | [diff] [blame] | 224 | // Replace the resource mask with a valid processor resource index. |
| 225 | const ResourceState &RS = *Resources[Pipe.first]; |
| 226 | Pipe.first = RS.getProcResourceID(); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 227 | Pipes.emplace_back(std::pair<ResourceRef, unsigned>(Pipe, CS.size())); |
| 228 | } else { |
| 229 | assert((countPopulation(R.first) > 1) && "Expected a group!"); |
| 230 | // Mark this group as reserved. |
| 231 | assert(R.second.isReserved()); |
| 232 | reserveResource(R.first); |
| 233 | BusyResources[ResourceRef(R.first, R.first)] += CS.size(); |
| 234 | } |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | void ResourceManager::cycleEvent(SmallVectorImpl<ResourceRef> &ResourcesFreed) { |
| 239 | for (std::pair<ResourceRef, unsigned> &BR : BusyResources) { |
| 240 | if (BR.second) |
| 241 | BR.second--; |
| 242 | if (!BR.second) { |
| 243 | // Release this resource. |
| 244 | const ResourceRef &RR = BR.first; |
| 245 | |
| 246 | if (countPopulation(RR.first) == 1) |
| 247 | release(RR); |
| 248 | |
| 249 | releaseResource(RR.first); |
| 250 | ResourcesFreed.push_back(RR); |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | for (const ResourceRef &RF : ResourcesFreed) |
| 255 | BusyResources.erase(RF); |
| 256 | } |
| 257 | |
| 258 | Instruction *Scheduler::scheduleInstruction(unsigned Idx, Instruction *MCIS) { |
| 259 | assert(WaitQueue.find(Idx) == WaitQueue.end()); |
| 260 | assert(ReadyQueue.find(Idx) == ReadyQueue.end()); |
| 261 | assert(IssuedQueue.find(Idx) == IssuedQueue.end()); |
| 262 | |
| 263 | // Special case where MCIS is a zero-latency instruction. A zero-latency |
| 264 | // instruction doesn't consume any scheduler resources. That is because it |
| 265 | // doesn't need to be executed. Most of the times, zero latency instructions |
| 266 | // are removed at register renaming stage. For example, register-register |
| 267 | // moves can be removed at register renaming stage by creating new aliases. |
| 268 | // Zero-idiom instruction (for example: a `xor reg, reg`) can also be |
| 269 | // eliminated at register renaming stage, since we know in advance that those |
| 270 | // clear their output register. |
| 271 | if (MCIS->isZeroLatency()) { |
Andrea Di Biagio | 373c38a | 2018-03-08 20:21:55 +0000 | [diff] [blame] | 272 | notifyInstructionReady(Idx); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 273 | MCIS->forceExecuted(); |
| 274 | notifyInstructionIssued(Idx, {}); |
| 275 | notifyInstructionExecuted(Idx); |
| 276 | return MCIS; |
| 277 | } |
| 278 | |
| 279 | // Consume entries in the reservation stations. |
| 280 | const InstrDesc &Desc = MCIS->getDesc(); |
Andrea Di Biagio | e1a1da1 | 2018-03-13 13:58:02 +0000 | [diff] [blame^] | 281 | Resources->reserveBuffers(Desc.Buffers); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 282 | |
| 283 | // Mark units with BufferSize=0 as reserved. These resources will only |
| 284 | // be released after MCIS is issued, and all the ResourceCycles for |
| 285 | // those units have been consumed. |
Andrea Di Biagio | e1a1da1 | 2018-03-13 13:58:02 +0000 | [diff] [blame^] | 286 | Resources->reserveDispatchHazardResources(Desc.Buffers); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 287 | |
| 288 | bool MayLoad = Desc.MayLoad; |
| 289 | bool MayStore = Desc.MayStore; |
| 290 | if (MayLoad || MayStore) |
| 291 | LSU->reserve(Idx, MayLoad, MayStore, Desc.HasSideEffects); |
| 292 | |
| 293 | MCIS->dispatch(); |
| 294 | bool IsReady = MCIS->isReady(); |
| 295 | if (IsReady && (MayLoad || MayStore)) |
| 296 | IsReady &= LSU->isReady(Idx); |
| 297 | |
| 298 | if (!IsReady) { |
| 299 | DEBUG(dbgs() << "[SCHEDULER] Adding " << Idx << " to the Wait Queue\n"); |
| 300 | WaitQueue[Idx] = MCIS; |
| 301 | return MCIS; |
| 302 | } |
| 303 | notifyInstructionReady(Idx); |
| 304 | |
| 305 | // Special case where the instruction is ready, and it uses an in-order |
| 306 | // dispatch/issue processor resource. The instruction is issued immediately to |
| 307 | // the pipelines. Any other in-order buffered resources (i.e. BufferSize=1) |
| 308 | // are consumed. |
| 309 | if (Resources->mustIssueImmediately(Desc)) { |
| 310 | DEBUG(dbgs() << "[SCHEDULER] Instruction " << Idx |
| 311 | << " issued immediately\n"); |
| 312 | issueInstruction(MCIS, Idx); |
| 313 | return MCIS; |
| 314 | } |
| 315 | |
| 316 | DEBUG(dbgs() << "[SCHEDULER] Adding " << Idx << " to the Ready Queue\n"); |
| 317 | ReadyQueue[Idx] = MCIS; |
| 318 | return MCIS; |
| 319 | } |
| 320 | |
| 321 | void Scheduler::cycleEvent(unsigned /* unused */) { |
| 322 | SmallVector<ResourceRef, 8> ResourcesFreed; |
| 323 | Resources->cycleEvent(ResourcesFreed); |
| 324 | |
| 325 | for (const ResourceRef &RR : ResourcesFreed) |
| 326 | notifyResourceAvailable(RR); |
| 327 | |
| 328 | updateIssuedQueue(); |
| 329 | updatePendingQueue(); |
| 330 | issue(); |
| 331 | } |
| 332 | |
| 333 | #ifndef NDEBUG |
| 334 | void Scheduler::dump() const { |
| 335 | dbgs() << "[SCHEDULER]: WaitQueue size is: " << WaitQueue.size() << '\n'; |
| 336 | dbgs() << "[SCHEDULER]: ReadyQueue size is: " << ReadyQueue.size() << '\n'; |
| 337 | dbgs() << "[SCHEDULER]: IssuedQueue size is: " << IssuedQueue.size() << '\n'; |
| 338 | Resources->dump(); |
| 339 | } |
| 340 | #endif |
| 341 | |
| 342 | Scheduler::Event Scheduler::canBeDispatched(const InstrDesc &Desc) const { |
| 343 | if (Desc.MayLoad && LSU->isLQFull()) |
| 344 | return HWS_LD_QUEUE_UNAVAILABLE; |
| 345 | if (Desc.MayStore && LSU->isSQFull()) |
| 346 | return HWS_ST_QUEUE_UNAVAILABLE; |
| 347 | |
| 348 | Scheduler::Event Event; |
Andrea Di Biagio | e1a1da1 | 2018-03-13 13:58:02 +0000 | [diff] [blame^] | 349 | switch (Resources->canBeDispatched(Desc.Buffers)) { |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 350 | case ResourceStateEvent::RS_BUFFER_AVAILABLE: |
| 351 | Event = HWS_AVAILABLE; |
| 352 | break; |
| 353 | case ResourceStateEvent::RS_BUFFER_UNAVAILABLE: |
| 354 | Event = HWS_QUEUE_UNAVAILABLE; |
| 355 | break; |
| 356 | case ResourceStateEvent::RS_RESERVED: |
| 357 | Event = HWS_DISPATCH_GROUP_RESTRICTION; |
| 358 | } |
| 359 | return Event; |
| 360 | } |
| 361 | |
| 362 | void Scheduler::issueInstruction(Instruction *IS, unsigned InstrIndex) { |
| 363 | // Issue the instruction and collect all the consumed resources |
| 364 | // into a vector. That vector is then used to notify the listener. |
| 365 | // Most instructions consume very few resurces (typically one or |
| 366 | // two resources). We use a small vector here, and conservatively |
| 367 | // initialize its capacity to 4. This should address the majority of |
| 368 | // the cases. |
| 369 | SmallVector<std::pair<ResourceRef, unsigned>, 4> UsedResources; |
| 370 | |
| 371 | const InstrDesc &D = IS->getDesc(); |
| 372 | Resources->issueInstruction(InstrIndex, D, UsedResources); |
| 373 | // Notify the instruction that it started executing. |
| 374 | // This updates the internal state of each write. |
| 375 | IS->execute(); |
| 376 | |
| 377 | if (D.MaxLatency) { |
| 378 | IssuedQueue[InstrIndex] = IS; |
| 379 | notifyInstructionIssued(InstrIndex, UsedResources); |
| 380 | } else { |
| 381 | // A zero latency instruction which reads and/or updates registers. |
| 382 | notifyInstructionIssued(InstrIndex, UsedResources); |
| 383 | notifyInstructionExecuted(InstrIndex); |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | void Scheduler::issue() { |
| 388 | std::vector<unsigned> ToRemove; |
| 389 | for (const QueueEntryTy QueueEntry : ReadyQueue) { |
| 390 | // Give priority to older instructions in ReadyQueue. The ready queue is |
| 391 | // ordered by key, and therefore older instructions are visited first. |
| 392 | Instruction *IS = QueueEntry.second; |
| 393 | const InstrDesc &D = IS->getDesc(); |
| 394 | if (!Resources->canBeIssued(D)) |
| 395 | continue; |
| 396 | unsigned InstrIndex = QueueEntry.first; |
| 397 | issueInstruction(IS, InstrIndex); |
| 398 | ToRemove.emplace_back(InstrIndex); |
| 399 | } |
| 400 | |
| 401 | for (const unsigned InstrIndex : ToRemove) |
| 402 | ReadyQueue.erase(InstrIndex); |
| 403 | } |
| 404 | |
| 405 | void Scheduler::updatePendingQueue() { |
| 406 | // Scan the set of waiting instructions and promote them to the |
| 407 | // ready queue if operands are all ready. |
| 408 | for (auto I = WaitQueue.begin(), E = WaitQueue.end(); I != E;) { |
| 409 | const QueueEntryTy Entry = *I; |
| 410 | Entry.second->cycleEvent(); |
| 411 | |
| 412 | const InstrDesc &Desc = Entry.second->getDesc(); |
| 413 | bool IsMemOp = Desc.MayLoad || Desc.MayStore; |
| 414 | bool IsReady = Entry.second->isReady(); |
| 415 | if (IsReady && IsMemOp) |
| 416 | IsReady &= LSU->isReady(Entry.first); |
| 417 | |
| 418 | if (IsReady) { |
| 419 | notifyInstructionReady(Entry.first); |
| 420 | ReadyQueue[Entry.first] = Entry.second; |
| 421 | auto ToRemove = I; |
| 422 | ++I; |
| 423 | WaitQueue.erase(ToRemove); |
| 424 | } else { |
| 425 | ++I; |
| 426 | } |
| 427 | } |
| 428 | } |
| 429 | |
| 430 | void Scheduler::updateIssuedQueue() { |
| 431 | for (auto I = IssuedQueue.begin(), E = IssuedQueue.end(); I != E;) { |
| 432 | const QueueEntryTy Entry = *I; |
| 433 | Entry.second->cycleEvent(); |
| 434 | if (Entry.second->isExecuted()) { |
| 435 | notifyInstructionExecuted(Entry.first); |
| 436 | auto ToRemove = I; |
| 437 | ++I; |
| 438 | IssuedQueue.erase(ToRemove); |
| 439 | } else { |
| 440 | DEBUG(dbgs() << "[SCHEDULER]: Instruction " << Entry.first |
| 441 | << " is still executing.\n"); |
| 442 | ++I; |
| 443 | } |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | void Scheduler::notifyInstructionIssued( |
| 448 | unsigned Index, const ArrayRef<std::pair<ResourceRef, unsigned>> &Used) { |
Clement Courbet | 844f22d | 2018-03-13 13:11:01 +0000 | [diff] [blame] | 449 | DEBUG(dbgs() << "[E] Instruction Issued: " << Index << '\n'; |
| 450 | for (const std::pair<ResourceRef, unsigned> &Resource |
| 451 | : Used) { |
| 452 | dbgs() << "[E] Resource Used: [" << Resource.first.first << '.' |
| 453 | << Resource.first.second << "]\n"; |
| 454 | dbgs() << " cycles: " << Resource.second << '\n'; |
| 455 | }); |
| 456 | Owner->notifyInstructionEvent(HWInstructionIssuedEvent(Index, Used)); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | void Scheduler::notifyInstructionExecuted(unsigned Index) { |
| 460 | LSU->onInstructionExecuted(Index); |
Clement Courbet | 844f22d | 2018-03-13 13:11:01 +0000 | [diff] [blame] | 461 | DEBUG(dbgs() << "[E] Instruction Executed: " << Index << '\n'); |
| 462 | Owner->notifyInstructionEvent( |
| 463 | HWInstructionEvent(HWInstructionEvent::Executed, Index)); |
| 464 | |
| 465 | const Instruction &IS = Owner->getInstruction(Index); |
| 466 | DU->onInstructionExecuted(IS.getRCUTokenID()); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | void Scheduler::notifyInstructionReady(unsigned Index) { |
Clement Courbet | 844f22d | 2018-03-13 13:11:01 +0000 | [diff] [blame] | 470 | DEBUG(dbgs() << "[E] Instruction Ready: " << Index << '\n'); |
| 471 | Owner->notifyInstructionEvent( |
| 472 | HWInstructionEvent(HWInstructionEvent::Ready, Index)); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | void Scheduler::notifyResourceAvailable(const ResourceRef &RR) { |
| 476 | Owner->notifyResourceAvailable(RR); |
| 477 | } |
| 478 | } // namespace mca |