[Driver] Allow XRay for more architectures on ELF systems
authorFangrui Song <i@maskray.me>
Wed, 21 Jun 2023 03:41:54 +0000 (20:41 -0700)
committerFangrui Song <i@maskray.me>
Wed, 21 Jun 2023 03:41:54 +0000 (20:41 -0700)
Codegen OS-agnostic for ELF and the runtime is mostly OS-agnostic. It
seems unnecessary to make restriction.

While here, rewrite test/Driver/XRay/xray-instrument*.c to be more conventional:
specify --target= explicitly instead of relying on the configured default target
(which needs `REQUIRES:`).

I am not sure enumerating every supported architecture is useful, so we just test a few.

clang/lib/Driver/XRayArgs.cpp
clang/test/Driver/XRay/xray-instrument-cpu.c [deleted file]
clang/test/Driver/XRay/xray-instrument-macos.c [deleted file]
clang/test/Driver/XRay/xray-instrument-os.c [deleted file]
clang/test/Driver/XRay/xray-instrument.c [new file with mode: 0644]

index 9a4b285..427c4ce 100644 (file)
@@ -31,7 +31,12 @@ XRayArgs::XRayArgs(const ToolChain &TC, const ArgList &Args) {
                     options::OPT_fno_xray_instrument, false))
     return;
   XRayInstrument = Args.getLastArg(options::OPT_fxray_instrument);
-  if (Triple.getOS() == llvm::Triple::Linux) {
+  if (Triple.isMacOSX()) {
+    if (Triple.getArch() != llvm::Triple::x86_64) {
+      D.Diag(diag::err_drv_unsupported_opt_for_target)
+          << XRayInstrument->getSpelling() << Triple.str();
+    }
+  } else if (Triple.isOSBinFormatELF()) {
     switch (Triple.getArch()) {
     case llvm::Triple::x86_64:
     case llvm::Triple::arm:
@@ -47,21 +52,6 @@ XRayArgs::XRayArgs(const ToolChain &TC, const ArgList &Args) {
       D.Diag(diag::err_drv_unsupported_opt_for_target)
           << XRayInstrument->getSpelling() << Triple.str();
     }
-  } else if (Triple.isOSFreeBSD() || Triple.isOSOpenBSD() ||
-             Triple.isOSNetBSD() || Triple.isMacOSX()) {
-    if (Triple.getArch() != llvm::Triple::x86_64) {
-      D.Diag(diag::err_drv_unsupported_opt_for_target)
-          << XRayInstrument->getSpelling() << Triple.str();
-    }
-  } else if (Triple.getOS() == llvm::Triple::Fuchsia) {
-    switch (Triple.getArch()) {
-    case llvm::Triple::x86_64:
-    case llvm::Triple::aarch64:
-      break;
-    default:
-      D.Diag(diag::err_drv_unsupported_opt_for_target)
-          << XRayInstrument->getSpelling() << Triple.str();
-    }
   } else {
     D.Diag(diag::err_drv_unsupported_opt_for_target)
         << XRayInstrument->getSpelling() << Triple.str();
diff --git a/clang/test/Driver/XRay/xray-instrument-cpu.c b/clang/test/Driver/XRay/xray-instrument-cpu.c
deleted file mode 100644 (file)
index a8bc2a6..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-// RUN: not %clang -o /dev/null -v -fxray-instrument -c %s
-// XFAIL: target={{(amd64|x86_64|x86_64h|powerpc64le)-.*}}
-// XFAIL: target={{(arm|aarch64|arm64|mips|mipsel|mips64|mips64el)-.*}}
-// REQUIRES: linux
-typedef int a;
diff --git a/clang/test/Driver/XRay/xray-instrument-macos.c b/clang/test/Driver/XRay/xray-instrument-macos.c
deleted file mode 100644 (file)
index ce68345..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-// RUN: %clang -o /dev/null -v -fxray-instrument -target x86_64-apple-macos10.11 -c %s
-// RUN: %clang -o /dev/null -v -fxray-instrument -target x86_64-apple-darwin15 -c %s
-// REQUIRES: x86_64 || x86_64h
-typedef int a;
diff --git a/clang/test/Driver/XRay/xray-instrument-os.c b/clang/test/Driver/XRay/xray-instrument-os.c
deleted file mode 100644 (file)
index 7a4f1c1..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-// RUN: not %clang -o /dev/null -v -fxray-instrument -c %s
-// XFAIL: target={{.*-(linux|freebsd).*}}, target=x86_64-apple-{{(darwin|macos).*}}
-// REQUIRES: target={{(amd64|x86_64|x86_64h|arm|aarch64|arm64)-.*}}
-typedef int a;
diff --git a/clang/test/Driver/XRay/xray-instrument.c b/clang/test/Driver/XRay/xray-instrument.c
new file mode 100644 (file)
index 0000000..4304184
--- /dev/null
@@ -0,0 +1,8 @@
+// RUN: %clang -### --target=aarch64-pc-freebsd -fxray-instrument -c %s -o /dev/null 2>&1 | FileCheck %s
+// RUN: %clang -### --target=x86_64-apple-darwin -fxray-instrument -c %s -o /dev/null 2>&1 | FileCheck %s
+// RUN: %clang -### --target=x86_64-pc-windows -fxray-instrument -c %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=ERR
+
+// CHECK: "-cc1" {{.*}}"-fxray-instrument"
+// ERR:   error: unsupported option '-fxray-instrument' for target
+
+typedef int a;