[llvm-exegesis] Fix PfmIssueCountersTable creation

This patch ensures that the pfm issue counter tables are the correct size, accounting for the invalid resource entry at the beginning of the resource tables.

It also fixes an issue with pfm failing to match event counters due to a trailing comma added to all the event names.

I've also added a counter comment to each entry as it helps locate problems with the tables.

Note: I don't have access to a SandyBridge test machine, which is the only model to make use of multiple event counters being mapped to a single resource. I don't know if pfm accepts a comma-seperated list or not, but that is what it was doing.

Differential Revision: https://reviews.llvm.org/D45787

llvm-svn: 330317
This commit is contained in:
Simon Pilgrim 2018-04-19 10:59:49 +00:00
parent a58926d51c
commit 0cb5a3029f

View File

@ -686,9 +686,11 @@ SubtargetEmitter::EmitRegisterFileTables(const CodeGenProcModel &ProcModel,
return CostTblIndex;
}
static bool EmitPfmIssueCountersTable(const CodeGenProcModel &ProcModel,
raw_ostream &OS) {
std::vector<const Record *> CounterDefs(ProcModel.ProcResourceDefs.size());
unsigned NumCounterDefs = 1 + ProcModel.ProcResourceDefs.size();
std::vector<const Record *> CounterDefs(NumCounterDefs);
bool HasCounters = false;
for (const Record *CounterDef : ProcModel.PfmIssueCounterDefs) {
const Record *&CD = CounterDefs[ProcModel.getProcResourceIdx(
@ -706,16 +708,19 @@ static bool EmitPfmIssueCountersTable(const CodeGenProcModel &ProcModel,
}
OS << "\nstatic const char* " << ProcModel.ModelName
<< "PfmIssueCounters[] = {\n";
for (const Record *CounterDef : CounterDefs) {
for (unsigned i = 0; i != NumCounterDefs; ++i) {
const Record *CounterDef = CounterDefs[i];
if (CounterDef) {
const auto PfmCounters = CounterDef->getValueAsListOfStrings("Counters");
if (PfmCounters.empty())
PrintFatalError(CounterDef->getLoc(), "empty counter list");
for (const StringRef CounterName : PfmCounters)
OS << " \"" << CounterName << ",\"";
OS << ", //" << CounterDef->getValueAsDef("Resource")->getName() << "\n";
OS << " \"" << PfmCounters[0];
for (unsigned p = 1, e = PfmCounters.size(); p != e; ++p)
OS << ",\" \"" << PfmCounters[p];
OS << "\", // #" << i << " = ";
OS << CounterDef->getValueAsDef("Resource")->getName() << "\n";
} else {
OS << " nullptr,\n";
OS << " nullptr, // #" << i << "\n";
}
}
OS << "};\n";