[llvm] b0623c0 - [SPIR-V] Replace isPipeOrAddressSpaceCastBI hardcoded list with table lookup (#207147)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 6 05:08:21 PDT 2026
Author: Arseniy Obolenskiy
Date: 2026-07-06T14:08:17+02:00
New Revision: b0623c024c2d3a2c26be1778c224c1678f925976
URL: https://github.com/llvm/llvm-project/commit/b0623c024c2d3a2c26be1778c224c1678f925976
DIFF: https://github.com/llvm/llvm-project/commit/b0623c024c2d3a2c26be1778c224c1678f925976.diff
LOG: [SPIR-V] Replace isPipeOrAddressSpaceCastBI hardcoded list with table lookup (#207147)
Added:
Modified:
llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
llvm/lib/Target/SPIRV/SPIRVBuiltins.h
llvm/lib/Target/SPIRV/SPIRVBuiltins.td
llvm/lib/Target/SPIRV/SPIRVUtils.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp b/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
index f97e0060c67e4..6b1abe326994a 100644
--- a/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp
@@ -3984,5 +3984,13 @@ lowerBuiltinType(const Type *OpaqueType,
return TargetType;
}
+
+bool isPipeOrAddressSpaceCastBuiltin(StringRef Name) {
+ 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
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";
}
More information about the llvm-commits
mailing list