diff --git a/llvm/cmake/modules/FindLibpfm.cmake b/llvm/cmake/modules/FindLibpfm.cmake --- a/llvm/cmake/modules/FindLibpfm.cmake +++ b/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 + #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() diff --git a/llvm/tools/llvm-exegesis/lib/X86/X86Counter.h b/llvm/tools/llvm-exegesis/lib/X86/X86Counter.h --- a/llvm/tools/llvm-exegesis/lib/X86/X86Counter.h +++ b/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 { diff --git a/llvm/tools/llvm-exegesis/lib/X86/X86Counter.cpp b/llvm/tools/llvm-exegesis/lib/X86/X86Counter.cpp --- a/llvm/tools/llvm-exegesis/lib/X86/X86Counter.cpp +++ b/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 #include