Skip to content

[flang-rt][NFC] Split up expensive .cpp files into multiple files - #198111

Merged
jhuber6 merged 2 commits into
llvm:mainfrom
jhuber6:SplitUpRuntime
May 18, 2026
Merged

[flang-rt][NFC] Split up expensive .cpp files into multiple files#198111
jhuber6 merged 2 commits into
llvm:mainfrom
jhuber6:SplitUpRuntime

Conversation

@jhuber6

@jhuber6 jhuber6 commented May 16, 2026

Copy link
Copy Markdown
Contributor

Summary:
This PR simply takes the existing .cpp files for the heaviest
implementations and separates them logically, typically between real,
integer, and complex types. The existing .cpp file is turned into a
.h file and we create new .cpp files that only contain the old
portion that used RTDEF. This allows for far more build system
parallelism, and it also means that static library linking semantics
mean that if the user only uses integer routines the linker will not
include the unused complex / real routines in the final executable.

All around this is a good practice for runtime libraries. Verified that
all _Fortran entrypoint routines are still present, port was strictly
mechanical.

The result of all of this is that I can now build flang-rt in ~10s
with all threads instead of ~50s due to the most expensive files being
split into parallelizable chunks.

@github-actions

github-actions Bot commented May 16, 2026

Copy link
Copy Markdown

🐧 Linux x64 Test Results

  • 313 tests passed

✅ The build succeeded and all tests passed.

@jhuber6
jhuber6 force-pushed the SplitUpRuntime branch 2 times, most recently from 7877805 to d55ce26 Compare May 16, 2026 17:21
@jhuber6
jhuber6 requested a review from kparzysz May 18, 2026 13:43

@Meinersbur Meinersbur left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that a sequential build will take longer, but IMHO that be well worth it. Do you have numbers on user time in addition to real time (I am curious about the template instantiation cost)?

The result of all of this is that I can now build flang-rt in ~10s
with all threads instead of ~50s due to the most expensive files being
split into parallelizable chunks.

This is only meaningful if you also mention how many threads the the system has.

Comment thread flang-rt/lib/runtime/matmul-transpose.cpp
Comment thread flang-rt/lib/runtime/matmul-transpose.h
Summary:
This PR simply takes the existing `.cpp` files for the heaviest
implementations and separates them logically, typically between real,
integer, and complex types. The existing `.cpp` file is turned into a
`.h` file and we create new `.cpp` files that *only* contain the old
portion that used `RTDEF`. This allows for far more build system
parallelism, and it also means that static library linking semantics
mean that if the user only uses integer routines the linker will not
include the unused complex / real routines in the final executable.

All around this is a good practice for runtime libraries. Verified that
all `_Fortran` entrypoint routines are still present, port was strictly
mechanical.

The result of all of this is that I can now build `flang-rt` in ~10s
with all threads instead of ~50s due to the most expensive files being
split into parallelizable chunks.
@jhuber6

jhuber6 commented May 18, 2026

Copy link
Copy Markdown
Contributor Author

Note that a sequential build will take longer, but IMHO that be well worth it. Do you have numbers on user time in addition to real time (I am curious about the template instantiation cost)?

The result of all of this is that I can now build flang-rt in ~10s
with all threads instead of ~50s due to the most expensive files being
split into parallelizable chunks.

This is only meaningful if you also mention how many threads the the system has.

The system I tested this on has 48. Agreed on the value, because the overhead associated with launching the compiler a few dozen more times is negligible next to the single-threaded compilation already taking >4 minutes. This was on my machine with a ninja clean.

> ninja clean && ninja
[96/96] Linking CXX static library lib/clang/23/lib/x86_64-unknown-linux-gnu/libflang_rt.runtime.a
ninja  339.95s user 4.83s system 2125% cpu 16.220 total

@Meinersbur Meinersbur left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Please give others a chance to comment before landing

@vzakhari vzakhari left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@jhuber6

jhuber6 commented May 18, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. For reference, this is before this PR:|

> ninja clean && ninja
[77/77] Linking CXX static library lib/clang/23/lib/x86_64-unknown-linux-gnu/libflang_rt.runtime.a
ninja  277.17s user 3.60s system 518% cpu 54.154 total

@jhuber6
jhuber6 merged commit d6f5793 into llvm:main May 18, 2026
10 checks passed
pedroMVicente pushed a commit to pedroMVicente/llvm-project that referenced this pull request May 19, 2026
…vm#198111)

Summary:
This PR simply takes the existing `.cpp` files for the heaviest
implementations and separates them logically, typically between real,
integer, and complex types. The existing `.cpp` file is turned into a
`.h` file and we create new `.cpp` files that *only* contain the old
portion that used `RTDEF`. This allows for far more build system
parallelism, and it also means that static library linking semantics
mean that if the user only uses integer routines the linker will not
include the unused complex / real routines in the final executable.

All around this is a good practice for runtime libraries. Verified that
all `_Fortran` entrypoint routines are still present, port was strictly
mechanical.

The result of all of this is that I can now build `flang-rt` in ~10s
with all threads instead of ~50s due to the most expensive files being
split into parallelizable chunks.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants