Skip to content

Commit 57f60c3

Browse files
committed
rebase: hook-up root elements to invoke there dump
- update ast test to ensure elements are correctly allocated
1 parent a62c4eb commit 57f60c3

File tree

5 files changed

+52
-2
lines changed

5 files changed

+52
-2
lines changed

clang/lib/AST/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ set(LLVM_LINK_COMPONENTS
22
BinaryFormat
33
Core
44
FrontendOpenMP
5+
FrontendHLSL
56
Support
67
TargetParser
78
)

clang/lib/AST/TextNodeDumper.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "clang/Basic/Specifiers.h"
2525
#include "clang/Basic/TypeTraits.h"
2626
#include "llvm/ADT/StringExtras.h"
27+
#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
2728

2829
#include <algorithm>
2930
#include <utility>
@@ -3040,6 +3041,7 @@ void TextNodeDumper::VisitHLSLBufferDecl(const HLSLBufferDecl *D) {
30403041
void TextNodeDumper::VisitHLSLRootSignatureDecl(
30413042
const HLSLRootSignatureDecl *D) {
30423043
dumpName(D);
3044+
llvm::hlsl::rootsig::dumpRootElements(OS, D->getRootElements());
30433045
}
30443046

30453047
void TextNodeDumper::VisitHLSLOutArgExpr(const HLSLOutArgExpr *E) {

clang/test/AST/HLSL/RootSignatures-AST.hlsl

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,19 @@
1515
"), " \
1616
"DescriptorTable(Sampler(s0, numDescriptors = 4, space = 1))"
1717

18-
// CHECK: -HLSLRootSignatureDecl 0x{{.*}} {{.*}} implicit [[SAMPLE_RS_DECL:__hlsl_rootsig_decl_.*]]
18+
// CHECK: -HLSLRootSignatureDecl 0x{{.*}} {{.*}} implicit [[SAMPLE_RS_DECL:__hlsl_rootsig_decl_\d*]]
19+
// CHECK-SAME: RootElements{
20+
// CHECK-SAME: CBV(b1, numDescriptors = 1, space = 0,
21+
// CHECK-SAME: offset = DescriptorTableOffsetAppend, flags = DataStaticWhileSetAtExecute),
22+
// CHECK-SAME: SRV(t1, numDescriptors = 8, space = 0,
23+
// CHECK-SAME: offset = DescriptorTableOffsetAppend, flags = DescriptorsVolatile),
24+
// CHECK-SAME: UAV(u1, numDescriptors = 0, space = 0,
25+
// CHECK-SAME: offset = DescriptorTableOffsetAppend, flags = DescriptorsVolatile),
26+
// CHECK-SAME: DescriptorTable(numClauses = 3, visibility = All),
27+
// CHECK-SAME: Sampler(s0, numDescriptors = 4, space = 1,
28+
// CHECK-SAME: offset = DescriptorTableOffsetAppend, flags = None),
29+
// CHECK-SAME: DescriptorTable(numClauses = 1, visibility = All)
30+
// CHECK-SAME: }
1931

2032
// CHECK: -RootSignatureAttr 0x{{.*}} {{.*}} [[SAMPLE_RS_DECL]]
2133
[RootSignature(SampleRS)]
@@ -51,7 +63,12 @@ void same_rs_string_main() {}
5163
// Ensure that when we define a different type root signature that it creates
5264
// a seperate decl and identifier to reference
5365

54-
// CHECK: -HLSLRootSignatureDecl 0x{{.*}} {{.*}} implicit [[DIFF_RS_DECL:__hlsl_rootsig_decl_.*]]
66+
// CHECK: -HLSLRootSignatureDecl 0x{{.*}} {{.*}} implicit [[DIFF_RS_DECL:__hlsl_rootsig_decl_\d*]]
67+
// CHECK-SAME: RootElements{
68+
// CHECK-SAME: Sampler(s0, numDescriptors = 4, space = 1,
69+
// CHECK-SAME: offset = DescriptorTableOffsetAppend, flags = None),
70+
// CHECK-SAME: DescriptorTable(numClauses = 1, visibility = All)
71+
// CHECK-SAME: }
5572

5673
// CHECK: -RootSignatureAttr 0x{{.*}} {{.*}} [[DIFF_RS_DECL]]
5774
[RootSignature(SampleDifferentRS)]

llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#ifndef LLVM_FRONTEND_HLSL_HLSLROOTSIGNATURE_H
1515
#define LLVM_FRONTEND_HLSL_HLSLROOTSIGNATURE_H
1616

17+
#include "llvm/ADT/ArrayRef.h"
1718
#include "llvm/Support/DXILABI.h"
1819
#include "llvm/Support/raw_ostream.h"
1920
#include <variant>
@@ -98,6 +99,8 @@ struct DescriptorTableClause {
9899
// Models RootElement : DescriptorTable | DescriptorTableClause
99100
using RootElement = std::variant<DescriptorTable, DescriptorTableClause>;
100101

102+
void dumpRootElements(raw_ostream &OS, ArrayRef<RootElement> Elements);
103+
101104
} // namespace rootsig
102105
} // namespace hlsl
103106
} // namespace llvm

llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,33 @@ void DescriptorTableClause::dump(raw_ostream &OS) const {
149149
OS << ")";
150150
}
151151

152+
// Helper struct so that we can use the overloaded notation of std::visit
153+
template <class... Ts> struct OverloadMethods : Ts... {
154+
using Ts::operator()...;
155+
};
156+
157+
template <class... Ts> OverloadMethods(Ts...) -> OverloadMethods<Ts...>;
158+
159+
void dumpRootElements(raw_ostream &OS, ArrayRef<RootElement> Elements) {
160+
OS << "RootElements{";
161+
bool First = true;
162+
for (auto Element : Elements) {
163+
if (!First)
164+
OS << ",";
165+
OS << " ";
166+
First = false;
167+
std::visit(OverloadMethods{
168+
[&OS](DescriptorTable Table) {
169+
Table.dump(OS);
170+
},
171+
[&OS](DescriptorTableClause Clause) {
172+
Clause.dump(OS);
173+
}
174+
}, Element);
175+
}
176+
OS << "}";
177+
}
178+
152179
} // namespace rootsig
153180
} // namespace hlsl
154181
} // namespace llvm

0 commit comments

Comments
 (0)