1 //===--------------------- Backend.cpp --------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// Implementation of class Backend which emulates an hardware OoO backend.
13 //===----------------------------------------------------------------------===//
16 #include "FetchStage.h"
17 #include "HWEventListener.h"
18 #include "llvm/CodeGen/TargetSchedule.h"
19 #include "llvm/Support/Debug.h"
23 #define DEBUG_TYPE "llvm-mca"
27 void Backend::addEventListener(HWEventListener *Listener) {
29 Listeners.insert(Listener);
33 while (Fetch->isReady() || !Dispatch->isReady())
37 void Backend::runCycle(unsigned Cycle) {
38 notifyCycleBegin(Cycle);
41 Dispatch->preExecute(IR);
42 HWS->cycleEvent(); // TODO: This will eventually be stage-ified.
44 while (Fetch->execute(IR)) {
45 if (!Dispatch->execute(IR))
47 Fetch->postExecute(IR);
50 notifyCycleEnd(Cycle);
53 void Backend::notifyCycleBegin(unsigned Cycle) {
54 LLVM_DEBUG(dbgs() << "[E] Cycle begin: " << Cycle << '\n');
55 for (HWEventListener *Listener : Listeners)
56 Listener->onCycleBegin();
59 void Backend::notifyInstructionEvent(const HWInstructionEvent &Event) {
60 for (HWEventListener *Listener : Listeners)
61 Listener->onInstructionEvent(Event);
64 void Backend::notifyStallEvent(const HWStallEvent &Event) {
65 for (HWEventListener *Listener : Listeners)
66 Listener->onStallEvent(Event);
69 void Backend::notifyResourceAvailable(const ResourceRef &RR) {
70 LLVM_DEBUG(dbgs() << "[E] Resource Available: [" << RR.first << '.'
71 << RR.second << "]\n");
72 for (HWEventListener *Listener : Listeners)
73 Listener->onResourceAvailable(RR);
76 void Backend::notifyReservedBuffers(ArrayRef<unsigned> Buffers) {
77 for (HWEventListener *Listener : Listeners)
78 Listener->onReservedBuffers(Buffers);
81 void Backend::notifyReleasedBuffers(ArrayRef<unsigned> Buffers) {
82 for (HWEventListener *Listener : Listeners)
83 Listener->onReleasedBuffers(Buffers);
86 void Backend::notifyCycleEnd(unsigned Cycle) {
87 LLVM_DEBUG(dbgs() << "[E] Cycle end: " << Cycle << "\n\n");
88 for (HWEventListener *Listener : Listeners)
89 Listener->onCycleEnd();