Skip to content

Commit 9499aaa

Browse files
committed
Merge remote-tracking branch 'origin/main' into vplan-remove-loop-region-instead-of-using-branch-on-cond-true
2 parents 4a0eb12 + 596fd10 commit 9499aaa

File tree

85 files changed

+3162
-768
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+3162
-768
lines changed

clang/Maintainers.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,15 @@ SYCL conformance
295295
| alexey.bader\@intel.com (email), bader (Phabricator), bader (GitHub)
296296
297297

298+
Issue Triage
299+
~~~~~~~~~~~~
300+
| Shafik Yaghmour
301+
| shafik.yaghmour\@intel.com (email), shafik (GitHub), shafik.yaghmour (Discord), shafik (Discourse)
302+
303+
| hstk30
304+
| hanwei62\@huawei.com (email), hstk30-hw (GitHub), hstk30(Discord), hstk30 (Discourse)
305+
306+
298307
Inactive Maintainers
299308
====================
300309
The following people have graciously spent time performing maintainership

clang/include/clang/Basic/TokenKinds.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ KEYWORD(out , KEYHLSL)
662662
// HLSL Type traits
663663
TYPE_TRAIT_2(__builtin_hlsl_is_scalarized_layout_compatible, IsScalarizedLayoutCompatible, KEYHLSL)
664664
TYPE_TRAIT_1(__builtin_hlsl_is_intangible, IsIntangibleType, KEYHLSL)
665+
TYPE_TRAIT_1(__builtin_hlsl_is_typed_resource_element_compatible, IsTypedResourceElementCompatible, KEYHLSL)
665666

666667
// OpenMP Type Traits
667668
UNARY_EXPR_OR_TYPE_TRAIT(__builtin_omp_required_simd_align, OpenMPRequiredSimdAlign, KEYALL)

