1 //===---------------------- FetchStage.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 /// 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. 13 /// 14 //===----------------------------------------------------------------------===// 15 16 #include "FetchStage.h" 17 18 namespace mca { 19 hasWorkToComplete() const20bool FetchStage::hasWorkToComplete() const { return SM.hasNext(); } 21 execute(InstRef & IR)22bool FetchStage::execute(InstRef &IR) { 23 if (!SM.hasNext()) 24 return false; 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); 29 return true; 30 } 31 postExecute()32void FetchStage::postExecute() { SM.updateNext(); } 33 cycleEnd()34void 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(); 39 }); 40 41 // Erase instructions up to the first that hasn't been retired. 42 if (It != Instructions.begin()) 43 Instructions.erase(Instructions.begin(), It); 44 } 45 46 } // namespace mca 47