[llvm] 7ead39a - [llvm-exegesis] Fix ifdefs in X86/Target.cpp

Pavel Kosov via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 24 12:32:58 PDT 2023


Author: Pavel Kosov
Date: 2023-04-24T22:31:40+03:00
New Revision: 7ead39aca61eb9df92d8920c771912c0bad3e469

URL: https://github.com/llvm/llvm-project/commit/7ead39aca61eb9df92d8920c771912c0bad3e469
DIFF: https://github.com/llvm/llvm-project/commit/7ead39aca61eb9df92d8920c771912c0bad3e469.diff

LOG: [llvm-exegesis] Fix ifdefs in X86/Target.cpp

As discussed in https://reviews.llvm.org/D96498, the correct macro
to check together with _MSC_VER is _M_X64. Testing for _MSC_VER with
__x86_64__ made tests fail on Windows in https://reviews.llvm.org/D146301.

Additionally, this commit replaces a few calls to llvm_unreachable() with
report_fatal_error() because it is actually reached even on Linux/i686,
causing obscure segfaults when expanded to __builtin_unreachable().

~~

Huawei RRI, OS Lab

Reviewed By: courbet

Differential Revision: https://reviews.llvm.org/D147926

Added: 
    

Modified: 
    llvm/test/tools/llvm-exegesis/X86/latency/dummy-counters.test
    llvm/tools/llvm-exegesis/lib/X86/Target.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-exegesis/X86/latency/dummy-counters.test b/llvm/test/tools/llvm-exegesis/X86/latency/dummy-counters.test
index 471b9f89578a4..c74c12c94793f 100644
--- a/llvm/test/tools/llvm-exegesis/X86/latency/dummy-counters.test
+++ b/llvm/test/tools/llvm-exegesis/X86/latency/dummy-counters.test
@@ -1,6 +1,5 @@
 # RUN: llvm-exegesis -mtriple=x86_64-unknown-unknown -mcpu=x86-64 -mode=latency -opcode-name=LEA64r --use-dummy-perf-counters | FileCheck %s
-# TODO Support non-Linux systems
-# REQUIRES: exegesis-can-execute-x86_64, system-linux
+# REQUIRES: exegesis-can-execute-x86_64
 
 CHECK:      ---
 CHECK-NEXT: mode: latency

diff  --git a/llvm/tools/llvm-exegesis/lib/X86/Target.cpp b/llvm/tools/llvm-exegesis/lib/X86/Target.cpp
index 1fad3e1f47540..833ba01e55467 100644
--- a/llvm/tools/llvm-exegesis/lib/X86/Target.cpp
+++ b/llvm/tools/llvm-exegesis/lib/X86/Target.cpp
@@ -21,6 +21,7 @@
 #include "llvm/MC/MCInstBuilder.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/Error.h"
+#include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/FormatVariadic.h"
 #include "llvm/TargetParser/Host.h"
 
@@ -31,7 +32,7 @@
 #include <immintrin.h>
 #include <intrin.h>
 #endif
-#if defined(__x86_64__) && defined(_MSC_VER)
+#if defined(_MSC_VER) && defined(_M_X64)
 #include <float.h> // For _clearfp in ~X86SavedState().
 #endif
 
@@ -625,39 +626,35 @@ namespace {
 class X86SavedState : public ExegesisTarget::SavedState {
 public:
   X86SavedState() {
-#ifdef __x86_64__
-# if defined(_MSC_VER)
+#if defined(_MSC_VER) && defined(_M_X64)
     _fxsave64(FPState);
     Eflags = __readeflags();
-# elif defined(__GNUC__)
+#elif defined(__GNUC__) && defined(__x86_64__)
     __builtin_ia32_fxsave64(FPState);
     Eflags = __builtin_ia32_readeflags_u64();
-# endif
 #else
-    llvm_unreachable("X86 exegesis running on non-X86 target");
+    report_fatal_error("X86 exegesis running on unsupported target");
 #endif
   }
 
   ~X86SavedState() {
     // Restoring the X87 state does not flush pending exceptions, make sure
     // these exceptions are flushed now.
-#ifdef __x86_64__
-# if defined(_MSC_VER)
+#if defined(_MSC_VER) && defined(_M_X64)
     _clearfp();
     _fxrstor64(FPState);
     __writeeflags(Eflags);
-# elif defined(__GNUC__)
+#elif defined(__GNUC__) && defined(__x86_64__)
     asm volatile("fwait");
     __builtin_ia32_fxrstor64(FPState);
     __builtin_ia32_writeeflags_u64(Eflags);
-# endif
 #else
-    llvm_unreachable("X86 exegesis running on non-X86 target");
+    report_fatal_error("X86 exegesis running on unsupported target");
 #endif
   }
 
 private:
-#ifdef __x86_64__
+#if defined(__x86_64__) || defined(_M_X64)
   alignas(16) char FPState[512];
   uint64_t Eflags;
 #endif
@@ -767,7 +764,7 @@ class ExegesisX86Target : public ExegesisTarget {
       // If the kernel supports it, the hardware still may not have it.
       return X86LbrCounter::checkLbrSupport();
 #else
-    llvm_unreachable("Running X86 exegesis on non-X86 target");
+    report_fatal_error("Running X86 exegesis on unsupported target");
 #endif
 #endif
     return llvm::make_error<llvm::StringError>(


        


More information about the llvm-commits mailing list