Skip to content

Commit 5725a41

Browse files
committed
--Added support for the extension SPV_INTEL_blocking_pipes
--Added test files for the extension SPV_INTEL_blocking_pipes
1 parent eb420fd commit 5725a41

File tree

8 files changed

+150
-1
lines changed

8 files changed

+150
-1
lines changed

llvm/docs/SPIRVUsage.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,8 @@ Below is a list of supported SPIR-V extensions, sorted alphabetically by their e
233233
- Adds support for 4-bit integer type, and allow this type to be used in cooperative matrices.
234234
* - ``SPV_KHR_float_controls2``
235235
- Adds ability to specify the floating-point environment in shaders. It can be used on whole modules and individual instructions.
236+
* - ``SPV_INTEL_blocking_pipes``
237+
- Adds new pipe read and write functions that have blocking semantics instead of the non-blocking semantics of the existing pipe read/write functions.
236238

237239
SPIR-V representation in LLVM IR
238240
================================

llvm/lib/Target/SPIRV/SPIRVBuiltins.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2362,6 +2362,15 @@ static bool generateBindlessImageINTELInst(const SPIRV::IncomingCall *Call,
23622362
return buildBindlessImageINTELInst(Call, Opcode, MIRBuilder, GR);
23632363
}
23642364

2365+
static bool generateBlockingPipesInst(const SPIRV::IncomingCall *Call,
2366+
MachineIRBuilder &MIRBuilder,
2367+
SPIRVGlobalRegistry *GR) {
2368+
const SPIRV::DemangledBuiltin *Builtin = Call->Builtin;
2369+
unsigned Opcode =
2370+
SPIRV::lookupNativeBuiltin(Builtin->Name, Builtin->Set)->Opcode;
2371+
return buildOpFromWrapper(MIRBuilder, Opcode, Call, Register(0));
2372+
}
2373+
23652374
static bool
23662375
generateTernaryBitwiseFunctionINTELInst(const SPIRV::IncomingCall *Call,
23672376
MachineIRBuilder &MIRBuilder,
@@ -2999,6 +3008,8 @@ std::optional<bool> lowerBuiltin(const StringRef DemangledCall,
29993008
return generate2DBlockIOINTELInst(Call.get(), MIRBuilder, GR);
30003009
case SPIRV::Pipe:
30013010
return generatePipeInst(Call.get(), MIRBuilder, GR);
3011+
case SPIRV::BlockingPipes:
3012+
return generateBlockingPipesInst(Call.get(), MIRBuilder, GR);
30023013
}
30033014
return false;
30043015
}

llvm/lib/Target/SPIRV/SPIRVBuiltins.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def BindlessINTEL : BuiltinGroup;
7070
def TernaryBitwiseINTEL : BuiltinGroup;
7171
def Block2DLoadStore : BuiltinGroup;
7272
def Pipe : BuiltinGroup;
73+
def BlockingPipes : BuiltinGroup;
7374

7475
//===----------------------------------------------------------------------===//
7576
// Class defining a demangled builtin record. The information in the record
@@ -1170,6 +1171,10 @@ defm : DemangledNativeBuiltin<"clock_read_hilo_device", OpenCL_std, KernelClock,
11701171
defm : DemangledNativeBuiltin<"clock_read_hilo_work_group", OpenCL_std, KernelClock, 0, 0, OpReadClockKHR>;
11711172
defm : DemangledNativeBuiltin<"clock_read_hilo_sub_group", OpenCL_std, KernelClock, 0, 0, OpReadClockKHR>;
11721173

1174+
//SPV_INTEL_blocking_pipes
1175+
defm : DemangledNativeBuiltin<"__spirv_WritePipeBlockingINTEL", OpenCL_std, BlockingPipes, 0, 0, OpWritePipeBlockingINTEL>;
1176+
defm : DemangledNativeBuiltin<"__spirv_ReadPipeBlockingINTEL", OpenCL_std, BlockingPipes, 0, 0, OpReadPipeBlockingINTEL>;
1177+
11731178
//===----------------------------------------------------------------------===//
11741179
// Class defining an atomic instruction on floating-point numbers.
11751180
//

llvm/lib/Target/SPIRV/SPIRVCommandLine.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ static const std::map<std::string, SPIRV::Extension::Extension, std::less<>>
151151
{"SPV_KHR_bfloat16", SPIRV::Extension::Extension::SPV_KHR_bfloat16},
152152
{"SPV_EXT_relaxed_printf_string_address_space",
153153
SPIRV::Extension::Extension::
154-
SPV_EXT_relaxed_printf_string_address_space}};
154+
SPV_EXT_relaxed_printf_string_address_space},
155+
{"SPV_INTEL_blocking_pipes",
156+
SPIRV::Extension::Extension::SPV_INTEL_blocking_pipes}};
155157

