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

[C++20] [Modules] Generating LLVM IR takes time proportional to unused code in imported modules #60693

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

Comments

@davidstone
Copy link
Contributor

davidstone commented Feb 12, 2023

Given the following two translation units:

export module a;

constexpr bool f() {
	for (unsigned n = 0; n != 1'000'000; ++n) {
	}
	return true;
}

template<typename>
struct s {
	static constexpr auto a = f();
	static constexpr auto b = f();
	static constexpr auto c = f();
	static constexpr auto d = f();
};

template struct s<int>;
template struct s<long>;
export module b;

import a;

After calling

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

I would expect module b should be compiled very quickly. Instead, I see

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

________________________________________________________
Executed in   13.09 millis    fish           external
   usr time    3.69 millis  594.00 micros    3.09 millis
   sys time    9.42 millis  157.00 micros    9.26 millis

which is reasonable, but

$ time clang++ -c b.pcm -o b.o

________________________________________________________
Executed in    5.45 secs    fish           external
   usr time    5.44 secs  677.00 micros    5.44 secs
   sys time    0.01 secs  177.00 micros    0.01 secs

which is not reasonable. This time scales linearly with the number of explicit template instantiations in module a.

This is as of 9f20142, but I have experienced this slowness in any version that supports modules.

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

llvmbot commented Feb 13, 2023

@llvm/issue-subscribers-clang-modules

@ChuanqiXu9 ChuanqiXu9 self-assigned this Feb 13, 2023
@ChuanqiXu9 ChuanqiXu9 changed the title Generating .o file for module takes time proportional to unused code in imported modules [C++20] [Modules] Generating LLVM IR takes time proportional to unused code in imported modules Feb 13, 2023
@ChuanqiXu9
Copy link
Member

ChuanqiXu9 commented Feb 13, 2023

For

// c.cpp
import a;

I get

$ time clang++ -std=c++20 -fprebuilt-module-path=. c.cpp -Xclang -disable-llvm-passes -S -emit-llvm -o c.ll

real	0m8.117s
user	0m8.018s
sys	0m0.012s

So the problem occurs during IR generation and this is not limited to module units.

CarlosAlbertoEnciso pushed a commit to SNSystems/llvm-debuginfo-analyzer that referenced this issue Feb 15, 2023
Close llvm/llvm-project#60693.

In this issue, we can find that the importer will try to generate the
template specialization again in the importer, which is not good and
wastes time. This patch tries to address the problem.
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