llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-spir-v

Author: Sietze Riemersma (KungFuDonkey)

<details>
<summary>Changes</summary>

>From issue #<!-- -->99105, #<!-- -->99076, #<!-- -->99090, #<!-- -->99106 and 
>adds the implementation of DeviceMemoryBarrier(WithGroupSync) and 
>AllMemoryBarrier(WithGroupSync) to DXIL and SPIRV.

---

Patch is 28.20 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/190633.diff


26 Files Affected:

- (modified) clang/include/clang/Basic/Builtins.td (+24) 
- (modified) clang/lib/CodeGen/CGHLSLBuiltins.cpp (+22) 
- (modified) clang/lib/CodeGen/CGHLSLRuntime.h (+6) 
- (modified) clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h (+47-1) 
- (added) clang/test/CodeGenHLSL/builtins/AllMemoryBarrier.hlsl (+20) 
- (added) clang/test/CodeGenHLSL/builtins/AllMemoryBarrierWithGroupSync.hlsl 
(+20) 
- (added) clang/test/CodeGenHLSL/builtins/DeviceMemoryBarrier.hlsl (+20) 
- (added) clang/test/CodeGenHLSL/builtins/DeviceMemoryBarrierWithGroupSync.hlsl 
(+20) 
- (added) clang/test/SemaHLSL/BuiltIns/AllMemoryBarrier-errors.hlsl (+6) 
- (added) 
clang/test/SemaHLSL/BuiltIns/AllMemoryBarrierWithGroupSync-errors.hlsl (+6) 
- (added) clang/test/SemaHLSL/BuiltIns/DeviceMemoryBarrier-errors.hlsl (+6) 
- (added) 
clang/test/SemaHLSL/BuiltIns/DeviceMemoryBarrierWithGroupSync-errors.hlsl (+6) 
- (modified) llvm/include/llvm/IR/IntrinsicsDirectX.td (+12) 
- (modified) llvm/include/llvm/IR/IntrinsicsSPIRV.td (+4) 
- (modified) llvm/lib/Target/DirectX/DXIL.td (+8) 
- (modified) llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp (+29-6) 
- (added) llvm/test/CodeGen/DirectX/all_memory_barrier.ll (+8) 
- (added) llvm/test/CodeGen/DirectX/all_memory_barrier_with_group_sync.ll (+8) 
- (added) llvm/test/CodeGen/DirectX/device_memory_barrier.ll (+8) 
- (added) llvm/test/CodeGen/DirectX/device_memory_barrier_with_group_sync.ll 
(+8) 
- (added) llvm/test/CodeGen/SPIRV/hlsl-intrinsics/all_memory_barrier.ll (+16) 
- (added) 
llvm/test/CodeGen/SPIRV/hlsl-intrinsics/all_memory_barrier_with_group_sync.ll 
(+17) 
- (added) llvm/test/CodeGen/SPIRV/hlsl-intrinsics/device_memory_barrier.ll 
(+16) 
- (added) 
llvm/test/CodeGen/SPIRV/hlsl-intrinsics/device_memory_barrier_with_group_sync.ll
 (+17) 
- (modified) llvm/test/CodeGen/SPIRV/hlsl-intrinsics/group_memory_barrier.ll 
(+2-2) 
- (modified) 
llvm/test/CodeGen/SPIRV/hlsl-intrinsics/group_memory_barrier_with_group_sync.ll 
(+1-1) 


``````````diff
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index b8bbc544595e2..33c176261c9e1 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -5492,6 +5492,30 @@ def HLSLClip: LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+def HLSLAllMemoryBarrier : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_all_memory_barrier"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void()";
+}
+
+def HLSLAllMemoryBarrierWithGroupSync: LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_all_memory_barrier_with_group_sync"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void()";
+}
+
+def HLSLDeviceMemoryBarrier : LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_device_memory_barrier"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void()";
+}
+
+def HLSLDeviceMemoryBarrierWithGroupSync: LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_hlsl_device_memory_barrier_with_group_sync"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void()";
+}
+
 def HLSLGroupMemoryBarrier : LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_group_memory_barrier"];
   let Attributes = [NoThrow, Const];
diff --git a/clang/lib/CodeGen/CGHLSLBuiltins.cpp 
b/clang/lib/CodeGen/CGHLSLBuiltins.cpp
index f510195dbd6cb..b82a237ecefca 100644
--- a/clang/lib/CodeGen/CGHLSLBuiltins.cpp
+++ b/clang/lib/CodeGen/CGHLSLBuiltins.cpp
@@ -1566,6 +1566,28 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
     assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
            "clip operands types mismatch");
     return handleHlslClip(E, this);
