[clang] [clang][HLSL] Add GroupMemoryBarrierWithGroupSync intrinsic (PR #111883)

Adam Yang via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 2 15:42:30 PST 2024


https://github.com/adam-yang updated https://github.com/llvm/llvm-project/pull/111883

>From b7d329a60d6de140df9d7a2484e7a998c3a7b532 Mon Sep 17 00:00:00 2001
From: Adam Yang <hanbyang at microsoft.com>
Date: Thu, 10 Oct 2024 10:20:37 -0700
Subject: [PATCH 1/8] Added the intrinsic to clang

---
 clang/include/clang/Basic/Builtins.td         |  6 +++++
 clang/lib/CodeGen/CGBuiltin.cpp               |  4 ++++
 clang/lib/CodeGen/CGHLSLRuntime.h             |  1 +
 clang/lib/Headers/hlsl/hlsl_intrinsics.h      | 12 ++++++++++
 clang/lib/Sema/SemaHLSL.cpp                   |  4 ++++
 ...roupMemoryBarrierWithGroupSync-errors.hlsl |  6 +++++
 .../GroupMemoryBarrierWithGroupSync.hlsl      | 22 +++++++++++++++++++
 7 files changed, 55 insertions(+)
 create mode 100644 clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync-errors.hlsl
 create mode 100644 clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync.hlsl

diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td
index db5cd73fba8ad1..dcde6b005c9c3e 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4924,6 +4924,12 @@ def HLSLClip: LangBuiltin<"HLSL_LANG"> {
   let Prototype = "void(...)";
 }
 
+def HLSLGroupMemoryBarrierWithGroupSync: LangBuiltin<"HLSL_LANG"> {
+  let Spellings = ["__builtin_group_memory_barrier_with_group_sync"];
+  let Attributes = [NoThrow, Const];
+  let Prototype = "void(...)";
+}
+
 // Builtins for XRay.
 def XRayCustomEvent : Builtin {
   let Spellings = ["__xray_customevent"];
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index cb9c23b8e0a0d0..3b6ba23a85a010 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19446,6 +19446,10 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
     assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
            "clip operands types mismatch");
     return handleHlslClip(E, this);
+  case Builtin::BI__builtin_group_memory_barrier_with_group_sync: {
+    Intrinsic::ID ID = CGM.getHLSLRuntime().getGroupMemoryBarrierWithGroupSyncIntrinsic();
+    return EmitRuntimeCall(Intrinsic::getDeclaration(&CGM.getModule(), ID));
+  }
   }
   return nullptr;
 }
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h b/clang/lib/CodeGen/CGHLSLRuntime.h
index 854214d6bc0677..767baa441e25a2 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -103,6 +103,7 @@ class CGHLSLRuntime {
 
   GENERATE_HLSL_INTRINSIC_FUNCTION(CreateHandleFromBinding, handle_fromBinding)
   GENERATE_HLSL_INTRINSIC_FUNCTION(BufferUpdateCounter, bufferUpdateCounter)
+  GENERATE_HLSL_INTRINSIC_FUNCTION(GroupMemoryBarrierWithGroupSync, groupMemoryBarrierWithGroupSync)
 
   //===----------------------------------------------------------------------===//
   // End of reserved area for HLSL intrinsic getters.
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index a3e0b5c65a6f52..aacf3ed31ef64b 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -2481,5 +2481,17 @@ float3 radians(float3);
 _HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_radians)
 float4 radians(float4);
 
+//===----------------------------------------------------------------------===//
+// GroupMemoryBarrierWithGroupSync builtins
+//===----------------------------------------------------------------------===//
+
+/// \fn void GroupMemoryBarrierWithGroupSync(void)
+/// \brief Blocks execution of all threads in a group until all group shared
+/// accesses have been completed and all threads in the group have reached this
+/// call.
+
+_HLSL_BUILTIN_ALIAS(__builtin_group_memory_barrier_with_group_sync)
+void GroupMemoryBarrierWithGroupSync(void);
+
 } // namespace hlsl
 #endif //_HLSL_HLSL_INTRINSICS_H_
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 8b2f24a8e4be0a..154f39f716bff7 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -2239,6 +2239,10 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
           << 1;
       return true;
     }
+  }
+  case Builtin::BI__builtin_group_memory_barrier_with_group_sync: {
+    if (SemaRef.checkArgCountAtMost(TheCall, 0))
+      return true;
     break;
   }
   }
