sammccall created this revision. sammccall added a reviewer: kadircet. Herald added a subscriber: usaxena95. Herald added a project: All. sammccall requested review of this revision. Herald added subscribers: cfe-commits, ilya-biryukov. Herald added a project: clang.
Most Exprs are serialized unabbreviated, so this saves 6 bits per expr. This is worth 0.3% on clangd --check=clangd/AST.cpp: 42276772 -> 42187128 Not terribly much but a trivial change... Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D124427 Files: clang/lib/Serialization/ASTReaderStmt.cpp clang/lib/Serialization/ASTWriterDecl.cpp clang/lib/Serialization/ASTWriterStmt.cpp Index: clang/lib/Serialization/ASTWriterStmt.cpp =================================================================== --- clang/lib/Serialization/ASTWriterStmt.cpp +++ clang/lib/Serialization/ASTWriterStmt.cpp @@ -544,8 +544,9 @@ VisitStmt(E); Record.AddTypeRef(E->getType()); Record.push_back(E->getDependence()); - Record.push_back(E->getValueKind()); - Record.push_back(E->getObjectKind()); + // Stmt is often written unabbreviated. + // VK(2) + OK(3) fit together into a single VBR6 chunk. + Record.push_back(E->getValueKind() | E->getObjectKind() << 2); } void ASTStmtWriter::VisitConstantExpr(ConstantExpr *E) { Index: clang/lib/Serialization/ASTWriterDecl.cpp =================================================================== --- clang/lib/Serialization/ASTWriterDecl.cpp +++ clang/lib/Serialization/ASTWriterDecl.cpp @@ -2296,9 +2296,8 @@ // Expr Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, ExprDependenceBits)); - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind - //DeclRefExpr + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 5)); // ValueKind, ObjectKind + // DeclRefExpr Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //HasQualifier Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //GetDeclFound Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ExplicitTemplateArgs @@ -2316,9 +2315,8 @@ // Expr Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, ExprDependenceBits)); - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind - //Integer Literal + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 5)); // ValueKind, ObjectKind + // Integer Literal Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location Abv->Add(BitCodeAbbrevOp(32)); // Bit Width Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Value @@ -2331,9 +2329,8 @@ // Expr Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, ExprDependenceBits)); - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind - //Character Literal + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 5)); // ValueKind, ObjectKind + // Character Literal Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getValue Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // getKind @@ -2346,8 +2343,7 @@ // Expr Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, ExprDependenceBits)); - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 5)); // ValueKind, ObjectKind // CastExpr Abv->Add(BitCodeAbbrevOp(0)); // PathSize Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // HasFPFeatures Index: clang/lib/Serialization/ASTReaderStmt.cpp =================================================================== --- clang/lib/Serialization/ASTReaderStmt.cpp +++ clang/lib/Serialization/ASTReaderStmt.cpp @@ -107,7 +107,7 @@ /// The number of record fields required for the Expr class /// itself. - static const unsigned NumExprFields = NumStmtFields + 4; + static const unsigned NumExprFields = NumStmtFields + 3; /// Read and initialize a ExplicitTemplateArgumentList structure. void ReadTemplateKWAndArgsInfo(ASTTemplateKWAndArgsInfo &Args, @@ -521,8 +521,9 @@ VisitStmt(E); E->setType(Record.readType()); E->setDependence(static_cast<ExprDependence>(Record.readInt())); - E->setValueKind(static_cast<ExprValueKind>(Record.readInt())); - E->setObjectKind(static_cast<ExprObjectKind>(Record.readInt())); + unsigned OKVK = Record.readInt(); + E->setValueKind(static_cast<ExprValueKind>(OKVK & 0x3)); + E->setObjectKind(static_cast<ExprObjectKind>(OKVK >> 2)); assert(Record.getIdx() == NumExprFields && "Incorrect expression field count"); }
Index: clang/lib/Serialization/ASTWriterStmt.cpp =================================================================== --- clang/lib/Serialization/ASTWriterStmt.cpp +++ clang/lib/Serialization/ASTWriterStmt.cpp @@ -544,8 +544,9 @@ VisitStmt(E); Record.AddTypeRef(E->getType()); Record.push_back(E->getDependence()); - Record.push_back(E->getValueKind()); - Record.push_back(E->getObjectKind()); + // Stmt is often written unabbreviated. + // VK(2) + OK(3) fit together into a single VBR6 chunk. + Record.push_back(E->getValueKind() | E->getObjectKind() << 2); } void ASTStmtWriter::VisitConstantExpr(ConstantExpr *E) { Index: clang/lib/Serialization/ASTWriterDecl.cpp =================================================================== --- clang/lib/Serialization/ASTWriterDecl.cpp +++ clang/lib/Serialization/ASTWriterDecl.cpp @@ -2296,9 +2296,8 @@ // Expr Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, ExprDependenceBits)); - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind - //DeclRefExpr + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 5)); // ValueKind, ObjectKind + // DeclRefExpr Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //HasQualifier Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //GetDeclFound Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); //ExplicitTemplateArgs @@ -2316,9 +2315,8 @@ // Expr Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, ExprDependenceBits)); - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind - //Integer Literal + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 5)); // ValueKind, ObjectKind + // Integer Literal Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location Abv->Add(BitCodeAbbrevOp(32)); // Bit Width Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Value @@ -2331,9 +2329,8 @@ // Expr Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, ExprDependenceBits)); - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind - //Character Literal + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 5)); // ValueKind, ObjectKind + // Character Literal Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getValue Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Location Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // getKind @@ -2346,8 +2343,7 @@ // Expr Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Type Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, ExprDependenceBits)); - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetValueKind - Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); //GetObjectKind + Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 5)); // ValueKind, ObjectKind // CastExpr Abv->Add(BitCodeAbbrevOp(0)); // PathSize Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // HasFPFeatures Index: clang/lib/Serialization/ASTReaderStmt.cpp =================================================================== --- clang/lib/Serialization/ASTReaderStmt.cpp +++ clang/lib/Serialization/ASTReaderStmt.cpp @@ -107,7 +107,7 @@ /// The number of record fields required for the Expr class /// itself. - static const unsigned NumExprFields = NumStmtFields + 4; + static const unsigned NumExprFields = NumStmtFields + 3; /// Read and initialize a ExplicitTemplateArgumentList structure. void ReadTemplateKWAndArgsInfo(ASTTemplateKWAndArgsInfo &Args, @@ -521,8 +521,9 @@ VisitStmt(E); E->setType(Record.readType()); E->setDependence(static_cast<ExprDependence>(Record.readInt())); - E->setValueKind(static_cast<ExprValueKind>(Record.readInt())); - E->setObjectKind(static_cast<ExprObjectKind>(Record.readInt())); + unsigned OKVK = Record.readInt(); + E->setValueKind(static_cast<ExprValueKind>(OKVK & 0x3)); + E->setObjectKind(static_cast<ExprObjectKind>(OKVK >> 2)); assert(Record.getIdx() == NumExprFields && "Incorrect expression field count"); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits