Skip to content

Add support for PGO to rust, fix clang pgo - #13396

Open
dcbaker wants to merge 13 commits into
mesonbuild:masterfrom
dcbaker:submit/clang-rustc-pgo
Open

Add support for PGO to rust, fix clang pgo#13396
dcbaker wants to merge 13 commits into
mesonbuild:masterfrom
dcbaker:submit/clang-rustc-pgo

Conversation

@dcbaker

@dcbaker dcbaker commented Jul 9, 2024

Copy link
Copy Markdown
Member

Clang (and other LLVM compilers) handle PGO slightly differently than GCC based compilers do. The following is a short list of differences:

  1. LLVM compilers generate files that must be merged with llvm-profdata, GCC based compilers do not
  2. LLVM compilers do not generate profile data for static libraries, but GCC based compilers do
  3. LLVM compilers want an explicit path to put their profile data in, while GCC compilers put the data next to the .o files

Fixes #5251
Fixes #13371

Based on #13377

@dcbaker
dcbaker requested a review from jpakkane as a code owner July 9, 2024 19:11
}

class ClangCompiler(GnuLikeCompiler):
class ClangCompiler(LLVMCompilerMixin, GnuLikeCompiler):

Check warning

Code scanning / CodeQL

Conflicting attributes in base classes

Base classes have conflicting values for attribute 'should_pgo_target': [Function should_pgo_target](1) and [Function should_pgo_target](2).
}

class RustCompiler(Compiler):
class RustCompiler(LLVMCompilerMixin, Compiler):

Check warning

Code scanning / CodeQL

Conflicting attributes in base classes

Base classes have conflicting values for attribute 'should_pgo_target': [Function should_pgo_target](1) and [Function should_pgo_target](2).
@dcbaker
dcbaker force-pushed the submit/clang-rustc-pgo branch 4 times, most recently from bfeb9bb to 8d8d8b8 Compare July 9, 2024 20:45
Compiles C/C++, ObjC/ObjC++, Fortran, and D sources
"""Compiles C/C++, ObjC/ObjC++, Fortran, and D sources.

:param target: The target which the source belongs to

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.

Be consistent about starting the description with a capital letter or not.

Comment thread mesonbuild/compilers/compilers.py Outdated


def get_base_compile_args(options: 'KeyedOptionDictType', compiler: 'Compiler', env: 'Environment') -> T.List[str]:
def get_base_compile_args(options: 'KeyedOptionDictType', compiler: 'Compiler', env: 'Environment', privatedir: str) -> T.List[str]:

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.

I would name the parameter private_dir to match the target function name.

Comment thread mesonbuild/compilers/mixins/gnu.py Outdated
Comment thread mesonbuild/compilers/compilers.py
@tristan957

Copy link
Copy Markdown
Member

Is it possible to add any tests for PGO?

dcbaker added 12 commits July 10, 2024 11:11
header dependency are usually order-only, but this actually provides a
full dependency.
Due to the confusing naming of the parameters, a number of arguments
were incorrectly added as full dependencies when they should be order
only.
This is important for Rust, which needs to have a path to write
temporary files to, and we want to put that in the target's private
directory.
Rustc needs a directory to read and write files from, and clang can make
use of this as well (which may be useful for profiling mixed rustc and
clang targets).
This helps to reduce code duplication around the code base.
GCC and Clang are actually somewhat different than each other on PGO.
GCC, expects a single directory where data will be written, and will
read and write itself. Clang expects a directory where it will write
data as the binary runs, and then expects an external tool
(llvm-profdata) to merge the resulting instrumentation files before
clang uses the profile data.
LLVM based compilers do not generate profile data for static libraries,
but GCC based compilers do.
Rustc works like clang, so we just need to plug into that path.
@dcbaker
dcbaker force-pushed the submit/clang-rustc-pgo branch from 8d8d8b8 to 069db29 Compare July 10, 2024 18:16
Since we don't seem to have any tests for this feature
@dcbaker

dcbaker commented Jul 10, 2024

Copy link
Copy Markdown
Member Author

changes since the last version:

  • made the argument name consistently pgo_dir, since this directory is a subdirectory of the private dir
  • added a few tests for PGO, including mixing C and Rust

@dcbaker dcbaker added this to the 1.13 milestone Jul 7, 2026
@bonzini bonzini added the needs-rebase For PRs that mostly have been reviewed, but have conflicts label Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-rebase For PRs that mostly have been reviewed, but have conflicts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feature req. PGO support for Rust Add support for LLVM/clang when using b_pgo

4 participants