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 "RetireStage.h"
18 #include "HWEventListener.h"
19 #include "llvm/Support/Debug.h"
23 #define DEBUG_TYPE "llvm-mca"
27 void RetireStage::cycleStart() {
31 const unsigned MaxRetirePerCycle = RCU.getMaxRetirePerCycle();
32 unsigned NumRetired = 0;
33 while (!RCU.isEmpty()) {
34 if (MaxRetirePerCycle != 0 && NumRetired == MaxRetirePerCycle)
36 const RetireControlUnit::RUToken &Current = RCU.peekCurrentToken();
37 if (!Current.Executed)
39 RCU.consumeCurrentToken();
40 notifyInstructionRetired(Current.IR);
45 void RetireStage::notifyInstructionRetired(const InstRef &IR) {
46 LLVM_DEBUG(dbgs() << "[E] Instruction Retired: #" << IR << '\n');
47 SmallVector<unsigned, 4> FreedRegs(PRF.getNumRegisterFiles());
48 const Instruction &Inst = *IR.getInstruction();
49 const InstrDesc &Desc = Inst.getDesc();
51 bool ShouldFreeRegs = !(Desc.isZeroLatency() && Inst.isDependencyBreaking());
52 for (const std::unique_ptr<WriteState> &WS : Inst.getDefs())
53 PRF.removeRegisterWrite(*WS.get(), FreedRegs, ShouldFreeRegs);
54 notifyEvent<HWInstructionEvent>(HWInstructionRetiredEvent(IR, FreedRegs));