This is an archive of the discontinued LLVM Phabricator instance.

Add a new flavor "BBLabels" to LLVM_BUILD_INSTRUMENTED
AcceptedPublic

Authored by shenhan on May 11 2022, 3:21 PM.

Details

Reviewers
tmsriram
hans
Summary

This CL adds "BBLabels" support for LLVM_BUILD_INSTRUMENTED.

"BBLabels" adds -fbasic-block-sections=labels to C/CXX flags as well as LD flags when doing ThinLTO. With this option, CMAKE builds binaries with auxiliary basic block meta data that later guide propeller[1] profile generation.

With this patch (and its to-be-uploaded child patch that adds support for passing propeller profiles using LLVM_PROFDATA_FILE), it enables people to build propeller optimized llvm tools in a formalized way.

Here is the proposed workflow to build a propeller optimized clang binary (similar to PGO build).

  1. Build instrumented clang binary:
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLVM_BUILD_INSTRUMENTED=BBLabels -DLLVM_ENABLE_PROJECTS="clang" llvm-project/llvm
ninja build
  1. Using the above built binary in day-to-day routine and collect perf.data file and then convert it to propeller profiles.
  2. Build the optimized clang binary:
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLVM_PROPELLER_PROFILES=<profile_name> -DLLVM_ENABLE_PROJECTS="clang" llvm-project/llvm

The experiment data show propeller optimized clang has a 5% compiler time improvement over PGO build.

[1]. Propeller, submitted in 2021.

Diff Detail

Event Timeline

shenhan created this revision.May 11 2022, 3:21 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 11 2022, 3:21 PM
Herald added a subscriber: mgorny. · View Herald Transcript
shenhan requested review of this revision.May 11 2022, 3:21 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 11 2022, 3:21 PM

Here is the proposed workflow to build a propeller optimized clang binary (similar to PGO build).

  1. Build instrumented clang binary:

cmake -G Ninja ... -DLLVM_BUILD_INSTRUMENTED=BBLabels ... llvm-project/llvm
ninja build

  1. Using the above built binary in day-to-day routine and collect perf.data file and then convert it to propeller profiles.
  1. Build the optimized clang binary:

cmake -G Ninja ... -DLLVM_PROPELLER_PROFILES=<profile> ... llvm-project/llvm

The experiment data show propeller optimized clang has a 5% compiler time improvement over PGO build.

Here is the proposed workflow to build a propeller optimized clang binary (similar to PGO build).

  1. Build instrumented clang binary:

cmake -G Ninja ... -DLLVM_BUILD_INSTRUMENTED=BBLabels ... llvm-project/llvm
ninja build

  1. Using the above built binary in day-to-day routine and collect perf.data file and then convert it to propeller profiles.
  1. Build the optimized clang binary:

cmake -G Ninja ... -DLLVM_PROPELLER_PROFILES=<profile> ... llvm-project/llvm

The experiment data show propeller optimized clang has a 5% compiler time improvement over PGO build.

Thanks! Please move this to the description.

llvm/cmake/modules/HandleLLVMOptions.cmake
981

Suggestion: Maybe say "Use BBLabels for Propeller instrumentation via basic block labels"

shenhan edited the summary of this revision. (Show Details)May 13 2022, 10:03 AM

Here is the proposed workflow to build a propeller optimized clang binary (similar to PGO build).

  1. Build instrumented clang binary:

cmake -G Ninja ... -DLLVM_BUILD_INSTRUMENTED=BBLabels ... llvm-project/llvm
ninja build

  1. Using the above built binary in day-to-day routine and collect perf.data file and then convert it to propeller profiles.
  1. Build the optimized clang binary:

cmake -G Ninja ... -DLLVM_PROPELLER_PROFILES=<profile> ... llvm-project/llvm

The experiment data show propeller optimized clang has a 5% compiler time improvement over PGO build.

Thanks! Please move this to the description.

Done.

hans added a comment.May 17 2022, 2:26 AM

Nice!

Please update llvm/docs/CMake.rst to document the different options of LLVM_BUILD_INSTRUMENTED.

Thanks for including the workflow for building a propeller-optimized Clang. Perhaps this should be added to llvm/docs/HowToBuildWithPGO.rst? Or could it be added to Propeller's documentation (where is that?). Also, could the workflow include to how apply this on top of ThinLTO and PGO for peak performance?

tmsriram accepted this revision.May 23 2022, 10:59 AM

This LGTM, please address hans' comments.

This revision is now accepted and ready to land.May 23 2022, 10:59 AM