LLVM  8.0.1
EntryStage.cpp
Go to the documentation of this file.
1 //===---------------------- EntryStage.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 
17 #include "llvm/MCA/Instruction.h"
18 
19 namespace llvm {
20 namespace mca {
21 
22 bool EntryStage::hasWorkToComplete() const { return CurrentInstruction; }
23 
24 bool EntryStage::isAvailable(const InstRef & /* unused */) const {
25  if (CurrentInstruction)
26  return checkNextStage(CurrentInstruction);
27  return false;
28 }
29 
30 void EntryStage::getNextInstruction() {
31  assert(!CurrentInstruction && "There is already an instruction to process!");
32  if (!SM.hasNext())
33  return;
34  SourceRef SR = SM.peekNext();
35  std::unique_ptr<Instruction> Inst = llvm::make_unique<Instruction>(SR.second);
36  CurrentInstruction = InstRef(SR.first, Inst.get());
37  Instructions.emplace_back(std::move(Inst));
38  SM.updateNext();
39 }
40 
42  assert(CurrentInstruction && "There is no instruction to process!");
43  if (llvm::Error Val = moveToTheNextStage(CurrentInstruction))
44  return Val;
45 
46  // Move the program counter.
47  CurrentInstruction.invalidate();
48  getNextInstruction();
49  return llvm::ErrorSuccess();
50 }
51 
53  if (!CurrentInstruction)
54  getNextInstruction();
55  return llvm::ErrorSuccess();
56 }
57 
59  // Find the first instruction which hasn't been retired.
60  auto Range = make_range(&Instructions[NumRetired], Instructions.end());
61  auto It = find_if(Range, [](const std::unique_ptr<Instruction> &I) {
62  return !I->isRetired();
63  });
64 
65  NumRetired = std::distance(Instructions.begin(), It);
66  // Erase instructions up to the first that hasn't been retired.
67  if ((NumRetired * 2) >= Instructions.size()) {
68  Instructions.erase(Instructions.begin(), It);
69  NumRetired = 0;
70  }
71 
72  return llvm::ErrorSuccess();
73 }
74 
75 } // namespace mca
76 } // namespace llvm
This class represents lattice values for constants.
Definition: AllocatorList.h:24
bool isAvailable(const InstRef &IR) const override
Returns true if it can execute IR during this cycle.
Definition: EntryStage.cpp:24
Subclass of Error for the sole purpose of identifying the success path in the type system...
Definition: Error.h:325
bool checkNextStage(const InstRef &IR) const
Definition: Stage.h:63
bool hasWorkToComplete() const override
Returns true if some instructions are still executing this stage.
Definition: EntryStage.cpp:22
An InstRef contains both a SourceMgr index and Instruction pair.
Definition: Instruction.h:478
This file defines the Entry stage of an instruction pipeline.
bool hasNext() const
Definition: SourceMgr.h:41
void invalidate()
Invalidate this reference.
Definition: Instruction.h:495
auto find_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly...
Definition: STLExtras.h:1214
SourceRef peekNext() const
Definition: SourceMgr.h:44
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
Error cycleEnd() override
Called once at the end of each cycle.
Definition: EntryStage.cpp:58
Error moveToTheNextStage(InstRef &IR)
Called when an instruction is ready to move the next pipeline stage.
Definition: Stage.h:71
#define I(x, y, z)
Definition: MD5.cpp:58
std::pair< unsigned, const Instruction & > SourceRef
Definition: SourceMgr.h:24
This file defines abstractions used by the Pipeline to model register reads, register writes and inst...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Lightweight error class with error context and mandatory checking.
Definition: Error.h:158
Error execute(InstRef &IR) override
The primary action that this stage performs on instruction IR.
Definition: EntryStage.cpp:41
Error cycleStart() override
Called once at the start of each cycle.
Definition: EntryStage.cpp:52