Skip to content

Commit feced11

Browse files
committed
[HLSL] Revert NFC refactor done in the previous commit
1 parent 1edeecc commit feced11

File tree

3 files changed

+69
-77
lines changed

3 files changed

+69
-77
lines changed

clang/lib/CodeGen/CGHLSLBuiltins.cpp

Lines changed: 68 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,61 @@ static Intrinsic::ID getFirstBitHighIntrinsic(CGHLSLRuntime &RT, QualType QT) {
240240
return RT.getFirstBitUHighIntrinsic();
241241
}
242242

243+
// Return wave active sum that corresponds to the QT scalar type
244+
static Intrinsic::ID getWaveActiveSumIntrinsic(llvm::Triple::ArchType Arch,
245+
CGHLSLRuntime &RT, QualType QT) {
246+
switch (Arch) {
247+
case llvm::Triple::spirv:
248+
return Intrinsic::spv_wave_reduce_sum;
249+
case llvm::Triple::dxil: {
250+
if (QT->isUnsignedIntegerType())
251+
return Intrinsic::dx_wave_reduce_usum;
252+
return Intrinsic::dx_wave_reduce_sum;
253+
}
254+
default:
255+
llvm_unreachable("Intrinsic WaveActiveSum"
256+
" not supported by target architecture");
257+
}
258+
}
259+
260+
// Return wave active max that corresponds to the QT scalar type
261+
static Intrinsic::ID getWaveActiveMaxIntrinsic(llvm::Triple::ArchType Arch,
262+
CGHLSLRuntime &RT, QualType QT) {
263+
switch (Arch) {
264+
case llvm::Triple::spirv:
265+
if (QT->isUnsignedIntegerType())
266+
return Intrinsic::spv_wave_reduce_umax;
267+
return Intrinsic::spv_wave_reduce_max;
268+
case llvm::Triple::dxil: {
269+
if (QT->isUnsignedIntegerType())
270+
return Intrinsic::dx_wave_reduce_umax;
271+
return Intrinsic::dx_wave_reduce_max;
272+
}
273+
default:
274+
llvm_unreachable("Intrinsic WaveActiveMax"
275+
" not supported by target architecture");
276+
}
277+
}
278+
279+
// Return wave active min that corresponds to the QT scalar type
280+
static Intrinsic::ID getWaveActiveMinIntrinsic(llvm::Triple::ArchType Arch,
281+
CGHLSLRuntime &RT, QualType QT) {
282+
switch (Arch) {
283+
case llvm::Triple::spirv:
284+
if (QT->isUnsignedIntegerType())
285+
return Intrinsic::spv_wave_reduce_umin;
286+
return Intrinsic::spv_wave_reduce_min;
287+
case llvm::Triple::dxil: {
288+
if (QT->isUnsignedIntegerType())
289+
return Intrinsic::dx_wave_reduce_umin;
290+
return Intrinsic::dx_wave_reduce_min;
291+
}
292+
default:
293+
llvm_unreachable("Intrinsic WaveActiveMin"
294+
" not supported by target architecture");
295+
}
296+
}
297+
243298
// Returns the mangled name for a builtin function that the SPIR-V backend
244299
// will expand into a spec Constant.
245300
static std::string getSpecConstantFunctionName(clang::QualType SpecConstantType,
@@ -739,33 +794,33 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
739794
ArrayRef{OpExpr});
740795
}
741796
case Builtin::BI__builtin_hlsl_wave_active_sum: {
742-
// Due to the use of variadic arguments, explicitly retrieve argument
797+
// Due to the use of variadic arguments, explicitly retreive argument
743798
Value *OpExpr = EmitScalarExpr(E->getArg(0));
744-
QualType QT = E->getArg(0)->getType();
745-
Intrinsic::ID IID = CGM.getHLSLRuntime().getWaveActiveSumIntrinsic(
746-
QT->isUnsignedIntegerType());
799+
Intrinsic::ID IID = getWaveActiveSumIntrinsic(
800+
getTarget().getTriple().getArch(), CGM.getHLSLRuntime(),
801+
E->getArg(0)->getType());
747802

748803
return EmitRuntimeCall(Intrinsic::getOrInsertDeclaration(
749804
&CGM.getModule(), IID, {OpExpr->getType()}),
750805
ArrayRef{OpExpr}, "hlsl.wave.active.sum");
751806
}
752807
case Builtin::BI__builtin_hlsl_wave_active_max: {
753-
// Due to the use of variadic arguments, explicitly retrieve argument
808+
// Due to the use of variadic arguments, explicitly retreive argument
754809
Value *OpExpr = EmitScalarExpr(E->getArg(0));
755-
QualType QT = E->getArg(0)->getType();
756-
Intrinsic::ID IID = CGM.getHLSLRuntime().getWaveActiveMaxIntrinsic(
757-
QT->isUnsignedIntegerType());
810+
Intrinsic::ID IID = getWaveActiveMaxIntrinsic(
811+
getTarget().getTriple().getArch(), CGM.getHLSLRuntime(),
812+
E->getArg(0)->getType());
758813

759814
return EmitRuntimeCall(Intrinsic::getOrInsertDeclaration(
760815
&CGM.getModule(), IID, {OpExpr->getType()}),
761816
ArrayRef{OpExpr}, "hlsl.wave.active.max");
762817
}
763818
case Builtin::BI__builtin_hlsl_wave_active_min: {
764-
// Due to the use of variadic arguments, explicitly retrieve argument
819+
// Due to the use of variadic arguments, explicitly retreive argument
765820
Value *OpExpr = EmitScalarExpr(E->getArg(0));
766-
QualType QT = E->getArg(0)->getType();
767-
Intrinsic::ID IID = CGM.getHLSLRuntime().getWaveActiveMinIntrinsic(
768-
QT->isUnsignedIntegerType());
821+
Intrinsic::ID IID = getWaveActiveMinIntrinsic(
822+
getTarget().getTriple().getArch(), CGM.getHLSLRuntime(),
823+
E->getArg(0)->getType());
769824

770825
return EmitRuntimeCall(Intrinsic::getOrInsertDeclaration(
771826
&CGM.getModule(), IID, {OpExpr->getType()}),
@@ -811,9 +866,7 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
811866
}
812867
case Builtin::BI__builtin_hlsl_wave_prefix_sum: {
813868
Value *OpExpr = EmitScalarExpr(E->getArg(0));
814-
QualType QT = E->getArg(0)->getType();
815-
Intrinsic::ID IID = CGM.getHLSLRuntime().getWavePrefixSumIntrinsic(
816-
QT->isUnsignedIntegerType());
869+
Intrinsic::ID IID = CGM.getHLSLRuntime().getWavePrefixSumIntrinsic();
817870
return EmitRuntimeCall(Intrinsic::getOrInsertDeclaration(
818871
&CGM.getModule(), IID, {OpExpr->getType()}),
819872
ArrayRef{OpExpr}, "hlsl.wave.prefix.sum");

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -276,29 +276,6 @@ llvm::Triple::ArchType CGHLSLRuntime::getArch() {
276276
return CGM.getTarget().getTriple().getArch();
277277
}
278278

279-
llvm::Intrinsic::ID
280-
CGHLSLRuntime::getUnsignedIntrinsicVariant(llvm::Intrinsic::ID IID) {
281-
switch (IID) {
282-
// DXIL intrinsics
283-
case Intrinsic::dx_wave_reduce_sum:
284-
return Intrinsic::dx_wave_reduce_usum;
285-
case Intrinsic::dx_wave_reduce_max:
286-
return Intrinsic::dx_wave_reduce_umax;
287-
case Intrinsic::dx_wave_reduce_min:
288-
return Intrinsic::dx_wave_reduce_umin;
289-
case Intrinsic::dx_wave_prefix_sum:
290-
return Intrinsic::dx_wave_prefix_usum;
291-
292-
// SPIR-V intrinsics
293-
case Intrinsic::spv_wave_reduce_max:
294-
return Intrinsic::spv_wave_reduce_umax;
295-
case Intrinsic::spv_wave_reduce_min:
296-
return Intrinsic::spv_wave_reduce_umin;
297-
default:
298-
return IID;
299-
}
300-
}
301-
302279
// Emits constant global variables for buffer constants declarations
303280
// and creates metadata linking the constant globals with the buffer global.
304281
void CGHLSLRuntime::emitBufferGlobalsAndMetadata(const HLSLBufferDecl *BufDecl,

clang/lib/CodeGen/CGHLSLRuntime.h

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -49,33 +49,6 @@
4949
} \
5050
}
5151

52-
// A function generator macro for picking the right intrinsic for the target
53-
// backend given IsUnsigned boolean condition. If IsUnsigned == true, it calls
54-
// getUnsignedIntrinsicVariant(IID) to retrieve the unsigned variant of the
55-
// intrinsic else the regular intrinsic is returned. (NOTE:
56-
// getUnsignedIntrinsicVariant returns IID itself if there is no unsigned
57-
// variant).
58-
#define GENERATE_HLSL_INTRINSIC_FUNCTION_SELECT_UNSIGNED(FunctionName, \
59-
IntrinsicPostfix) \
60-
llvm::Intrinsic::ID get##FunctionName##Intrinsic(bool IsUnsigned) { \
61-
llvm::Triple::ArchType Arch = getArch(); \
62-
switch (Arch) { \
63-
case llvm::Triple::dxil: { \
64-
static constexpr llvm::Intrinsic::ID IID = \
65-
llvm::Intrinsic::dx_##IntrinsicPostfix; \
66-
return IsUnsigned ? getUnsignedIntrinsicVariant(IID) : IID; \
67-
} \
68-
case llvm::Triple::spirv: { \
69-
static constexpr llvm::Intrinsic::ID IID = \
70-
llvm::Intrinsic::spv_##IntrinsicPostfix; \
71-
return IsUnsigned ? getUnsignedIntrinsicVariant(IID) : IID; \
72-
} \
73-
default: \
74-
llvm_unreachable("Intrinsic " #IntrinsicPostfix \
75-
" not supported by target architecture"); \
76-
} \
77-
}
78-
7952
using ResourceClass = llvm::dxil::ResourceClass;
8053

