Skip to content

Commit 9ec5afe

Browse files
authored
[NFC][RootSignature] Move RootSignature util functions (llvm#142491)
`HLSLRootSignature.h` was originally created to hold the struct definitions of an `llvm::hlsl::rootsig::RootElement` and some helper functions for it. However, there many users of the structs that don't require any of the helper methods. This requires us to link the `FrontendHLSL` library, where we otherwise wouldn't need to. For instance: - This [revert](llvm#142005) was required as it requires linking to the unrequired `FrontendHLSL` library - As part of the change required here: llvm#126557. We will want to add an `HLSLRootSignatureVersion` enum. Ideally this could live with the root signature struct defs, but we don't want to link the helper objects into `clang/Basic/TargetOptions.h` This change allows the struct definitions to be kept in a single header file and to then have the `FrontendHLSL` library only be linked when required.
1 parent 3887c23 commit 9ec5afe

File tree

7 files changed

+73
-44
lines changed

7 files changed

+73
-44
lines changed

clang/lib/AST/TextNodeDumper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +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"
27+
#include "llvm/Frontend/HLSL/HLSLRootSignatureUtils.h"
2828

2929
#include <algorithm>
3030
#include <utility>

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "clang/AST/Type.h"
2424
#include "clang/Basic/TargetOptions.h"
2525
#include "llvm/ADT/SmallVector.h"
26+
#include "llvm/Frontend/HLSL/HLSLRootSignatureUtils.h"
2627
#include "llvm/IR/Constants.h"
2728
#include "llvm/IR/DerivedTypes.h"
2829
#include "llvm/IR/GlobalVariable.h"

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

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,19 @@
66
//
77
//===----------------------------------------------------------------------===//
88
///
9-
/// \file This file contains helper objects for working with HLSL Root
10-
/// Signatures.
9+
/// \file This file contains structure definitions of HLSL Root Signature
10+
/// objects.
1111
///
1212
//===----------------------------------------------------------------------===//
1313

1414
#ifndef LLVM_FRONTEND_HLSL_HLSLROOTSIGNATURE_H
1515
#define LLVM_FRONTEND_HLSL_HLSLROOTSIGNATURE_H
1616

17-
#include "llvm/ADT/ArrayRef.h"
1817
#include "llvm/Support/Compiler.h"
1918
#include "llvm/Support/DXILABI.h"
20-
#include "llvm/Support/raw_ostream.h"
2119
#include <variant>
2220

2321
namespace llvm {
24-
class LLVMContext;
25-
class MDNode;
26-
class Metadata;
27-
2822
namespace hlsl {
2923
namespace rootsig {
3024

@@ -195,8 +189,6 @@ struct DescriptorTable {
195189
uint32_t NumClauses = 0;
196190
};
197191

198-
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const DescriptorTable &Table);
199-
200192
static const uint32_t NumDescriptorsUnbounded = 0xffffffff;
201193
static const uint32_t DescriptorTableOffsetAppend = 0xffffffff;
202194
// Models DTClause : CBV | SRV | UAV | Sampler, by collecting like parameters
@@ -225,9 +217,6 @@ struct DescriptorTableClause {
225217
}
226218
};
227219

228-
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS,
229-
const DescriptorTableClause &Clause);
230-
231220
struct StaticSampler {
232221
Register Reg;
233222
SamplerFilter Filter = SamplerFilter::Anisotropic;
@@ -264,32 +253,6 @@ using RootElement =
264253
std::variant<RootFlags, RootConstants, RootDescriptor, DescriptorTable,
265254
DescriptorTableClause, StaticSampler>;
266255

267-
LLVM_ABI void dumpRootElements(raw_ostream &OS, ArrayRef<RootElement> Elements);
268-
269-
class MetadataBuilder {
270-
public:
271-
MetadataBuilder(llvm::LLVMContext &Ctx, ArrayRef<RootElement> Elements)
272-
: Ctx(Ctx), Elements(Elements) {}
273-
274-
/// Iterates through the elements and dispatches onto the correct Build method
275-
///
276-
/// Accumulates the root signature and returns the Metadata node that is just
277-
/// a list of all the elements
278-
LLVM_ABI MDNode *BuildRootSignature();
279-
280-
private:
281-
/// Define the various builders for the different metadata types
282-
MDNode *BuildRootFlags(const RootFlags &Flags);
283-
MDNode *BuildRootConstants(const RootConstants &Constants);
284-
MDNode *BuildRootDescriptor(const RootDescriptor &Descriptor);
285-
MDNode *BuildDescriptorTable(const DescriptorTable &Table);
286-
MDNode *BuildDescriptorTableClause(const DescriptorTableClause &Clause);
287-
288-
llvm::LLVMContext &Ctx;
289-
ArrayRef<RootElement> Elements;
290-
SmallVector<Metadata *> GeneratedMetadata;
291-
};
292-
293256
} // namespace rootsig
294257
} // namespace hlsl
295258
} // namespace llvm
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//===- HLSLRootSignatureUtils.h - HLSL Root Signature helpers -------------===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
///
9+
/// \file This file contains helper obejcts for working with HLSL Root
10+
/// Signatures.
11+
///
12+
//===----------------------------------------------------------------------===//
13+
14+
#ifndef LLVM_FRONTEND_HLSL_HLSLROOTSIGNATUREUTILS_H
15+
#define LLVM_FRONTEND_HLSL_HLSLROOTSIGNATUREUTILS_H
16+
17+
#include "llvm/ADT/ArrayRef.h"
18+
#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
19+
#include "llvm/Support/Compiler.h"
20+
#include "llvm/Support/raw_ostream.h"
21+
22+
namespace llvm {
23+
class LLVMContext;
24+
class MDNode;
25+
class Metadata;
26+
27+
namespace hlsl {
28+
namespace rootsig {
29+
30+
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS,
31+
const DescriptorTableClause &Clause);
32+
33+
LLVM_ABI raw_ostream &operator<<(raw_ostream &OS, const DescriptorTable &Table);
34+
35+
LLVM_ABI void dumpRootElements(raw_ostream &OS, ArrayRef<RootElement> Elements);
36+
37+
class MetadataBuilder {
38+
public:
39+
MetadataBuilder(llvm::LLVMContext &Ctx, ArrayRef<RootElement> Elements)
40+
: Ctx(Ctx), Elements(Elements) {}
41+
42+
/// Iterates through the elements and dispatches onto the correct Build method
43+
///
44+
/// Accumulates the root signature and returns the Metadata node that is just
45+
/// a list of all the elements
46+
LLVM_ABI MDNode *BuildRootSignature();
47+
48+
private:
49+
/// Define the various builders for the different metadata types
50+
MDNode *BuildRootFlags(const RootFlags &Flags);
51+
MDNode *BuildRootConstants(const RootConstants &Constants);
52+
MDNode *BuildRootDescriptor(const RootDescriptor &Descriptor);
53+
MDNode *BuildDescriptorTable(const DescriptorTable &Table);
54+
MDNode *BuildDescriptorTableClause(const DescriptorTableClause &Clause);
55+
56+
llvm::LLVMContext &Ctx;
57+
ArrayRef<RootElement> Elements;
58+
SmallVector<Metadata *> GeneratedMetadata;
59+
};
60+
61+
} // namespace rootsig
62+
} // namespace hlsl
63+
} // namespace llvm
64+
65+
#endif // LLVM_FRONTEND_HLSL_HLSLROOTSIGNATUREUTILS_H