diff --git a/clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync-errors.hlsl b/clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync-errors.hlsl
new file mode 100644
index 00000000000000..9ffc1ebce1c909
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync-errors.hlsl
@@ -0,0 +1,6 @@
+// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -verify-ignore-unexpected
+
+void test_too_many_arg() {
+  __builtin_group_memory_barrier_with_group_sync(0);
+  // expected-error at -1 {{too many arguments to function call, expected at most 0, have 1}}
+}
diff --git a/clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync.hlsl b/clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync.hlsl
new file mode 100644
index 00000000000000..f93c1966bf64bc
--- /dev/null
+++ b/clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync.hlsl
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
+// RUN:   dxil-pc-shadermodel6.3-compute %s \
+// RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
+// RUN:   -DTARGET=dx -DFNATTRS=noundef
+// 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 -DFNATTRS="spir_func noundef"
+
+// CHECK: define [[FNATTRS]] i32 @
+[numthreads(1, 1, 1)]
+void main() {
+  while (true) {
+// CHECK: call void @llvm.[[TARGET]].groupMemoryBarrierWithGroupSync()
+  GroupMemoryBarrierWithGroupSync();
+  break;
+  }
+}
+
+// CHECK: declare void @llvm.[[TARGET]].groupMemoryBarrierWithGroupSync() #[[ATTRS:[0-9]+]]
+// CHECK-NOT: attributes #[[ATTRS]] = {{.+}}memory(none){{.+}}
+// CHECK: attributes #[[ATTRS]] = {

>From bff904d1fee63ee0510df4ec5d5d36eabf87b867 Mon Sep 17 00:00:00 2001
From: Adam Yang <hanbyang at microsoft.com>
Date: Thu, 10 Oct 2024 11:17:36 -0700
Subject: [PATCH 2/8] Tests fixed

---
 .../GroupMemoryBarrierWithGroupSync-errors.hlsl   |  2 +-
 .../builtins/GroupMemoryBarrierWithGroupSync.hlsl | 15 ++++++---------
 2 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync-errors.hlsl b/clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync-errors.hlsl
