1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-21 03:53:04 +02:00
llvm-mirror/lib/MCA/Pipeline.cpp
Chandler Carruth ae65e281f3 Update the file headers across all of the LLVM projects in the monorepo
to reflect the new license.

We understand that people may be surprised that we're moving the header
entirely to discuss the new license. We checked this carefully with the
Foundation's lawyer and we believe this is the correct approach.

Essentially, all code in the project is now made available by the LLVM
project under our new license, so you will see that the license headers
include that license only. Some of our contributors have contributed
code under our old license, and accordingly, we have retained a copy of
our old license notice in the top-level files in each project and
repository.

llvm-svn: 351636
2019-01-19 08:50:56 +00:00

97 lines
2.6 KiB
C++

//===--------------------- Pipeline.cpp -------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
/// \file
///
/// This file implements an ordered container of stages that simulate the
/// pipeline of a hardware backend.
///
//===----------------------------------------------------------------------===//
#include "llvm/MCA/Pipeline.h"
#include "llvm/MCA/HWEventListener.h"
#include "llvm/Support/Debug.h"
namespace llvm {
namespace mca {
#define DEBUG_TYPE "llvm-mca"
void Pipeline::addEventListener(HWEventListener *Listener) {
if (Listener)
Listeners.insert(Listener);
for (auto &S : Stages)
S->addListener(Listener);
}
bool Pipeline::hasWorkToProcess() {
return any_of(Stages, [](const std::unique_ptr<Stage> &S) {
return S->hasWorkToComplete();
});
}
Expected<unsigned> Pipeline::run() {
assert(!Stages.empty() && "Unexpected empty pipeline found!");
do {
notifyCycleBegin();
if (Error Err = runCycle())
return std::move(Err);
notifyCycleEnd();
++Cycles;
} while (hasWorkToProcess());
return Cycles;
}
Error Pipeline::runCycle() {
Error Err = ErrorSuccess();
// Update stages before we start processing new instructions.
for (auto I = Stages.rbegin(), E = Stages.rend(); I != E && !Err; ++I) {
const std::unique_ptr<Stage> &S = *I;
Err = S->cycleStart();
}
// Now fetch and execute new instructions.
InstRef IR;
Stage &FirstStage = *Stages[0];
while (!Err && FirstStage.isAvailable(IR))
Err = FirstStage.execute(IR);
// Update stages in preparation for a new cycle.
for (auto I = Stages.rbegin(), E = Stages.rend(); I != E && !Err; ++I) {
const std::unique_ptr<Stage> &S = *I;
Err = S->cycleEnd();
}
return Err;
}
void Pipeline::appendStage(std::unique_ptr<Stage> S) {
assert(S && "Invalid null stage in input!");
if (!Stages.empty()) {
Stage *Last = Stages.back().get();
Last->setNextInSequence(S.get());
}
Stages.push_back(std::move(S));
}
void Pipeline::notifyCycleBegin() {
LLVM_DEBUG(dbgs() << "\n[E] Cycle begin: " << Cycles << '\n');
for (HWEventListener *Listener : Listeners)
Listener->onCycleBegin();
}
void Pipeline::notifyCycleEnd() {
LLVM_DEBUG(dbgs() << "[E] Cycle end: " << Cycles << "\n");
for (HWEventListener *Listener : Listeners)
Listener->onCycleEnd();
}
} // namespace mca.
} // namespace llvm