Author: Sam McCall Date: 2022-04-25T12:09:40+02:00 New Revision: 0cd5cd19af0eee1d35077de6824b2fe3022d2280
URL: https://github.com/llvm/llvm-project/commit/0cd5cd19af0eee1d35077de6824b2fe3022d2280 DIFF: https://github.com/llvm/llvm-project/commit/0cd5cd19af0eee1d35077de6824b2fe3022d2280.diff LOG: [Serialization] write expr dependence bits as a single integer When exprs are written unabbreviated: - these were encoded as 5 x vbr6 = 30 bits - now they fit exactly into a one-chunk vbr = 6 bits clangd --check=clangd/AST.cpp reports ~1% reduction in PCH size (42826720->42474460) Differential Revision: https://reviews.llvm.org/D124250 Added: Modified: clang/lib/Serialization/ASTReaderStmt.cpp clang/lib/Serialization/ASTWriterDecl.cpp clang/lib/Serialization/ASTWriterStmt.cpp Removed: ################################################################################ diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp b/clang/lib/Serialization/ASTReaderStmt.cpp index 281385ad9e7d9..77ea1b95d5be5 100644 --- a/clang/lib/Serialization/ASTReaderStmt.cpp +++ b/clang/lib/Serialization/ASTReaderStmt.cpp @@ -107,8 +107,7 @@ namespace clang { /// The number of record fields required for the Expr class /// itself. - static const unsigned NumExprFields = - NumStmtFields + llvm::BitWidth<ExprDependence> + 3; + static const unsigned NumExprFields = NumStmtFields + 4; /// Read and initialize a ExplicitTemplateArgumentList structure. void ReadTemplateKWAndArgsInfo(ASTTemplateKWAndArgsInfo &Args, @@ -521,26 +520,7 @@ void ASTStmtReader::VisitCapturedStmt(CapturedStmt *S) { void ASTStmtReader::VisitExpr(Expr *E) { VisitStmt(E); E->setType(Record.readType()); - - // FIXME: write and read all DependentFlags with a single call. - bool TypeDependent = Record.readInt(); - bool ValueDependent = Record.readInt(); - bool InstantiationDependent = Record.readInt(); - bool ContainsUnexpandedTemplateParameters = Record.readInt(); - bool ContainsErrors = Record.readInt(); - auto Deps = ExprDependence::None; - if (TypeDependent) - Deps |= ExprDependence::Type; - if (ValueDependent) - Deps |= ExprDependence::Value; - if (InstantiationDependent) - Deps |= ExprDependence::Instantiation; - if (ContainsUnexpandedTemplateParameters) - Deps |= ExprDependence::UnexpandedPack; - if (ContainsErrors) - Deps |= ExprDependence::Error; - E->setDependence(Deps); - + E->setDependence(static_cast<ExprDependence>(Record.readInt())); E->setValueKind(static_cast<ExprValueKind>(Record.readInt())); E->setObjectKind(static_cast<ExprObjectKind>(Record.readInt())); assert(Record.getIdx() == NumExprFields && diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp index 4e9e97514de0b..3666d5a6daab8 100644 --- a/clang/lib/Serialization/ASTWriterDecl.cpp +++ b/clang/lib/Serialization/ASTWriterDecl.cpp @@ -2288,17 +2288,14 @@ void ASTWriter::WriteDeclAbbrevs() { Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); DeclCXXMethodAbbrev = Stream.EmitAbbrev(std::move(Abv)); + unsigned ExprDependenceBits = llvm::BitWidth<ExprDependence>; // Abbreviation for EXPR_DECL_REF Abv = std::make_shared<BitCodeAbbrev>(); Abv->Add(BitCodeAbbrevOp(serialization::EXPR_DECL_REF)); //Stmt // Expr Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ContainsErrors + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, ExprDependenceBits)); Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind //DeclRefExpr @@ -2318,11 +2315,7 @@ void ASTWriter::WriteDeclAbbrevs() { //Stmt // Expr Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ContainsErrors + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, ExprDependenceBits)); Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind //Integer Literal @@ -2337,11 +2330,7 @@ void ASTWriter::WriteDeclAbbrevs() { //Stmt // Expr Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ContainsErrors + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, ExprDependenceBits)); Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind //Character Literal @@ -2356,11 +2345,7 @@ void ASTWriter::WriteDeclAbbrevs() { // Stmt // Expr Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //TypeDependent - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ValueDependent - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //InstantiationDependent - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //UnexpandedParamPack - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ContainsErrors + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, ExprDependenceBits)); Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind // CastExpr diff --git a/clang/lib/Serialization/ASTWriterStmt.cpp b/clang/lib/Serialization/ASTWriterStmt.cpp index 1a4c782d5917d..587aad3f11e06 100644 --- a/clang/lib/Serialization/ASTWriterStmt.cpp +++ b/clang/lib/Serialization/ASTWriterStmt.cpp @@ -543,11 +543,7 @@ void ASTStmtWriter::VisitCapturedStmt(CapturedStmt *S) { void ASTStmtWriter::VisitExpr(Expr *E) { VisitStmt(E); Record.AddTypeRef(E->getType()); - Record.push_back(E->isTypeDependent()); - Record.push_back(E->isValueDependent()); - Record.push_back(E->isInstantiationDependent()); - Record.push_back(E->containsUnexpandedParameterPack()); - Record.push_back(E->containsErrors()); + Record.push_back(E->getDependence()); Record.push_back(E->getValueKind()); Record.push_back(E->getObjectKind()); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits