Skip to content

Commit 15b31c3

Browse files
committed
[NFC] Allow target intrinsic switching to optionally be set.
1 parent c2bb056 commit 15b31c3

File tree

1 file changed

+53
-36
lines changed

1 file changed

+53
-36
lines changed

clang/lib/CodeGen/CGHLSLRuntime.h

Lines changed: 53 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,36 @@
3030
#include <optional>
3131
#include <vector>
3232

33+
#define GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT(FunctionName, \
34+
IntrinsicPostfix) \
35+
GENERATE_HLSL_INTRINSIC_FUNCTION(FunctionName, IntrinsicPostfix, 1, 1)
36+
3337
// A function generator macro for picking the right intrinsic
3438
// for the target backend
35-
#define GENERATE_HLSL_INTRINSIC_FUNCTION(FunctionName, IntrinsicPostfix) \
39+
#define GENERATE_HLSL_INTRINSIC_FUNCTION(FunctionName, IntrinsicPostfix, \
40+
IncludeDXIL, IncludeSPIRV) \
3641
llvm::Intrinsic::ID get##FunctionName##Intrinsic() { \
3742
llvm::Triple::ArchType Arch = getArch(); \
3843
switch (Arch) { \
39-
case llvm::Triple::dxil: \
40-
return llvm::Intrinsic::dx_##IntrinsicPostfix; \
41-
case llvm::Triple::spirv: \
42-
return llvm::Intrinsic::spv_##IntrinsicPostfix; \
44+
/* Include DXIL case only if IncludeDXIL is true */ \
45+
IF_INCLUDE(IncludeDXIL, case llvm::Triple::dxil \
46+
: return llvm::Intrinsic::dx_##IntrinsicPostfix;) \
47+
/* Include SPIRV case only if IncludeSPIRV is true */ \
48+
IF_INCLUDE(IncludeSPIRV, case llvm::Triple::spirv \
49+
: return llvm::Intrinsic::spv_##IntrinsicPostfix;) \
50+
\
4351
default: \
4452
llvm_unreachable("Intrinsic " #IntrinsicPostfix \
4553
" not supported by target architecture"); \
4654
} \
4755
}
4856

57+
#define IF_INCLUDE(Condition, Code) IF_INCLUDE_IMPL(Condition, Code)
58+
#define IF_INCLUDE_IMPL(Condition, Code) IF_INCLUDE_##Condition(Code)
59+
60+
#define IF_INCLUDE_1(Code) Code
61+
#define IF_INCLUDE_0(Code)
62+
4963
namespace llvm {
5064
class GlobalVariable;
5165
class Function;
@@ -72,37 +86,40 @@ class CGHLSLRuntime {
7286
// Start of reserved area for HLSL intrinsic getters.
7387
//===----------------------------------------------------------------------===//
7488

75-
GENERATE_HLSL_INTRINSIC_FUNCTION(All, all)
76-
GENERATE_HLSL_INTRINSIC_FUNCTION(Any, any)
77-
GENERATE_HLSL_INTRINSIC_FUNCTION(Cross, cross)
78-
GENERATE_HLSL_INTRINSIC_FUNCTION(Degrees, degrees)
79-
GENERATE_HLSL_INTRINSIC_FUNCTION(Frac, frac)
80-
GENERATE_HLSL_INTRINSIC_FUNCTION(Length, length)
81-
GENERATE_HLSL_INTRINSIC_FUNCTION(Lerp, lerp)
82-
GENERATE_HLSL_INTRINSIC_FUNCTION(Normalize, normalize)
83-
GENERATE_HLSL_INTRINSIC_FUNCTION(Rsqrt, rsqrt)
84-
GENERATE_HLSL_INTRINSIC_FUNCTION(Saturate, saturate)
85-
GENERATE_HLSL_INTRINSIC_FUNCTION(Sign, sign)
86-
GENERATE_HLSL_INTRINSIC_FUNCTION(Step, step)
87-
GENERATE_HLSL_INTRINSIC_FUNCTION(Radians, radians)
88-
GENERATE_HLSL_INTRINSIC_FUNCTION(ThreadId, thread_id)
89-
GENERATE_HLSL_INTRINSIC_FUNCTION(FDot, fdot)
90-
GENERATE_HLSL_INTRINSIC_FUNCTION(SDot, sdot)
91-
GENERATE_HLSL_INTRINSIC_FUNCTION(UDot, udot)
92-
GENERATE_HLSL_INTRINSIC_FUNCTION(Dot4AddI8Packed, dot4add_i8packed)
93-
GENERATE_HLSL_INTRINSIC_FUNCTION(Dot4AddU8Packed, dot4add_u8packed)
94-
GENERATE_HLSL_INTRINSIC_FUNCTION(WaveActiveAnyTrue, wave_any)
95-
GENERATE_HLSL_INTRINSIC_FUNCTION(WaveActiveCountBits, wave_active_countbits)
96-
GENERATE_HLSL_INTRINSIC_FUNCTION(WaveIsFirstLane, wave_is_first_lane)
97-
GENERATE_HLSL_INTRINSIC_FUNCTION(WaveReadLaneAt, wave_readlane)
98-
GENERATE_HLSL_INTRINSIC_FUNCTION(FirstBitUHigh, firstbituhigh)
99-
GENERATE_HLSL_INTRINSIC_FUNCTION(FirstBitSHigh, firstbitshigh)
100-
GENERATE_HLSL_INTRINSIC_FUNCTION(NClamp, nclamp)
101-
GENERATE_HLSL_INTRINSIC_FUNCTION(SClamp, sclamp)
102-
GENERATE_HLSL_INTRINSIC_FUNCTION(UClamp, uclamp)
103-
104-
GENERATE_HLSL_INTRINSIC_FUNCTION(CreateHandleFromBinding, handle_fromBinding)
105-
GENERATE_HLSL_INTRINSIC_FUNCTION(BufferUpdateCounter, bufferUpdateCounter)
89+
GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT(All, all)
90+
GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT(Any, any)
91+
GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT(Cross, cross)
92+
GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT(Degrees, degrees)
93+
GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT(Frac, frac)
94+
GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT(Length, length)
95+
GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT(Lerp, lerp)
96+
GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT(Normalize, normalize)
97+
GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT(Rsqrt, rsqrt)
98+
GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT(Saturate, saturate)
99+
GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT(Sign, sign)
100+
GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT(Step, step)
101+
GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT(Radians, radians)
102+
GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT(ThreadId, thread_id)
103+
GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT(FDot, fdot)
104+
GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT(SDot, sdot)
105+
GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT(UDot, udot)
106+
GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT(Dot4AddI8Packed, dot4add_i8packed)
107+
GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT(Dot4AddU8Packed, dot4add_u8packed)
108+
GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT(WaveActiveAnyTrue, wave_any)
109+
GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT(WaveActiveCountBits,
110+
wave_active_countbits)
111+
GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT(WaveIsFirstLane, wave_is_first_lane)
112+
GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT(WaveReadLaneAt, wave_readlane)
113+
GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT(FirstBitUHigh, firstbituhigh)
114+
GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT(FirstBitSHigh, firstbitshigh)
115+
GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT(NClamp, nclamp)
116+
GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT(SClamp, sclamp)
117+
GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT(UClamp, uclamp)
118+
119+
GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT(CreateHandleFromBinding,
120+
handle_fromBinding)
121+
GENERATE_HLSL_INTRINSIC_FUNCTION_DEFAULT(BufferUpdateCounter,
122+
bufferUpdateCounter)
106123

107124
//===----------------------------------------------------------------------===//
108125
// End of reserved area for HLSL intrinsic getters.

0 commit comments

Comments
 (0)