[all-commits] [llvm/llvm-project] 20e904: [Serialization] Support loading template specializ...
Chuanqi Xu via All-commits
all-commits at lists.llvm.org
Tue Dec 10 17:41:08 PST 2024
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 20e904950967c125abc1e91f57e5a373987ff016
https://github.com/llvm/llvm-project/commit/20e904950967c125abc1e91f57e5a373987ff016
Author: Chuanqi Xu <yedeng.yd at linux.alibaba.com>
Date: 2024-12-11 (Wed, 11 Dec 2024)
Changed paths:
M clang/include/clang/AST/DeclTemplate.h
M clang/include/clang/AST/ExternalASTSource.h
M clang/include/clang/Sema/MultiplexExternalSemaSource.h
M clang/include/clang/Serialization/ASTBitCodes.h
M clang/include/clang/Serialization/ASTReader.h
M clang/include/clang/Serialization/ASTWriter.h
M clang/lib/AST/DeclTemplate.cpp
M clang/lib/AST/ExternalASTSource.cpp
M clang/lib/AST/ODRHash.cpp
M clang/lib/Sema/MultiplexExternalSemaSource.cpp
M clang/lib/Serialization/ASTCommon.h
M clang/lib/Serialization/ASTReader.cpp
M clang/lib/Serialization/ASTReaderDecl.cpp
M clang/lib/Serialization/ASTReaderInternals.h
M clang/lib/Serialization/ASTWriter.cpp
M clang/lib/Serialization/ASTWriterDecl.cpp
M clang/lib/Serialization/CMakeLists.txt
A clang/lib/Serialization/TemplateArgumentHasher.cpp
A clang/lib/Serialization/TemplateArgumentHasher.h
M clang/test/Modules/cxx-templates.cpp
M clang/test/Modules/odr_hash.cpp
A clang/test/Modules/recursive-instantiations.cppm
M clang/test/OpenMP/target_parallel_ast_print.cpp
M clang/test/OpenMP/target_teams_ast_print.cpp
M clang/test/OpenMP/task_ast_print.cpp
M clang/test/OpenMP/teams_ast_print.cpp
M clang/unittests/Serialization/CMakeLists.txt
A clang/unittests/Serialization/LoadSpecLazilyTest.cpp
M lldb/source/Plugins/ExpressionParser/Clang/ASTUtils.h
Log Message:
-----------
[Serialization] Support loading template specializations lazily (#119333)
Reland https://github.com/llvm/llvm-project/pull/83237
---
(Original comments)
Currently all the specializations of a template (including
instantiation, specialization and partial specializations) will be
loaded at once if we want to instantiate another instance for the
template, or find instantiation for the template, or just want to
complete the redecl chain.
This means basically we need to load every specializations for the
template once the template declaration got loaded. This is bad since
when we load a specialization, we need to load all of its template
arguments. Then we have to deserialize a lot of unnecessary
declarations.
For example,
```
// M.cppm
export module M;
export template <class T>
class A {};
export class ShouldNotBeLoaded {};
export class Temp {
A<ShouldNotBeLoaded> AS;
};
// use.cpp
import M;
A<int> a;
```
We have a specialization ` A<ShouldNotBeLoaded>` in `M.cppm` and we
instantiate the template `A` in `use.cpp`. Then we will deserialize
`ShouldNotBeLoaded` surprisingly when compiling `use.cpp`. And this
patch tries to avoid that.
Given that the templates are heavily used in C++, this is a pain point
for the performance.
This patch adds MultiOnDiskHashTable for specializations in the
ASTReader. Then we will only deserialize the specializations with the
same template arguments. We made that by using ODRHash for the template
arguments as the key of the hash table.
To review this patch, I think `ASTReaderDecl::AddLazySpecializations`
may be a good entry point.
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list