clang/include/clang/Sema/SemaHLSL.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ class SemaHLSL : public SemaBase {
132132

133133
// HLSL Type trait implementations
134134
bool IsScalarizedLayoutCompatible(QualType T1, QualType T2) const;
135+
bool IsTypedResourceElementCompatible(QualType T1);
135136

136137
bool CheckCompatibleParameterABI(FunctionDecl *New, FunctionDecl *Old);
137138

clang/lib/CodeGen/Targets/SPIR.cpp

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ class CommonSPIRTargetCodeGenInfo : public TargetCodeGenInfo {
5252

5353
unsigned getOpenCLKernelCallingConv() const override;
5454
llvm::Type *getOpenCLType(CodeGenModule &CGM, const Type *T) const override;
55+
llvm::Type *getHLSLType(CodeGenModule &CGM, const Type *Ty) const override;
56+
llvm::Type *getSPIRVImageTypeFromHLSLResource(
57+
const HLSLAttributedResourceType::Attributes &attributes,
58+
llvm::Type *ElementType, llvm::LLVMContext &Ctx) const;
5559
};
5660
class SPIRVTargetCodeGenInfo : public CommonSPIRTargetCodeGenInfo {
5761
public:
@@ -323,6 +327,81 @@ llvm::Type *CommonSPIRTargetCodeGenInfo::getOpenCLType(CodeGenModule &CGM,
323327
return nullptr;
324328
}
325329

330+
llvm::Type *CommonSPIRTargetCodeGenInfo::getHLSLType(CodeGenModule &CGM,
331+
const Type *Ty) const {
332+
auto *ResType = dyn_cast<HLSLAttributedResourceType>(Ty);
333+
if (!ResType)
334+
return nullptr;
335+
336+
llvm::LLVMContext &Ctx = CGM.getLLVMContext();
337+
const HLSLAttributedResourceType::Attributes &ResAttrs = ResType->getAttrs();
338+
switch (ResAttrs.ResourceClass) {
339+
case llvm::dxil::ResourceClass::UAV:
340+
case llvm::dxil::ResourceClass::SRV: {
341+
// TypedBuffer and RawBuffer both need element type
342+
QualType ContainedTy = ResType->getContainedType();
343+
if (ContainedTy.isNull())
344+
return nullptr;
345+
346+
assert(!ResAttrs.RawBuffer &&
347+
"Raw buffers handles are not implemented for SPIR-V yet");
348+
assert(!ResAttrs.IsROV &&
349+
"Rasterizer order views not implemented for SPIR-V yet");
350+
351+
// convert element type
352+
llvm::Type *ElemType = CGM.getTypes().ConvertType(ContainedTy);
353+
return getSPIRVImageTypeFromHLSLResource(ResAttrs, ElemType, Ctx);
354+
}
355+
case llvm::dxil::ResourceClass::CBuffer:
356+
llvm_unreachable("CBuffer handles are not implemented for SPIR-V yet");
357+
break;
358+
case llvm::dxil::ResourceClass::Sampler:
359+
return llvm::TargetExtType::get(Ctx, "spirv.Sampler");
360+
}
361+
return nullptr;
362+
}
363+
364+
llvm::Type *CommonSPIRTargetCodeGenInfo::getSPIRVImageTypeFromHLSLResource(
365+
const HLSLAttributedResourceType::Attributes &attributes,
366+
llvm::Type *ElementType, llvm::LLVMContext &Ctx) const {
367+
368+
if (ElementType->isVectorTy())
369+
ElementType = ElementType->getScalarType();
370+
371+
assert((ElementType->isIntegerTy() || ElementType->isFloatingPointTy()) &&
372+
"The element type for a SPIR-V resource must be a scalar integer or "
373+
"floating point type.");
374+
375+
// These parameters correspond to the operands to the OpTypeImage SPIR-V
376+
// instruction. See
377+
// https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#OpTypeImage.
378+
SmallVector<unsigned, 6> IntParams(6, 0);
379+
380+
// Dim
381+
// For now we assume everything is a buffer.
382+
IntParams[0] = 5;
383+
384+
// Depth
385+
// HLSL does not indicate if it is a depth texture or not, so we use unknown.
386+
IntParams[1] = 2;
387+
388+
// Arrayed
389+
IntParams[2] = 0;
390+
391+
// MS
392+
IntParams[3] = 0;
393+
394+
// Sampled
395+
IntParams[4] =
396+
attributes.ResourceClass == llvm::dxil::ResourceClass::UAV ? 2 : 1;
397+
398+
// Image format.
399+
// Setting to unknown for now.
400+
IntParams[5] = 0;
401+
402+
return llvm::TargetExtType::get(Ctx, "spirv.Image", {ElementType}, IntParams);
403+
}
404+
326405
std::unique_ptr<TargetCodeGenInfo>
327406
CodeGen::createCommonSPIRTargetCodeGenInfo(CodeGenModule &CGM) {
328407
return std::make_unique<CommonSPIRTargetCodeGenInfo>(CGM.getTypes());

clang/lib/Driver/ToolChains/PS4CPU.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,16 @@ void tools::PS5cpu::Linker::ConstructJob(Compilation &C, const JobAction &JA,
293293
"dead-reloc-in-nonalloc=.debug_ranges=0xfffffffffffffffe");
294294
CmdArgs.push_back("-z");
295295
CmdArgs.push_back("dead-reloc-in-nonalloc=.debug_loc=0xfffffffffffffffe");
296+
297+
// The PlayStation loader expects linked objects to be laid out in a
298+
// particular way. This is achieved by linker scripts that are supplied
299+
// with the SDK. The scripts are inside <sdkroot>/target/lib, which is
300+
// added as a search path elsewhere.
301+
// "PRX" has long stood for "PlayStation Relocatable eXecutable".
302+
CmdArgs.push_back("--default-script");
303+
CmdArgs.push_back(Static ? "static.script"
304+
: Shared ? "prx.script"
305+
: "main.script");
296306
}
297307

298308
if (Static)

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5032,6 +5032,7 @@ static bool CheckUnaryTypeTraitTypeCompleteness(Sema &S, TypeTrait UTT,
50325032
case UTT_IsScalar:
50335033
case UTT_IsCompound:
50345034
case UTT_IsMemberPointer:
5035+
case UTT_IsTypedResourceElementCompatible:
50355036
// Fall-through
50365037

50375038
// These traits are modeled on type predicates in C++0x [meta.unary.prop]
@@ -5714,6 +5715,15 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait UTT,
57145715
tok::kw___builtin_hlsl_is_intangible))
57155716
return false;
57165717
return T->isHLSLIntangibleType();
5718+
5719+
case UTT_IsTypedResourceElementCompatible:
5720+
assert(Self.getLangOpts().HLSL &&
5721+
"line vector layout compatible types are HLSL-only feature");
5722+
if (Self.RequireCompleteType(TInfo->getTypeLoc().getBeginLoc(), T,
5723+
diag::err_incomplete_type))
5724+
return false;
5725+
5726+
return Self.HLSL().IsTypedResourceElementCompatible(T);
57175727
}
57185728
}
57195729

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,6 +2199,51 @@ static void BuildFlattenedTypeList(QualType BaseTy,
21992199
}
22002200
}
22012201

