Skip to content

Commit 0ed0c09

Browse files
committed
self-review: misc clean up
1 parent 5ccbf46 commit 0ed0c09

File tree

4 files changed

+31
-18
lines changed

4 files changed

+31
-18
lines changed

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,14 @@ void addDxilValVersion(StringRef ValVersionStr, llvm::Module &M) {
6868
DXILValMD->addOperand(Val);
6969
}
7070

71-
void addRootSignature(
72-
ArrayRef<llvm::hlsl::rootsig::RootElement> Elements,
73-
llvm::Function *Fn, llvm::Module &M) {
71+
void addRootSignature(ArrayRef<llvm::hlsl::rootsig::RootElement> Elements,
72+
llvm::Function *Fn, llvm::Module &M) {
7473
auto &Ctx = M.getContext();
7574

7675
llvm::hlsl::rootsig::MetadataBuilder Builder(Ctx, Elements);
7776
MDNode *RootSignature = Builder.BuildRootSignature();
78-
MDNode *FnPairing = MDNode::get(Ctx, {ValueAsMetadata::get(Fn),
79-
RootSignature});
77+
MDNode *FnPairing =
78+
MDNode::get(Ctx, {ValueAsMetadata::get(Fn), RootSignature});
8079

8180
StringRef RootSignatureValKey = "dx.rootsignatures";
8281
auto *RootSignatureValMD = M.getOrInsertNamedMetadata(RootSignatureValKey);
@@ -443,7 +442,8 @@ void CGHLSLRuntime::emitEntryFunction(const FunctionDecl *FD,
443442
const AttrVec &Attrs = FD->getAttrs();
444443
for (const Attr *Attr : Attrs) {
445444
if (const auto *RSAttr = dyn_cast<RootSignatureAttr>(Attr))
446-
addRootSignature(RSAttr->getSignatureDecl()->getRootElements(), EntryFn, M);
445+
addRootSignature(RSAttr->getSignatureDecl()->getRootElements(), EntryFn,
446+
M);
447447
}
448448
}
449449

clang/test/CodeGenHLSL/RootSignature.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ void FirstEntry() {}
1919
[numthreads(1,1,1)]
2020
void SecondEntry() {}
2121

22-
// Sanity test to ensure to root is added for this function
22+
// Sanity test to ensure no root is added for this function
2323
[shader("compute")]
2424
[numthreads(1,1,1)]
2525
void ThirdEntry() {}

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,18 @@ using RootElement = std::variant<RootFlags, RootConstants, DescriptorTable,
131131
void dumpRootElements(raw_ostream &OS, ArrayRef<RootElement> Elements);
132132

133133
class MetadataBuilder {
134-
public:
134+
public:
135135
MetadataBuilder(llvm::LLVMContext &Ctx, ArrayRef<RootElement> Elements)
136-
: Ctx(Ctx), Elements(Elements) {}
136+
: Ctx(Ctx), Elements(Elements) {}
137137

138-
// Iterates through the elements and builds the respective nodes
138+
/// Iterates through the elements and dispatches onto the correct Build method
139+
///
140+
/// Accumulates the root signature and returns the Metadata node that is just
141+
/// a list of all the elements
139142
MDNode *BuildRootSignature();
140143

141-
private:
142-
// Define the various builders for the different metadata types
144+
private:
145+
/// Define the various builders for the different metadata types
143146
MDNode *BuildDescriptorTable(const DescriptorTable &Table);
144147
MDNode *BuildDescriptorTableClause(const DescriptorTableClause &Clause);
145148

llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
///
1111
//===----------------------------------------------------------------------===//
1212

13-
#include "llvm/ADT/bit.h"
1413
#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
14+
#include "llvm/ADT/bit.h"
1515
#include "llvm/IR/IRBuilder.h"
1616
#include "llvm/IR/Metadata.h"
1717
#include "llvm/IR/Module.h"
@@ -198,17 +198,27 @@ MDNode *MetadataBuilder::BuildRootSignature() {
198198
MDNode *MetadataBuilder::BuildDescriptorTable(const DescriptorTable &Table) {
199199
IRBuilder<> B(Ctx);
200200
SmallVector<Metadata *> TableOperands;
201+
// Set the mandatory arguments
201202
TableOperands.push_back(MDString::get(Ctx, "DescriptorTable"));
202-
TableOperands.push_back(ConstantAsMetadata::get(B.getInt32(llvm::to_underlying(Table.Visibility))));
203-
204-
assert(Table.NumClauses <= GeneratedMetadata.size() && "Table expected all owned clauses to be generated already");
205-
TableOperands.append(GeneratedMetadata.end() - Table.NumClauses, GeneratedMetadata.end());
203+
TableOperands.push_back(ConstantAsMetadata::get(
204+
B.getInt32(llvm::to_underlying(Table.Visibility))));
205+
206+
// Remaining operands are references to the table's clauses. The in-memory
207+
// representation of the Root Elements created from parsing will ensure that
208+
// the previous N elements are the clauses for this table.
209+
assert(Table.NumClauses <= GeneratedMetadata.size() &&
210+
"Table expected all owned clauses to be generated already");
211+
// So, add a refence to each clause to our operands
212+
TableOperands.append(GeneratedMetadata.end() - Table.NumClauses,
213+
GeneratedMetadata.end());
214+
// Then, remove those clauses from the general list of Root Elements
206215
GeneratedMetadata.pop_back_n(Table.NumClauses);
207216

208217
return MDNode::get(Ctx, TableOperands);
209218
}
210219

211-
MDNode *MetadataBuilder::BuildDescriptorTableClause(const DescriptorTableClause &Clause) {
220+
MDNode *MetadataBuilder::BuildDescriptorTableClause(
221+
const DescriptorTableClause &Clause) {
212222
IRBuilder<> B(Ctx);
213223
return MDNode::get(Ctx, {
214224
ClauseTypeToName(Ctx, Clause.Type),

0 commit comments

Comments
 (0)