LLVM  8.0.1
DispatchStage.h
Go to the documentation of this file.
1 //===----------------------- DispatchStage.h --------------------*- 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 models the dispatch component of an instruction pipeline.
12 ///
13 /// The DispatchStage is responsible for updating instruction dependencies
14 /// and communicating to the simulated instruction scheduler that an instruction
15 /// is ready to be scheduled for execution.
16 ///
17 //===----------------------------------------------------------------------===//
18 
19 #ifndef LLVM_MCA_DISPATCH_STAGE_H
20 #define LLVM_MCA_DISPATCH_STAGE_H
21 
22 #include "llvm/MC/MCRegisterInfo.h"
27 #include "llvm/MCA/Instruction.h"
28 #include "llvm/MCA/Stages/Stage.h"
29 
30 namespace llvm {
31 namespace mca {
32 
33 // Implements the hardware dispatch logic.
34 //
35 // This class is responsible for the dispatch stage, in which instructions are
36 // dispatched in groups to the Scheduler. An instruction can be dispatched if
37 // the following conditions are met:
38 // 1) There are enough entries in the reorder buffer (see class
39 // RetireControlUnit) to write the opcodes associated with the instruction.
40 // 2) There are enough physical registers to rename output register operands.
41 // 3) There are enough entries available in the used buffered resource(s).
42 //
43 // The number of micro opcodes that can be dispatched in one cycle is limited by
44 // the value of field 'DispatchWidth'. A "dynamic dispatch stall" occurs when
45 // processor resources are not available. Dispatch stall events are counted
46 // during the entire execution of the code, and displayed by the performance
47 // report when flag '-dispatch-stats' is specified.
48 //
49 // If the number of micro opcodes exceedes DispatchWidth, then the instruction
50 // is dispatched in multiple cycles.
51 class DispatchStage final : public Stage {
52  unsigned DispatchWidth;
53  unsigned AvailableEntries;
54  unsigned CarryOver;
55  InstRef CarriedOver;
56  const MCSubtargetInfo &STI;
57  RetireControlUnit &RCU;
58  RegisterFile &PRF;
59 
60  bool checkRCU(const InstRef &IR) const;
61  bool checkPRF(const InstRef &IR) const;
62  bool canDispatch(const InstRef &IR) const;
63  Error dispatch(InstRef IR);
64 
65  void updateRAWDependencies(ReadState &RS, const MCSubtargetInfo &STI);
66 
67  void notifyInstructionDispatched(const InstRef &IR,
68  ArrayRef<unsigned> UsedPhysRegs,
69  unsigned uOps) const;
70 
71 public:
72  DispatchStage(const MCSubtargetInfo &Subtarget, const MCRegisterInfo &MRI,
73  unsigned MaxDispatchWidth, RetireControlUnit &R,
74  RegisterFile &F)
75  : DispatchWidth(MaxDispatchWidth), AvailableEntries(MaxDispatchWidth),
76  CarryOver(0U), CarriedOver(), STI(Subtarget), RCU(R), PRF(F) {}
77 
78  bool isAvailable(const InstRef &IR) const override;
79 
80  // The dispatch logic internally doesn't buffer instructions. So there is
81  // never work to do at the beginning of every cycle.
82  bool hasWorkToComplete() const override { return false; }
83  Error cycleStart() override;
84  Error execute(InstRef &IR) override;
85 
86 #ifndef NDEBUG
87  void dump() const;
88 #endif
89 };
90 } // namespace mca
91 } // namespace llvm
92 
93 #endif // LLVM_MCA_DISPATCH_STAGE_H
This class represents lattice values for constants.
Definition: AllocatorList.h:24
This file simulates the hardware responsible for retiring instructions.
bool hasWorkToComplete() const override
Returns true if some instructions are still executing this stage.
Definition: DispatchStage.h:82
F(f)
An InstRef contains both a SourceMgr index and Instruction pair.
Definition: Instruction.h:478
This class tracks which instructions are in-flight (i.e., dispatched but not retired) in the OoO back...
Tracks register operand latency in cycles.
Definition: Instruction.h:205
This file defines a register mapping file class.
Error cycleStart() override
Called once at the start of each cycle.
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
This file defines a stage.
unsigned const MachineRegisterInfo * MRI
Manages hardware register files, and tracks register definitions for register renaming purposes...
Definition: RegisterFile.h:36
This file defines the main interface for hardware event listeners.
DispatchStage(const MCSubtargetInfo &Subtarget, const MCRegisterInfo &MRI, unsigned MaxDispatchWidth, RetireControlUnit &R, RegisterFile &F)
Definition: DispatchStage.h:72
Generic base class for all target subtargets.
This file defines abstractions used by the Pipeline to model register reads, register writes and inst...
Error execute(InstRef &IR) override
The primary action that this stage performs on instruction IR.
Lightweight error class with error context and mandatory checking.
Definition: Error.h:158
Statically lint checks LLVM IR
Definition: Lint.cpp:193
bool isAvailable(const InstRef &IR) const override
Returns true if it can execute IR during this cycle.