Skip to content

Commit 37b2397

Browse files
committed
[HLSL] Get intrinsics using the same approach as getWaveActiveSumIntrinsic
1 parent feced11 commit 37b2397

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

clang/lib/CodeGen/CGHLSLBuiltins.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,23 @@ static Intrinsic::ID getWaveActiveMinIntrinsic(llvm::Triple::ArchType Arch,
295295
}
296296
}
297297

298+
// Return wave active max that corresponds to the QT scalar type
299+
static Intrinsic::ID getWavePrefixSumIntrinsic(llvm::Triple::ArchType Arch,
300+
CGHLSLRuntime &RT, QualType QT) {
301+
switch (Arch) {
302+
case llvm::Triple::spirv:
303+
return Intrinsic::spv_wave_prefix_sum;
304+
case llvm::Triple::dxil: {
305+
if (QT->isUnsignedIntegerType())
306+
return Intrinsic::dx_wave_prefix_usum;
307+
return Intrinsic::dx_wave_prefix_sum;
308+
}
309+
default:
310+
llvm_unreachable("Intrinsic WavePrefixSum"
311+
" not supported by target architecture");
312+
}
313+
}
314+
298315
// Returns the mangled name for a builtin function that the SPIR-V backend
299316
// will expand into a spec Constant.
300317
static std::string getSpecConstantFunctionName(clang::QualType SpecConstantType,
@@ -866,7 +883,9 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
866883
}
867884
case Builtin::BI__builtin_hlsl_wave_prefix_sum: {
868885
Value *OpExpr = EmitScalarExpr(E->getArg(0));
869-
Intrinsic::ID IID = CGM.getHLSLRuntime().getWavePrefixSumIntrinsic();
886+
Intrinsic::ID IID = getWavePrefixSumIntrinsic(
887+
getTarget().getTriple().getArch(), CGM.getHLSLRuntime(),
888+
E->getArg(0)->getType());
870889
return EmitRuntimeCall(Intrinsic::getOrInsertDeclaration(
871890
&CGM.getModule(), IID, {OpExpr->getType()}),
872891
ArrayRef{OpExpr}, "hlsl.wave.prefix.sum");

clang/lib/CodeGen/CGHLSLRuntime.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ class CGHLSLRuntime {
144144
GENERATE_HLSL_INTRINSIC_FUNCTION(WaveIsFirstLane, wave_is_first_lane)
145145
GENERATE_HLSL_INTRINSIC_FUNCTION(WaveGetLaneCount, wave_get_lane_count)
146146
GENERATE_HLSL_INTRINSIC_FUNCTION(WaveReadLaneAt, wave_readlane)
147-
GENERATE_HLSL_INTRINSIC_FUNCTION(WavePrefixSum, wave_prefix_sum)
148147
GENERATE_HLSL_INTRINSIC_FUNCTION(FirstBitUHigh, firstbituhigh)
149148
GENERATE_HLSL_INTRINSIC_FUNCTION(FirstBitSHigh, firstbitshigh)
150149
GENERATE_HLSL_INTRINSIC_FUNCTION(FirstBitLow, firstbitlow)

0 commit comments

Comments
 (0)