1 //===--------------------- Pipeline.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 /// This file implements an ordered container of stages that simulate the
12 /// pipeline of a hardware backend.
14 //===----------------------------------------------------------------------===//
17 #include "HWEventListener.h"
18 #include "llvm/CodeGen/TargetSchedule.h"
19 #include "llvm/Support/Debug.h"
23 #define DEBUG_TYPE "llvm-mca"
27 void Pipeline::addEventListener(HWEventListener *Listener) {
29 Listeners.insert(Listener);
30 for (auto &S : Stages)
31 S->addListener(Listener);
34 bool Pipeline::hasWorkToProcess() {
35 const auto It = llvm::find_if(Stages, [](const std::unique_ptr<Stage> &S) {
36 return S->hasWorkToComplete();
38 return It != Stages.end();
41 // This routine returns early if any stage returns 'false' after execute() is
43 bool Pipeline::executeStages(InstRef &IR) {
44 for (const std::unique_ptr<Stage> &S : Stages)
50 void Pipeline::preExecuteStages() {
51 for (const std::unique_ptr<Stage> &S : Stages)
55 void Pipeline::postExecuteStages() {
56 for (const std::unique_ptr<Stage> &S : Stages)
60 void Pipeline::run() {
61 while (hasWorkToProcess()) {
69 void Pipeline::runCycle() {
70 // Update the stages before we do any processing for this cycle.
72 for (auto &S : Stages)
75 // Continue executing this cycle until any stage claims it cannot make
79 if (!executeStages(IR))
84 for (auto &S : Stages)
88 void Pipeline::notifyCycleBegin() {
89 LLVM_DEBUG(dbgs() << "[E] Cycle begin: " << Cycles << '\n');
90 for (HWEventListener *Listener : Listeners)
91 Listener->onCycleBegin();
94 void Pipeline::notifyCycleEnd() {
95 LLVM_DEBUG(dbgs() << "[E] Cycle end: " << Cycles << "\n\n");
96 for (HWEventListener *Listener : Listeners)
97 Listener->onCycleEnd();