1 //===---------------------- FetchStage.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 defines the Fetch stage of an instruction pipeline. Its sole
12 /// purpose in life is to produce instructions for the rest of the pipeline.
14 //===----------------------------------------------------------------------===//
16 #include "FetchStage.h"
20 bool FetchStage::hasWorkToComplete() const { return SM.hasNext(); }
22 bool FetchStage::execute(InstRef &IR) {
25 const SourceRef SR = SM.peekNext();
26 std::unique_ptr<Instruction> I = IB.createInstruction(*SR.second);
27 IR = InstRef(SR.first, I.get());
28 Instructions[IR.getSourceIndex()] = std::move(I);
32 void FetchStage::postExecute() { SM.updateNext(); }
34 void FetchStage::cycleEnd() {
35 // Find the first instruction which hasn't been retired.
36 const InstMap::iterator It =
37 llvm::find_if(Instructions, [](const InstMap::value_type &KeyValuePair) {
38 return !KeyValuePair.second->isRetired();
41 // Erase instructions up to the first that hasn't been retired.
42 if (It != Instructions.begin())
43 Instructions.erase(Instructions.begin(), It);