Skip to content

Commit 8269b59

Browse files
authored
[SYCL] Cherry-pick llvm-spirv patch (#7930)
I want to use this immediately for a bugfix. It's self contained and shouldn't affect anthing else Original commit: KhronosGroup/SPIRV-LLVM-Translator@2439639 Signed-off-by: Sarnie, Nick <[email protected]>
1 parent c3c3c19 commit 8269b59

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed

llvm-spirv/lib/SPIRV/SPIRVWriter.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,8 @@ SPIRVFunction *LLVMToSPIRVBase::transFunctionDecl(Function *F) {
904904

905905
transFPGAFunctionMetadata(BF, F);
906906

907+
transFunctionMetadataAsUserSemanticDecoration(BF, F);
908+
907909
SPIRVDBG(dbgs() << "[transFunction] " << *F << " => ";
908910
spvdbgs() << *BF << '\n';)
909911
return BF;
@@ -1048,6 +1050,29 @@ void LLVMToSPIRVBase::transFPGAFunctionMetadata(SPIRVFunction *BF,
10481050
transMetadataDecorations(FDecoMD, BF);
10491051
}
10501052

1053+
void LLVMToSPIRVBase::transFunctionMetadataAsUserSemanticDecoration(
1054+
SPIRVFunction *BF, Function *F) {
1055+
if (auto *RegisterAllocModeMD = F->getMetadata("RegisterAllocMode")) {
1056+
// TODO: Once the design for per-kernel register size allocation is
1057+
// finalized, we will need to move away from UserSemantic and introduce an
1058+
// extension
1059+
int RegisterAllocNodeMDOp = getMDOperandAsInt(RegisterAllocModeMD, 0);
1060+
// The current RegisterAllocMode metadata format is as follows
1061+
// AUTO - 0
1062+
// SMALL - 1
1063+
// LARGE - 2
1064+
// DEFAULT - 3
1065+
// Currently we only support SMALL and LARGE
1066+
if (RegisterAllocNodeMDOp == 1 || RegisterAllocNodeMDOp == 2) {
1067+
// 4 threads per eu means large grf mode, and 8 threads per eu
1068+
// means small grf mode
1069+
std::string NumThreads = RegisterAllocNodeMDOp == 2 ? "4" : "8";
1070+
BF->addDecorate(new SPIRVDecorateUserSemanticAttr(
1071+
BF, "num-thread-per-eu " + NumThreads));
1072+
}
1073+
}
1074+
}
1075+
10511076
SPIRVValue *LLVMToSPIRVBase::transConstantUse(Constant *C) {
10521077
// Constant expressions expect their pointer types to be i8* in opaque pointer
10531078
// mode, but the value may have a different "natural" type. If that is the

llvm-spirv/lib/SPIRV/SPIRVWriter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ class LLVMToSPIRVBase : protected BuiltinCallHelper {
122122
SPIRVFunction *transFunctionDecl(Function *F);
123123
void transVectorComputeMetadata(Function *F);
124124
void transFPGAFunctionMetadata(SPIRVFunction *BF, Function *F);
125+
void transFunctionMetadataAsUserSemanticDecoration(SPIRVFunction *BF,
126+
Function *F);
125127
bool transGlobalVariables();
126128

127129
Op transBoolOpCode(SPIRVValue *Opn, Op OC);
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
; RUN: llvm-as %s -o %t.bc
2+
; RUN: llvm-spirv -spirv-text %t.bc -o - | FileCheck %s --check-prefix=CHECK-SPIRV
3+
; RUN: llvm-spirv %t.bc -o %t.spv
4+
; RUN: spirv-val %t.spv
5+
; RUN: llvm-spirv -r -emit-opaque-pointers %t.spv -o - | llvm-dis -o - | FileCheck %s --check-prefix=CHECK-LLVM
6+
7+
; CHECK-SPIRV: 8 Decorate 4 UserSemantic "num-thread-per-eu 4"
8+
; CHECK-SPIRV: 8 Decorate 6 UserSemantic "num-thread-per-eu 8"
9+
; CHECK-SPIRV-NOT: 8 Decorate 8
10+
; CHECK-SPIRV-NOT: 8 Decorate 10
11+
; CHECK-SPIRV-NOT: 8 Decorate 12
12+
13+
; CHECK-LLVM: @[[FLAG0:[0-9]+]] = private unnamed_addr constant [20 x i8] c"num-thread-per-eu 4\00", section "llvm.metadata"
14+
; CHECK-LLVM: @[[FLAG1:[0-9]+]] = private unnamed_addr constant [20 x i8] c"num-thread-per-eu 8\00", section "llvm.metadata"
15+
16+
; CHECK-LLVM: @llvm.global.annotations = appending global [2 x { ptr, ptr, ptr, i32, ptr }] [{ ptr, ptr, ptr, i32, ptr } { ptr @main_l3, ptr @[[FLAG0]], ptr undef, i32 undef, ptr undef }, { ptr, ptr, ptr, i32, ptr } { ptr @main_l6, ptr @[[FLAG1]], ptr undef, i32 undef, ptr undef }], section "llvm.metadata"
17+
18+
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"
19+
target triple = "spir64"
20+
21+
; Function Attrs: noinline nounwind optnone
22+
define weak dso_local spir_kernel void @main_l3() #0 !RegisterAllocMode !10 {
23+
newFuncRoot:
24+
ret void
25+
}
26+
27+
; Function Attrs: noinline nounwind optnone
28+
define weak dso_local spir_kernel void @main_l6() #0 !RegisterAllocMode !11 {
29+
newFuncRoot:
30+
ret void
31+
}
32+
33+
; Function Attrs: noinline nounwind optnone
34+
define weak dso_local spir_kernel void @main_l9() #0 !RegisterAllocMode !12 {
35+
newFuncRoot:
36+
ret void
37+
}
38+
39+
; Function Attrs: noinline nounwind optnone
40+
define weak dso_local spir_kernel void @main_l13() #0 !RegisterAllocMode !13 {
41+
newFuncRoot:
42+
ret void
43+
}
44+
45+
; Function Attrs: noinline nounwind optnone
46+
define weak dso_local spir_kernel void @main_l19() #0 {
47+
newFuncRoot:
48+
ret void
49+
}
50+
51+
attributes #0 = { noinline nounwind optnone }
52+
53+
54+
!opencl.compiler.options = !{!0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0, !0}
55+
!spirv.Source = !{!2, !3, !3, !3, !3, !3, !2, !3, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2, !2}
56+
!llvm.module.flags = !{!4, !5, !6, !7, !8}
57+
!spirv.MemoryModel = !{!9, !9, !9, !9, !9, !9}
58+
!spirv.ExecutionMode = !{}
59+
60+
!0 = !{}
61+
!2 = !{i32 4, i32 200000}
62+
!3 = !{i32 3, i32 200000}
63+
!4 = !{i32 1, !"wchar_size", i32 4}
64+
!5 = !{i32 7, !"openmp", i32 50}
65+
!6 = !{i32 7, !"openmp-device", i32 50}
66+
!7 = !{i32 8, !"PIC Level", i32 2}
67+
!8 = !{i32 7, !"frame-pointer", i32 2}
68+
!9 = !{i32 2, i32 2}
69+
!10 = !{i32 2}
70+
!11 = !{i32 1}
71+
!12 = !{i32 0}
72+
!13 = !{i32 3}

0 commit comments

Comments
 (0)