зеркало из https://github.com/microsoft/clang-1.git
Use ASTVector instead of std::vector for the Exprs in InitListExpr. Performance
measurements of '-fsyntax-only' on combine.c (403.gcc) shows no real performance change, but now the vector isn't leaked. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@101195 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Родитель
9c9bd84383
Коммит
709210feee
|
@ -18,6 +18,7 @@
|
|||
#include "clang/AST/Stmt.h"
|
||||
#include "clang/AST/Type.h"
|
||||
#include "clang/AST/DeclAccessPair.h"
|
||||
#include "clang/AST/ASTVector.h"
|
||||
#include "llvm/ADT/APSInt.h"
|
||||
#include "llvm/ADT/APFloat.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
|
@ -2440,7 +2441,8 @@ public:
|
|||
/// serves as its syntactic form.
|
||||
class InitListExpr : public Expr {
|
||||
// FIXME: Eliminate this vector in favor of ASTContext allocation
|
||||
std::vector<Stmt *> InitExprs;
|
||||
typedef ASTVector<Stmt *> InitExprsTy;
|
||||
InitExprsTy InitExprs;
|
||||
SourceLocation LBraceLoc, RBraceLoc;
|
||||
|
||||
/// Contains the initializer list that describes the syntactic form
|
||||
|
@ -2456,11 +2458,13 @@ class InitListExpr : public Expr {
|
|||
bool HadArrayRangeDesignator;
|
||||
|
||||
public:
|
||||
InitListExpr(SourceLocation lbraceloc, Expr **initexprs, unsigned numinits,
|
||||
InitListExpr(ASTContext &C, SourceLocation lbraceloc,
|
||||
Expr **initexprs, unsigned numinits,
|
||||
SourceLocation rbraceloc);
|
||||
|
||||
/// \brief Build an empty initializer list.
|
||||
explicit InitListExpr(EmptyShell Empty) : Expr(InitListExprClass, Empty) { }
|
||||
explicit InitListExpr(ASTContext &C, EmptyShell Empty)
|
||||
: Expr(InitListExprClass, Empty), InitExprs(C) { }
|
||||
|
||||
unsigned getNumInits() const { return InitExprs.size(); }
|
||||
|
||||
|
@ -2480,7 +2484,7 @@ public:
|
|||
}
|
||||
|
||||
/// \brief Reserve space for some number of initializers.
|
||||
void reserveInits(unsigned NumInits);
|
||||
void reserveInits(ASTContext &C, unsigned NumInits);
|
||||
|
||||
/// @brief Specify the number of initializers
|
||||
///
|
||||
|
@ -2497,7 +2501,7 @@ public:
|
|||
/// When @p Init is out of range for this initializer list, the
|
||||
/// initializer list will be extended with NULL expressions to
|
||||
/// accomodate the new entry.
|
||||
Expr *updateInit(unsigned Init, Expr *expr);
|
||||
Expr *updateInit(ASTContext &C, unsigned Init, Expr *expr);
|
||||
|
||||
/// \brief If this initializes a union, specifies which field in the
|
||||
/// union to initialize.
|
||||
|
@ -2543,8 +2547,8 @@ public:
|
|||
virtual child_iterator child_begin();
|
||||
virtual child_iterator child_end();
|
||||
|
||||
typedef std::vector<Stmt *>::iterator iterator;
|
||||
typedef std::vector<Stmt *>::reverse_iterator reverse_iterator;
|
||||
typedef InitExprsTy::iterator iterator;
|
||||
typedef InitExprsTy::reverse_iterator reverse_iterator;
|
||||
|
||||
iterator begin() { return InitExprs.begin(); }
|
||||
iterator end() { return InitExprs.end(); }
|
||||
|
|
|
@ -722,10 +722,11 @@ OverloadedOperatorKind BinaryOperator::getOverloadedOperator(Opcode Opc) {
|
|||
return OverOps[Opc];
|
||||
}
|
||||
|
||||
InitListExpr::InitListExpr(SourceLocation lbraceloc,
|
||||
InitListExpr::InitListExpr(ASTContext &C, SourceLocation lbraceloc,
|
||||
Expr **initExprs, unsigned numInits,
|
||||
SourceLocation rbraceloc)
|
||||
: Expr(InitListExprClass, QualType(), false, false),
|
||||
InitExprs(C, numInits),
|
||||
LBraceLoc(lbraceloc), RBraceLoc(rbraceloc), SyntacticForm(0),
|
||||
UnionFieldInit(0), HadArrayRangeDesignator(false)
|
||||
{
|
||||
|
@ -736,24 +737,24 @@ InitListExpr::InitListExpr(SourceLocation lbraceloc,
|
|||
ValueDependent = true;
|
||||
}
|
||||
|
||||
InitExprs.insert(InitExprs.end(), initExprs, initExprs+numInits);
|
||||
InitExprs.insert(C, InitExprs.end(), initExprs, initExprs+numInits);
|
||||
}
|
||||
|
||||
void InitListExpr::reserveInits(unsigned NumInits) {
|
||||
void InitListExpr::reserveInits(ASTContext &C, unsigned NumInits) {
|
||||
if (NumInits > InitExprs.size())
|
||||
InitExprs.reserve(NumInits);
|
||||
InitExprs.reserve(C, NumInits);
|
||||
}
|
||||
|
||||
void InitListExpr::resizeInits(ASTContext &Context, unsigned NumInits) {
|
||||
void InitListExpr::resizeInits(ASTContext &C, unsigned NumInits) {
|
||||
for (unsigned Idx = NumInits, LastIdx = InitExprs.size();
|
||||
Idx < LastIdx; ++Idx)
|
||||
InitExprs[Idx]->Destroy(Context);
|
||||
InitExprs.resize(NumInits, 0);
|
||||
InitExprs[Idx]->Destroy(C);
|
||||
InitExprs.resize(C, NumInits, 0);
|
||||
}
|
||||
|
||||
Expr *InitListExpr::updateInit(unsigned Init, Expr *expr) {
|
||||
Expr *InitListExpr::updateInit(ASTContext &C, unsigned Init, Expr *expr) {
|
||||
if (Init >= InitExprs.size()) {
|
||||
InitExprs.insert(InitExprs.end(), Init - InitExprs.size() + 1, 0);
|
||||
InitExprs.insert(C, InitExprs.end(), Init - InitExprs.size() + 1, 0);
|
||||
InitExprs.back() = expr;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -554,9 +554,9 @@ unsigned PCHStmtReader::VisitExtVectorElementExpr(ExtVectorElementExpr *E) {
|
|||
unsigned PCHStmtReader::VisitInitListExpr(InitListExpr *E) {
|
||||
VisitExpr(E);
|
||||
unsigned NumInits = Record[Idx++];
|
||||
E->reserveInits(NumInits);
|
||||
E->reserveInits(*Reader.getContext(), NumInits);
|
||||
for (unsigned I = 0; I != NumInits; ++I)
|
||||
E->updateInit(I,
|
||||
E->updateInit(*Reader.getContext(), I,
|
||||
cast<Expr>(StmtStack[StmtStack.size() - NumInits - 1 + I]));
|
||||
E->setSyntacticForm(cast_or_null<InitListExpr>(StmtStack.back()));
|
||||
E->setLBraceLoc(SourceLocation::getFromRawEncoding(Record[Idx++]));
|
||||
|
@ -1124,7 +1124,7 @@ Stmt *PCHReader::ReadStmt(llvm::BitstreamCursor &Cursor) {
|
|||
break;
|
||||
|
||||
case pch::EXPR_INIT_LIST:
|
||||
S = new (Context) InitListExpr(Empty);
|
||||
S = new (Context) InitListExpr(*getContext(), Empty);
|
||||
break;
|
||||
|
||||
case pch::EXPR_DESIGNATED_INIT:
|
||||
|
|
|
@ -2754,9 +2754,10 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp,
|
|||
CastExpr::CK_Unknown, SuperRep);
|
||||
} else {
|
||||
// (struct objc_super) { <exprs from above> }
|
||||
InitListExpr *ILE = new (Context) InitListExpr(SourceLocation(),
|
||||
&InitExprs[0], InitExprs.size(),
|
||||
SourceLocation());
|
||||
InitListExpr *ILE =
|
||||
new (Context) InitListExpr(*Context, SourceLocation(),
|
||||
&InitExprs[0], InitExprs.size(),
|
||||
SourceLocation());
|
||||
TypeSourceInfo *superTInfo
|
||||
= Context->getTrivialTypeSourceInfo(superType);
|
||||
SuperRep = new (Context) CompoundLiteralExpr(SourceLocation(), superTInfo,
|
||||
|
@ -2853,9 +2854,10 @@ Stmt *RewriteObjC::SynthMessageExpr(ObjCMessageExpr *Exp,
|
|||
CastExpr::CK_Unknown, SuperRep);
|
||||
} else {
|
||||
// (struct objc_super) { <exprs from above> }
|
||||
InitListExpr *ILE = new (Context) InitListExpr(SourceLocation(),
|
||||
&InitExprs[0], InitExprs.size(),
|
||||
SourceLocation());
|
||||
InitListExpr *ILE =
|
||||
new (Context) InitListExpr(*Context, SourceLocation(),
|
||||
&InitExprs[0], InitExprs.size(),
|
||||
SourceLocation());
|
||||
TypeSourceInfo *superTInfo
|
||||
= Context->getTrivialTypeSourceInfo(superType);
|
||||
SuperRep = new (Context) CompoundLiteralExpr(SourceLocation(), superTInfo,
|
||||
|
|
|
@ -3730,8 +3730,8 @@ Sema::ActOnInitList(SourceLocation LBraceLoc, MultiExprArg initlist,
|
|||
// Semantic analysis for initializers is done by ActOnDeclarator() and
|
||||
// CheckInitializer() - it requires knowledge of the object being intialized.
|
||||
|
||||
InitListExpr *E = new (Context) InitListExpr(LBraceLoc, InitList, NumInit,
|
||||
RBraceLoc);
|
||||
InitListExpr *E = new (Context) InitListExpr(Context, LBraceLoc, InitList,
|
||||
NumInit, RBraceLoc);
|
||||
E->setType(Context.VoidTy); // FIXME: just a place holder for now.
|
||||
return Owned(E);
|
||||
}
|
||||
|
@ -4002,7 +4002,8 @@ Sema::ActOnCastOfParenListExpr(Scope *S, SourceLocation LParenLoc,
|
|||
// FIXME: This means that pretty-printing the final AST will produce curly
|
||||
// braces instead of the original commas.
|
||||
Op.release();
|
||||
InitListExpr *E = new (Context) InitListExpr(LParenLoc, &initExprs[0],
|
||||
InitListExpr *E = new (Context) InitListExpr(Context, LParenLoc,
|
||||
&initExprs[0],
|
||||
initExprs.size(), RParenLoc);
|
||||
E->setType(Ty);
|
||||
return BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, Owned(E));
|
||||
|
@ -4732,7 +4733,7 @@ static void ConstructTransparentUnion(ASTContext &C, Expr *&E,
|
|||
QualType UnionType, FieldDecl *Field) {
|
||||
// Build an initializer list that designates the appropriate member
|
||||
// of the transparent union.
|
||||
InitListExpr *Initializer = new (C) InitListExpr(SourceLocation(),
|
||||
InitListExpr *Initializer = new (C) InitListExpr(C, SourceLocation(),
|
||||
&E, 1,
|
||||
SourceLocation());
|
||||
Initializer->setType(UnionType);
|
||||
|
|
|
@ -281,7 +281,7 @@ void InitListChecker::FillInValueInitForField(unsigned Init, FieldDecl *Field,
|
|||
// extend the initializer list to include the constructor
|
||||
// call and make a note that we'll need to take another pass
|
||||
// through the initializer list.
|
||||
ILE->updateInit(Init, MemberInit.takeAs<Expr>());
|
||||
ILE->updateInit(SemaRef.Context, Init, MemberInit.takeAs<Expr>());
|
||||
RequiresSecondPass = true;
|
||||
}
|
||||
} else if (InitListExpr *InnerILE
|
||||
|
@ -391,7 +391,7 @@ InitListChecker::FillInValueInitializations(const InitializedEntity &Entity,
|
|||
// extend the initializer list to include the constructor
|
||||
// call and make a note that we'll need to take another pass
|
||||
// through the initializer list.
|
||||
ILE->updateInit(Init, ElementInit.takeAs<Expr>());
|
||||
ILE->updateInit(SemaRef.Context, Init, ElementInit.takeAs<Expr>());
|
||||
RequiresSecondPass = true;
|
||||
}
|
||||
} else if (InitListExpr *InnerILE
|
||||
|
@ -1702,7 +1702,8 @@ InitListChecker::getStructuredSubobjectInit(InitListExpr *IList, unsigned Index,
|
|||
}
|
||||
|
||||
InitListExpr *Result
|
||||
= new (SemaRef.Context) InitListExpr(InitRange.getBegin(), 0, 0,
|
||||
= new (SemaRef.Context) InitListExpr(SemaRef.Context,
|
||||
InitRange.getBegin(), 0, 0,
|
||||
InitRange.getEnd());
|
||||
|
||||
Result->setType(CurrentObjectType.getNonReferenceType());
|
||||
|
@ -1740,12 +1741,12 @@ InitListChecker::getStructuredSubobjectInit(InitListExpr *IList, unsigned Index,
|
|||
if (NumElements < NumInits)
|
||||
NumElements = IList->getNumInits();
|
||||
|
||||
Result->reserveInits(NumElements);
|
||||
Result->reserveInits(SemaRef.Context, NumElements);
|
||||
|
||||
// Link this new initializer list into the structured initializer
|
||||
// lists.
|
||||
if (StructuredList)
|
||||
StructuredList->updateInit(StructuredIndex, Result);
|
||||
StructuredList->updateInit(SemaRef.Context, StructuredIndex, Result);
|
||||
else {
|
||||
Result->setSyntacticForm(IList);
|
||||
SyntacticToSemantic[IList] = Result;
|
||||
|
@ -1763,7 +1764,8 @@ void InitListChecker::UpdateStructuredListElement(InitListExpr *StructuredList,
|
|||
if (!StructuredList)
|
||||
return;
|
||||
|
||||
if (Expr *PrevInit = StructuredList->updateInit(StructuredIndex, expr)) {
|
||||
if (Expr *PrevInit = StructuredList->updateInit(SemaRef.Context,
|
||||
StructuredIndex, expr)) {
|
||||
// This initializer overwrites a previous initializer. Warn.
|
||||
SemaRef.Diag(expr->getSourceRange().getBegin(),
|
||||
diag::warn_initializer_overrides)
|
||||
|
|
Загрузка…
Ссылка в новой задаче