[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Add Metadata generation of Root Signatures for Attr (PR #125131)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Jan 30 15:06:58 PST 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 14e7253752ddf98e953061dfbf28a008b18f10ed 016f380a03875fc1251794e6d4e9555d0c60d3e9 --extensions cpp,h -- llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp clang/lib/CodeGen/CGHLSLRuntime.cpp llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 168bda18eb..1280de7142 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -126,8 +126,8 @@ void addRootSignature(
llvm::hlsl::root_signature::MetadataBuilder Builder(Ctx, Elements);
MDNode *RootSignature = Builder.BuildRootSignature();
- MDNode *FnPairing = MDNode::get(Ctx, {ValueAsMetadata::get(Fn),
- RootSignature});
+ MDNode *FnPairing =
+ MDNode::get(Ctx, {ValueAsMetadata::get(Fn), RootSignature});
StringRef RootSignatureValKey = "dx.rootsignatures";
auto *RootSignatureValMD = M.getOrInsertNamedMetadata(RootSignatureValKey);
diff --git a/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h b/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h
index 433cd9bc10..31fd68821b 100644
--- a/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h
+++ b/llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h
@@ -129,14 +129,14 @@ using ParamType = std::variant<uint32_t *, DescriptorRangeOffset *,
DescriptorRangeFlags *, ShaderVisibility *>;
class MetadataBuilder {
- public:
+public:
MetadataBuilder(llvm::LLVMContext &Ctx, ArrayRef<RootElement> Elements)
- : Ctx(Ctx), Elements(Elements) {}
+ : Ctx(Ctx), Elements(Elements) {}
// Iterates through the elements and builds the respective nodes
MDNode *BuildRootSignature();
- private:
+private:
// Define the various builders for the different metadata types
MDNode *BuildDescriptorTable(const DescriptorTable &Table);
MDNode *BuildDescriptorTableClause(const DescriptorTableClause &Clause);
diff --git a/llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp b/llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp
index 0e88046a83..212ccd9fd1 100644
--- a/llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp
+++ b/llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp
@@ -1,4 +1,5 @@
-//===- HLSLRootSignature.cpp - HLSL Root Signature helper objects ----------===//
+//===- HLSLRootSignature.cpp - HLSL Root Signature helper objects
+//----------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -47,16 +48,15 @@ template <class... Ts> OverloadBuilds(Ts...) -> OverloadBuilds<Ts...>;
MDNode *MetadataBuilder::BuildRootSignature() {
for (const RootElement &Element : Elements) {
MDNode *ElementMD =
- std::visit(
- OverloadBuilds{
- [&](DescriptorTable Table) -> MDNode * {
- return BuildDescriptorTable(Table);
- },
- [&](DescriptorTableClause Clause) -> MDNode * {
- return BuildDescriptorTableClause(Clause);
- },
- },
- Element);
+ std::visit(OverloadBuilds{
+ [&](DescriptorTable Table) -> MDNode * {
+ return BuildDescriptorTable(Table);
+ },
+ [&](DescriptorTableClause Clause) -> MDNode * {
+ return BuildDescriptorTableClause(Clause);
+ },
+ },
+ Element);
GeneratedMetadata.push_back(ElementMD);
}
@@ -67,28 +67,34 @@ MDNode *MetadataBuilder::BuildDescriptorTable(const DescriptorTable &Table) {
IRBuilder<> B(Ctx);
SmallVector<Metadata *> TableOperands;
TableOperands.push_back(MDString::get(Ctx, "DescriptorTable"));
- TableOperands.push_back(ConstantAsMetadata::get(B.getInt32(llvm::to_underlying(Table.Visibility))));
+ TableOperands.push_back(ConstantAsMetadata::get(
+ B.getInt32(llvm::to_underlying(Table.Visibility))));
- assert(Table.NumClauses <= GeneratedMetadata.size() && "Table expected all owned clauses to be generated already");
- TableOperands.append(GeneratedMetadata.end() - Table.NumClauses, GeneratedMetadata.end());
+ assert(Table.NumClauses <= GeneratedMetadata.size() &&
+ "Table expected all owned clauses to be generated already");
+ TableOperands.append(GeneratedMetadata.end() - Table.NumClauses,
+ GeneratedMetadata.end());
GeneratedMetadata.pop_back_n(Table.NumClauses);
return MDNode::get(Ctx, TableOperands);
}
-MDNode *MetadataBuilder::BuildDescriptorTableClause(const DescriptorTableClause &Clause) {
+MDNode *MetadataBuilder::BuildDescriptorTableClause(
+ const DescriptorTableClause &Clause) {
IRBuilder<> B(Ctx);
- return MDNode::get(Ctx, {
- ClauseTypeToName(Ctx, Clause.Type),
- ConstantAsMetadata::get(B.getInt32(Clause.NumDescriptors)),
- ConstantAsMetadata::get(B.getInt32(Clause.Register.Number)),
- ConstantAsMetadata::get(B.getInt32(Clause.Space)),
- ConstantAsMetadata::get(B.getInt32(llvm::to_underlying(Clause.Offset))),
- ConstantAsMetadata::get(B.getInt32(llvm::to_underlying(Clause.Flags))),
- });
+ return MDNode::get(
+ Ctx, {
+ ClauseTypeToName(Ctx, Clause.Type),
+ ConstantAsMetadata::get(B.getInt32(Clause.NumDescriptors)),
+ ConstantAsMetadata::get(B.getInt32(Clause.Register.Number)),
+ ConstantAsMetadata::get(B.getInt32(Clause.Space)),
+ ConstantAsMetadata::get(
+ B.getInt32(llvm::to_underlying(Clause.Offset))),
+ ConstantAsMetadata::get(
+ B.getInt32(llvm::to_underlying(Clause.Flags))),
+ });
}
} // namespace root_signature
} // namespace hlsl
} // namespace llvm
-
``````````
</details>
https://github.com/llvm/llvm-project/pull/125131
More information about the llvm-branch-commits
mailing list