Skip to content

Commit 0233994

Browse files
committed
Make the layout struct name shorter
Use "__layout." prefix instead of "__hostlayout.struct." to make the text output more concise for both AST and LLVM IR.
1 parent fc939db commit 0233994

File tree

4 files changed

+31
-33
lines changed

4 files changed

+31
-33
lines changed

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ static IdentifierInfo *getHostLayoutStructName(Sema &S,
318318
MustBeUnique = true;
319319
}
320320

321-
std::string Name = "__hostlayout.struct." + NameBase;
321+
std::string Name = "__layout." + NameBase;
322322
IdentifierInfo *II = &AST.Idents.get(Name, tok::TokenKind::identifier);
323323
if (!MustBeUnique)
324324
return II;
@@ -443,8 +443,8 @@ static CXXRecordDecl *createHostLayoutStruct(Sema &S, CXXRecordDecl *StructDecl,
443443
// - empty structs
444444
// - zero-sized arrays
445445
// - non-variable declarations
446-
static CXXRecordDecl *createHostLayoutStructForBuffer(Sema &S,
447-
HLSLBufferDecl *BufDecl) {
446+
// The layour struct will be added to the HLSLBufferDecl declarations.
447+
void createHostLayoutStructForBuffer(Sema &S, HLSLBufferDecl *BufDecl) {
448448
ASTContext &AST = S.getASTContext();
449449
IdentifierInfo *II = getHostLayoutStructName(S, BufDecl->getIdentifier(),
450450
true, BufDecl->getDeclContext());
@@ -466,7 +466,6 @@ static CXXRecordDecl *createHostLayoutStructForBuffer(Sema &S,
466466
}
467467
LS->completeDefinition();
468468
BufDecl->addDecl(LS);
469-
return LS;
470469
}
471470

472471
// Handle end of cbuffer/tbuffer declaration
@@ -477,8 +476,7 @@ void SemaHLSL::ActOnFinishBuffer(Decl *Dcl, SourceLocation RBrace) {
477476
validatePackoffset(SemaRef, BufDecl);
478477

479478
// create buffer layout struct
480-
CXXRecordDecl *LayoutStruct =
481-
createHostLayoutStructForBuffer(SemaRef, BufDecl);
479+
createHostLayoutStructForBuffer(SemaRef, BufDecl);
482480

483481
SemaRef.PopDeclContext();
484482
}

clang/test/AST/HLSL/ast-dump-comment-cbuffer-tbuffer.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ tbuffer B {
4545
// AST-NEXT: TextComment {{.*}} Text=" CBuffer decl."
4646
// AST-NEXT: VarDecl {{.*}} a 'float'
4747
// AST-NEXT: VarDecl {{.*}} b 'int'
48-
// AST-NEXT: CXXRecordDecl {{.*}} implicit class __hostlayout.struct.A definition
48+
// AST-NEXT: CXXRecordDecl {{.*}} implicit class __layout.A definition
4949
// AST: FieldDecl {{.*}} a 'float'
5050
// AST-NEXT: FieldDecl {{.*}} b 'int'
5151

@@ -57,6 +57,6 @@ tbuffer B {
5757
// AST-NEXT: TextComment {{.*}} Text=" TBuffer decl."
5858
// AST-NEXT: VarDecl {{.*}} c 'float'
5959
// AST-NEXT: VarDecl {{.*}} d 'int'
60-
// AST-NEXT: CXXRecordDecl {{.*}} implicit class __hostlayout.struct.B definition
60+
// AST-NEXT: CXXRecordDecl {{.*}} implicit class __layout.B definition
6161
// AST: FieldDecl {{.*}} c 'float'
6262
// AST-NEXT: FieldDecl {{.*}} d 'int'

clang/test/AST/HLSL/cbuffer.hlsl

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ typedef float EmptyArrayTypedef[10][0];
4141
cbuffer CB {
4242
// CHECK: VarDecl {{.*}} col:9 used a1 'float'
4343
float a1;
44-
// CHECK: CXXRecordDecl {{.*}} implicit class __hostlayout.struct.CB definition
44+
// CHECK: CXXRecordDecl {{.*}} implicit class __layout.CB definition
4545
// CHECK: FieldDecl {{.*}} a1 'float'
4646
}
4747

@@ -60,7 +60,7 @@ cbuffer CB {
6060
float d2[0];
6161
// CHECK: VarDecl {{.*}} col:9 e2 'float'
6262
float e2;
63-
// CHECK: CXXRecordDecl {{.*}} implicit class __hostlayout.struct.CB.1 definition
63+
// CHECK: CXXRecordDecl {{.*}} implicit class __layout.CB.1 definition
6464
// CHECK: FieldDecl {{.*}} a2 'float'
6565
// CHECK-NEXT: FieldDecl {{.*}} e2 'float'
6666
}
@@ -76,11 +76,11 @@ cbuffer CB {
7676
B s2;
7777
// CHECK: VarDecl {{.*}} col:12 s3 'CTypedef':'C
7878
CTypedef s3;
79-
// CHECK: CXXRecordDecl {{.*}} implicit class __hostlayout.struct.B definition
79+
// CHECK: CXXRecordDecl {{.*}} implicit class __layout.B definition
8080
// CHECK: FieldDecl {{.*}} a 'float'
81-
// CHECK: CXXRecordDecl {{.*}} implicit class __hostlayout.struct.CB.2 definition
81+
// CHECK: CXXRecordDecl {{.*}} implicit class __layout.CB.2 definition
8282
// CHECK: FieldDecl {{.*}} s1 'A'
83-
// CHECK: FieldDecl {{.*}} s2 '__hostlayout.struct.B'
83+
// CHECK: FieldDecl {{.*}} s2 '__layout.B'
8484
}
8585

8686
// check that layout struct is created for D because of its base struct
@@ -90,15 +90,15 @@ cbuffer CB {
9090
cbuffer CB {
9191
// CHECK: VarDecl {{.*}} s4 'D'
9292
D s4;
93-
// CHECK: CXXRecordDecl {{.*}} implicit class __hostlayout.struct.D definition
93+
// CHECK: CXXRecordDecl {{.*}} implicit class __layout.D definition
9494
// CHECK: FieldDecl {{.*}} b 'float'
95-
// CHECK: CXXRecordDecl {{.*}} implicit class __hostlayout.struct.CB.3 definition
96-
// CHECK: FieldDecl {{.*}} s4 '__hostlayout.struct.D'
95+
// CHECK: CXXRecordDecl {{.*}} implicit class __layout.CB.3 definition
96+
// CHECK: FieldDecl {{.*}} s4 '__layout.D'
9797
}
9898

9999
// check that layout struct is created for E because because its base struct
100100
// is empty and should be eliminated, and BTypedef should reuse the previously
101-
// defined '__hostlayout.struct.B'
101+
// defined '__layout.B'
102102
// CHECK: HLSLBufferDecl {{.*}} line:105:9 cbuffer CB
103103
// CHECK: HLSLResourceClassAttr {{.*}} Implicit CBuffer
104104
// CHECK: HLSLResourceAttr {{.*}} Implicit CBuffer
@@ -107,12 +107,12 @@ cbuffer CB {
107107
E s5;
108108
// CHECK: VarDecl {{.*}} s6 'BTypedef':'B'
109109
BTypedef s6;
110-
// CHECK: CXXRecordDecl {{.*}} implicit class __hostlayout.struct.E definition
110+
// CHECK: CXXRecordDecl {{.*}} implicit class __layout.E definition
111111
// CHECK: FieldDecl {{.*}} c 'float'
112-
// CHECK-NOT: CXXRecordDecl {{.*}} implicit class __hostlayout.struct.B definition
113-
// CHECK: CXXRecordDecl {{.*}} implicit class __hostlayout.struct.CB.4 definition
114-
// CHECK: FieldDecl {{.*}} s5 '__hostlayout.struct.E'
115-
// CHECK: FieldDecl {{.*}} s6 '__hostlayout.struct.B'
112+
// CHECK-NOT: CXXRecordDecl {{.*}} implicit class __layout.B definition
113+
// CHECK: CXXRecordDecl {{.*}} implicit class __layout.CB.4 definition
114+
// CHECK: FieldDecl {{.*}} s5 '__layout.E'
115+
// CHECK: FieldDecl {{.*}} s6 '__layout.B'
116116
}
117117

118118
// check that this produces empty layout struct
@@ -130,7 +130,7 @@ cbuffer CB {
130130
RWBuffer<float> Buf;
131131
// CHECK: VarDecl {{.*}} ea 'EmptyArrayTypedef':'float[10][0]'
132132
EmptyArrayTypedef ea;
133-
// CHECK: CXXRecordDecl {{.*}} implicit class __hostlayout.struct.CB.5 definition
133+
// CHECK: CXXRecordDecl {{.*}} implicit class __layout.CB.5 definition
134134
// CHECK-NOT: FieldDecl
135135
}
136136

@@ -141,10 +141,10 @@ cbuffer CB {
141141
cbuffer CB {
142142
// CHECK: VarDecl {{.*}} s8 'F'
143143
F s8;
144-
// CHECK: CXXRecordDecl {{.*}} implicit class __hostlayout.struct.F definition
144+
// CHECK: CXXRecordDecl {{.*}} implicit class __layout.F definition
145145
// CHECK: public 'A'
146-
// CHECK: CXXRecordDecl {{.*}} implicit class __hostlayout.struct.CB.6 definition
147-
// CHECK: FieldDecl {{.*}} s8 '__hostlayout.struct.F'
146+
// CHECK: CXXRecordDecl {{.*}} implicit class __layout.CB.6 definition
147+
// CHECK: FieldDecl {{.*}} s8 '__layout.F'
148148
}
149149

150150
// anonymous structs
@@ -170,13 +170,13 @@ cbuffer CB {
170170
RWBuffer<float> f;
171171
} s10;
172172
// CHECK: VarDecl {{.*}} s10 'struct (unnamed struct at {{.*}}cbuffer.hlsl:166:3
173-
// CHECK: CXXRecordDecl {{.*}} implicit class __hostlayout.struct.anon definition
173+
// CHECK: CXXRecordDecl {{.*}} implicit class __layout.anon definition
174174
// CHECK: FieldDecl {{.*}} e 'float'
175-
// CHECK: CXXRecordDecl {{.*}} implicit class __hostlayout.struct.anon.1 definition
175+
// CHECK: CXXRecordDecl {{.*}} implicit class __layout.anon.1 definition
176176
// CHECK: FieldDecl {{.*}} g 'int'
177-
// CHECK: CXXRecordDecl {{.*}} implicit class __hostlayout.struct.CB.7 definition
178-
// CHECK: FieldDecl {{.*}} s9 '__hostlayout.struct.anon'
179-
// CHECK: FieldDecl {{.*}} s10 '__hostlayout.struct.anon.1'
177+
// CHECK: CXXRecordDecl {{.*}} implicit class __layout.CB.7 definition
178+
// CHECK: FieldDecl {{.*}} s9 '__layout.anon'
179+
// CHECK: FieldDecl {{.*}} s10 '__layout.anon.1'
180180
}
181181

182182
// Add uses for the constant buffer declarations so they are not optimized away

clang/test/AST/HLSL/pch_hlsl_buffer.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ float foo() {
2121
// CHECK-NEXT: HLSLResourceClassAttr {{.*}} Implicit CBuffer
2222
// CHECK-NEXT: HLSLResourceAttr {{.*}} Implicit CBuffer
2323
// CHECK-NEXT: VarDecl 0x[[A:[0-9a-f]+]] {{.*}} imported used a 'float'
24-
// CHECK-NEXT: CXXRecordDecl {{.*}} imported implicit <undeserialized declarations> class __hostlayout.struct.A definition
24+
// CHECK-NEXT: CXXRecordDecl {{.*}} imported implicit <undeserialized declarations> class __layout.A definition
2525
// CHECK: FieldDecl {{.*}} imported a 'float'
2626

2727
// CHECK: HLSLBufferDecl {{.*}} line:11:9 imported <undeserialized declarations> tbuffer B
2828
// CHECK-NEXT: HLSLResourceClassAttr {{.*}} Implicit SRV
2929
// CHECK-NEXT: HLSLResourceAttr {{.*}} Implicit TBuffer
3030
// CHECK-NEXT: VarDecl 0x[[B:[0-9a-f]+]] {{.*}} imported used b 'float'
31-
// CHECK-NEXT: CXXRecordDecl 0x{{[0-9a-f]+}} {{.*}} imported implicit <undeserialized declarations> class __hostlayout.struct.B definition
31+
// CHECK-NEXT: CXXRecordDecl 0x{{[0-9a-f]+}} {{.*}} imported implicit <undeserialized declarations> class __layout.B definition
3232
// CHECK: FieldDecl 0x{{[0-9a-f]+}} {{.*}} imported b 'float'
3333

3434
// CHECK-NEXT: FunctionDecl {{.*}} line:15:7 imported foo 'float ()'

0 commit comments

Comments
 (0)