[clang] [NFC][HLSL] Allow target intrinsic switching to optionally be set. (PR #117648)
Farzon Lotfi via cfe-commits
cfe-commits at lists.llvm.org
Mon Dec 2 12:06:24 PST 2024
================
@@ -30,22 +30,36 @@
#include <optional>
#include <vector>
+#define GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT(FunctionName, \
+ IntrinsicPostfix) \
+ GENERATE_HLSL_INTRINSIC_FUNCTION(FunctionName, IntrinsicPostfix, 1, 1)
+
// A function generator macro for picking the right intrinsic
// for the target backend
-#define GENERATE_HLSL_INTRINSIC_FUNCTION(FunctionName, IntrinsicPostfix) \
+#define GENERATE_HLSL_INTRINSIC_FUNCTION(FunctionName, IntrinsicPostfix, \
+ IncludeDXIL, IncludeSPIRV) \
llvm::Intrinsic::ID get##FunctionName##Intrinsic() { \
llvm::Triple::ArchType Arch = getArch(); \
switch (Arch) { \
- case llvm::Triple::dxil: \
- return llvm::Intrinsic::dx_##IntrinsicPostfix; \
- case llvm::Triple::spirv: \
- return llvm::Intrinsic::spv_##IntrinsicPostfix; \
+ /* Include DXIL case only if IncludeDXIL is true */ \
+ IF_INCLUDE(IncludeDXIL, case llvm::Triple::dxil \
+ : return llvm::Intrinsic::dx_##IntrinsicPostfix;) \
+ /* Include SPIRV case only if IncludeSPIRV is true */ \
+ IF_INCLUDE(IncludeSPIRV, case llvm::Triple::spirv \
+ : return llvm::Intrinsic::spv_##IntrinsicPostfix;) \
+ \
default: \
llvm_unreachable("Intrinsic " #IntrinsicPostfix \
" not supported by target architecture"); \
} \
}
+#define IF_INCLUDE(Condition, Code) IF_INCLUDE_IMPL(Condition, Code)
+#define IF_INCLUDE_IMPL(Condition, Code) IF_INCLUDE_##Condition(Code)
+
+#define IF_INCLUDE_1(Code) Code
+#define IF_INCLUDE_0(Code)
----------------
farzonl wrote:
that would mean a new macro per backend. Also the point of the macro was to make one function that could toggle between all the different target intrinsics our language supports. If we have one generate per DX or SPV that's no better than directly passing the target intrinsic id.
https://github.com/llvm/llvm-project/pull/117648
More information about the cfe-commits
mailing list