]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/llvm-mca/FetchStage.cpp
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / llvm-mca / FetchStage.cpp
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
20 bool FetchStage::hasWorkToComplete() const { return SM.hasNext(); }
21
22 bool 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
32 void FetchStage::postExecute() { SM.updateNext(); }
33
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();
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