1//===- TargetPfmCounters.td - Target Pfm Counters -*- tablegen ----------*-===//
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-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the target-independent interfaces for performance counters.
10//
11//===----------------------------------------------------------------------===//
12
13// Definition of a hardware counters from libpfm identifiers.
14class PfmCounter<string counter> {
15  // The name of the counter that measures events.
16  // The name can be "some_counter + some_other_counter", in which case the
17  // measured value is the sum of events on these counters.
18  string Counter = counter;
19}
20
21// Issue counters can be tied to a ProcResource
22class PfmIssueCounter<string resource_name, string counter>
23    : PfmCounter<counter> {
24  // The name of the ProcResource on which uops are issued. This is used by
25  // llvm-exegesis to compare measurements with values in the SchedModels.
26  // If the CPU has a sched model, this should correspond to the name of a
27  // ProcResource.
28  string ResourceName = resource_name;
29}
30
31// Definition of a validation event. A validation event represents a specific
32// event that can be measured using performance counters that is interesting
33// in regard to the snippet state.
34class ValidationEvent <int event_number> {
35  int EventNumber = event_number;
36}
37
38// TableGen names for events defined in `llvm::exegesis::ValidationEvent`.
39def InstructionRetired  : ValidationEvent<0>;
40def L1DCacheLoadMiss : ValidationEvent<1>;
41def L1DCacheStoreMiss : ValidationEvent<2>;
42def L1ICacheLoadMiss : ValidationEvent<3>;
43def DataTLBLoadMiss : ValidationEvent<4>;
44def DataTLBStoreMiss : ValidationEvent<5>;
45def InstructionTLBLoadMiss : ValidationEvent<6>;
46def BranchPredictionMiss : ValidationEvent<7>;
47
48
49// PfmValidationCounter provides a mapping between the events that are
50// are interesting in regards to the snippet execution environment and
51// a concrete performance counter name that can be looked up in libpfm.
52class PfmValidationCounter<ValidationEvent event_type, string counter>
53    : PfmCounter<counter> {
54  // The name of the event that the validation counter detects.
55  ValidationEvent EventType = event_type;
56}
57
58def NoPfmCounter : PfmCounter <""> {}
59
60// Set of PfmCounters for measuring sched model characteristics.
61class ProcPfmCounters {
62  // Processors can define how to measure cycles by defining a CycleCounter.
63  PfmCounter CycleCounter = NoPfmCounter;
64  // Processors can define how to measure uops by defining a UopsCounter.
65  PfmCounter UopsCounter = NoPfmCounter;
66  // Processors can define how to measure issued uops by defining IssueCounters.
67  list<PfmIssueCounter> IssueCounters = [];
68  // Processor can list mappings between validation events and real counters
69  // to measure the specified events.
70  list<PfmValidationCounter> ValidationCounters = [];
71}
72
73// A binding of a set of counters to a CPU.
74class PfmCountersBinding<string cpu_name, ProcPfmCounters counters> {
75  string CpuName = cpu_name;
76  ProcPfmCounters Counters = counters;
77}
78
79// Declares the default binding for unbound CPUs for the target.
80class PfmCountersDefaultBinding<ProcPfmCounters counters>
81    : PfmCountersBinding<"", counters> {}
82