-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[llvm-exegesis] Add tablegen support for validation counters #76652
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[llvm-exegesis] Add tablegen support for validation counters #76652
Conversation
This method was simply a wrapper around readOrError. All users within the llvm-exegesis code base should have been processing an actual error rather than using the wrapper. This patch removes the wrapper and rewrites the users (just 1) to use the readOrError method.
@llvm/pr-subscribers-tools-llvm-exegesis @llvm/pr-subscribers-backend-x86 Author: Aiden Grossman (boomanaiden154) ChangesThis patch adds support in the llvm-exegesis tablegen emitter for validation counters. Full support for validation counters in llvm-exegesis is added in a future patch. Full diff: https://github.com/llvm/llvm-project/pull/76652.diff 5 Files Affected:
diff --git a/llvm/include/llvm/Target/TargetPfmCounters.td b/llvm/include/llvm/Target/TargetPfmCounters.td
index b00f3e19c35f90..72f6b39f4878f4 100644
--- a/llvm/include/llvm/Target/TargetPfmCounters.td
+++ b/llvm/include/llvm/Target/TargetPfmCounters.td
@@ -28,6 +28,22 @@ class PfmIssueCounter<string resource_name, string counter>
string ResourceName = resource_name;
}
+class ValidationEvent <int event_number> {
+ int EventNumber = event_number;
+}
+
+def L1DCacheLoadMiss : ValidationEvent<0>;
+def InstructionRetired : ValidationEvent<1>;
+def DataTLBLoadMiss : ValidationEvent<2>;
+def DataTLBStoreMiss : ValidationEvent<3>;
+
+// Validation counters can be tied to a specific event
+class PfmValidationCounter<ValidationEvent event_type, string counter>
+ : PfmCounter<counter> {
+ // The name of the event that the validation counter detects.
+ ValidationEvent EventType = event_type;
+}
+
def NoPfmCounter : PfmCounter <""> {}
// Set of PfmCounters for measuring sched model characteristics.
@@ -38,6 +54,9 @@ class ProcPfmCounters {
PfmCounter UopsCounter = NoPfmCounter;
// Processors can define how to measure issued uops by defining IssueCounters.
list<PfmIssueCounter> IssueCounters = [];
+ // Processor can list mappings between validation events and real counters
+ // to measure the specified events.
+ list<PfmValidationCounter> ValidationCounters = [];
}
// A binding of a set of counters to a CPU.
diff --git a/llvm/lib/Target/X86/X86PfmCounters.td b/llvm/lib/Target/X86/X86PfmCounters.td
index 49ef6efc6aecf2..99cac504f157d3 100644
--- a/llvm/lib/Target/X86/X86PfmCounters.td
+++ b/llvm/lib/Target/X86/X86PfmCounters.td
@@ -275,6 +275,9 @@ def ZnVer2PfmCounters : ProcPfmCounters {
PfmIssueCounter<"Zn2AGU", "ls_dispatch:ld_st_dispatch + ls_dispatch:ld_dispatch + ls_dispatch:store_dispatch">,
PfmIssueCounter<"Zn2Divider", "div_op_count">
];
+ let ValidationCounters = [
+ PfmValidationCounter<InstructionRetired, "RETIRED_INSTRUCTIONS">
+ ];
}
def : PfmCountersBinding<"znver2", ZnVer2PfmCounters>;
@@ -288,6 +291,9 @@ def ZnVer3PfmCounters : ProcPfmCounters {
PfmIssueCounter<"Zn3Store", "ls_dispatch:store_dispatch">,
PfmIssueCounter<"Zn3Divider", "div_op_count">
];
+ let ValidationCounters = [
+ PfmValidationCounter<InstructionRetired, "RETIRED_INSTRUCTIONS">
+ ];
}
def : PfmCountersBinding<"znver3", ZnVer3PfmCounters>;
diff --git a/llvm/tools/llvm-exegesis/lib/Target.cpp b/llvm/tools/llvm-exegesis/lib/Target.cpp
index 23c80e5b98953a..20b4afb9b8f676 100644
--- a/llvm/tools/llvm-exegesis/lib/Target.cpp
+++ b/llvm/tools/llvm-exegesis/lib/Target.cpp
@@ -147,13 +147,14 @@ std::unique_ptr<BenchmarkRunner> ExegesisTarget::createUopsBenchmarkRunner(
ExecutionMode);
}
-static_assert(std::is_trivial_v<PfmCountersInfo>,
- "We shouldn't have dynamic initialization here");
-const PfmCountersInfo PfmCountersInfo::Default = {nullptr, nullptr, nullptr,
- 0u};
+const PfmCountersInfo PfmCountersInfo::Default = {
+ nullptr, nullptr, nullptr, 0u, {}};
const PfmCountersInfo PfmCountersInfo::Dummy = {
- pfm::PerfEvent::DummyEventString, pfm::PerfEvent::DummyEventString, nullptr,
- 0u};
+ pfm::PerfEvent::DummyEventString,
+ pfm::PerfEvent::DummyEventString,
+ nullptr,
+ 0u,
+ {}};
const PfmCountersInfo &ExegesisTarget::getPfmCounters(StringRef CpuName) const {
assert(llvm::is_sorted(
diff --git a/llvm/tools/llvm-exegesis/lib/Target.h b/llvm/tools/llvm-exegesis/lib/Target.h
index c37dd8b7082162..3956bc983181f6 100644
--- a/llvm/tools/llvm-exegesis/lib/Target.h
+++ b/llvm/tools/llvm-exegesis/lib/Target.h
@@ -32,6 +32,8 @@
#include "llvm/TargetParser/SubtargetFeature.h"
#include "llvm/TargetParser/Triple.h"
+#include <unordered_map>
+
namespace llvm {
namespace exegesis {
@@ -39,6 +41,13 @@ extern cl::OptionCategory Options;
extern cl::OptionCategory BenchmarkOptions;
extern cl::OptionCategory AnalysisOptions;
+enum ValidationEvent {
+ L1DCacheLoadMiss,
+ InstructionRetired,
+ DataTLBLoadMiss,
+ DataTLBStoreMiss
+};
+
struct PfmCountersInfo {
// An optional name of a performance counter that can be used to measure
// cycles.
@@ -59,6 +68,8 @@ struct PfmCountersInfo {
const IssueCounter *IssueCounters;
unsigned NumIssueCounters;
+ std::unordered_map<ValidationEvent, const char *> ValidationCounters;
+
static const PfmCountersInfo Default;
static const PfmCountersInfo Dummy;
};
diff --git a/llvm/utils/TableGen/ExegesisEmitter.cpp b/llvm/utils/TableGen/ExegesisEmitter.cpp
index 736f1220be14dd..247ed83f25ea64 100644
--- a/llvm/utils/TableGen/ExegesisEmitter.cpp
+++ b/llvm/utils/TableGen/ExegesisEmitter.cpp
@@ -22,6 +22,8 @@
#include <string>
#include <vector>
+#include <iostream>
+
using namespace llvm;
#define DEBUG_TYPE "exegesis-emitter"
@@ -81,6 +83,11 @@ collectPfmCounters(const RecordKeeper &Records) {
"duplicate ResourceName " + ResourceName);
AddPfmCounterName(IssueCounter);
}
+
+ for (const Record *ValidationCounter :
+ Def->getValueAsListOfDefs("ValidationCounters"))
+ AddPfmCounterName(ValidationCounter);
+
AddPfmCounterName(Def->getValueAsDef("CycleCounter"));
AddPfmCounterName(Def->getValueAsDef("UopsCounter"));
}
@@ -109,6 +116,8 @@ void ExegesisEmitter::emitPfmCountersInfo(const Record &Def,
Def.getValueAsDef("UopsCounter")->getValueAsString("Counter");
const size_t NumIssueCounters =
Def.getValueAsListOfDefs("IssueCounters").size();
+ const size_t NumValidationCounters =
+ Def.getValueAsListOfDefs("ValidationCounters").size();
OS << "\nstatic const PfmCountersInfo " << Target << Def.getName()
<< " = {\n";
@@ -129,10 +138,25 @@ void ExegesisEmitter::emitPfmCountersInfo(const Record &Def,
// Issue Counters
if (NumIssueCounters == 0)
- OS << " nullptr, // No issue counters.\n 0\n";
+ OS << " nullptr, 0, // No issue counters\n";
else
OS << " " << Target << "PfmIssueCounters + " << IssueCountersTableOffset
- << ", " << NumIssueCounters << " // Issue counters.\n";
+ << ", " << NumIssueCounters << ", // Issue counters.\n";
+
+ // Validation Counters
+ if (NumValidationCounters == 0)
+ OS << " {} // No validation counters.\n";
+ else {
+ OS << " {\n";
+ for (const Record *ValidationCounter :
+ Def.getValueAsListOfDefs("ValidationCounters")) {
+ OS << " { " << ValidationCounter->getValueAsDef("EventType")->getName()
+ << ", " << Target << "PfmCounterNames["
+ << getPfmCounterId(ValidationCounter->getValueAsString("Counter"))
+ << "]}\n";
+ }
+ OS << " } // Validation counters.\n";
+ }
OS << "};\n";
IssueCountersTableOffset += NumIssueCounters;
|
@legrosbuffle When you get a chance, are you able to take another look at this along with the other patches in the stack?
I also have a couple other patches that would be nice to land soon. It would be great if you could take a look at them also: |
While landing llvm#76652, I realized I messed up a rebase/merge at some point and some of the changes I intended to land with llvm#76652 ended up in a different PR (llvm#76653) instead. This patch fixes the validation counters to how they were intended to land in llvm#76652.
This patch adds support in the llvm-exegesis tablegen emitter for validation counters. Full support for validation counters in llvm-exegesis is added in a future patch.