[llvm] r346489 - [llvm-exegesis][NFC] Add a way to declare the default counter binding for unbound CPUs for a target.
Clement Courbet via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 9 05:15:33 PST 2018
Author: courbet
Date: Fri Nov 9 05:15:32 2018
New Revision: 346489
URL: http://llvm.org/viewvc/llvm-project?rev=346489&view=rev
Log:
[llvm-exegesis][NFC] Add a way to declare the default counter binding for unbound CPUs for a target.
Summary:
This simplifies the code and moves everything to tablegen for consistency. This
also prepares the ground for adding issue counters.
Reviewers: gchatelet, john.brawn, jsji
Subscribers: nemanjai, mgorny, javed.absar, kbarton, tschuett, llvm-commits
Differential Revision: https://reviews.llvm.org/D54297
Added:
llvm/trunk/lib/Target/AArch64/AArch64PfmCounters.td
llvm/trunk/lib/Target/PowerPC/PPCPfmCounters.td
Modified:
llvm/trunk/include/llvm/Target/TargetPfmCounters.td
llvm/trunk/lib/Target/AArch64/AArch64.td
llvm/trunk/lib/Target/AArch64/CMakeLists.txt
llvm/trunk/lib/Target/PowerPC/CMakeLists.txt
llvm/trunk/lib/Target/PowerPC/PPC.td
llvm/trunk/lib/Target/X86/X86PfmCounters.td
llvm/trunk/tools/llvm-exegesis/lib/AArch64/Target.cpp
llvm/trunk/tools/llvm-exegesis/lib/Latency.cpp
llvm/trunk/tools/llvm-exegesis/lib/Latency.h
llvm/trunk/tools/llvm-exegesis/lib/PowerPC/Target.cpp
llvm/trunk/tools/llvm-exegesis/lib/Target.cpp
llvm/trunk/unittests/tools/llvm-exegesis/AArch64/TargetTest.cpp
llvm/trunk/unittests/tools/llvm-exegesis/PowerPC/TargetTest.cpp
llvm/trunk/utils/TableGen/ExegesisEmitter.cpp
Modified: llvm/trunk/include/llvm/Target/TargetPfmCounters.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetPfmCounters.td?rev=346489&r1=346488&r2=346489&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetPfmCounters.td (original)
+++ llvm/trunk/include/llvm/Target/TargetPfmCounters.td Fri Nov 9 05:15:32 2018
@@ -44,3 +44,7 @@ class PfmCountersBinding<string cpu_name
string CpuName = cpu_name;
ProcPfmCounters Counters = counters;
}
+
+// Declares the default binding for unbound CPUs for the target.
+class PfmCountersDefaultBinding<ProcPfmCounters counters>
+ : PfmCountersBinding<"", counters> {}
Modified: llvm/trunk/lib/Target/AArch64/AArch64.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64.td?rev=346489&r1=346488&r2=346489&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/AArch64.td (original)
+++ llvm/trunk/lib/Target/AArch64/AArch64.td Fri Nov 9 05:15:32 2018
@@ -626,3 +626,9 @@ def AArch64 : Target {
let AssemblyWriters = [GenericAsmWriter, AppleAsmWriter];
let AllowRegisterRenaming = 1;
}
+
+//===----------------------------------------------------------------------===//
+// Pfm Counters
+//===----------------------------------------------------------------------===//
+
+include "AArch64PfmCounters.td"
Added: llvm/trunk/lib/Target/AArch64/AArch64PfmCounters.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/AArch64PfmCounters.td?rev=346489&view=auto
==============================================================================
--- llvm/trunk/lib/Target/AArch64/AArch64PfmCounters.td (added)
+++ llvm/trunk/lib/Target/AArch64/AArch64PfmCounters.td Fri Nov 9 05:15:32 2018
@@ -0,0 +1,19 @@
+//===-- AArch64PfmCounters.td - AArch64 Hardware Counters --*- tablegen -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This describes the available hardware counters for AArch64.
+//
+//===----------------------------------------------------------------------===//
+
+def CpuCyclesPfmCounter : PfmCounter<"CPU_CYCLES">;
+
+def DefaultPfmCounters : ProcPfmCounters {
+ let CycleCounter = CpuCyclesPfmCounter;
+}
+def : PfmCountersDefaultBinding<DefaultPfmCounters>;
Modified: llvm/trunk/lib/Target/AArch64/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/AArch64/CMakeLists.txt?rev=346489&r1=346488&r2=346489&view=diff
==============================================================================
--- llvm/trunk/lib/Target/AArch64/CMakeLists.txt (original)
+++ llvm/trunk/lib/Target/AArch64/CMakeLists.txt Fri Nov 9 05:15:32 2018
@@ -15,6 +15,7 @@ tablegen(LLVM AArch64GenRegisterBank.inc
tablegen(LLVM AArch64GenRegisterInfo.inc -gen-register-info)
tablegen(LLVM AArch64GenSubtargetInfo.inc -gen-subtarget)
tablegen(LLVM AArch64GenSystemOperands.inc -gen-searchable-tables)
+tablegen(LLVM AArch64GenExegesis.inc -gen-exegesis)
add_public_tablegen_target(AArch64CommonTableGen)
Modified: llvm/trunk/lib/Target/PowerPC/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/CMakeLists.txt?rev=346489&r1=346488&r2=346489&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/CMakeLists.txt (original)
+++ llvm/trunk/lib/Target/PowerPC/CMakeLists.txt Fri Nov 9 05:15:32 2018
@@ -10,6 +10,7 @@ tablegen(LLVM PPCGenInstrInfo.inc -gen-i
tablegen(LLVM PPCGenMCCodeEmitter.inc -gen-emitter)
tablegen(LLVM PPCGenRegisterInfo.inc -gen-register-info)
tablegen(LLVM PPCGenSubtargetInfo.inc -gen-subtarget)
+tablegen(LLVM PPCGenExegesis.inc -gen-exegesis)
add_public_tablegen_target(PowerPCCommonTableGen)
Modified: llvm/trunk/lib/Target/PowerPC/PPC.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPC.td?rev=346489&r1=346488&r2=346489&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPC.td (original)
+++ llvm/trunk/lib/Target/PowerPC/PPC.td Fri Nov 9 05:15:32 2018
@@ -305,11 +305,11 @@ def : Processor<"generic", G3Itineraries
FeatureMFTB]>;
def : ProcessorModel<"440", PPC440Model, [Directive440, FeatureISEL,
FeatureFRES, FeatureFRSQRTE,
- FeatureICBT, FeatureBookE,
+ FeatureICBT, FeatureBookE,
FeatureMSYNC, FeatureMFTB]>;
def : ProcessorModel<"450", PPC440Model, [Directive440, FeatureISEL,
FeatureFRES, FeatureFRSQRTE,
- FeatureICBT, FeatureBookE,
+ FeatureICBT, FeatureBookE,
FeatureMSYNC, FeatureMFTB]>;
def : Processor<"601", G3Itineraries, [Directive601, FeatureFPU]>;
def : Processor<"602", G3Itineraries, [Directive602, FeatureFPU,
@@ -348,7 +348,7 @@ def : Processor<"7450", G4PlusItinerarie
FeatureFRES, FeatureFRSQRTE,
FeatureMFTB]>;
def : Processor<"g4+", G4PlusItineraries, [Directive7400, FeatureAltivec,
- FeatureFRES, FeatureFRSQRTE,
+ FeatureFRES, FeatureFRSQRTE,
FeatureMFTB]>;
def : ProcessorModel<"970", G5Model,
@@ -369,11 +369,11 @@ def : ProcessorModel<"e500", PPCE500Mode
FeatureISEL, FeatureMFTB]>;
def : ProcessorModel<"e500mc", PPCE500mcModel,
[DirectiveE500mc,
- FeatureSTFIWX, FeatureICBT, FeatureBookE,
+ FeatureSTFIWX, FeatureICBT, FeatureBookE,
FeatureISEL, FeatureMFTB]>;
def : ProcessorModel<"e5500", PPCE5500Model,
[DirectiveE5500, FeatureMFOCRF, Feature64Bit,
- FeatureSTFIWX, FeatureICBT, FeatureBookE,
+ FeatureSTFIWX, FeatureICBT, FeatureBookE,
FeatureISEL, FeatureMFTB]>;
def : ProcessorModel<"a2", PPCA2Model,
[DirectiveA2, FeatureICBT, FeatureBookE, FeatureMFOCRF,
@@ -428,7 +428,7 @@ def : ProcessorModel<"pwr6x", G5Model,
FeatureMFTB, DeprecatedDST]>;
def : ProcessorModel<"pwr7", P7Model, ProcessorFeatures.Power7FeatureList>;
def : ProcessorModel<"pwr8", P8Model, ProcessorFeatures.Power8FeatureList>;
-def : ProcessorModel<"pwr9", P9Model, ProcessorFeatures.Power9FeatureList>;
+def : ProcessorModel<"pwr9", P9Model, ProcessorFeatures.Power9FeatureList>;
def : Processor<"ppc", G3Itineraries, [Directive32, FeatureHardFloat,
FeatureMFTB]>;
def : Processor<"ppc32", G3Itineraries, [Directive32, FeatureHardFloat,
@@ -478,3 +478,9 @@ def PPC : Target {
let AssemblyParserVariants = [PPCAsmParserVariant];
let AllowRegisterRenaming = 1;
}
+
+//===----------------------------------------------------------------------===//
+// Pfm Counters
+//===----------------------------------------------------------------------===//
+
+include "PPCPfmCounters.td"
Added: llvm/trunk/lib/Target/PowerPC/PPCPfmCounters.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCPfmCounters.td?rev=346489&view=auto
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCPfmCounters.td (added)
+++ llvm/trunk/lib/Target/PowerPC/PPCPfmCounters.td Fri Nov 9 05:15:32 2018
@@ -0,0 +1,19 @@
+//===-- PPCPfmCounters.td - PPC Hardware Counters ----------*- tablegen -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This describes the available hardware counters for PPC.
+//
+//===----------------------------------------------------------------------===//
+
+def CpuCyclesPfmCounter : PfmCounter<"CYCLES">;
+
+def DefaultPfmCounters : ProcPfmCounters {
+ let CycleCounter = CpuCyclesPfmCounter;
+}
+def : PfmCountersDefaultBinding<DefaultPfmCounters>;
Modified: llvm/trunk/lib/Target/X86/X86PfmCounters.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86PfmCounters.td?rev=346489&r1=346488&r2=346489&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86PfmCounters.td (original)
+++ llvm/trunk/lib/Target/X86/X86PfmCounters.td Fri Nov 9 05:15:32 2018
@@ -14,6 +14,10 @@
def UnhaltedCoreCyclesPfmCounter : PfmCounter<"unhalted_core_cycles">;
def UopsIssuedPfmCounter : PfmCounter<"uops_issued:any">;
+// No default counters on X86.
+def DefaultPfmCounters : ProcPfmCounters {}
+def : PfmCountersDefaultBinding<DefaultPfmCounters>;
+
def SandyBridgePfmCounters : ProcPfmCounters {
let CycleCounter = UnhaltedCoreCyclesPfmCounter;
let UopsCounter = UopsIssuedPfmCounter;
Modified: llvm/trunk/tools/llvm-exegesis/lib/AArch64/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/AArch64/Target.cpp?rev=346489&r1=346488&r2=346489&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/AArch64/Target.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/AArch64/Target.cpp Fri Nov 9 05:15:32 2018
@@ -14,22 +14,6 @@
namespace llvm {
namespace exegesis {
-namespace {
-
-class AArch64LatencyBenchmarkRunner : public LatencyBenchmarkRunner {
-public:
- AArch64LatencyBenchmarkRunner(const LLVMState &State)
- : LatencyBenchmarkRunner(State) {}
-
-private:
- const char *getCounterName() const override {
- // All AArch64 subtargets have CPU_CYCLES as the cycle counter name
- return "CPU_CYCLES";
- }
-};
-
-namespace {
-
static unsigned getLoadImmediateOpcode(unsigned RegBitWidth) {
switch (RegBitWidth) {
case 32:
@@ -50,11 +34,13 @@ static llvm::MCInst loadImmediate(unsign
.addImm(Value.getZExtValue());
}
-} // namespace
+#include "AArch64GenExegesis.inc"
+
+namespace {
class ExegesisAArch64Target : public ExegesisTarget {
public:
- ExegesisAArch64Target() : ExegesisTarget({}) {}
+ ExegesisAArch64Target() : ExegesisTarget(AArch64CpuPfmCounters) {}
private:
std::vector<llvm::MCInst> setRegTo(const llvm::MCSubtargetInfo &STI,
@@ -76,11 +62,6 @@ private:
// Function return is a pseudo-instruction that needs to be expanded
PM.add(llvm::createAArch64ExpandPseudoPass());
}
-
- std::unique_ptr<BenchmarkRunner>
- createLatencyBenchmarkRunner(const LLVMState &State) const override {
- return llvm::make_unique<AArch64LatencyBenchmarkRunner>(State);
- }
};
} // namespace
Modified: llvm/trunk/tools/llvm-exegesis/lib/Latency.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/Latency.cpp?rev=346489&r1=346488&r2=346489&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Latency.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Latency.cpp Fri Nov 9 05:15:32 2018
@@ -166,13 +166,6 @@ LatencySnippetGenerator::generateCodeTem
return std::move(Results);
}
-const char *LatencyBenchmarkRunner::getCounterName() const {
- const char *CounterName = State.getPfmCounters().CycleCounter;
- if (!CounterName)
- llvm::report_fatal_error("sched model does not define a cycle counter");
- return CounterName;
-}
-
LatencyBenchmarkRunner::~LatencyBenchmarkRunner() = default;
llvm::Expected<std::vector<BenchmarkMeasure>>
@@ -182,9 +175,9 @@ LatencyBenchmarkRunner::runMeasurements(
// measure several times and take the minimum value.
constexpr const int NumMeasurements = 30;
int64_t MinValue = std::numeric_limits<int64_t>::max();
- const char *CounterName = getCounterName();
+ const char *CounterName = State.getPfmCounters().CycleCounter;
if (!CounterName)
- llvm::report_fatal_error("could not determine cycle counter name");
+ llvm::report_fatal_error("sched model does not define a cycle counter");
for (size_t I = 0; I < NumMeasurements; ++I) {
auto ExpectedCounterValue = Executor.runAndMeasure(CounterName);
if (!ExpectedCounterValue)
Modified: llvm/trunk/tools/llvm-exegesis/lib/Latency.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/Latency.h?rev=346489&r1=346488&r2=346489&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Latency.h (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Latency.h Fri Nov 9 05:15:32 2018
@@ -40,8 +40,6 @@ public:
private:
llvm::Expected<std::vector<BenchmarkMeasure>>
runMeasurements(const FunctionExecutor &Executor) const override;
-
- virtual const char *getCounterName() const;
};
} // namespace exegesis
} // namespace llvm
Modified: llvm/trunk/tools/llvm-exegesis/lib/PowerPC/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/PowerPC/Target.cpp?rev=346489&r1=346488&r2=346489&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/PowerPC/Target.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/PowerPC/Target.cpp Fri Nov 9 05:15:32 2018
@@ -15,24 +15,12 @@
namespace llvm {
namespace exegesis {
-namespace {
-class PowerPCLatencyBenchmarkRunner : public LatencyBenchmarkRunner {
-public:
- PowerPCLatencyBenchmarkRunner(const LLVMState &State)
- : LatencyBenchmarkRunner(State) {}
-
-private:
- const char *getCounterName() const override {
- // All PowerPC subtargets have CYCLES as the cycle counter name
- return "CYCLES";
- }
-};
-} // end anonymous namespace
+#include "PPCGenExegesis.inc"
namespace {
class ExegesisPowerPCTarget : public ExegesisTarget {
public:
- ExegesisPowerPCTarget() : ExegesisTarget({}) {}
+ ExegesisPowerPCTarget() : ExegesisTarget(PPCCpuPfmCounters) {}
private:
std::vector<llvm::MCInst> setRegTo(const llvm::MCSubtargetInfo &STI,
@@ -41,10 +29,6 @@ private:
bool matchesArch(llvm::Triple::ArchType Arch) const override {
return Arch == llvm::Triple::ppc64le;
}
- std::unique_ptr<BenchmarkRunner>
- createLatencyBenchmarkRunner(const LLVMState &State) const override {
- return llvm::make_unique<PowerPCLatencyBenchmarkRunner>(State);
- }
};
} // end anonymous namespace
Modified: llvm/trunk/tools/llvm-exegesis/lib/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-exegesis/lib/Target.cpp?rev=346489&r1=346488&r2=346489&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-exegesis/lib/Target.cpp (original)
+++ llvm/trunk/tools/llvm-exegesis/lib/Target.cpp Fri Nov 9 05:15:32 2018
@@ -87,7 +87,8 @@ ExegesisTarget::createUopsBenchmarkRunne
static_assert(std::is_pod<PfmCountersInfo>::value,
"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 &
ExegesisTarget::getPfmCounters(llvm::StringRef CpuName) const {
@@ -103,7 +104,13 @@ ExegesisTarget::getPfmCounters(llvm::Str
std::lower_bound(CpuPfmCounters.begin(), CpuPfmCounters.end(), CpuName);
if (Found == CpuPfmCounters.end() ||
llvm::StringRef(Found->CpuName) != CpuName) {
- return PfmCountersInfo::Default;
+ // Use the default.
+ if (CpuPfmCounters.begin() != CpuPfmCounters.end() &&
+ CpuPfmCounters.begin()->CpuName[0] == '\0') {
+ Found = CpuPfmCounters.begin(); // The target specifies a default.
+ } else {
+ return PfmCountersInfo::Default; // No default for the target.
+ }
}
assert(Found->PCI && "Missing counters");
return *Found->PCI;
Modified: llvm/trunk/unittests/tools/llvm-exegesis/AArch64/TargetTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/tools/llvm-exegesis/AArch64/TargetTest.cpp?rev=346489&r1=346488&r2=346489&view=diff
==============================================================================
--- llvm/trunk/unittests/tools/llvm-exegesis/AArch64/TargetTest.cpp (original)
+++ llvm/trunk/unittests/tools/llvm-exegesis/AArch64/TargetTest.cpp Fri Nov 9 05:15:32 2018
@@ -59,6 +59,12 @@ TEST_F(AArch64TargetTest, SetRegToConsta
EXPECT_THAT(Insts, Not(IsEmpty()));
}
+TEST_F(AArch64TargetTest, DefaultPfmCounters) {
+ EXPECT_EQ(ExegesisTarget_->getPfmCounters("").CycleCounter, "CPU_CYCLES");
+ EXPECT_EQ(ExegesisTarget_->getPfmCounters("unknown_cpu").CycleCounter,
+ "CPU_CYCLES");
+}
+
} // namespace
} // namespace exegesis
} // namespace llvm
Modified: llvm/trunk/unittests/tools/llvm-exegesis/PowerPC/TargetTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/tools/llvm-exegesis/PowerPC/TargetTest.cpp?rev=346489&r1=346488&r2=346489&view=diff
==============================================================================
--- llvm/trunk/unittests/tools/llvm-exegesis/PowerPC/TargetTest.cpp (original)
+++ llvm/trunk/unittests/tools/llvm-exegesis/PowerPC/TargetTest.cpp Fri Nov 9 05:15:32 2018
@@ -59,6 +59,12 @@ TEST_F(PowerPCTargetTest, SetRegToConsta
EXPECT_THAT(Insts, Not(IsEmpty()));
}
+TEST_F(PowerPCTargetTest, DefaultPfmCounters) {
+ EXPECT_EQ(ExegesisTarget_->getPfmCounters("").CycleCounter, "CYCLES");
+ EXPECT_EQ(ExegesisTarget_->getPfmCounters("unknown_cpu").CycleCounter,
+ "CYCLES");
+}
+
} // namespace
} // namespace exegesis
} // namespace llvm
Modified: llvm/trunk/utils/TableGen/ExegesisEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/ExegesisEmitter.cpp?rev=346489&r1=346488&r2=346489&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/ExegesisEmitter.cpp (original)
+++ llvm/trunk/utils/TableGen/ExegesisEmitter.cpp Fri Nov 9 05:15:32 2018
@@ -11,6 +11,7 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallSet.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Debug.h"
@@ -114,10 +115,6 @@ void ExegesisEmitter::emitPfmCountersInf
const size_t NumIssueCounters =
Def.getValueAsListOfDefs("IssueCounters").size();
- // This is the default, do not emit.
- if (CycleCounter.empty() && UopsCounter.empty() && NumIssueCounters == 0)
- return;
-
OS << "\nstatic const PfmCountersInfo " << Target << Def.getName()
<< " = {\n";
@@ -157,28 +154,35 @@ void ExegesisEmitter::emitPfmCounters(ra
// Emit the IssueCounters table.
const auto PfmCounterDefs =
Records.getAllDerivedDefinitions("ProcPfmCounters");
- OS << "static const PfmCountersInfo::IssueCounter " << Target
- << "PfmIssueCounters[] = {\n";
- for (const Record *Def : PfmCounterDefs) {
- for (const Record *ICDef : Def->getValueAsListOfDefs("IssueCounters"))
- OS << " { " << Target << "PfmCounterNames["
- << getPfmCounterId(ICDef->getValueAsString("Counter")) << "], \""
- << ICDef->getValueAsString("ResourceName") << "\"},\n";
+ // Only emit if non-empty.
+ const bool HasAtLeastOnePfmIssueCounter =
+ llvm::any_of(PfmCounterDefs, [](const Record *Def) {
+ return !Def->getValueAsListOfDefs("IssueCounters").empty();
+ });
+ if (HasAtLeastOnePfmIssueCounter) {
+ OS << "static const PfmCountersInfo::IssueCounter " << Target
+ << "PfmIssueCounters[] = {\n";
+ for (const Record *Def : PfmCounterDefs) {
+ for (const Record *ICDef : Def->getValueAsListOfDefs("IssueCounters"))
+ OS << " { " << Target << "PfmCounterNames["
+ << getPfmCounterId(ICDef->getValueAsString("Counter")) << "], \""
+ << ICDef->getValueAsString("ResourceName") << "\"},\n";
+ }
+ OS << "};\n";
}
- OS << "};\n";
-
// Now generate the PfmCountersInfo.
unsigned IssueCountersTableOffset = 0;
for (const Record *Def : PfmCounterDefs)
emitPfmCountersInfo(*Def, IssueCountersTableOffset, OS);
OS << "\n";
-}
+} // namespace
void ExegesisEmitter::emitPfmCountersLookupTable(raw_ostream &OS) const {
std::vector<Record *> Bindings =
Records.getAllDerivedDefinitions("PfmCountersBinding");
+ assert(!Bindings.empty() && "there must be at least one binding");
llvm::sort(Bindings, [](const Record *L, const Record *R) {
return L->getValueAsString("CpuName") < R->getValueAsString("CpuName");
});
More information about the llvm-commits
mailing list