1 //===---------------------- RetireStage.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 retire stage of an instruction pipeline.
12 /// The RetireStage represents the process logic that interacts with the
13 /// simulated RetireControlUnit hardware.
15 //===----------------------------------------------------------------------===//
17 #include "llvm/MCA/Stages/RetireStage.h"
18 #include "llvm/MCA/HWEventListener.h"
19 #include "llvm/Support/Debug.h"
21 #define DEBUG_TYPE "llvm-mca"
26 llvm::Error RetireStage::cycleStart() {
28 return llvm::ErrorSuccess();
30 const unsigned MaxRetirePerCycle = RCU.getMaxRetirePerCycle();
31 unsigned NumRetired = 0;
32 while (!RCU.isEmpty()) {
33 if (MaxRetirePerCycle != 0 && NumRetired == MaxRetirePerCycle)
35 const RetireControlUnit::RUToken &Current = RCU.peekCurrentToken();
36 if (!Current.Executed)
38 RCU.consumeCurrentToken();
39 notifyInstructionRetired(Current.IR);
43 return llvm::ErrorSuccess();
46 llvm::Error RetireStage::execute(InstRef &IR) {
47 RCU.onInstructionExecuted(IR.getInstruction()->getRCUTokenID());
48 return llvm::ErrorSuccess();
51 void RetireStage::notifyInstructionRetired(const InstRef &IR) const {
52 LLVM_DEBUG(llvm::dbgs() << "[E] Instruction Retired: #" << IR << '\n');
53 llvm::SmallVector<unsigned, 4> FreedRegs(PRF.getNumRegisterFiles());
54 const Instruction &Inst = *IR.getInstruction();
56 for (const WriteState &WS : Inst.getDefs())
57 PRF.removeRegisterWrite(WS, FreedRegs);
58 notifyEvent<HWInstructionEvent>(HWInstructionRetiredEvent(IR, FreedRegs));