156158
bool SPIRVExtensionsParser::parse(cl::Option &O, StringRef ArgName,
157159
StringRef ArgValue,

llvm/lib/Target/SPIRV/SPIRVInstrInfo.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,3 +987,9 @@ def OpSubgroup2DBlockPrefetchINTEL: Op<6234, (outs), (ins ID:$element_size, ID:$
987987
def OpSubgroup2DBlockStoreINTEL: Op<6235, (outs), (ins ID:$element_size, ID:$block_width, ID:$block_height,
988988
ID:$block_count, ID:$src_ptr, ID:$dst_base_ptr, ID:$memory_width, ID:$memory_height, ID:$memory_pitch, ID:$coord),
989989
"OpSubgroup2DBlockStoreINTEL $element_size $block_width $block_height $block_count $src_ptr $dst_base_ptr $memory_width $memory_height $memory_pitch $coord">;
990+
991+
//SPV_INTEL_blocking_pipes
992+
def OpReadPipeBlockingINTEL :Op<5946, (outs), (ins ID:$pipe, ID:$pointer, ID:$packetSize, ID:$packetAlignment),
993+
"OpReadPipeBlockingINTEL $pipe $pointer $packetSize $packetAlignment">;
994+
def OpWritePipeBlockingINTEL :Op<5946, (outs), (ins ID:$pipe, ID:$pointer, ID:$packetSize, ID:$packetAlignment),
995+
"OpWritePipeBlockingINTEL $pipe $pointer $packetSize $packetAlignment">;

llvm/lib/Target/SPIRV/SPIRVModuleAnalysis.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,6 +1802,13 @@ void addInstrRequirements(const MachineInstr &MI,
18021802
Reqs.addCapability(
18031803
SPIRV::Capability::CooperativeMatrixCheckedInstructionsINTEL);
18041804
break;
1805+
case SPIRV::OpReadPipeBlockingINTEL:
1806+
case SPIRV::OpWritePipeBlockingINTEL:
1807+
if (ST.canUseExtension(SPIRV::Extension::SPV_INTEL_blocking_pipes)) {
1808+
Reqs.addExtension(SPIRV::Extension::SPV_INTEL_blocking_pipes);
1809+
Reqs.addCapability(SPIRV::Capability::BlockingPipesINTEL);
1810+
}
1811+
break;
18051812
case SPIRV::OpCooperativeMatrixGetElementCoordINTEL:
18061813
if (!ST.canUseExtension(SPIRV::Extension::SPV_INTEL_joint_matrix))
18071814
report_fatal_error("OpCooperativeMatrixGetElementCoordINTEL requires the "

llvm/lib/Target/SPIRV/SPIRVSymbolicOperands.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,7 @@ defm TensorFloat32RoundingINTEL : CapabilityOperand<6425, 0, 0, [SPV_INTEL_tenso
600600
defm BFloat16TypeKHR : CapabilityOperand<5116, 0, 0, [SPV_KHR_bfloat16], []>;
601601
defm BFloat16DotProductKHR : CapabilityOperand<5117, 0, 0, [SPV_KHR_bfloat16], [BFloat16TypeKHR]>;
602602
defm BFloat16CooperativeMatrixKHR : CapabilityOperand<5118, 0, 0, [SPV_KHR_bfloat16], [BFloat16TypeKHR, CooperativeMatrixKHR]>;
603+
defm BlockingPipesINTEL : CapabilityOperand<5945, 0, 0, [SPV_INTEL_blocking_pipes], []>;
603604

604605
//===----------------------------------------------------------------------===//
605606
// Multiclass used to define SourceLanguage enum values and at the same time
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv32-unknown-unknown --spirv-ext=+SPV_INTEL_blocking_pipes %s -o - | FileCheck %s --check-prefixes=CHECK-SPIRV
2+
; TODO: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown --spirv-ext=+SPV_INTEL_blocking_pipes %s -o - -filetype=obj | spirv-val %}
3+
4+
%opencl.pipe_ro_t = type opaque
5+
%opencl.pipe_wo_t = type opaque
6+
7+
; CHECK-SPIRV: OpCapability BlockingPipesINTEL
8+
; CHECK-SPIRV: OpExtension "SPV_INTEL_blocking_pipes"
9+
; CHECK-SPIRV: %[[PipeRTy:[0-9]+]] = OpTypePipe ReadOnly
10+
; CHECK-SPIRV: %[[PipeWTy:[0-9]+]] = OpTypePipe WriteOnly
11+
; CHECK-SPIRV: %[[PipeR1:[0-9]+]] = OpLoad %[[PipeRTy]] %[[#]] Aligned 8
12+
; CHECK-SPIRV: OpReadPipeBlockingINTEL %[[PipeR1]] %[[#]] %[[#]] %[[#]]
13+
; CHECK-SPIRV: %[[PipeR2:[0-9]+]] = OpLoad %[[PipeRTy]] %[[#]] Aligned 8
14+
; CHECK-SPIRV: OpReadPipeBlockingINTEL %[[PipeR2]] %[[#]] %[[#]] %[[#]]
15+
; CHECK-SPIRV: %[[PipeW1:[0-9]+]] = OpLoad %[[PipeWTy]] %[[#]] Aligned 8
16+
; CHECK-SPIRV: OpWritePipeBlockingINTEL %[[PipeW1]] %[[#]] %[[#]] %[[#]]
17+
; CHECK-SPIRV: %[[PipeW2:[0-9]+]] = OpLoad %[[PipeWTy]] %[[#]] Aligned 8
18+
; CHECK-SPIRV: OpWritePipeBlockingINTEL %[[PipeW2]] %[[#]] %[[#]] %[[#]]
19+
20+
21+
; Function Attrs: convergent noinline nounwind optnone
22+
define spir_func void @foo(target("spirv.Pipe", 0) %p, ptr addrspace(1) %ptr) #0 {
23+
entry:
24+
%p.addr = alloca target("spirv.Pipe", 0), align 8
25+
%ptr.addr = alloca ptr addrspace(1), align 8
26+
store target("spirv.Pipe", 0) %p, target("spirv.Pipe", 0)* %p.addr, align 8
27+
store ptr addrspace(1) %ptr, ptr %ptr.addr, align 8
28+
%0 = load target("spirv.Pipe", 0), target("spirv.Pipe", 0)* %p.addr, align 8
29+
%1 = load ptr addrspace(1), ptr %ptr.addr, align 8
30+
%2 = addrspacecast ptr addrspace(1) %1 to ptr addrspace(4)
31+
call spir_func void @_Z29__spirv_ReadPipeBlockingINTELIiEv8ocl_pipePiii(target("spirv.Pipe", 0) %0, ptr addrspace(4) %2, i32 4, i32 4)
32+
ret void
33+
}
34+
35+
declare dso_local spir_func void @_Z29__spirv_ReadPipeBlockingINTELIiEv8ocl_pipePiii(target("spirv.Pipe", 0), ptr addrspace(4), i32, i32)
36+
37+
; Function Attrs: convergent noinline nounwind optnone
38+
define spir_func void @bar(target("spirv.Pipe", 0) %p, ptr addrspace(1) %ptr) #0 {
39+
entry:
40+
%p.addr = alloca target("spirv.Pipe", 0), align 8
41+
%ptr.addr = alloca ptr addrspace(1), align 8
42+
store target("spirv.Pipe", 0) %p, target("spirv.Pipe", 0)* %p.addr, align 8
43+
store ptr addrspace(1) %ptr, ptr %ptr.addr, align 8
44+
%0 = load target("spirv.Pipe", 0), target("spirv.Pipe", 0)* %p.addr, align 8
45+
%1 = load ptr addrspace(1), ptr %ptr.addr, align 8
46+
%2 = addrspacecast ptr addrspace(1) %1 to ptr addrspace(4)
47+
call spir_func void @_Z29__spirv_ReadPipeBlockingINTELIiEv8ocl_pipePvii(target("spirv.Pipe", 0) %0, ptr addrspace(4) %2, i32 4, i32 4)
48+
ret void
49+
}
50+
51+
declare dso_local spir_func void @_Z29__spirv_ReadPipeBlockingINTELIiEv8ocl_pipePvii(target("spirv.Pipe", 0), ptr addrspace(4), i32, i32)
52+
53+
; Function Attrs: convergent noinline nounwind optnone
54+
define spir_func void @boo(target("spirv.Pipe", 1) %p, ptr addrspace(1) %ptr) #0 {
55+
entry:
56+
%p.addr = alloca target("spirv.Pipe", 1), align 8
57+
%ptr.addr = alloca ptr addrspace(1), align 8
58+
store target("spirv.Pipe", 1) %p, target("spirv.Pipe", 1)* %p.addr, align 8
59+
store ptr addrspace(1) %ptr, ptr %ptr.addr, align 8
60+
%0 = load target("spirv.Pipe", 1), target("spirv.Pipe", 1)* %p.addr, align 8
61+
%1 = load ptr addrspace(1), ptr %ptr.addr, align 8
62+
%2 = addrspacecast ptr addrspace(1) %1 to ptr addrspace(4)
63+
call spir_func void @_Z30__spirv_WritePipeBlockingINTELIKiEv8ocl_pipePiii(target("spirv.Pipe", 1) %0, ptr addrspace(4) %2, i32 4, i32 4)
64+
ret void
65+
}
66+
67+
declare dso_local spir_func void @_Z30__spirv_WritePipeBlockingINTELIKiEv8ocl_pipePiii(target("spirv.Pipe", 1), ptr addrspace(4), i32, i32)
68+
69+
; Function Attrs: convergent noinline nounwind optnone
70+
define spir_func void @baz(target("spirv.Pipe", 1) %p, ptr addrspace(1) %ptr) #0 {
71+
entry:
72+
%p.addr = alloca target("spirv.Pipe", 1), align 8
73+
%ptr.addr = alloca ptr addrspace(1), align 8
74+
store target("spirv.Pipe", 1) %p, target("spirv.Pipe", 1)* %p.addr, align 8
75+
store ptr addrspace(1) %ptr, ptr %ptr.addr, align 8
76+
%0 = load target("spirv.Pipe", 1), target("spirv.Pipe", 1)* %p.addr, align 8
77+
%1 = load ptr addrspace(1), ptr %ptr.addr, align 8
78+
%2 = addrspacecast ptr addrspace(1) %1 to ptr addrspace(4)
79+
call spir_func void @_Z30__spirv_WritePipeBlockingINTELIKiEv8ocl_pipePvii(target("spirv.Pipe", 1) %0, ptr addrspace(4) %2, i32 4, i32 4)
80+
ret void
81+
}
82+
83+
declare dso_local spir_func void @_Z30__spirv_WritePipeBlockingINTELIKiEv8ocl_pipePvii(target("spirv.Pipe", 1), ptr addrspace(4), i32, i32)
84+
85+
; CHECK-LLVM: declare spir_func void @__read_pipe_2_bl(ptr addrspace(1), ptr addrspace(4), i32, i32)
86+
; CHECK-LLVM: declare spir_func void @__write_pipe_2_bl(ptr addrspace(1), ptr addrspace(4), i32, i32)
87+
88+
; Function Attrs: convergent mustprogress norecurse nounwind
89+
define linkonce_odr dso_local spir_func void @WritePipeBLockingi9Pointer(ptr addrspace(4) align 2 dereferenceable(2) %_Data) {
90+
entry:
91+
%_Data.addr = alloca ptr addrspace(4), align 8
92+
%_WPipe = alloca target("spirv.Pipe", 1), align 8
93+
%_Data.addr.ascast = addrspacecast ptr %_Data.addr to ptr addrspace(4)
94+
%_WPipe.ascast = addrspacecast target("spirv.Pipe", 1)* %_WPipe to target("spirv.Pipe", 1) addrspace(4)*
95+
store ptr addrspace(4) %_Data, ptr addrspace(4) %_Data.addr.ascast, align 8
96+
%0 = bitcast target("spirv.Pipe", 1)* %_WPipe to ptr
97+
%1 = load target("spirv.Pipe", 1), target("spirv.Pipe", 1) addrspace(4)* %_WPipe.ascast, align 8
98+
%2 = load ptr addrspace(4), ptr addrspace(4) %_Data.addr.ascast, align 8
99+
call spir_func void @_Z30__spirv_WritePipeBlockingINTELIDU9_Ev8ocl_pipePKT_ii(target("spirv.Pipe", 1) %1, ptr addrspace(4) %2, i32 2, i32 2)
100+
ret void
101+
}
102+
103+
declare dso_local spir_func void @_Z30__spirv_WritePipeBlockingINTELIDU9_Ev8ocl_pipePKT_ii(target("spirv.Pipe", 1), ptr addrspace(4), i32, i32)
104+
105+
attributes #0 = { convergent noinline nounwind optnone "correctly-rounded-divide-sqrt-fp-math"="false" "denorms-are-zero"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="false" "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" "unsafe-fp-math"="false" "use-soft-float"="false" }
106+
107+
!llvm.module.flags = !{!0}
108+
!opencl.ocl.version = !{!1}
109+
!opencl.spir.version = !{!1}
110+
!llvm.ident = !{!2}
111+
112+
!0 = !{i32 1, !"wchar_size", i32 4}
113+
!1 = !{i32 2, i32 0}
114+
!2 = !{!"clang version 9.0.0 (https://github.com/MrSidims/llvm.git c627b787284c5bcc917ea9742908baa1b856e176)"}
115+

0 commit comments

Comments
 (0)