Skip to content

Commit 0f97b92

Browse files
committed
Added the intrinsic to clang
1 parent fabe7e3 commit 0f97b92

File tree

7 files changed

+56
-0
lines changed

7 files changed

+56
-0
lines changed

clang/include/clang/Basic/Builtins.td

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4830,6 +4830,12 @@ def HLSLRadians : LangBuiltin<"HLSL_LANG"> {
48304830
let Prototype = "void(...)";
48314831
}
48324832

4833+
def HLSLGroupMemoryBarrierWithGroupSync: LangBuiltin<"HLSL_LANG"> {
4834+
let Spellings = ["__builtin_group_memory_barrier_with_group_sync"];
4835+
let Attributes = [NoThrow, Const];
4836+
let Prototype = "void(...)";
4837+
}
4838+
48334839
// Builtins for XRay.
48344840
def XRayCustomEvent : Builtin {
48354841
let Spellings = ["__xray_customevent"];

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18901,6 +18901,10 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
1890118901
CGM.getHLSLRuntime().getRadiansIntrinsic(), ArrayRef<Value *>{Op0},
1890218902
nullptr, "hlsl.radians");
1890318903
}
18904+
case Builtin::BI__builtin_group_memory_barrier_with_group_sync: {
18905+
Intrinsic::ID ID = CGM.getHLSLRuntime().getGroupMemoryBarrierWithGroupSyncIntrinsic();
18906+
return EmitRuntimeCall(Intrinsic::getDeclaration(&CGM.getModule(), ID));
18907+
}
1890418908
}
1890518909
return nullptr;
1890618910
}

clang/lib/CodeGen/CGHLSLRuntime.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class CGHLSLRuntime {
8989
GENERATE_HLSL_INTRINSIC_FUNCTION(SDot, sdot)
9090
GENERATE_HLSL_INTRINSIC_FUNCTION(UDot, udot)
9191
GENERATE_HLSL_INTRINSIC_FUNCTION(WaveIsFirstLane, wave_is_first_lane)
92+
GENERATE_HLSL_INTRINSIC_FUNCTION(GroupMemoryBarrierWithGroupSync, groupMemoryBarrierWithGroupSync)
9293

9394
//===----------------------------------------------------------------------===//
9495
// 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
@@ -2168,5 +2168,17 @@ float3 radians(float3);
21682168
_HLSL_BUILTIN_ALIAS(__builtin_hlsl_elementwise_radians)
21692169
float4 radians(float4);
21702170

2171+
//===----------------------------------------------------------------------===//
2172+
// GroupMemoryBarrierWithGroupSync builtins
2173+
//===----------------------------------------------------------------------===//
2174+
2175+
/// \fn void GroupMemoryBarrierWithGroupSync(void)
2176+
/// \brief Blocks execution of all threads in a group until all group shared
2177+
/// accesses have been completed and all threads in the group have reached this
2178+
/// call.
2179+
2180+
_HLSL_BUILTIN_ALIAS(__builtin_group_memory_barrier_with_group_sync)
2181+
void GroupMemoryBarrierWithGroupSync(void);
2182+
21712183
} // namespace hlsl
21722184
#endif //_HLSL_HLSL_INTRINSICS_H_

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2018,6 +2018,11 @@ bool SemaHLSL::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
20182018
return true;
20192019
break;
20202020
}
2021+
case Builtin::BI__builtin_group_memory_barrier_with_group_sync: {
2022+
if (SemaRef.checkArgCountAtMost(TheCall, 0))
2023+
return true;
2024+
break;
2025+
}
20212026
}
20222027
return false;
20232028
}
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)