Skip to content

Commit afa8aee

Browse files
authored
[RISCV][llvm-exegesis] Add default Pfm cycle counter. (llvm#121866)
Also tested with Ubuntu on SiFive's HiFive Premier P550 board. Curiously latency is reporting ~1.5 on basic scalar arithmetic, scalar mul is ~3.5, and div is ~36.5. This 0.5 cycles higher than I expect.
1 parent 6192faf commit afa8aee

File tree

5 files changed

+37
-2
lines changed

5 files changed

+37
-2
lines changed

llvm/lib/Target/RISCV/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ tablegen(LLVM RISCVGenRegisterBank.inc -gen-register-bank)
1515
tablegen(LLVM RISCVGenRegisterInfo.inc -gen-register-info)
1616
tablegen(LLVM RISCVGenSearchableTables.inc -gen-searchable-tables)
1717
tablegen(LLVM RISCVGenSubtargetInfo.inc -gen-subtarget)
18+
tablegen(LLVM RISCVGenExegesis.inc -gen-exegesis)
1819

1920
set(LLVM_TARGET_DEFINITIONS RISCVGISel.td)
2021
tablegen(LLVM RISCVGenGlobalISel.inc -gen-global-isel)

llvm/lib/Target/RISCV/RISCV.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ include "RISCVSchedXiangShanNanHu.td"
6363

6464
include "RISCVProcessors.td"
6565

66+
//===----------------------------------------------------------------------===//
67+
// Pfm Counters
68+
//===----------------------------------------------------------------------===//
69+
70+
include "RISCVPfmCounters.td"
71+
6672
//===----------------------------------------------------------------------===//
6773
// Define the RISC-V target.
6874
//===----------------------------------------------------------------------===//
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//===---- RISCVPfmCounters.td - RISC-V Hardware Counters ---*- tablegen -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
//
9+
// This describes the available hardware counters for RISC-V.
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
def CpuCyclesPfmCounter : PfmCounter<"CYCLES">;
14+
15+
def DefaultPfmCounters : ProcPfmCounters {
16+
let CycleCounter = CpuCyclesPfmCounter;
17+
}
18+
def : PfmCountersDefaultBinding<DefaultPfmCounters>;

llvm/tools/llvm-exegesis/lib/RISCV/Target.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
namespace llvm {
2525
namespace exegesis {
2626

27+
#include "RISCVGenExegesis.inc"
28+
2729
namespace {
2830

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

134136
ExegesisRISCVTarget::ExegesisRISCVTarget()
135-
: ExegesisTarget(ArrayRef<CpuAndPfmCounters>{},
136-
RISCV_MC::isOpcodeAvailable) {}
137+
: ExegesisTarget(RISCVCpuPfmCounters, RISCV_MC::isOpcodeAvailable) {}
137138

138139
bool ExegesisRISCVTarget::matchesArch(Triple::ArchType Arch) const {
139140
return Arch == Triple::riscv32 || Arch == Triple::riscv64;

llvm/unittests/tools/llvm-exegesis/RISCV/TargetTest.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ TEST_F(RISCVTargetTest, SetRegToConstant) {
4242
EXPECT_THAT(Insts, Not(IsEmpty()));
4343
}
4444

45+
TEST_F(RISCVTargetTest, DefaultPfmCounters) {
46+
const std::string Expected = "CYCLES";
47+
EXPECT_EQ(State.getExegesisTarget().getPfmCounters("").CycleCounter,
48+
Expected);
49+
EXPECT_EQ(
50+
State.getExegesisTarget().getPfmCounters("unknown_cpu").CycleCounter,
51+
Expected);
52+
}
53+
4554
} // namespace
4655
} // namespace exegesis
4756
} // namespace llvm

0 commit comments

Comments
 (0)