[llvm] [Exegesis][RISCV] Add RISCV support for llvm-exegesis (PR #89047)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 13 06:24:22 PDT 2024


================
@@ -0,0 +1,73 @@
+//===-- RISCVCounters.cpp ---------------------------------------*- C++ -*-===//
+//
+// 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 file defines RISC-V perf counters.
+//
+//===----------------------------------------------------------------------===//
+
+#include "RISCVCounters.h"
+
+namespace llvm {
+namespace exegesis {
+
+// This implementation of RISCV target for Exegesis doesn't use libpfm
+// and provides manual implementation of performance counters.
+
+inline uint64_t getRISCVCpuCyclesCount() {
+#ifdef __riscv
+  uint64_t Counter;
+  asm("csrr %0, cycle" : "=r"(Counter)::"memory");
----------------
dtcxzyw wrote:

It is incorrect on rv32. See also https://github.com/google/benchmark/blob/8e1823d6f59c1d0fdc084fd903c989e6816ea097/src/cycleclock.h#L192-L214.

BTW, as cycle counter is unavailable since Linux 6.6, I think libpfm is still needed.

See also
https://github.com/google/benchmark/commit/99bdb2127d1fa1cff444bbefb814e105c7d20c45

https://github.com/llvm/llvm-project/pull/89047


More information about the llvm-commits mailing list