[llvm] [SPIR-V] Replace isPipeOrAddressSpaceCastBI hardcoded list with table lookup (PR #207147)
Arseniy Obolenskiy via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 6 01:58:24 PDT 2026
https://github.com/aobolensk updated https://github.com/llvm/llvm-project/pull/207147
>From 8ca6cfd89be951a2cc52d2d4a9737481e5bf6f65 Mon Sep 17 00:00:00 2001
From: Arseniy Obolenskiy <arseniy.obolenskiy at amd.com>
Date: Thu, 2 Jul 2026 11:25:00 +0200
Subject: [PATCH 1/2] [SPIR-V] Replace isPipeOrAddressSpaceCastBI hardcoded
list with table lookup
---
llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp | 4 ++++
llvm/lib/Target/SPIRV/SPIRVBuiltins.h | 3 +++
llvm/lib/Target/SPIRV/SPIRVBuiltins.td | 2 ++
llvm/lib/Target/SPIRV/SPIRVUtils.cpp | 29 ++-----------------------
4 files changed, 11 insertions(+), 27 deletions(-)
diff --git a/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp b/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
index f97e0060c67e4..d7adc5e108172 100644
--- a/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
@@ -3984,5 +3984,9 @@ lowerBuiltinType(const Type *OpaqueType,
return TargetType;
}
+
+bool isPipeOrAddressSpaceCastBuiltin(StringRef Name) {
+ return lookupBuiltin(Name, OpenCL_std) != nullptr;
+}
} // namespace SPIRV
} // namespace llvm
diff --git a/llvm/lib/Target/SPIRV/SPIRVBuiltins.h b/llvm/lib/Target/SPIRV/SPIRVBuiltins.h
index 81a6cc697ead7..88afb38a7c5aa 100644
--- a/llvm/lib/Target/SPIRV/SPIRVBuiltins.h
+++ b/llvm/lib/Target/SPIRV/SPIRVBuiltins.h
@@ -83,6 +83,9 @@ SPIRVTypeInst lowerBuiltinType(const Type *Type,
AccessQualifier::AccessQualifier AccessQual,
MachineIRBuilder &MIRBuilder,
SPIRVGlobalRegistry *GR);
+
+/// Returns true if \p Name is a pipe or address-space-cast OpenCL builtin.
+bool isPipeOrAddressSpaceCastBuiltin(StringRef Name);
} // namespace SPIRV
} // namespace llvm
#endif // LLVM_LIB_TARGET_SPIRV_SPIRVBUILTINS_H
diff --git a/llvm/lib/Target/SPIRV/SPIRVBuiltins.td b/llvm/lib/Target/SPIRV/SPIRVBuiltins.td
index 64d5695ef2167..d8aa8d63f921f 100644
--- a/llvm/lib/Target/SPIRV/SPIRVBuiltins.td
+++ b/llvm/lib/Target/SPIRV/SPIRVBuiltins.td
@@ -1256,6 +1256,8 @@ defm : DemangledNativeBuiltin<"clock_read_hilo_sub_group", OpenCL_std, KernelClo
//SPV_ALTERA_blocking_pipes
defm : DemangledNativeBuiltin<"__spirv_WritePipeBlockingINTEL", OpenCL_std, BlockingPipes, 0, 0, OpWritePipeBlockingALTERA>;
defm : DemangledNativeBuiltin<"__spirv_ReadPipeBlockingINTEL", OpenCL_std, BlockingPipes, 0, 0, OpReadPipeBlockingALTERA>;
+defm : DemangledNativeBuiltin<"__read_pipe_2_bl", OpenCL_std, BlockingPipes, 4, 4, OpReadPipeBlockingALTERA>;
+defm : DemangledNativeBuiltin<"__write_pipe_2_bl", OpenCL_std, BlockingPipes, 4, 4, OpWritePipeBlockingALTERA>;
defm : DemangledNativeBuiltin<"__spirv_ReadClockKHR", OpenCL_std, KernelClock, 1, 1, OpReadClockKHR>;
//SPV_ALTERA_arbitrary_precision_fixed_point
diff --git a/llvm/lib/Target/SPIRV/SPIRVUtils.cpp b/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
index 23998deadc7f4..ecb095b5f09cf 100644
--- a/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVUtils.cpp
@@ -13,6 +13,7 @@
#include "SPIRVUtils.h"
#include "MCTargetDesc/SPIRVBaseInfo.h"
#include "SPIRV.h"
+#include "SPIRVBuiltins.h"
#include "SPIRVGlobalRegistry.h"
#include "SPIRVInstrInfo.h"
#include "SPIRVSubtarget.h"
@@ -535,32 +536,6 @@ Type *getMDOperandAsType(const MDNode *N, unsigned I) {
return toTypedPointer(ElementTy);
}
-// The set of names is borrowed from the SPIR-V translator.
-// TODO: may be implemented in SPIRVBuiltins.td.
-static bool isPipeOrAddressSpaceCastBI(const StringRef MangledName) {
- return MangledName == "write_pipe_2" || MangledName == "read_pipe_2" ||
- MangledName == "write_pipe_2_bl" || MangledName == "read_pipe_2_bl" ||
- MangledName == "write_pipe_4" || MangledName == "read_pipe_4" ||
- MangledName == "reserve_write_pipe" ||
- MangledName == "reserve_read_pipe" ||
- MangledName == "commit_write_pipe" ||
- MangledName == "commit_read_pipe" ||
- MangledName == "work_group_reserve_write_pipe" ||
- MangledName == "work_group_reserve_read_pipe" ||
- MangledName == "work_group_commit_write_pipe" ||
- MangledName == "work_group_commit_read_pipe" ||
- MangledName == "get_pipe_num_packets_ro" ||
- MangledName == "get_pipe_max_packets_ro" ||
- MangledName == "get_pipe_num_packets_wo" ||
- MangledName == "get_pipe_max_packets_wo" ||
- MangledName == "sub_group_reserve_write_pipe" ||
- MangledName == "sub_group_reserve_read_pipe" ||
- MangledName == "sub_group_commit_write_pipe" ||
- MangledName == "sub_group_commit_read_pipe" ||
- MangledName == "to_global" || MangledName == "to_local" ||
- MangledName == "to_private";
-}
-
static bool isEnqueueKernelBI(const StringRef MangledName) {
return MangledName == "__enqueue_kernel_basic" ||
MangledName == "__enqueue_kernel_basic_events" ||
@@ -580,7 +555,7 @@ static bool isNonMangledOCLBuiltin(StringRef Name) {
return false;
return isEnqueueKernelBI(Name) || isKernelQueryBI(Name) ||
- isPipeOrAddressSpaceCastBI(Name.drop_front(2)) ||
+ SPIRV::isPipeOrAddressSpaceCastBuiltin(Name) ||
Name == "__translate_sampler_initializer";
}
>From 1a48ff20fd7835806236882dab9624c383368324 Mon Sep 17 00:00:00 2001
From: Arseniy Obolenskiy <arseniy.obolenskiy at amd.com>
Date: Mon, 6 Jul 2026 10:58:13 +0200
Subject: [PATCH 2/2] add builtin group checks
---
llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp b/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
index d7adc5e108172..6b1abe326994a 100644
--- a/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
@@ -3986,7 +3986,11 @@ lowerBuiltinType(const Type *OpaqueType,
}
bool isPipeOrAddressSpaceCastBuiltin(StringRef Name) {
- return lookupBuiltin(Name, OpenCL_std) != nullptr;
+ const DemangledBuiltin *Builtin = lookupBuiltin(Name, OpenCL_std);
+ if (!Builtin)
+ return false;
+ return Builtin->Group == Pipe || Builtin->Group == CastToPtr ||
+ Builtin->Group == BlockingPipes;
}
} // namespace SPIRV
} // namespace llvm
More information about the llvm-commits
mailing list