Skip to content

Conversation

@slinder1
Copy link
Contributor

@slinder1 slinder1 commented Nov 4, 2025

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.

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.
Copy link
Contributor Author

slinder1 commented Nov 4, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@slinder1 slinder1 requested review from arsenm, epilk and kzhuravl November 4, 2025 23:17
@slinder1 slinder1 marked this pull request as ready for review November 4, 2025 23:17
@llvmbot llvmbot added clang Clang issues not falling into any other category backend:AMDGPU clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels Nov 4, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 4, 2025

@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-backend-amdgpu

Author: Scott Linder (slinder1)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/166464.diff

2 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/Gnu.cpp (+1)
  • (added) clang/test/Driver/amdgpu-unwind.cl (+26)
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index 7616076847a2c..51f9ee0de5797 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -3032,6 +3032,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={{.*}}"

@llvmbot
Copy link
Member

llvmbot commented Nov 4, 2025

@llvm/pr-subscribers-clang

Author: Scott Linder (slinder1)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/166464.diff

2 Files Affected:

  • (modified) clang/lib/Driver/ToolChains/Gnu.cpp (+1)
  • (added) clang/test/Driver/amdgpu-unwind.cl (+26)
diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp
index 7616076847a2c..51f9ee0de5797 100644
--- a/clang/lib/Driver/ToolChains/Gnu.cpp
+++ b/clang/lib/Driver/ToolChains/Gnu.cpp
@@ -3032,6 +3032,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={{.*}}"

@arsenm
Copy link
Contributor

arsenm commented Nov 4, 2025

To avoid codegen changes when enabling debug-info

Don't really understand how this is connected to this; that's just a general bug. What does this actually do in the backend?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend:AMDGPU clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants