Path: blob/main/contrib/llvm-project/llvm/tools/llvm-mca/Views/SchedulerStatistics.h
35290 views
//===--------------------- SchedulerStatistics.h ----------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7/// \file8///9/// This file defines class SchedulerStatistics. Class SchedulerStatistics is a10/// View that listens to instruction issue events in order to print general11/// statistics related to the hardware schedulers.12///13/// Example:14/// ========15///16/// Schedulers - number of cycles where we saw N instructions issued:17/// [# issued], [# cycles]18/// 0, 6 (2.9%)19/// 1, 106 (50.7%)20/// 2, 97 (46.4%)21///22/// Scheduler's queue usage:23/// [1] Resource name.24/// [2] Average number of used buffer entries.25/// [3] Maximum number of used buffer entries.26/// [4] Total number of buffer entries.27///28/// [1] [2] [3] [4]29/// JALU01 0 0 2030/// JFPU01 15 18 1831/// JLSAGU 0 0 1232//33//===----------------------------------------------------------------------===//3435#ifndef LLVM_TOOLS_LLVM_MCA_SCHEDULERSTATISTICS_H36#define LLVM_TOOLS_LLVM_MCA_SCHEDULERSTATISTICS_H3738#include "llvm/ADT/SmallVector.h"39#include "llvm/MC/MCSubtargetInfo.h"40#include "llvm/MCA/View.h"41#include <map>4243namespace llvm {44namespace mca {4546class SchedulerStatistics final : public View {47const llvm::MCSchedModel &SM;48unsigned LQResourceID;49unsigned SQResourceID;5051unsigned NumIssued;52unsigned NumCycles;5354unsigned MostRecentLoadDispatched;55unsigned MostRecentStoreDispatched;5657// Tracks the usage of a scheduler's queue.58struct BufferUsage {59unsigned SlotsInUse;60unsigned MaxUsedSlots;61uint64_t CumulativeNumUsedSlots;62};6364using Histogram = std::map<unsigned, unsigned>;65Histogram IssueWidthPerCycle;6667std::vector<BufferUsage> Usage;6869void updateHistograms();70void printSchedulerStats(llvm::raw_ostream &OS) const;71void printSchedulerUsage(llvm::raw_ostream &OS) const;7273public:74SchedulerStatistics(const llvm::MCSubtargetInfo &STI);75void onEvent(const HWInstructionEvent &Event) override;76void onCycleBegin() override { NumCycles++; }77void onCycleEnd() override { updateHistograms(); }7879// Increases the number of used scheduler queue slots of every buffered80// resource in the Buffers set.81void onReservedBuffers(const InstRef &IR,82llvm::ArrayRef<unsigned> Buffers) override;8384// Decreases by one the number of used scheduler queue slots of every85// buffered resource in the Buffers set.86void onReleasedBuffers(const InstRef &IR,87llvm::ArrayRef<unsigned> Buffers) override;8889void printView(llvm::raw_ostream &OS) const override;90StringRef getNameAsString() const override { return "SchedulerStatistics"; }91bool isSerializable() const override { return false; }92};93} // namespace mca94} // namespace llvm9596#endif979899