[llvm-exegesis] Fix PfmIssueCountersTable creation
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Thu, 19 Apr 2018 10:59:49 +0000 (10:59 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Thu, 19 Apr 2018 10:59:49 +0000 (10:59 +0000)
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

llvm/utils/TableGen/SubtargetEmitter.cpp

index 38b0df6..e2e5b8b 100644 (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";