[clang] [llvm] [PGO][Offload] Disable PGO on NVPTX (PR #133522)

Ethan Luis McDonough via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 28 14:19:15 PDT 2025


https://github.com/EthanLuisMcDonough created https://github.com/llvm/llvm-project/pull/133522

None

>From d21330ea2a3d2cd7ea035361e239bb3da16fbb9f Mon Sep 17 00:00:00 2001
From: Ethan Luis McDonough <ethanluismcdonough at gmail.com>
Date: Fri, 28 Mar 2025 16:17:44 -0500
Subject: [PATCH] [PGO][Offload] Disable PGO on NVPTX

---
 clang/lib/Driver/ToolChains/Clang.cpp         |  4 ++-
 clang/test/Driver/cuda-no-pgo-or-coverage.cu  | 33 +++++++++++++++++++
 .../malformed-ptr-to-counter-array.test       |  2 +-
 offload/test/offloading/gpupgo/pgo1.c         |  2 +-
 offload/test/offloading/gpupgo/pgo2.c         |  2 +-
 5 files changed, 39 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/Driver/cuda-no-pgo-or-coverage.cu

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 26fa234dd4e9b..5f45cf0865b9e 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6397,7 +6397,9 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
   Args.AddLastArg(CmdArgs, options::OPT_fconvergent_functions,
                   options::OPT_fno_convergent_functions);
 
-  addPGOAndCoverageFlags(TC, C, JA, Output, Args, SanitizeArgs, CmdArgs);
+  // NVPTX doesn't support PGO or coverage
+  if (!Triple.isNVPTX())
+    addPGOAndCoverageFlags(TC, C, JA, Output, Args, SanitizeArgs, CmdArgs);
 
   Args.AddLastArg(CmdArgs, options::OPT_fclang_abi_compat_EQ);
 
diff --git a/clang/test/Driver/cuda-no-pgo-or-coverage.cu b/clang/test/Driver/cuda-no-pgo-or-coverage.cu
new file mode 100644
index 0000000000000..b84587e1e182b
--- /dev/null
+++ b/clang/test/Driver/cuda-no-pgo-or-coverage.cu
@@ -0,0 +1,33 @@
+// Check that profiling/coverage arguments doen't get passed down to device-side
+// compilation.
+//
+//
+// XRUN: not %clang -### --target=x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 \
+// XRUN:   -fprofile-generate %s 2>&1 | \
+// XRUN:   FileCheck --check-prefixes=CHECK,PROF %s
+//
+// RUN: not %clang -### --target=x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 \
+// RUN:   -fprofile-instr-generate %s 2>&1 | \
+// RUN:   FileCheck --check-prefixes=CHECK,PROF %s
+//
+// RUN: not %clang -### --target=x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 \
+// RUN:   -coverage %s 2>&1 | \
+// RUN:   FileCheck --check-prefixes=CHECK,GCOV %s
+//
+// RUN: not %clang -### --target=x86_64-linux-gnu -c --cuda-gpu-arch=sm_20 \
+// RUN:   -ftest-coverage %s 2>&1 | \
+// RUN:   FileCheck --check-prefixes=CHECK,GCOV %s
+//
+// RUN: not %clang -### --target=x86_64-linux-gnu -c --cuda-gpu-arch=sm_20   \
+// RUN:   -fprofile-instr-generate -fcoverage-mapping %s 2>&1 | \
+// RUN:   FileCheck --check-prefixes=CHECK,PROF %s
+//
+//
+// CHECK-NOT: error: unsupported option '-fprofile
+// CHECK-NOT: error: invalid argument
+// CHECK-DAG: "-fcuda-is-device"
+// CHECK-NOT: "-f{{[^"/]*coverage.*}}"
+// CHECK-NOT: "-fprofile{{[^"]*}}"
+// CHECK: "-triple" "x86_64-unknown-linux-gnu"
+// PROF:      "-fprofile{{.*}}"
+// GCOV:      "-coverage-notes-file=
diff --git a/llvm/test/tools/llvm-profdata/malformed-ptr-to-counter-array.test b/llvm/test/tools/llvm-profdata/malformed-ptr-to-counter-array.test
index 49c5ae9b0931d..83cf76f68fb63 100644
--- a/llvm/test/tools/llvm-profdata/malformed-ptr-to-counter-array.test
+++ b/llvm/test/tools/llvm-profdata/malformed-ptr-to-counter-array.test
@@ -1,7 +1,7 @@
 // Header
 //
 // INSTR_PROF_RAW_HEADER(uint64_t, Magic, __llvm_profile_get_magic())
-// INSTR_PROF_RAW_HEADER(uint64_t, Version, Version)
+// INSTR_PROF_RAW_HEADER(uint64_t, Version, __llvm_profile_get_version())
 // INSTR_PROF_RAW_HEADER(uint64_t, BinaryIdsSize, __llvm_write_binary_ids(NULL))
 // INSTR_PROF_RAW_HEADER(uint64_t, DataSize, DataSize)
 // INSTR_PROF_RAW_HEADER(uint64_t, CountersSize, CountersSize)
diff --git a/offload/test/offloading/gpupgo/pgo1.c b/offload/test/offloading/gpupgo/pgo1.c
index c8011cbae83c0..af6d8e806cd37 100644
--- a/offload/test/offloading/gpupgo/pgo1.c
+++ b/offload/test/offloading/gpupgo/pgo1.c
@@ -14,7 +14,7 @@
 // RUN:     %target_triple.%basename_t.clang.profraw | \
 // RUN:     %fcheck-generic --check-prefix="CLANG-PGO"
 
-// REQUIRES: gpu
+// REQUIRES: amdgpu
 // REQUIRES: pgo
 
 int test1(int a) { return a / 2; }
diff --git a/offload/test/offloading/gpupgo/pgo2.c b/offload/test/offloading/gpupgo/pgo2.c
index b75b0beaffdec..b67a63bc8fc3d 100644
--- a/offload/test/offloading/gpupgo/pgo2.c
+++ b/offload/test/offloading/gpupgo/pgo2.c
@@ -48,7 +48,7 @@
 // RUN:     %target_triple.%basename_t.hfdi.profraw \
 // RUN:     | %fcheck-generic --check-prefix="LLVM-DEVICE"
 
-// REQUIRES: gpu
+// REQUIRES: amdgpu
 // REQUIRES: pgo
 
 int main() {



More information about the llvm-commits mailing list