[clang] [llvm] [HLSL][DXIL][SPIRV] WavePrefixSum intrinsic support (PR #167946)

via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 20 05:30:41 PST 2025


================
@@ -49,6 +49,33 @@
     }                                                                          \
   }
 
+// A function generator macro for picking the right intrinsic for the target
+// backend given IsUnsigned boolean condition. If IsUnsigned == true, it calls
+// getUnsignedIntrinsicVariant(IID) to retrieve the unsigned variant of the
+// intrinsic else the regular intrinsic is returned. (NOTE:
+// getUnsignedIntrinsicVariant returns IID itself if there is no unsigned
+// variant).
+#define GENERATE_HLSL_INTRINSIC_FUNCTION_SELECT_UNSIGNED(FunctionName,         \
+                                                         IntrinsicPostfix)     \
+  llvm::Intrinsic::ID get##FunctionName##Intrinsic(bool IsUnsigned) {          \
+    llvm::Triple::ArchType Arch = getArch();                                   \
+    switch (Arch) {                                                            \
+    case llvm::Triple::dxil: {                                                 \
+      static constexpr llvm::Intrinsic::ID IID =                               \
+          llvm::Intrinsic::dx_##IntrinsicPostfix;                              \
+      return IsUnsigned ? getUnsignedIntrinsicVariant(IID) : IID;              \
+    }                                                                          \
+    case llvm::Triple::spirv: {                                                \
+      static constexpr llvm::Intrinsic::ID IID =                               \
+          llvm::Intrinsic::spv_##IntrinsicPostfix;                             \
+      return IsUnsigned ? getUnsignedIntrinsicVariant(IID) : IID;              \
+    }                                                                          \
+    default:                                                                   \
+      llvm_unreachable("Intrinsic " #IntrinsicPostfix                          \
+                       " not supported by target architecture");               \
+    }                                                                          \
+  }
----------------
kcloudy0717 wrote:

Will revert the macro change and use the same approach as dot product intrinsics.

https://github.com/llvm/llvm-project/pull/167946


More information about the cfe-commits mailing list