Skip to content

AMDGPU: Start using LLVMContext errors in buffer fat pointer lowering #142014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

arsenm
Copy link
Contributor

@arsenm arsenm commented May 29, 2025

Avoid using report_fatal_error. Many more uses that should be converted
in the pass remain.

Copy link
Contributor Author

arsenm commented May 29, 2025

@llvmbot
Copy link
Member

llvmbot commented May 29, 2025

@llvm/pr-subscribers-backend-amdgpu

Author: Matt Arsenault (arsenm)

Changes

Avoid using report_fatal_error. Many more uses that should be converted
in the pass remain.


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

2 Files Affected:

  • (modified) llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp (+16-7)
  • (added) llvm/test/CodeGen/AMDGPU/buffer-fat-pointer-unsupported-errors.ll (+22)
diff --git a/llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp b/llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp
index 3835f4cfceefc..0f002b016af0c 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPULowerBufferFatPointers.cpp
@@ -2430,17 +2430,26 @@ bool AMDGPULowerBufferFatPointers::run(Module &M, const TargetMachine &TM) {
   // its arguments or return types adjusted.
   SmallVector<std::pair<Function *, bool>> NeedsRemap;
 
+  LLVMContext &Ctx = M.getContext();
+
   BufferFatPtrToStructTypeMap StructTM(DL);
   BufferFatPtrToIntTypeMap IntTM(DL);
   for (const GlobalVariable &GV : M.globals()) {
-    if (GV.getAddressSpace() == AMDGPUAS::BUFFER_FAT_POINTER)
-      report_fatal_error("Global variables with a buffer fat pointer address "
-                         "space (7) are not supported");
+    if (GV.getAddressSpace() == AMDGPUAS::BUFFER_FAT_POINTER) {
+      // FIXME: Use DiagnosticInfo unsupported but it requires a Function
+      Ctx.emitError("global variables with a buffer fat pointer address "
+                    "space (7) are not supported");
+      continue;
+    }
+
     Type *VT = GV.getValueType();
-    if (VT != StructTM.remapType(VT))
-      report_fatal_error("Global variables that contain buffer fat pointers "
-                         "(address space 7 pointers) are unsupported. Use "
-                         "buffer resource pointers (address space 8) instead.");
+    if (VT != StructTM.remapType(VT)) {
+      // FIXME: Use DiagnosticInfo unsupported but it requires a Function
+      Ctx.emitError("global variables that contain buffer fat pointers "
+                    "(address space 7 pointers) are unsupported. Use "
+                    "buffer resource pointers (address space 8) instead");
+      continue;
+    }
   }
 
   {
diff --git a/llvm/test/CodeGen/AMDGPU/buffer-fat-pointer-unsupported-errors.ll b/llvm/test/CodeGen/AMDGPU/buffer-fat-pointer-unsupported-errors.ll
new file mode 100644
index 0000000000000..3fc8d73bb0536
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/buffer-fat-pointer-unsupported-errors.ll
@@ -0,0 +1,22 @@
+; RUN: split-file %s %t
+; RUN: not opt -mtriple=amdgcn-amd-amdhsa -disable-output -passes=amdgpu-lower-buffer-fat-pointers %t/contains-null-init.ll 2>&1 | FileCheck -check-prefix=ERR0 %s
+; RUN: not opt -mtriple=amdgcn-amd-amdhsa -disable-output -passes=amdgpu-lower-buffer-fat-pointers %t/contains-poison-init.ll 2>&1 | FileCheck -check-prefix=ERR1 %s
+; RUN: not opt -mtriple=amdgcn-amd-amdhsa -disable-output -passes=amdgpu-lower-buffer-fat-pointers %t/defined-gv-type.ll 2>&1 | FileCheck -check-prefix=ERR2 %s
+; RUN: not opt -mtriple=amdgcn-amd-amdhsa -disable-output -passes=amdgpu-lower-buffer-fat-pointers %t/declared-gv-type.ll 2>&1 | FileCheck -check-prefix=ERR3 %s
+
+;--- contains-null-init.ll
+; ERR0: error: global variables that contain buffer fat pointers (address space 7 pointers) are unsupported. Use buffer resource pointers (address space 8) instead
+@init_null = global ptr addrspace(7) null
+
+;--- contains-poison-init.ll
+; ERR1: error: global variables that contain buffer fat pointers (address space 7 pointers) are unsupported. Use buffer resource pointers (address space 8) instead
+@init_poison = global ptr addrspace(7) poison
+
+;--- defined-gv-type.ll
+; ERR2: error: global variables with a buffer fat pointer address space (7) are not supported
+@gv_is_addrspace_7 = addrspace(7) global i32 0
+
+;--- declared-gv-type.ll
+; ERR3: error: global variables with a buffer fat pointer address space (7) are not supported
+@extern_gv_is_addrspace_7 = external addrspace(7) global i32
+

@arsenm arsenm marked this pull request as ready for review May 29, 2025 19:15
Copy link
Contributor Author

arsenm commented May 30, 2025

Merge activity

  • May 30, 5:48 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • May 30, 5:50 AM UTC: Graphite rebased this pull request as part of a merge.
  • May 30, 5:52 AM UTC: @arsenm merged this pull request with Graphite.

Avoid using report_fatal_error. Many more uses that should be converted
in the pass remain.
@arsenm arsenm force-pushed the users/arsenm/amdgpu/start-using-context-errors-buffer-fat-pointer-lowering branch from 30a7806 to 77d99f4 Compare May 30, 2025 05:50
@arsenm arsenm merged commit 6b81483 into main May 30, 2025
5 of 9 checks passed
@arsenm arsenm deleted the users/arsenm/amdgpu/start-using-context-errors-buffer-fat-pointer-lowering branch May 30, 2025 05:52
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Jun 3, 2025
…llvm#142014)

Avoid using report_fatal_error. Many more uses that should be converted
in the pass remain.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants