Skip to content

Commit f5e71a6

Browse files
committed
review: use TrailingObjects to store elements instead of on the context
1 parent b4a074e commit f5e71a6

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

clang/include/clang/AST/Decl.h

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5179,22 +5179,35 @@ class HLSLBufferDecl final : public NamedDecl, public DeclContext {
51795179
friend class ASTDeclWriter;
51805180
};
51815181

5182-
class HLSLRootSignatureDecl final : public NamedDecl {
5183-
ArrayRef<llvm::hlsl::rootsig::RootElement> RootElements;
5182+
class HLSLRootSignatureDecl final
5183+
: public NamedDecl,
5184+
private llvm::TrailingObjects<HLSLRootSignatureDecl,
5185+
llvm::hlsl::rootsig::RootElement> {
5186+
friend TrailingObjects;
5187+
5188+
unsigned NumElems;
51845189

5185-
HLSLRootSignatureDecl(
5186-
DeclContext *DC, SourceLocation Loc, IdentifierInfo *ID,
5187-
ArrayRef<llvm::hlsl::rootsig::RootElement> RootElements);
5190+
llvm::hlsl::rootsig::RootElement *getElems() {
5191+
return getTrailingObjects<llvm::hlsl::rootsig::RootElement>();
5192+
}
5193+
5194+
const llvm::hlsl::rootsig::RootElement *getElems() const {
5195+
return getTrailingObjects<llvm::hlsl::rootsig::RootElement>();
5196+
}
5197+
5198+
HLSLRootSignatureDecl(DeclContext *DC, SourceLocation Loc, IdentifierInfo *ID,
5199+
unsigned NumElems);
51885200

51895201
public:
51905202
static HLSLRootSignatureDecl *
51915203
Create(ASTContext &C, DeclContext *DC, SourceLocation Loc, IdentifierInfo *ID,
51925204
ArrayRef<llvm::hlsl::rootsig::RootElement> RootElements);
5205+
51935206
static HLSLRootSignatureDecl *CreateDeserialized(ASTContext &C,
51945207
GlobalDeclID ID);
51955208

5196-
ArrayRef<llvm::hlsl::rootsig::RootElement> &getRootElements() {
5197-
return RootElements;
5209+
ArrayRef<llvm::hlsl::rootsig::RootElement> getRootElements() const {
5210+
return {getElems(), NumElems};
51985211
}
51995212

52005213
// Implement isa/cast/dyncast/etc.

clang/lib/AST/Decl.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5843,24 +5843,31 @@ bool HLSLBufferDecl::buffer_decls_empty() {
58435843
// HLSLRootSignatureDecl Implementation
58445844
//===----------------------------------------------------------------------===//
58455845

5846-
HLSLRootSignatureDecl::HLSLRootSignatureDecl(
5847-
DeclContext *DC, SourceLocation Loc, IdentifierInfo *ID,
5848-
ArrayRef<llvm::hlsl::rootsig::RootElement> RootElements)
5846+
HLSLRootSignatureDecl::HLSLRootSignatureDecl(DeclContext *DC,
5847+
SourceLocation Loc,
5848+
IdentifierInfo *ID,
5849+
unsigned NumElems)
58495850
: NamedDecl(Decl::Kind::HLSLRootSignature, DC, Loc, DeclarationName(ID)),
5850-
RootElements(RootElements) {}
5851+
NumElems(NumElems) {}
58515852

58525853
HLSLRootSignatureDecl *HLSLRootSignatureDecl::Create(
58535854
ASTContext &C, DeclContext *DC, SourceLocation Loc, IdentifierInfo *ID,
58545855
ArrayRef<llvm::hlsl::rootsig::RootElement> RootElements) {
5855-
HLSLRootSignatureDecl *Result =
5856-
new (C, DC) HLSLRootSignatureDecl(DC, Loc, ID, RootElements);
5857-
return Result;
5856+
HLSLRootSignatureDecl *RSDecl =
5857+
new (C, DC,
5858+
additionalSizeToAlloc<llvm::hlsl::rootsig::RootElement>(
5859+
RootElements.size()))
5860+
HLSLRootSignatureDecl(DC, Loc, ID, RootElements.size());
5861+
auto *StoredElems = RSDecl->getElems();
5862+
std::uninitialized_copy(RootElements.begin(), RootElements.end(),
5863+
StoredElems);
5864+
return RSDecl;
58585865
}
58595866

58605867
HLSLRootSignatureDecl *
58615868
HLSLRootSignatureDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) {
5862-
HLSLRootSignatureDecl *Result =
5863-
new (C, ID) HLSLRootSignatureDecl(nullptr, SourceLocation(), nullptr, {});
5869+
HLSLRootSignatureDecl *Result = new (C, ID)
5870+
HLSLRootSignatureDecl(nullptr, SourceLocation(), nullptr, /*NumElems=*/0);
58645871
return Result;
58655872
}
58665873

0 commit comments

Comments
 (0)