Skip to content

Commit 3a1228a

Browse files
authored
[SPIRV] Add GroupMemoryBarrierWithGroupSync intrinsic (#111888)
partially fixes #70103 ### Changes * Added int_spv_group_memory_barrier_with_group_sync intrinsic in IntrinsicsSPIRV.td * Added lowering for int_spv_group_memory_barrier_with_group_sync in SPIRVInstructionSelector.cpp * Added SPIRV backend test case ### Related PRs * [[clang][HLSL] Add GroupMemoryBarrierWithGroupSync intrinsic #111883](#111883) * [[DXIL] Add GroupMemoryBarrierWithGroupSync intrinsic #111884](#111884)
1 parent 3754fc1 commit 3a1228a

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

llvm/include/llvm/IR/IntrinsicsSPIRV.td

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ let TargetPrefix = "spv" in {
8787
def int_spv_wave_readlane : DefaultAttrsIntrinsic<[llvm_any_ty], [LLVMMatchType<0>, llvm_i32_ty], [IntrConvergent, IntrNoMem]>;
8888
def int_spv_sign : DefaultAttrsIntrinsic<[LLVMScalarOrSameVectorWidth<0, llvm_i32_ty>], [llvm_any_ty], [IntrNoMem]>;
8989
def int_spv_radians : DefaultAttrsIntrinsic<[LLVMMatchType<0>], [llvm_anyfloat_ty], [IntrNoMem]>;
90+
def int_spv_group_memory_barrier_with_group_sync : DefaultAttrsIntrinsic<[], [], []>;
9091

9192
// Create resource handle given the binding information. Returns a
9293
// type appropriate for the kind of resource given the set id, binding id,

llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2547,6 +2547,17 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register ResVReg,
25472547
return selectExtInst(ResVReg, ResType, I, CL::rsqrt, GL::InverseSqrt);
25482548
case Intrinsic::spv_sign:
25492549
return selectSign(ResVReg, ResType, I);
2550+
case Intrinsic::spv_group_memory_barrier_with_group_sync: {
2551+
Register MemSemReg =
2552+
buildI32Constant(SPIRV::MemorySemantics::SequentiallyConsistent, I);
2553+
Register ScopeReg = buildI32Constant(SPIRV::Scope::Workgroup, I);
2554+
MachineBasicBlock &BB = *I.getParent();
2555+
return BuildMI(BB, I, I.getDebugLoc(), TII.get(SPIRV::OpControlBarrier))
2556+
.addUse(ScopeReg)
2557+
.addUse(ScopeReg)
2558+
.addUse(MemSemReg)
2559+
.constrainAllUses(TII, TRI, RBI);
2560+
} break;
25502561
case Intrinsic::spv_lifetime_start:
25512562
case Intrinsic::spv_lifetime_end: {
25522563
unsigned Op = IID == Intrinsic::spv_lifetime_start ? SPIRV::OpLifetimeStart
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s
2+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - -filetype=obj | spirv-val %}
3+
4+
; CHECK: OpMemoryModel Logical GLSL450
5+
6+
define void @test_group_memory_barrier_with_group_sync() {
7+
entry:
8+
; CHECK: %[[#TY:]] = OpTypeInt 32 0
9+
; CHECK-DAG: %[[#MEM_SEM:]] = OpConstant %[[#TY]] 16
10+
; CHECK-DAG: %[[#EXEC_AND_MEM_SCOPE:]] = OpConstant %[[#TY]] 2
11+
; CHECK: OpControlBarrier %[[#EXEC_AND_MEM_SCOPE]] %[[#EXEC_AND_MEM_SCOPE]] %[[#MEM_SEM]]
12+
call void @llvm.spv.group.memory.barrier.with.group.sync()
13+
ret void
14+
}

0 commit comments

Comments
 (0)