Skip to content

Commit c328c96

Browse files
authored
Merge branch 'main' into xegpu_simt_dist_gpu_index_ops_support
2 parents 42cc1dd + 3a5af23 commit c328c96

File tree

36 files changed

+2215
-754
lines changed

36 files changed

+2215
-754
lines changed

clang/docs/LanguageExtensions.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1859,12 +1859,18 @@ The following type trait primitives are supported by Clang. Those traits marked
18591859
* ``__is_trivially_constructible`` (C++, GNU, Microsoft)
18601860
* ``__is_trivially_copyable`` (C++, GNU, Microsoft)
18611861
* ``__is_trivially_destructible`` (C++, MSVC 2013)
1862-
* ``__is_trivially_relocatable`` (Clang): Returns true if moving an object
1862+
* ``__is_trivially_relocatable`` (Clang) (Deprecated,
1863+
use ``__builtin_is_cpp_trivially_relocatable`` instead).
1864+
Returns true if moving an object
18631865
of the given type, and then destroying the source object, is known to be
18641866
functionally equivalent to copying the underlying bytes and then dropping the
18651867
source object on the floor. This is true of trivial types,
18661868
C++26 relocatable types, and types which
18671869
were made trivially relocatable via the ``clang::trivial_abi`` attribute.
1870+
This trait is deprecated and should be replaced by
1871+
``__builtin_is_cpp_trivially_relocatable``. Note however that it is generally
1872+
unsafe to relocate a C++-relocatable type with ``memcpy`` or ``memmove``;
1873+
use ``__builtin_trivially_relocate``.
18681874
* ``__builtin_is_cpp_trivially_relocatable`` (C++): Returns true if an object
18691875
is trivially relocatable, as defined by the C++26 standard [meta.unary.prop].
18701876
Note that when relocating the caller code should ensure that if the object is polymorphic,

clang/docs/ReleaseNotes.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,15 @@ Bug Fixes to Compiler Builtins
581581
- ``__has_unique_object_representations(Incomplete[])`` is no longer accepted, per
582582
`LWG4113 <https://cplusplus.github.io/LWG/issue4113>`_.
583583

584+
- ``__builtin_is_cpp_trivially_relocatable``, ``__builtin_is_replaceable`` and
585+
``__builtin_trivially_relocate`` have been added to support standard C++26 relocation.
586+
587+
- ``__is_trivially_relocatable`` has been deprecated, and uses should be replaced by
588+
``__builtin_is_cpp_trivially_relocatable``.
589+
Note that, it is generally unsafe to ``memcpy`` non-trivially copyable types that
590+
are ``__builtin_is_cpp_trivially_relocatable``. It is recommanded to use
591+
``__builtin_trivially_relocate`` instead.
592+
584593
Bug Fixes to Attribute Support
585594
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
586595
- Fixed crash when a parameter to the ``clang::annotate`` attribute evaluates to ``void``. See #GH119125

