Who is this for?

This is an introductory topic for developers who compile C or C++ applications on AArch64 Linux and want to use link-time optimization (LTO) with profile-guided optimization (PGO).

What will you learn?

Upon completion of this Learning Path, you will be able to:

  • Understand how LTO and PGO guide LLVM optimizations.
  • Build Full-LTO and Thin-LTO binaries with Clang on AArch64.
  • Generate and inspect sample-based and instrumentation-based profiles.
  • Use each profile type to build and run an optimized example application.

Prerequisites

Before starting, you will need the following:

  • An AArch64 Linux system with LLVM installed. You need Clang, LLD, llvm-bcanalyzer, llvm-profdata, llvm-profgen, and llvm-readelf in your PATH. For setup instructions, see the LLVM toolchain for Linux on Arm install guide.
  • For the sample PGO workflow based on Branch Record Buffer Extension (BRBE), a processor that implements the BRBE, Linux kernel 6.17 or later, and Linux perf. Other sample-based PGO workflows can use sources such as Statistical Profiling Extension (SPE) or Performance Monitoring Unit (PMU) events and have different requirements.

Summary

AI-assisted

This summary was drafted with an approved AI-assisted workflow and reviewed by Arm contributors before publication. Human technical review remains part of the process so the final page reflects engineering rigor, accuracy, and Arm editorial standards.

Close
?
You’ll combine LLVM LTO with PGO to guide Clang optimization of an AArch64 C++ application on Linux. First, you’ll prepare the toolchain and example. Then, you’ll build Full-LTO and Thin-LTO variants and collect sample profiles with perf. You’ll create frontend, IR-level, and context-sensitive profiles, merge and inspect profiles with LLVM tools, and apply each profile in optimized LTO builds.

Frequently asked questions

AI-assisted

These FAQs were drafted with an approved AI-assisted workflow and reviewed by Arm contributors before publication. Human technical review remains part of the process so the final page reflects engineering rigor, accuracy, and Arm editorial standards.

Close
?
What should I have in my workspace after the setup step?
You should have the bsort.cpp source file and two directories: out for objects and binaries, and prof for raw and converted profile data. Keep these locations separate so you can distinguish build artifacts from profiling data.
Which LTO mode should I use first: Full-LTO or Thin-LTO?
Try both. Each mode emits LLVM bitcode during compilation but performs link-time optimization differently. Use the documented commands to build each mode and compare the results.
How do I know sample-based PGO data collection worked with `perf`?
Confirm that perf produced recording data that llvm-profgen can convert into an LLVM sample profile. If collection fails, check that your processor implements BRBE and that perf is available. You can use other sample sources, such as SPE or PMU events, with their own requirements.
Where does FE-PGO write its profile data and how is it used?
FE-PGO writes counters to a path you provide with -fprofile-instr-generate, typically under the prof directory. After running the instrumented binary, use llvm-profdata to convert and inspect the profile data. Then, use that profile in your next optimized Clang build.
How can I verify that an optimized build actually used LTO or a profile?
Check that your build invoked the appropriate LTO mode and included the profile-use option for your profile type, such as -fprofile-sample-use for S-PGO. You can also inspect objects or binaries with LLVM tools to review emitted bitcode or profile-driven metadata.
Next