index 9ffc1ebce1c909..58d265c7c56f38 100644
--- a/clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync-errors.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync-errors.hlsl
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only -disable-llvm-passes -verify -verify-ignore-unexpected
+// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -emit-llvm-only -disable-llvm-passes -verify -verify-ignore-unexpected
 
 void test_too_many_arg() {
   __builtin_group_memory_barrier_with_group_sync(0);
diff --git a/clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync.hlsl b/clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync.hlsl
index f93c1966bf64bc..1287de6119384a 100644
--- a/clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync.hlsl
@@ -1,20 +1,17 @@
 // RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
-// RUN:   dxil-pc-shadermodel6.3-compute %s \
+// RUN:   dxil-pc-shadermodel6.0-library %s \
 // RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
-// RUN:   -DTARGET=dx -DFNATTRS=noundef
+// RUN:   -DTARGET=dx -DFNATTRS=noundef -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 -DFNATTRS="spir_func noundef"
+// RUN:   -DTARGET=spv -DFNATTRS="spir_func noundef" -check-prefixes=CHECK,CHECK-SPIRV
 
-// CHECK: define [[FNATTRS]] i32 @
-[numthreads(1, 1, 1)]
-void main() {
-  while (true) {
+// CHECK-DXIL: define void @
+// CHECK-SPIRV: define spir_func void @
+void test_GroupMemoryBarrierWithGroupSync() {
 // CHECK: call void @llvm.[[TARGET]].groupMemoryBarrierWithGroupSync()
   GroupMemoryBarrierWithGroupSync();
-  break;
-  }
 }
 
 // CHECK: declare void @llvm.[[TARGET]].groupMemoryBarrierWithGroupSync() #[[ATTRS:[0-9]+]]

>From 759d9cdd95c0e40fa67ca2fce0680e81f500b747 Mon Sep 17 00:00:00 2001
From: Adam Yang <hanbyang at microsoft.com>
Date: Thu, 10 Oct 2024 12:30:58 -0700
Subject: [PATCH 3/8] Fixed formatting, missing hlsl prefix in the builtin, and
 reflected the naming changes in the intrinsics

---
 clang/include/clang/Basic/Builtins.td                        | 2 +-
 clang/lib/CodeGen/CGBuiltin.cpp                              | 5 +++--
 clang/lib/CodeGen/CGHLSLRuntime.h                            | 3 ++-
 clang/lib/Headers/hlsl/hlsl_intrinsics.h                     | 2 +-
 clang/lib/Sema/SemaHLSL.cpp                                  | 2 +-
 .../builtins/GroupMemoryBarrierWithGroupSync-errors.hlsl     | 2 +-
 .../builtins/GroupMemoryBarrierWithGroupSync.hlsl            | 4 ++--
 7 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td
index dcde6b005c9c3e..c4e5808b9f2b93 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4925,7 +4925,7 @@ def HLSLClip: LangBuiltin<"HLSL_LANG"> {
 }
 
 def HLSLGroupMemoryBarrierWithGroupSync: LangBuiltin<"HLSL_LANG"> {
-  let Spellings = ["__builtin_group_memory_barrier_with_group_sync"];
+  let Spellings = ["__builtin_hlsl_group_memory_barrier_with_group_sync"];
   let Attributes = [NoThrow, Const];
   let Prototype = "void(...)";
 }
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 3b6ba23a85a010..2ca9d5f518795f 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19446,8 +19446,9 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
     assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
            "clip operands types mismatch");
     return handleHlslClip(E, this);
-  case Builtin::BI__builtin_group_memory_barrier_with_group_sync: {
-    Intrinsic::ID ID = CGM.getHLSLRuntime().getGroupMemoryBarrierWithGroupSyncIntrinsic();
+  case Builtin::BI__builtin_hlsl_group_memory_barrier_with_group_sync: {
+    Intrinsic::ID ID =
+        CGM.getHLSLRuntime().getGroupMemoryBarrierWithGroupSyncIntrinsic();
     return EmitRuntimeCall(Intrinsic::getDeclaration(&CGM.getModule(), ID));
   }
   }
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.h b/clang/lib/CodeGen/CGHLSLRuntime.h
index 767baa441e25a2..bb120c8b5e9e60 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.h
+++ b/clang/lib/CodeGen/CGHLSLRuntime.h
@@ -103,7 +103,8 @@ class CGHLSLRuntime {
 
   GENERATE_HLSL_INTRINSIC_FUNCTION(CreateHandleFromBinding, handle_fromBinding)
   GENERATE_HLSL_INTRINSIC_FUNCTION(BufferUpdateCounter, bufferUpdateCounter)
-  GENERATE_HLSL_INTRINSIC_FUNCTION(GroupMemoryBarrierWithGroupSync, groupMemoryBarrierWithGroupSync)
+  GENERATE_HLSL_INTRINSIC_FUNCTION(GroupMemoryBarrierWithGroupSync,
+                                   group_memory_barrier_with_group_sync)
 
   //===----------------------------------------------------------------------===//
   // End of reserved area for HLSL intrinsic getters.
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index aacf3ed31ef64b..1126e13600f8af 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -2490,7 +2490,7 @@ float4 radians(float4);
 /// accesses have been completed and all threads in the group have reached this
 /// call.
 
-_HLSL_BUILTIN_ALIAS(__builtin_group_memory_barrier_with_group_sync)
+_HLSL_BUILTIN_ALIAS(__builtin_hlsl_group_memory_barrier_with_group_sync)
 void GroupMemoryBarrierWithGroupSync(void);
 
 } // namespace hlsl
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 154f39f716bff7..095eeb256d56c9 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -2240,7 +2240,7 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
       return true;
     }
   }
