[clang] 730bf8c - [Clang] Update target parser for address spaces for AMDGPU (#175998)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Jan 14 10:13:32 PST 2026
Author: Joseph Huber
Date: 2026-01-14T12:13:27-06:00
New Revision: 730bf8c89531040f9ba7687c33c4d633b742e74a
URL: https://github.com/llvm/llvm-project/commit/730bf8c89531040f9ba7687c33c4d633b742e74a
DIFF: https://github.com/llvm/llvm-project/commit/730bf8c89531040f9ba7687c33c4d633b742e74a.diff
LOG: [Clang] Update target parser for address spaces for AMDGPU (#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
Added:
Modified:
clang/test/TableGen/target-builtins-prototype-parser.td
clang/utils/TableGen/ClangBuiltinsEmitter.cpp
Removed:
################################################################################
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")
More information about the cfe-commits
mailing list