Skip to content

Commit 4cab0b6

Browse files
SC llvm teamSC llvm team
SC llvm team
authored and
SC llvm team
committed
Merged main:01bc672b8a41 into origin/amd-gfx:9191a26f4d41
Local branch origin/amd-gfx 9191a26 Merged main:3382aef944ef into origin/amd-gfx:1058b0887612 Remote branch main 01bc672 [HLSL] Desugar ConstantArrayType when calculating cbuffer field layout (llvm#134683)
2 parents 9191a26 + 01bc672 commit 4cab0b6

File tree

10 files changed

+34
-12
lines changed

10 files changed

+34
-12
lines changed

clang/lib/CodeGen/HLSLBufferLayoutBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ bool HLSLBufferLayoutBuilder::layoutField(const FieldDecl *FD,
195195
// Unwrap array to find the element type and get combined array size.
196196
QualType Ty = FieldTy;
197197
while (Ty->isConstantArrayType()) {
198-
const ConstantArrayType *ArrayTy = cast<ConstantArrayType>(Ty);
198+
auto *ArrayTy = CGM.getContext().getAsConstantArrayType(Ty);
199199
ArrayCount *= ArrayTy->getSExtSize();
200200
Ty = ArrayTy->getElementType();
201201
}

clang/test/CodeGenHLSL/cbuffer.hlsl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,19 @@ cbuffer CBArrays : register(b2) {
9999
// CHECK: @c7 = external addrspace(2) global [2 x i64], align 8
100100
// CHECK: @c8 = external addrspace(2) global [4 x i32], align 4
101101

102+
typedef uint32_t4 uint32_t8[2];
103+
typedef uint4 T1;
104+
typedef T1 T2[2]; // check a double typedef
105+
106+
cbuffer CBTypedefArray {
107+
uint32_t8 t1[2];
108+
T2 t2[2];
109+
}
110+
111+
// CHECK: @CBTypedefArray.cb = global target("dx.CBuffer", target("dx.Layout", %__cblayout_CBTypedefArray,
112+
// CHECK-SAME: 128, 0, 64))
113+
// CHECK: @t1 = external addrspace(2) global [2 x [2 x <4 x i32>]], align 16
114+
// CHECK: @t2 = external addrspace(2) global [2 x [2 x <4 x i32>]], align 16
102115
struct Empty {};
103116

104117
struct A {
@@ -278,7 +291,7 @@ void main() {
278291
// CHECK-NEXT: call void @_init_resource_CBScalars.cb()
279292
// CHECK-NEXT: call void @_init_resource_CBArrays.cb()
280293

281-
// CHECK: !hlsl.cbs = !{![[CBSCALARS:[0-9]+]], ![[CBVECTORS:[0-9]+]], ![[CBARRAYS:[0-9]+]], ![[CBSTRUCTS:[0-9]+]], ![[CBCLASSES:[0-9]+]],
294+
// CHECK: !hlsl.cbs = !{![[CBSCALARS:[0-9]+]], ![[CBVECTORS:[0-9]+]], ![[CBARRAYS:[0-9]+]], ![[CBTYPEDEFARRAY:[0-9]+]], ![[CBSTRUCTS:[0-9]+]], ![[CBCLASSES:[0-9]+]],
282295
// CHECK-SAME: ![[CBMIX:[0-9]+]], ![[CB_A:[0-9]+]], ![[CB_B:[0-9]+]], ![[CB_C:[0-9]+]]}
283296

284297
// CHECK: ![[CBSCALARS]] = !{ptr @CBScalars.cb, ptr addrspace(2) @a1, ptr addrspace(2) @a2, ptr addrspace(2) @a3, ptr addrspace(2) @a4,
@@ -290,6 +303,8 @@ void main() {
290303
// CHECK: ![[CBARRAYS]] = !{ptr @CBArrays.cb, ptr addrspace(2) @c1, ptr addrspace(2) @c2, ptr addrspace(2) @c3, ptr addrspace(2) @c4,
291304
// CHECK-SAME: ptr addrspace(2) @c5, ptr addrspace(2) @c6, ptr addrspace(2) @c7, ptr addrspace(2) @c8}
292305

306+
// CHECK: ![[CBTYPEDEFARRAY]] = !{ptr @CBTypedefArray.cb, ptr addrspace(2) @t1, ptr addrspace(2) @t2}
307+
293308
// CHECK: ![[CBSTRUCTS]] = !{ptr @CBStructs.cb, ptr addrspace(2) @a, ptr addrspace(2) @b, ptr addrspace(2) @c, ptr addrspace(2) @array_of_A,
294309
// CHECK-SAME: ptr addrspace(2) @d, ptr addrspace(2) @e, ptr addrspace(2) @f}
295310

llvm/examples/Kaleidoscope/BuildingAJIT/Chapter1/toy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ static std::unique_ptr<PrototypeAST> ParsePrototype() {
636636
// Read the precedence if present.
637637
if (CurTok == tok_number) {
638638
if (NumVal < 1 || NumVal > 100)
639-
return LogErrorP("Invalid precedecnce: must be 1..100");
639+
return LogErrorP("Invalid precedence: must be 1..100");
640640
BinaryPrecedence = (unsigned)NumVal;
641641
getNextToken();
642642
}

llvm/examples/Kaleidoscope/BuildingAJIT/Chapter2/toy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ static std::unique_ptr<PrototypeAST> ParsePrototype() {
636636
// Read the precedence if present.
637637
if (CurTok == tok_number) {
638638
if (NumVal < 1 || NumVal > 100)
639-
return LogErrorP("Invalid precedecnce: must be 1..100");
639+
return LogErrorP("Invalid precedence: must be 1..100");
640640
BinaryPrecedence = (unsigned)NumVal;
641641
getNextToken();
642642
}

llvm/examples/Kaleidoscope/BuildingAJIT/Chapter3/toy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ static std::unique_ptr<PrototypeAST> ParsePrototype() {
636636
// Read the precedence if present.
637637
if (CurTok == tok_number) {
638638
if (NumVal < 1 || NumVal > 100)
639-
return LogErrorP("Invalid precedecnce: must be 1..100");
639+
return LogErrorP("Invalid precedence: must be 1..100");
640640
BinaryPrecedence = (unsigned)NumVal;
641641
getNextToken();
642642
}

llvm/examples/Kaleidoscope/BuildingAJIT/Chapter4/toy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ static std::unique_ptr<PrototypeAST> ParsePrototype() {
619619
// Read the precedence if present.
620620
if (CurTok == tok_number) {
621621
if (NumVal < 1 || NumVal > 100)
622-
return LogErrorP("Invalid precedecnce: must be 1..100");
622+
return LogErrorP("Invalid precedence: must be 1..100");
623623
BinaryPrecedence = (unsigned)NumVal;
624624
getNextToken();
625625
}

llvm/include/llvm/Config/llvm-config.h.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
/* Indicate that this is LLVM compiled from the amd-gfx branch. */
1818
#define LLVM_HAVE_BRANCH_AMD_GFX
19-
#define LLVM_MAIN_REVISION 533283
19+
#define LLVM_MAIN_REVISION 533286
2020

2121
/* Define if LLVM_ENABLE_DUMP is enabled */
2222
#cmakedefine LLVM_ENABLE_DUMP

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9924,11 +9924,8 @@ void LoopVectorizationPlanner::adjustRecipesForReductions(
99249924
VPValue *Cmp = Select->getOperand(0);
99259925
// If the compare is checking the reduction PHI node, adjust it to check
99269926
// the start value.
9927-
if (VPRecipeBase *CmpR = Cmp->getDefiningRecipe()) {
9928-
for (unsigned I = 0; I != CmpR->getNumOperands(); ++I)
9929-
if (CmpR->getOperand(I) == PhiR)
9930-
CmpR->setOperand(I, PhiR->getStartValue());
9931-
}
9927+
if (VPRecipeBase *CmpR = Cmp->getDefiningRecipe())
9928+
CmpR->replaceUsesOfWith(PhiR, PhiR->getStartValue());
99329929
Builder.setInsertPoint(Select);
99339930

99349931
// If the true value of the select is the reduction phi, the new value is

llvm/lib/Transforms/Vectorize/VPlan.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1414,6 +1414,13 @@ void VPValue::replaceUsesWithIf(
14141414
}
14151415
}
14161416

1417+
void VPUser::replaceUsesOfWith(VPValue *From, VPValue *To) {
1418+
for (unsigned Idx = 0; Idx != getNumOperands(); ++Idx) {
1419+
if (getOperand(Idx) == From)
1420+
setOperand(Idx, To);
1421+
}
1422+
}
1423+
14171424
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
14181425
void VPValue::printAsOperand(raw_ostream &OS, VPSlotTracker &Tracker) const {
14191426
OS << Tracker.getOrCreateName(this);

llvm/lib/Transforms/Vectorize/VPlanValue.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ class VPUser {
246246
New->addUser(*this);
247247
}
248248

249+
/// Replaces all uses of \p From in the VPUser with \p To.
250+
void replaceUsesOfWith(VPValue *From, VPValue *To);
251+
249252
typedef SmallVectorImpl<VPValue *>::iterator operand_iterator;
250253
typedef SmallVectorImpl<VPValue *>::const_iterator const_operand_iterator;
251254
typedef iterator_range<operand_iterator> operand_range;

0 commit comments

Comments
 (0)