clang/include/clang/Basic/Attr.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4785,15 +4785,15 @@ def HLSLResourceBinding: InheritableAttr {
47854785
SlotNumber = SlotNum;
47864786
SpaceNumber = SpaceNum;
47874787
}
4788-
bool isImplicit() const {
4789-
return !SlotNumber.has_value();
4788+
bool hasRegisterSlot() const {
4789+
return SlotNumber.has_value();
47904790
}
47914791
RegisterType getRegisterType() const {
4792-
assert(!isImplicit() && "binding does not have register slot");
4792+
assert(hasRegisterSlot() && "binding does not have register slot");
47934793
return RegType;
47944794
}
47954795
unsigned getSlotNumber() const {
4796-
assert(!isImplicit() && "binding does not have register slot");
4796+
assert(hasRegisterSlot() && "binding does not have register slot");
47974797
return SlotNumber.value();
47984798
}
47994799
unsigned getSpaceNumber() const {

clang/include/clang/Basic/TokenKinds.def

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,6 @@ TYPE_TRAIT_2(__is_pointer_interconvertible_base_of, IsPointerInterconvertibleBas
544544
#include "clang/Basic/TransformTypeTraits.def"
545545

546546
// Clang-only C++ Type Traits
547-
TYPE_TRAIT_1(__is_trivially_relocatable, IsTriviallyRelocatable, KEYCXX)
548547
TYPE_TRAIT_1(__is_trivially_equality_comparable, IsTriviallyEqualityComparable, KEYCXX)
549548
TYPE_TRAIT_1(__is_bounded_array, IsBoundedArray, KEYCXX)
550549
TYPE_TRAIT_1(__is_unbounded_array, IsUnboundedArray, KEYCXX)
@@ -556,8 +555,11 @@ TYPE_TRAIT_2(__reference_converts_from_temporary, ReferenceConvertsFromTemporary
556555
// IsDeducible is only used internally by clang for CTAD implementation and
557556
// is not exposed to users.
558557
TYPE_TRAIT_2(/*EmptySpellingName*/, IsDeducible, KEYCXX)
559-
TYPE_TRAIT_1(__is_bitwise_cloneable, IsBitwiseCloneable, KEYALL)
558+
559+
// __is_trivially_relocatable is deprecated
560560
TYPE_TRAIT_1(__builtin_is_cpp_trivially_relocatable, IsCppTriviallyRelocatable, KEYCXX)
561+
TYPE_TRAIT_1(__is_trivially_relocatable, IsTriviallyRelocatable, KEYCXX)
562+
TYPE_TRAIT_1(__is_bitwise_cloneable, IsBitwiseCloneable, KEYALL)
561563
TYPE_TRAIT_1(__builtin_is_replaceable, IsReplaceable, KEYCXX)
562564
TYPE_TRAIT_1(__builtin_structured_binding_size, StructuredBindingSize, KEYCXX)
563565

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ void CGHLSLRuntime::addBuffer(const HLSLBufferDecl *BufDecl) {
261261
BufDecl->getAttr<HLSLResourceBindingAttr>();
262262
// FIXME: handle implicit binding if no binding attribute is found
263263
// (llvm/llvm-project#110722)
264-
if (RBA && !RBA->isImplicit())
264+
if (RBA && RBA->hasRegisterSlot())
265265
initializeBufferFromBinding(CGM, BufGV, RBA->getSlotNumber(),
266266
RBA->getSpaceNumber());
267267
}

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6449,6 +6449,9 @@ void DiagnoseBuiltinDeprecation(Sema& S, TypeTrait Kind,
64496449
case UTT_HasTrivialDestructor:
64506450
Replacement = UTT_IsTriviallyDestructible;
64516451
break;
6452+
case UTT_IsTriviallyRelocatable:
6453+
Replacement = clang::UTT_IsCppTriviallyRelocatable;
6454+
break;
64526455
default:
64536456
return;
64546457
}

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,7 +1979,7 @@ void SemaHLSL::ActOnEndOfTranslationUnit(TranslationUnitDecl *TU) {
19791979
for (const Decl *VD : DefaultCBufferDecls) {
19801980
const HLSLResourceBindingAttr *RBA =
19811981
VD->getAttr<HLSLResourceBindingAttr>();
1982-
if (RBA && !RBA->isImplicit() &&
1982+
if (RBA && RBA->hasRegisterSlot() &&
19831983
RBA->getRegisterType() == HLSLResourceBindingAttr::RegisterType::C) {
19841984
DefaultCBuffer->setHasValidPackoffset(true);
19851985
break;
@@ -3271,7 +3271,7 @@ static bool initVarDeclWithCtor(Sema &S, VarDecl *VD,
32713271

32723272
static bool initGlobalResourceDecl(Sema &S, VarDecl *VD) {
32733273
HLSLResourceBindingAttr *RBA = VD->getAttr<HLSLResourceBindingAttr>();
3274-
if (!RBA || RBA->isImplicit())
3274+
if (!RBA || !RBA->hasRegisterSlot())
32753275
// FIXME: add support for implicit binding (llvm/llvm-project#110722)
32763276
return false;
32773277

@@ -3356,7 +3356,7 @@ void SemaHLSL::processExplicitBindingsOnDecl(VarDecl *VD) {
33563356
bool HasBinding = false;
33573357
for (Attr *A : VD->attrs()) {
33583358
HLSLResourceBindingAttr *RBA = dyn_cast<HLSLResourceBindingAttr>(A);
3359-
if (!RBA || RBA->isImplicit())
3359+
if (!RBA || !RBA->hasRegisterSlot())
33603360
continue;
33613361
HasBinding = true;
33623362

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,101 @@
11
// RUN: %clang_cc1 -std=hlsl202x -finclude-default-header -triple dxil-pc-shadermodel6.3-library %s \
2-
// RUN: -fnative-half-type -emit-llvm -disable-llvm-passes -o - | \
3-
// RUN: FileCheck %s --check-prefixes=CHECK,NATIVE_HALF \
2+
// RUN: -fnative-half-type -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,NATIVE_HALF \
43
// RUN: -DTARGET=dx -DFNATTRS=noundef -DFFNATTRS="nofpclass(nan inf)"
4+
55
// RUN: %clang_cc1 -std=hlsl202x -finclude-default-header -triple dxil-pc-shadermodel6.3-library %s \
6-
// RUN: -emit-llvm -disable-llvm-passes -o - | \
7-
// RUN: FileCheck %s --check-prefixes=CHECK,NO_HALF \
6+
// RUN: -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF \
87
// RUN: -DTARGET=dx -DFNATTRS=noundef -DFFNATTRS="nofpclass(nan inf)"
8+
99
// RUN: %clang_cc1 -std=hlsl202x -finclude-default-header -triple spirv-unknown-vulkan-compute %s \
10-
// RUN: -fnative-half-type -emit-llvm -disable-llvm-passes -o - | \
11-
// RUN: FileCheck %s --check-prefixes=CHECK,NATIVE_HALF \
10+
// RUN: -fnative-half-type -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,NATIVE_HALF \
1211
// RUN: -DTARGET=spv -DFNATTRS="spir_func noundef" -DFFNATTRS="nofpclass(nan inf)"
12+
1313
// RUN: %clang_cc1 -std=hlsl202x -finclude-default-header -triple spirv-unknown-vulkan-compute %s \
14-
// RUN: -emit-llvm -disable-llvm-passes -o - | \
15-
// RUN: FileCheck %s --check-prefixes=CHECK,NO_HALF \
14+
// RUN: -emit-llvm -o - | FileCheck %s --check-prefixes=CHECK,NO_HALF \
1615
// RUN: -DTARGET=spv -DFNATTRS="spir_func noundef" -DFFNATTRS="nofpclass(nan inf)"
1716

1817
#ifdef __HLSL_ENABLE_16_BIT
1918
// NATIVE_HALF: define [[FNATTRS]] <4 x i16> {{.*}}test_clamp_short4_mismatch
20-
// NATIVE_HALF: call <4 x i16> @llvm.[[TARGET]].sclamp.v4i16
19+
// NATIVE_HALF: [[CONV0:%.*]] = insertelement <4 x i16> poison, i16 %{{.*}}, i64 0
20+
// NATIVE_HALF: [[CONV1:%.*]] = shufflevector <4 x i16> [[CONV0]], <4 x i16> poison, <4 x i32> zeroinitializer
21+
// NATIVE_HALF: [[CLAMP:%.*]] = call {{.*}} <4 x i16> @llvm.[[TARGET]].sclamp.v4i16(<4 x i16> %{{.*}}, <4 x i16> %{{.*}}, <4 x i16> [[CONV1]])
22+
// NATIVE_HALF: ret <4 x i16> [[CLAMP]]
2123
int16_t4 test_clamp_short4_mismatch(int16_t4 p0, int16_t p1) { return clamp(p0, p0,p1); }
2224

2325
// NATIVE_HALF: define [[FNATTRS]] <4 x i16> {{.*}}test_clamp_ushort4_mismatch
24-
// NATIVE_HALF: call <4 x i16> @llvm.[[TARGET]].uclamp.v4i16
26+
// NATIVE_HALF: [[CONV0:%.*]] = insertelement <4 x i16> poison, i16 %{{.*}}, i64 0
27+
// NATIVE_HALF: [[CONV1:%.*]] = shufflevector <4 x i16> [[CONV0]], <4 x i16> poison, <4 x i32> zeroinitializer
28+
// NATIVE_HALF: [[CLAMP:%.*]] = call {{.*}} <4 x i16> @llvm.[[TARGET]].uclamp.v4i16(<4 x i16> %{{.*}}, <4 x i16> %{{.*}}, <4 x i16> [[CONV1]])
29+
// NATIVE_HALF: ret <4 x i16> [[CLAMP]]
2530
uint16_t4 test_clamp_ushort4_mismatch(uint16_t4 p0, uint16_t p1) { return clamp(p0, p0,p1); }
2631
#endif
2732

2833
// CHECK: define [[FNATTRS]] <4 x i32> {{.*}}test_clamp_int4_mismatch
29-
// CHECK: call <4 x i32> @llvm.[[TARGET]].sclamp.v4i32
34+
// CHECK: [[CONV0:%.*]] = insertelement <4 x i32> poison, i32 %{{.*}}, i64 0
35+
// CHECK: [[CONV1:%.*]] = shufflevector <4 x i32> [[CONV0]], <4 x i32> poison, <4 x i32> zeroinitializer
36+
// CHECK: [[CLAMP:%.*]] = call {{.*}} <4 x i32> @llvm.[[TARGET]].sclamp.v4i32(<4 x i32> %{{.*}}, <4 x i32> %{{.*}}, <4 x i32> [[CONV1]])
37+
// CHECK: ret <4 x i32> [[CLAMP]]
3038
int4 test_clamp_int4_mismatch(int4 p0, int p1) { return clamp(p0, p0,p1); }
3139

3240
// CHECK: define [[FNATTRS]] <4 x i32> {{.*}}test_clamp_uint4_mismatch
33-
// CHECK: call <4 x i32> @llvm.[[TARGET]].uclamp.v4i32
41+
// CHECK: [[CONV0:%.*]] = insertelement <4 x i32> poison, i32 %{{.*}}, i64 0
42+
// CHECK: [[CONV1:%.*]] = shufflevector <4 x i32> [[CONV0]], <4 x i32> poison, <4 x i32> zeroinitializer
43+
// CHECK: [[CLAMP:%.*]] = call {{.*}} <4 x i32> @llvm.[[TARGET]].uclamp.v4i32(<4 x i32> %{{.*}}, <4 x i32> %{{.*}}, <4 x i32> [[CONV1]])
44+
// CHECK: ret <4 x i32> [[CLAMP]]
3445
uint4 test_clamp_uint4_mismatch(uint4 p0, uint p1) { return clamp(p0, p0,p1); }
3546

3647
// CHECK: define [[FNATTRS]] <4 x i64> {{.*}}test_clamp_long4_mismatch
37-
// CHECK: call <4 x i64> @llvm.[[TARGET]].sclamp.v4i64
48+
// CHECK: [[CONV0:%.*]] = insertelement <4 x i64> poison, i64 %{{.*}}, i64 0
49+
// CHECK: [[CONV1:%.*]] = shufflevector <4 x i64> [[CONV0]], <4 x i64> poison, <4 x i32> zeroinitializer
50+
// CHECK: [[CLAMP:%.*]] = call {{.*}} <4 x i64> @llvm.[[TARGET]].sclamp.v4i64(<4 x i64> %{{.*}}, <4 x i64> %{{.*}}, <4 x i64> [[CONV1]])
51+
// CHECK: ret <4 x i64> [[CLAMP]]
3852
int64_t4 test_clamp_long4_mismatch(int64_t4 p0, int64_t p1) { return clamp(p0, p0,p1); }
3953

4054
// CHECK: define [[FNATTRS]] <4 x i64> {{.*}}test_clamp_ulong4_mismatch
41-
// CHECK: call <4 x i64> @llvm.[[TARGET]].uclamp.v4i64
55+
// CHECK: [[CONV0:%.*]] = insertelement <4 x i64> poison, i64 %{{.*}}, i64 0
56+
// CHECK: [[CONV1:%.*]] = shufflevector <4 x i64> [[CONV0]], <4 x i64> poison, <4 x i32> zeroinitializer
57+
// CHECK: [[CLAMP:%.*]] = call {{.*}} <4 x i64> @llvm.[[TARGET]].uclamp.v4i64(<4 x i64> %{{.*}}, <4 x i64> %{{.*}}, <4 x i64> [[CONV1]])
58+
// CHECK: ret <4 x i64> [[CLAMP]]
4259
uint64_t4 test_clamp_ulong4_mismatch(uint64_t4 p0, uint64_t p1) { return clamp(p0, p0,p1); }
4360

4461
// NATIVE_HALF: define [[FNATTRS]] [[FFNATTRS]] <4 x half> {{.*}}test_clamp_half4_mismatch
45-
// NATIVE_HALF: call reassoc nnan ninf nsz arcp afn <4 x half> @llvm.[[TARGET]].nclamp.v4f16
62+
// NATIVE_HALF: [[CONV0:%.*]] = insertelement <4 x half> poison, half %{{.*}}, i64 0
63+
// NATIVE_HALF: [[CONV1:%.*]] = shufflevector <4 x half> [[CONV0]], <4 x half> poison, <4 x i32> zeroinitializer
64+
// NATIVE_HALF: [[CLAMP:%.*]] = call reassoc nnan ninf nsz arcp afn {{.*}} <4 x half> @llvm.[[TARGET]].nclamp.v4f16(<4 x half> %{{.*}}, <4 x half> %{{.*}}, <4 x half> [[CONV1]])
65+
// NATIVE_HALF: ret <4 x half> [[CLAMP]]
4666
// NO_HALF: define [[FNATTRS]] [[FFNATTRS]] <4 x float> {{.*}}test_clamp_half4_mismatch
47-
// NO_HALF: call reassoc nnan ninf nsz arcp afn <4 x float> @llvm.[[TARGET]].nclamp.v4f32(
67+
// NO_HALF: [[CONV0:%.*]] = insertelement <4 x float> poison, float %{{.*}}, i64 0
68+
// NO_HALF: [[CONV1:%.*]] = shufflevector <4 x float> [[CONV0]], <4 x float> poison, <4 x i32> zeroinitializer
69+
// NO_HALF: [[CLAMP:%.*]] = call reassoc nnan ninf nsz arcp afn {{.*}} <4 x float> @llvm.[[TARGET]].nclamp.v4f32(<4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x float> [[CONV1]])
70+
// NO_HALF: ret <4 x float> [[CLAMP]]
4871
half4 test_clamp_half4_mismatch(half4 p0, half p1) { return clamp(p0, p0,p1); }
4972

5073
// CHECK: define [[FNATTRS]] [[FFNATTRS]] <4 x float> {{.*}}test_clamp_float4_mismatch
51-
// CHECK: call reassoc nnan ninf nsz arcp afn <4 x float> @llvm.[[TARGET]].nclamp.v4f32
74+
// CHECK: [[CONV0:%.*]] = insertelement <4 x float> poison, float %{{.*}}, i64 0
75+
// CHECK: [[CONV1:%.*]] = shufflevector <4 x float> [[CONV0]], <4 x float> poison, <4 x i32> zeroinitializer
76+
// CHECK: [[CLAMP:%.*]] = call reassoc nnan ninf nsz arcp afn {{.*}} <4 x float> @llvm.[[TARGET]].nclamp.v4f32(<4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x float> [[CONV1]])
77+
// CHECK: ret <4 x float> [[CLAMP]]
5278
float4 test_clamp_float4_mismatch(float4 p0, float p1) { return clamp(p0, p0,p1); }
5379

54-
// CHECK: define [[FNATTRS]] [[FFNATTRS]] <4 x double> {{.*}}test_clamp_double4_mismatch
55-
// CHECK: call reassoc nnan ninf nsz arcp afn <4 x double> @llvm.[[TARGET]].nclamp.v4f64
56-
double4 test_clamp_double4_mismatch(double4 p0, double p1) { return clamp(p0, p0,p1); }
80+
81+
// CHECK: define [[FNATTRS]] [[FFNATTRS]] <4 x double> {{.*}}test_clamp_double4_mismatch1
82+
// CHECK: [[CONV0:%.*]] = insertelement <4 x double> poison, double %{{.*}}, i64 0
83+
// CHECK: [[CONV1:%.*]] = shufflevector <4 x double> [[CONV0]], <4 x double> poison, <4 x i32> zeroinitializer
84+
// CHECK: [[CLAMP:%.*]] = call reassoc nnan ninf nsz arcp afn {{.*}} <4 x double> @llvm.[[TARGET]].nclamp.v4f64(<4 x double> %{{.*}}, <4 x double> %{{.*}}, <4 x double> [[CONV1]])
85+
// CHECK: ret <4 x double> [[CLAMP]]
86+
double4 test_clamp_double4_mismatch1(double4 p0, double p1) { return clamp(p0, p0,p1); }
5787
// CHECK: define [[FNATTRS]] [[FFNATTRS]] <4 x double> {{.*}}test_clamp_double4_mismatch2
58-
// CHECK: call reassoc nnan ninf nsz arcp afn <4 x double> @llvm.[[TARGET]].nclamp.v4f64
88+
// CHECK: [[CONV0:%.*]] = insertelement <4 x double> poison, double %{{.*}}, i64 0
89+
// CHECK: [[CONV1:%.*]] = shufflevector <4 x double> [[CONV0]], <4 x double> poison, <4 x i32> zeroinitializer
90+
// CHECK: [[CLAMP:%.*]] = call reassoc nnan ninf nsz arcp afn {{.*}} <4 x double> @llvm.[[TARGET]].nclamp.v4f64(<4 x double> %{{.*}}, <4 x double> [[CONV1]], <4 x double> %{{.*}})
91+
// CHECK: ret <4 x double> [[CLAMP]]
5992
double4 test_clamp_double4_mismatch2(double4 p0, double p1) { return clamp(p0, p1,p0); }
6093

6194
// CHECK: define [[FNATTRS]] <3 x i32> {{.*}}test_overloads3
62-
// CHECK: call <3 x i32> @llvm.[[TARGET]].uclamp.v3i32
95+
// CHECK: [[CONV0:%.*]] = insertelement <3 x i32> poison, i32 %{{.*}}, i64 0
96+
// CHECK: [[CONV1:%.*]] = shufflevector <3 x i32> [[CONV0]], <3 x i32> poison, <3 x i32> zeroinitializer
97+
// CHECK: [[CONV2:%.*]] = insertelement <3 x i32> poison, i32 %{{.*}}, i64 0
98+
// CHECK: [[CONV3:%.*]] = shufflevector <3 x i32> [[CONV2]], <3 x i32> poison, <3 x i32> zeroinitializer
99+
// CHECK: [[CLAMP:%.*]] = call {{.*}} <3 x i32> @llvm.[[TARGET]].uclamp.v3i32(<3 x i32> %{{.*}}, <3 x i32> [[CONV1]], <3 x i32> [[CONV3]])
100+
// CHECK: ret <3 x i32> [[CLAMP]]
63101
uint3 test_overloads3(uint3 p0, uint p1, uint p2) { return clamp(p0, p1, p2); }

0 commit comments

Comments
 (0)