+  case Builtin::BI__builtin_hlsl_all_memory_barrier: {
+    Intrinsic::ID ID = CGM.getHLSLRuntime().getAllMemoryBarrierIntrinsic();
+    return EmitRuntimeCall(
+        Intrinsic::getOrInsertDeclaration(&CGM.getModule(), ID));
+  }
+  case Builtin::BI__builtin_hlsl_all_memory_barrier_with_group_sync: {
+    Intrinsic::ID ID =
+        CGM.getHLSLRuntime().getAllMemoryBarrierWithGroupSyncIntrinsic();
+    return EmitRuntimeCall(
+        Intrinsic::getOrInsertDeclaration(&CGM.getModule(), ID));
+  }
+  case Builtin::BI__builtin_hlsl_device_memory_barrier: {
+    Intrinsic::ID ID = CGM.getHLSLRuntime().getDeviceMemoryBarrierIntrinsic();
+    return EmitRuntimeCall(
+        Intrinsic::getOrInsertDeclaration(&CGM.getModule(), ID));
+  }
+  case Builtin::BI__builtin_hlsl_device_memory_barrier_with_group_sync: {
+    Intrinsic::ID ID =
+        CGM.getHLSLRuntime().getDeviceMemoryBarrierWithGroupSyncIntrinsic();
+    return EmitRuntimeCall(
+        Intrinsic::getOrInsertDeclaration(&CGM.getModule(), ID));
+  }
   case Builtin::BI__builtin_hlsl_group_memory_barrier: {
     Intrinsic::ID ID = CGM.getHLSLRuntime().getGroupMemoryBarrierIntrinsic();
     return EmitRuntimeCall(
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h 
b/clang/lib/CodeGen/CGHLSLRuntime.h
index b1c5b3318a11e..21e7ddf394bbd 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -189,6 +189,12 @@ class CGHLSLRuntime {
   GENERATE_HLSL_INTRINSIC_FUNCTION(NonUniformResourceIndex,
                                    resource_nonuniformindex)
   GENERATE_HLSL_INTRINSIC_FUNCTION(BufferUpdateCounter, resource_updatecounter)
+  GENERATE_HLSL_INTRINSIC_FUNCTION(AllMemoryBarrier, all_memory_barrier)
+  GENERATE_HLSL_INTRINSIC_FUNCTION(AllMemoryBarrierWithGroupSync,
+                                   all_memory_barrier_with_group_sync)
+  GENERATE_HLSL_INTRINSIC_FUNCTION(DeviceMemoryBarrier, device_memory_barrier)
+  GENERATE_HLSL_INTRINSIC_FUNCTION(DeviceMemoryBarrierWithGroupSync,
+                                   device_memory_barrier_with_group_sync)
   GENERATE_HLSL_INTRINSIC_FUNCTION(GroupMemoryBarrier, group_memory_barrier)
   GENERATE_HLSL_INTRINSIC_FUNCTION(GroupMemoryBarrierWithGroupSync,
                                    group_memory_barrier_with_group_sync)
diff --git a/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h
index 80c415ef66644..9581c1543f468 100644
--- a/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h
@@ -3927,7 +3927,53 @@ _HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_radians)
 float4 radians(float4);
 
 
//===----------------------------------------------------------------------===//
-// GroupMemoryBarrierbuiltins
+// AllMemoryBarrier builtins
+//===----------------------------------------------------------------------===//
+
+/// \fn void AllMemoryBarrier(void)
+/// \brief Blocks execution of all threads in a group until all memory
+/// accesses have been completed.
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_all_memory_barrier)
+__attribute__((convergent)) void AllMemoryBarrier(void);
+
+//===----------------------------------------------------------------------===//
+// AllMemoryBarrierWithGroupSync builtins
+//===----------------------------------------------------------------------===//
+
+/// \fn void AllMemoryBarrierWithGroupSync(void)
+/// \brief Blocks execution of all threads in a group until all memory
+/// accesses have been completed and all threads in the group have reached this
+/// call.
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_all_memory_barrier_with_group_sync)
+__attribute__((convergent)) void AllMemoryBarrierWithGroupSync(void);
+
+//===----------------------------------------------------------------------===//
+// DeviceMemoryBarrier builtins
+//===----------------------------------------------------------------------===//
+
+/// \fn void DeviceMemoryBarrier(void)
+/// \brief Blocks execution of all threads in a group until all device memory
+/// accesses have been completed.
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_device_memory_barrier)
+__attribute__((convergent)) void DeviceMemoryBarrier(void);
+
+//===----------------------------------------------------------------------===//
+// DeviceMemoryBarrierWithGroupSync builtins
+//===----------------------------------------------------------------------===//
+
+/// \fn void DeviceMemoryBarrierWithGroupSync(void)
+/// \brief Blocks execution of all threads in a group until all device memory
+/// accesses have been completed and all threads in the group have reached this
+/// call.
+
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_device_memory_barrier_with_group_sync)
+__attribute__((convergent)) void DeviceMemoryBarrierWithGroupSync(void);
+
+//===----------------------------------------------------------------------===//
+// GroupMemoryBarrier builtins
 