-  case Builtin::BI__builtin_group_memory_barrier_with_group_sync: {
+  case Builtin::BI__builtin_hlsl_group_memory_barrier_with_group_sync: {
     if (SemaRef.checkArgCountAtMost(TheCall, 0))
       return true;
     break;
diff --git a/clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync-errors.hlsl b/clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync-errors.hlsl
index 58d265c7c56f38..82f36758d8f9ec 100644
--- a/clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync-errors.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync-errors.hlsl
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -emit-llvm-only -disable-llvm-passes -verify -verify-ignore-unexpected
 
 void test_too_many_arg() {
-  __builtin_group_memory_barrier_with_group_sync(0);
+  __builtin_hlsl_group_memory_barrier_with_group_sync(0);
   // expected-error at -1 {{too many arguments to function call, expected at most 0, have 1}}
 }
diff --git a/clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync.hlsl b/clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync.hlsl
index 1287de6119384a..145cb21f775b08 100644
--- a/clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync.hlsl
@@ -10,10 +10,10 @@
 // CHECK-DXIL: define void @
 // CHECK-SPIRV: define spir_func void @
 void test_GroupMemoryBarrierWithGroupSync() {
-// CHECK: call void @llvm.[[TARGET]].groupMemoryBarrierWithGroupSync()
+// CHECK: call void @llvm.[[TARGET]].group.memory.barrier.with.group.sync()
   GroupMemoryBarrierWithGroupSync();
 }
 
-// CHECK: declare void @llvm.[[TARGET]].groupMemoryBarrierWithGroupSync() #[[ATTRS:[0-9]+]]
+// CHECK: declare void @llvm.[[TARGET]].group.memory.barrier.with.group.sync() #[[ATTRS:[0-9]+]]
 // CHECK-NOT: attributes #[[ATTRS]] = {{.+}}memory(none){{.+}}
 // CHECK: attributes #[[ATTRS]] = {

>From d07949be84ac6a7a059e34fb8ee6d1d7a10cbd7d Mon Sep 17 00:00:00 2001
From: Adam Yang <hanbyang at microsoft.com>
Date: Thu, 10 Oct 2024 13:26:01 -0700
Subject: [PATCH 4/8] Moved error test to the test folder. Changed lib shader
 model to 6.3

---
 .../CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync.hlsl   | 2 +-
 .../BuiltIns}/GroupMemoryBarrierWithGroupSync-errors.hlsl       | 0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename clang/test/{CodeGenHLSL/builtins => SemaHLSL/BuiltIns}/GroupMemoryBarrierWithGroupSync-errors.hlsl (100%)

diff --git a/clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync.hlsl b/clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync.hlsl
index 145cb21f775b08..333a1d68cdf3aa 100644
--- a/clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync.hlsl
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
-// RUN:   dxil-pc-shadermodel6.0-library %s \
+// RUN:   dxil-pc-shadermodel6.3-library %s \
 // RUN:   -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
 // RUN:   -DTARGET=dx -DFNATTRS=noundef -check-prefixes=CHECK,CHECK-DXIL
 // RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
diff --git a/clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/GroupMemoryBarrierWithGroupSync-errors.hlsl
similarity index 100%
rename from clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync-errors.hlsl
rename to clang/test/SemaHLSL/BuiltIns/GroupMemoryBarrierWithGroupSync-errors.hlsl

>From 62d1256e66da4a41eb3610d9fc15a1a79999c5a6 Mon Sep 17 00:00:00 2001
From: Adam Yang <hanbyang at microsoft.com>
Date: Tue, 15 Oct 2024 12:36:22 -0700
Subject: [PATCH 5/8] Removed unneeded `-verify-ignore-unexpected` in the
 errors test. Removed the unneeded arguments in the builtin definition

---
 clang/include/clang/Basic/Builtins.td                           | 2 +-
 .../BuiltIns/GroupMemoryBarrierWithGroupSync-errors.hlsl        | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/Builtins.td b/clang/include/clang/Basic/Builtins.td
index c4e5808b9f2b93..98d7b2b1720637 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4927,7 +4927,7 @@ def HLSLClip: LangBuiltin<"HLSL_LANG"> {
 def HLSLGroupMemoryBarrierWithGroupSync: LangBuiltin<"HLSL_LANG"> {
   let Spellings = ["__builtin_hlsl_group_memory_barrier_with_group_sync"];
   let Attributes = [NoThrow, Const];
-  let Prototype = "void(...)";
+  let Prototype = "void()";
 }
 
 // Builtins for XRay.
diff --git a/clang/test/SemaHLSL/BuiltIns/GroupMemoryBarrierWithGroupSync-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/GroupMemoryBarrierWithGroupSync-errors.hlsl
index 82f36758d8f9ec..8de093f5368dfc 100644
--- a/clang/test/SemaHLSL/BuiltIns/GroupMemoryBarrierWithGroupSync-errors.hlsl
+++ b/clang/test/SemaHLSL/BuiltIns/GroupMemoryBarrierWithGroupSync-errors.hlsl
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.6-library %s -emit-llvm-only -disable-llvm-passes -verify -verify-ignore-unexpected
+// 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_group_memory_barrier_with_group_sync(0);

>From 551589a42c23f871e119239912674ab00f6798d3 Mon Sep 17 00:00:00 2001
From: Adam Yang <31109344+adam-yang at users.noreply.github.com>
Date: Tue, 15 Oct 2024 16:26:21 -0700
Subject: [PATCH 6/8] No longer checking the args for the builtin, since the
 declaration no longer has any arguments

---
 clang/lib/Sema/SemaHLSL.cpp                                  | 5 -----
 .../BuiltIns/GroupMemoryBarrierWithGroupSync-errors.hlsl     | 2 +-
 2 files changed, 1 insertion(+), 6 deletions(-)

diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 095eeb256d56c9..5ea6c1970acb01 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -2240,11 +2240,6 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
       return true;
     }
   }
