Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 1 | //===--------------------- Backend.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 | /// Implementation of class Backend which emulates an hardware OoO backend. |
| 12 | /// |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "Backend.h" |
| 16 | #include "HWEventListener.h" |
| 17 | #include "llvm/CodeGen/TargetSchedule.h" |
| 18 | #include "llvm/Support/Debug.h" |
| 19 | |
| 20 | namespace mca { |
| 21 | |
| 22 | #define DEBUG_TYPE "llvm-mca" |
| 23 | |
| 24 | using namespace llvm; |
| 25 | |
| 26 | void Backend::addEventListener(HWEventListener *Listener) { |
| 27 | if (Listener) |
| 28 | Listeners.insert(Listener); |
| 29 | } |
| 30 | |
| 31 | void Backend::runCycle(unsigned Cycle) { |
| 32 | notifyCycleBegin(Cycle); |
| 33 | |
Andrea Di Biagio | 4732d43ca | 2018-03-14 14:57:23 +0000 | [diff] [blame] | 34 | while (SM.hasNext()) { |
| 35 | InstRef IR = SM.peekNext(); |
| 36 | std::unique_ptr<Instruction> NewIS( |
| 37 | IB->createInstruction(STI, IR.first, *IR.second)); |
| 38 | const InstrDesc &Desc = NewIS->getDesc(); |
Andrea Di Biagio | 91ab2ee | 2018-03-19 13:23:07 +0000 | [diff] [blame^] | 39 | if (!DU->isAvailable(Desc.NumMicroOps) || |
| 40 | !DU->canDispatch(IR.first, *NewIS)) |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 41 | break; |
| 42 | |
Andrea Di Biagio | 4732d43ca | 2018-03-14 14:57:23 +0000 | [diff] [blame] | 43 | Instruction *IS = NewIS.get(); |
| 44 | Instructions[IR.first] = std::move(NewIS); |
| 45 | IS->setRCUTokenID(DU->dispatch(IR.first, IS, STI)); |
| 46 | SM.updateNext(); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | notifyCycleEnd(Cycle); |
| 50 | } |
| 51 | |
| 52 | void Backend::notifyCycleBegin(unsigned Cycle) { |
| 53 | DEBUG(dbgs() << "[E] Cycle begin: " << Cycle << '\n'); |
| 54 | for (HWEventListener *Listener : Listeners) |
| 55 | Listener->onCycleBegin(Cycle); |
| 56 | |
| 57 | DU->cycleEvent(Cycle); |
| 58 | HWS->cycleEvent(Cycle); |
| 59 | } |
| 60 | |
Clement Courbet | 844f22d | 2018-03-13 13:11:01 +0000 | [diff] [blame] | 61 | void Backend::notifyInstructionEvent(const HWInstructionEvent &Event) { |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 62 | for (HWEventListener *Listener : Listeners) |
Clement Courbet | 844f22d | 2018-03-13 13:11:01 +0000 | [diff] [blame] | 63 | Listener->onInstructionEvent(Event); |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 64 | } |
| 65 | |
Andrea Di Biagio | 91ab2ee | 2018-03-19 13:23:07 +0000 | [diff] [blame^] | 66 | void Backend::notifyStallEvent(const HWStallEvent &Event) { |
| 67 | for (HWEventListener *Listener : Listeners) |
| 68 | Listener->onStallEvent(Event); |
| 69 | } |
| 70 | |
Andrea Di Biagio | 3a6b092 | 2018-03-08 13:05:02 +0000 | [diff] [blame] | 71 | void Backend::notifyResourceAvailable(const ResourceRef &RR) { |
| 72 | DEBUG(dbgs() << "[E] Resource Available: [" << RR.first << '.' << RR.second |
| 73 | << "]\n"); |
| 74 | for (HWEventListener *Listener : Listeners) |
| 75 | Listener->onResourceAvailable(RR); |
| 76 | } |
| 77 | |
| 78 | void Backend::notifyCycleEnd(unsigned Cycle) { |
| 79 | DEBUG(dbgs() << "[E] Cycle end: " << Cycle << "\n\n"); |
| 80 | for (HWEventListener *Listener : Listeners) |
| 81 | Listener->onCycleEnd(Cycle); |
| 82 | } |
| 83 | |
| 84 | } // namespace mca. |