Skip to content

Commit 5d76555

Browse files
authored
[NFC][HLSL][RootSignature] Use operator<< overload instead of dump method (#141127)
- we will need to provide a way to dump `RootFlags` for serialization and by using operator overloads we can maintain a consistent interface This is an NFC to allow for #138192 to be more straightforwardly implemented.
1 parent 2b64b15 commit 5d76555

File tree

3 files changed

+28
-23
lines changed

3 files changed

+28
-23
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,10 @@ struct DescriptorTable {
100100
// Denotes that the previous NumClauses in the RootElement array
101101
// are the clauses in the table.
102102
uint32_t NumClauses = 0;
103-
104-
void dump(raw_ostream &OS) const;
105103
};
106104

105+
raw_ostream &operator<<(raw_ostream &OS, const DescriptorTable &Table);
106+
107107
static const uint32_t NumDescriptorsUnbounded = 0xffffffff;
108108
static const uint32_t DescriptorTableOffsetAppend = 0xffffffff;
109109
// Models DTClause : CBV | SRV | UAV | Sampler, by collecting like parameters
@@ -130,10 +130,10 @@ struct DescriptorTableClause {
130130
break;
131131
}
132132
}
133-
134-
void dump(raw_ostream &OS) const;
135133
};
136134

135+
raw_ostream &operator<<(raw_ostream &OS, const DescriptorTableClause &Clause);
136+
137137
/// Models RootElement : RootFlags | RootConstants | RootDescriptor
138138
/// | DescriptorTable | DescriptorTableClause
139139
///

llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,6 @@ static raw_ostream &operator<<(raw_ostream &OS,
7171
return OS;
7272
}
7373

74-
void DescriptorTable::dump(raw_ostream &OS) const {
75-
OS << "DescriptorTable(numClauses = " << NumClauses
76-
<< ", visibility = " << Visibility << ")";
77-
}
78-
7974
static raw_ostream &operator<<(raw_ostream &OS, const ClauseType &Type) {
8075
switch (Type) {
8176
case ClauseType::CBuffer:
@@ -137,14 +132,24 @@ static raw_ostream &operator<<(raw_ostream &OS,
137132
return OS;
138133
}
139134

140-
void DescriptorTableClause::dump(raw_ostream &OS) const {
141-
OS << Type << "(" << Reg << ", numDescriptors = " << NumDescriptors
142-
<< ", space = " << Space << ", offset = ";
143-
if (Offset == DescriptorTableOffsetAppend)
135+
raw_ostream &operator<<(raw_ostream &OS, const DescriptorTable &Table) {
136+
OS << "DescriptorTable(numClauses = " << Table.NumClauses
137+
<< ", visibility = " << Table.Visibility << ")";
138+
139+
return OS;
140+
}
141+
142+
raw_ostream &operator<<(raw_ostream &OS, const DescriptorTableClause &Clause) {
143+
OS << Clause.Type << "(" << Clause.Reg
144+
<< ", numDescriptors = " << Clause.NumDescriptors
145+
<< ", space = " << Clause.Space << ", offset = ";
146+
if (Clause.Offset == DescriptorTableOffsetAppend)
144147
OS << "DescriptorTableOffsetAppend";
145148
else
146-
OS << Offset;
147-
OS << ", flags = " << Flags << ")";
149+
OS << Clause.Offset;
150+
OS << ", flags = " << Clause.Flags << ")";
151+
152+
return OS;
148153
}
149154

150155
void dumpRootElements(raw_ostream &OS, ArrayRef<RootElement> Elements) {
@@ -154,11 +159,11 @@ void dumpRootElements(raw_ostream &OS, ArrayRef<RootElement> Elements) {
154159
if (!First)
155160
OS << ",";
156161
OS << " ";
157-
First = false;
158162
if (const auto &Clause = std::get_if<DescriptorTableClause>(&Element))
159-
Clause->dump(OS);
163+
OS << *Clause;
160164
if (const auto &Table = std::get_if<DescriptorTable>(&Element))
161-
Table->dump(OS);
165+
OS << *Table;
166+
First = false;
162167
}
163168
OS << "}";
164169
}

llvm/unittests/Frontend/HLSLRootSignatureDumpTest.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ TEST(HLSLRootSignatureTest, DescriptorCBVClauseDump) {
2121

2222
std::string Out;
2323
llvm::raw_string_ostream OS(Out);
24-
Clause.dump(OS);
24+
OS << Clause;
2525
OS.flush();
2626

2727
std::string Expected = "CBV(b0, numDescriptors = 1, space = 0, "
@@ -41,7 +41,7 @@ TEST(HLSLRootSignatureTest, DescriptorSRVClauseDump) {
4141

4242
std::string Out;
4343
llvm::raw_string_ostream OS(Out);
44-
Clause.dump(OS);
44+
OS << Clause;
4545
OS.flush();
4646

4747
std::string Expected =
@@ -60,7 +60,7 @@ TEST(HLSLRootSignatureTest, DescriptorUAVClauseDump) {
6060

6161
std::string Out;
6262
llvm::raw_string_ostream OS(Out);
63-
Clause.dump(OS);
63+
OS << Clause;
6464
OS.flush();
6565

6666
std::string Expected =
@@ -84,7 +84,7 @@ TEST(HLSLRootSignatureTest, DescriptorSamplerClauseDump) {
8484

8585
std::string Out;
8686
llvm::raw_string_ostream OS(Out);
87-
Clause.dump(OS);
87+
OS << Clause;
8888
OS.flush();
8989

9090
std::string Expected = "Sampler(s0, numDescriptors = 2, space = 42, offset = "
@@ -100,7 +100,7 @@ TEST(HLSLRootSignatureTest, DescriptorTableDump) {
100100

101101
std::string Out;
102102
llvm::raw_string_ostream OS(Out);
103-
Table.dump(OS);
103+
OS << Table;
104104
OS.flush();
105105

106106
std::string Expected =

0 commit comments

Comments
 (0)