diff options
| author | Clement Courbet <courbet@google.com> | 2018-04-10 08:16:37 +0000 |
|---|---|---|
| committer | Clement Courbet <courbet@google.com> | 2018-04-10 08:16:37 +0000 |
| commit | b449379eae0267d4993e273cc38f980ac4c264ca (patch) | |
| tree | dbe049f10b64d8a88f2ce6905353586673c47337 /llvm/utils/TableGen/SubtargetEmitter.cpp | |
| parent | 30fda45c18c0424b28f1b901a15c12a148aadc46 (diff) | |
| download | bcm5719-llvm-b449379eae0267d4993e273cc38f980ac4c264ca.tar.gz bcm5719-llvm-b449379eae0267d4993e273cc38f980ac4c264ca.zip | |
[MC][TableGen] Add optional libpfm counter names for ProcResUnits.
Summary:
Subtargets can define the libpfm counter names that can be used to
measure cycles and uops issued on ProcResUnits.
This allows making llvm-exegesis available on more targets.
Fixes PR36984.
Reviewers: gchatelet, RKSimon, andreadb, craig.topper
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D45360
llvm-svn: 329675
Diffstat (limited to 'llvm/utils/TableGen/SubtargetEmitter.cpp')
| -rw-r--r-- | llvm/utils/TableGen/SubtargetEmitter.cpp | 62 |
1 files changed, 59 insertions, 3 deletions
diff --git a/llvm/utils/TableGen/SubtargetEmitter.cpp b/llvm/utils/TableGen/SubtargetEmitter.cpp index 443a752ff29..e42f27ab149 100644 --- a/llvm/utils/TableGen/SubtargetEmitter.cpp +++ b/llvm/utils/TableGen/SubtargetEmitter.cpp @@ -635,7 +635,7 @@ static void EmitRegisterFileInfo(const CodeGenProcModel &ProcModel, OS << ProcModel.ModelName << "RegisterCosts,\n "; else OS << "nullptr,\n "; - OS << NumCostEntries << " // Number of register cost entries.\n"; + OS << NumCostEntries << ", // Number of register cost entries.\n"; } unsigned @@ -686,6 +686,57 @@ SubtargetEmitter::EmitRegisterFileTables(const CodeGenProcModel &ProcModel, return CostTblIndex; } +static bool EmitPfmIssueCountersTable(const CodeGenProcModel &ProcModel, + raw_ostream &OS) { + std::vector<const Record *> CounterDefs(ProcModel.ProcResourceDefs.size()); + bool HasCounters = false; + for (const Record *CounterDef : ProcModel.PfmIssueCounterDefs) { + const Record *&CD = CounterDefs[ProcModel.getProcResourceIdx( + CounterDef->getValueAsDef("Resource"))]; + if (CD) { + PrintFatalError(CounterDef->getLoc(), + "multiple issue counters for " + + CounterDef->getValueAsDef("Resource")->getName()); + } + CD = CounterDef; + HasCounters = true; + } + if (!HasCounters) { + return false; + } + OS << "\nstatic const char* " << ProcModel.ModelName + << "PfmIssueCounters[] = {\n"; + for (const Record *CounterDef : CounterDefs) { + 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"; + } else { + OS << " nullptr,\n"; + } + } + OS << "};\n"; + return true; +} + +static void EmitPfmCounters(const CodeGenProcModel &ProcModel, + const bool HasPfmIssueCounters, raw_ostream &OS) { + // Emit the cycle counter. + if (ProcModel.PfmCycleCounterDef) + OS << " \"" << ProcModel.PfmCycleCounterDef->getValueAsString("Counter") + << "\", // Cycle counter.\n"; + else + OS << " nullptr, // No cycle counter.\n"; + + // Emit a reference to issue counters table. + if (HasPfmIssueCounters) + OS << " " << ProcModel.ModelName << "PfmIssueCounters\n"; + else + OS << " nullptr, // No issue counters.\n"; +} void SubtargetEmitter::EmitExtraProcessorInfo(const CodeGenProcModel &ProcModel, raw_ostream &OS) { @@ -693,6 +744,9 @@ void SubtargetEmitter::EmitExtraProcessorInfo(const CodeGenProcModel &ProcModel, // defined register file), and a table of register costs. unsigned NumCostEntries = EmitRegisterFileTables(ProcModel, OS); + // Generate a table of ProcRes counter names. + const bool HasPfmIssueCounters = EmitPfmIssueCountersTable(ProcModel, OS); + // Now generate a table for the extra processor info. OS << "\nstatic const llvm::MCExtraProcessorInfo " << ProcModel.ModelName << "ExtraInfo = {\n "; @@ -705,6 +759,8 @@ void SubtargetEmitter::EmitExtraProcessorInfo(const CodeGenProcModel &ProcModel, EmitRegisterFileInfo(ProcModel, ProcModel.RegisterFiles.size(), NumCostEntries, OS); + EmitPfmCounters(ProcModel, HasPfmIssueCounters, OS); + OS << "};\n"; } @@ -1308,9 +1364,9 @@ void SubtargetEmitter::EmitProcessorModels(raw_ostream &OS) { else OS << " nullptr, // No Itinerary\n"; if (PM.hasExtraProcessorInfo()) - OS << " &" << PM.ModelName << "ExtraInfo\n"; + OS << " &" << PM.ModelName << "ExtraInfo,\n"; else - OS << " nullptr // No extra processor descriptor\n"; + OS << " nullptr // No extra processor descriptor\n"; OS << "};\n"; } } |