2202+
bool SemaHLSL::IsTypedResourceElementCompatible(clang::QualType QT) {
2203+
if (QT.isNull())
2204+
return false;
2205+
2206+
// check if the outer type was an array type
2207+
if (QT->isArrayType())
2208+
return false;
2209+
2210+
llvm::SmallVector<QualType, 4> QTTypes;
2211+
BuildFlattenedTypeList(QT, QTTypes);
2212+
2213+
assert(QTTypes.size() > 0 &&
2214+
"expected at least one constituent type from non-null type");
2215+
QualType FirstQT = QTTypes[0];
2216+
2217+
// element count cannot exceed 4
2218+
if (QTTypes.size() > 4)
2219+
return false;
2220+
2221+
for (QualType TempQT : QTTypes) {
2222+
// ensure homogeneity
2223+
if (TempQT != FirstQT)
2224+
return false;
2225+
2226+
if (const BuiltinType *BT = TempQT->getAs<BuiltinType>()) {
2227+
if (BT->getKind() == BuiltinType::Bool ||
2228+
BT->getKind() == BuiltinType::Enum)
2229+
return false;
2230+
2231+
// Check if it is an array type.
2232+
if (TempQT->isArrayType())
2233+
return false;
2234+
}
2235+
}
2236+
2237+
// if the loop above completes without returning, then
2238+
// we've guaranteed homogeneity
2239+
int TotalSizeInBytes =
2240+
(SemaRef.Context.getTypeSize(FirstQT) / 8) * QTTypes.size();
2241+
if (TotalSizeInBytes > 16)
2242+
return false;
2243+
2244+
return true;
2245+
}
2246+
22022247
bool SemaHLSL::IsScalarizedLayoutCompatible(QualType T1, QualType T2) const {
22032248
if (T1.isNull() || T2.isNull())
22042249
return false;

clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,39 @@
1-
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.2-compute -finclude-default-header -fnative-half-type -emit-llvm -o - %s | FileCheck %s
1+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.2-compute -finclude-default-header -fnative-half-type -emit-llvm -o - %s | FileCheck %s -check-prefixes=DXIL
2+
// RUN: %clang_cc1 -triple spirv-pc-vulkan-compute -finclude-default-header -fnative-half-type -emit-llvm -o - %s | FileCheck %s -check-prefixes=SPIRV
23

34
// NOTE: The type name number and whether the struct is packed or not will mostly
45
// likely change once subscript operators are properly implemented (llvm/llvm-project#95956)
56
// and theinterim field of the contained type is removed.
67

7-
// CHECK: %"class.hlsl::RWBuffer" = type <{ target("dx.TypedBuffer", i16, 1, 0, 1)
8-
// CHECK: %"class.hlsl::RWBuffer.0" = type <{ target("dx.TypedBuffer", i16, 1, 0, 0)
9-
// CHECK: %"class.hlsl::RWBuffer.2" = type { target("dx.TypedBuffer", i32, 1, 0, 1)
10-
// CHECK: %"class.hlsl::RWBuffer.3" = type { target("dx.TypedBuffer", i32, 1, 0, 0)
11-
// CHECK: %"class.hlsl::RWBuffer.4" = type { target("dx.TypedBuffer", i64, 1, 0, 1)
12-
// CHECK: %"class.hlsl::RWBuffer.5" = type { target("dx.TypedBuffer", i64, 1, 0, 0)
13-
// CHECK: %"class.hlsl::RWBuffer.6" = type <{ target("dx.TypedBuffer", half, 1, 0, 0)
14-
// CHECK: %"class.hlsl::RWBuffer.8" = type { target("dx.TypedBuffer", float, 1, 0, 0)
15-
// CHECK: %"class.hlsl::RWBuffer.9" = type { target("dx.TypedBuffer", double, 1, 0, 0)
16-
// CHECK: %"class.hlsl::RWBuffer.10" = type { target("dx.TypedBuffer", <4 x i16>, 1, 0, 0)
17-
// CHECK: %"class.hlsl::RWBuffer.11" = type { target("dx.TypedBuffer", <3 x i32>, 1, 0, 0)
18-
// CHECK: %"class.hlsl::RWBuffer.12" = type { target("dx.TypedBuffer", <2 x half>, 1, 0, 0)
19-
// CHECK: %"class.hlsl::RWBuffer.13" = type { target("dx.TypedBuffer", <3 x float>, 1, 0, 0)
8+
// DXIL: %"class.hlsl::RWBuffer" = type <{ target("dx.TypedBuffer", i16, 1, 0, 1)
9+
// DXIL: %"class.hlsl::RWBuffer.0" = type <{ target("dx.TypedBuffer", i16, 1, 0, 0)
10+
// DXIL: %"class.hlsl::RWBuffer.2" = type { target("dx.TypedBuffer", i32, 1, 0, 1)
11+
// DXIL: %"class.hlsl::RWBuffer.3" = type { target("dx.TypedBuffer", i32, 1, 0, 0)
12+
// DXIL: %"class.hlsl::RWBuffer.4" = type { target("dx.TypedBuffer", i64, 1, 0, 1)
13+
// DXIL: %"class.hlsl::RWBuffer.5" = type { target("dx.TypedBuffer", i64, 1, 0, 0)
14+
// DXIL: %"class.hlsl::RWBuffer.6" = type <{ target("dx.TypedBuffer", half, 1, 0, 0)
15+
// DXIL: %"class.hlsl::RWBuffer.8" = type { target("dx.TypedBuffer", float, 1, 0, 0)
16+
// DXIL: %"class.hlsl::RWBuffer.9" = type { target("dx.TypedBuffer", double, 1, 0, 0)
17+
// DXIL: %"class.hlsl::RWBuffer.10" = type { target("dx.TypedBuffer", <4 x i16>, 1, 0, 0)
18+
// DXIL: %"class.hlsl::RWBuffer.11" = type { target("dx.TypedBuffer", <3 x i32>, 1, 0, 0)
19+
// DXIL: %"class.hlsl::RWBuffer.12" = type { target("dx.TypedBuffer", <2 x half>, 1, 0, 0)
20+
// DXIL: %"class.hlsl::RWBuffer.13" = type { target("dx.TypedBuffer", <3 x float>, 1, 0, 0)
21+
22+
// SPIRV: %"class.hlsl::RWBuffer" = type <{ target("spirv.Image", i16, 5, 2, 0, 0, 2, 0), i16, [6 x i8] }>
23+
// SPIRV: %"class.hlsl::RWBuffer.0" = type <{ target("spirv.Image", i16, 5, 2, 0, 0, 2, 0), i16, [6 x i8] }>
24+
// SPIRV: %"class.hlsl::RWBuffer.2" = type <{ target("spirv.Image", i32, 5, 2, 0, 0, 2, 0), i32, [4 x i8] }>
25+
// SPIRV: %"class.hlsl::RWBuffer.4" = type <{ target("spirv.Image", i32, 5, 2, 0, 0, 2, 0), i32, [4 x i8] }>
26+
// SPIRV: %"class.hlsl::RWBuffer.6" = type { target("spirv.Image", i64, 5, 2, 0, 0, 2, 0), i64 }
27+
// SPIRV: %"class.hlsl::RWBuffer.7" = type { target("spirv.Image", i64, 5, 2, 0, 0, 2, 0), i64 }
28+
// SPIRV: %"class.hlsl::RWBuffer.8" = type <{ target("spirv.Image", half, 5, 2, 0, 0, 2, 0), half, [6 x i8] }>
29+
// SPIRV: %"class.hlsl::RWBuffer.10" = type <{ target("spirv.Image", float, 5, 2, 0, 0, 2, 0), float, [4 x i8] }>
30+
// SPIRV: %"class.hlsl::RWBuffer.12" = type { target("spirv.Image", double, 5, 2, 0, 0, 2, 0), double }
31+
// SPIRV: %"class.hlsl::RWBuffer.13" = type { target("spirv.Image", i16, 5, 2, 0, 0, 2, 0), <4 x i16> }
32+
// SPIRV: %"class.hlsl::RWBuffer.14" = type { target("spirv.Image", i32, 5, 2, 0, 0, 2, 0), <3 x i32> }
33+
// SPIRV: %"class.hlsl::RWBuffer.15" = type <{ target("spirv.Image", half, 5, 2, 0, 0, 2, 0), <2 x half>, [4 x i8] }>
34+
// SPIRV: %"class.hlsl::RWBuffer.17" = type { target("spirv.Image", float, 5, 2, 0, 0, 2, 0), <3 x float> }
35+
36+
2037

2138
RWBuffer<int16_t> BufI16;
2239
RWBuffer<uint16_t> BufU16;

clang/test/Driver/ps5-linker.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,19 @@
6666
// CHECK-NO-EXE-NOT: "--unresolved-symbols
6767
// CHECK-NO-EXE-NOT: "-z"
6868

69+
// Test that an appropriate linker script is supplied by the driver.
70+
71+
// RUN: %clang --target=x86_64-sie-ps5 %s -### 2>&1 | FileCheck --check-prefixes=CHECK-SCRIPT -DSCRIPT=main %s
72+
// RUN: %clang --target=x86_64-sie-ps5 %s -shared -### 2>&1 | FileCheck --check-prefixes=CHECK-SCRIPT -DSCRIPT=prx %s
73+
// RUN: %clang --target=x86_64-sie-ps5 %s -static -### 2>&1 | FileCheck --check-prefixes=CHECK-SCRIPT -DSCRIPT=static %s
74+
// RUN: %clang --target=x86_64-sie-ps5 %s -r -### 2>&1 | FileCheck --check-prefixes=CHECK-NO-SCRIPT %s
75+
76+
// CHECK-SCRIPT: {{ld(\.exe)?}}"
77+
// CHECK-SCRIPT-SAME: "--default-script" "[[SCRIPT]].script"
78+
79+
// CHECK-NO-SCRIPT: {{ld(\.exe)?}}"
80+
// CHECK-NO-SCRIPT-NOT: "--default-script"
81+
6982
// Test that -static is forwarded to the linker
7083

7184
// RUN: %clang --target=x86_64-sie-ps5 -static %s -### 2>&1 | FileCheck --check-prefixes=CHECK-STATIC %s
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.6-library -finclude-default-header -fnative-half-type -verify %s
2+
// expected-no-diagnostics
3+
4+
struct oneInt {
5+
int i;
6+
};
7+
8+
struct twoInt {
9+
int aa;
10+
int ab;
11+
};
12+
13+
struct threeInts {
14+
oneInt o;
15+
twoInt t;
16+
};
17+
18+
struct oneFloat {
19+
float f;
20+
};
21+
struct depthDiff {
22+
int i;
23+
oneInt o;
24+
oneFloat f;
25+
};
26+
27+
struct notHomogenous{
28+
int i;
29+
float f;
30+
};
31+
32+
struct EightElements {
33+
twoInt x[2];
34+
twoInt y[2];
35+
};
36+
37+
struct EightHalves {
38+
half x[8];
39+
};
40+
41+
struct intVec {
42+
int2 i;
43+
};
44+
45+
struct oneIntWithVec {
46+
int i;
47+
oneInt i2;
48+
int2 i3;
49+
};
50+
51+
struct weirdStruct {
52+
int i;
53+
intVec iv;
54+
};
55+
56+
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(int), "");
57+
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(float), "");
58+
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(float4), "");
59+
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(double2), "");
60+
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(oneInt), "");
61+
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(oneFloat), "");
62+
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(twoInt), "");
63+
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(threeInts), "");
64+
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(notHomogenous), "");
65+
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(depthDiff), "");
66+
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(EightElements), "");
67+
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(EightHalves), "");
68+
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(oneIntWithVec), "");
69+
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(weirdStruct), "");
70+
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(RWBuffer<int>), "");
71+
72+
73+
// arrays not allowed
74+
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(half[4]), "");
75+
76+
template<typename T> struct TemplatedBuffer {
77+
T a;
78+
__hlsl_resource_t h;
79+
};
80+
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(TemplatedBuffer<int>), "");
81+
82+
struct MyStruct1 : TemplatedBuffer<float> {
83+
float x;
84+
};
85+
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(MyStruct1), "");
86+
87+
struct MyStruct2 {
88+
const TemplatedBuffer<float> TB[10];
89+
};
90+
_Static_assert(!__builtin_hlsl_is_typed_resource_element_compatible(MyStruct2), "");
91+
92+
template<typename T> struct SimpleTemplate {
93+
T a;
94+
};
95+
96+
// though the element type is incomplete, the type trait should still technically return true
97+
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(SimpleTemplate<__hlsl_resource_t>), "");
98+
99+
_Static_assert(__builtin_hlsl_is_typed_resource_element_compatible(SimpleTemplate<float>), "");
100+
101+

0 commit comments

Comments
 (0)