]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/MCA/Stages/RetireStage.cpp
MFC r345805: Unify SCSI_STATUS_BUSY retry handling with other cases.
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / MCA / Stages / RetireStage.cpp
1 //===---------------------- RetireStage.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 retire stage of an instruction pipeline.
12 /// The RetireStage represents the process logic that interacts with the
13 /// simulated RetireControlUnit hardware.
14 ///
15 //===----------------------------------------------------------------------===//
16
17 #include "llvm/MCA/Stages/RetireStage.h"
18 #include "llvm/MCA/HWEventListener.h"
19 #include "llvm/Support/Debug.h"
20
21 #define DEBUG_TYPE "llvm-mca"
22
23 namespace llvm {
24 namespace mca {
25
26 llvm::Error RetireStage::cycleStart() {
27   if (RCU.isEmpty())
28     return llvm::ErrorSuccess();
29
30   const unsigned MaxRetirePerCycle = RCU.getMaxRetirePerCycle();
31   unsigned NumRetired = 0;
32   while (!RCU.isEmpty()) {
33     if (MaxRetirePerCycle != 0 && NumRetired == MaxRetirePerCycle)
34       break;
35     const RetireControlUnit::RUToken &Current = RCU.peekCurrentToken();
36     if (!Current.Executed)
37       break;
38     RCU.consumeCurrentToken();
39     notifyInstructionRetired(Current.IR);
40     NumRetired++;
41   }
42
43   return llvm::ErrorSuccess();
44 }
45
46 llvm::Error RetireStage::execute(InstRef &IR) {
47   RCU.onInstructionExecuted(IR.getInstruction()->getRCUTokenID());
48   return llvm::ErrorSuccess();
49 }
50
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();
55
56   for (const WriteState &WS : Inst.getDefs())
57     PRF.removeRegisterWrite(WS, FreedRegs);
58   notifyEvent<HWInstructionEvent>(HWInstructionRetiredEvent(IR, FreedRegs));
59 }
60
61 } // namespace mca
62 } // namespace llvm