llvm/lib/Frontend/HLSL/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
add_llvm_component_library(LLVMFrontendHLSL
22
CBuffer.cpp
33
HLSLResource.cpp
4-
HLSLRootSignature.cpp
4+
HLSLRootSignatureUtils.cpp
55

66
ADDITIONAL_HEADER_DIRS
77
${LLVM_MAIN_INCLUDE_DIR}/llvm/Frontend

llvm/lib/Frontend/HLSL/HLSLRootSignature.cpp renamed to llvm/lib/Frontend/HLSL/HLSLRootSignatureUtils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===- HLSLRootSignature.cpp - HLSL Root Signature helper objects ---------===//
1+
//===- HLSLRootSignatureUtils.cpp - HLSL Root Signature helpers -----------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -10,7 +10,7 @@
1010
///
1111
//===----------------------------------------------------------------------===//
1212

13-
#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
13+
#include "llvm/Frontend/HLSL/HLSLRootSignatureUtils.h"
1414
#include "llvm/ADT/SmallString.h"
1515
#include "llvm/ADT/bit.h"
1616
#include "llvm/IR/IRBuilder.h"

llvm/unittests/Frontend/HLSLRootSignatureDumpTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
9+
#include "llvm/Frontend/HLSL/HLSLRootSignatureUtils.h"
1010
#include "gtest/gtest.h"
1111

1212
using namespace llvm::hlsl::rootsig;

0 commit comments

Comments
 (0)