[llvm] r340668 - [llvm-mca] Move ResourceManager from Scheduler into its own file. NFC.

Matt Davis via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 24 15:59:13 PDT 2018


Author: mattd
Date: Fri Aug 24 15:59:13 2018
New Revision: 340668

URL: http://llvm.org/viewvc/llvm-project?rev=340668&view=rev
Log:
[llvm-mca] Move ResourceManager from Scheduler into its own file. NFC.

This time I should be preserving history of the ResourceManager changes.

Added:
    llvm/trunk/tools/llvm-mca/ResourceManager.cpp
      - copied, changed from r340661, llvm/trunk/tools/llvm-mca/Scheduler.cpp
    llvm/trunk/tools/llvm-mca/ResourceManager.h
      - copied, changed from r340661, llvm/trunk/tools/llvm-mca/Scheduler.h
Modified:
    llvm/trunk/tools/llvm-mca/CMakeLists.txt
    llvm/trunk/tools/llvm-mca/Scheduler.cpp
    llvm/trunk/tools/llvm-mca/Scheduler.h

Modified: llvm/trunk/tools/llvm-mca/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/CMakeLists.txt?rev=340668&r1=340667&r2=340668&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/CMakeLists.txt (original)
+++ llvm/trunk/tools/llvm-mca/CMakeLists.txt Fri Aug 24 15:59:13 2018
@@ -25,6 +25,7 @@ add_llvm_tool(llvm-mca
   Pipeline.cpp
   PipelinePrinter.cpp
   RegisterFile.cpp
+  ResourceManager.cpp
   RetireControlUnit.cpp
   RetireStage.cpp
   Scheduler.cpp

Copied: llvm/trunk/tools/llvm-mca/ResourceManager.cpp (from r340661, llvm/trunk/tools/llvm-mca/Scheduler.cpp)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/ResourceManager.cpp?p2=llvm/trunk/tools/llvm-mca/ResourceManager.cpp&p1=llvm/trunk/tools/llvm-mca/Scheduler.cpp&r1=340661&r2=340668&rev=340668&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/Scheduler.cpp (original)
+++ llvm/trunk/tools/llvm-mca/ResourceManager.cpp Fri Aug 24 15:59:13 2018
@@ -1,4 +1,4 @@
-//===--------------------- Scheduler.cpp ------------------------*- C++ -*-===//
+//===--------------------- ResourceManager.cpp ------------------*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -6,12 +6,14 @@
 // License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
-//
-// A scheduler for processor resource units and processor resource groups.
-//
+/// \file
+///
+/// The classes here represent processor resource units and their management
+/// strategy.  These classes are managed by the Scheduler.
+///
 //===----------------------------------------------------------------------===//
 
-#include "Scheduler.h"
+#include "ResourceManager.h"
 #include "Support.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/raw_ostream.h"
@@ -21,14 +23,8 @@ namespace mca {
 using namespace llvm;
 
 #define DEBUG_TYPE "llvm-mca"
-
 ResourceStrategy::~ResourceStrategy() = default;
 
-void Scheduler::initializeStrategy(std::unique_ptr<SchedulerStrategy> S) {
-  // Ensure we have a valid (non-null) strategy object.
-  Strategy = S ? std::move(S) : llvm::make_unique<DefaultSchedulerStrategy>();
-}
-
 void DefaultResourceStrategy::skipMask(uint64_t Mask) {
   NextInSequenceMask &= (~Mask);
   if (!NextInSequenceMask) {
@@ -55,8 +51,8 @@ void DefaultResourceStrategy::used(uint6
   skipMask(Mask);
 }
 
-ResourceState::ResourceState(const llvm::MCProcResourceDesc &Desc,
-                             unsigned Index, uint64_t Mask)
+ResourceState::ResourceState(const MCProcResourceDesc &Desc, unsigned Index,
+                             uint64_t Mask)
     : ProcResourceDescIndex(Index), ResourceMask(Mask),
       BufferSize(Desc.BufferSize) {
   if (llvm::countPopulation(ResourceMask) > 1)
@@ -101,7 +97,7 @@ getStrategyFor(const ResourceState &RS)
   return std::unique_ptr<ResourceStrategy>(nullptr);
 }
 
-ResourceManager::ResourceManager(const llvm::MCSchedModel &SM)
+ResourceManager::ResourceManager(const MCSchedModel &SM)
     : ProcResID2Mask(SM.getNumProcResourceKinds()) {
   computeProcResourceMasks(SM, ProcResID2Mask);
   Resources.resize(SM.getNumProcResourceKinds());
@@ -310,219 +306,4 @@ void ResourceManager::releaseResource(ui
   Resource.clearReserved();
 }
 
-// Anchor the vtable of SchedulerStrategy and DefaultSchedulerStrategy.
-SchedulerStrategy::~SchedulerStrategy() = default;
-DefaultSchedulerStrategy::~DefaultSchedulerStrategy() = default;
-
-#ifndef NDEBUG
-void Scheduler::dump() const {
-  dbgs() << "[SCHEDULER]: WaitSet size is: " << WaitSet.size() << '\n';
-  dbgs() << "[SCHEDULER]: ReadySet size is: " << ReadySet.size() << '\n';
-  dbgs() << "[SCHEDULER]: IssuedSet size is: " << IssuedSet.size() << '\n';
-  Resources->dump();
-}
-#endif
-
-Scheduler::Status Scheduler::isAvailable(const InstRef &IR) const {
-  const InstrDesc &Desc = IR.getInstruction()->getDesc();
-
-  switch (Resources->canBeDispatched(Desc.Buffers)) {
-  case ResourceStateEvent::RS_BUFFER_UNAVAILABLE:
-    return Scheduler::SC_BUFFERS_FULL;
-  case ResourceStateEvent::RS_RESERVED:
-    return Scheduler::SC_DISPATCH_GROUP_STALL;
-  case ResourceStateEvent::RS_BUFFER_AVAILABLE:
-    break;
-  }
-
-  // Give lower priority to LSUnit stall events.
-  switch (LSU->isAvailable(IR)) {
-  case LSUnit::LSU_LQUEUE_FULL:
-    return Scheduler::SC_LOAD_QUEUE_FULL;
-  case LSUnit::LSU_SQUEUE_FULL:
-    return Scheduler::SC_STORE_QUEUE_FULL;
-  case LSUnit::LSU_AVAILABLE:
-    return Scheduler::SC_AVAILABLE;
-  }
-
-  llvm_unreachable("Don't know how to process this LSU state result!");
-}
-
-void Scheduler::issueInstructionImpl(
-    InstRef &IR,
-    SmallVectorImpl<std::pair<ResourceRef, double>> &UsedResources) {
-  Instruction *IS = IR.getInstruction();
-  const InstrDesc &D = IS->getDesc();
-
-  // Issue the instruction and collect all the consumed resources
-  // into a vector. That vector is then used to notify the listener.
-  Resources->issueInstruction(D, UsedResources);
-
-  // Notify the instruction that it started executing.
-  // This updates the internal state of each write.
-  IS->execute();
-
-  if (IS->isExecuting())
-    IssuedSet.emplace_back(IR);
-  else if (IS->isExecuted())
-    LSU->onInstructionExecuted(IR);
-}
-
-// Release the buffered resources and issue the instruction.
-void Scheduler::issueInstruction(
-    InstRef &IR, SmallVectorImpl<std::pair<ResourceRef, double>> &UsedResources,
-    SmallVectorImpl<InstRef> &ReadyInstructions) {
-  const Instruction &Inst = *IR.getInstruction();
-  bool HasDependentUsers = Inst.hasDependentUsers();
-
-  Resources->releaseBuffers(Inst.getDesc().Buffers);
-  issueInstructionImpl(IR, UsedResources);
-  // Instructions that have been issued during this cycle might have unblocked
-  // other dependent instructions. Dependent instructions may be issued during
-  // this same cycle if operands have ReadAdvance entries.  Promote those
-  // instructions to the ReadySet and notify the caller that those are ready.
-  if (HasDependentUsers)
-    promoteToReadySet(ReadyInstructions);
-}
-
-void Scheduler::promoteToReadySet(SmallVectorImpl<InstRef> &Ready) {
-  // Scan the set of waiting instructions and promote them to the
-  // ready queue if operands are all ready.
-  unsigned RemovedElements = 0;
-  for (auto I = WaitSet.begin(), E = WaitSet.end(); I != E;) {
-    InstRef &IR = *I;
-    if (!IR.isValid())
-      break;
-
-    // Check if this instruction is now ready. In case, force
-    // a transition in state using method 'update()'.
-    Instruction &IS = *IR.getInstruction();
-    if (!IS.isReady())
-      IS.update();
-
-    // Check if there are still unsolved data dependencies.
-    if (!isReady(IR)) {
-      ++I;
-      continue;
-    }
-
-    Ready.emplace_back(IR);
-    ReadySet.emplace_back(IR);
-
-    IR.invalidate();
-    ++RemovedElements;
-    std::iter_swap(I, E - RemovedElements);
-  }
-
-  WaitSet.resize(WaitSet.size() - RemovedElements);
-}
-
-InstRef Scheduler::select() {
-  unsigned QueueIndex = ReadySet.size();
-  for (unsigned I = 0, E = ReadySet.size(); I != E; ++I) {
-    const InstRef &IR = ReadySet[I];
-    if (QueueIndex == ReadySet.size() ||
-        Strategy->compare(IR, ReadySet[QueueIndex])) {
-      const InstrDesc &D = IR.getInstruction()->getDesc();
-      if (Resources->canBeIssued(D))
-        QueueIndex = I;
-    }
-  }
-
-  if (QueueIndex == ReadySet.size())
-    return InstRef();
-
-  // We found an instruction to issue.
-  InstRef IR = ReadySet[QueueIndex];
-  std::swap(ReadySet[QueueIndex], ReadySet[ReadySet.size() - 1]);
-  ReadySet.pop_back();
-  return IR;
-}
-
-void Scheduler::updateIssuedSet(SmallVectorImpl<InstRef> &Executed) {
-  unsigned RemovedElements = 0;
-  for (auto I = IssuedSet.begin(), E = IssuedSet.end(); I != E;) {
-    InstRef &IR = *I;
-    if (!IR.isValid())
-      break;
-    Instruction &IS = *IR.getInstruction();
-    if (!IS.isExecuted()) {
-      LLVM_DEBUG(dbgs() << "[SCHEDULER]: Instruction #" << IR
-                        << " is still executing.\n");
-      ++I;
-      continue;
-    }
-
-    // Instruction IR has completed execution.
-    LSU->onInstructionExecuted(IR);
-    Executed.emplace_back(IR);
-    ++RemovedElements;
-    IR.invalidate();
-    std::iter_swap(I, E - RemovedElements);
-  }
-
-  IssuedSet.resize(IssuedSet.size() - RemovedElements);
-}
-
-void Scheduler::cycleEvent(SmallVectorImpl<ResourceRef> &Freed,
-                           SmallVectorImpl<InstRef> &Executed,
-                           SmallVectorImpl<InstRef> &Ready) {
-  // Release consumed resources.
-  Resources->cycleEvent(Freed);
-
-  // Propagate the cycle event to the 'Issued' and 'Wait' sets.
-  for (InstRef &IR : IssuedSet)
-    IR.getInstruction()->cycleEvent();
-
-  updateIssuedSet(Executed);
-
-  for (InstRef &IR : WaitSet)
-    IR.getInstruction()->cycleEvent();
-
-  promoteToReadySet(Ready);
-}
-
-bool Scheduler::mustIssueImmediately(const InstRef &IR) const {
-  // Instructions that use an in-order dispatch/issue processor resource must be
-  // issued immediately to the pipeline(s). Any other in-order buffered
-  // resources (i.e. BufferSize=1) is consumed.
-  const InstrDesc &Desc = IR.getInstruction()->getDesc();
-  return Desc.isZeroLatency() || Resources->mustIssueImmediately(Desc);
-}
-
-void Scheduler::dispatch(const InstRef &IR) {
-  const InstrDesc &Desc = IR.getInstruction()->getDesc();
-  Resources->reserveBuffers(Desc.Buffers);
-
-  // If necessary, reserve queue entries in the load-store unit (LSU).
-  bool IsMemOp = Desc.MayLoad || Desc.MayStore;
-  if (IsMemOp)
-    LSU->dispatch(IR);
-
-  if (!isReady(IR)) {
-    LLVM_DEBUG(dbgs() << "[SCHEDULER] Adding #" << IR << " to the WaitSet\n");
-    WaitSet.push_back(IR);
-    return;
-  }
-
-  // Don't add a zero-latency instruction to the Ready queue.
-  // A zero-latency instruction doesn't consume any scheduler resources. That is
-  // because it doesn't need to be executed, and it is often removed at register
-  // renaming stage. For example, register-register moves are often optimized at
-  // register renaming stage by simply updating register aliases. On some
-  // targets, zero-idiom instructions (for example: a xor that clears the value
-  // of a register) are treated specially, and are often eliminated at register
-  // renaming stage.
-  if (!mustIssueImmediately(IR)) {
-    LLVM_DEBUG(dbgs() << "[SCHEDULER] Adding #" << IR << " to the ReadySet\n");
-    ReadySet.push_back(IR);
-  }
-}
-
-bool Scheduler::isReady(const InstRef &IR) const {
-  const InstrDesc &Desc = IR.getInstruction()->getDesc();
-  bool IsMemOp = Desc.MayLoad || Desc.MayStore;
-  return IR.getInstruction()->isReady() && (!IsMemOp || LSU->isReady(IR));
-}
-
 } // namespace mca

Copied: llvm/trunk/tools/llvm-mca/ResourceManager.h (from r340661, llvm/trunk/tools/llvm-mca/Scheduler.h)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/ResourceManager.h?p2=llvm/trunk/tools/llvm-mca/ResourceManager.h&p1=llvm/trunk/tools/llvm-mca/Scheduler.h&r1=340661&r2=340668&rev=340668&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/Scheduler.h (original)
+++ llvm/trunk/tools/llvm-mca/ResourceManager.h Fri Aug 24 15:59:13 2018
@@ -1,4 +1,4 @@
-//===--------------------- Scheduler.h ------------------------*- C++ -*-===//
+//===--------------------- ResourceManager.h --------------------*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
@@ -8,21 +8,19 @@
 //===----------------------------------------------------------------------===//
 /// \file
 ///
-/// A scheduler for Processor Resource Units and Processor Resource Groups.
+/// The classes here represent processor resource units and their management
+/// strategy.  These classes are managed by the Scheduler.
 ///
 //===----------------------------------------------------------------------===//
 
-#ifndef LLVM_TOOLS_LLVM_MCA_SCHEDULER_H
-#define LLVM_TOOLS_LLVM_MCA_SCHEDULER_H
+#ifndef LLVM_TOOLS_LLVM_MCA_RESOURCE_MANAGER_H
+#define LLVM_TOOLS_LLVM_MCA_RESOURCE_MANAGER_H
 
-#include "HardwareUnit.h"
 #include "Instruction.h"
-#include "LSUnit.h"
 #include "llvm/ADT/ArrayRef.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/MC/MCSubtargetInfo.h"
-#include <map>
+#include "llvm/MC/MCSchedule.h"
 
 namespace mca {
 
@@ -356,192 +354,7 @@ public:
       Resource->dump();
   }
 #endif
-}; // namespace mca
-
-class SchedulerStrategy {
-public:
-  SchedulerStrategy() = default;
-  virtual ~SchedulerStrategy();
-
-  /// Returns true if Lhs should take priority over Rhs.
-  ///
-  /// This method is used by class Scheduler to select the "best" ready
-  /// instruction to issue to the underlying pipelines.
-  virtual bool compare(const InstRef &Lhs, const InstRef &Rhs) const = 0;
-};
-
-/// Default instruction selection strategy used by class Scheduler.
-class DefaultSchedulerStrategy : public SchedulerStrategy {
-  /// This method ranks instructions based on their age, and the number of known
-  /// users. The lower the rank value, the better.
-  int computeRank(const InstRef &Lhs) const {
-    return Lhs.getSourceIndex() - Lhs.getInstruction()->getNumUsers();
-  }
-
-public:
-  DefaultSchedulerStrategy() = default;
-  virtual ~DefaultSchedulerStrategy();
-
-  bool compare(const InstRef &Lhs, const InstRef &Rhs) const override {
-    int LhsRank = computeRank(Lhs);
-    int RhsRank = computeRank(Rhs);
-
-    /// Prioritize older instructions over younger instructions to minimize the
-    /// pressure on the reorder buffer.
-    if (LhsRank == RhsRank)
-      return Lhs.getSourceIndex() < Rhs.getSourceIndex();
-    return LhsRank < RhsRank;
-  }
-};
-
-/// Class Scheduler is responsible for issuing instructions to pipeline
-/// resources.
-///
-/// Internally, it delegates to a ResourceManager the management of processor
-/// resources. This class is also responsible for tracking the progress of
-/// instructions from the dispatch stage, until the write-back stage.
-///
-/// An instruction dispatched to the Scheduler is initially placed into either
-/// the 'WaitSet' or the 'ReadySet' depending on the availability of the input
-/// operands.
-///
-/// An instruction is moved from the WaitSet to the ReadySet when register
-/// operands become available, and all memory dependencies are met.
-/// Instructions that are moved from the WaitSet to the ReadySet transition
-/// in state from 'IS_AVAILABLE' to 'IS_READY'.
-///
-/// On every cycle, the Scheduler checks if it can promote instructions from the
-/// WaitSet to the ReadySet.
-///
-/// An Instruction is moved from the ReadySet the `IssuedSet` when it is issued
-/// to a (one or more) pipeline(s). This event also causes an instruction state
-/// transition (i.e. from state IS_READY, to state IS_EXECUTING). An Instruction
-/// leaves the IssuedSet when it reaches the write-back stage.
-class Scheduler : public HardwareUnit {
-  LSUnit *LSU;
-
-  // Instruction selection strategy for this Scheduler.
-  std::unique_ptr<SchedulerStrategy> Strategy;
-
-  // Hardware resources that are managed by this scheduler.
-  std::unique_ptr<ResourceManager> Resources;
-
-  std::vector<InstRef> WaitSet;
-  std::vector<InstRef> ReadySet;
-  std::vector<InstRef> IssuedSet;
-
-  /// Verify the given selection strategy and set the Strategy member
-  /// accordingly.  If no strategy is provided, the DefaultSchedulerStrategy is
-  /// used.
-  void initializeStrategy(std::unique_ptr<SchedulerStrategy> S);
-
-  /// Issue an instruction without updating the ready queue.
-  void issueInstructionImpl(
-      InstRef &IR,
-      llvm::SmallVectorImpl<std::pair<ResourceRef, double>> &Pipes);
-
-  // Identify instructions that have finished executing, and remove them from
-  // the IssuedSet. References to executed instructions are added to input
-  // vector 'Executed'.
-  void updateIssuedSet(llvm::SmallVectorImpl<InstRef> &Executed);
-
-  // Try to promote instructions from WaitSet to ReadySet.
-  // Add promoted instructions to the 'Ready' vector in input.
-  void promoteToReadySet(llvm::SmallVectorImpl<InstRef> &Ready);
-
-public:
-  Scheduler(const llvm::MCSchedModel &Model, LSUnit *Lsu)
-      : LSU(Lsu), Resources(llvm::make_unique<ResourceManager>(Model)) {
-    initializeStrategy(nullptr);
-  }
-  Scheduler(const llvm::MCSchedModel &Model, LSUnit *Lsu,
-            std::unique_ptr<SchedulerStrategy> SelectStrategy)
-      : LSU(Lsu), Resources(llvm::make_unique<ResourceManager>(Model)) {
-    initializeStrategy(std::move(SelectStrategy));
-  }
-  Scheduler(std::unique_ptr<ResourceManager> RM, LSUnit *Lsu,
-            std::unique_ptr<SchedulerStrategy> SelectStrategy)
-      : LSU(Lsu), Resources(std::move(RM)) {
-    initializeStrategy(std::move(SelectStrategy));
-  }
-
-  // Stalls generated by the scheduler.
-  enum Status {
-    SC_AVAILABLE,
-    SC_LOAD_QUEUE_FULL,
-    SC_STORE_QUEUE_FULL,
-    SC_BUFFERS_FULL,
-    SC_DISPATCH_GROUP_STALL,
-  };
-
-  /// Check if the instruction in 'IR' can be dispatched and returns an answer
-  /// in the form of a Status value.
-  ///
-  /// The DispatchStage is responsible for querying the Scheduler before
-  /// dispatching new instructions. This routine is used for performing such
-  /// a query.  If the instruction 'IR' can be dispatched, then true is
-  /// returned, otherwise false is returned with Event set to the stall type.
-  /// Internally, it also checks if the load/store unit is available.
-  Status isAvailable(const InstRef &IR) const;
-
-  /// Reserves buffer and LSUnit queue resources that are necessary to issue
-  /// this instruction.
-  ///
-  /// Returns true if instruction IR is ready to be issued to the underlying
-  /// pipelines. Note that this operation cannot fail; it assumes that a
-  /// previous call to method `isAvailable(IR)` returned `SC_AVAILABLE`.
-  void dispatch(const InstRef &IR);
-
-  /// Returns true if IR is ready to be executed by the underlying pipelines.
-  /// This method assumes that IR has been previously dispatched.
-  bool isReady(const InstRef &IR) const;
-
-  /// Issue an instruction and populates a vector of used pipeline resources,
-  /// and a vector of instructions that transitioned to the ready state as a
-  /// result of this event.
-  void
-  issueInstruction(InstRef &IR,
-                   llvm::SmallVectorImpl<std::pair<ResourceRef, double>> &Used,
-                   llvm::SmallVectorImpl<InstRef> &Ready);
-
-  /// Returns true if IR has to be issued immediately, or if IR is a zero
-  /// latency instruction.
-  bool mustIssueImmediately(const InstRef &IR) const;
-
-  /// This routine notifies the Scheduler that a new cycle just started.
-  ///
-  /// It notifies the underlying ResourceManager that a new cycle just started.
-  /// Vector `Freed` is populated with resourceRef related to resources that
-  /// have changed in state, and that are now available to new instructions.
-  /// Instructions executed are added to vector Executed, while vector Ready is
-  /// populated with instructions that have become ready in this new cycle.
-  void cycleEvent(llvm::SmallVectorImpl<ResourceRef> &Freed,
-                  llvm::SmallVectorImpl<InstRef> &Ready,
-                  llvm::SmallVectorImpl<InstRef> &Executed);
-
-  /// Convert a resource mask into a valid llvm processor resource identifier.
-  unsigned getResourceID(uint64_t Mask) const {
-    return Resources->resolveResourceMask(Mask);
-  }
-
-  /// Select the next instruction to issue from the ReadySet. Returns an invalid
-  /// instruction reference if there are no ready instructions, or if processor
-  /// resources are not available.
-  InstRef select();
-
-#ifndef NDEBUG
-  // Update the ready queues.
-  void dump() const;
-
-  // This routine performs a sanity check.  This routine should only be called
-  // when we know that 'IR' is not in the scheduler's instruction queues.
-  void sanityCheck(const InstRef &IR) const {
-    assert(llvm::find(WaitSet, IR) == WaitSet.end());
-    assert(llvm::find(ReadySet, IR) == ReadySet.end());
-    assert(llvm::find(IssuedSet, IR) == IssuedSet.end());
-  }
-#endif // !NDEBUG
 };
 } // namespace mca
 
-#endif // LLVM_TOOLS_LLVM_MCA_SCHEDULER_H
+#endif // LLVM_TOOLS_LLVM_MCA_RESOURCE_MANAGER_H

Modified: llvm/trunk/tools/llvm-mca/Scheduler.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/Scheduler.cpp?rev=340668&r1=340667&r2=340668&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/Scheduler.cpp (original)
+++ llvm/trunk/tools/llvm-mca/Scheduler.cpp Fri Aug 24 15:59:13 2018
@@ -12,7 +12,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "Scheduler.h"
-#include "Support.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/raw_ostream.h"
 
@@ -22,294 +21,11 @@ using namespace llvm;
 
 #define DEBUG_TYPE "llvm-mca"
 
-ResourceStrategy::~ResourceStrategy() = default;
-
 void Scheduler::initializeStrategy(std::unique_ptr<SchedulerStrategy> S) {
   // Ensure we have a valid (non-null) strategy object.
   Strategy = S ? std::move(S) : llvm::make_unique<DefaultSchedulerStrategy>();
 }
 
-void DefaultResourceStrategy::skipMask(uint64_t Mask) {
-  NextInSequenceMask &= (~Mask);
-  if (!NextInSequenceMask) {
-    NextInSequenceMask = ResourceUnitMask ^ RemovedFromNextInSequence;
-    RemovedFromNextInSequence = 0;
-  }
-}
-
-uint64_t DefaultResourceStrategy::select(uint64_t ReadyMask) {
-  // This method assumes that ReadyMask cannot be zero.
-  uint64_t CandidateMask = llvm::PowerOf2Floor(NextInSequenceMask);
-  while (!(ReadyMask & CandidateMask)) {
-    skipMask(CandidateMask);
-    CandidateMask = llvm::PowerOf2Floor(NextInSequenceMask);
-  }
-  return CandidateMask;
-}
-
-void DefaultResourceStrategy::used(uint64_t Mask) {
-  if (Mask > NextInSequenceMask) {
-    RemovedFromNextInSequence |= Mask;
-    return;
-  }
-  skipMask(Mask);
-}
-
-ResourceState::ResourceState(const llvm::MCProcResourceDesc &Desc,
-                             unsigned Index, uint64_t Mask)
-    : ProcResourceDescIndex(Index), ResourceMask(Mask),
-      BufferSize(Desc.BufferSize) {
-  if (llvm::countPopulation(ResourceMask) > 1)
-    ResourceSizeMask = ResourceMask ^ llvm::PowerOf2Floor(ResourceMask);
-  else
-    ResourceSizeMask = (1ULL << Desc.NumUnits) - 1;
-  ReadyMask = ResourceSizeMask;
-  AvailableSlots = BufferSize == -1 ? 0U : static_cast<unsigned>(BufferSize);
-  Unavailable = false;
-}
-
-bool ResourceState::isReady(unsigned NumUnits) const {
-  return (!isReserved() || isADispatchHazard()) &&
-         llvm::countPopulation(ReadyMask) >= NumUnits;
-}
-
-ResourceStateEvent ResourceState::isBufferAvailable() const {
-  if (isADispatchHazard() && isReserved())
-    return RS_RESERVED;
-  if (!isBuffered() || AvailableSlots)
-    return RS_BUFFER_AVAILABLE;
-  return RS_BUFFER_UNAVAILABLE;
-}
-
-#ifndef NDEBUG
-void ResourceState::dump() const {
-  dbgs() << "MASK: " << ResourceMask << ", SIZE_MASK: " << ResourceSizeMask
-         << ", RDYMASK: " << ReadyMask << ", BufferSize=" << BufferSize
-         << ", AvailableSlots=" << AvailableSlots
-         << ", Reserved=" << Unavailable << '\n';
-}
-#endif
-
-static unsigned getResourceStateIndex(uint64_t Mask) {
-  return std::numeric_limits<uint64_t>::digits - llvm::countLeadingZeros(Mask);
-}
-
-static std::unique_ptr<ResourceStrategy>
-getStrategyFor(const ResourceState &RS) {
-  if (RS.isAResourceGroup() || RS.getNumUnits() > 1)
-    return llvm::make_unique<DefaultResourceStrategy>(RS.getReadyMask());
-  return std::unique_ptr<ResourceStrategy>(nullptr);
-}
-
-ResourceManager::ResourceManager(const llvm::MCSchedModel &SM)
-    : ProcResID2Mask(SM.getNumProcResourceKinds()) {
-  computeProcResourceMasks(SM, ProcResID2Mask);
-  Resources.resize(SM.getNumProcResourceKinds());
-  Strategies.resize(SM.getNumProcResourceKinds());
-
-  for (unsigned I = 0, E = SM.getNumProcResourceKinds(); I < E; ++I) {
-    uint64_t Mask = ProcResID2Mask[I];
-    unsigned Index = getResourceStateIndex(Mask);
-    Resources[Index] =
-        llvm::make_unique<ResourceState>(*SM.getProcResource(I), I, Mask);
-    Strategies[Index] = getStrategyFor(*Resources[Index]);
-  }
-}
-
-void ResourceManager::setCustomStrategyImpl(std::unique_ptr<ResourceStrategy> S,
-                                            uint64_t ResourceMask) {
-  unsigned Index = getResourceStateIndex(ResourceMask);
-  assert(Index < Resources.size() && "Invalid processor resource index!");
-  assert(S && "Unexpected null strategy in input!");
-  Strategies[Index] = std::move(S);
-}
-
-unsigned ResourceManager::resolveResourceMask(uint64_t Mask) const {
-  return Resources[getResourceStateIndex(Mask)]->getProcResourceID();
-}
-
-unsigned ResourceManager::getNumUnits(uint64_t ResourceID) const {
-  return Resources[getResourceStateIndex(ResourceID)]->getNumUnits();
-}
-
-// Returns the actual resource consumed by this Use.
-// First, is the primary resource ID.
-// Second, is the specific sub-resource ID.
-ResourceRef ResourceManager::selectPipe(uint64_t ResourceID) {
-  unsigned Index = getResourceStateIndex(ResourceID);
-  ResourceState &RS = *Resources[Index];
-  assert(RS.isReady() && "No available units to select!");
-
-  // Special case where RS is not a group, and it only declares a single
-  // resource unit.
-  if (!RS.isAResourceGroup() && RS.getNumUnits() == 1)
-    return std::make_pair(ResourceID, RS.getReadyMask());
-
-  uint64_t SubResourceID = Strategies[Index]->select(RS.getReadyMask());
-  if (RS.isAResourceGroup())
-    return selectPipe(SubResourceID);
-  return std::make_pair(ResourceID, SubResourceID);
-}
-
-void ResourceManager::use(const ResourceRef &RR) {
-  // Mark the sub-resource referenced by RR as used.
-  ResourceState &RS = *Resources[getResourceStateIndex(RR.first)];
-  RS.markSubResourceAsUsed(RR.second);
-  // If there are still available units in RR.first,
-  // then we are done.
-  if (RS.isReady())
-    return;
-
-  // Notify to other resources that RR.first is no longer available.
-  for (std::unique_ptr<ResourceState> &Res : Resources) {
-    ResourceState &Current = *Res;
-    if (!Current.isAResourceGroup() || Current.getResourceMask() == RR.first)
-      continue;
-
-    if (Current.containsResource(RR.first)) {
-      unsigned Index = getResourceStateIndex(Current.getResourceMask());
-      Current.markSubResourceAsUsed(RR.first);
-      Strategies[Index]->used(RR.first);
-    }
-  }
-}
-
-void ResourceManager::release(const ResourceRef &RR) {
-  ResourceState &RS = *Resources[getResourceStateIndex(RR.first)];
-  bool WasFullyUsed = !RS.isReady();
-  RS.releaseSubResource(RR.second);
-  if (!WasFullyUsed)
-    return;
-
-  for (std::unique_ptr<ResourceState> &Res : Resources) {
-    ResourceState &Current = *Res;
-    if (!Current.isAResourceGroup() || Current.getResourceMask() == RR.first)
-      continue;
-
-    if (Current.containsResource(RR.first))
-      Current.releaseSubResource(RR.first);
-  }
-}
-
-ResourceStateEvent
-ResourceManager::canBeDispatched(ArrayRef<uint64_t> Buffers) const {
-  ResourceStateEvent Result = ResourceStateEvent::RS_BUFFER_AVAILABLE;
-  for (uint64_t Buffer : Buffers) {
-    ResourceState &RS = *Resources[getResourceStateIndex(Buffer)];
-    Result = RS.isBufferAvailable();
-    if (Result != ResourceStateEvent::RS_BUFFER_AVAILABLE)
-      break;
-  }
-  return Result;
-}
-
-void ResourceManager::reserveBuffers(ArrayRef<uint64_t> Buffers) {
-  for (const uint64_t Buffer : Buffers) {
-    ResourceState &RS = *Resources[getResourceStateIndex(Buffer)];
-    assert(RS.isBufferAvailable() == ResourceStateEvent::RS_BUFFER_AVAILABLE);
-    RS.reserveBuffer();
-
-    if (RS.isADispatchHazard()) {
-      assert(!RS.isReserved());
-      RS.setReserved();
-    }
-  }
-}
-
-void ResourceManager::releaseBuffers(ArrayRef<uint64_t> Buffers) {
-  for (const uint64_t R : Buffers)
-    Resources[getResourceStateIndex(R)]->releaseBuffer();
-}
-
-bool ResourceManager::canBeIssued(const InstrDesc &Desc) const {
-  return std::all_of(Desc.Resources.begin(), Desc.Resources.end(),
-                     [&](const std::pair<uint64_t, const ResourceUsage> &E) {
-                       unsigned NumUnits =
-                           E.second.isReserved() ? 0U : E.second.NumUnits;
-                       unsigned Index = getResourceStateIndex(E.first);
-                       return Resources[Index]->isReady(NumUnits);
-                     });
-}
-
-// Returns true if all resources are in-order, and there is at least one
-// resource which is a dispatch hazard (BufferSize = 0).
-bool ResourceManager::mustIssueImmediately(const InstrDesc &Desc) const {
-  if (!canBeIssued(Desc))
-    return false;
-  bool AllInOrderResources = all_of(Desc.Buffers, [&](uint64_t BufferMask) {
-    unsigned Index = getResourceStateIndex(BufferMask);
-    const ResourceState &Resource = *Resources[Index];
-    return Resource.isInOrder() || Resource.isADispatchHazard();
-  });
-  if (!AllInOrderResources)
-    return false;
-
-  return any_of(Desc.Buffers, [&](uint64_t BufferMask) {
-    return Resources[getResourceStateIndex(BufferMask)]->isADispatchHazard();
-  });
-}
-
-void ResourceManager::issueInstruction(
-    const InstrDesc &Desc,
-    SmallVectorImpl<std::pair<ResourceRef, double>> &Pipes) {
-  for (const std::pair<uint64_t, ResourceUsage> &R : Desc.Resources) {
-    const CycleSegment &CS = R.second.CS;
-    if (!CS.size()) {
-      releaseResource(R.first);
-      continue;
-    }
-
-    assert(CS.begin() == 0 && "Invalid {Start, End} cycles!");
-    if (!R.second.isReserved()) {
-      ResourceRef Pipe = selectPipe(R.first);
-      use(Pipe);
-      BusyResources[Pipe] += CS.size();
-      // Replace the resource mask with a valid processor resource index.
-      const ResourceState &RS = *Resources[getResourceStateIndex(Pipe.first)];
-      Pipe.first = RS.getProcResourceID();
-      Pipes.emplace_back(
-          std::pair<ResourceRef, double>(Pipe, static_cast<double>(CS.size())));
-    } else {
-      assert((countPopulation(R.first) > 1) && "Expected a group!");
-      // Mark this group as reserved.
-      assert(R.second.isReserved());
-      reserveResource(R.first);
-      BusyResources[ResourceRef(R.first, R.first)] += CS.size();
-    }
-  }
-}
-
-void ResourceManager::cycleEvent(SmallVectorImpl<ResourceRef> &ResourcesFreed) {
-  for (std::pair<ResourceRef, unsigned> &BR : BusyResources) {
-    if (BR.second)
-      BR.second--;
-    if (!BR.second) {
-      // Release this resource.
-      const ResourceRef &RR = BR.first;
-
-      if (countPopulation(RR.first) == 1)
-        release(RR);
-
-      releaseResource(RR.first);
-      ResourcesFreed.push_back(RR);
-    }
-  }
-
-  for (const ResourceRef &RF : ResourcesFreed)
-    BusyResources.erase(RF);
-}
-
-void ResourceManager::reserveResource(uint64_t ResourceID) {
-  ResourceState &Resource = *Resources[getResourceStateIndex(ResourceID)];
-  assert(!Resource.isReserved());
-  Resource.setReserved();
-}
-
-void ResourceManager::releaseResource(uint64_t ResourceID) {
-  ResourceState &Resource = *Resources[getResourceStateIndex(ResourceID)];
-  Resource.clearReserved();
-}
-
 // Anchor the vtable of SchedulerStrategy and DefaultSchedulerStrategy.
 SchedulerStrategy::~SchedulerStrategy() = default;
 DefaultSchedulerStrategy::~DefaultSchedulerStrategy() = default;

Modified: llvm/trunk/tools/llvm-mca/Scheduler.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-mca/Scheduler.h?rev=340668&r1=340667&r2=340668&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-mca/Scheduler.h (original)
+++ llvm/trunk/tools/llvm-mca/Scheduler.h Fri Aug 24 15:59:13 2018
@@ -16,348 +16,13 @@
 #define LLVM_TOOLS_LLVM_MCA_SCHEDULER_H
 
 #include "HardwareUnit.h"
-#include "Instruction.h"
 #include "LSUnit.h"
-#include "llvm/ADT/ArrayRef.h"
-#include "llvm/ADT/DenseMap.h"
+#include "ResourceManager.h"
 #include "llvm/ADT/SmallVector.h"
-#include "llvm/MC/MCSubtargetInfo.h"
-#include <map>
+#include "llvm/MC/MCSchedule.h"
 
 namespace mca {
 
-/// Used to notify the internal state of a processor resource.
-///
-/// A processor resource is available if it is not reserved, and there are
-/// available slots in the buffer.  A processor resource is unavailable if it
-/// is either reserved, or the associated buffer is full. A processor resource
-/// with a buffer size of -1 is always available if it is not reserved.
-///
-/// Values of type ResourceStateEvent are returned by method
-/// ResourceState::isBufferAvailable(), which is used to query the internal
-/// state of a resource.
-///
-/// The naming convention for resource state events is:
-///  * Event names start with prefix RS_
-///  * Prefix RS_ is followed by a string describing the actual resource state.
-enum ResourceStateEvent {
-  RS_BUFFER_AVAILABLE,
-  RS_BUFFER_UNAVAILABLE,
-  RS_RESERVED
-};
-
-/// Resource allocation strategy used by hardware scheduler resources.
-class ResourceStrategy {
-  ResourceStrategy(const ResourceStrategy &) = delete;
-  ResourceStrategy &operator=(const ResourceStrategy &) = delete;
-
-public:
-  ResourceStrategy() {}
-  virtual ~ResourceStrategy();
-
-  /// Selects a processor resource unit from a ReadyMask.
-  virtual uint64_t select(uint64_t ReadyMask) = 0;
-
-  /// Called by the ResourceManager when a processor resource group, or a
-  /// processor resource with multiple units has become unavailable.
-  ///
-  /// The default strategy uses this information to bias its selection logic.
-  virtual void used(uint64_t ResourceMask) {}
-};
-
-/// Default resource allocation strategy used by processor resource groups and
-/// processor resources with multiple units.
-class DefaultResourceStrategy final : public ResourceStrategy {
-  /// A Mask of resource unit identifiers.
-  ///
-  /// There is one bit set for every available resource unit.
-  /// It defaults to the value of field ResourceSizeMask in ResourceState.
-  const unsigned ResourceUnitMask;
-
-  /// A simple round-robin selector for processor resource units.
-  /// Each bit of this mask identifies a sub resource within a group.
-  ///
-  /// As an example, lets assume that this is a default policy for a
-  /// processor resource group composed by the following three units:
-  ///   ResourceA -- 0b001
-  ///   ResourceB -- 0b010
-  ///   ResourceC -- 0b100
-  ///
-  /// Field NextInSequenceMask is used to select the next unit from the set of
-  /// resource units. It defaults to the value of field `ResourceUnitMasks` (in
-  /// this example, it defaults to mask '0b111').
-  ///
-  /// The round-robin selector would firstly select 'ResourceC', then
-  /// 'ResourceB', and eventually 'ResourceA'.  When a resource R is used, the
-  /// corresponding bit in NextInSequenceMask is cleared.  For example, if
-  /// 'ResourceC' is selected, then the new value of NextInSequenceMask becomes
-  /// 0xb011.
-  ///
-  /// When NextInSequenceMask becomes zero, it is automatically reset to the
-  /// default value (i.e. ResourceUnitMask).
-  uint64_t NextInSequenceMask;
-
-  /// This field is used to track resource units that are used (i.e. selected)
-  /// by other groups other than the one associated with this strategy object.
-  ///
-  /// In LLVM processor resource groups are allowed to partially (or fully)
-  /// overlap. That means, a same unit may be visible to multiple groups.
-  /// This field keeps track of uses that have originated from outside of
-  /// this group. The idea is to bias the selection strategy, so that resources
-  /// that haven't been used by other groups get prioritized.
-  ///
-  /// The end goal is to (try to) keep the resource distribution as much uniform
-  /// as possible. By construction, this mask only tracks one-level of resource
-  /// usage. Therefore, this strategy is expected to be less accurate when same
-  /// units are used multiple times by other groups within a single round of
-  /// select.
-  ///
-  /// Note: an LRU selector would have a better accuracy at the cost of being
-  /// slightly more expensive (mostly in terms of runtime cost). Methods
-  /// 'select' and 'used', are always in the hot execution path of llvm-mca.
-  /// Therefore, a slow implementation of 'select' would have a negative impact
-  /// on the overall performance of the tool.
-  uint64_t RemovedFromNextInSequence;
-
-  void skipMask(uint64_t Mask);
-
-public:
-  DefaultResourceStrategy(uint64_t UnitMask)
-      : ResourceStrategy(), ResourceUnitMask(UnitMask),
-        NextInSequenceMask(UnitMask), RemovedFromNextInSequence(0) {}
-  virtual ~DefaultResourceStrategy() = default;
-
-  uint64_t select(uint64_t ReadyMask) override;
-  void used(uint64_t Mask) override;
-};
-
-/// A processor resource descriptor.
-///
-/// There is an instance of this class for every processor resource defined by
-/// the machine scheduling model.
-/// Objects of class ResourceState dynamically track the usage of processor
-/// resource units.
-class ResourceState {
-  /// An index to the MCProcResourceDesc entry in the processor model.
-  const unsigned ProcResourceDescIndex;
-  /// A resource mask. This is generated by the tool with the help of
-  /// function `mca::createProcResourceMasks' (see Support.h).
-  const uint64_t ResourceMask;
-
-  /// A ProcResource can have multiple units.
-  ///
-  /// For processor resource groups,
-  /// this field default to the value of field `ResourceMask`; the number of
-  /// bits set is equal to the cardinality of the group.  For normal (i.e.
-  /// non-group) resources, the number of bits set in this mask is equivalent
-  /// to the number of units declared by the processor model (see field
-  /// 'NumUnits' in 'ProcResourceUnits').
-  uint64_t ResourceSizeMask;
-
-  /// A mask of ready units.
-  uint64_t ReadyMask;
-
-  /// Buffered resources will have this field set to a positive number different
-  /// than zero. A buffered resource behaves like a reservation station
-  /// implementing its own buffer for out-of-order execution.
-  ///
-  /// A BufferSize of 1 is used by scheduler resources that force in-order
-  /// execution.
-  ///
-  /// A BufferSize of 0 is used to model in-order issue/dispatch resources.
-  /// Since in-order issue/dispatch resources don't implement buffers, dispatch
-  /// events coincide with issue events.
-  /// Also, no other instruction ca be dispatched/issue while this resource is
-  /// in use. Only when all the "resource cycles" are consumed (after the issue
-  /// event), a new instruction ca be dispatched.
-  const int BufferSize;
-
-  /// Available slots in the buffer (zero, if this is not a buffered resource).
-  unsigned AvailableSlots;
-
-  /// This field is set if this resource is currently reserved.
-  ///
-  /// Resources can be reserved for a number of cycles.
-  /// Instructions can still be dispatched to reserved resources. However,
-  /// istructions dispatched to a reserved resource cannot be issued to the
-  /// underlying units (i.e. pipelines) until the resource is released.
-  bool Unavailable;
-
-  /// Checks for the availability of unit 'SubResMask' in the group.
-  bool isSubResourceReady(uint64_t SubResMask) const {
-    return ReadyMask & SubResMask;
-  }
-
-public:
-  ResourceState(const llvm::MCProcResourceDesc &Desc, unsigned Index,
-                uint64_t Mask);
-
-  unsigned getProcResourceID() const { return ProcResourceDescIndex; }
-  uint64_t getResourceMask() const { return ResourceMask; }
-  uint64_t getReadyMask() const { return ReadyMask; }
-  int getBufferSize() const { return BufferSize; }
-
-  bool isBuffered() const { return BufferSize > 0; }
-  bool isInOrder() const { return BufferSize == 1; }
-
-  /// Returns true if this is an in-order dispatch/issue resource.
-  bool isADispatchHazard() const { return BufferSize == 0; }
-  bool isReserved() const { return Unavailable; }
-
-  void setReserved() { Unavailable = true; }
-  void clearReserved() { Unavailable = false; }
-
-  /// Returs true if this resource is not reserved, and if there are at least
-  /// `NumUnits` available units.
-  bool isReady(unsigned NumUnits = 1) const;
-
-  bool isAResourceGroup() const {
-    return llvm::countPopulation(ResourceMask) > 1;
-  }
-
-  bool containsResource(uint64_t ID) const { return ResourceMask & ID; }
-
-  void markSubResourceAsUsed(uint64_t ID) {
-    assert(isSubResourceReady(ID));
-    ReadyMask ^= ID;
-  }
-
-  void releaseSubResource(uint64_t ID) {
-    assert(!isSubResourceReady(ID));
-    ReadyMask ^= ID;
-  }
-
-  unsigned getNumUnits() const {
-    return isAResourceGroup() ? 1U : llvm::countPopulation(ResourceSizeMask);
-  }
-
-  /// Checks if there is an available slot in the resource buffer.
-  ///
-  /// Returns RS_BUFFER_AVAILABLE if this is not a buffered resource, or if
-  /// there is a slot available.
-  ///
-  /// Returns RS_RESERVED if this buffered resource is a dispatch hazard, and it
-  /// is reserved.
-  ///
-  /// Returns RS_BUFFER_UNAVAILABLE if there are no available slots.
-  ResourceStateEvent isBufferAvailable() const;
-
-  /// Reserve a slot in the buffer.
-  void reserveBuffer() {
-    if (AvailableSlots)
-      AvailableSlots--;
-  }
-
-  /// Release a slot in the buffer.
-  void releaseBuffer() {
-    if (BufferSize > 0)
-      AvailableSlots++;
-    assert(AvailableSlots <= static_cast<unsigned>(BufferSize));
-  }
-
-#ifndef NDEBUG
-  void dump() const;
-#endif
-};
-
-/// A resource unit identifier.
-///
-/// This is used to identify a specific processor resource unit using a pair
-/// of indices where the 'first' index is a processor resource mask, and the
-/// 'second' index is an index for a "sub-resource" (i.e. unit).
-typedef std::pair<uint64_t, uint64_t> ResourceRef;
-
-// First: a MCProcResourceDesc index identifying a buffered resource.
-// Second: max number of buffer entries used in this resource.
-typedef std::pair<unsigned, unsigned> BufferUsageEntry;
-
-/// A resource manager for processor resource units and groups.
-///
-/// This class owns all the ResourceState objects, and it is responsible for
-/// acting on requests from a Scheduler by updating the internal state of
-/// ResourceState objects.
-/// This class doesn't know about instruction itineraries and functional units.
-/// In future, it can be extended to support itineraries too through the same
-/// public interface.
-class ResourceManager {
-  // The resource manager owns all the ResourceState.
-  std::vector<std::unique_ptr<ResourceState>> Resources;
-  std::vector<std::unique_ptr<ResourceStrategy>> Strategies;
-
-  // Keeps track of which resources are busy, and how many cycles are left
-  // before those become usable again.
-  llvm::SmallDenseMap<ResourceRef, unsigned> BusyResources;
-
-  // A table to map processor resource IDs to processor resource masks.
-  llvm::SmallVector<uint64_t, 8> ProcResID2Mask;
-
-  // Returns the actual resource unit that will be used.
-  ResourceRef selectPipe(uint64_t ResourceID);
-
-  void use(const ResourceRef &RR);
-  void release(const ResourceRef &RR);
-
-  unsigned getNumUnits(uint64_t ResourceID) const;
-
-  // Overrides the selection strategy for the processor resource with the given
-  // mask.
-  void setCustomStrategyImpl(std::unique_ptr<ResourceStrategy> S,
-                             uint64_t ResourceMask);
-
-public:
-  ResourceManager(const llvm::MCSchedModel &SM);
-  virtual ~ResourceManager() = default;
-
-  // Overrides the selection strategy for the resource at index ResourceID in
-  // the MCProcResourceDesc table.
-  void setCustomStrategy(std::unique_ptr<ResourceStrategy> S,
-                         unsigned ResourceID) {
-    assert(ResourceID < ProcResID2Mask.size() &&
-           "Invalid resource index in input!");
-    return setCustomStrategyImpl(std::move(S), ProcResID2Mask[ResourceID]);
-  }
-
-  // Returns RS_BUFFER_AVAILABLE if buffered resources are not reserved, and if
-  // there are enough available slots in the buffers.
-  ResourceStateEvent canBeDispatched(llvm::ArrayRef<uint64_t> Buffers) const;
-
-  // Return the processor resource identifier associated to this Mask.
-  unsigned resolveResourceMask(uint64_t Mask) const;
-
-  // Consume a slot in every buffered resource from array 'Buffers'. Resource
-  // units that are dispatch hazards (i.e. BufferSize=0) are marked as reserved.
-  void reserveBuffers(llvm::ArrayRef<uint64_t> Buffers);
-
-  // Release buffer entries previously allocated by method reserveBuffers.
-  void releaseBuffers(llvm::ArrayRef<uint64_t> Buffers);
-
-  // Reserve a processor resource. A reserved resource is not available for
-  // instruction issue until it is released.
-  void reserveResource(uint64_t ResourceID);
-
-  // Release a previously reserved processor resource.
-  void releaseResource(uint64_t ResourceID);
-
-  // Returns true if all resources are in-order, and there is at least one
-  // resource which is a dispatch hazard (BufferSize = 0).
-  bool mustIssueImmediately(const InstrDesc &Desc) const;
-
-  bool canBeIssued(const InstrDesc &Desc) const;
-
-  void issueInstruction(
-      const InstrDesc &Desc,
-      llvm::SmallVectorImpl<std::pair<ResourceRef, double>> &Pipes);
-
-  void cycleEvent(llvm::SmallVectorImpl<ResourceRef> &ResourcesFreed);
-
-#ifndef NDEBUG
-  void dump() const {
-    for (const std::unique_ptr<ResourceState> &Resource : Resources)
-      Resource->dump();
-  }
-#endif
-}; // namespace mca
-
 class SchedulerStrategy {
 public:
   SchedulerStrategy() = default;




More information about the llvm-commits mailing list