Skip to content

[RISCV][llvm-exegesis] Add default Pfm cycle counter. #121866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions llvm/lib/Target/RISCV/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions llvm/lib/Target/RISCV/RISCV.td
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ include "RISCVSchedXiangShanNanHu.td"

include "RISCVProcessors.td"

//===----------------------------------------------------------------------===//
// Pfm Counters
//===----------------------------------------------------------------------===//

include "RISCVPfmCounters.td"

//===----------------------------------------------------------------------===//
// Define the RISC-V target.
//===----------------------------------------------------------------------===//
Expand Down
18 changes: 18 additions & 0 deletions llvm/lib/Target/RISCV/RISCVPfmCounters.td
Original file line number Diff line number Diff line change
@@ -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<DefaultPfmCounters>;
5 changes: 3 additions & 2 deletions llvm/tools/llvm-exegesis/lib/RISCV/Target.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
namespace llvm {
namespace exegesis {

#include "RISCVGenExegesis.inc"

namespace {

// Stores constant value to a general-purpose (integer) register.
Expand Down Expand Up @@ -132,8 +134,7 @@ class ExegesisRISCVTarget : public ExegesisTarget {
};

ExegesisRISCVTarget::ExegesisRISCVTarget()
: ExegesisTarget(ArrayRef<CpuAndPfmCounters>{},
RISCV_MC::isOpcodeAvailable) {}
: ExegesisTarget(RISCVCpuPfmCounters, RISCV_MC::isOpcodeAvailable) {}

bool ExegesisRISCVTarget::matchesArch(Triple::ArchType Arch) const {
return Arch == Triple::riscv32 || Arch == Triple::riscv64;
Expand Down
9 changes: 9 additions & 0 deletions llvm/unittests/tools/llvm-exegesis/RISCV/TargetTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading