OSDN Git Service

[llvm-mca] Fix header comments. NFC.
[android-x86/external-llvm.git] / tools / llvm-mca / Backend.cpp
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 "FetchStage.h"
17 #include "HWEventListener.h"
18 #include "llvm/CodeGen/TargetSchedule.h"
19 #include "llvm/Support/Debug.h"
20
21 namespace mca {
22
23 #define DEBUG_TYPE "llvm-mca"
24
25 using namespace llvm;
26
27 void Backend::addEventListener(HWEventListener *Listener) {
28   if (Listener)
29     Listeners.insert(Listener);
30 }
31
32 void Backend::run() {
33   while (Fetch->isReady() || !Dispatch->isReady())
34     runCycle(Cycles++);
35 }
36
37 void Backend::runCycle(unsigned Cycle) {
38   notifyCycleBegin(Cycle);
39
40   InstRef IR;
41   Dispatch->preExecute(IR);
42   HWS->cycleEvent(); // TODO: This will eventually be stage-ified.
43
44   while (Fetch->execute(IR)) {
45     if (!Dispatch->execute(IR))
46       break;
47     Fetch->postExecute(IR);
48   }
49
50   notifyCycleEnd(Cycle);
51 }
52
53 void Backend::notifyCycleBegin(unsigned Cycle) {
54   LLVM_DEBUG(dbgs() << "[E] Cycle begin: " << Cycle << '\n');
55   for (HWEventListener *Listener : Listeners)
56     Listener->onCycleBegin();
57 }
58
59 void Backend::notifyInstructionEvent(const HWInstructionEvent &Event) {
60   for (HWEventListener *Listener : Listeners)
61     Listener->onInstructionEvent(Event);
62 }
63
64 void Backend::notifyStallEvent(const HWStallEvent &Event) {
65   for (HWEventListener *Listener : Listeners)
66     Listener->onStallEvent(Event);
67 }
68
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);
74 }
75
76 void Backend::notifyReservedBuffers(ArrayRef<unsigned> Buffers) {
77   for (HWEventListener *Listener : Listeners)
78     Listener->onReservedBuffers(Buffers);
79 }
80
81 void Backend::notifyReleasedBuffers(ArrayRef<unsigned> Buffers) {
82   for (HWEventListener *Listener : Listeners)
83     Listener->onReleasedBuffers(Buffers);
84 }
85
86 void Backend::notifyCycleEnd(unsigned Cycle) {
87   LLVM_DEBUG(dbgs() << "[E] Cycle end: " << Cycle << "\n\n");
88   for (HWEventListener *Listener : Listeners)
89     Listener->onCycleEnd();
90 }
91 } // namespace mca.