Skip to content

Commit f7ebe9f

Browse files
committed
[SYCL] Enable basic support for 2020 specialization constants in sycl-post-link
SYCL 2020 specialization constants implementation will use new intrinsic in DPC++ headers to provide required markup for the compiler. By doing this change, SpecConstantsPass starts to support new interface for specialization constants. It doesn't implement handling of new arguments, which would be done in further PRs (for now new arguments are just ignored).
1 parent dcfb6b1 commit f7ebe9f

File tree

4 files changed

+74
-7
lines changed

4 files changed

+74
-7
lines changed

llvm/test/tools/sycl-post-link/composite-spec-constant.ll

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; RUN: sycl-post-link -spec-const=rt --ir-output-only %s -S -o - \
2-
; RUN: | FileCheck %s --implicit-check-not __sycl_getCompositeSpecConstantValue
2+
; RUN: | FileCheck %s --implicit-check-not __sycl_getCompositeSpecConstantValue --implicit-check-not __sycl_getComposite2020SpecConstantValue
33
;
44
; This test is intended to check that sycl-post-link tool is capable of handling
55
; composite specialization constants by lowering them into a set of SPIR-V
@@ -23,7 +23,17 @@
2323
; CHECK: %[[#POD:]] = call %struct._ZTS3POD.POD @"_Z29__spirv_SpecConstantCompositeAstruct._ZTS1A.Aclass._ZTSN2cl4sycl3vecIiLi2EEE.cl::sycl::vec"([2 x %struct._ZTS1A.A] %[[#NA]], %"class._ZTSN2cl4sycl3vecIiLi2EEE.cl::sycl::vec" %[[#B]]), !SYCL_SPEC_CONST_SYM_ID ![[#MD:]]
2424
; CHECK: store %struct._ZTS3POD.POD %[[#POD]]
2525
;
26+
; Test checks related to 2020 API for composite specialization constants.
27+
;
28+
; CHECK: %[[#N0:]] = call i32 @_Z20__spirv_SpecConstantii(i32 [[#ID + 6]], i32
29+
; CHECK: %[[#N1:]] = call float @_Z20__spirv_SpecConstantif(i32 [[#ID + 7]], float
30+
; CHECK: %[[#CONST:]] = call %struct._ZTS1A.A @_Z29__spirv_SpecConstantCompositeif(i32 %[[#N0]], float %[[#N1]]), !SYCL_SPEC_CONST_SYM_ID ![[#MD1:]]
31+
; CHECK: %struct._ZTS1A.A %[[#CONST]]
32+
;
33+
; Common metadata checks
34+
;
2635
; CHECK: ![[#MD]] = !{!"_ZTS3POD", i32 [[#ID]], i32 [[#ID + 1]], i32 [[#ID + 2]], i32 [[#ID + 3]], i32 [[#ID + 4]], i32 [[#ID + 5]]}
36+
; CHECK: ![[#MD1]] = !{!"_ZTS13MyComposConst", i32 [[#ID + 6]], i32 [[#ID + 7]]}
2737

2838
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
2939
target triple = "spir64-unknown-unknown-sycldevice"
@@ -36,8 +46,10 @@ target triple = "spir64-unknown-unknown-sycldevice"
3646
%"class._ZTSN2cl4sycl2idILi1EEE.cl::sycl::id" = type { %"class._ZTSN2cl4sycl6detail5arrayILi1EEE.cl::sycl::detail::array" }
3747

3848
$_ZTS4Test = comdat any
49+
$_ZTS17SpecializedKernel = comdat any
3950

4051
@__builtin_unique_stable_name._ZNK2cl4sycl6ONEAPI12experimental13spec_constantI3PODS4_E3getIS4_EENSt9enable_ifIXsr3std6is_podIT_EE5valueES8_E4typeEv = private unnamed_addr addrspace(1) constant [9 x i8] c"_ZTS3POD\00", align 1
52+
@__builtin_unique_stable_name._ZNK2cl4sycl6ONEAPI12experimental13spec_constantI13MyComposConstE3getIS4_EENSt9enable_ifIXaasr3std8is_classIT_EE5valuesr3std6is_podIS9_EE5valueES9_E4typeEv = private unnamed_addr addrspace(1) constant [20 x i8] c"_ZTS13MyComposConst\00", align 1
4153

4254
; Function Attrs: convergent norecurse uwtable
4355
define weak_odr dso_local spir_kernel void @_ZTS4Test(%struct._ZTS3POD.POD addrspace(1)* %_arg_, %"class._ZTSN2cl4sycl5rangeILi1EEE.cl::sycl::range"* byval(%"class._ZTSN2cl4sycl5rangeILi1EEE.cl::sycl::range") align 8 %_arg_1, %"class._ZTSN2cl4sycl5rangeILi1EEE.cl::sycl::range"* byval(%"class._ZTSN2cl4sycl5rangeILi1EEE.cl::sycl::range") align 8 %_arg_2, %"class._ZTSN2cl4sycl2idILi1EEE.cl::sycl::id"* byval(%"class._ZTSN2cl4sycl2idILi1EEE.cl::sycl::id") align 8 %_arg_3) local_unnamed_addr #0 comdat !kernel_arg_buffer_location !4 {
@@ -57,6 +69,30 @@ entry:
5769
ret void
5870
}
5971

72+
; Function Attrs: convergent norecurse
73+
define weak_odr dso_local spir_kernel void @_ZTS17SpecializedKernel(float addrspace(1)* %_arg_, %"class._ZTSN2cl4sycl5rangeILi1EEE.cl::sycl::range"* byval(%"class._ZTSN2cl4sycl5rangeILi1EEE.cl::sycl::range") align 8 %_arg_1, %"class._ZTSN2cl4sycl5rangeILi1EEE.cl::sycl::range"* byval(%"class._ZTSN2cl4sycl5rangeILi1EEE.cl::sycl::range") align 8 %_arg_2, %"class._ZTSN2cl4sycl2idILi1EEE.cl::sycl::id"* byval(%"class._ZTSN2cl4sycl2idILi1EEE.cl::sycl::id") align 8 %_arg_3) local_unnamed_addr #0 comdat !kernel_arg_buffer_location !4 {
74+
entry:
75+
%c.i = alloca %struct._ZTS1A.A, align 4
76+
%0 = getelementptr inbounds %"class._ZTSN2cl4sycl2idILi1EEE.cl::sycl::id", %"class._ZTSN2cl4sycl2idILi1EEE.cl::sycl::id"* %_arg_3, i64 0, i32 0, i32 0, i64 0
77+
%1 = addrspacecast i64* %0 to i64 addrspace(4)*
78+
%2 = load i64, i64 addrspace(4)* %1, align 8
79+
%add.ptr.i = getelementptr inbounds float, float addrspace(1)* %_arg_, i64 %2
80+
%c.ascast.i = addrspacecast %struct._ZTS1A.A* %c.i to %struct._ZTS1A.A addrspace(4)*
81+
%3 = bitcast %struct._ZTS1A.A* %c.i to i8*
82+
call void @llvm.lifetime.start.p0i8(i64 8, i8* nonnull %3) #3
83+
call spir_func void @_Z40__sycl_getComposite2020SpecConstantValueI13MyComposConstET_PKcPvS4_(%struct._ZTS1A.A addrspace(4)* sret(%struct._ZTS1A.A) align 4 %c.ascast.i, i8 addrspace(4)* getelementptr inbounds ([20 x i8], [20 x i8] addrspace(4)* addrspacecast ([20 x i8] addrspace(1)* @__builtin_unique_stable_name._ZNK2cl4sycl6ONEAPI12experimental13spec_constantI13MyComposConstE3getIS4_EENSt9enable_ifIXaasr3std8is_classIT_EE5valuesr3std6is_podIS9_EE5valueES9_E4typeEv to [20 x i8] addrspace(4)*), i64 0, i64 0), i8 addrspace(4)* null, i8 addrspace(4)* null) #4
84+
%a.i = getelementptr inbounds %struct._ZTS1A.A, %struct._ZTS1A.A addrspace(4)* %c.ascast.i, i64 0, i32 0
85+
%4 = load i32, i32 addrspace(4)* %a.i, align 4
86+
%conv.i = sitofp i32 %4 to float
87+
%b.i = getelementptr inbounds %struct._ZTS1A.A, %struct._ZTS1A.A addrspace(4)* %c.ascast.i, i64 0, i32 1
88+
%5 = load float, float addrspace(4)* %b.i, align 4
89+
%add.i = fadd float %5, %conv.i
90+
%ptridx.ascast.i.i = addrspacecast float addrspace(1)* %add.ptr.i to float addrspace(4)*
91+
store float %add.i, float addrspace(4)* %ptridx.ascast.i.i, align 4, !tbaa !11
92+
call void @llvm.lifetime.end.p0i8(i64 8, i8* nonnull %3) #3
93+
ret void
94+
}
95+
6096
; Function Attrs: argmemonly nounwind willreturn
6197
declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #1
6298

@@ -69,6 +105,9 @@ declare void @llvm.memcpy.p4i8.p0i8.i64(i8 addrspace(4)* noalias nocapture write
69105
; Function Attrs: convergent
70106
declare dso_local spir_func void @_Z36__sycl_getCompositeSpecConstantValueI3PODET_PKc(%struct._ZTS3POD.POD addrspace(4)* sret(%struct._ZTS3POD.POD) align 8, i8 addrspace(4)*) local_unnamed_addr #2
71107

108+
; Function Attrs: convergent
109+
declare dso_local spir_func void @_Z40__sycl_getComposite2020SpecConstantValueI13MyComposConstET_PKcPvS4_(%struct._ZTS1A.A addrspace(4)* sret(%struct._ZTS1A.A) align 4, i8 addrspace(4)*, i8 addrspace(4)*, i8 addrspace(4)*) local_unnamed_addr #2
110+
72111
attributes #0 = { convergent norecurse uwtable "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "sycl-module-id"="../sycl/test/spec_const/composite.cpp" "tune-cpu"="generic" "uniform-work-group-size"="true" "unsafe-fp-math"="false" "use-soft-float"="false" }
73112
attributes #1 = { argmemonly nounwind willreturn }
74113
attributes #2 = { convergent "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "tune-cpu"="generic" "unsafe-fp-math"="false" "use-soft-float"="false" }
@@ -89,3 +128,6 @@ attributes #4 = { convergent }
89128
!6 = !{!7, !7, i64 0}
90129
!7 = !{!"omnipotent char", !8, i64 0}
91130
!8 = !{!"Simple C++ TBAA"}
131+
!9 = !{!"int", !7, i64 0}
132+
!10 = !{!"float", !7, i64 0}
133+
!11 = !{!10, !10, i64 0}

llvm/test/tools/sycl-post-link/spec_const_O2.ll

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ $_ZTS17SpecializedKernel = comdat any
3939
; CHECK-NOT: @__unique_stable_name.SC_If12MyFloatConstE3getEv
4040
@__unique_stable_name.SC_Id13MyDoubleConstE3getEv = private unnamed_addr constant [20 x i8] c"_ZTS13MyDoubleConst\00", align 1
4141
; CHECK-NOT: @__unique_stable_name.SC_Id13MyDoubleConstE3getEv
42+
@__unique_stable_name.SC_Id14MyDoubleConst2E3getEv = private unnamed_addr constant [21 x i8] c"_ZTS14MyDoubleConst2\00", align 1
43+
; CHECK-NOT: @__unique_stable_name.SC_Id14MyDoubleConst2E3getEv
4244

4345
; Function Attrs: norecurse
4446
define weak_odr dso_local spir_kernel void @_ZTS17SpecializedKernel(float addrspace(1)* %0, %"cl::sycl::range"* byval(%"cl::sycl::range") align 8 %1, %"cl::sycl::range"* byval(%"cl::sycl::range") align 8 %2, %"cl::sycl::id"* byval(%"cl::sycl::id") align 8 %3) local_unnamed_addr #0 comdat !kernel_arg_addr_space !4 !kernel_arg_access_qual !5 !kernel_arg_type !6 !kernel_arg_base_type !6 !kernel_arg_type_qual !7 {
@@ -111,10 +113,14 @@ define weak_odr dso_local spir_kernel void @_ZTS17SpecializedKernel(float addrsp
111113
; CHECK-RT: %{{[0-9]+}} = call double @_Z20__spirv_SpecConstantid(i32 10, double 0.000000e+00), !SYCL_SPEC_CONST_SYM_ID ![[ID10:[0-9]+]]
112114
%36 = fadd double %35, %34
113115
; CHECK-DEF: %[[SUM9:[0-9]+]] = fadd double 0.000000e+00, %[[VAL7]]
114-
%37 = fptrunc double %36 to float
115-
; CHECK-DEF: %[[VAL8:[0-9]+]] = fptrunc double %[[SUM9]] to float
116-
%38 = addrspacecast float addrspace(1)* %7 to float addrspace(4)*
117-
store float %37, float addrspace(4)* %38, align 4, !tbaa !8
116+
%37 = tail call spir_func double @_Z37__sycl_getScalar2020SpecConstantValueIdET_PKcPvS3_(i8 addrspace(4)* addrspacecast (i8* getelementptr inbounds ([21 x i8], [21 x i8]* @__unique_stable_name.SC_Id14MyDoubleConst2E3getEv, i64 0, i64 0) to i8 addrspace(4)*), i8 addrspace(4)* null, i8 addrspace(4)* null)
117+
; CHECK-RT: %{{[0-9]+}} = call double @_Z20__spirv_SpecConstantid(i32 11, double 0.000000e+00), !SYCL_SPEC_CONST_SYM_ID ![[ID11:[0-9]+]]
118+
%38 = fadd double %37, %36
119+
; CHECK-DEF: %[[SUM10:[0-9]+]] = fadd double 0.000000e+00, %[[SUM9]]
120+
%39 = fptrunc double %38 to float
121+
; CHECK-DEF: %[[VAL8:[0-9]+]] = fptrunc double %[[SUM10]] to float
122+
%40 = addrspacecast float addrspace(1)* %7 to float addrspace(4)*
123+
store float %39, float addrspace(4)* %40, align 4, !tbaa !8
118124
ret void
119125
}
120126

@@ -140,6 +146,8 @@ declare dso_local spir_func float @_Z27__sycl_getSpecConstantValueIfET_PKc(i8 ad
140146

141147
declare dso_local spir_func double @_Z27__sycl_getSpecConstantValueIdET_PKc(i8 addrspace(4)*) local_unnamed_addr #1
142148

149+
declare dso_local spir_func double @_Z37__sycl_getScalar2020SpecConstantValueIdET_PKcPvS3_(i8 addrspace(4)*, i8 addrspace(4)*, i8 addrspace(4)*) local_unnamed_addr #1
150+
143151
attributes #0 = { norecurse "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "sycl-module-id"="/iusers/kbobrovs/ws/kbobrovs_llvm/sycl/test/spec_const/spec_const_types.cpp" "uniform-work-group-size"="true" "unsafe-fp-math"="false" "use-soft-float"="false" }
144152
attributes #1 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "frame-pointer"="all" "less-precise-fpmad"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
145153

llvm/tools/sycl-post-link/SpecConstants.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ namespace {
2828
constexpr char SYCL_GET_SPEC_CONST_VAL[] = "_Z27__sycl_getSpecConstantValue";
2929
constexpr char SYCL_GET_COMPOSITE_SPEC_CONST_VAL[] =
3030
"_Z36__sycl_getCompositeSpecConstantValue";
31+
constexpr char SYCL_GET_SCALAR_2020_SPEC_CONST_VAL[] =
32+
"_Z37__sycl_getScalar2020SpecConstantValue";
33+
constexpr char SYCL_GET_COMPOSITE_2020_SPEC_CONST_VAL[] =
34+
"_Z40__sycl_getComposite2020SpecConstantValue";
3135

3236
// Unmangled base name of all __spirv_SpecConstant intrinsics which differ by
3337
// the value type.
@@ -403,7 +407,9 @@ PreservedAnalyses SpecConstantsPass::run(Module &M,
403407
continue;
404408

405409
if (!F.getName().startswith(SYCL_GET_SPEC_CONST_VAL) &&
406-
!F.getName().startswith(SYCL_GET_COMPOSITE_SPEC_CONST_VAL))
410+
!F.getName().startswith(SYCL_GET_COMPOSITE_SPEC_CONST_VAL) &&
411+
!F.getName().startswith(SYCL_GET_SCALAR_2020_SPEC_CONST_VAL) &&
412+
!F.getName().startswith(SYCL_GET_COMPOSITE_2020_SPEC_CONST_VAL))
407413
continue;
408414

409415
SmallVector<CallInst *, 32> SCIntrCalls;
@@ -420,7 +426,8 @@ PreservedAnalyses SpecConstantsPass::run(Module &M,
420426
// literals are passed to it in the SYCL RT source code, and application
421427
// code can't use this intrinsic directly.
422428
bool IsComposite =
423-
F.getName().startswith(SYCL_GET_COMPOSITE_SPEC_CONST_VAL);
429+
F.getName().startswith(SYCL_GET_COMPOSITE_SPEC_CONST_VAL) ||
430+
F.getName().startswith(SYCL_GET_COMPOSITE_2020_SPEC_CONST_VAL);
424431

425432
SmallVector<Instruction *, 3> DelInsts;
426433
DelInsts.push_back(CI);

sycl/include/CL/sycl/detail/sycl_fe_intrins.hpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,14 @@ SYCL_EXTERNAL T __sycl_getSpecConstantValue(const char *ID);
2121
template <typename T>
2222
SYCL_EXTERNAL T __sycl_getCompositeSpecConstantValue(const char *ID);
2323

24+
template <typename T>
25+
SYCL_EXTERNAL T __sycl_getScalar2020SpecConstantValue(const char *SymbolicID,
26+
void *DefaultValue,
27+
void *RTBuffer);
28+
29+
template <typename T>
30+
SYCL_EXTERNAL T __sycl_getComposite2020SpecConstantValue(const char *SymbolicID,
31+
void *DefaultValue,
32+
void *RTBuffer);
33+
2434
#endif

0 commit comments

Comments
 (0)