-  case Builtin::BI__builtin_hlsl_group_memory_barrier_with_group_sync: {
-    if (SemaRef.checkArgCountAtMost(TheCall, 0))
-      return true;
-    break;
-  }
   }
   return false;
 }
diff --git a/clang/test/SemaHLSL/BuiltIns/GroupMemoryBarrierWithGroupSync-errors.hlsl b/clang/test/SemaHLSL/BuiltIns/GroupMemoryBarrierWithGroupSync-errors.hlsl
index 8de093f5368dfc..24067fbb275b77 100644
--- a/clang/test/SemaHLSL/BuiltIns/GroupMemoryBarrierWithGroupSync-errors.hlsl
+++ b/clang/test/SemaHLSL/BuiltIns/GroupMemoryBarrierWithGroupSync-errors.hlsl
@@ -2,5 +2,5 @@
 
 void test_too_many_arg() {
   __builtin_hlsl_group_memory_barrier_with_group_sync(0);
-  // expected-error at -1 {{too many arguments to function call, expected at most 0, have 1}}
+  // expected-error at -1 {{too many arguments to function call, expected 0, have 1}}
 }

>From 09febc741a68cbbf42a3e53109bc707753a74828 Mon Sep 17 00:00:00 2001
From: Adam Yang <hanbyang at microsoft.com>
Date: Mon, 2 Dec 2024 02:26:12 -0800
Subject: [PATCH 7/8] Fixed deprecated call and test

---
 clang/lib/CodeGen/CGBuiltin.cpp                                | 3 ++-
 .../CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync.hlsl  | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 2ca9d5f518795f..cc775ca74f1263 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19449,7 +19449,8 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
   case Builtin::BI__builtin_hlsl_group_memory_barrier_with_group_sync: {
     Intrinsic::ID ID =
         CGM.getHLSLRuntime().getGroupMemoryBarrierWithGroupSyncIntrinsic();
-    return EmitRuntimeCall(Intrinsic::getDeclaration(&CGM.getModule(), ID));
+    return EmitRuntimeCall(
+        Intrinsic::getOrInsertDeclaration(&CGM.getModule(), ID));
   }
   }
   return nullptr;
diff --git a/clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync.hlsl b/clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync.hlsl
index 333a1d68cdf3aa..9d95d54852c0be 100644
--- a/clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/GroupMemoryBarrierWithGroupSync.hlsl
@@ -10,7 +10,8 @@
 // CHECK-DXIL: define void @
 // CHECK-SPIRV: define spir_func void @
 void test_GroupMemoryBarrierWithGroupSync() {
-// CHECK: call void @llvm.[[TARGET]].group.memory.barrier.with.group.sync()
+// CHECK-DXIL: call void @llvm.[[TARGET]].group.memory.barrier.with.group.sync()
+// CHECK-SPIRV: call spir_func void @llvm.[[TARGET]].group.memory.barrier.with.group.sync()
   GroupMemoryBarrierWithGroupSync();
 }
 

>From 0f6cce7a37484e16cdb9e5e38b89027a596f3a92 Mon Sep 17 00:00:00 2001
From: Adam Yang <31109344+adam-yang at users.noreply.github.com>
Date: Mon, 2 Dec 2024 15:41:57 -0800
Subject: [PATCH 8/8] Fixed stray deletion of line from rebasing

---
 clang/lib/Sema/SemaHLSL.cpp | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 5ea6c1970acb01..8b2f24a8e4be0a 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -2239,6 +2239,7 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
           << 1;
       return true;
     }
+    break;
   }
   }
   return false;



More information about the cfe-commits mailing list