Skip to content

Commit b7d329a

Browse files
committed
Added the intrinsic to clang
1 parent 085e7d2 commit b7d329a

File tree

7 files changed

+55
-0
lines changed

7 files changed

+55
-0
lines changed

clang/include/clang/Basic/Builtins.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4924,6 +4924,12 @@ def HLSLClip: LangBuiltin<"HLSL_LANG"> {
49244924
let Prototype = "void(...)";
49254925
}
49264926

4927+
def HLSLGroupMemoryBarrierWithGroupSync: LangBuiltin<"HLSL_LANG"> {
4928+
let Spellings = ["__builtin_group_memory_barrier_with_group_sync"];
4929+
let Attributes = [NoThrow, Const];
4930+
let Prototype = "void(...)";
4931+
}
4932+
49274933
// Builtins for XRay.
49284934
def XRayCustomEvent : Builtin {
49294935
let Spellings = ["__xray_customevent"];

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19446,6 +19446,10 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
1944619446
assert(E->getArg(0)->getType()->hasFloatingRepresentation() &&
1944719447
"clip operands types mismatch");
1944819448
return handleHlslClip(E, this);
19449+
case Builtin::BI__builtin_group_memory_barrier_with_group_sync: {
19450+
Intrinsic::ID ID = CGM.getHLSLRuntime().getGroupMemoryBarrierWithGroupSyncIntrinsic();
19451+
return EmitRuntimeCall(Intrinsic::getDeclaration(&CGM.getModule(), ID));
19452+
}
1944919453
}
1945019454
return nullptr;
1945119455
}

clang/lib/CodeGen/CGHLSLRuntime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class CGHLSLRuntime {
103103

104104
GENERATE_HLSL_INTRINSIC_FUNCTION(CreateHandleFromBinding, handle_fromBinding)
105105
GENERATE_HLSL_INTRINSIC_FUNCTION(BufferUpdateCounter, bufferUpdateCounter)
106+
GENERATE_HLSL_INTRINSIC_FUNCTION(GroupMemoryBarrierWithGroupSync, groupMemoryBarrierWithGroupSync)
106107

107108
//===----------------------------------------------------------------------===//
108109
// End of reserved area for HLSL intrinsic getters.

clang/lib/Headers/hlsl/hlsl_intrinsics.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2481,5 +2481,17 @@ float3 radians(float3);
24812481
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_radians)
24822482
float4 radians(float4);
24832483

2484+
//===----------------------------------------------------------------------===//
2485+
// GroupMemoryBarrierWithGroupSync builtins
2486+
//===----------------------------------------------------------------------===//
2487+
2488+
/// \fn void GroupMemoryBarrierWithGroupSync(void)
2489+
/// \brief Blocks execution of all threads in a group until all group shared
2490+
/// accesses have been completed and all threads in the group have reached this
2491+
/// call.
2492+
2493+
_HLSL_BUILTIN_ALIAS(__builtin_group_memory_barrier_with_group_sync)
2494+
void GroupMemoryBarrierWithGroupSync(void);
2495+
24842496
} // namespace hlsl
24852497
#endif //_HLSL_HLSL_INTRINSICS_H_

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,6 +2239,10 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
22392239
<< 1;
22402240
return true;
22412241
}
2242+
}
2243+
case Builtin::BI__builtin_group_memory_barrier_with_group_sync: {
2244+
if (SemaRef.checkArgCountAtMost(TheCall, 0))
2245+
return true;
22422246
break;
22432247
}
22442248
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// 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
2+
3+
void test_too_many_arg() {
4+
__builtin_group_memory_barrier_with_group_sync(0);
5+
// expected-error@-1 {{too many arguments to function call, expected at most 0, have 1}}
6+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
2+
// RUN: dxil-pc-shadermodel6.3-compute %s \
3+
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
4+
// RUN: -DTARGET=dx -DFNATTRS=noundef
5+
// RUN: %clang_cc1 -finclude-default-header -x hlsl -triple \
6+
// RUN: spirv-unknown-vulkan-compute %s \
7+
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %s \
8+
// RUN: -DTARGET=spv -DFNATTRS="spir_func noundef"
9+
10+
// CHECK: define [[FNATTRS]] i32 @
11+
[numthreads(1, 1, 1)]
12+
void main() {
13+
while (true) {
14+
// CHECK: call void @llvm.[[TARGET]].groupMemoryBarrierWithGroupSync()
15+
GroupMemoryBarrierWithGroupSync();
16+
break;
17+
}
18+
}
19+
20+
// CHECK: declare void @llvm.[[TARGET]].groupMemoryBarrierWithGroupSync() #[[ATTRS:[0-9]+]]
21+
// CHECK-NOT: attributes #[[ATTRS]] = {{.+}}memory(none){{.+}}
22+
// CHECK: attributes #[[ATTRS]] = {

0 commit comments

Comments
 (0)