Skip to content

Commit 99e226b

Browse files
authored
Support FPGA function !spirv.Decoration metadata (#1727)
Supporting the new FPGA kernel attribute pipelined needs the translator to handle !spirv.Decoration metadata on functions as well as on global variables. If the MD is found on the function, call the existing translation of metadata.
1 parent 8d352d8 commit 99e226b

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

lib/SPIRV/SPIRVWriter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,8 @@ void LLVMToSPIRVBase::transVectorComputeMetadata(Function *F) {
974974
}
975975
}
976976

977+
static void transMetadataDecorations(Metadata *MD, SPIRVEntry *Target);
978+
977979
void LLVMToSPIRVBase::transFPGAFunctionMetadata(SPIRVFunction *BF,
978980
Function *F) {
979981
if (MDNode *StallEnable = F->getMetadata(kSPIR2MD::StallEnable)) {
@@ -1022,6 +1024,10 @@ void LLVMToSPIRVBase::transFPGAFunctionMetadata(SPIRVFunction *BF,
10221024
BF->addDecorate(new SPIRVDecoratePipelineEnableINTEL(BF, !Disable));
10231025
}
10241026
}
1027+
1028+
// In addition, process the decorations on the function
1029+
if (auto *FDecoMD = F->getMetadata(SPIRV_MD_DECORATIONS))
1030+
transMetadataDecorations(FDecoMD, BF);
10251031
}
10261032

10271033
SPIRVValue *LLVMToSPIRVBase::transConstantUse(Constant *C) {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
; Check that !spirv.Decorations are handled on FPGA functions as well as global variables
2+
; RUN: llvm-as %s -o %t.bc
3+
; RUN: llvm-spirv %t.bc --spirv-ext=+SPV_INTEL_fpga_invocation_pipelining_attributes -spirv-text -o - | FileCheck %s --check-prefix=CHECK-SPIRV
4+
; RUN: llvm-spirv --spirv-ext=+SPV_INTEL_fpga_invocation_pipelining_attributes %t.bc -o %t.spv
5+
; RUN: llvm-spirv --spirv-ext=+SPV_INTEL_fpga_invocation_pipelining_attributes -r -emit-opaque-pointers %t.spv --spirv-target-env=SPV-IR -o %t.rev.bc
6+
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-SPV-IR
7+
; RUN: llvm-spirv -r --spirv-ext=+SPV_INTEL_fpga_invocation_pipelining_attributes -emit-opaque-pointers %t.spv --spirv-target-env=SPV-IR -o %t.rev.bc
8+
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM
9+
10+
target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
11+
target triple = "spir"
12+
13+
; Function Attrs: convergent nounwind
14+
define spir_kernel void @k(float %a, float %b, float %c) #0 !kernel_arg_addr_space !4 !kernel_arg_access_qual !5 !kernel_arg_type !6 !kernel_arg_type_qual !7 !kernel_arg_base_type !6 !spirv.Decorations !9 {
15+
entry:
16+
ret void
17+
}
18+
19+
; CHECK-SPIRV: Decorate [[PId1:[0-9]+]] PipelineEnableINTEL 1
20+
; CHECK-SPIRV: Decorate [[PId1]] InitiationIntervalINTEL 2
21+
22+
!llvm.module.flags = !{!0}
23+
!opencl.ocl.version = !{!1}
24+
!opencl.spir.version = !{!2}
25+
!llvm.ident = !{!3}
26+
27+
!0 = !{i32 1, !"wchar_size", i32 4}
28+
!1 = !{i32 1, i32 0}
29+
!2 = !{i32 1, i32 2}
30+
!3 = !{!"clang version 14.0.0"}
31+
!4 = !{i32 0, i32 0, i32 0}
32+
!5 = !{!"none", !"none", !"none"}
33+
!6 = !{!"float", !"float", !"float"}
34+
!7 = !{!"", !"", !""}
35+
!8 = !{i32 19}
36+
!9 = !{!10, !11}
37+
!10 = !{i32 5919, i32 1}
38+
!11 = !{i32 5917, i32 2}
39+
40+
; CHECK-SPV-IR: define spir_kernel void @k(float %a, float %b, float %c) {{.*}} !initiation_interval ![[II:[0-9]+]] !disable_loop_pipelining ![[DISABLE_LOOP_PIPELINING:[0-9]+]] {
41+
; CHECK-SPV-IR-DAG: ![[II]] = !{i32 2}
42+
; CHECK-SPV-IR-DAG: ![[DISABLE_LOOP_PIPELINING]] = !{i32 0}
43+
44+
; CHECK-LLVM-NOT: define spir_kernel void @k(float %a, float %b, float %c) {{.*}} !spirv.Decorations ![[DecoListId:[0-9]+]] {
45+
; CHECK-LLVM: define spir_kernel void @k(float %a, float %b, float %c) {{.*}} {

0 commit comments

Comments
 (0)