diff options
author | Alexander Kornienko <alexfh@google.com> | 2012-07-09 10:04:07 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2012-07-09 10:04:07 +0000 |
commit | 4990890fc9428f98bef90ba349203a648c592778 (patch) | |
tree | 9c2fcfee3f7fb584462952bf667caaffa7fa44ed /lib | |
parent | ef0ebee9a4e1e6254b9c54c6fbb30045ed959c37 (diff) |
Inline storage of attributes in AttributedStmt.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@159925 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AST/Stmt.cpp | 17 | ||||
-rw-r--r-- | lib/AST/StmtPrinter.cpp | 6 | ||||
-rw-r--r-- | lib/Sema/SemaStmt.cpp | 8 | ||||
-rw-r--r-- | lib/Sema/SemaStmtAttr.cpp | 2 | ||||
-rw-r--r-- | lib/Sema/TreeTransform.h | 3 | ||||
-rw-r--r-- | lib/Serialization/ASTReaderStmt.cpp | 9 | ||||
-rw-r--r-- | lib/Serialization/ASTWriter.cpp | 8 | ||||
-rw-r--r-- | lib/Serialization/ASTWriterDecl.cpp | 3 | ||||
-rw-r--r-- | lib/Serialization/ASTWriterStmt.cpp | 1 |
9 files changed, 41 insertions, 16 deletions
diff --git a/lib/AST/Stmt.cpp b/lib/AST/Stmt.cpp index b6bb528220..ff6374c2d8 100644 --- a/lib/AST/Stmt.cpp +++ b/lib/AST/Stmt.cpp @@ -273,6 +273,23 @@ const char *LabelStmt::getName() const { return getDecl()->getIdentifier()->getNameStart(); } +AttributedStmt *AttributedStmt::Create(ASTContext &C, SourceLocation Loc, + ArrayRef<const Attr*> Attrs, + Stmt *SubStmt) { + void *Mem = C.Allocate(sizeof(AttributedStmt) + + sizeof(Attr*) * (Attrs.size() - 1), + llvm::alignOf<AttributedStmt>()); + return new (Mem) AttributedStmt(Loc, Attrs, SubStmt); +} + +AttributedStmt *AttributedStmt::CreateEmpty(ASTContext &C, unsigned NumAttrs) { + assert(NumAttrs > 0 && "NumAttrs should be greater than zero"); + void *Mem = C.Allocate(sizeof(AttributedStmt) + + sizeof(Attr*) * (NumAttrs - 1), + llvm::alignOf<AttributedStmt>()); + return new (Mem) AttributedStmt(EmptyShell(), NumAttrs); +} + // This is defined here to avoid polluting Stmt.h with importing Expr.h SourceRange ReturnStmt::getSourceRange() const { if (RetExpr) diff --git a/lib/AST/StmtPrinter.cpp b/lib/AST/StmtPrinter.cpp index 8b989e6ae3..2f7cb55c7c 100644 --- a/lib/AST/StmtPrinter.cpp +++ b/lib/AST/StmtPrinter.cpp @@ -173,9 +173,9 @@ void StmtPrinter::VisitLabelStmt(LabelStmt *Node) { void StmtPrinter::VisitAttributedStmt(AttributedStmt *Node) { OS << "[["; bool first = true; - for (AttrVec::const_iterator it = Node->getAttrs().begin(), - end = Node->getAttrs().end(); - it != end; ++it) { + for (ArrayRef<const Attr*>::iterator it = Node->getAttrs().begin(), + end = Node->getAttrs().end(); + it != end; ++it) { if (!first) { OS << ", "; first = false; diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 2db8b5da63..9be1d34dae 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -370,12 +370,10 @@ Sema::ActOnLabelStmt(SourceLocation IdentLoc, LabelDecl *TheDecl, } StmtResult Sema::ActOnAttributedStmt(SourceLocation AttrLoc, - const AttrVec &Attrs, + ArrayRef<const Attr*> Attrs, Stmt *SubStmt) { - // Fill in the declaration and return it. Variable length will require to - // change this to AttributedStmt::Create(Context, ....); - // and probably using ArrayRef - AttributedStmt *LS = new (Context) AttributedStmt(AttrLoc, Attrs, SubStmt); + // Fill in the declaration and return it. + AttributedStmt *LS = AttributedStmt::Create(Context, AttrLoc, Attrs, SubStmt); return Owned(LS); } diff --git a/lib/Sema/SemaStmtAttr.cpp b/lib/Sema/SemaStmtAttr.cpp index 395b9d6259..3c15b7a8af 100644 --- a/lib/Sema/SemaStmtAttr.cpp +++ b/lib/Sema/SemaStmtAttr.cpp @@ -61,7 +61,7 @@ static Attr *ProcessStmtAttribute(Sema &S, Stmt *St, const AttributeList &A, StmtResult Sema::ProcessStmtAttributes(Stmt *S, AttributeList *AttrList, SourceRange Range) { - AttrVec Attrs; + SmallVector<const Attr*, 8> Attrs; for (const AttributeList* l = AttrList; l; l = l->getNext()) { if (Attr *a = ProcessStmtAttribute(*this, S, *l, Range)) Attrs.push_back(a); diff --git a/lib/Sema/TreeTransform.h b/lib/Sema/TreeTransform.h index 3b41f758d9..b03f86bb0e 100644 --- a/lib/Sema/TreeTransform.h +++ b/lib/Sema/TreeTransform.h @@ -1050,7 +1050,8 @@ public: /// /// By default, performs semantic analysis to build the new statement. /// Subclasses may override this routine to provide different behavior. - StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, const AttrVec &Attrs, + StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, + ArrayRef<const Attr*> Attrs, Stmt *SubStmt) { return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt); } diff --git a/lib/Serialization/ASTReaderStmt.cpp b/lib/Serialization/ASTReaderStmt.cpp index 460841b2ff..7d56f10eb5 100644 --- a/lib/Serialization/ASTReaderStmt.cpp +++ b/lib/Serialization/ASTReaderStmt.cpp @@ -162,9 +162,12 @@ void ASTStmtReader::VisitLabelStmt(LabelStmt *S) { void ASTStmtReader::VisitAttributedStmt(AttributedStmt *S) { VisitStmt(S); + uint64_t NumAttrs = Record[Idx++]; AttrVec Attrs; Reader.ReadAttributes(F, Attrs, Record, Idx); - S->Attrs = Attrs; + assert(NumAttrs == S->NumAttrs); + assert(NumAttrs == Attrs.size()); + std::copy(Attrs.begin(), Attrs.end(), S->Attrs); S->SubStmt = Reader.ReadSubStmt(); S->AttrLoc = ReadSourceLocation(Record, Idx); } @@ -1648,7 +1651,9 @@ Stmt *ASTReader::ReadStmtFromStream(ModuleFile &F) { break; case STMT_ATTRIBUTED: - S = new (Context) AttributedStmt(Empty); + S = AttributedStmt::CreateEmpty( + Context, + /*NumAttrs*/Record[ASTStmtReader::NumStmtFields]); break; case STMT_IF: diff --git a/lib/Serialization/ASTWriter.cpp b/lib/Serialization/ASTWriter.cpp index 566c8b77f5..6a6863f17b 100644 --- a/lib/Serialization/ASTWriter.cpp +++ b/lib/Serialization/ASTWriter.cpp @@ -3086,10 +3086,12 @@ void ASTWriter::WriteMergedDecls() { //===----------------------------------------------------------------------===// /// \brief Write a record containing the given attributes. -void ASTWriter::WriteAttributes(const AttrVec &Attrs, RecordDataImpl &Record) { +void ASTWriter::WriteAttributes(ArrayRef<const Attr*> Attrs, + RecordDataImpl &Record) { Record.push_back(Attrs.size()); - for (AttrVec::const_iterator i = Attrs.begin(), e = Attrs.end(); i != e; ++i){ - const Attr * A = *i; + for (ArrayRef<const Attr *>::iterator i = Attrs.begin(), + e = Attrs.end(); i != e; ++i){ + const Attr *A = *i; Record.push_back(A->getKind()); // FIXME: stable encoding, target attrs AddSourceRange(A->getRange(), Record); diff --git a/lib/Serialization/ASTWriterDecl.cpp b/lib/Serialization/ASTWriterDecl.cpp index d4ebc1c42a..96b602221e 100644 --- a/lib/Serialization/ASTWriterDecl.cpp +++ b/lib/Serialization/ASTWriterDecl.cpp @@ -151,7 +151,8 @@ void ASTDeclWriter::VisitDecl(Decl *D) { Record.push_back(D->isInvalidDecl()); Record.push_back(D->hasAttrs()); if (D->hasAttrs()) - Writer.WriteAttributes(D->getAttrs(), Record); + Writer.WriteAttributes(ArrayRef<const Attr*>(D->getAttrs().begin(), + D->getAttrs().size()), Record); Record.push_back(D->isImplicit()); Record.push_back(D->isUsed(false)); Record.push_back(D->isReferenced()); diff --git a/lib/Serialization/ASTWriterStmt.cpp b/lib/Serialization/ASTWriterStmt.cpp index aa24962b66..f63388fa2f 100644 --- a/lib/Serialization/ASTWriterStmt.cpp +++ b/lib/Serialization/ASTWriterStmt.cpp @@ -109,6 +109,7 @@ void ASTStmtWriter::VisitLabelStmt(LabelStmt *S) { void ASTStmtWriter::VisitAttributedStmt(AttributedStmt *S) { VisitStmt(S); + Record.push_back(S->getAttrs().size()); Writer.WriteAttributes(S->getAttrs(), Record); Writer.AddStmt(S->getSubStmt()); Writer.AddSourceLocation(S->getAttrLoc(), Record); |