[PATCH] D105861: [llvm-exegesis] Rework cmake variables around LIBPFM checking.

Vy Nguyen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 12 17:33:23 PDT 2021


oontvoo created this revision.
oontvoo added reviewers: courbet, ondrasej.
Herald added subscribers: mstojanovic, mgorny.
oontvoo requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Related PR/revisions: D84076 <https://reviews.llvm.org/D84076>, PR51017+D105615 <https://reviews.llvm.org/D105615>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105861

Files:
  llvm/cmake/modules/FindLibpfm.cmake
  llvm/tools/llvm-exegesis/lib/X86/X86Counter.cpp
  llvm/tools/llvm-exegesis/lib/X86/X86Counter.h


Index: llvm/tools/llvm-exegesis/lib/X86/X86Counter.h
===================================================================
--- llvm/tools/llvm-exegesis/lib/X86/X86Counter.h
+++ llvm/tools/llvm-exegesis/lib/X86/X86Counter.h
@@ -15,14 +15,14 @@
 #ifndef LLVM_TOOLS_LLVM_EXEGESIS_LIB_X86_X86COUNTER_H
 #define LLVM_TOOLS_LLVM_EXEGESIS_LIB_X86_X86COUNTER_H
 
-#include "../PerfHelper.h"
-#include "llvm/Support/Error.h"
-
 // FIXME: Use appropriate wrappers for poll.h and mman.h
 // to support Windows and remove this linux-only guard.
 #if defined(__linux__) && defined(HAVE_LIBPFM) &&                              \
     defined(LIBPFM_HAS_FIELD_CYCLES)
 
+#include "../PerfHelper.h"
+#include "llvm/Support/Error.h"
+
 namespace llvm {
 namespace exegesis {
 
Index: llvm/tools/llvm-exegesis/lib/X86/X86Counter.cpp
===================================================================
--- llvm/tools/llvm-exegesis/lib/X86/X86Counter.cpp
+++ llvm/tools/llvm-exegesis/lib/X86/X86Counter.cpp
@@ -16,11 +16,9 @@
 #include "llvm/Support/Endian.h"
 #include "llvm/Support/Errc.h"
 
-#ifdef HAVE_LIBPFM
 #include "perfmon/perf_event.h"
 #include "perfmon/pfmlib.h"
 #include "perfmon/pfmlib_perf_event.h"
-#endif // HAVE_LIBPFM
 
 #include <atomic>
 #include <chrono>
Index: llvm/cmake/modules/FindLibpfm.cmake
===================================================================
--- llvm/cmake/modules/FindLibpfm.cmake
+++ llvm/cmake/modules/FindLibpfm.cmake
@@ -12,10 +12,19 @@
 if (LLVM_ENABLE_LIBPFM)
   check_library_exists(pfm pfm_initialize "" HAVE_LIBPFM_INITIALIZE)
   if(HAVE_LIBPFM_INITIALIZE)
-    check_include_file(perfmon/perf_event.h HAVE_PERFMON_PERF_EVENT_H)
-    check_include_file(perfmon/pfmlib.h HAVE_PERFMON_PFMLIB_H)
-    check_include_file(perfmon/pfmlib_perf_event.h HAVE_PERFMON_PFMLIB_PERF_EVENT_H)
-    if(HAVE_PERFMON_PERF_EVENT_H AND HAVE_PERFMON_PFMLIB_H AND HAVE_PERFMON_PFMLIB_PERF_EVENT_H)
+    # Check to see if compilation with all libpfm headers succeed.
+    # Note: We do not use check_include_file() here because on some older
+    # libpfm versions, we have seen header-not-found errors
+    # while building, even though check_include_file() succeeded.
+    CHECK_CXX_SOURCE_COMPILES("
+      #include <perfmon/perf_event.h>
+      #include "perfmon/pfmlib.h"
+      #include "perfmon/pfmlib_perf_event.h"
+      int main() {
+        perf_branch_entry entry;
+        return 0;
+      }" COMPILE_WITH_HEADERS)
+    if(COMPILE_WITH_HEADERS)
       set(HAVE_LIBPFM 1)
       # Check to see if perf_branch_entry has the field 'cycles'.
       # We couldn't use CheckStructHasMember here because 'cycles' is a bit field which is not
@@ -26,7 +35,7 @@
           perf_branch_entry entry;
           entry.cycles = 2;
           return 0;
-        }" COMPILE_WITH_CYCLES)
+         }" COMPILE_WITH_CYCLES)
       if(COMPILE_WITH_CYCLES)
         set(LIBPFM_HAS_FIELD_CYCLES 1)
       endif()


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105861.358110.patch
Type: text/x-patch
Size: 2918 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210713/5cb4fd15/attachment.bin>


More information about the llvm-commits mailing list