Skip to content

Commit 7593c79

Browse files
refactoring spirv
1 parent 4e5aa2d commit 7593c79

File tree

4 files changed

+7
-34
lines changed

4 files changed

+7
-34
lines changed

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18966,10 +18966,10 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
1896618966
const HLSLOutArgExpr *OutArg2 = dyn_cast<HLSLOutArgExpr>(E->getArg(2));
1896718967

1896818968
auto emitSplitDouble =
18969-
[](CGBuilderTy *Builder, llvm::Value *arg,
18969+
[](CGBuilderTy *Builder, llvm::Intrinsic::ID intrId, llvm::Value *arg,
1897018970
llvm::Type *retType) -> std::pair<Value *, Value *> {
1897118971
CallInst *CI =
18972-
Builder->CreateIntrinsic(retType, llvm::Intrinsic::dx_splitdouble,
18972+
Builder->CreateIntrinsic(retType, intrId,
1897318973
{arg}, nullptr, "hlsl.asuint");
1897418974

1897518975
Value *arg0 = Builder->CreateExtractValue(CI, 0);
@@ -18987,7 +18987,7 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
1898718987
llvm::StructType *retType = llvm::StructType::get(Int32Ty, Int32Ty);
1898818988

1898918989
if (!Op0->getType()->isVectorTy()) {
18990-
auto [arg0, arg1] = emitSplitDouble(&Builder, Op0, retType);
18990+
auto [arg0, arg1] = emitSplitDouble(&Builder, CGM.getHLSLRuntime().getSplitdoubleIntrinsic(), Op0, retType);
1899118991

1899218992
Builder.CreateStore(arg0, Op1TmpLValue.getAddress());
1899318993
auto *s = Builder.CreateStore(arg1, Op2TmpLValue.getAddress());
@@ -19006,7 +19006,7 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
1900619006
for (uint64_t idx = 0; idx < Op0VecTy->getNumElements(); idx++) {
1900719007
Value *op = Builder.CreateExtractElement(Op0, idx);
1900819008

19009-
auto [arg0, arg1] = emitSplitDouble(&Builder, op, retType);
19009+
auto [arg0, arg1] = emitSplitDouble(&Builder, CGM.getHLSLRuntime().getSplitdoubleIntrinsic(), op, retType);
1901019010

1901119011
if (idx == 0) {
1901219012
inserts.first = Builder.CreateInsertElement(i32VecTy, arg0, idx);

clang/lib/CodeGen/CGHLSLRuntime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ class CGHLSLRuntime {
8888
GENERATE_HLSL_INTRINSIC_FUNCTION(ThreadId, thread_id)
8989
GENERATE_HLSL_INTRINSIC_FUNCTION(FDot, fdot)
9090
GENERATE_HLSL_INTRINSIC_FUNCTION(SDot, sdot)
91+
GENERATE_HLSL_INTRINSIC_FUNCTION(Splitdouble, splitdouble);
9192
GENERATE_HLSL_INTRINSIC_FUNCTION(UDot, udot)
9293
GENERATE_HLSL_INTRINSIC_FUNCTION(WaveIsFirstLane, wave_is_first_lane)
9394
GENERATE_HLSL_INTRINSIC_FUNCTION(WaveReadLaneAt, wave_readlane)

clang/lib/Headers/hlsl/hlsl_intrinsics.h

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,6 @@ template <typename T> constexpr uint asuint(T F) {
447447
/// \param D The input double.
448448
/// \param lowbits The output lowbits of D.
449449
/// \param highbits The highbits lowbits D.
450-
#if __is_target_arch(dxil)
451450
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_splitdouble)
452451
void asuint(double, out uint, out uint);
453452
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_splitdouble)
@@ -457,35 +456,6 @@ void asuint(double3, out uint3, out uint3);
457456
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_splitdouble)
458457
void asuint(double4, out uint4, out uint4);
459458

460-
#elif __is_target_arch(spirv)
461-
462-
static inline void asuint(double4 D, out uint4 lowbits, out uint4 highbits) {
463-
uint4 bottom = __detail::bit_cast<uint4>(D.xy);
464-
uint4 top = __detail::bit_cast<uint4>(D.zw);
465-
lowbits = uint4(bottom.x, bottom.z, top.x, top.z);
466-
highbits = uint4(bottom.y, bottom.w, top.y, top.w);
467-
}
468-
469-
static inline void asuint(double3 D, out uint3 lowbits, out uint3 highbits) {
470-
uint4 bottom = __detail::bit_cast<uint4>(D.xy);
471-
uint2 top = __detail::bit_cast<uint2>(D.z);
472-
lowbits = uint3(bottom.x, bottom.z, top.x);
473-
highbits = uint3(bottom.y, bottom.w, top.y);
474-
}
475-
476-
static inline void asuint(double2 D, out uint2 lowbits, out uint2 highbits) {
477-
uint4 bottom = __detail::bit_cast<uint4>(D.xy);
478-
lowbits = uint2(bottom.x, bottom.z);
479-
highbits = uint2(bottom.y, bottom.w);
480-
}
481-
482-
static inline void asuint(double D, out uint lowbits, out uint highbits) {
483-
uint2 bottom = __detail::bit_cast<uint2>(D);
484-
lowbits = uint(bottom.x);
485-
highbits = uint(bottom.y);
486-
}
487-
488-
#endif
489459

490460
//===----------------------------------------------------------------------===//
491461
// atan builtins

llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2569,6 +2569,8 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register ResVReg,
25692569
}
25702570
case Intrinsic::spv_wave_readlane:
25712571
return selectWaveReadLaneAt(ResVReg, ResType, I);
2572+
case Intrinsic::spv_splitdouble:
2573+
return selectSplitdouble(ResVReg, ResType, I);
25722574
case Intrinsic::spv_step:
25732575
return selectExtInst(ResVReg, ResType, I, CL::step, GL::Step);
25742576
case Intrinsic::spv_radians:

0 commit comments

Comments
 (0)