Skip to content

Reduce Decl's dependency on DeclContext/other Decls. #113950

Open
@erichkeane

Description

@erichkeane

One of the outcomes of the llvm-dev talk by @zygoloid is that it got me thinking about ways to improve template instantiation time. One such problem is that we rebuild every Decl every time, particularly VarDecl thanks to its link to its DeclContext and other Decls, instead of being able ot use them like we do with some Stmt nodes.

There are three steps to this:
1- Remove the dependency on DeclContext for Decl types where this doesn't matter. From a quick look, it seems that various FunctionDecl types probably still need the link, as does VarDecls at the global state, so moving this out of Decl and reproducing the DeclContext references in each place it is needed (plus conditionally NOT referencing it in the VarDecl case) is likely a great first step.

2- Replace the DeclContext::decls implementation/storage. Currently this is done by using a linked-list as a part of Decl, which obviously causes a dependency on the "next" declaration, so we could only re-use the 'last' declarations. Instead, we could perhaps have some sort of storage on DeclContext itself to do this relationship.

3- Update instantiation of various Decl types to re-use the node if none of its children change. VarDecl in the "parent is a function decl" case is probably a great first step that ends up saving us a bit, but other types likely assume they always need to be rebuilt. This part is likely a long-tail, but we can enable it via 1 and 2.

FILING this as an issue so that someone someday will work on this. I don't really have time short-term, so if someone is wanting to take this one, please feel free!

Metadata

Metadata

Assignees

Labels

clang:frontendLanguage frontend issues, e.g. anything involving "Sema"code-cleanup

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions