Skip to content

Commit 6e842d7

Browse files
committed
review: use TrailingObjects to store elements instead of on the context
1 parent 141c732 commit 6e842d7

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
@@ -5851,24 +5851,31 @@ bool HLSLBufferDecl::buffer_decls_empty() {
58515851
// HLSLRootSignatureDecl Implementation
58525852
//===----------------------------------------------------------------------===//
58535853

5854-
HLSLRootSignatureDecl::HLSLRootSignatureDecl(
5855-
DeclContext *DC, SourceLocation Loc, IdentifierInfo *ID,
5856-
ArrayRef<llvm::hlsl::rootsig::RootElement> RootElements)
5854+
HLSLRootSignatureDecl::HLSLRootSignatureDecl(DeclContext *DC,
5855+
SourceLocation Loc,
5856+
IdentifierInfo *ID,
5857+
unsigned NumElems)
58575858
: NamedDecl(Decl::Kind::HLSLRootSignature, DC, Loc, DeclarationName(ID)),
5858-
RootElements(RootElements) {}
5859+
NumElems(NumElems) {}
58595860

58605861
HLSLRootSignatureDecl *HLSLRootSignatureDecl::Create(
58615862
ASTContext &C, DeclContext *DC, SourceLocation Loc, IdentifierInfo *ID,
58625863
ArrayRef<llvm::hlsl::rootsig::RootElement> RootElements) {
5863-
HLSLRootSignatureDecl *Result =
5864-
new (C, DC) HLSLRootSignatureDecl(DC, Loc, ID, RootElements);
5865-
return Result;
5864+
HLSLRootSignatureDecl *RSDecl =
5865+
new (C, DC,
5866+
additionalSizeToAlloc<llvm::hlsl::rootsig::RootElement>(
5867+
RootElements.size()))
5868+
HLSLRootSignatureDecl(DC, Loc, ID, RootElements.size());
5869+
auto *StoredElems = RSDecl->getElems();
5870+
std::uninitialized_copy(RootElements.begin(), RootElements.end(),
5871+
StoredElems);
5872+
return RSDecl;
58665873
}
58675874

58685875
HLSLRootSignatureDecl *
58695876
HLSLRootSignatureDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) {
5870-
HLSLRootSignatureDecl *Result =
5871-
new (C, ID) HLSLRootSignatureDecl(nullptr, SourceLocation(), nullptr, {});
5877+
HLSLRootSignatureDecl *Result = new (C, ID)
5878+
HLSLRootSignatureDecl(nullptr, SourceLocation(), nullptr, /*NumElems=*/0);
58725879
return Result;
58735880
}
58745881

0 commit comments

Comments
 (0)