https://github.com/jhuber6 created 
https://github.com/llvm/llvm-project/pull/175998

Summary:
This does three things:
1. Allows address_space<0>, this is not a no-op currently as it has real
   type checking signficange. The SPIR-V backend also does not currently
   use `0` as a generic address space.
2. Allows parsing address space pointers inside vectors, this required
   parsing the correct closing bracket instead of the first found
3. Adds the two missing AMDGPU builtin types.

Split off from https://github.com/llvm/llvm-project/pull/175873


>From 06ab45e584388dfe59b6b319123e3d85c3c85324 Mon Sep 17 00:00:00 2001
From: Joseph Huber <[email protected]>
Date: Wed, 14 Jan 2026 11:22:53 -0600
Subject: [PATCH] [Clang] Update target parser for address spaces for AMDGPU

Summary:
This does three things:
1. Allows address_space<0>, this is not a no-op currently as it has real
   type checking signficange. The SPIR-V backend also does not currently
   use `0` as a generic address space.
2. Allows parsing address space pointers inside vectors, this required
   parsing the correct closing bracket instead of the first found
3. Adds the two missing AMDGPU builtin types.

Split off from https://github.com/llvm/llvm-project/pull/175873
---
 .../target-builtins-prototype-parser.td         |  6 ++++++
 clang/utils/TableGen/ClangBuiltinsEmitter.cpp   | 17 ++++++++++++++---
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/clang/test/TableGen/target-builtins-prototype-parser.td 
b/clang/test/TableGen/target-builtins-prototype-parser.td
index 451f1a18b8ad0..1cd40444e35a0 100644
--- a/clang/test/TableGen/target-builtins-prototype-parser.td
+++ b/clang/test/TableGen/target-builtins-prototype-parser.td
@@ -63,6 +63,12 @@ def : Builtin {
   let Spellings = ["__builtin_09"];
 }
 
+def : Builtin {
+// CHECK: Builtin::Info{{.*}} __builtin_10 {{.*}} /* V2i*0 */
+  let Prototype = "_Vector<2, int address_space<0> *>()";
+  let Spellings = ["__builtin_10"];
+}
+
 #ifdef ERROR_EXPECTED_LANES
 def : Builtin {
 // ERROR_EXPECTED_LANES: :[[# @LINE + 1]]:7: error: Expected number of lanes 
after '_ExtVector<'
diff --git a/clang/utils/TableGen/ClangBuiltinsEmitter.cpp 
b/clang/utils/TableGen/ClangBuiltinsEmitter.cpp
index 9b6dd37c7a4a9..fb089a811ef92 100644
--- a/clang/utils/TableGen/ClangBuiltinsEmitter.cpp
+++ b/clang/utils/TableGen/ClangBuiltinsEmitter.cpp
@@ -200,7 +200,18 @@ class PrototypeParser {
       // we cannot have nested _ExtVector.
       if (Current.starts_with("_ExtVector<") ||
           Current.starts_with("_Vector<")) {
-        const size_t EndTemplate = Current.find('>', 0);
+        size_t Pos = Current.find('<');
+        int Depth = 1;
+
+        // There may be a nested address_space<...> modifier on the type.
+        while (Depth > 0 && ++Pos < Current.size()) {
+          if (Current[Pos] == '<')
+            ++Depth;
+          else if (Current[Pos] == '>')
+            --Depth;
+        }
+
+        const size_t EndTemplate = Pos;
         ParseType(Current.substr(0, EndTemplate + 1));
         // Move the prototype beyond _ExtVector<...>
         I += EndTemplate + 1;
@@ -248,8 +259,6 @@ class PrototypeParser {
       if (ArgStr.getAsInteger(10, Number))
         PrintFatalError(
             Loc, "Expected an integer argument to the address_space 
qualifier");
-      if (Number == 0)
-        PrintFatalError(Loc, "No need for a qualifier for address space `0`");
       return Number;
     };
 
@@ -331,6 +340,8 @@ class PrototypeParser {
                                .Case("__float128", "LLd")
                                .Case("__fp16", "h")
                                .Case("__hlsl_resource_t", "Qr")
+                               .Case("__amdgpu_buffer_rsrc_t", "Qb")
+                               .Case("__amdgpu_texture_t", "Qt")
                                .Case("__int128_t", "LLLi")
                                .Case("_Float16", "x")
                                .Case("__bf16", "y")

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

Reply via email to