8154
namespace llvm {
@@ -168,17 +141,10 @@ class CGHLSLRuntime {
168141
GENERATE_HLSL_INTRINSIC_FUNCTION(WaveActiveAllTrue, wave_all)
169142
GENERATE_HLSL_INTRINSIC_FUNCTION(WaveActiveAnyTrue, wave_any)
170143
GENERATE_HLSL_INTRINSIC_FUNCTION(WaveActiveCountBits, wave_active_countbits)
171-
GENERATE_HLSL_INTRINSIC_FUNCTION_SELECT_UNSIGNED(WaveActiveSum,
172-
wave_reduce_sum)
173-
GENERATE_HLSL_INTRINSIC_FUNCTION_SELECT_UNSIGNED(WaveActiveMax,
174-
wave_reduce_max)
175-
GENERATE_HLSL_INTRINSIC_FUNCTION_SELECT_UNSIGNED(WaveActiveMin,
176-
wave_reduce_min)
177144
GENERATE_HLSL_INTRINSIC_FUNCTION(WaveIsFirstLane, wave_is_first_lane)
178145
GENERATE_HLSL_INTRINSIC_FUNCTION(WaveGetLaneCount, wave_get_lane_count)
179146
GENERATE_HLSL_INTRINSIC_FUNCTION(WaveReadLaneAt, wave_readlane)
180-
GENERATE_HLSL_INTRINSIC_FUNCTION_SELECT_UNSIGNED(WavePrefixSum,
181-
wave_prefix_sum)
147+
GENERATE_HLSL_INTRINSIC_FUNCTION(WavePrefixSum, wave_prefix_sum)
182148
GENERATE_HLSL_INTRINSIC_FUNCTION(FirstBitUHigh, firstbituhigh)
183149
GENERATE_HLSL_INTRINSIC_FUNCTION(FirstBitSHigh, firstbitshigh)
184150
GENERATE_HLSL_INTRINSIC_FUNCTION(FirstBitLow, firstbitlow)
@@ -281,10 +247,6 @@ class CGHLSLRuntime {
281247

282248
llvm::Triple::ArchType getArch();
283249

284-
// Returns the unsigned variant of the given intrinsic ID if possible,
285-
// otherwise, the original intrinsic ID is returned.
286-
llvm::Intrinsic::ID getUnsignedIntrinsicVariant(llvm::Intrinsic::ID IID);
287-
288250
llvm::DenseMap<const clang::RecordType *, llvm::TargetExtType *> LayoutTypes;
289251
unsigned SPIRVLastAssignedInputSemanticLocation = 0;
290252
};

0 commit comments

Comments
 (0)