https://github.com/slinder1 updated 
https://github.com/llvm/llvm-project/pull/166464

>From 7b340a9d1911e70d4ed1d741406c06ac9d0734ad Mon Sep 17 00:00:00 2001
From: Scott Linder <[email protected]>
Date: Tue, 4 Nov 2025 17:59:54 +0000
Subject: [PATCH] [Clang] Default to async unwind tables for amdgcn

To avoid codegen changes when enabling debug-info (see
https://bugs.llvm.org/show_bug.cgi?id=37240) we want to
enable unwind tables by default.

There is some pessimization in post-prologepilog scheduling, and a
general solution to the problem of CFI_INSTRUCTION-as-scheduling-barrier
should be explored.
---
 clang/lib/Driver/ToolChains/Gnu.cpp |  1 +
 clang/test/Driver/amdgpu-unwind.cl  | 26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+)
 create mode 100644 clang/test/Driver/amdgpu-unwind.cl

diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp 
b/clang/lib/Driver/ToolChains/Gnu.cpp
index 1bfcd1f4f3a7c..779983f12d3c8 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -3030,6 +3030,7 @@ Generic_GCC::getDefaultUnwindTableLevel(const ArgList 
&Args) const {
   switch (getArch()) {
   case llvm::Triple::aarch64:
   case llvm::Triple::aarch64_be:
+  case llvm::Triple::amdgcn:
   case llvm::Triple::ppc:
   case llvm::Triple::ppcle:
   case llvm::Triple::ppc64:
diff --git a/clang/test/Driver/amdgpu-unwind.cl 
b/clang/test/Driver/amdgpu-unwind.cl
new file mode 100644
index 0000000000000..611d9735b15a4
--- /dev/null
+++ b/clang/test/Driver/amdgpu-unwind.cl
@@ -0,0 +1,26 @@
+// REQUIRES: amdgpu-registered-target
+
+// Default options
+// RUN: %clang -### -x cl -target amdgcn-amd-amdhsa -c -emit-llvm 
--no-offloadlib %s 2>&1 | FileCheck -check-prefix=ASYNC-TABLES %s
+// RUN: %clang -### -x hip --offload-arch=gfx90a --offload-device-only 
--no-offloadlib -c -emit-llvm %s 2>&1 | FileCheck -check-prefix=ASYNC-TABLES  %s
+// RUN: %clang -### -fopenmp --offload-arch=gfx90a --offload-device-only 
--no-offloadlib -c -emit-llvm %s 2>&1 | FileCheck -check-prefix=ASYNC-TABLES  %s
+
+// Explicitly enable sync-tables (somewhat surprisingly this is still 
preempted by the default-on async tables)
+// RUN: %clang -### -x cl -target amdgcn-amd-amdhsa -c -emit-llvm 
--no-offloadlib -funwind-tables %s 2>&1 | FileCheck -check-prefix=ASYNC-TABLES 
%s
+// RUN: %clang -### -x hip --offload-arch=gfx90a --offload-device-only 
--no-offloadlib -c -emit-llvm -funwind-tables %s 2>&1 | FileCheck 
-check-prefix=ASYNC-TABLES  %s
+// RUN: %clang -### -fopenmp --offload-arch=gfx90a --offload-device-only 
--no-offloadlib -c -emit-llvm -funwind-tables %s 2>&1 | FileCheck 
-check-prefix=ASYNC-TABLES  %s
+
+// Explicitly enable sync-tables and surpress default async-tables
+// RUN: %clang -### -x cl -target amdgcn-amd-amdhsa -c -emit-llvm 
--no-offloadlib -funwind-tables -fno-asynchronous-unwind-tables %s 2>&1 | 
FileCheck -check-prefix=SYNC-TABLES %s
+// RUN: %clang -### -x hip --offload-arch=gfx90a --offload-device-only 
--no-offloadlib -c -emit-llvm -funwind-tables -fno-asynchronous-unwind-tables 
%s 2>&1 | FileCheck -check-prefix=SYNC-TABLES  %s
+// RUN: %clang -### -fopenmp --offload-arch=gfx90a --offload-device-only 
--no-offloadlib -c -emit-llvm -funwind-tables -fno-asynchronous-unwind-tables 
%s 2>&1 | FileCheck -check-prefix=SYNC-TABLES  %s
+
+// Suppress the default async-tables
+// RUN: %clang -### -x cl -target amdgcn-amd-amdhsa -c -emit-llvm 
--no-offloadlib -fno-asynchronous-unwind-tables %s 2>&1 | FileCheck 
-check-prefix=NO-TABLES %s
+// RUN: %clang -### -x hip --offload-arch=gfx90a --offload-device-only 
--no-offloadlib -c -emit-llvm -fno-asynchronous-unwind-tables %s 2>&1 | 
FileCheck -check-prefix=NO-TABLES  %s
+// RUN: %clang -### -fopenmp --offload-arch=gfx90a --offload-device-only 
--no-offloadlib -c -emit-llvm -fno-asynchronous-unwind-tables %s 2>&1 | 
FileCheck -check-prefix=NO-TABLES  %s
+
+
+// ASYNC-TABLES: "-triple" "amdgcn-amd-amdhsa" {{.*}} "-funwind-tables=2"
+// SYNC-TABLES: "-triple" "amdgcn-amd-amdhsa" {{.*}} "-funwind-tables=1"
+// NO-TABLES-NOT: "-triple" "amdgcn-amd-amdhsa" {{.*}} "-funwind-tables={{.*}}"

_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to