From: Daniel Dunbar Date: Wed, 15 Oct 2008 17:52:29 +0000 (+0000) Subject: Use BatchEmitOwnedPtrs for writing multiple child exprs, per review. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=20c77e995d5f1bad8fc59fe9e1883a563d94f535;p=clang Use BatchEmitOwnedPtrs for writing multiple child exprs, per review. Also added serialization support to OverloadExpr. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57588 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Expr.h b/include/clang/AST/Expr.h index c2ba3f9ee4..d11c1aa287 100644 --- a/include/clang/AST/Expr.h +++ b/include/clang/AST/Expr.h @@ -1353,6 +1353,9 @@ public: // Iterators virtual child_iterator child_begin(); virtual child_iterator child_end(); + + virtual void EmitImpl(llvm::Serializer& S) const; + static OverloadExpr* CreateImpl(llvm::Deserializer& D, ASTContext& C); }; /// VAArgExpr, used for the builtin function __builtin_va_start. diff --git a/lib/AST/StmtSerialization.cpp b/lib/AST/StmtSerialization.cpp index a6bcf7e8b5..baee030144 100644 --- a/lib/AST/StmtSerialization.cpp +++ b/lib/AST/StmtSerialization.cpp @@ -827,8 +827,7 @@ void ShuffleVectorExpr::EmitImpl(llvm::Serializer& S) const { S.Emit(BuiltinLoc); S.Emit(RParenLoc); S.EmitInt(NumExprs); - for (unsigned i = 0; i < NumExprs; ++i) - S.EmitOwnedPtr(getExpr(i)); + S.BatchEmitOwnedPtrs(NumExprs, &SubExprs[0]); } ShuffleVectorExpr* ShuffleVectorExpr::CreateImpl(llvm::Deserializer& D, @@ -837,10 +836,9 @@ ShuffleVectorExpr* ShuffleVectorExpr::CreateImpl(llvm::Deserializer& D, SourceLocation BL = SourceLocation::ReadVal(D); SourceLocation RP = SourceLocation::ReadVal(D); unsigned NumExprs = D.ReadInt(); + // FIXME: Avoid extra allocation. llvm::SmallVector Exprs(NumExprs); - for (unsigned i = 0; i < NumExprs; ++i) - Exprs[i] = D.ReadOwnedPtr(C); - + D.BatchReadOwnedPtrs(NumExprs, Exprs.begin(), C); return new ShuffleVectorExpr(Exprs.begin(), NumExprs, T, BL, RP); } @@ -848,19 +846,37 @@ void ChooseExpr::EmitImpl(llvm::Serializer& S) const { S.Emit(getType()); S.Emit(BuiltinLoc); S.Emit(RParenLoc); - S.EmitOwnedPtr(getCond()); - S.EmitOwnedPtr(getLHS()); - S.EmitOwnedPtr(getRHS()); + S.BatchEmitOwnedPtrs((unsigned) END_EXPR, &SubExprs[0]); } ChooseExpr* ChooseExpr::CreateImpl(llvm::Deserializer& D, ASTContext& C) { QualType T = QualType::ReadVal(D); SourceLocation BL = SourceLocation::ReadVal(D); SourceLocation RP = SourceLocation::ReadVal(D); - Expr *Cond = D.ReadOwnedPtr(C); - Expr *LHS = D.ReadOwnedPtr(C); - Expr *RHS = D.ReadOwnedPtr(C); - return new ChooseExpr(BL, Cond, LHS, RHS, T, RP); + ChooseExpr *CE = new ChooseExpr(BL, 0, 0, 0, T, RP); + D.BatchReadOwnedPtrs((unsigned) END_EXPR, &CE->SubExprs[0], C); + return CE; +} + +void OverloadExpr::EmitImpl(llvm::Serializer& S) const { + S.Emit(getType()); + S.Emit(BuiltinLoc); + S.Emit(RParenLoc); + S.EmitInt(FnIndex); + S.EmitInt(NumExprs); + S.BatchEmitOwnedPtrs(NumExprs, &SubExprs[0]); +} + +OverloadExpr* OverloadExpr::CreateImpl(llvm::Deserializer& D, ASTContext& C) { + QualType T = QualType::ReadVal(D); + SourceLocation BL = SourceLocation::ReadVal(D); + SourceLocation RP = SourceLocation::ReadVal(D); + unsigned FnIndex = D.ReadInt(); + unsigned NumExprs = D.ReadInt(); + // FIXME: Avoid extra allocation. + llvm::SmallVector Exprs(NumExprs); + D.BatchReadOwnedPtrs(NumExprs, Exprs.begin(), C); + return new OverloadExpr(Exprs.begin(), NumExprs, FnIndex, T, BL, RP); } void VAArgExpr::EmitImpl(llvm::Serializer& S) const {