[clang] [llvm] [HLSL] Implementation of the fmod intrinsic (PR #108849)
https://github.com/lizhengxing created https://github.com/llvm/llvm-project/pull/108849 This change implements the frontend for #99118 Builtins.td - add the fmod builtin CGBuiltin.cpp - add the builtin to DirectX intrinsic mapping hlsl_intrinsics.h - add the fmod api SemaHLSL.cpp - add type checks for builtin IntrinsicsDirectX.td - add the fmod DirectX intrinsic >From 565ec725470af2537cce0c9528e0655418921f14 Mon Sep 17 00:00:00 2001 From: Zhengxing Li Date: Fri, 13 Sep 2024 13:19:31 -0700 Subject: [PATCH] [HLSL] Implementation of the fmod intrinsic This change implements the frontend for #99118 Builtins.td - add the fmod builtin CGBuiltin.cpp - add the builtin to DirectX intrinsic mapping hlsl_intrinsics.h - add the fmod api SemaHLSL.cpp - add type checks for builtin IntrinsicsDirectX.td - add the fmod DirectX intrinsic --- clang/include/clang/Basic/Builtins.td | 6 + clang/lib/CodeGen/CGBuiltin.cpp | 19 +++ clang/lib/Headers/hlsl/hlsl_intrinsics.h | 33 + clang/lib/Sema/SemaHLSL.cpp | 12 ++ clang/test/CodeGenHLSL/builtins/fmod.hlsl | 122 ++ clang/test/SemaHLSL/BuiltIns/fmod-errors.hlsl | 38 ++ llvm/include/llvm/IR/IntrinsicsDirectX.td | 1 + 7 files changed, 231 insertions(+) create mode 100644 clang/test/CodeGenHLSL/builtins/fmod.hlsl create mode 100644 clang/test/SemaHLSL/BuiltIns/fmod-errors.hlsl diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 6cf03d27055cd9..56a6813ecd205e 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -4782,6 +4782,12 @@ def HLSLStep: LangBuiltin<"HLSL_LANG"> { let Prototype = "void(...)"; } +def HLSLFmod : LangBuiltin<"HLSL_LANG"> { + let Spellings = ["__builtin_hlsl_elementwise_fmod"]; + let Attributes = [NoThrow, Const]; + let Prototype = "void(...)"; +} + // Builtins for XRay. def XRayCustomEvent : Builtin { let Spellings = ["__xray_customevent"]; diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index a52e880a764252..840c773020dfab 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -18709,6 +18709,25 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID, CGM.getHLSLRuntime().getNormalizeIntrinsic(), ArrayRef{X}, nullptr, "hlsl.normalize"); } + case Builtin::BI__builtin_hlsl_elementwise_fmod: { +Value *Op0 = EmitScalarExpr(E->getArg(0)); +Value *Op1 = EmitScalarExpr(E->getArg(1)); +if (!E->getArg(0)->getType()->hasFloatingRepresentation() || +(E->getArg(0)->getType() != E->getArg(1)->getType())) + llvm_unreachable("fmod operands must have the same float representation"); + +llvm::Triple::ArchType Arch = CGM.getTarget().getTriple().getArch(); +assert(((Arch == llvm::Triple::dxil) || (Arch == llvm::Triple::spirv)) && + "Unknown target architecture"); + +if (CGM.getTarget().getTriple().getArch() == llvm::Triple::dxil) + return Builder.CreateIntrinsic( + /*ReturnType=*/Op0->getType(), Intrinsic::dx_fmod, + ArrayRef{Op0, Op1}, nullptr, "dx.fmod"); + +// HLSL's Fmod builtin is equivalent to SPIRV's OpFRem instruction +return Builder.CreateFRem(Op0, Op1, "fmod"); + } case Builtin::BI__builtin_hlsl_elementwise_frac: { Value *Op0 = EmitScalarExpr(E->getArg(0)); if (!E->getArg(0)->getType()->hasFloatingRepresentation()) diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h index d08dcd350d558b..6ff45e191923e8 100644 --- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h +++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h @@ -807,6 +807,39 @@ float3 floor(float3); _HLSL_BUILTIN_ALIAS(__builtin_elementwise_floor) float4 floor(float4); +//===--===// +// fmod builtins +//===--===// + +/// \fn T fmod(T x, T y) +/// \brief Returns the linear interpolation of x to y. +/// \param x [in] The dividend. +/// \param y [in] The divisor. +/// +/// Return the floating-point remainder of the x parameter divided by the y parameter. + +_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2) +_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_fmod) +half fmod(half, half); +_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2) +_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_fmod) +half2 fmod(half2, half2); +_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2) +_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_fmod) +half3 fmod(half3, half3); +_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2) +_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_fmod) +half4 fmod(half4, half4); + +_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_fmod) +float fmod(float, float); +_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_fmod) +float2 fmod(float2,
[clang] [llvm] [HLSL] Implementation of the fmod intrinsic (PR #108849)
@@ -90,4 +90,5 @@ def int_dx_rsqrt : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>] def int_dx_wave_is_first_lane : DefaultAttrsIntrinsic<[llvm_i1_ty], [], [IntrConvergent]>; def int_dx_sign : DefaultAttrsIntrinsic<[LLVMScalarOrSameVectorWidth<0, llvm_i32_ty>], [llvm_any_ty]>; def int_dx_step : DefaultAttrsIntrinsic<[LLVMMatchType<0>], [llvm_anyfloat_ty, LLVMMatchType<0>]>; +def int_dx_fmod : DefaultAttrsIntrinsic<[LLVMMatchType<0>], [llvm_anyfloat_ty, LLVMMatchType<0>]>; lizhengxing wrote: Unlike SPIRV backend, currently the Directx backend only lowers the intrinsics not instructions. I have a follow-up PR will expand this dx specific intrinsic. https://github.com/llvm/llvm-project/pull/108849 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implement SV_GroupID semantic (PR #115911)
@@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm -finclude-default-header -disable-llvm-passes -o - %s | FileCheck %s + +// Make sure SV_GroupID translated into dx.group.id. + +// CHECK: define void @foo() +// CHECK: %[[#ID:]] = call i32 @llvm.dx.group.id(i32 0) +// CHECK: call void @{{.*}}foo{{.*}}(i32 %[[#ID]]) +[shader("compute")] +[numthreads(8,8,1)] +void foo(uint Idx : SV_GroupID) {} + +// CHECK: define void @bar() +// CHECK: %[[#ID_X:]] = call i32 @llvm.dx.group.id(i32 0) +// CHECK: %[[#ID_X_:]] = insertelement <2 x i32> poison, i32 %[[#ID_X]], i64 0 +// CHECK: %[[#ID_Y:]] = call i32 @llvm.dx.group.id(i32 1) +// CHECK: %[[#ID_XY:]] = insertelement <2 x i32> %[[#ID_X_]], i32 %[[#ID_Y]], i64 1 +// CHECK: call void @{{.*}}bar{{.*}}(<2 x i32> %[[#ID_XY]]) +[shader("compute")] +[numthreads(8,8,1)] +void bar(uint2 Idx : SV_GroupID) {} lizhengxing wrote: This test is from `DispatchThreadID.hlsl` . I'll add the uint3 test in the next commit with the changes from all feedbacks. https://github.com/llvm/llvm-project/pull/115911 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implement SV_GroupID semantic (PR #115911)
https://github.com/lizhengxing edited https://github.com/llvm/llvm-project/pull/115911 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implement SV_GroupID semantic (PR #115911)
https://github.com/lizhengxing edited https://github.com/llvm/llvm-project/pull/115911 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implement SV_GroupID semantic (PR #115911)
https://github.com/lizhengxing created https://github.com/llvm/llvm-project/pull/115911 Support SV_GroupID attribute. Translate it into dx.group.id in clang codeGen. Fixes: #70120 >From 2e231d66b405ffec843651f5d4260db91a0ed6a5 Mon Sep 17 00:00:00 2001 From: Zhengxing Li Date: Tue, 1 Oct 2024 15:13:34 -0700 Subject: [PATCH] [HLSL] Implement SV_GroupID semantic Support SV_GroupID attribute. Translate it into dx.group.id in clang codeGen. Fixes: #70120 --- clang/include/clang/Basic/Attr.td | 7 ++ clang/include/clang/Basic/AttrDocs.td | 11 clang/include/clang/Sema/SemaHLSL.h | 1 + clang/lib/CodeGen/CGHLSLRuntime.cpp | 5 clang/lib/Parse/ParseHLSL.cpp | 1 + clang/lib/Sema/SemaDeclAttr.cpp | 3 +++ clang/lib/Sema/SemaHLSL.cpp | 16 ++-- .../CodeGenHLSL/semantics/SV_GroupID.hlsl | 21 .../SemaHLSL/Semantics/entry_parameter.hlsl | 11 +--- .../Semantics/invalid_entry_parameter.hlsl| 22 .../Semantics/valid_entry_parameter.hlsl | 25 +++ 11 files changed, 117 insertions(+), 6 deletions(-) create mode 100644 clang/test/CodeGenHLSL/semantics/SV_GroupID.hlsl diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index a631e81d40aa68..52df814deecc02 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -4587,6 +4587,13 @@ def HLSLNumThreads: InheritableAttr { let Documentation = [NumThreadsDocs]; } +def HLSLSV_GroupID: HLSLAnnotationAttr { + let Spellings = [HLSLAnnotation<"SV_GroupID">]; + let Subjects = SubjectList<[ParmVar, Field]>; + let LangOpts = [HLSL]; + let Documentation = [HLSLSV_GroupIDDocs]; +} + def HLSLSV_GroupIndex: HLSLAnnotationAttr { let Spellings = [HLSLAnnotation<"SV_GroupIndex">]; let Subjects = SubjectList<[ParmVar, GlobalVar]>; diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index b64dbef6332e6a..0a20f87d0ddb37 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -7816,6 +7816,17 @@ randomized. }]; } +def HLSLSV_GroupIDDocs : Documentation { + let Category = DocCatFunction; + let Content = [{ +The ``SV_GroupID`` semantic, when applied to an input parameter, specifies a +data binding to map the group id to the specified parameter. This attribute is +only supported in compute shaders. + +The full documentation is available here: https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/sv-groupid + }]; +} + def HLSLSV_GroupIndexDocs : Documentation { let Category = DocCatFunction; let Content = [{ diff --git a/clang/include/clang/Sema/SemaHLSL.h b/clang/include/clang/Sema/SemaHLSL.h index 06c541dec08cc8..f36b46d0c7ad43 100644 --- a/clang/include/clang/Sema/SemaHLSL.h +++ b/clang/include/clang/Sema/SemaHLSL.h @@ -119,6 +119,7 @@ class SemaHLSL : public SemaBase { void handleNumThreadsAttr(Decl *D, const ParsedAttr &AL); void handleWaveSizeAttr(Decl *D, const ParsedAttr &AL); void handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL); + void handleSV_GroupIDAttr(Decl *D, const ParsedAttr &AL); void handlePackOffsetAttr(Decl *D, const ParsedAttr &AL); void handleShaderAttr(Decl *D, const ParsedAttr &AL); void handleResourceBindingAttr(Decl *D, const ParsedAttr &AL); diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp index 7ba0d615018181..d5bdabe1fdf893 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -389,6 +389,11 @@ llvm::Value *CGHLSLRuntime::emitInputSemantic(IRBuilder<> &B, CGM.getIntrinsic(getThreadIdIntrinsic()); return buildVectorInput(B, ThreadIDIntrinsic, Ty); } + if (D.hasAttr()) { +llvm::Function *GroupIDIntrinsic = +CGM.getIntrinsic(Intrinsic::dx_group_id); +return buildVectorInput(B, GroupIDIntrinsic, Ty); + } assert(false && "Unhandled parameter attribute"); return nullptr; } diff --git a/clang/lib/Parse/ParseHLSL.cpp b/clang/lib/Parse/ParseHLSL.cpp index b36ea4012c26e1..2f67718f94c68c 100644 --- a/clang/lib/Parse/ParseHLSL.cpp +++ b/clang/lib/Parse/ParseHLSL.cpp @@ -280,6 +280,7 @@ void Parser::ParseHLSLAnnotations(ParsedAttributes &Attrs, case ParsedAttr::UnknownAttribute: Diag(Loc, diag::err_unknown_hlsl_semantic) << II; return; + case ParsedAttr::AT_HLSLSV_GroupID: case ParsedAttr::AT_HLSLSV_GroupIndex: case ParsedAttr::AT_HLSLSV_DispatchThreadID: break; diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index d05d326178e1b8..cea51bd507f288 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -6990,6 +6990,9 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL, case ParsedAttr::AT_HLSLWaveSize: S.HLSL().handleWaveSizeAttr(D, AL);
[clang] [HLSL] Implement SV_GroupID semantic (PR #115911)
https://github.com/lizhengxing updated https://github.com/llvm/llvm-project/pull/115911 >From 6418461717614d5879688d32a0ab9bf9d9137328 Mon Sep 17 00:00:00 2001 From: Zhengxing Li Date: Tue, 1 Oct 2024 15:13:34 -0700 Subject: [PATCH] [HLSL] Implement SV_GroupID semantic Support SV_GroupID attribute. Translate it into dx.group.id in clang codeGen. Fixes: #70120 --- clang/include/clang/Basic/Attr.td | 7 ++ clang/include/clang/Basic/AttrDocs.td | 11 clang/include/clang/Sema/SemaHLSL.h | 1 + clang/lib/CodeGen/CGHLSLRuntime.cpp | 4 +++ clang/lib/Parse/ParseHLSL.cpp | 1 + clang/lib/Sema/SemaDeclAttr.cpp | 3 +++ clang/lib/Sema/SemaHLSL.cpp | 16 ++-- .../CodeGenHLSL/semantics/SV_GroupID.hlsl | 21 .../SemaHLSL/Semantics/entry_parameter.hlsl | 11 +--- .../Semantics/invalid_entry_parameter.hlsl| 22 .../Semantics/valid_entry_parameter.hlsl | 25 +++ 11 files changed, 116 insertions(+), 6 deletions(-) create mode 100644 clang/test/CodeGenHLSL/semantics/SV_GroupID.hlsl diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index a631e81d40aa68..52df814deecc02 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -4587,6 +4587,13 @@ def HLSLNumThreads: InheritableAttr { let Documentation = [NumThreadsDocs]; } +def HLSLSV_GroupID: HLSLAnnotationAttr { + let Spellings = [HLSLAnnotation<"SV_GroupID">]; + let Subjects = SubjectList<[ParmVar, Field]>; + let LangOpts = [HLSL]; + let Documentation = [HLSLSV_GroupIDDocs]; +} + def HLSLSV_GroupIndex: HLSLAnnotationAttr { let Spellings = [HLSLAnnotation<"SV_GroupIndex">]; let Subjects = SubjectList<[ParmVar, GlobalVar]>; diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index b64dbef6332e6a..0a20f87d0ddb37 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -7816,6 +7816,17 @@ randomized. }]; } +def HLSLSV_GroupIDDocs : Documentation { + let Category = DocCatFunction; + let Content = [{ +The ``SV_GroupID`` semantic, when applied to an input parameter, specifies a +data binding to map the group id to the specified parameter. This attribute is +only supported in compute shaders. + +The full documentation is available here: https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/sv-groupid + }]; +} + def HLSLSV_GroupIndexDocs : Documentation { let Category = DocCatFunction; let Content = [{ diff --git a/clang/include/clang/Sema/SemaHLSL.h b/clang/include/clang/Sema/SemaHLSL.h index 06c541dec08cc8..f36b46d0c7ad43 100644 --- a/clang/include/clang/Sema/SemaHLSL.h +++ b/clang/include/clang/Sema/SemaHLSL.h @@ -119,6 +119,7 @@ class SemaHLSL : public SemaBase { void handleNumThreadsAttr(Decl *D, const ParsedAttr &AL); void handleWaveSizeAttr(Decl *D, const ParsedAttr &AL); void handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL); + void handleSV_GroupIDAttr(Decl *D, const ParsedAttr &AL); void handlePackOffsetAttr(Decl *D, const ParsedAttr &AL); void handleShaderAttr(Decl *D, const ParsedAttr &AL); void handleResourceBindingAttr(Decl *D, const ParsedAttr &AL); diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp index 7ba0d615018181..2c293523fca8ca 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -389,6 +389,10 @@ llvm::Value *CGHLSLRuntime::emitInputSemantic(IRBuilder<> &B, CGM.getIntrinsic(getThreadIdIntrinsic()); return buildVectorInput(B, ThreadIDIntrinsic, Ty); } + if (D.hasAttr()) { +llvm::Function *GroupIDIntrinsic = CGM.getIntrinsic(Intrinsic::dx_group_id); +return buildVectorInput(B, GroupIDIntrinsic, Ty); + } assert(false && "Unhandled parameter attribute"); return nullptr; } diff --git a/clang/lib/Parse/ParseHLSL.cpp b/clang/lib/Parse/ParseHLSL.cpp index b36ea4012c26e1..2f67718f94c68c 100644 --- a/clang/lib/Parse/ParseHLSL.cpp +++ b/clang/lib/Parse/ParseHLSL.cpp @@ -280,6 +280,7 @@ void Parser::ParseHLSLAnnotations(ParsedAttributes &Attrs, case ParsedAttr::UnknownAttribute: Diag(Loc, diag::err_unknown_hlsl_semantic) << II; return; + case ParsedAttr::AT_HLSLSV_GroupID: case ParsedAttr::AT_HLSLSV_GroupIndex: case ParsedAttr::AT_HLSLSV_DispatchThreadID: break; diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index d05d326178e1b8..cea51bd507f288 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -6990,6 +6990,9 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL, case ParsedAttr::AT_HLSLWaveSize: S.HLSL().handleWaveSizeAttr(D, AL); break; + case ParsedAttr::AT_HLSLSV_GroupID: +S.HLSL().handleSV_GroupIDAttr(D, AL); +break
[clang] [HLSL] Implementation of the fmod intrinsic (PR #108849)
https://github.com/lizhengxing edited https://github.com/llvm/llvm-project/pull/108849 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implementation of the elementwise fmod builtin (PR #108849)
https://github.com/lizhengxing edited https://github.com/llvm/llvm-project/pull/108849 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implementation of the fmod intrinsic (PR #108849)
@@ -0,0 +1,79 @@ +// DirectX target: +// +// -- Native Half support test --- +// +// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \ +// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \ +// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \ +// RUN: --check-prefixes=CHECK \ lizhengxing wrote: Done. https://github.com/llvm/llvm-project/pull/108849 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implementation of the fmod intrinsic (PR #108849)
@@ -0,0 +1,38 @@ + +// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -verify-ignore-unexpected + +float test_too_few_arg() { lizhengxing wrote: Done. Add 2 double type tests https://github.com/llvm/llvm-project/pull/108849 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implementation of the fmod intrinsic (PR #108849)
lizhengxing wrote: > We should announce `__builtin_elementwise_fmod` here: > `clang/docs/ReleaseNotes.rst` See @spall PR where we just did this: > https://github.com/llvm/llvm-project/pull/108121/files Done. https://github.com/llvm/llvm-project/pull/108849 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implementation of the fmod intrinsic (PR #108849)
@@ -0,0 +1,38 @@ + +// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -verify-ignore-unexpected + +float test_too_few_arg() { + return __builtin_elementwise_fmod(); + // expected-error@-1 {{too few arguments to function call, expected 2, have 0}} +} + +float2 test_too_many_arg(float2 p0, float2 p1, float2 p3) { + return __builtin_elementwise_fmod(p0, p1, p3); + // expected-error@-1 {{too many arguments to function call, expected 2, have 3}} +} + +float builtin_bool_to_float_type_promotion(bool p1, bool p2) { + return __builtin_elementwise_fmod(p1, p2); + // expected-error@-1 {{passing 'bool' to parameter of incompatible type 'float'}} +} + +float builtin_fmod_int_to_float_promotion(int p1, int p2) { + return __builtin_elementwise_fmod(p1, p2); + // expected-error@-1 {{passing 'int' to parameter of incompatible type 'float'}} +} + +float2 builtin_fmod_int2_to_float2_promotion(int2 p1, int2 p2) { + return __builtin_elementwise_fmod(p1, p2); + // expected-error@-1 {{passing 'int2' (aka 'vector') to parameter of incompatible type '__attribute__((__vector_size__(2 * sizeof(float float' (vector of 2 'float' values)}} +} + +// builtins are variadic functions and so are subject to DefaultVariadicArgumentPromotion +half builtin_fmod_half_scalar (half p0, half p1) { lizhengxing wrote: @farzonl You mean that we should remove builtin_fmod_half_scalar and builtin_fmod_float_scalar tests? https://github.com/llvm/llvm-project/pull/108849 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implementation of the fmod intrinsic (PR #108849)
https://github.com/lizhengxing updated https://github.com/llvm/llvm-project/pull/108849 >From 42015171d9756e3566021530a1e9479aad8de2c4 Mon Sep 17 00:00:00 2001 From: Zhengxing Li Date: Fri, 13 Sep 2024 13:19:31 -0700 Subject: [PATCH] [HLSL] Implementation of the fmod intrinsic This change implements the frontend for #99118 Builtins.td - add the fmod builtin CGBuiltin.cpp - lower the builtin to llvm FRem instruction hlsl_intrinsics.h - add the fmod api SemaHLSL.cpp - add type checks for builtin clang/docs/LanguageExtensions.rst - add the builtin in *Elementwise Builtins* clang/docs/ReleaseNotes.rst- announce the builtin --- clang/docs/LanguageExtensions.rst | 2 + clang/docs/ReleaseNotes.rst | 2 + clang/include/clang/Basic/Builtins.td | 6 ++ clang/lib/CodeGen/CGBuiltin.cpp | 3 +- clang/lib/Headers/hlsl/hlsl_intrinsics.h | 33 clang/lib/Sema/SemaHLSL.cpp | 12 +++ clang/test/CodeGenHLSL/builtins/fmod.hlsl | 77 +++ clang/test/SemaHLSL/BuiltIns/fmod-errors.hlsl | 37 + 8 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 clang/test/CodeGenHLSL/builtins/fmod.hlsl create mode 100644 clang/test/SemaHLSL/BuiltIns/fmod-errors.hlsl diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index 0c6b9b1b8f9ce4..ea4b4bcec55e77 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -700,6 +700,8 @@ Unless specified otherwise operation(±0) = ±0 and operation(±infinity) = ±in T __builtin_elementwise_canonicalize(T x) return the platform specific canonical encoding floating point types of a floating-point number T __builtin_elementwise_copysign(T x, T y) return the magnitude of x with the sign of y.floating point types + T __builtin_elementwise_fmod(T x, T y) return The floating-point remainder of (x/y) whose sign floating point types + matches the sign of x. T __builtin_elementwise_max(T x, T y) return x or y, whichever is larger integer and floating point types T __builtin_elementwise_min(T x, T y) return x or y, whichever is smaller integer and floating point types T __builtin_elementwise_add_sat(T x, T y) return the sum of x and y, clamped to the range of integer types diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index e511614fcf2451..6af5a6824f84c4 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -123,6 +123,8 @@ C++ Language Changes - Add ``__builtin_elementwise_popcount`` builtin for integer types only. +- Add ``__builtin_elementwise_fmod`` builtin for floating point types only. + - The builtin type alias ``__builtin_common_type`` has been added to improve the performance of ``std::common_type``. diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 8c5d7ad763bf97..cc7d97b2690917 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -4788,6 +4788,12 @@ def HLSLStep: LangBuiltin<"HLSL_LANG"> { let Prototype = "void(...)"; } +def HLSLFmod : LangBuiltin<"HLSL_LANG"> { + let Spellings = ["__builtin_elementwise_fmod"]; + let Attributes = [NoThrow, Const]; + let Prototype = "void(...)"; +} + // Builtins for XRay. def XRayCustomEvent : Builtin { let Spellings = ["__xray_customevent"]; diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 942468204f054c..37655bc06c1eeb 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -2844,7 +2844,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, case Builtin::BI__builtin_fmodf: case Builtin::BI__builtin_fmodf16: case Builtin::BI__builtin_fmodl: -case Builtin::BI__builtin_fmodf128: { +case Builtin::BI__builtin_fmodf128: +case Builtin::BI__builtin_elementwise_fmod: { CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E); Value *Arg1 = EmitScalarExpr(E->getArg(0)); Value *Arg2 = EmitScalarExpr(E->getArg(1)); diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h index b139f9eb7d999b..aa7c61d3d7a6a7 100644 --- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h +++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h @@ -913,6 +913,39 @@ float3 floor(float3); _HLSL_BUILTIN_ALIAS(__builtin_elementwise_floor) float4 floor(float4); +//===--===// +// fmod builtins +//===--===// + +/// \fn T fmod(T x, T y) +/// \brief Returns the linea
[clang] [HLSL] Implementation of the fmod intrinsic (PR #108849)
https://github.com/lizhengxing edited https://github.com/llvm/llvm-project/pull/108849 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implementation of the fmod intrinsic (PR #108849)
@@ -0,0 +1,38 @@ + +// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -verify-ignore-unexpected + +float test_too_few_arg() { + return __builtin_elementwise_fmod(); + // expected-error@-1 {{too few arguments to function call, expected 2, have 0}} +} + +float2 test_too_many_arg(float2 p0, float2 p1, float2 p3) { + return __builtin_elementwise_fmod(p0, p1, p3); + // expected-error@-1 {{too many arguments to function call, expected 2, have 3}} +} + +float builtin_bool_to_float_type_promotion(bool p1, bool p2) { + return __builtin_elementwise_fmod(p1, p2); + // expected-error@-1 {{passing 'bool' to parameter of incompatible type 'float'}} +} + +float builtin_fmod_int_to_float_promotion(int p1, int p2) { + return __builtin_elementwise_fmod(p1, p2); + // expected-error@-1 {{passing 'int' to parameter of incompatible type 'float'}} +} + +float2 builtin_fmod_int2_to_float2_promotion(int2 p1, int2 p2) { + return __builtin_elementwise_fmod(p1, p2); + // expected-error@-1 {{passing 'int2' (aka 'vector') to parameter of incompatible type '__attribute__((__vector_size__(2 * sizeof(float float' (vector of 2 'float' values)}} +} + +// builtins are variadic functions and so are subject to DefaultVariadicArgumentPromotion +half builtin_fmod_half_scalar (half p0, half p1) { lizhengxing wrote: Done. Removed builtin_fmod_half_scalar and builtin_fmod_float_scalar tests. https://github.com/llvm/llvm-project/pull/108849 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implementation of the fmod intrinsic (PR #108849)
lizhengxing wrote: > The SPIRV frem testing doesn't appear to be complete in > `llvm/test/CodeGen/SPIRV/instructions/scalar-floating-point-arithmetic.ll` > `llvm/test/CodeGen/SPIRV/instructions/vector-floating-point-arithmetic.ll` > > for all our cases we defined in `hlsl_intrinsics.h`. Should we add more test > cases? > > Personally I'd like to see at least one test case in: > `llvm/test/CodeGen/SPIRV/hlsl-intrinsics/fmod.ll` Makes it easy to track > which intrinsics we have completed for the SPIRV backend. I'll add those codegen tests in the second PR for #99118 . That PR is backend specific. https://github.com/llvm/llvm-project/pull/108849 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implementation of the fmod intrinsic (PR #108849)
@@ -0,0 +1,38 @@ + +// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -verify-ignore-unexpected + +float test_too_few_arg() { + return __builtin_hlsl_elementwise_fmod(); + // expected-error@-1 {{too few arguments to function call, expected 2, have 0}} +} + +float2 test_too_many_arg(float2 p0, float2 p1, float2 p3) { + return __builtin_hlsl_elementwise_fmod(p0, p1, p3); + // expected-error@-1 {{too many arguments to function call, expected 2, have 3}} +} + +float builtin_bool_to_float_type_promotion(bool p1, bool p2) { + return __builtin_hlsl_elementwise_fmod(p1, p2); + // expected-error@-1 {{passing 'bool' to parameter of incompatible type 'float'}} +} + +float builtin_fmod_int_to_float_promotion(int p1, int p2) { + return __builtin_hlsl_elementwise_fmod(p1, p2); + // expected-error@-1 {{passing 'int' to parameter of incompatible type 'float'}} +} + +float2 builtin_fmod_int2_to_float2_promotion(int2 p1, int2 p2) { + return __builtin_hlsl_elementwise_fmod(p1, p2); + // expected-error@-1 {{passing 'int2' (aka 'vector') to parameter of incompatible type '__attribute__((__vector_size__(2 * sizeof(float float' (vector of 2 'float' values)}} +} + +// builtins are variadic functions and so are subject to DefaultVariadicArgumentPromotion +half builtin_fmod_half_scalar (half p0, half p1) { + return __builtin_hlsl_elementwise_fmod(p0, p1); + // expected-error@-1 {{passing 'double' to parameter of incompatible type 'float'}} +} + +float builtin_fmod_float_scalar (float p0, float p1) { + return __builtin_hlsl_elementwise_fmod (p0, p1); + // expected-error@-1 {{passing 'double' to parameter of incompatible type 'float'}} +} lizhengxing wrote: Done. https://github.com/llvm/llvm-project/pull/108849 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implementation of the fmod intrinsic (PR #108849)
@@ -18709,6 +18709,25 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID, CGM.getHLSLRuntime().getNormalizeIntrinsic(), ArrayRef{X}, nullptr, "hlsl.normalize"); } + case Builtin::BI__builtin_hlsl_elementwise_fmod: { lizhengxing wrote: Done. https://github.com/llvm/llvm-project/pull/108849 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implementation of the fmod intrinsic (PR #108849)
@@ -90,4 +90,5 @@ def int_dx_rsqrt : DefaultAttrsIntrinsic<[llvm_anyfloat_ty], [LLVMMatchType<0>] def int_dx_wave_is_first_lane : DefaultAttrsIntrinsic<[llvm_i1_ty], [], [IntrConvergent]>; def int_dx_sign : DefaultAttrsIntrinsic<[LLVMScalarOrSameVectorWidth<0, llvm_i32_ty>], [llvm_any_ty]>; def int_dx_step : DefaultAttrsIntrinsic<[LLVMMatchType<0>], [llvm_anyfloat_ty, LLVMMatchType<0>]>; +def int_dx_fmod : DefaultAttrsIntrinsic<[LLVMMatchType<0>], [llvm_anyfloat_ty, LLVMMatchType<0>]>; lizhengxing wrote: Done. https://github.com/llvm/llvm-project/pull/108849 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implementation of the fmod intrinsic (PR #108849)
@@ -4782,6 +4782,12 @@ def HLSLStep: LangBuiltin<"HLSL_LANG"> { let Prototype = "void(...)"; } +def HLSLFmod : LangBuiltin<"HLSL_LANG"> { + let Spellings = ["__builtin_hlsl_elementwise_fmod"]; lizhengxing wrote: Done. https://github.com/llvm/llvm-project/pull/108849 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implementation of the fmod intrinsic (PR #108849)
https://github.com/lizhengxing updated https://github.com/llvm/llvm-project/pull/108849 >From 9942e3129cdb37969adceb40c42ea17042c61b2b Mon Sep 17 00:00:00 2001 From: Zhengxing Li Date: Fri, 13 Sep 2024 13:19:31 -0700 Subject: [PATCH] [HLSL] Implementation of the fmod intrinsic This change implements the frontend for #99118 Builtins.td - add the fmod builtin CGBuiltin.cpp - lower the builtin to llvm FRem instruction hlsl_intrinsics.h - add the fmod api SemaHLSL.cpp - add type checks for builtin clang/docs/LanguageExtensions.rst - add the builtin in *Elementwise Builtins* --- clang/docs/LanguageExtensions.rst | 2 + clang/include/clang/Basic/Builtins.td | 6 ++ clang/lib/CodeGen/CGBuiltin.cpp | 3 +- clang/lib/Headers/hlsl/hlsl_intrinsics.h | 33 clang/lib/Sema/SemaHLSL.cpp | 12 +++ clang/test/CodeGenHLSL/builtins/fmod.hlsl | 79 +++ clang/test/SemaHLSL/BuiltIns/fmod-errors.hlsl | 38 + 7 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 clang/test/CodeGenHLSL/builtins/fmod.hlsl create mode 100644 clang/test/SemaHLSL/BuiltIns/fmod-errors.hlsl diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index 0c6b9b1b8f9ce4..ea4b4bcec55e77 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -700,6 +700,8 @@ Unless specified otherwise operation(±0) = ±0 and operation(±infinity) = ±in T __builtin_elementwise_canonicalize(T x) return the platform specific canonical encoding floating point types of a floating-point number T __builtin_elementwise_copysign(T x, T y) return the magnitude of x with the sign of y.floating point types + T __builtin_elementwise_fmod(T x, T y) return The floating-point remainder of (x/y) whose sign floating point types + matches the sign of x. T __builtin_elementwise_max(T x, T y) return x or y, whichever is larger integer and floating point types T __builtin_elementwise_min(T x, T y) return x or y, whichever is smaller integer and floating point types T __builtin_elementwise_add_sat(T x, T y) return the sum of x and y, clamped to the range of integer types diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 8c5d7ad763bf97..cc7d97b2690917 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -4788,6 +4788,12 @@ def HLSLStep: LangBuiltin<"HLSL_LANG"> { let Prototype = "void(...)"; } +def HLSLFmod : LangBuiltin<"HLSL_LANG"> { + let Spellings = ["__builtin_elementwise_fmod"]; + let Attributes = [NoThrow, Const]; + let Prototype = "void(...)"; +} + // Builtins for XRay. def XRayCustomEvent : Builtin { let Spellings = ["__xray_customevent"]; diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 942468204f054c..37655bc06c1eeb 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -2844,7 +2844,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, case Builtin::BI__builtin_fmodf: case Builtin::BI__builtin_fmodf16: case Builtin::BI__builtin_fmodl: -case Builtin::BI__builtin_fmodf128: { +case Builtin::BI__builtin_fmodf128: +case Builtin::BI__builtin_elementwise_fmod: { CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E); Value *Arg1 = EmitScalarExpr(E->getArg(0)); Value *Arg2 = EmitScalarExpr(E->getArg(1)); diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h index b139f9eb7d999b..aa7c61d3d7a6a7 100644 --- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h +++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h @@ -913,6 +913,39 @@ float3 floor(float3); _HLSL_BUILTIN_ALIAS(__builtin_elementwise_floor) float4 floor(float4); +//===--===// +// fmod builtins +//===--===// + +/// \fn T fmod(T x, T y) +/// \brief Returns the linear interpolation of x to y. +/// \param x [in] The dividend. +/// \param y [in] The divisor. +/// +/// Return the floating-point remainder of the x parameter divided by the y parameter. + +_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2) +_HLSL_BUILTIN_ALIAS(__builtin_elementwise_fmod) +half fmod(half, half); +_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2) +_HLSL_BUILTIN_ALIAS(__builtin_elementwise_fmod) +half2 fmod(half2, half2); +_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2) +_HLSL_BUILTIN_ALIAS(__builtin_elementwise_fmod) +half3 fmod(half3, half3); +_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2) +_HLSL_BUILTIN_ALIAS(__builti
[clang] [HLSL] Implementation of the fmod intrinsic (PR #108849)
https://github.com/lizhengxing edited https://github.com/llvm/llvm-project/pull/108849 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implementation of the fmod intrinsic (PR #108849)
@@ -0,0 +1,79 @@ +// DirectX target: +// +// -- Native Half support test --- +// +// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \ +// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \ +// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \ +// RUN: --check-prefixes=CHECK \ +// RUN: -DFNATTRS=noundef -DTYPE=half + +// +// -- No Native Half support test --- +// +// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \ +// RUN: dxil-pc-shadermodel6.3-library %s -emit-llvm -disable-llvm-passes \ +// RUN: -o - | FileCheck %s --check-prefixes=CHECK \ +// RUN: -DFNATTRS=noundef -DTYPE=float + + +// Spirv target: +// +// -- Native Half support test --- +// +// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \ +// RUN: spirv-unknown-vulkan-compute %s -fnative-half-type \ +// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \ +// RUN: --check-prefixes=CHECK \ +// RUN: -DFNATTRS="spir_func noundef" -DTYPE=half + +// +// -- No Native Half support test --- +// +// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \ +// RUN: spirv-unknown-vulkan-compute %s -emit-llvm -disable-llvm-passes \ +// RUN: -o - | FileCheck %s --check-prefixes=CHECK \ +// RUN: -DFNATTRS="spir_func noundef" -DTYPE=float + + + +// CHECK: define [[FNATTRS]] [[TYPE]] @ +// CHECK: %fmod = frem [[TYPE]] +// CHECK: ret [[TYPE]] %fmod +half test_fmod_half(half p0, half p1) { return fmod(p0, p1); } + +// CHECK: define [[FNATTRS]] <2 x [[TYPE]]> @ +// CHECK: %fmod = frem <2 x [[TYPE]]> +// CHECK: ret <2 x [[TYPE]]> %fmod +half2 test_fmod_half2(half2 p0, half2 p1) { return fmod(p0, p1); } + +// CHECK: define [[FNATTRS]] <3 x [[TYPE]]> @ +// CHECK: %fmod = frem <3 x [[TYPE]]> +// CHECK: ret <3 x [[TYPE]]> %fmod +half3 test_fmod_half3(half3 p0, half3 p1) { return fmod(p0, p1); } + +// CHECK: define [[FNATTRS]] <4 x [[TYPE]]> @ +// CHECK: %fmod = frem <4 x [[TYPE]]> +// CHECK: ret <4 x [[TYPE]]> %fmod +half4 test_fmod_half4(half4 p0, half4 p1) { return fmod(p0, p1); } + +// CHECK: define [[FNATTRS]] float @ +// CHECK: %fmod = frem float +// CHECK: ret float %fmod +float test_fmod_float(float p0, float p1) { return fmod(p0, p1); } + +// CHECK: define [[FNATTRS]] <2 x float> @ +// CHECK: %fmod = frem <2 x float> +// CHECK: ret <2 x float> %fmod +float2 test_fmod_float2(float2 p0, float2 p1) { return fmod(p0, p1); } + +// CHECK: define [[FNATTRS]] <3 x float> @ +// CHECK: %fmod = frem <3 x float> +// CHECK: ret <3 x float> %fmod +float3 test_fmod_float3(float3 p0, float3 p1) { return fmod(p0, p1); } + +// DX-CHECK: define [[FNATTRS]] <4 x float> @ lizhengxing wrote: > Why is this group the only DX-CHECK? Fixed. https://github.com/llvm/llvm-project/pull/108849 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implementation of the fmod intrinsic (PR #108849)
https://github.com/lizhengxing updated https://github.com/llvm/llvm-project/pull/108849 >From a12d65fabcc87a50e6c0d83e9f69862bb859b894 Mon Sep 17 00:00:00 2001 From: Zhengxing Li Date: Fri, 13 Sep 2024 13:19:31 -0700 Subject: [PATCH] [HLSL] Implementation of the fmod intrinsic This change implements the frontend for #99118 Builtins.td - add the fmod builtin CGBuiltin.cpp - lower the builtin to llvm FRem instruction hlsl_intrinsics.h - add the fmod api SemaHLSL.cpp - add type checks for builtin clang/docs/LanguageExtensions.rst - add the builtin in *Elementwise Builtins* --- clang/docs/LanguageExtensions.rst | 2 + clang/include/clang/Basic/Builtins.td | 6 ++ clang/lib/CodeGen/CGBuiltin.cpp | 3 +- clang/lib/Headers/hlsl/hlsl_intrinsics.h | 33 clang/lib/Sema/SemaHLSL.cpp | 12 +++ clang/test/CodeGenHLSL/builtins/fmod.hlsl | 79 +++ clang/test/SemaHLSL/BuiltIns/fmod-errors.hlsl | 38 + 7 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 clang/test/CodeGenHLSL/builtins/fmod.hlsl create mode 100644 clang/test/SemaHLSL/BuiltIns/fmod-errors.hlsl diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index 0c6b9b1b8f9ce4..ea4b4bcec55e77 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -700,6 +700,8 @@ Unless specified otherwise operation(±0) = ±0 and operation(±infinity) = ±in T __builtin_elementwise_canonicalize(T x) return the platform specific canonical encoding floating point types of a floating-point number T __builtin_elementwise_copysign(T x, T y) return the magnitude of x with the sign of y.floating point types + T __builtin_elementwise_fmod(T x, T y) return The floating-point remainder of (x/y) whose sign floating point types + matches the sign of x. T __builtin_elementwise_max(T x, T y) return x or y, whichever is larger integer and floating point types T __builtin_elementwise_min(T x, T y) return x or y, whichever is smaller integer and floating point types T __builtin_elementwise_add_sat(T x, T y) return the sum of x and y, clamped to the range of integer types diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 8c5d7ad763bf97..cc7d97b2690917 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -4788,6 +4788,12 @@ def HLSLStep: LangBuiltin<"HLSL_LANG"> { let Prototype = "void(...)"; } +def HLSLFmod : LangBuiltin<"HLSL_LANG"> { + let Spellings = ["__builtin_elementwise_fmod"]; + let Attributes = [NoThrow, Const]; + let Prototype = "void(...)"; +} + // Builtins for XRay. def XRayCustomEvent : Builtin { let Spellings = ["__xray_customevent"]; diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 942468204f054c..37655bc06c1eeb 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -2844,7 +2844,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, case Builtin::BI__builtin_fmodf: case Builtin::BI__builtin_fmodf16: case Builtin::BI__builtin_fmodl: -case Builtin::BI__builtin_fmodf128: { +case Builtin::BI__builtin_fmodf128: +case Builtin::BI__builtin_elementwise_fmod: { CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E); Value *Arg1 = EmitScalarExpr(E->getArg(0)); Value *Arg2 = EmitScalarExpr(E->getArg(1)); diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h index b139f9eb7d999b..aa7c61d3d7a6a7 100644 --- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h +++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h @@ -913,6 +913,39 @@ float3 floor(float3); _HLSL_BUILTIN_ALIAS(__builtin_elementwise_floor) float4 floor(float4); +//===--===// +// fmod builtins +//===--===// + +/// \fn T fmod(T x, T y) +/// \brief Returns the linear interpolation of x to y. +/// \param x [in] The dividend. +/// \param y [in] The divisor. +/// +/// Return the floating-point remainder of the x parameter divided by the y parameter. + +_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2) +_HLSL_BUILTIN_ALIAS(__builtin_elementwise_fmod) +half fmod(half, half); +_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2) +_HLSL_BUILTIN_ALIAS(__builtin_elementwise_fmod) +half2 fmod(half2, half2); +_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2) +_HLSL_BUILTIN_ALIAS(__builtin_elementwise_fmod) +half3 fmod(half3, half3); +_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2) +_HLSL_BUILTIN_ALIAS(__builti
[clang] [HLSL] Implementation of the elementwise fmod builtin (PR #108849)
https://github.com/lizhengxing updated https://github.com/llvm/llvm-project/pull/108849 >From 516d0e5c84df23c91b2ec430bcfb48da0d5ea0be Mon Sep 17 00:00:00 2001 From: Zhengxing Li Date: Fri, 13 Sep 2024 13:19:31 -0700 Subject: [PATCH] [HLSL] Implementation of the elementwise fmod builtin This change add the elementwise fmod builtin to support HLSL function 'fmod' in clang for #99118 Builtins.td - add the fmod builtin CGBuiltin.cpp - lower the builtin to llvm FRem instruction hlsl_intrinsics.h - add the fmod api SemaChecking.cpp - add type checks for builtin SemaHLSL.cpp - add HLSL type checks for builtin clang/docs/LanguageExtensions.rst - add the builtin in *Elementwise Builtins* clang/docs/ReleaseNotes.rst- announce the builtin --- clang/docs/LanguageExtensions.rst | 2 + clang/docs/ReleaseNotes.rst | 2 + clang/include/clang/Basic/Builtins.td | 6 ++ clang/lib/CodeGen/CGBuiltin.cpp | 3 +- clang/lib/Headers/hlsl/hlsl_intrinsics.h | 33 clang/lib/Sema/SemaChecking.cpp | 1 + clang/lib/Sema/SemaHLSL.cpp | 12 +++ .../test/CodeGen/builtins-elementwise-math.c | 20 + .../CodeGen/strictfp-elementwise-bulitins.cpp | 11 +++ clang/test/CodeGenHLSL/builtins/fmod.hlsl | 77 +++ clang/test/Sema/builtins-elementwise-math.c | 27 ++- .../SemaCXX/builtins-elementwise-math.cpp | 8 ++ clang/test/SemaHLSL/BuiltIns/fmod-errors.hlsl | 37 + 13 files changed, 237 insertions(+), 2 deletions(-) create mode 100644 clang/test/CodeGenHLSL/builtins/fmod.hlsl create mode 100644 clang/test/SemaHLSL/BuiltIns/fmod-errors.hlsl diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index 0c6b9b1b8f9ce4..ea4b4bcec55e77 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -700,6 +700,8 @@ Unless specified otherwise operation(±0) = ±0 and operation(±infinity) = ±in T __builtin_elementwise_canonicalize(T x) return the platform specific canonical encoding floating point types of a floating-point number T __builtin_elementwise_copysign(T x, T y) return the magnitude of x with the sign of y.floating point types + T __builtin_elementwise_fmod(T x, T y) return The floating-point remainder of (x/y) whose sign floating point types + matches the sign of x. T __builtin_elementwise_max(T x, T y) return x or y, whichever is larger integer and floating point types T __builtin_elementwise_min(T x, T y) return x or y, whichever is smaller integer and floating point types T __builtin_elementwise_add_sat(T x, T y) return the sum of x and y, clamped to the range of integer types diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 14907e7db18de3..d039636e462a7b 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -123,6 +123,8 @@ C++ Language Changes - Add ``__builtin_elementwise_popcount`` builtin for integer types only. +- Add ``__builtin_elementwise_fmod`` builtin for floating point types only. + - The builtin type alias ``__builtin_common_type`` has been added to improve the performance of ``std::common_type``. diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 8c5d7ad763bf97..0bd8e02cbe73fa 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -1328,6 +1328,12 @@ def ElementwisePopcount : Builtin { let Prototype = "void(...)"; } +def ElementwiseFmod : Builtin { + let Spellings = ["__builtin_elementwise_fmod"]; + let Attributes = [NoThrow, Const, CustomTypeChecking]; + let Prototype = "void(...)"; +} + def ElementwisePow : Builtin { let Spellings = ["__builtin_elementwise_pow"]; let Attributes = [NoThrow, Const, CustomTypeChecking]; diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 249aead33ad73d..b57a2f25c21255 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -2878,7 +2878,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, case Builtin::BI__builtin_fmodf: case Builtin::BI__builtin_fmodf16: case Builtin::BI__builtin_fmodl: -case Builtin::BI__builtin_fmodf128: { +case Builtin::BI__builtin_fmodf128: +case Builtin::BI__builtin_elementwise_fmod: { CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E); Value *Arg1 = EmitScalarExpr(E->getArg(0)); Value *Arg2 = EmitScalarExpr(E->getArg(1)); diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h index b139f9eb7d999b..aa7c61d3d7a6a7 100644 --
[clang] [HLSL] Implementation of the elementwise fmod builtin (PR #108849)
https://github.com/lizhengxing updated https://github.com/llvm/llvm-project/pull/108849 >From 516d0e5c84df23c91b2ec430bcfb48da0d5ea0be Mon Sep 17 00:00:00 2001 From: Zhengxing Li Date: Fri, 13 Sep 2024 13:19:31 -0700 Subject: [PATCH] [HLSL] Implementation of the elementwise fmod builtin This change add the elementwise fmod builtin to support HLSL function 'fmod' in clang for #99118 Builtins.td - add the fmod builtin CGBuiltin.cpp - lower the builtin to llvm FRem instruction hlsl_intrinsics.h - add the fmod api SemaChecking.cpp - add type checks for builtin SemaHLSL.cpp - add HLSL type checks for builtin clang/docs/LanguageExtensions.rst - add the builtin in *Elementwise Builtins* clang/docs/ReleaseNotes.rst- announce the builtin --- clang/docs/LanguageExtensions.rst | 2 + clang/docs/ReleaseNotes.rst | 2 + clang/include/clang/Basic/Builtins.td | 6 ++ clang/lib/CodeGen/CGBuiltin.cpp | 3 +- clang/lib/Headers/hlsl/hlsl_intrinsics.h | 33 clang/lib/Sema/SemaChecking.cpp | 1 + clang/lib/Sema/SemaHLSL.cpp | 12 +++ .../test/CodeGen/builtins-elementwise-math.c | 20 + .../CodeGen/strictfp-elementwise-bulitins.cpp | 11 +++ clang/test/CodeGenHLSL/builtins/fmod.hlsl | 77 +++ clang/test/Sema/builtins-elementwise-math.c | 27 ++- .../SemaCXX/builtins-elementwise-math.cpp | 8 ++ clang/test/SemaHLSL/BuiltIns/fmod-errors.hlsl | 37 + 13 files changed, 237 insertions(+), 2 deletions(-) create mode 100644 clang/test/CodeGenHLSL/builtins/fmod.hlsl create mode 100644 clang/test/SemaHLSL/BuiltIns/fmod-errors.hlsl diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index 0c6b9b1b8f9ce4..ea4b4bcec55e77 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -700,6 +700,8 @@ Unless specified otherwise operation(±0) = ±0 and operation(±infinity) = ±in T __builtin_elementwise_canonicalize(T x) return the platform specific canonical encoding floating point types of a floating-point number T __builtin_elementwise_copysign(T x, T y) return the magnitude of x with the sign of y.floating point types + T __builtin_elementwise_fmod(T x, T y) return The floating-point remainder of (x/y) whose sign floating point types + matches the sign of x. T __builtin_elementwise_max(T x, T y) return x or y, whichever is larger integer and floating point types T __builtin_elementwise_min(T x, T y) return x or y, whichever is smaller integer and floating point types T __builtin_elementwise_add_sat(T x, T y) return the sum of x and y, clamped to the range of integer types diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 14907e7db18de3..d039636e462a7b 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -123,6 +123,8 @@ C++ Language Changes - Add ``__builtin_elementwise_popcount`` builtin for integer types only. +- Add ``__builtin_elementwise_fmod`` builtin for floating point types only. + - The builtin type alias ``__builtin_common_type`` has been added to improve the performance of ``std::common_type``. diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 8c5d7ad763bf97..0bd8e02cbe73fa 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -1328,6 +1328,12 @@ def ElementwisePopcount : Builtin { let Prototype = "void(...)"; } +def ElementwiseFmod : Builtin { + let Spellings = ["__builtin_elementwise_fmod"]; + let Attributes = [NoThrow, Const, CustomTypeChecking]; + let Prototype = "void(...)"; +} + def ElementwisePow : Builtin { let Spellings = ["__builtin_elementwise_pow"]; let Attributes = [NoThrow, Const, CustomTypeChecking]; diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 249aead33ad73d..b57a2f25c21255 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -2878,7 +2878,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, case Builtin::BI__builtin_fmodf: case Builtin::BI__builtin_fmodf16: case Builtin::BI__builtin_fmodl: -case Builtin::BI__builtin_fmodf128: { +case Builtin::BI__builtin_fmodf128: +case Builtin::BI__builtin_elementwise_fmod: { CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E); Value *Arg1 = EmitScalarExpr(E->getArg(0)); Value *Arg2 = EmitScalarExpr(E->getArg(1)); diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h index b139f9eb7d999b..aa7c61d3d7a6a7 100644 --
[clang] [HLSL] Implementation of the elementwise fmod builtin (PR #108849)
lizhengxing wrote: > change the title of this PR to remove the word intrinsic. That word has a > specific meaning in LLVM and folks might get confused. Something like: > `[HLSL] Implementation of the fmod API`. > > If you really want to use the word intrinsic then just reuse the HLSL keyword > so HLSL is a modifier to specify the kind of intrinsic: `[HLSL] > Implementation of the fmod HLSL intrinsic`. Done. Renamed it to `[HLSL] Implementation of the elementwise fmod builtin` . https://github.com/llvm/llvm-project/pull/108849 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implementation of the elementwise fmod builtin (PR #108849)
lizhengxing wrote: > This LGTM. There is one last thing we might want to do. But I'm not requiring > it for sign off. We ussually add elementwise math builtins here: > > * `clang/test/CodeGen/builtins-elementwise-math.c` > * `clang/test/CodeGen/strictfp-elementwise-bulitins.cpp` > * `clang/test/Sema/builtins-elementwise-math.c` > * `clang/test/SemaCXX/builtins-elementwise-math.cpp` > > Also I'd take a look at the existing fmod test cases and make sure there is > nothing we need to update there: > > ```shell > clang/test/CodeGen/X86/math-builtins.c:11: f = __builtin_fmod(f,f);f = > __builtin_fmodf(f,f); f = __builtin_fmodl(f,f); f = > __builtin_fmodf128(f,f); > clang/test/CodeGen/builtins.c:318: resd = __builtin_fmod(D,D); > clang/test/CodeGen/constrained-math-builtins.c:11: f = __builtin_fmod(f,f); > f = __builtin_fmodf(f,f); f = __builtin_fmodl(f,f); f = > __builtin_fmodf128(f,f); > clang/test/CodeGenOpenCL/builtins-f16.cl:55: res = __builtin_fmodf16(h0, h1); > ``` Done. https://github.com/llvm/llvm-project/pull/108849 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implementation of the elementwise fmod builtin (PR #108849)
lizhengxing wrote: Done. https://github.com/llvm/llvm-project/pull/108849 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implementation of the elementwise fmod builtin (PR #108849)
https://github.com/lizhengxing updated https://github.com/llvm/llvm-project/pull/108849 >From 9ed71b8fb37dbc72bd5378c3b6be534b7bb51f60 Mon Sep 17 00:00:00 2001 From: Zhengxing Li Date: Fri, 13 Sep 2024 13:19:31 -0700 Subject: [PATCH] [HLSL] Implementation of the elementwise fmod builtin This change add the elementwise fmod builtin to support HLSL function 'fmod' in clang for #99118 Builtins.td - add the fmod builtin CGBuiltin.cpp - lower the builtin to llvm FRem instruction hlsl_intrinsics.h - add the fmod api SemaChecking.cpp - add type checks for builtin SemaHLSL.cpp - add HLSL type checks for builtin clang/docs/LanguageExtensions.rst - add the builtin in *Elementwise Builtins* clang/docs/ReleaseNotes.rst- announce the builtin --- clang/docs/LanguageExtensions.rst | 2 + clang/docs/ReleaseNotes.rst | 2 + clang/include/clang/Basic/Builtins.td | 6 ++ clang/lib/CodeGen/CGBuiltin.cpp | 3 +- clang/lib/Headers/hlsl/hlsl_intrinsics.h | 33 clang/lib/Sema/SemaChecking.cpp | 1 + clang/lib/Sema/SemaHLSL.cpp | 1 + .../test/CodeGen/builtins-elementwise-math.c | 20 + .../CodeGen/strictfp-elementwise-bulitins.cpp | 11 +++ clang/test/CodeGenHLSL/builtins/fmod.hlsl | 77 +++ clang/test/Sema/builtins-elementwise-math.c | 27 ++- .../SemaCXX/builtins-elementwise-math.cpp | 8 ++ clang/test/SemaHLSL/BuiltIns/fmod-errors.hlsl | 22 ++ 13 files changed, 211 insertions(+), 2 deletions(-) create mode 100644 clang/test/CodeGenHLSL/builtins/fmod.hlsl create mode 100644 clang/test/SemaHLSL/BuiltIns/fmod-errors.hlsl diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index 0c6b9b1b8f9ce4..ea4b4bcec55e77 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -700,6 +700,8 @@ Unless specified otherwise operation(±0) = ±0 and operation(±infinity) = ±in T __builtin_elementwise_canonicalize(T x) return the platform specific canonical encoding floating point types of a floating-point number T __builtin_elementwise_copysign(T x, T y) return the magnitude of x with the sign of y.floating point types + T __builtin_elementwise_fmod(T x, T y) return The floating-point remainder of (x/y) whose sign floating point types + matches the sign of x. T __builtin_elementwise_max(T x, T y) return x or y, whichever is larger integer and floating point types T __builtin_elementwise_min(T x, T y) return x or y, whichever is smaller integer and floating point types T __builtin_elementwise_add_sat(T x, T y) return the sum of x and y, clamped to the range of integer types diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 14907e7db18de3..d039636e462a7b 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -123,6 +123,8 @@ C++ Language Changes - Add ``__builtin_elementwise_popcount`` builtin for integer types only. +- Add ``__builtin_elementwise_fmod`` builtin for floating point types only. + - The builtin type alias ``__builtin_common_type`` has been added to improve the performance of ``std::common_type``. diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 8c5d7ad763bf97..0bd8e02cbe73fa 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -1328,6 +1328,12 @@ def ElementwisePopcount : Builtin { let Prototype = "void(...)"; } +def ElementwiseFmod : Builtin { + let Spellings = ["__builtin_elementwise_fmod"]; + let Attributes = [NoThrow, Const, CustomTypeChecking]; + let Prototype = "void(...)"; +} + def ElementwisePow : Builtin { let Spellings = ["__builtin_elementwise_pow"]; let Attributes = [NoThrow, Const, CustomTypeChecking]; diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 9033cd1ccd781d..d739597de4c855 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -2878,7 +2878,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, case Builtin::BI__builtin_fmodf: case Builtin::BI__builtin_fmodf16: case Builtin::BI__builtin_fmodl: -case Builtin::BI__builtin_fmodf128: { +case Builtin::BI__builtin_fmodf128: +case Builtin::BI__builtin_elementwise_fmod: { CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E); Value *Arg1 = EmitScalarExpr(E->getArg(0)); Value *Arg2 = EmitScalarExpr(E->getArg(1)); diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h index b139f9eb7d999b..aa7c61d3d7a6a7 100644 --- a/c
[clang] [HLSL] Implementation of the elementwise fmod builtin (PR #108849)
@@ -1645,6 +1645,18 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) { return true; break; } + case Builtin::BI__builtin_elementwise_fmod: { lizhengxing wrote: Done. https://github.com/llvm/llvm-project/pull/108849 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implementation of the elementwise fmod builtin (PR #108849)
@@ -0,0 +1,37 @@ + +// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -verify-ignore-unexpected + +float test_too_few_arg() { + return __builtin_elementwise_fmod(); + // expected-error@-1 {{too few arguments to function call, expected 2, have 0}} +} + +float2 test_too_many_arg(float2 p0, float2 p1, float2 p3) { lizhengxing wrote: Done. Removed the redundant tests in `clang/test/SemaHLSL/BuiltIns/fmod-errors.hlsl` https://github.com/llvm/llvm-project/pull/108849 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implementation of the elementwise fmod builtin (PR #108849)
https://github.com/lizhengxing updated https://github.com/llvm/llvm-project/pull/108849 >From a48abd93d9261a9026531bfd69aff52b0374d8d8 Mon Sep 17 00:00:00 2001 From: Zhengxing Li Date: Fri, 13 Sep 2024 13:19:31 -0700 Subject: [PATCH] [HLSL] Implementation of the elementwise fmod builtin This change add the elementwise fmod builtin to support HLSL function 'fmod' in clang for #99118 Builtins.td - add the fmod builtin CGBuiltin.cpp - lower the builtin to llvm FRem instruction hlsl_intrinsics.h - add the fmod api SemaChecking.cpp - add type checks for builtin SemaHLSL.cpp - add HLSL type checks for builtin clang/docs/LanguageExtensions.rst - add the builtin in *Elementwise Builtins* clang/docs/ReleaseNotes.rst- announce the builtin --- clang/docs/LanguageExtensions.rst | 2 + clang/docs/ReleaseNotes.rst | 2 + clang/include/clang/Basic/Builtins.td | 6 ++ clang/lib/CodeGen/CGBuiltin.cpp | 3 +- clang/lib/Headers/hlsl/hlsl_intrinsics.h | 34 clang/lib/Sema/SemaChecking.cpp | 1 + clang/lib/Sema/SemaHLSL.cpp | 1 + .../test/CodeGen/builtins-elementwise-math.c | 20 + .../CodeGen/strictfp-elementwise-bulitins.cpp | 11 +++ clang/test/CodeGenHLSL/builtins/fmod.hlsl | 77 +++ clang/test/Sema/builtins-elementwise-math.c | 27 ++- .../SemaCXX/builtins-elementwise-math.cpp | 8 ++ clang/test/SemaHLSL/BuiltIns/fmod-errors.hlsl | 22 ++ 13 files changed, 212 insertions(+), 2 deletions(-) create mode 100644 clang/test/CodeGenHLSL/builtins/fmod.hlsl create mode 100644 clang/test/SemaHLSL/BuiltIns/fmod-errors.hlsl diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index 0c6b9b1b8f9ce4..ea4b4bcec55e77 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -700,6 +700,8 @@ Unless specified otherwise operation(±0) = ±0 and operation(±infinity) = ±in T __builtin_elementwise_canonicalize(T x) return the platform specific canonical encoding floating point types of a floating-point number T __builtin_elementwise_copysign(T x, T y) return the magnitude of x with the sign of y.floating point types + T __builtin_elementwise_fmod(T x, T y) return The floating-point remainder of (x/y) whose sign floating point types + matches the sign of x. T __builtin_elementwise_max(T x, T y) return x or y, whichever is larger integer and floating point types T __builtin_elementwise_min(T x, T y) return x or y, whichever is smaller integer and floating point types T __builtin_elementwise_add_sat(T x, T y) return the sum of x and y, clamped to the range of integer types diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 14907e7db18de3..d039636e462a7b 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -123,6 +123,8 @@ C++ Language Changes - Add ``__builtin_elementwise_popcount`` builtin for integer types only. +- Add ``__builtin_elementwise_fmod`` builtin for floating point types only. + - The builtin type alias ``__builtin_common_type`` has been added to improve the performance of ``std::common_type``. diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 8c5d7ad763bf97..0bd8e02cbe73fa 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -1328,6 +1328,12 @@ def ElementwisePopcount : Builtin { let Prototype = "void(...)"; } +def ElementwiseFmod : Builtin { + let Spellings = ["__builtin_elementwise_fmod"]; + let Attributes = [NoThrow, Const, CustomTypeChecking]; + let Prototype = "void(...)"; +} + def ElementwisePow : Builtin { let Spellings = ["__builtin_elementwise_pow"]; let Attributes = [NoThrow, Const, CustomTypeChecking]; diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 9033cd1ccd781d..d739597de4c855 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -2878,7 +2878,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, case Builtin::BI__builtin_fmodf: case Builtin::BI__builtin_fmodf16: case Builtin::BI__builtin_fmodl: -case Builtin::BI__builtin_fmodf128: { +case Builtin::BI__builtin_fmodf128: +case Builtin::BI__builtin_elementwise_fmod: { CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E); Value *Arg1 = EmitScalarExpr(E->getArg(0)); Value *Arg2 = EmitScalarExpr(E->getArg(1)); diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h index b139f9eb7d999b..eadea2033885da 100644 --- a/c
[clang] [HLSL] Implementation of the elementwise fmod builtin (PR #108849)
https://github.com/lizhengxing updated https://github.com/llvm/llvm-project/pull/108849 >From a48abd93d9261a9026531bfd69aff52b0374d8d8 Mon Sep 17 00:00:00 2001 From: Zhengxing Li Date: Fri, 13 Sep 2024 13:19:31 -0700 Subject: [PATCH] [HLSL] Implementation of the elementwise fmod builtin This change add the elementwise fmod builtin to support HLSL function 'fmod' in clang for #99118 Builtins.td - add the fmod builtin CGBuiltin.cpp - lower the builtin to llvm FRem instruction hlsl_intrinsics.h - add the fmod api SemaChecking.cpp - add type checks for builtin SemaHLSL.cpp - add HLSL type checks for builtin clang/docs/LanguageExtensions.rst - add the builtin in *Elementwise Builtins* clang/docs/ReleaseNotes.rst- announce the builtin --- clang/docs/LanguageExtensions.rst | 2 + clang/docs/ReleaseNotes.rst | 2 + clang/include/clang/Basic/Builtins.td | 6 ++ clang/lib/CodeGen/CGBuiltin.cpp | 3 +- clang/lib/Headers/hlsl/hlsl_intrinsics.h | 34 clang/lib/Sema/SemaChecking.cpp | 1 + clang/lib/Sema/SemaHLSL.cpp | 1 + .../test/CodeGen/builtins-elementwise-math.c | 20 + .../CodeGen/strictfp-elementwise-bulitins.cpp | 11 +++ clang/test/CodeGenHLSL/builtins/fmod.hlsl | 77 +++ clang/test/Sema/builtins-elementwise-math.c | 27 ++- .../SemaCXX/builtins-elementwise-math.cpp | 8 ++ clang/test/SemaHLSL/BuiltIns/fmod-errors.hlsl | 22 ++ 13 files changed, 212 insertions(+), 2 deletions(-) create mode 100644 clang/test/CodeGenHLSL/builtins/fmod.hlsl create mode 100644 clang/test/SemaHLSL/BuiltIns/fmod-errors.hlsl diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index 0c6b9b1b8f9ce4..ea4b4bcec55e77 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -700,6 +700,8 @@ Unless specified otherwise operation(±0) = ±0 and operation(±infinity) = ±in T __builtin_elementwise_canonicalize(T x) return the platform specific canonical encoding floating point types of a floating-point number T __builtin_elementwise_copysign(T x, T y) return the magnitude of x with the sign of y.floating point types + T __builtin_elementwise_fmod(T x, T y) return The floating-point remainder of (x/y) whose sign floating point types + matches the sign of x. T __builtin_elementwise_max(T x, T y) return x or y, whichever is larger integer and floating point types T __builtin_elementwise_min(T x, T y) return x or y, whichever is smaller integer and floating point types T __builtin_elementwise_add_sat(T x, T y) return the sum of x and y, clamped to the range of integer types diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 14907e7db18de3..d039636e462a7b 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -123,6 +123,8 @@ C++ Language Changes - Add ``__builtin_elementwise_popcount`` builtin for integer types only. +- Add ``__builtin_elementwise_fmod`` builtin for floating point types only. + - The builtin type alias ``__builtin_common_type`` has been added to improve the performance of ``std::common_type``. diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 8c5d7ad763bf97..0bd8e02cbe73fa 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -1328,6 +1328,12 @@ def ElementwisePopcount : Builtin { let Prototype = "void(...)"; } +def ElementwiseFmod : Builtin { + let Spellings = ["__builtin_elementwise_fmod"]; + let Attributes = [NoThrow, Const, CustomTypeChecking]; + let Prototype = "void(...)"; +} + def ElementwisePow : Builtin { let Spellings = ["__builtin_elementwise_pow"]; let Attributes = [NoThrow, Const, CustomTypeChecking]; diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 9033cd1ccd781d..d739597de4c855 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -2878,7 +2878,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, case Builtin::BI__builtin_fmodf: case Builtin::BI__builtin_fmodf16: case Builtin::BI__builtin_fmodl: -case Builtin::BI__builtin_fmodf128: { +case Builtin::BI__builtin_fmodf128: +case Builtin::BI__builtin_elementwise_fmod: { CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E); Value *Arg1 = EmitScalarExpr(E->getArg(0)); Value *Arg2 = EmitScalarExpr(E->getArg(1)); diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h index b139f9eb7d999b..eadea2033885da 100644 --- a/c
[clang] [HLSL] Implementation of the elementwise fmod builtin (PR #108849)
lizhengxing wrote: @farzonl Could you help to merge this PR? The 2 failing checks are in libc++ since yesterday. It might be caused by [#107638](https://github.com/llvm/llvm-project/pull/107638). @hekota pinged the authors of [#107638](https://github.com/llvm/llvm-project/pull/107638) to see if they think it might be related. https://github.com/llvm/llvm-project/pull/108849 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implementation of the elementwise fmod builtin (PR #108849)
https://github.com/lizhengxing updated https://github.com/llvm/llvm-project/pull/108849 >From 96a8f95b6e6cc9b59c856afc3297454ede241487 Mon Sep 17 00:00:00 2001 From: Zhengxing Li Date: Fri, 13 Sep 2024 13:19:31 -0700 Subject: [PATCH] [HLSL] Implementation of the elementwise fmod builtin This change add the elementwise fmod builtin to support HLSL function 'fmod' in clang for #99118 Builtins.td - add the fmod builtin CGBuiltin.cpp - lower the builtin to llvm FRem instruction hlsl_intrinsics.h - add the fmod api SemaChecking.cpp - add type checks for builtin SemaHLSL.cpp - add HLSL type checks for builtin clang/docs/LanguageExtensions.rst - add the builtin in *Elementwise Builtins* clang/docs/ReleaseNotes.rst- announce the builtin --- clang/docs/LanguageExtensions.rst | 2 + clang/docs/ReleaseNotes.rst | 2 + clang/include/clang/Basic/Builtins.td | 6 ++ clang/lib/CodeGen/CGBuiltin.cpp | 3 +- clang/lib/Headers/hlsl/hlsl_intrinsics.h | 34 clang/lib/Sema/SemaChecking.cpp | 1 + clang/lib/Sema/SemaHLSL.cpp | 1 + .../test/CodeGen/builtins-elementwise-math.c | 20 + .../CodeGen/strictfp-elementwise-bulitins.cpp | 11 +++ clang/test/CodeGenHLSL/builtins/fmod.hlsl | 77 +++ clang/test/Sema/builtins-elementwise-math.c | 27 ++- .../SemaCXX/builtins-elementwise-math.cpp | 8 ++ clang/test/SemaHLSL/BuiltIns/fmod-errors.hlsl | 22 ++ 13 files changed, 212 insertions(+), 2 deletions(-) create mode 100644 clang/test/CodeGenHLSL/builtins/fmod.hlsl create mode 100644 clang/test/SemaHLSL/BuiltIns/fmod-errors.hlsl diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index 0c6b9b1b8f9ce4..ea4b4bcec55e77 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -700,6 +700,8 @@ Unless specified otherwise operation(±0) = ±0 and operation(±infinity) = ±in T __builtin_elementwise_canonicalize(T x) return the platform specific canonical encoding floating point types of a floating-point number T __builtin_elementwise_copysign(T x, T y) return the magnitude of x with the sign of y.floating point types + T __builtin_elementwise_fmod(T x, T y) return The floating-point remainder of (x/y) whose sign floating point types + matches the sign of x. T __builtin_elementwise_max(T x, T y) return x or y, whichever is larger integer and floating point types T __builtin_elementwise_min(T x, T y) return x or y, whichever is smaller integer and floating point types T __builtin_elementwise_add_sat(T x, T y) return the sum of x and y, clamped to the range of integer types diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 1fbcac807d0b30..2e9560f553d94f 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -141,6 +141,8 @@ C++ Language Changes - Add ``__builtin_elementwise_popcount`` builtin for integer types only. +- Add ``__builtin_elementwise_fmod`` builtin for floating point types only. + - The builtin type alias ``__builtin_common_type`` has been added to improve the performance of ``std::common_type``. diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td index 33791270800c9d..8090119e512fbb 100644 --- a/clang/include/clang/Basic/Builtins.td +++ b/clang/include/clang/Basic/Builtins.td @@ -1328,6 +1328,12 @@ def ElementwisePopcount : Builtin { let Prototype = "void(...)"; } +def ElementwiseFmod : Builtin { + let Spellings = ["__builtin_elementwise_fmod"]; + let Attributes = [NoThrow, Const, CustomTypeChecking]; + let Prototype = "void(...)"; +} + def ElementwisePow : Builtin { let Spellings = ["__builtin_elementwise_pow"]; let Attributes = [NoThrow, Const, CustomTypeChecking]; diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 9033cd1ccd781d..d739597de4c855 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -2878,7 +2878,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, case Builtin::BI__builtin_fmodf: case Builtin::BI__builtin_fmodf16: case Builtin::BI__builtin_fmodl: -case Builtin::BI__builtin_fmodf128: { +case Builtin::BI__builtin_fmodf128: +case Builtin::BI__builtin_elementwise_fmod: { CodeGenFunction::CGFPOptionsRAII FPOptsRAII(*this, E); Value *Arg1 = EmitScalarExpr(E->getArg(0)); Value *Arg2 = EmitScalarExpr(E->getArg(1)); diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h index b139f9eb7d999b..eadea2033885da 100644 --- a/c
[clang] [HLSL] Implement SV_GroupID semantic (PR #115911)
https://github.com/lizhengxing updated https://github.com/llvm/llvm-project/pull/115911 >From 6418461717614d5879688d32a0ab9bf9d9137328 Mon Sep 17 00:00:00 2001 From: Zhengxing Li Date: Tue, 1 Oct 2024 15:13:34 -0700 Subject: [PATCH 1/4] [HLSL] Implement SV_GroupID semantic Support SV_GroupID attribute. Translate it into dx.group.id in clang codeGen. Fixes: #70120 --- clang/include/clang/Basic/Attr.td | 7 ++ clang/include/clang/Basic/AttrDocs.td | 11 clang/include/clang/Sema/SemaHLSL.h | 1 + clang/lib/CodeGen/CGHLSLRuntime.cpp | 4 +++ clang/lib/Parse/ParseHLSL.cpp | 1 + clang/lib/Sema/SemaDeclAttr.cpp | 3 +++ clang/lib/Sema/SemaHLSL.cpp | 16 ++-- .../CodeGenHLSL/semantics/SV_GroupID.hlsl | 21 .../SemaHLSL/Semantics/entry_parameter.hlsl | 11 +--- .../Semantics/invalid_entry_parameter.hlsl| 22 .../Semantics/valid_entry_parameter.hlsl | 25 +++ 11 files changed, 116 insertions(+), 6 deletions(-) create mode 100644 clang/test/CodeGenHLSL/semantics/SV_GroupID.hlsl diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index a631e81d40aa68..52df814deecc02 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -4587,6 +4587,13 @@ def HLSLNumThreads: InheritableAttr { let Documentation = [NumThreadsDocs]; } +def HLSLSV_GroupID: HLSLAnnotationAttr { + let Spellings = [HLSLAnnotation<"SV_GroupID">]; + let Subjects = SubjectList<[ParmVar, Field]>; + let LangOpts = [HLSL]; + let Documentation = [HLSLSV_GroupIDDocs]; +} + def HLSLSV_GroupIndex: HLSLAnnotationAttr { let Spellings = [HLSLAnnotation<"SV_GroupIndex">]; let Subjects = SubjectList<[ParmVar, GlobalVar]>; diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index b64dbef6332e6a..0a20f87d0ddb37 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -7816,6 +7816,17 @@ randomized. }]; } +def HLSLSV_GroupIDDocs : Documentation { + let Category = DocCatFunction; + let Content = [{ +The ``SV_GroupID`` semantic, when applied to an input parameter, specifies a +data binding to map the group id to the specified parameter. This attribute is +only supported in compute shaders. + +The full documentation is available here: https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/sv-groupid + }]; +} + def HLSLSV_GroupIndexDocs : Documentation { let Category = DocCatFunction; let Content = [{ diff --git a/clang/include/clang/Sema/SemaHLSL.h b/clang/include/clang/Sema/SemaHLSL.h index 06c541dec08cc8..f36b46d0c7ad43 100644 --- a/clang/include/clang/Sema/SemaHLSL.h +++ b/clang/include/clang/Sema/SemaHLSL.h @@ -119,6 +119,7 @@ class SemaHLSL : public SemaBase { void handleNumThreadsAttr(Decl *D, const ParsedAttr &AL); void handleWaveSizeAttr(Decl *D, const ParsedAttr &AL); void handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL); + void handleSV_GroupIDAttr(Decl *D, const ParsedAttr &AL); void handlePackOffsetAttr(Decl *D, const ParsedAttr &AL); void handleShaderAttr(Decl *D, const ParsedAttr &AL); void handleResourceBindingAttr(Decl *D, const ParsedAttr &AL); diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp index 7ba0d615018181..2c293523fca8ca 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -389,6 +389,10 @@ llvm::Value *CGHLSLRuntime::emitInputSemantic(IRBuilder<> &B, CGM.getIntrinsic(getThreadIdIntrinsic()); return buildVectorInput(B, ThreadIDIntrinsic, Ty); } + if (D.hasAttr()) { +llvm::Function *GroupIDIntrinsic = CGM.getIntrinsic(Intrinsic::dx_group_id); +return buildVectorInput(B, GroupIDIntrinsic, Ty); + } assert(false && "Unhandled parameter attribute"); return nullptr; } diff --git a/clang/lib/Parse/ParseHLSL.cpp b/clang/lib/Parse/ParseHLSL.cpp index b36ea4012c26e1..2f67718f94c68c 100644 --- a/clang/lib/Parse/ParseHLSL.cpp +++ b/clang/lib/Parse/ParseHLSL.cpp @@ -280,6 +280,7 @@ void Parser::ParseHLSLAnnotations(ParsedAttributes &Attrs, case ParsedAttr::UnknownAttribute: Diag(Loc, diag::err_unknown_hlsl_semantic) << II; return; + case ParsedAttr::AT_HLSLSV_GroupID: case ParsedAttr::AT_HLSLSV_GroupIndex: case ParsedAttr::AT_HLSLSV_DispatchThreadID: break; diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index d05d326178e1b8..cea51bd507f288 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -6990,6 +6990,9 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL, case ParsedAttr::AT_HLSLWaveSize: S.HLSL().handleWaveSizeAttr(D, AL); break; + case ParsedAttr::AT_HLSLSV_GroupID: +S.HLSL().handleSV_GroupIDAttr(D, AL); +b
[clang] [HLSL] Implement SV_GroupID semantic (PR #115911)
@@ -784,6 +785,17 @@ void SemaHLSL::handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL) { HLSLSV_DispatchThreadIDAttr(getASTContext(), AL)); } +void SemaHLSL::handleSV_GroupIDAttr(Decl *D, const ParsedAttr &AL) { + auto *VD = cast(D); + if (!isLegalTypeForHLSLSV_ThreadOrGroupID(VD->getType())) { +Diag(AL.getLoc(), diag::err_hlsl_attr_invalid_type) +<< AL << "uint/uint2/uint3"; lizhengxing wrote: @llvm-beanz Done. Renamed the function name to `diagnoseInputIDType` https://github.com/llvm/llvm-project/pull/115911 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implement SV_GroupID semantic (PR #115911)
https://github.com/lizhengxing updated https://github.com/llvm/llvm-project/pull/115911 >From 6418461717614d5879688d32a0ab9bf9d9137328 Mon Sep 17 00:00:00 2001 From: Zhengxing Li Date: Tue, 1 Oct 2024 15:13:34 -0700 Subject: [PATCH 1/2] [HLSL] Implement SV_GroupID semantic Support SV_GroupID attribute. Translate it into dx.group.id in clang codeGen. Fixes: #70120 --- clang/include/clang/Basic/Attr.td | 7 ++ clang/include/clang/Basic/AttrDocs.td | 11 clang/include/clang/Sema/SemaHLSL.h | 1 + clang/lib/CodeGen/CGHLSLRuntime.cpp | 4 +++ clang/lib/Parse/ParseHLSL.cpp | 1 + clang/lib/Sema/SemaDeclAttr.cpp | 3 +++ clang/lib/Sema/SemaHLSL.cpp | 16 ++-- .../CodeGenHLSL/semantics/SV_GroupID.hlsl | 21 .../SemaHLSL/Semantics/entry_parameter.hlsl | 11 +--- .../Semantics/invalid_entry_parameter.hlsl| 22 .../Semantics/valid_entry_parameter.hlsl | 25 +++ 11 files changed, 116 insertions(+), 6 deletions(-) create mode 100644 clang/test/CodeGenHLSL/semantics/SV_GroupID.hlsl diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index a631e81d40aa68..52df814deecc02 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -4587,6 +4587,13 @@ def HLSLNumThreads: InheritableAttr { let Documentation = [NumThreadsDocs]; } +def HLSLSV_GroupID: HLSLAnnotationAttr { + let Spellings = [HLSLAnnotation<"SV_GroupID">]; + let Subjects = SubjectList<[ParmVar, Field]>; + let LangOpts = [HLSL]; + let Documentation = [HLSLSV_GroupIDDocs]; +} + def HLSLSV_GroupIndex: HLSLAnnotationAttr { let Spellings = [HLSLAnnotation<"SV_GroupIndex">]; let Subjects = SubjectList<[ParmVar, GlobalVar]>; diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index b64dbef6332e6a..0a20f87d0ddb37 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -7816,6 +7816,17 @@ randomized. }]; } +def HLSLSV_GroupIDDocs : Documentation { + let Category = DocCatFunction; + let Content = [{ +The ``SV_GroupID`` semantic, when applied to an input parameter, specifies a +data binding to map the group id to the specified parameter. This attribute is +only supported in compute shaders. + +The full documentation is available here: https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/sv-groupid + }]; +} + def HLSLSV_GroupIndexDocs : Documentation { let Category = DocCatFunction; let Content = [{ diff --git a/clang/include/clang/Sema/SemaHLSL.h b/clang/include/clang/Sema/SemaHLSL.h index 06c541dec08cc8..f36b46d0c7ad43 100644 --- a/clang/include/clang/Sema/SemaHLSL.h +++ b/clang/include/clang/Sema/SemaHLSL.h @@ -119,6 +119,7 @@ class SemaHLSL : public SemaBase { void handleNumThreadsAttr(Decl *D, const ParsedAttr &AL); void handleWaveSizeAttr(Decl *D, const ParsedAttr &AL); void handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL); + void handleSV_GroupIDAttr(Decl *D, const ParsedAttr &AL); void handlePackOffsetAttr(Decl *D, const ParsedAttr &AL); void handleShaderAttr(Decl *D, const ParsedAttr &AL); void handleResourceBindingAttr(Decl *D, const ParsedAttr &AL); diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp index 7ba0d615018181..2c293523fca8ca 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -389,6 +389,10 @@ llvm::Value *CGHLSLRuntime::emitInputSemantic(IRBuilder<> &B, CGM.getIntrinsic(getThreadIdIntrinsic()); return buildVectorInput(B, ThreadIDIntrinsic, Ty); } + if (D.hasAttr()) { +llvm::Function *GroupIDIntrinsic = CGM.getIntrinsic(Intrinsic::dx_group_id); +return buildVectorInput(B, GroupIDIntrinsic, Ty); + } assert(false && "Unhandled parameter attribute"); return nullptr; } diff --git a/clang/lib/Parse/ParseHLSL.cpp b/clang/lib/Parse/ParseHLSL.cpp index b36ea4012c26e1..2f67718f94c68c 100644 --- a/clang/lib/Parse/ParseHLSL.cpp +++ b/clang/lib/Parse/ParseHLSL.cpp @@ -280,6 +280,7 @@ void Parser::ParseHLSLAnnotations(ParsedAttributes &Attrs, case ParsedAttr::UnknownAttribute: Diag(Loc, diag::err_unknown_hlsl_semantic) << II; return; + case ParsedAttr::AT_HLSLSV_GroupID: case ParsedAttr::AT_HLSLSV_GroupIndex: case ParsedAttr::AT_HLSLSV_DispatchThreadID: break; diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index d05d326178e1b8..cea51bd507f288 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -6990,6 +6990,9 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL, case ParsedAttr::AT_HLSLWaveSize: S.HLSL().handleWaveSizeAttr(D, AL); break; + case ParsedAttr::AT_HLSLSV_GroupID: +S.HLSL().handleSV_GroupIDAttr(D, AL); +b
[clang] [HLSL] Implement SV_GroupID semantic (PR #115911)
https://github.com/lizhengxing updated https://github.com/llvm/llvm-project/pull/115911 >From 6418461717614d5879688d32a0ab9bf9d9137328 Mon Sep 17 00:00:00 2001 From: Zhengxing Li Date: Tue, 1 Oct 2024 15:13:34 -0700 Subject: [PATCH 1/3] [HLSL] Implement SV_GroupID semantic Support SV_GroupID attribute. Translate it into dx.group.id in clang codeGen. Fixes: #70120 --- clang/include/clang/Basic/Attr.td | 7 ++ clang/include/clang/Basic/AttrDocs.td | 11 clang/include/clang/Sema/SemaHLSL.h | 1 + clang/lib/CodeGen/CGHLSLRuntime.cpp | 4 +++ clang/lib/Parse/ParseHLSL.cpp | 1 + clang/lib/Sema/SemaDeclAttr.cpp | 3 +++ clang/lib/Sema/SemaHLSL.cpp | 16 ++-- .../CodeGenHLSL/semantics/SV_GroupID.hlsl | 21 .../SemaHLSL/Semantics/entry_parameter.hlsl | 11 +--- .../Semantics/invalid_entry_parameter.hlsl| 22 .../Semantics/valid_entry_parameter.hlsl | 25 +++ 11 files changed, 116 insertions(+), 6 deletions(-) create mode 100644 clang/test/CodeGenHLSL/semantics/SV_GroupID.hlsl diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index a631e81d40aa68..52df814deecc02 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -4587,6 +4587,13 @@ def HLSLNumThreads: InheritableAttr { let Documentation = [NumThreadsDocs]; } +def HLSLSV_GroupID: HLSLAnnotationAttr { + let Spellings = [HLSLAnnotation<"SV_GroupID">]; + let Subjects = SubjectList<[ParmVar, Field]>; + let LangOpts = [HLSL]; + let Documentation = [HLSLSV_GroupIDDocs]; +} + def HLSLSV_GroupIndex: HLSLAnnotationAttr { let Spellings = [HLSLAnnotation<"SV_GroupIndex">]; let Subjects = SubjectList<[ParmVar, GlobalVar]>; diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index b64dbef6332e6a..0a20f87d0ddb37 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -7816,6 +7816,17 @@ randomized. }]; } +def HLSLSV_GroupIDDocs : Documentation { + let Category = DocCatFunction; + let Content = [{ +The ``SV_GroupID`` semantic, when applied to an input parameter, specifies a +data binding to map the group id to the specified parameter. This attribute is +only supported in compute shaders. + +The full documentation is available here: https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/sv-groupid + }]; +} + def HLSLSV_GroupIndexDocs : Documentation { let Category = DocCatFunction; let Content = [{ diff --git a/clang/include/clang/Sema/SemaHLSL.h b/clang/include/clang/Sema/SemaHLSL.h index 06c541dec08cc8..f36b46d0c7ad43 100644 --- a/clang/include/clang/Sema/SemaHLSL.h +++ b/clang/include/clang/Sema/SemaHLSL.h @@ -119,6 +119,7 @@ class SemaHLSL : public SemaBase { void handleNumThreadsAttr(Decl *D, const ParsedAttr &AL); void handleWaveSizeAttr(Decl *D, const ParsedAttr &AL); void handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL); + void handleSV_GroupIDAttr(Decl *D, const ParsedAttr &AL); void handlePackOffsetAttr(Decl *D, const ParsedAttr &AL); void handleShaderAttr(Decl *D, const ParsedAttr &AL); void handleResourceBindingAttr(Decl *D, const ParsedAttr &AL); diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp index 7ba0d615018181..2c293523fca8ca 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -389,6 +389,10 @@ llvm::Value *CGHLSLRuntime::emitInputSemantic(IRBuilder<> &B, CGM.getIntrinsic(getThreadIdIntrinsic()); return buildVectorInput(B, ThreadIDIntrinsic, Ty); } + if (D.hasAttr()) { +llvm::Function *GroupIDIntrinsic = CGM.getIntrinsic(Intrinsic::dx_group_id); +return buildVectorInput(B, GroupIDIntrinsic, Ty); + } assert(false && "Unhandled parameter attribute"); return nullptr; } diff --git a/clang/lib/Parse/ParseHLSL.cpp b/clang/lib/Parse/ParseHLSL.cpp index b36ea4012c26e1..2f67718f94c68c 100644 --- a/clang/lib/Parse/ParseHLSL.cpp +++ b/clang/lib/Parse/ParseHLSL.cpp @@ -280,6 +280,7 @@ void Parser::ParseHLSLAnnotations(ParsedAttributes &Attrs, case ParsedAttr::UnknownAttribute: Diag(Loc, diag::err_unknown_hlsl_semantic) << II; return; + case ParsedAttr::AT_HLSLSV_GroupID: case ParsedAttr::AT_HLSLSV_GroupIndex: case ParsedAttr::AT_HLSLSV_DispatchThreadID: break; diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index d05d326178e1b8..cea51bd507f288 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -6990,6 +6990,9 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const ParsedAttr &AL, case ParsedAttr::AT_HLSLWaveSize: S.HLSL().handleWaveSizeAttr(D, AL); break; + case ParsedAttr::AT_HLSLSV_GroupID: +S.HLSL().handleSV_GroupIDAttr(D, AL); +b
[clang] [HLSL] Implement SV_GroupThreadId semantic (PR #117781)
https://github.com/lizhengxing ready_for_review https://github.com/llvm/llvm-project/pull/117781 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implement SV_GroupThreadId semantic (PR #117781)
https://github.com/lizhengxing created https://github.com/llvm/llvm-project/pull/117781 Support SV_GroupThreadId attribute. Translate it into dx.thread.id.in.group in clang codeGen. Fixes: #70122 >From 9d5ffe00f2a1093ca2c28cce184cad0324f53de2 Mon Sep 17 00:00:00 2001 From: Zhengxing Li Date: Wed, 13 Nov 2024 10:54:16 -0800 Subject: [PATCH] [HLSL] Implement SV_GroupThreadId semantic Support SV_GroupThreadId attribute. Translate it into dx.thread.id.in.group in clang codeGen. Fixes: #70122 --- clang/include/clang/Basic/Attr.td | 7 clang/include/clang/Basic/AttrDocs.td | 11 +++ clang/include/clang/Sema/SemaHLSL.h | 1 + clang/lib/CodeGen/CGHLSLRuntime.cpp | 5 +++ clang/lib/Parse/ParseHLSL.cpp | 1 + clang/lib/Sema/SemaDeclAttr.cpp | 3 ++ clang/lib/Sema/SemaHLSL.cpp | 10 ++ .../semantics/SV_GroupThreadID.hlsl | 32 +++ .../SemaHLSL/Semantics/entry_parameter.hlsl | 13 +--- .../Semantics/invalid_entry_parameter.hlsl| 22 + .../Semantics/valid_entry_parameter.hlsl | 25 +++ 11 files changed, 125 insertions(+), 5 deletions(-) create mode 100644 clang/test/CodeGenHLSL/semantics/SV_GroupThreadID.hlsl diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index b055cbd769bb50..9c8e27c0f34e93 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -4621,6 +4621,13 @@ def HLSLNumThreads: InheritableAttr { let Documentation = [NumThreadsDocs]; } +def HLSLSV_GroupThreadID: HLSLAnnotationAttr { + let Spellings = [HLSLAnnotation<"SV_GroupThreadID">]; + let Subjects = SubjectList<[ParmVar, Field]>; + let LangOpts = [HLSL]; + let Documentation = [HLSLSV_GroupThreadIDDocs]; +} + def HLSLSV_GroupID: HLSLAnnotationAttr { let Spellings = [HLSLAnnotation<"SV_GroupID">]; let Subjects = SubjectList<[ParmVar, Field]>; diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index aafd4449e47004..88bf9a020586ea 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -7934,6 +7934,17 @@ randomized. }]; } +def HLSLSV_GroupThreadIDDocs : Documentation { + let Category = DocCatFunction; + let Content = [{ +The ``SV_GroupThreadID`` semantic, when applied to an input parameter, specifies which +individual thread within a thread group is executing in. This attribute is +only supported in compute shaders. + +The full documentation is available here: https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/sv-groupthreadid + }]; +} + def HLSLSV_GroupIDDocs : Documentation { let Category = DocCatFunction; let Content = [{ diff --git a/clang/include/clang/Sema/SemaHLSL.h b/clang/include/clang/Sema/SemaHLSL.h index ee685d95c96154..f4cd11f423a84a 100644 --- a/clang/include/clang/Sema/SemaHLSL.h +++ b/clang/include/clang/Sema/SemaHLSL.h @@ -119,6 +119,7 @@ class SemaHLSL : public SemaBase { void handleNumThreadsAttr(Decl *D, const ParsedAttr &AL); void handleWaveSizeAttr(Decl *D, const ParsedAttr &AL); void handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL); + void handleSV_GroupThreadIDAttr(Decl *D, const ParsedAttr &AL); void handleSV_GroupIDAttr(Decl *D, const ParsedAttr &AL); void handlePackOffsetAttr(Decl *D, const ParsedAttr &AL); void handleShaderAttr(Decl *D, const ParsedAttr &AL); diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp index 2c293523fca8ca..19db7faddaeac0 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -389,6 +389,11 @@ llvm::Value *CGHLSLRuntime::emitInputSemantic(IRBuilder<> &B, CGM.getIntrinsic(getThreadIdIntrinsic()); return buildVectorInput(B, ThreadIDIntrinsic, Ty); } + if (D.hasAttr()) { +llvm::Function *GroupThreadIDIntrinsic = +CGM.getIntrinsic(Intrinsic::dx_thread_id_in_group); +return buildVectorInput(B, GroupThreadIDIntrinsic, Ty); + } if (D.hasAttr()) { llvm::Function *GroupIDIntrinsic = CGM.getIntrinsic(Intrinsic::dx_group_id); return buildVectorInput(B, GroupIDIntrinsic, Ty); diff --git a/clang/lib/Parse/ParseHLSL.cpp b/clang/lib/Parse/ParseHLSL.cpp index 4de342b63ed802..443bf2b9ec626a 100644 --- a/clang/lib/Parse/ParseHLSL.cpp +++ b/clang/lib/Parse/ParseHLSL.cpp @@ -280,6 +280,7 @@ void Parser::ParseHLSLAnnotations(ParsedAttributes &Attrs, case ParsedAttr::UnknownAttribute: Diag(Loc, diag::err_unknown_hlsl_semantic) << II; return; + case ParsedAttr::AT_HLSLSV_GroupThreadID: case ParsedAttr::AT_HLSLSV_GroupID: case ParsedAttr::AT_HLSLSV_GroupIndex: case ParsedAttr::AT_HLSLSV_DispatchThreadID: diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 53cc8cb6afd7dc..47e946c3ee64bc 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema
[clang] [HLSL] Implement SV_GroupID semantic (PR #115911)
https://github.com/lizhengxing edited https://github.com/llvm/llvm-project/pull/115911 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implement SV_GroupID semantic (PR #115911)
@@ -27,3 +27,25 @@ struct ST2 { static uint X : SV_DispatchThreadID; uint s : SV_DispatchThreadID; }; + +[numthreads(8,8,1)] +// expected-error@+1 {{attribute 'SV_GroupID' only applies to a field or parameter of type 'uint/uint2/uint3'}} +void CSMain_GID(float ID : SV_GroupID) { +} + +[numthreads(8,8,1)] +// expected-error@+1 {{attribute 'SV_GroupID' only applies to a field or parameter of type 'uint/uint2/uint3'}} +void CSMain2_GID(ST GID : SV_GroupID) { + +} + +void foo_GID() { +// expected-warning@+1 {{'SV_GroupID' attribute only applies to parameters and non-static data members}} + uint GIS : SV_GroupID; +} + +struct ST2_GID { +// expected-warning@+1 {{'SV_GroupID' attribute only applies to parameters and non-static data members}} +static uint GID : SV_GroupID; +uint s_gid : SV_GroupID; +}; lizhengxing wrote: Added new line at EOF. https://github.com/llvm/llvm-project/pull/115911 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implement SV_GroupID semantic (PR #115911)
@@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm -finclude-default-header -disable-llvm-passes -o - %s | FileCheck %s + +// Make sure SV_GroupID translated into dx.group.id. + +// CHECK: define void @foo() +// CHECK: %[[#ID:]] = call i32 @llvm.dx.group.id(i32 0) +// CHECK: call void @{{.*}}foo{{.*}}(i32 %[[#ID]]) +[shader("compute")] +[numthreads(8,8,1)] +void foo(uint Idx : SV_GroupID) {} + +// CHECK: define void @bar() +// CHECK: %[[#ID_X:]] = call i32 @llvm.dx.group.id(i32 0) +// CHECK: %[[#ID_X_:]] = insertelement <2 x i32> poison, i32 %[[#ID_X]], i64 0 +// CHECK: %[[#ID_Y:]] = call i32 @llvm.dx.group.id(i32 1) +// CHECK: %[[#ID_XY:]] = insertelement <2 x i32> %[[#ID_X_]], i32 %[[#ID_Y]], i64 1 +// CHECK: call void @{{.*}}bar{{.*}}(<2 x i32> %[[#ID_XY]]) +[shader("compute")] +[numthreads(8,8,1)] +void bar(uint2 Idx : SV_GroupID) {} lizhengxing wrote: Add the unit3 case in the test. https://github.com/llvm/llvm-project/pull/115911 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implement SV_GroupThreadId semantic (PR #117781)
@@ -2,15 +2,18 @@ // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-mesh -hlsl-entry CSMain -x hlsl -finclude-default-header -verify -o - %s [numthreads(8,8,1)] -// expected-error@+3 {{attribute 'SV_GroupIndex' is unsupported in 'mesh' shaders, requires compute}} -// expected-error@+2 {{attribute 'SV_DispatchThreadID' is unsupported in 'mesh' shaders, requires compute}} -// expected-error@+1 {{attribute 'SV_GroupID' is unsupported in 'mesh' shaders, requires compute}} -void CSMain(int GI : SV_GroupIndex, uint ID : SV_DispatchThreadID, uint GID : SV_GroupID) { -// CHECK: FunctionDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> line:[[@LINE-1]]:6 CSMain 'void (int, uint, uint)' +// expected-error@+4 {{attribute 'SV_GroupIndex' is unsupported in 'mesh' shaders, requires compute}} +// expected-error@+3 {{attribute 'SV_DispatchThreadID' is unsupported in 'mesh' shaders, requires compute}} +// expected-error@+2 {{attribute 'SV_GroupID' is unsupported in 'mesh' shaders, requires compute}} +// expected-error@+1 {{attribute 'SV_GroupThreadID' is unsupported in 'mesh' shaders, requires compute}} +void CSMain(int GI : SV_GroupIndex, uint ID : SV_DispatchThreadID, uint GID : SV_GroupID, uint GThreadID : SV_GroupThreadID) { lizhengxing wrote: @tex3d It makes sense to me. I'll try to move the non-CS checks into `invalid_entry_parameter.hlsl` https://github.com/llvm/llvm-project/pull/117781 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implement SV_GroupThreadId semantic (PR #117781)
@@ -49,3 +49,28 @@ void CSMain3_GID(uint3 : SV_GroupID) { // CHECK-NEXT: ParmVarDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> col:24 'uint3' // CHECK-NEXT: HLSLSV_GroupIDAttr } + +[numthreads(8,8,1)] +void CSMain_GThreadID(uint ID : SV_GroupThreadID) { +// CHECK: FunctionDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> line:[[@LINE-1]]:6 CSMain_GThreadID 'void (uint)' +// CHECK-NEXT: ParmVarDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> col:28 ID 'uint' +// CHECK-NEXT: HLSLSV_GroupThreadIDAttr +} +[numthreads(8,8,1)] +void CSMain1_GThreadID(uint2 ID : SV_GroupThreadID) { +// CHECK: FunctionDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> line:[[@LINE-1]]:6 CSMain1_GThreadID 'void (uint2)' +// CHECK-NEXT: ParmVarDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> col:30 ID 'uint2' +// CHECK-NEXT: HLSLSV_GroupThreadIDAttr +} +[numthreads(8,8,1)] +void CSMain2_GThreadID(uint3 ID : SV_GroupThreadID) { +// CHECK: FunctionDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> line:[[@LINE-1]]:6 CSMain2_GThreadID 'void (uint3)' +// CHECK-NEXT: ParmVarDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> col:30 ID 'uint3' +// CHECK-NEXT: HLSLSV_GroupThreadIDAttr +} +[numthreads(8,8,1)] +void CSMain3_GThreadID(uint3 : SV_GroupThreadID) { lizhengxing wrote: @inbelic This is for the function which you don't name and don't use an input parameter, but it's still part of the funciton signature. https://github.com/llvm/llvm-project/pull/117781 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implement SV_GroupThreadId semantic (PR #117781)
lizhengxing wrote: > Do we need to consider how spirv handles this? Otherwise, LGTM This PR is similar to the one for SV_GroupID. We don't consider the spirv part for both PRs. https://github.com/llvm/llvm-project/pull/117781 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [HLSL] Implement SV_GroupThreadId semantic (PR #117781)
@@ -2,15 +2,18 @@ // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-mesh -hlsl-entry CSMain -x hlsl -finclude-default-header -verify -o - %s [numthreads(8,8,1)] -// expected-error@+3 {{attribute 'SV_GroupIndex' is unsupported in 'mesh' shaders, requires compute}} -// expected-error@+2 {{attribute 'SV_DispatchThreadID' is unsupported in 'mesh' shaders, requires compute}} -// expected-error@+1 {{attribute 'SV_GroupID' is unsupported in 'mesh' shaders, requires compute}} -void CSMain(int GI : SV_GroupIndex, uint ID : SV_DispatchThreadID, uint GID : SV_GroupID) { -// CHECK: FunctionDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> line:[[@LINE-1]]:6 CSMain 'void (int, uint, uint)' +// expected-error@+4 {{attribute 'SV_GroupIndex' is unsupported in 'mesh' shaders, requires compute}} +// expected-error@+3 {{attribute 'SV_DispatchThreadID' is unsupported in 'mesh' shaders, requires compute}} +// expected-error@+2 {{attribute 'SV_GroupID' is unsupported in 'mesh' shaders, requires compute}} +// expected-error@+1 {{attribute 'SV_GroupThreadID' is unsupported in 'mesh' shaders, requires compute}} +void CSMain(int GI : SV_GroupIndex, uint ID : SV_DispatchThreadID, uint GID : SV_GroupID, uint GThreadID : SV_GroupThreadID) { lizhengxing wrote: @tex3d Yes, you're right. I checked the spec https://microsoft.github.io/DirectX-Specs/d3d/MeshShader.html . Those 4 attributes are legal for the mesh shader. I think that they are legal for the amplification shader as well. It looks like that we did something wrong in `SemaHLSL::CheckSemanticAnnotation` function ``` switch (AnnotationAttr->getKind()) { case attr::HLSLSV_DispatchThreadID: case attr::HLSLSV_GroupIndex: case attr::HLSLSV_GroupThreadID: case attr::HLSLSV_GroupID: if (ST == llvm::Triple::Compute) return; DiagnoseAttrStageMismatch(AnnotationAttr, ST, {llvm::Triple::Compute}); break; ``` We only check `Compute Shader` triple. I think that we should add checks for `Mesh Shader` and `Amplification Shader` triples here. Right? https://github.com/llvm/llvm-project/pull/117781 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement SV_GroupThreadId semantic (PR #117781)
https://github.com/lizhengxing updated https://github.com/llvm/llvm-project/pull/117781 >From 2941d87dbaf091aa443ad57ce55e98e7bab83d2b Mon Sep 17 00:00:00 2001 From: Zhengxing Li Date: Wed, 13 Nov 2024 10:54:16 -0800 Subject: [PATCH 1/4] [HLSL] Implement SV_GroupThreadId semantic Support SV_GroupThreadId attribute. Translate it into dx.thread.id.in.group in clang codeGen. Fixes: #70122 --- clang/include/clang/Basic/Attr.td | 7 clang/include/clang/Basic/AttrDocs.td | 11 +++ clang/include/clang/Sema/SemaHLSL.h | 1 + clang/lib/CodeGen/CGHLSLRuntime.cpp | 5 +++ clang/lib/Parse/ParseHLSL.cpp | 1 + clang/lib/Sema/SemaDeclAttr.cpp | 3 ++ clang/lib/Sema/SemaHLSL.cpp | 10 ++ .../semantics/SV_GroupThreadID.hlsl | 32 +++ .../SemaHLSL/Semantics/entry_parameter.hlsl | 13 +--- .../Semantics/invalid_entry_parameter.hlsl| 22 + .../Semantics/valid_entry_parameter.hlsl | 25 +++ 11 files changed, 125 insertions(+), 5 deletions(-) create mode 100644 clang/test/CodeGenHLSL/semantics/SV_GroupThreadID.hlsl diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 17fc36fbe2ac8c..90d2a2056fe1ba 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -4651,6 +4651,13 @@ def HLSLNumThreads: InheritableAttr { let Documentation = [NumThreadsDocs]; } +def HLSLSV_GroupThreadID: HLSLAnnotationAttr { + let Spellings = [HLSLAnnotation<"SV_GroupThreadID">]; + let Subjects = SubjectList<[ParmVar, Field]>; + let LangOpts = [HLSL]; + let Documentation = [HLSLSV_GroupThreadIDDocs]; +} + def HLSLSV_GroupID: HLSLAnnotationAttr { let Spellings = [HLSLAnnotation<"SV_GroupID">]; let Subjects = SubjectList<[ParmVar, Field]>; diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index 7a82b8fa320590..fdad4c9a3ea191 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -7941,6 +7941,17 @@ randomized. }]; } +def HLSLSV_GroupThreadIDDocs : Documentation { + let Category = DocCatFunction; + let Content = [{ +The ``SV_GroupThreadID`` semantic, when applied to an input parameter, specifies which +individual thread within a thread group is executing in. This attribute is +only supported in compute shaders. + +The full documentation is available here: https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/sv-groupthreadid + }]; +} + def HLSLSV_GroupIDDocs : Documentation { let Category = DocCatFunction; let Content = [{ diff --git a/clang/include/clang/Sema/SemaHLSL.h b/clang/include/clang/Sema/SemaHLSL.h index ee685d95c96154..f4cd11f423a84a 100644 --- a/clang/include/clang/Sema/SemaHLSL.h +++ b/clang/include/clang/Sema/SemaHLSL.h @@ -119,6 +119,7 @@ class SemaHLSL : public SemaBase { void handleNumThreadsAttr(Decl *D, const ParsedAttr &AL); void handleWaveSizeAttr(Decl *D, const ParsedAttr &AL); void handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL); + void handleSV_GroupThreadIDAttr(Decl *D, const ParsedAttr &AL); void handleSV_GroupIDAttr(Decl *D, const ParsedAttr &AL); void handlePackOffsetAttr(Decl *D, const ParsedAttr &AL); void handleShaderAttr(Decl *D, const ParsedAttr &AL); diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp index 2c293523fca8ca..19db7faddaeac0 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -389,6 +389,11 @@ llvm::Value *CGHLSLRuntime::emitInputSemantic(IRBuilder<> &B, CGM.getIntrinsic(getThreadIdIntrinsic()); return buildVectorInput(B, ThreadIDIntrinsic, Ty); } + if (D.hasAttr()) { +llvm::Function *GroupThreadIDIntrinsic = +CGM.getIntrinsic(Intrinsic::dx_thread_id_in_group); +return buildVectorInput(B, GroupThreadIDIntrinsic, Ty); + } if (D.hasAttr()) { llvm::Function *GroupIDIntrinsic = CGM.getIntrinsic(Intrinsic::dx_group_id); return buildVectorInput(B, GroupIDIntrinsic, Ty); diff --git a/clang/lib/Parse/ParseHLSL.cpp b/clang/lib/Parse/ParseHLSL.cpp index 4de342b63ed802..443bf2b9ec626a 100644 --- a/clang/lib/Parse/ParseHLSL.cpp +++ b/clang/lib/Parse/ParseHLSL.cpp @@ -280,6 +280,7 @@ void Parser::ParseHLSLAnnotations(ParsedAttributes &Attrs, case ParsedAttr::UnknownAttribute: Diag(Loc, diag::err_unknown_hlsl_semantic) << II; return; + case ParsedAttr::AT_HLSLSV_GroupThreadID: case ParsedAttr::AT_HLSLSV_GroupID: case ParsedAttr::AT_HLSLSV_GroupIndex: case ParsedAttr::AT_HLSLSV_DispatchThreadID: diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 4fd8ef6dbebf84..5d7ee097383771 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -7114,6 +7114,9 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const Parsed
[clang] [llvm] [HLSL] Implement SV_GroupThreadId semantic (PR #117781)
@@ -3606,6 +3613,32 @@ bool SPIRVInstructionSelector::selectSpvThreadId(Register ResVReg, return Result && MIB.constrainAllUses(TII, TRI, RBI); } +bool SPIRVInstructionSelector::selectSpvThreadId(Register ResVReg, + const SPIRVType *ResType, + MachineInstr &I) const { + // DX intrinsic: @llvm.dx.thread.id(i32) + // ID Name Description + // 93 ThreadId reads the thread ID + // + // In SPIR-V, llvm.dx.thread.id maps to a `GlobalInvocationId` builtin + // variable + return loadVec3BuiltinInputID(SPIRV::BuiltIn::GlobalInvocationId, ResVReg, +ResType, I); lizhengxing wrote: @tex3d Done. Updated the PR based on your comments. https://github.com/llvm/llvm-project/pull/117781 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement SV_GroupThreadId semantic (PR #117781)
@@ -3606,6 +3613,32 @@ bool SPIRVInstructionSelector::selectSpvThreadId(Register ResVReg, return Result && MIB.constrainAllUses(TII, TRI, RBI); } +bool SPIRVInstructionSelector::selectSpvThreadId(Register ResVReg, + const SPIRVType *ResType, + MachineInstr &I) const { + // DX intrinsic: @llvm.dx.thread.id(i32) + // ID Name Description + // 93 ThreadId reads the thread ID + // + // In SPIR-V, llvm.dx.thread.id maps to a `GlobalInvocationId` builtin + // variable lizhengxing wrote: @tex3d Done. The comment was updated in the latest commit of the PR. https://github.com/llvm/llvm-project/pull/117781 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL][SPIR-V] implement SV_GroupID semantic lowering (PR #121521)
@@ -0,0 +1,82 @@ +; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv-vulkan-unknown %s -o - | FileCheck %s +; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-vulkan-unknown %s -o - -filetype=obj | spirv-val %} + +; This file generated from the following command: +; clang -cc1 -triple spirv-vulkan-library -x hlsl -emit-llvm -disable-llvm-passes -finclude-default-header - -o -
[clang] [llvm] [HLSL][SPIR-V] implement SV_GroupID semantic lowering (PR #121521)
https://github.com/lizhengxing updated https://github.com/llvm/llvm-project/pull/121521 >From 21114c408baaa9309e3370d46a4ee196cc4f714a Mon Sep 17 00:00:00 2001 From: Zhengxing Li Date: Thu, 2 Jan 2025 12:30:18 -0800 Subject: [PATCH 1/2] [HLSL][SPIR-V] implement SV_GroupID semantic lowering The HLSL SV_GroupID semantic attribute is lowered into @llvm.spv.group.id intrinsic in LLVM IR for SPIR-V target. In the SPIR-V backend, this is now translated to a `WorkgroupId` builtin variable. Fixes #118700 which's a follow-up work to #70120 --- clang/lib/CodeGen/CGHLSLRuntime.cpp | 2 +- clang/lib/CodeGen/CGHLSLRuntime.h | 1 + .../CodeGenHLSL/semantics/SV_GroupID.hlsl | 34 llvm/include/llvm/IR/IntrinsicsSPIRV.td | 1 + .../Target/SPIRV/SPIRVInstructionSelector.cpp | 8 ++ .../SPIRV/hlsl-intrinsics/SV_GroupID.ll | 82 +++ 6 files changed, 112 insertions(+), 16 deletions(-) create mode 100644 llvm/test/CodeGen/SPIRV/hlsl-intrinsics/SV_GroupID.ll diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp index c354e58e15f4bb..5679bd71581795 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -395,7 +395,7 @@ llvm::Value *CGHLSLRuntime::emitInputSemantic(IRBuilder<> &B, return buildVectorInput(B, GroupThreadIDIntrinsic, Ty); } if (D.hasAttr()) { -llvm::Function *GroupIDIntrinsic = CGM.getIntrinsic(Intrinsic::dx_group_id); +llvm::Function *GroupIDIntrinsic = CGM.getIntrinsic(getGroupIdIntrinsic()); return buildVectorInput(B, GroupIDIntrinsic, Ty); } assert(false && "Unhandled parameter attribute"); diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h b/clang/lib/CodeGen/CGHLSLRuntime.h index edb87f9d5efdf9..3d5724118611cb 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.h +++ b/clang/lib/CodeGen/CGHLSLRuntime.h @@ -87,6 +87,7 @@ class CGHLSLRuntime { GENERATE_HLSL_INTRINSIC_FUNCTION(Radians, radians) GENERATE_HLSL_INTRINSIC_FUNCTION(ThreadId, thread_id) GENERATE_HLSL_INTRINSIC_FUNCTION(GroupThreadId, thread_id_in_group) + GENERATE_HLSL_INTRINSIC_FUNCTION(GroupId, group_id) GENERATE_HLSL_INTRINSIC_FUNCTION(FDot, fdot) GENERATE_HLSL_INTRINSIC_FUNCTION(SDot, sdot) GENERATE_HLSL_INTRINSIC_FUNCTION(UDot, udot) diff --git a/clang/test/CodeGenHLSL/semantics/SV_GroupID.hlsl b/clang/test/CodeGenHLSL/semantics/SV_GroupID.hlsl index 5e09f0fe06d4e6..3aa054afc90451 100644 --- a/clang/test/CodeGenHLSL/semantics/SV_GroupID.hlsl +++ b/clang/test/CodeGenHLSL/semantics/SV_GroupID.hlsl @@ -1,32 +1,36 @@ -// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm -finclude-default-header -disable-llvm-passes -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm -finclude-default-header -disable-llvm-passes -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-DXIL -DTARGET=dx +// RUN: %clang_cc1 -triple spirv-linux-vulkan-library -x hlsl -emit-llvm -finclude-default-header -disable-llvm-passes -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-SPIRV -DTARGET=spv -// Make sure SV_GroupID translated into dx.group.id. +// Make sure SV_GroupID translated into dx.group.id for directx target and spv.group.id for spirv target. -// CHECK: define void @foo() -// CHECK: %[[#ID:]] = call i32 @llvm.dx.group.id(i32 0) -// CHECK: call void @{{.*}}foo{{.*}}(i32 %[[#ID]]) +// CHECK: define void @foo() +// CHECK: %[[#ID:]] = call i32 @llvm.[[TARGET]].group.id(i32 0) +// CHECK-DXIL: call void @{{.*}}foo{{.*}}(i32 %[[#ID]]) +// CHECK-SPIRV: call spir_func void @{{.*}}foo{{.*}}(i32 %[[#ID]]) [shader("compute")] [numthreads(8,8,1)] void foo(uint Idx : SV_GroupID) {} -// CHECK: define void @bar() -// CHECK: %[[#ID_X:]] = call i32 @llvm.dx.group.id(i32 0) -// CHECK: %[[#ID_X_:]] = insertelement <2 x i32> poison, i32 %[[#ID_X]], i64 0 -// CHECK: %[[#ID_Y:]] = call i32 @llvm.dx.group.id(i32 1) -// CHECK: %[[#ID_XY:]] = insertelement <2 x i32> %[[#ID_X_]], i32 %[[#ID_Y]], i64 1 -// CHECK: call void @{{.*}}bar{{.*}}(<2 x i32> %[[#ID_XY]]) +// CHECK: define void @bar() +// CHECK: %[[#ID_X:]] = call i32 @llvm.[[TARGET]].group.id(i32 0) +// CHECK: %[[#ID_X_:]] = insertelement <2 x i32> poison, i32 %[[#ID_X]], i64 0 +// CHECK: %[[#ID_Y:]] = call i32 @llvm.[[TARGET]].group.id(i32 1) +// CHECK: %[[#ID_XY:]] = insertelement <2 x i32> %[[#ID_X_]], i32 %[[#ID_Y]], i64 1 +// CHECK-DXIL: call void @{{.*}}bar{{.*}}(<2 x i32> %[[#ID_XY]]) +// CHECK-SPIRV: call spir_func void @{{.*}}bar{{.*}}(<2 x i32> %[[#ID_XY]]) [shader("compute")] [numthreads(8,8,1)] void bar(uint2 Idx : SV_GroupID) {} // CHECK: define void @test() -// CHECK: %[[#ID_X:]] = call i32 @llvm.dx.group.id(i32 0) +// CHECK: %[[#ID_X:]] = call i32 @llvm.[[TARGET]].group.id(i32 0) // CHECK: %[[#ID_X_:]] = insertelement <3 x i32> poison, i32 %[[#ID_X]], i64 0 -// CHECK: %[[
[clang] [llvm] [HLSL][SPIR-V] implement SV_GroupID semantic lowering (PR #121521)
@@ -0,0 +1,82 @@ +; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv-vulkan-unknown %s -o - | FileCheck %s +; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-vulkan-unknown %s -o - -filetype=obj | spirv-val %} + +; This file generated from the following command: +; clang -cc1 -triple spirv-vulkan-library -x hlsl -emit-llvm -disable-llvm-passes -finclude-default-header - -o -
[clang] [llvm] [HLSL] Implement SV_GroupThreadId semantic (PR #117781)
@@ -2851,7 +2851,21 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register ResVReg, .constrainAllUses(TII, TRI, RBI); break; case Intrinsic::spv_thread_id: -return selectSpvThreadId(ResVReg, ResType, I); +// The HLSL SV_DispatchThreadID semantic is lowered to llvm.spv.thread.id +// intrinsic in LLVM IR for SPIR-V backend. +// +// In SPIR-V backend, llvm.spv.thread.id is now correctly translated to a +// `GlobalInvocationId` builtin variable lizhengxing wrote: @tex3d Those comments are based on the original comments in `selectSpvThreadId` function with minimal changes. They were added by @sudonatalie. If there's no objections from other reviewers, I think it's fine to keep those comments here. https://github.com/llvm/llvm-project/pull/117781 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement SV_GroupThreadId semantic (PR #117781)
https://github.com/lizhengxing updated https://github.com/llvm/llvm-project/pull/117781 >From e66f451e1db4c321acbfac578fa57f286af2fe27 Mon Sep 17 00:00:00 2001 From: Zhengxing Li Date: Wed, 13 Nov 2024 10:54:16 -0800 Subject: [PATCH 1/4] [HLSL] Implement SV_GroupThreadId semantic Support SV_GroupThreadId attribute. Translate it into dx.thread.id.in.group in clang codeGen. Fixes: #70122 --- clang/include/clang/Basic/Attr.td | 7 clang/include/clang/Basic/AttrDocs.td | 11 +++ clang/include/clang/Sema/SemaHLSL.h | 1 + clang/lib/CodeGen/CGHLSLRuntime.cpp | 5 +++ clang/lib/Parse/ParseHLSL.cpp | 1 + clang/lib/Sema/SemaDeclAttr.cpp | 3 ++ clang/lib/Sema/SemaHLSL.cpp | 10 ++ .../semantics/SV_GroupThreadID.hlsl | 32 +++ .../SemaHLSL/Semantics/entry_parameter.hlsl | 13 +--- .../Semantics/invalid_entry_parameter.hlsl| 22 + .../Semantics/valid_entry_parameter.hlsl | 25 +++ 11 files changed, 125 insertions(+), 5 deletions(-) create mode 100644 clang/test/CodeGenHLSL/semantics/SV_GroupThreadID.hlsl diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 17fc36fbe2ac8c..90d2a2056fe1ba 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -4651,6 +4651,13 @@ def HLSLNumThreads: InheritableAttr { let Documentation = [NumThreadsDocs]; } +def HLSLSV_GroupThreadID: HLSLAnnotationAttr { + let Spellings = [HLSLAnnotation<"SV_GroupThreadID">]; + let Subjects = SubjectList<[ParmVar, Field]>; + let LangOpts = [HLSL]; + let Documentation = [HLSLSV_GroupThreadIDDocs]; +} + def HLSLSV_GroupID: HLSLAnnotationAttr { let Spellings = [HLSLAnnotation<"SV_GroupID">]; let Subjects = SubjectList<[ParmVar, Field]>; diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index 7a82b8fa320590..fdad4c9a3ea191 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -7941,6 +7941,17 @@ randomized. }]; } +def HLSLSV_GroupThreadIDDocs : Documentation { + let Category = DocCatFunction; + let Content = [{ +The ``SV_GroupThreadID`` semantic, when applied to an input parameter, specifies which +individual thread within a thread group is executing in. This attribute is +only supported in compute shaders. + +The full documentation is available here: https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/sv-groupthreadid + }]; +} + def HLSLSV_GroupIDDocs : Documentation { let Category = DocCatFunction; let Content = [{ diff --git a/clang/include/clang/Sema/SemaHLSL.h b/clang/include/clang/Sema/SemaHLSL.h index ee685d95c96154..f4cd11f423a84a 100644 --- a/clang/include/clang/Sema/SemaHLSL.h +++ b/clang/include/clang/Sema/SemaHLSL.h @@ -119,6 +119,7 @@ class SemaHLSL : public SemaBase { void handleNumThreadsAttr(Decl *D, const ParsedAttr &AL); void handleWaveSizeAttr(Decl *D, const ParsedAttr &AL); void handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL); + void handleSV_GroupThreadIDAttr(Decl *D, const ParsedAttr &AL); void handleSV_GroupIDAttr(Decl *D, const ParsedAttr &AL); void handlePackOffsetAttr(Decl *D, const ParsedAttr &AL); void handleShaderAttr(Decl *D, const ParsedAttr &AL); diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp index 2c293523fca8ca..19db7faddaeac0 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -389,6 +389,11 @@ llvm::Value *CGHLSLRuntime::emitInputSemantic(IRBuilder<> &B, CGM.getIntrinsic(getThreadIdIntrinsic()); return buildVectorInput(B, ThreadIDIntrinsic, Ty); } + if (D.hasAttr()) { +llvm::Function *GroupThreadIDIntrinsic = +CGM.getIntrinsic(Intrinsic::dx_thread_id_in_group); +return buildVectorInput(B, GroupThreadIDIntrinsic, Ty); + } if (D.hasAttr()) { llvm::Function *GroupIDIntrinsic = CGM.getIntrinsic(Intrinsic::dx_group_id); return buildVectorInput(B, GroupIDIntrinsic, Ty); diff --git a/clang/lib/Parse/ParseHLSL.cpp b/clang/lib/Parse/ParseHLSL.cpp index 4de342b63ed802..443bf2b9ec626a 100644 --- a/clang/lib/Parse/ParseHLSL.cpp +++ b/clang/lib/Parse/ParseHLSL.cpp @@ -280,6 +280,7 @@ void Parser::ParseHLSLAnnotations(ParsedAttributes &Attrs, case ParsedAttr::UnknownAttribute: Diag(Loc, diag::err_unknown_hlsl_semantic) << II; return; + case ParsedAttr::AT_HLSLSV_GroupThreadID: case ParsedAttr::AT_HLSLSV_GroupID: case ParsedAttr::AT_HLSLSV_GroupIndex: case ParsedAttr::AT_HLSLSV_DispatchThreadID: diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 4fd8ef6dbebf84..5d7ee097383771 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -7114,6 +7114,9 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const Parsed
[clang] [llvm] [HLSL] Implement SV_GroupThreadId semantic (PR #117781)
lizhengxing wrote: @sudonatalie Hello Natalie, Could you help review this PR when you're available since it will modify your changes (https://github.com/llvm/llvm-project/pull/82536), Thanks. https://github.com/llvm/llvm-project/pull/117781 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement SV_GroupThreadId semantic (PR #117781)
@@ -3606,6 +3613,32 @@ bool SPIRVInstructionSelector::selectSpvThreadId(Register ResVReg, return Result && MIB.constrainAllUses(TII, TRI, RBI); } +bool SPIRVInstructionSelector::selectSpvThreadId(Register ResVReg, + const SPIRVType *ResType, + MachineInstr &I) const { + // DX intrinsic: @llvm.dx.thread.id(i32) + // ID Name Description + // 93 ThreadId reads the thread ID + // + // In SPIR-V, llvm.dx.thread.id maps to a `GlobalInvocationId` builtin + // variable + return loadVec3BuiltinInputID(SPIRV::BuiltIn::GlobalInvocationId, ResVReg, +ResType, I); lizhengxing wrote: @tex3d Yeah, I noticed this as well. I don't call `loadVec3BuiltinInputID` directly just for keep the change minimal. https://github.com/llvm/llvm-project/pull/117781 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement SV_GroupThreadId semantic (PR #117781)
https://github.com/lizhengxing edited https://github.com/llvm/llvm-project/pull/117781 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL][SPIRV] Implement SV_GroupThreadId semantic (PR #117781)
https://github.com/lizhengxing edited https://github.com/llvm/llvm-project/pull/117781 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement SV_GroupThreadId semantic (PR #117781)
https://github.com/lizhengxing edited https://github.com/llvm/llvm-project/pull/117781 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL][SPIRV] Implement SV_GroupThreadId semantic (PR #117781)
https://github.com/lizhengxing edited https://github.com/llvm/llvm-project/pull/117781 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement SV_GroupThreadId semantic (PR #117781)
https://github.com/lizhengxing edited https://github.com/llvm/llvm-project/pull/117781 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement SV_GroupThreadId semantic (PR #117781)
https://github.com/lizhengxing updated https://github.com/llvm/llvm-project/pull/117781 >From 2941d87dbaf091aa443ad57ce55e98e7bab83d2b Mon Sep 17 00:00:00 2001 From: Zhengxing Li Date: Wed, 13 Nov 2024 10:54:16 -0800 Subject: [PATCH 1/3] [HLSL] Implement SV_GroupThreadId semantic Support SV_GroupThreadId attribute. Translate it into dx.thread.id.in.group in clang codeGen. Fixes: #70122 --- clang/include/clang/Basic/Attr.td | 7 clang/include/clang/Basic/AttrDocs.td | 11 +++ clang/include/clang/Sema/SemaHLSL.h | 1 + clang/lib/CodeGen/CGHLSLRuntime.cpp | 5 +++ clang/lib/Parse/ParseHLSL.cpp | 1 + clang/lib/Sema/SemaDeclAttr.cpp | 3 ++ clang/lib/Sema/SemaHLSL.cpp | 10 ++ .../semantics/SV_GroupThreadID.hlsl | 32 +++ .../SemaHLSL/Semantics/entry_parameter.hlsl | 13 +--- .../Semantics/invalid_entry_parameter.hlsl| 22 + .../Semantics/valid_entry_parameter.hlsl | 25 +++ 11 files changed, 125 insertions(+), 5 deletions(-) create mode 100644 clang/test/CodeGenHLSL/semantics/SV_GroupThreadID.hlsl diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td index 17fc36fbe2ac8c..90d2a2056fe1ba 100644 --- a/clang/include/clang/Basic/Attr.td +++ b/clang/include/clang/Basic/Attr.td @@ -4651,6 +4651,13 @@ def HLSLNumThreads: InheritableAttr { let Documentation = [NumThreadsDocs]; } +def HLSLSV_GroupThreadID: HLSLAnnotationAttr { + let Spellings = [HLSLAnnotation<"SV_GroupThreadID">]; + let Subjects = SubjectList<[ParmVar, Field]>; + let LangOpts = [HLSL]; + let Documentation = [HLSLSV_GroupThreadIDDocs]; +} + def HLSLSV_GroupID: HLSLAnnotationAttr { let Spellings = [HLSLAnnotation<"SV_GroupID">]; let Subjects = SubjectList<[ParmVar, Field]>; diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td index 7a82b8fa320590..fdad4c9a3ea191 100644 --- a/clang/include/clang/Basic/AttrDocs.td +++ b/clang/include/clang/Basic/AttrDocs.td @@ -7941,6 +7941,17 @@ randomized. }]; } +def HLSLSV_GroupThreadIDDocs : Documentation { + let Category = DocCatFunction; + let Content = [{ +The ``SV_GroupThreadID`` semantic, when applied to an input parameter, specifies which +individual thread within a thread group is executing in. This attribute is +only supported in compute shaders. + +The full documentation is available here: https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/sv-groupthreadid + }]; +} + def HLSLSV_GroupIDDocs : Documentation { let Category = DocCatFunction; let Content = [{ diff --git a/clang/include/clang/Sema/SemaHLSL.h b/clang/include/clang/Sema/SemaHLSL.h index ee685d95c96154..f4cd11f423a84a 100644 --- a/clang/include/clang/Sema/SemaHLSL.h +++ b/clang/include/clang/Sema/SemaHLSL.h @@ -119,6 +119,7 @@ class SemaHLSL : public SemaBase { void handleNumThreadsAttr(Decl *D, const ParsedAttr &AL); void handleWaveSizeAttr(Decl *D, const ParsedAttr &AL); void handleSV_DispatchThreadIDAttr(Decl *D, const ParsedAttr &AL); + void handleSV_GroupThreadIDAttr(Decl *D, const ParsedAttr &AL); void handleSV_GroupIDAttr(Decl *D, const ParsedAttr &AL); void handlePackOffsetAttr(Decl *D, const ParsedAttr &AL); void handleShaderAttr(Decl *D, const ParsedAttr &AL); diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp index 2c293523fca8ca..19db7faddaeac0 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -389,6 +389,11 @@ llvm::Value *CGHLSLRuntime::emitInputSemantic(IRBuilder<> &B, CGM.getIntrinsic(getThreadIdIntrinsic()); return buildVectorInput(B, ThreadIDIntrinsic, Ty); } + if (D.hasAttr()) { +llvm::Function *GroupThreadIDIntrinsic = +CGM.getIntrinsic(Intrinsic::dx_thread_id_in_group); +return buildVectorInput(B, GroupThreadIDIntrinsic, Ty); + } if (D.hasAttr()) { llvm::Function *GroupIDIntrinsic = CGM.getIntrinsic(Intrinsic::dx_group_id); return buildVectorInput(B, GroupIDIntrinsic, Ty); diff --git a/clang/lib/Parse/ParseHLSL.cpp b/clang/lib/Parse/ParseHLSL.cpp index 4de342b63ed802..443bf2b9ec626a 100644 --- a/clang/lib/Parse/ParseHLSL.cpp +++ b/clang/lib/Parse/ParseHLSL.cpp @@ -280,6 +280,7 @@ void Parser::ParseHLSLAnnotations(ParsedAttributes &Attrs, case ParsedAttr::UnknownAttribute: Diag(Loc, diag::err_unknown_hlsl_semantic) << II; return; + case ParsedAttr::AT_HLSLSV_GroupThreadID: case ParsedAttr::AT_HLSLSV_GroupID: case ParsedAttr::AT_HLSLSV_GroupIndex: case ParsedAttr::AT_HLSLSV_DispatchThreadID: diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp index 4fd8ef6dbebf84..5d7ee097383771 100644 --- a/clang/lib/Sema/SemaDeclAttr.cpp +++ b/clang/lib/Sema/SemaDeclAttr.cpp @@ -7114,6 +7114,9 @@ ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D, const Parsed
[clang] [llvm] [HLSL] Implement SV_GroupThreadId semantic (PR #117781)
@@ -2,15 +2,18 @@ // RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-mesh -hlsl-entry CSMain -x hlsl -finclude-default-header -verify -o - %s [numthreads(8,8,1)] -// expected-error@+3 {{attribute 'SV_GroupIndex' is unsupported in 'mesh' shaders, requires compute}} -// expected-error@+2 {{attribute 'SV_DispatchThreadID' is unsupported in 'mesh' shaders, requires compute}} -// expected-error@+1 {{attribute 'SV_GroupID' is unsupported in 'mesh' shaders, requires compute}} -void CSMain(int GI : SV_GroupIndex, uint ID : SV_DispatchThreadID, uint GID : SV_GroupID) { -// CHECK: FunctionDecl 0x{{[0-9a-fA-F]+}} <{{.*}}> line:[[@LINE-1]]:6 CSMain 'void (int, uint, uint)' +// expected-error@+4 {{attribute 'SV_GroupIndex' is unsupported in 'mesh' shaders, requires compute}} +// expected-error@+3 {{attribute 'SV_DispatchThreadID' is unsupported in 'mesh' shaders, requires compute}} +// expected-error@+2 {{attribute 'SV_GroupID' is unsupported in 'mesh' shaders, requires compute}} +// expected-error@+1 {{attribute 'SV_GroupThreadID' is unsupported in 'mesh' shaders, requires compute}} +void CSMain(int GI : SV_GroupIndex, uint ID : SV_DispatchThreadID, uint GID : SV_GroupID, uint GThreadID : SV_GroupThreadID) { lizhengxing wrote: @tex3d Done. Updated the test in this commit https://github.com/llvm/llvm-project/pull/117781/commits/dc8d779f067e5b8d22e56036c4ba7320e297f339 https://github.com/llvm/llvm-project/pull/117781 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL] Implement SV_GroupThreadId semantic (PR #117781)
@@ -389,6 +389,11 @@ llvm::Value *CGHLSLRuntime::emitInputSemantic(IRBuilder<> &B, CGM.getIntrinsic(getThreadIdIntrinsic()); return buildVectorInput(B, ThreadIDIntrinsic, Ty); } + if (D.hasAttr()) { +llvm::Function *GroupThreadIDIntrinsic = +CGM.getIntrinsic(Intrinsic::dx_thread_id_in_group); lizhengxing wrote: @llvm-beanz Done. Added the SPIR-V lowering in this commit https://github.com/llvm/llvm-project/pull/117781/commits/28f823454873d4bc029f2ec57bed3a9707bbf1b2 https://github.com/llvm/llvm-project/pull/117781 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Add fake use emission to Clang with -fextend-lifetimes (PR #110102)
lizhengxing wrote: It's a name mangling issue on Windows (or maybe other OS). For example, the check `// CHECK-LABEL: define{{.*}}**_ZN1C4testEi**(ptr{{[^,]*}} %this, i32{{.*}} %p)` in fake-use-this.cpp expects the string contains `_ZN1C4testEi`. However, the compiler on Windows outputs `define dso_local noundef zeroext i1 @"?test@C@@QEAA_NH@Z"` https://github.com/llvm/llvm-project/pull/110102 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [HLSL][SPIR-V] implement SV_GroupID semantic lowering (PR #121521)
https://github.com/lizhengxing created https://github.com/llvm/llvm-project/pull/121521 The HLSL SV_GroupID semantic attribute is lowered into @llvm.spv.group.id intrinsic in LLVM IR for SPIR-V target. In the SPIR-V backend, this is now translated to a `WorkgroupId` builtin variable. Fixes #118700 which's a follow-up work to #70120 >From 21114c408baaa9309e3370d46a4ee196cc4f714a Mon Sep 17 00:00:00 2001 From: Zhengxing Li Date: Thu, 2 Jan 2025 12:30:18 -0800 Subject: [PATCH] [HLSL][SPIR-V] implement SV_GroupID semantic lowering The HLSL SV_GroupID semantic attribute is lowered into @llvm.spv.group.id intrinsic in LLVM IR for SPIR-V target. In the SPIR-V backend, this is now translated to a `WorkgroupId` builtin variable. Fixes #118700 which's a follow-up work to #70120 --- clang/lib/CodeGen/CGHLSLRuntime.cpp | 2 +- clang/lib/CodeGen/CGHLSLRuntime.h | 1 + .../CodeGenHLSL/semantics/SV_GroupID.hlsl | 34 llvm/include/llvm/IR/IntrinsicsSPIRV.td | 1 + .../Target/SPIRV/SPIRVInstructionSelector.cpp | 8 ++ .../SPIRV/hlsl-intrinsics/SV_GroupID.ll | 82 +++ 6 files changed, 112 insertions(+), 16 deletions(-) create mode 100644 llvm/test/CodeGen/SPIRV/hlsl-intrinsics/SV_GroupID.ll diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp index c354e58e15f4bb..5679bd71581795 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -395,7 +395,7 @@ llvm::Value *CGHLSLRuntime::emitInputSemantic(IRBuilder<> &B, return buildVectorInput(B, GroupThreadIDIntrinsic, Ty); } if (D.hasAttr()) { -llvm::Function *GroupIDIntrinsic = CGM.getIntrinsic(Intrinsic::dx_group_id); +llvm::Function *GroupIDIntrinsic = CGM.getIntrinsic(getGroupIdIntrinsic()); return buildVectorInput(B, GroupIDIntrinsic, Ty); } assert(false && "Unhandled parameter attribute"); diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h b/clang/lib/CodeGen/CGHLSLRuntime.h index edb87f9d5efdf9..3d5724118611cb 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.h +++ b/clang/lib/CodeGen/CGHLSLRuntime.h @@ -87,6 +87,7 @@ class CGHLSLRuntime { GENERATE_HLSL_INTRINSIC_FUNCTION(Radians, radians) GENERATE_HLSL_INTRINSIC_FUNCTION(ThreadId, thread_id) GENERATE_HLSL_INTRINSIC_FUNCTION(GroupThreadId, thread_id_in_group) + GENERATE_HLSL_INTRINSIC_FUNCTION(GroupId, group_id) GENERATE_HLSL_INTRINSIC_FUNCTION(FDot, fdot) GENERATE_HLSL_INTRINSIC_FUNCTION(SDot, sdot) GENERATE_HLSL_INTRINSIC_FUNCTION(UDot, udot) diff --git a/clang/test/CodeGenHLSL/semantics/SV_GroupID.hlsl b/clang/test/CodeGenHLSL/semantics/SV_GroupID.hlsl index 5e09f0fe06d4e6..3aa054afc90451 100644 --- a/clang/test/CodeGenHLSL/semantics/SV_GroupID.hlsl +++ b/clang/test/CodeGenHLSL/semantics/SV_GroupID.hlsl @@ -1,32 +1,36 @@ -// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm -finclude-default-header -disable-llvm-passes -o - %s | FileCheck %s +// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm -finclude-default-header -disable-llvm-passes -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-DXIL -DTARGET=dx +// RUN: %clang_cc1 -triple spirv-linux-vulkan-library -x hlsl -emit-llvm -finclude-default-header -disable-llvm-passes -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-SPIRV -DTARGET=spv -// Make sure SV_GroupID translated into dx.group.id. +// Make sure SV_GroupID translated into dx.group.id for directx target and spv.group.id for spirv target. -// CHECK: define void @foo() -// CHECK: %[[#ID:]] = call i32 @llvm.dx.group.id(i32 0) -// CHECK: call void @{{.*}}foo{{.*}}(i32 %[[#ID]]) +// CHECK: define void @foo() +// CHECK: %[[#ID:]] = call i32 @llvm.[[TARGET]].group.id(i32 0) +// CHECK-DXIL: call void @{{.*}}foo{{.*}}(i32 %[[#ID]]) +// CHECK-SPIRV: call spir_func void @{{.*}}foo{{.*}}(i32 %[[#ID]]) [shader("compute")] [numthreads(8,8,1)] void foo(uint Idx : SV_GroupID) {} -// CHECK: define void @bar() -// CHECK: %[[#ID_X:]] = call i32 @llvm.dx.group.id(i32 0) -// CHECK: %[[#ID_X_:]] = insertelement <2 x i32> poison, i32 %[[#ID_X]], i64 0 -// CHECK: %[[#ID_Y:]] = call i32 @llvm.dx.group.id(i32 1) -// CHECK: %[[#ID_XY:]] = insertelement <2 x i32> %[[#ID_X_]], i32 %[[#ID_Y]], i64 1 -// CHECK: call void @{{.*}}bar{{.*}}(<2 x i32> %[[#ID_XY]]) +// CHECK: define void @bar() +// CHECK: %[[#ID_X:]] = call i32 @llvm.[[TARGET]].group.id(i32 0) +// CHECK: %[[#ID_X_:]] = insertelement <2 x i32> poison, i32 %[[#ID_X]], i64 0 +// CHECK: %[[#ID_Y:]] = call i32 @llvm.[[TARGET]].group.id(i32 1) +// CHECK: %[[#ID_XY:]] = insertelement <2 x i32> %[[#ID_X_]], i32 %[[#ID_Y]], i64 1 +// CHECK-DXIL: call void @{{.*}}bar{{.*}}(<2 x i32> %[[#ID_XY]]) +// CHECK-SPIRV: call spir_func void @{{.*}}bar{{.*}}(<2 x i32> %[[#ID_XY]]) [shader("compute")] [numthreads(8,8,1)] void bar(uint2 Idx : SV_GroupID) {} // CHECK
[clang] [llvm] [HLSL][SPIR-V] implement SV_GroupID semantic lowering (PR #121521)
https://github.com/lizhengxing closed https://github.com/llvm/llvm-project/pull/121521 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Match .exe on Windows (PR #128894)
https://github.com/lizhengxing approved this pull request. https://github.com/llvm/llvm-project/pull/128894 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits