Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Modules] EvaluateAsInitializer executed on used variable templates in every importer #61040

Closed
davidstone opened this issue Feb 27, 2023 · 3 comments
Assignees
Labels
clang:modules C++20 modules and Clang Header Modules

Comments

@davidstone
Copy link
Contributor

Given the following two translation units:

export module a;

#define REPEAT8(x) \
	(x), \
	(x), \
	(x), \
	(x), \
	(x), \
	(x), \
	(x), \
	(x)


unsigned a() {
	unsigned x = 0;
	REPEAT8(REPEAT8(REPEAT8(REPEAT8(REPEAT8(REPEAT8(++x))))));
	return x;
}

template<typename>
unsigned aa = a();

void aaa() {
	aa<int>;
}
export module b;

import a;

And compiled with

clang++ -std=c++20 -x c++-module --precompile -c a.cpp -o a.pcm
clang++ -std=c++20 -fmodule-file=a=a.pcm -x c++-module -c b.cpp

Causes the compilation of b.cpp to take longer than expected, especially if optimizations are turned on. Passing -ftime-trace shows that most of the non-optimizer time is spent in EvaluateAsInitializer on aa. If optimizations are turned on, it then spends a bunch of extra time compiling module b for optimizations, primarily SROAPass, but that is possibly just a duplicate of #60996

@davidstone davidstone changed the title [Modules] Initializers of used variable templates evaluated in every importer [Modules] EvaluateAsInitializer executed on used variable templates in every importer Feb 28, 2023
@davidstone
Copy link
Contributor Author

In this example, if I declare unsigned a() as constexpr unsigned a() and thereby cause aa to have constant initialization, then in this example module b no longer spends time in EvaluateAsInitializer. However, the real program I reduced this from has a module that spends time on EvaluateAsInitializer even when the module contains nothing but imports, and the variable templates it is evaluating are all declared constexpr.

@EugeneZelenko EugeneZelenko added clang:modules C++20 modules and Clang Header Modules and removed new issue labels Feb 28, 2023
@llvmbot
Copy link
Collaborator

llvmbot commented Feb 28, 2023

@llvm/issue-subscribers-clang-modules

@ChuanqiXu9
Copy link
Member

Fixed in af86957.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:modules C++20 modules and Clang Header Modules
Projects
None yet
Development

No branches or pull requests

4 participants