88 lines · c
1//===--------------------- DispatchStatistics.h -----------------*- C++ -*-===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8/// \file9///10/// This file implements a view that prints a few statistics related to the11/// dispatch logic. It collects and analyzes instruction dispatch events as12/// well as static/dynamic dispatch stall events.13///14/// Example:15/// ========16///17/// Dynamic Dispatch Stall Cycles:18/// RAT - Register unavailable: 019/// RCU - Retire tokens unavailable: 020/// SCHEDQ - Scheduler full: 4221/// LQ - Load queue full: 022/// SQ - Store queue full: 023/// GROUP - Static restrictions on the dispatch group: 024///25///26/// Dispatch Logic - number of cycles where we saw N micro opcodes dispatched:27/// [# dispatched], [# cycles]28/// 0, 15 (11.5%)29/// 2, 4 (3.1%)30///31//===----------------------------------------------------------------------===//32 33#ifndef LLVM_TOOLS_LLVM_MCA_DISPATCHVIEW_H34#define LLVM_TOOLS_LLVM_MCA_DISPATCHVIEW_H35 36#include "llvm/ADT/SmallVector.h"37#include "llvm/MC/MCSubtargetInfo.h"38#include "llvm/MCA/View.h"39#include <map>40 41namespace llvm {42namespace mca {43 44class DispatchStatistics : public View {45 unsigned NumDispatched;46 unsigned NumCycles;47 48 // Counts dispatch stall events caused by unavailability of resources. There49 // is one counter for every generic stall kind (see class HWStallEvent).50 llvm::SmallVector<unsigned, 8> HWStalls;51 52 using Histogram = std::map<unsigned, unsigned>;53 Histogram DispatchGroupSizePerCycle;54 55 void updateHistograms() {56 DispatchGroupSizePerCycle[NumDispatched]++;57 NumDispatched = 0;58 }59 60 void printDispatchHistogram(llvm::raw_ostream &OS) const;61 62 void printDispatchStalls(llvm::raw_ostream &OS) const;63 64public:65 DispatchStatistics()66 : NumDispatched(0), NumCycles(0),67 HWStalls(HWStallEvent::LastGenericEvent) {}68 69 void onEvent(const HWStallEvent &Event) override;70 71 void onEvent(const HWInstructionEvent &Event) override;72 73 void onCycleBegin() override { NumCycles++; }74 75 void onCycleEnd() override { updateHistograms(); }76 77 void printView(llvm::raw_ostream &OS) const override {78 printDispatchStalls(OS);79 printDispatchHistogram(OS);80 }81 StringRef getNameAsString() const override { return "DispatchStatistics"; }82 json::Value toJSON() const override;83};84} // namespace mca85} // namespace llvm86 87#endif88