diff --git a/llvm/lib/Target/RISCV/CMakeLists.txt b/llvm/lib/Target/RISCV/CMakeLists.txt index 44661647a86310..98d3615ebab58d 100644 --- a/llvm/lib/Target/RISCV/CMakeLists.txt +++ b/llvm/lib/Target/RISCV/CMakeLists.txt @@ -15,6 +15,7 @@ tablegen(LLVM RISCVGenRegisterBank.inc -gen-register-bank) tablegen(LLVM RISCVGenRegisterInfo.inc -gen-register-info) tablegen(LLVM RISCVGenSearchableTables.inc -gen-searchable-tables) tablegen(LLVM RISCVGenSubtargetInfo.inc -gen-subtarget) +tablegen(LLVM RISCVGenExegesis.inc -gen-exegesis) set(LLVM_TARGET_DEFINITIONS RISCVGISel.td) tablegen(LLVM RISCVGenGlobalISel.inc -gen-global-isel) diff --git a/llvm/lib/Target/RISCV/RISCV.td b/llvm/lib/Target/RISCV/RISCV.td index 963124140cd035..4e0c64a5ca2c6f 100644 --- a/llvm/lib/Target/RISCV/RISCV.td +++ b/llvm/lib/Target/RISCV/RISCV.td @@ -63,6 +63,12 @@ include "RISCVSchedXiangShanNanHu.td" include "RISCVProcessors.td" +//===----------------------------------------------------------------------===// +// Pfm Counters +//===----------------------------------------------------------------------===// + +include "RISCVPfmCounters.td" + //===----------------------------------------------------------------------===// // Define the RISC-V target. //===----------------------------------------------------------------------===// diff --git a/llvm/lib/Target/RISCV/RISCVPfmCounters.td b/llvm/lib/Target/RISCV/RISCVPfmCounters.td new file mode 100644 index 00000000000000..013e789a9e9217 --- /dev/null +++ b/llvm/lib/Target/RISCV/RISCVPfmCounters.td @@ -0,0 +1,18 @@ +//===---- RISCVPfmCounters.td - RISC-V Hardware Counters ---*- tablegen -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// +// +// This describes the available hardware counters for RISC-V. +// +//===----------------------------------------------------------------------===// + +def CpuCyclesPfmCounter : PfmCounter<"CYCLES">; + +def DefaultPfmCounters : ProcPfmCounters { + let CycleCounter = CpuCyclesPfmCounter; +} +def : PfmCountersDefaultBinding; diff --git a/llvm/tools/llvm-exegesis/lib/RISCV/Target.cpp b/llvm/tools/llvm-exegesis/lib/RISCV/Target.cpp index 41d361532908ca..5636782bdf7f6f 100644 --- a/llvm/tools/llvm-exegesis/lib/RISCV/Target.cpp +++ b/llvm/tools/llvm-exegesis/lib/RISCV/Target.cpp @@ -24,6 +24,8 @@ namespace llvm { namespace exegesis { +#include "RISCVGenExegesis.inc" + namespace { // Stores constant value to a general-purpose (integer) register. @@ -132,8 +134,7 @@ class ExegesisRISCVTarget : public ExegesisTarget { }; ExegesisRISCVTarget::ExegesisRISCVTarget() - : ExegesisTarget(ArrayRef{}, - RISCV_MC::isOpcodeAvailable) {} + : ExegesisTarget(RISCVCpuPfmCounters, RISCV_MC::isOpcodeAvailable) {} bool ExegesisRISCVTarget::matchesArch(Triple::ArchType Arch) const { return Arch == Triple::riscv32 || Arch == Triple::riscv64; diff --git a/llvm/unittests/tools/llvm-exegesis/RISCV/TargetTest.cpp b/llvm/unittests/tools/llvm-exegesis/RISCV/TargetTest.cpp index 745a6c68c9a0e1..12d3ce7165a864 100644 --- a/llvm/unittests/tools/llvm-exegesis/RISCV/TargetTest.cpp +++ b/llvm/unittests/tools/llvm-exegesis/RISCV/TargetTest.cpp @@ -42,6 +42,15 @@ TEST_F(RISCVTargetTest, SetRegToConstant) { EXPECT_THAT(Insts, Not(IsEmpty())); } +TEST_F(RISCVTargetTest, DefaultPfmCounters) { + const std::string Expected = "CYCLES"; + EXPECT_EQ(State.getExegesisTarget().getPfmCounters("").CycleCounter, + Expected); + EXPECT_EQ( + State.getExegesisTarget().getPfmCounters("unknown_cpu").CycleCounter, + Expected); +} + } // namespace } // namespace exegesis } // namespace llvm