Path: blob/main/contrib/llvm-project/llvm/tools/llvm-mca/Views/DispatchStatistics.h
35290 views
//===--------------------- DispatchStatistics.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 implements a view that prints a few statistics related to the10/// dispatch logic. It collects and analyzes instruction dispatch events as11/// well as static/dynamic dispatch stall events.12///13/// Example:14/// ========15///16/// Dynamic Dispatch Stall Cycles:17/// RAT - Register unavailable: 018/// RCU - Retire tokens unavailable: 019/// SCHEDQ - Scheduler full: 4220/// LQ - Load queue full: 021/// SQ - Store queue full: 022/// GROUP - Static restrictions on the dispatch group: 023///24///25/// Dispatch Logic - number of cycles where we saw N micro opcodes dispatched:26/// [# dispatched], [# cycles]27/// 0, 15 (11.5%)28/// 2, 4 (3.1%)29///30//===----------------------------------------------------------------------===//3132#ifndef LLVM_TOOLS_LLVM_MCA_DISPATCHVIEW_H33#define LLVM_TOOLS_LLVM_MCA_DISPATCHVIEW_H3435#include "llvm/ADT/SmallVector.h"36#include "llvm/MC/MCSubtargetInfo.h"37#include "llvm/MCA/View.h"38#include <map>3940namespace llvm {41namespace mca {4243class DispatchStatistics : public View {44unsigned NumDispatched;45unsigned NumCycles;4647// Counts dispatch stall events caused by unavailability of resources. There48// is one counter for every generic stall kind (see class HWStallEvent).49llvm::SmallVector<unsigned, 8> HWStalls;5051using Histogram = std::map<unsigned, unsigned>;52Histogram DispatchGroupSizePerCycle;5354void updateHistograms() {55DispatchGroupSizePerCycle[NumDispatched]++;56NumDispatched = 0;57}5859void printDispatchHistogram(llvm::raw_ostream &OS) const;6061void printDispatchStalls(llvm::raw_ostream &OS) const;6263public:64DispatchStatistics()65: NumDispatched(0), NumCycles(0),66HWStalls(HWStallEvent::LastGenericEvent) {}6768void onEvent(const HWStallEvent &Event) override;6970void onEvent(const HWInstructionEvent &Event) override;7172void onCycleBegin() override { NumCycles++; }7374void onCycleEnd() override { updateHistograms(); }7576void printView(llvm::raw_ostream &OS) const override {77printDispatchStalls(OS);78printDispatchHistogram(OS);79}80StringRef getNameAsString() const override { return "DispatchStatistics"; }81json::Value toJSON() const override;82};83} // namespace mca84} // namespace llvm8586#endif878889