LLVM 22.0.0git
RetireStage.cpp
Go to the documentation of this file.
1//===---------------------- RetireStage.cpp ---------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8/// \file
9///
10/// This file defines the retire stage of an instruction pipeline.
11/// The RetireStage represents the process logic that interacts with the
12/// simulated RetireControlUnit hardware.
13///
14//===----------------------------------------------------------------------===//
15
18#include "llvm/Support/Debug.h"
19
20#define DEBUG_TYPE "llvm-mca"
21
22namespace llvm {
23namespace mca {
24
26 PRF.cycleStart();
27
28 const unsigned MaxRetirePerCycle = RCU.getMaxRetirePerCycle();
29 unsigned NumRetired = 0;
30 while (!RCU.isEmpty()) {
31 if (MaxRetirePerCycle != 0 && NumRetired == MaxRetirePerCycle)
32 break;
33 const RetireControlUnit::RUToken &Current = RCU.getCurrentToken();
34 if (!Current.Executed)
35 break;
37 RCU.consumeCurrentToken();
38 NumRetired++;
39 }
40
41 return llvm::ErrorSuccess();
42}
43
45 PRF.cycleEnd();
46 return llvm::ErrorSuccess();
47}
48
50 Instruction &IS = *IR.getInstruction();
51
52 PRF.onInstructionExecuted(&IS);
53 unsigned TokenID = IS.getRCUTokenID();
55 RCU.onInstructionExecuted(TokenID);
56
57 return llvm::ErrorSuccess();
58}
59
61 LLVM_DEBUG(llvm::dbgs() << "[E] Instruction Retired: #" << IR << '\n');
62 llvm::SmallVector<unsigned, 4> FreedRegs(PRF.getNumRegisterFiles());
63 const Instruction &Inst = *IR.getInstruction();
64
65 // Release the load/store queue entries.
66 if (Inst.isMemOp())
67 LSU.onInstructionRetired(IR);
68
69 for (const WriteState &WS : Inst.getDefs())
70 PRF.removeRegisterWrite(WS, FreedRegs);
72}
73
74} // namespace mca
75} // namespace llvm
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines the main interface for hardware event listeners.
Legalize the Machine IR a function s Machine IR
Definition Legalizer.cpp:80
This file defines the retire stage of a default instruction pipeline.
#define LLVM_DEBUG(...)
Definition Debug.h:114
Subclass of Error for the sole purpose of identifying the success path in the type system.
Definition Error.h:334
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
An InstRef contains both a SourceMgr index and Instruction pair.
SmallVectorImpl< WriteState > & getDefs()
An instruction propagated through the simulated instruction pipeline.
unsigned getRCUTokenID() const
Error cycleEnd() override
Called once at the end of each cycle.
void notifyInstructionRetired(const InstRef &IR) const
Error cycleStart() override
Called once at the start of each cycle.
Error execute(InstRef &IR) override
The primary action that this stage performs on instruction IR.
void notifyEvent(const EventT &Event) const
Notify listeners of a particular hardware event.
Definition Stage.h:83
Tracks uses of a register definition (e.g.
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition Debug.cpp:207
static const unsigned UnhandledTokenID