Skip to content

Commit 0229456

Browse files
authored
[SYCL] Adjust CompileTimePropertiesPass for sycl_ext_oneapi_prefetch (#11597)
The first part: #11458 Adjust the CompileTimePropertiesPass so it can convert new properties into spirv decorations.
1 parent 58b5952 commit 0229456

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed

llvm/lib/SYCLLowerIR/CompileTimeProperties.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,9 @@ SYCL_COMPILE_TIME_PROPERTY("sycl-stride-size", 5883, DecorValueTy::uint32)
5454
SYCL_COMPILE_TIME_PROPERTY("sycl-word-size", 5884, DecorValueTy::uint32)
5555
SYCL_COMPILE_TIME_PROPERTY("sycl-bi-directional-ports-true", 5885,
5656
DecorValueTy::none)
57+
58+
// The corresponding SPIR-V OpCodes for sycl_ext_oneapi_prefetch
59+
// SYCL Spec: https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/proposed/sycl_ext_oneapi_prefetch.asciidoc
60+
// SPIR-V Spec: https://github.com/KhronosGroup/SPIRV-Registry/blob/main/extensions/INTEL/SPV_INTEL_cache_controls.asciidoc
61+
SYCL_COMPILE_TIME_PROPERTY("sycl-prefetch-hint", 6442, DecorValueTy::uint32)
62+
SYCL_COMPILE_TIME_PROPERTY("sycl-prefetch-hint-nt", 6442, DecorValueTy::uint32)

llvm/lib/SYCLLowerIR/CompileTimePropertiesPass.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,15 @@ bool CompileTimePropertiesPass::transformSYCLPropertiesAnnotation(
645645
// always valid, even if the decoration parameters are not strings.
646646
NewAnnotString += "{" + std::to_string(DecorCode);
647647
if (PropVal)
648-
NewAnnotString += ":\"" + PropVal->str() + "\"";
648+
NewAnnotString += ":\"" + PropVal->str();
649+
650+
if (PropName == "sycl-prefetch-hint")
651+
NewAnnotString += ",1"; // CachedINTEL
652+
if (PropName == "sycl-prefetch-hint-nt")
653+
NewAnnotString += ",3"; // InvalidateAfterReadINTEL
654+
655+
if (PropVal)
656+
NewAnnotString += "\"";
649657
NewAnnotString += "}";
650658
}
651659

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
; RUN: opt -passes=compile-time-properties %s -S | FileCheck %s
2+
3+
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"
4+
target triple = "spir64-unknown-unknown"
5+
6+
$_ZTSZ4mainEUlvE_ = comdat any
7+
8+
@.str = private unnamed_addr addrspace(1) constant [16 x i8] c"sycl-properties\00", section "llvm.metadata"
9+
@.str.1 = private unnamed_addr addrspace(1) constant [16 x i8] c"../prefetch.hpp\00", section "llvm.metadata"
10+
@.str.2 = private unnamed_addr addrspace(1) constant [19 x i8] c"sycl-prefetch-hint\00", section "llvm.metadata"
11+
@.str.3 = private unnamed_addr addrspace(1) constant [2 x i8] c"0\00", section "llvm.metadata"
12+
@.args = private unnamed_addr addrspace(1) constant { ptr addrspace(1), ptr addrspace(1) } { ptr addrspace(1) @.str.2, ptr addrspace(1) @.str.3 }, section "llvm.metadata"
13+
@.str.4 = private unnamed_addr addrspace(1) constant [2 x i8] c"1\00", section "llvm.metadata"
14+
@.args.5 = private unnamed_addr addrspace(1) constant { ptr addrspace(1), ptr addrspace(1) } { ptr addrspace(1) @.str.2, ptr addrspace(1) @.str.4 }, section "llvm.metadata"
15+
@.str.6 = private unnamed_addr addrspace(1) constant [22 x i8] c"sycl-prefetch-hint-nt\00", section "llvm.metadata"
16+
@.str.7 = private unnamed_addr addrspace(1) constant [2 x i8] c"2\00", section "llvm.metadata"
17+
@.args.8 = private unnamed_addr addrspace(1) constant { ptr addrspace(1), ptr addrspace(1) } { ptr addrspace(1) @.str.6, ptr addrspace(1) @.str.7 }, section "llvm.metadata"
18+
19+
; CHECK: @[[NewAnnotStr1:.*]] = private unnamed_addr addrspace(1) constant [13 x i8] c"{6442:\220,1\22}\00"
20+
; CHECK: @[[NewAnnotStr2:.*]] = private unnamed_addr addrspace(1) constant [13 x i8] c"{6442:\221,1\22}\00"
21+
; CHECK: @[[NewAnnotStr3:.*]] = private unnamed_addr addrspace(1) constant [13 x i8] c"{6442:\222,3\22}\00"
22+
23+
; Function Attrs: convergent norecurse nounwind
24+
define weak_odr dso_local spir_kernel void @_ZTSZ4mainEUlvE_(ptr addrspace(1) noundef align 1 %_arg_dataPtr) local_unnamed_addr comdat !srcloc !5 !kernel_arg_buffer_location !6 !sycl_fixed_targets !7 !sycl_kernel_omit_args !8 {
25+
entry:
26+
%0 = addrspacecast ptr addrspace(1) %_arg_dataPtr to ptr addrspace(4)
27+
%call.i.i.i.i = tail call spir_func noundef ptr addrspace(1) @_Z41__spirv_GenericCastToPtrExplicit_ToGlobalPvi(ptr addrspace(4) noundef %0, i32 noundef 5)
28+
%1 = tail call ptr addrspace(1) @llvm.ptr.annotation.p1.p1(ptr addrspace(1) %call.i.i.i.i, ptr addrspace(1) @.str, ptr addrspace(1) @.str.1, i32 76, ptr addrspace(1) @.args)
29+
; CHECK %{{.*}} = call ptr addrspace(1) @llvm.ptr.annotation.p1.p1(ptr {{.*}}, ptr addrspace(1) @[[NewAnnotStr1]]{{.*}}
30+
tail call spir_func void @_Z20__spirv_ocl_prefetchPU3AS1Kcm(ptr addrspace(1) noundef %1, i64 noundef 1)
31+
%arrayidx3.i = getelementptr inbounds i8, ptr addrspace(4) %0, i64 1
32+
%call.i.i.i13.i = tail call spir_func noundef ptr addrspace(1) @_Z41__spirv_GenericCastToPtrExplicit_ToGlobalPvi(ptr addrspace(4) noundef %arrayidx3.i, i32 noundef 5)
33+
%2 = tail call ptr addrspace(1) @llvm.ptr.annotation.p1.p1(ptr addrspace(1) %call.i.i.i13.i, ptr addrspace(1) @.str, ptr addrspace(1) @.str.1, i32 80, ptr addrspace(1) @.args.5)
34+
; CHECK %{{.*}} = call ptr addrspace(1) @llvm.ptr.annotation.p1.p1(ptr {{.*}}, ptr addrspace(1) @[[NewAnnotStr2]]{{.*}}
35+
tail call spir_func void @_Z20__spirv_ocl_prefetchPU3AS1Kcm(ptr addrspace(1) noundef %2, i64 noundef 1)
36+
%arrayidx7.i = getelementptr inbounds i8, ptr addrspace(4) %0, i64 2
37+
%call.i.i.i16.i = tail call spir_func noundef ptr addrspace(1) @_Z41__spirv_GenericCastToPtrExplicit_ToGlobalPvi(ptr addrspace(4) noundef %arrayidx7.i, i32 noundef 5)
38+
%3 = tail call ptr addrspace(1) @llvm.ptr.annotation.p1.p1(ptr addrspace(1) %call.i.i.i16.i, ptr addrspace(1) @.str, ptr addrspace(1) @.str.1, i32 80, ptr addrspace(1) @.args.8)
39+
; CHECK %{{.*}} = call ptr addrspace(1) @llvm.ptr.annotation.p1.p1(ptr {{.*}}, ptr addrspace(1) @[[NewAnnotStr3]]{{.*}}
40+
tail call spir_func void @_Z20__spirv_ocl_prefetchPU3AS1Kcm(ptr addrspace(1) noundef %3, i64 noundef 2)
41+
ret void
42+
}
43+
44+
; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: readwrite)
45+
declare ptr addrspace(1) @llvm.ptr.annotation.p1.p1(ptr addrspace(1), ptr addrspace(1), ptr addrspace(1), i32, ptr addrspace(1))
46+
47+
; Function Attrs: convergent nounwind
48+
declare dso_local spir_func void @_Z20__spirv_ocl_prefetchPU3AS1Kcm(ptr addrspace(1) noundef, i64 noundef) local_unnamed_addr
49+
50+
; Function Attrs: convergent mustprogress nofree nounwind willreturn memory(none)
51+
declare dso_local spir_func noundef ptr addrspace(1) @_Z41__spirv_GenericCastToPtrExplicit_ToGlobalPvi(ptr addrspace(4) noundef, i32 noundef) local_unnamed_addr
52+
53+
!llvm.module.flags = !{!0, !1}
54+
!opencl.spir.version = !{!2}
55+
!spirv.Source = !{!3}
56+
!llvm.ident = !{!4}
57+
58+
!0 = !{i32 1, !"wchar_size", i32 4}
59+
!1 = !{i32 7, !"frame-pointer", i32 2}
60+
!2 = !{i32 1, i32 2}
61+
!3 = !{i32 4, i32 100000}
62+
!4 = !{!"clang version 18.0.0"}
63+
!5 = !{i32 1522}
64+
!6 = !{i32 -1}
65+
!7 = !{}
66+
!8 = !{i1 false}

0 commit comments

Comments
 (0)