Skip to content

Commit 75edf0c

Browse files
committed
[NFC] [Serialization] Avoid accessing PendingBodies as much as possible
The 'HaveBody' parameter in isConsumerInterestedIn is only used for the function decl if it doesn't have a body already. It should be relatively less frequent than the call to isConsumerInterestedIn. So we can delay the computing of `HaveBdoy` to make it more efficient.
1 parent dda7333 commit 75edf0c

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

clang/include/clang/Serialization/ASTReader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,6 +1492,7 @@ class ASTReader
14921492
getModuleFileLevelDecls(ModuleFile &Mod);
14931493

14941494
private:
1495+
bool isConsumerInterestedIn(Decl *D);
14951496
void PassInterestingDeclsToConsumer();
14961497
void PassInterestingDeclToConsumer(Decl *D);
14971498

clang/lib/Serialization/ASTReaderDecl.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3198,7 +3198,7 @@ inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) {
31983198
/// This routine should return true for anything that might affect
31993199
/// code generation, e.g., inline function definitions, Objective-C
32003200
/// declarations with metadata, etc.
3201-
static bool isConsumerInterestedIn(ASTContext &Ctx, Decl *D, bool HasBody) {
3201+
bool ASTReader::isConsumerInterestedIn(Decl *D) {
32023202
// An ObjCMethodDecl is never considered as "interesting" because its
32033203
// implementation container always is.
32043204

@@ -3207,7 +3207,7 @@ static bool isConsumerInterestedIn(ASTContext &Ctx, Decl *D, bool HasBody) {
32073207
if (isPartOfPerModuleInitializer(D)) {
32083208
auto *M = D->getImportedOwningModule();
32093209
if (M && M->Kind == Module::ModuleMapModule &&
3210-
Ctx.DeclMustBeEmitted(D))
3210+
getContext().DeclMustBeEmitted(D))
32113211
return false;
32123212
}
32133213

@@ -3222,7 +3222,7 @@ static bool isConsumerInterestedIn(ASTContext &Ctx, Decl *D, bool HasBody) {
32223222
(Var->isThisDeclarationADefinition() == VarDecl::Definition ||
32233223
OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(Var));
32243224
if (const auto *Func = dyn_cast<FunctionDecl>(D))
3225-
return Func->doesThisDeclarationHaveABody() || HasBody;
3225+
return Func->doesThisDeclarationHaveABody() || PendingBodies.count(D);
32263226

32273227
if (auto *ES = D->getASTContext().getExternalSource())
32283228
if (ES->hasExternalDefinitions(D) == ExternalASTSource::EK_Never)
@@ -4173,7 +4173,7 @@ void ASTReader::PassInterestingDeclsToConsumer() {
41734173
while (!PotentiallyInterestingDecls.empty()) {
41744174
Decl *D = PotentiallyInterestingDecls.front();
41754175
PotentiallyInterestingDecls.pop_front();
4176-
if (isConsumerInterestedIn(getContext(), D, PendingBodies.count(D)))
4176+
if (isConsumerInterestedIn(D))
41774177
PassInterestingDeclToConsumer(D);
41784178
}
41794179
}
@@ -4197,8 +4197,7 @@ void ASTReader::loadDeclUpdateRecords(PendingUpdateRecord &Record) {
41974197
// the declaration, then we know it was interesting and we skip the call
41984198
// to isConsumerInterestedIn because it is unsafe to call in the
41994199
// current ASTReader state.
4200-
bool WasInteresting =
4201-
Record.JustLoaded || isConsumerInterestedIn(getContext(), D, false);
4200+
bool WasInteresting = Record.JustLoaded || isConsumerInterestedIn(D);
42024201
for (auto &FileAndOffset : UpdateOffsets) {
42034202
ModuleFile *F = FileAndOffset.first;
42044203
uint64_t Offset = FileAndOffset.second;
@@ -4230,8 +4229,7 @@ void ASTReader::loadDeclUpdateRecords(PendingUpdateRecord &Record) {
42304229

42314230
// We might have made this declaration interesting. If so, remember that
42324231
// we need to hand it off to the consumer.
4233-
if (!WasInteresting &&
4234-
isConsumerInterestedIn(getContext(), D, PendingBodies.count(D))) {
4232+
if (!WasInteresting && isConsumerInterestedIn(D)) {
42354233
PotentiallyInterestingDecls.push_back(D);
42364234
WasInteresting = true;
42374235
}

0 commit comments

Comments
 (0)