//===----------------------------------------------------------------------===//
 
 /// \fn void GroupMemoryBarrier(void)
diff --git a/clang/test/CodeGenHLSL/builtins/AllMemoryBarrier.hlsl 
b/clang/test/CodeGenHLSL/builtins/AllMemoryBarrier.hlsl
new file mode 100644
index 0000000000000..90d51c716c771
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/AllMemoryBarrier.hlsl
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s \
+// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
+// RUN:   -DTARGET=dx -check-prefixes=CHECK,CHECK-DXIL
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
+// RUN:   spirv-unknown-vulkan-compute %s \
+// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
+// RUN:   -DTARGET=spv -check-prefixes=CHECK,CHECK-SPIRV
+
+// CHECK-DXIL: define hidden void @
+// CHECK-SPIRV: define hidden spir_func void @
+void test_AllMemoryBarrier() {
+// CHECK-DXIL: call void @llvm.[[TARGET]].all.memory.barrier()
+// CHECK-SPIRV: call spir_func void @llvm.[[TARGET]].all.memory.barrier()
+  AllMemoryBarrier();
+}
+
+// CHECK: declare void @llvm.[[TARGET]].all.memory.barrier() #[[ATTRS:[0-9]+]]
+// CHECK-NOT: attributes #[[ATTRS]] = {{.+}}memory(none){{.+}}
+// CHECK: attributes #[[ATTRS]] = {{.+}}convergent{{.+}}
diff --git a/clang/test/CodeGenHLSL/builtins/AllMemoryBarrierWithGroupSync.hlsl 
b/clang/test/CodeGenHLSL/builtins/AllMemoryBarrierWithGroupSync.hlsl
new file mode 100644
index 0000000000000..6ddb69671e094
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/AllMemoryBarrierWithGroupSync.hlsl
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s \
+// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
+// RUN:   -DTARGET=dx -check-prefixes=CHECK,CHECK-DXIL
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
+// RUN:   spirv-unknown-vulkan-compute %s \
+// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
+// RUN:   -DTARGET=spv -check-prefixes=CHECK,CHECK-SPIRV
+
+// CHECK-DXIL: define hidden void @
+// CHECK-SPIRV: define hidden spir_func void @
+void test_AllMemoryBarrierWithGroupSync() {
+// CHECK-DXIL: call void @llvm.[[TARGET]].all.memory.barrier.with.group.sync()
+// CHECK-SPIRV: call spir_func void 
@llvm.[[TARGET]].all.memory.barrier.with.group.sync()
+  AllMemoryBarrierWithGroupSync();
+}
+
+// CHECK: declare void @llvm.[[TARGET]].all.memory.barrier.with.group.sync() 
#[[ATTRS:[0-9]+]]
+// CHECK-NOT: attributes #[[ATTRS]] = {{.+}}memory(none){{.+}}
+// CHECK: attributes #[[ATTRS]] = {{.+}}convergent{{.+}}
diff --git a/clang/test/CodeGenHLSL/builtins/DeviceMemoryBarrier.hlsl 
b/clang/test/CodeGenHLSL/builtins/DeviceMemoryBarrier.hlsl
new file mode 100644
index 0000000000000..e2c08f7775c8c
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/DeviceMemoryBarrier.hlsl
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s \
+// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
+// RUN:   -DTARGET=dx -check-prefixes=CHECK,CHECK-DXIL
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
+// RUN:   spirv-unknown-vulkan-compute %s \
+// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
+// RUN:   -DTARGET=spv -check-prefixes=CHECK,CHECK-SPIRV
+
+// CHECK-DXIL: define hidden void @
+// CHECK-SPIRV: define hidden spir_func void @
+void test_DeviceMemoryBarrier() {
+// CHECK-DXIL: call void @llvm.[[TARGET]].device.memory.barrier()
+// CHECK-SPIRV: call spir_func void @llvm.[[TARGET]].device.memory.barrier()
+  DeviceMemoryBarrier();
+}
+
+// CHECK: declare void @llvm.[[TARGET]].device.memory.barrier() 
#[[ATTRS:[0-9]+]]
+// CHECK-NOT: attributes #[[ATTRS]] = {{.+}}memory(none){{.+}}
+// CHECK: attributes #[[ATTRS]] = {{.+}}convergent{{.+}}
diff --git 
a/clang/test/CodeGenHLSL/builtins/DeviceMemoryBarrierWithGroupSync.hlsl 
b/clang/test/CodeGenHLSL/builtins/DeviceMemoryBarrierWithGroupSync.hlsl
new file mode 100644
index 0000000000000..fa455f5f8338b
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/DeviceMemoryBarrierWithGroupSync.hlsl
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-library %s \
+// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
+// RUN:   -DTARGET=dx -check-prefixes=CHECK,CHECK-DXIL
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
+// RUN:   spirv-unknown-vulkan-compute %s \
+// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
+// RUN:   -DTARGET=spv -check-prefixes=CHECK,CHECK-SPIRV
+
+// CHECK-DXIL: define hidden void @
+// CHECK-SPIRV: define hidden spir_func void @
+void test_DeviceMemoryBarrierWithGroupSync() {
+// CHECK-DXIL: call void 
@llvm.[[TARGET]].device.memory.barrier.with.group.sync()
+// CHECK-SPIRV: call spir_func void 
@llvm.[[TARGET]].device.memory.barrier.with.group.sync()
+  DeviceMemoryBarrierWithGroupSync();
+}
+
+// CHECK: declare void 
@llvm.[[TARGET]].device.memory.barrier.with.group.sync() #[[ATTRS:[0-9]+]]
+// CHECK-NOT: attributes #[[ATTRS]] = {{.+}}memory(none){{.+}}
+// CHECK: attributes #[[ATTRS]] = {{.+}}convergent{{.+}}
diff --git a/clang/test/SemaHLSL/BuiltIns/AllMemoryBarrier-errors.hlsl 
b/clang/test/SemaHLSL/BuiltIns/AllMemoryBarrier-errors.hlsl
new file mode 100644
index 0000000000000..63fd11a3095d8
--- /dev/null
+++ b/clang/test/SemaHLSL/BuiltIns/AllMemoryBarrier-errors.hlsl
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -emit-llvm-only -disable-llvm-passes -verify
+
+void test_too_many_arg() {
+  __builtin_hlsl_all_memory_barrier(0);
+  // expected-error@-1 {{too many arguments to function call, expected 0, have 
1}}
+}
diff --git 
a/clang/test/SemaHLSL/BuiltIns/AllMemoryBarrierWithGroupSync-errors.hlsl 
b/clang/test/SemaHLSL/BuiltIns/AllMemoryBarrierWithGroupSync-errors.hlsl
new file mode 100644
index 0000000000000..7a50be66ebb8c
--- /dev/null
+++ b/clang/test/SemaHLSL/BuiltIns/AllMemoryBarrierWithGroupSync-errors.hlsl
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -emit-llvm-only -disable-llvm-passes -verify
+
+void test_too_many_arg() {
+  __builtin_hlsl_all_memory_barrier_with_group_sync(0);
+  // expected-error@-1 {{too many arguments to function call, expected 0, have 
1}}
+}
diff --git a/clang/test/SemaHLSL/BuiltIns/DeviceMemoryBarrier-errors.hlsl 
b/clang/test/SemaHLSL/BuiltIns/DeviceMemoryBarrier-errors.hlsl
new file mode 100644
index 0000000000000..16a57a36fc399
--- /dev/null
+++ b/clang/test/SemaHLSL/BuiltIns/DeviceMemoryBarrier-errors.hlsl
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -emit-llvm-only -disable-llvm-passes -verify
+
+void test_too_many_arg() {
+  __builtin_hlsl_device_memory_barrier(0);
+  // expected-error@-1 {{too many arguments to function call, expected 0, have 
1}}
+}
diff --git 
a/clang/test/SemaHLSL/BuiltIns/DeviceMemoryBarrierWithGroupSync-errors.hlsl 
b/clang/test/SemaHLSL/BuiltIns/DeviceMemoryBarrierWithGroupSync-errors.hlsl
new file mode 100644
index 0000000000000..ddbd7ba768009
--- /dev/null
+++ b/clang/test/SemaHLSL/BuiltIns/DeviceMemoryBarrierWithGroupSync-errors.hlsl
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.6-library %s -emit-llvm-only -disable-llvm-passes -verify
+
+void test_too_many_arg() {
+  __builtin_hlsl_device_memory_barrier_with_group_sync(0);
+  // expected-error@-1 {{too many arguments to function call, expected 0, have 
1}}
+}
diff --git a/llvm/include/llvm/IR/IntrinsicsDirectX.td 
b/llvm/include/llvm/IR/IntrinsicsDirectX.td
index 728bf47a17516..fecbff82e3638 100644
--- a/llvm/include/llvm/IR/IntrinsicsDirectX.td
+++ b/llvm/include/llvm/IR/IntrinsicsDirectX.td
@@ -285,6 +285,18 @@ def int_dx_firstbituhigh : 
DefaultAttrsIntrinsic<[LLVMScalarOrSameVectorWidth<0,
 def int_dx_firstbitshigh : 
DefaultAttrsIntrinsic<[LLVMScalarOrSameVectorWidth<0, llvm_i32_ty>], 
[llvm_anyint_ty], [IntrNoMem]>;
 def int_dx_firstbitlow : DefaultAttrsIntrinsic<[LLVMScalarOrSameVectorWidth<0, 
llvm_i32_ty>], [llvm_anyint_ty], [IntrNoMem]>;
 
+def int_dx_all_memory_barrier
+    : DefaultAttrsIntrinsic<[], [], [IntrConvergent]>;
+
+def int_dx_all_memory_barrier_with_group_sync
+    : DefaultAttrsIntrinsic<[], [], [IntrConvergent]>;
+
+def int_dx_device_memory_barrier
+    : DefaultAttrsIntrinsic<[], [], [IntrConvergent]>;
+
+def int_dx_device_memory_barrier_with_group_sync
+    : DefaultAttrsIntrinsic<[], [], [IntrConvergent]>;
+
 def int_dx_group_memory_barrier
     : DefaultAttrsIntrinsic<[], [], [IntrConvergent]>;
 
diff --git a/llvm/include/llvm/IR/IntrinsicsSPIRV.td 
b/llvm/include/llvm/IR/IntrinsicsSPIRV.td
index d2a5fa1f08724..e0c64277ae342 100644
--- a/llvm/include/llvm/IR/IntrinsicsSPIRV.td
+++ b/llvm/include/llvm/IR/IntrinsicsSPIRV.td
@@ -157,6 +157,10 @@ def int_spv_rsqrt : 
DefaultAttrsIntrinsic<[LLVMMatchType<0>], [llvm_anyfloat_ty]
   def int_spv_quad_read_across_y : DefaultAttrsIntrinsic<[llvm_any_ty], 
[LLVMMatchType<0>], [IntrConvergent, IntrNoMem]>;
   def int_spv_sign : DefaultAttrsIntrinsic<[LLVMScalarOrSameVectorWidth<0, 
llvm_i32_ty>], [llvm_any_ty], [IntrNoMem]>;
   def int_spv_radians : DefaultAttrsIntrinsic<[LLVMMatchType<0>], 
[llvm_anyfloat_ty], [IntrNoMem]>;
+  def int_spv_all_memory_barrier : DefaultAttrsIntrinsic<[], [], 
[IntrConvergent]>;
+  def int_spv_all_memory_barrier_with_group_sync : DefaultAttrsIntrinsic<[], 
[], [IntrConvergent]>;
+  def int_spv_device_memory_barrier : DefaultAttrsIntrinsic<[], [], 
[IntrConvergent]>;
+  def int_spv_device_memory_barrier_with_group_sync : 
DefaultAttrsIntrinsic<[], [], [IntrConvergent]>;
   def int_spv_group_memory_barrier : DefaultAttrsIntrinsic<[], [], 
[IntrConvergent]>;
   def int_spv_group_memory_barrier_with_group_sync : 
ClangBuiltin<"__builtin_spirv_group_barrier">,
     DefaultAttrsIntrinsic<[], [], [IntrConvergent]>;
diff --git a/llvm/lib/Target/DirectX/DXIL.td b/llvm/lib/Target/DirectX/DXIL.td
index 0a1e0114aa3bb..41f09f9db1017 100644
--- a/llvm/lib/Target/DirectX/DXIL.td
+++ b/llvm/lib/Target/DirectX/DXIL.td
@@ -931,6 +931,14 @@ def GetDimensions : DXILOp<72, getDimensions> {
 def Barrier : DXILOp<80, barrier> {
   let Doc = "inserts a memory barrier in the shader";
   let intrinsics = [
+    IntrinSelect<int_dx_all_memory_barrier,
+                 [IntrinArgI32<BarrierMode_AllMemoryBarrier>]>,
+    IntrinSelect<int_dx_all_memory_barrier_with_group_sync,
+                 [IntrinArgI32<BarrierMode_AllMemoryBarrierWithGroupSync>]>,
+    IntrinSelect<int_dx_device_memory_barrier,
+                 [IntrinArgI32<BarrierMode_DeviceMemoryBarrier>]>,
+    IntrinSelect<int_dx_device_memory_barrier_with_group_sync,
+                 [IntrinArgI32<BarrierMode_DeviceMemoryBarrierWithGroupSync>]>,
     IntrinSelect<int_dx_group_memory_barrier,
                  [IntrinArgI32<BarrierMode_GroupMemoryBarrier>]>,
     IntrinSelect<int_dx_group_memory_barrier_with_group_sync,
diff --git a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp 
b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
index 9da8397efc22f..8417e591d6128 100644
--- a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
@@ -2928,18 +2928,19 @@ bool 
SPIRVInstructionSelector::selectBarrierInst(MachineInstr &I,
          "Device Scope must set UniformMemory and ImageMemory semantic "
          "in Barrier instruction");
 
-  Register MemSemReg = buildI32Constant(MemSem, I);
-  Register ScopeReg = buildI32Constant(Scope, I);
   MachineBasicBlock &BB = *I.getParent();
-  auto MI =
-      BuildMI(BB, I, I.getDebugLoc(), TII.get(BarrierType)).addUse(ScopeReg);
+  auto MI = BuildMI(BB, I, I.getDebugLoc(), TII.get(BarrierType));
 
   // OpControlBarrier needs to also set Execution Scope
   if (WithGroupSync) {
-    MI.addUse(ScopeReg);
+    Register ExecReg = buildI32Constant(SPIRV::Scope::Workgroup, I);
+    MI.addUse(ExecReg);
   }
 
-  MI.addUse(MemSemReg).constrainAllUses(TII, TRI, RBI);
+  Register ScopeReg = buildI32Constant(Scope, I);
+  Register MemSemReg = buildI32Constant(MemSem, I);
+
+  MI.addUse(ScopeReg).addUse(MemSemReg).constrainAllUses(TII, TRI, RBI);
   return true;
 }
 
@@ -4521,6 +4522,28 @@ bool SPIRVInstructionSelector::selectIntrinsic(Register 
ResVReg,
     return selectFirstBitHigh(ResVReg, ResType, I, /*IsSigned=*/true);
   case Intrinsic::spv_firstbitlow: // There is no CL equivlent of FindILsb
     return selectFirstBitLow(ResVReg, ResType, I);
+  case Intrinsic::spv_all_memory_barrier:
+    return selectBarrierInst(I, SPIRV::Scope::Device,
+                             SPIRV::MemorySemantics::UniformMemory |
+                                 SPIRV::MemorySemantics::ImageMemory |
+                                 SPIRV::MemorySemantics::WorkgroupMemory,
+                             /*WithGroupSync*/ false);
+  case Intrinsic::spv_all_memory_barrier_with_group_sync:
+    return selectBarrierInst(I, SPIRV::Scope::Device,
+                             SPIRV::MemorySemantics::UniformMemory |
+                                 SPIRV::MemorySemantics::ImageMemory |
+                                 SPIRV::MemorySemantics::WorkgroupMemory,
+                             /*WithGroupSync*/ true);
+  case Intrinsic::spv_device_memory_barrier:
+    return selectBarrierInst(I, SPIRV::Scope::Device,
+                             SPIRV::MemorySemantics::UniformMemory |
+                                 SPIRV::MemorySemantics::ImageMemory,
+                             /*WithGroupSync*/ false);
+  case Intrinsic::spv_device_memory_barrier_with_group_sync:
+    return selectBarrierInst(I, SPIRV::Sc...
[truncated]

``````````

</details>


https://github.com/llvm/llvm-project/pull/190633
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to