Lines Matching +full:clang +full:- +full:pgo
3 # Use of this source code is governed by a BSD-style license that can be
6 """Generates a PGO profile for LLVM.
10 Note that this script has a few (perhaps surprising) side-effects:
39 HOST_TRIPLE = "x86_64-pc-linux-gnu"
44 "x86_64-cros-linux-gnu",
45 "armv7a-cros-linux-gnueabihf",
46 "aarch64-cros-linux-gnu",
49 # Set of all of the cross-* libraries we need.
51 f"cross-{triple}/{package}"
54 for package in ("glibc", "libcxx", "llvm-libunwind", "linux-headers")
58 def ensure_llvm_binpkg_exists() -> bool:
66 pkg = Path(SAVED_LLVM_BINPKG_STAMP.read_text(encoding="utf-8"))
67 # Double-check this, since this package is considered a cache artifact
73 SAVED_LLVM_BINPKG_STAMP.write_text(str(pkg), encoding="utf-8")
79 logging.info("Restoring non-PGO'ed LLVM installation")
80 pkg = Path(SAVED_LLVM_BINPKG_STAMP.read_text(encoding="utf-8"))
83 ), f"Non-PGO'ed binpkg at {pkg} does not exist. Can't restore"
87 def find_missing_cross_libs() -> FrozenSet[str]:
88 """Returns cross-* libraries that need to be installed for workloads."""
90 ["equery", "l", "--format=$cp", "cross-*/*"],
101 return ALL_NEEDED_CROSS_LIBS - has_packages
105 """Ensures that we have cross-* libs for all `IMPORTANT_TRIPLES`."""
108 logging.info("All cross-compiler libraries are already installed")
112 logging.info("Installing cross-compiler libs: %s", missing_packages)
114 ["sudo", "emerge", "-j", "-G"] + missing_packages,
119 """Emerges a sys-devel/llvm with PGO instrumentation enabled."""
121 "llvm_pgo_generate -llvm_pgo_use"
124 # - ThinLTO should have no significant impact on where Clang puts
126 # - In practice, both "PGO generated with ThinLTO enabled," and "PGO
129 " -thinlto"
133 " -wrapper_ccache"
148 "sys-devel/llvm",
153 def build_profiling_env(profile_dir: Path) -> Dict[str, str]:
154 profile_pattern = str(profile_dir / "profile-%m.profraw")
162 """Raises an exception if clang doesn't generate profraw files.
165 clang_bin: the path to a clang binary.
171 [clang_bin, "--help"],
179 f"The clang binary at {clang_bin} generated no profile"
197 encoding="utf-8",
202 """Fetches PGO generation workloads into `target_dir`."""
205 # - absl is reasonably-written and self-contained
206 # - gtest is needed if tests are to be built; in order to have absl do much
232 gs_url="gs://chromeos-localmirror/distfiles/"
233 "abseil-cpp-a86bb8a97e38bc1361289a786410c0eb5824099c.tar.bz2",
239 gs_url="gs://chromeos-mirror/gentoo/distfiles/"
240 "gtest-1b18723e874b256c1e39378c6774a90701d70f7a.tar.gz",
276 clang = triple + "-clang"
283 "-G",
285 "-DCMAKE_BUILD_TYPE=RelWithDebInfo",
286 f"-DCMAKE_C_COMPILER={clang}",
287 f"-DCMAKE_CXX_COMPILER={clang}++",
288 "-DABSL_BUILD_TESTING=ON",
289 "-DABSL_USE_EXTERNAL_GOOGLETEST=ON",
290 "-DABSL_USE_GOOGLETEST_HEAD=OFF",
291 "-DABSL_FIND_GOOGLETEST=OFF",
296 f"-DCMAKE_C_FLAGS={extra_cflags}",
297 f"-DCMAKE_CXX_FLAGS={extra_cflags}",
308 ["ninja", "-v", "all"],
314 def read_exactly_one_dirent(directory: Path) -> Path:
324 def run_workloads(target_dir: Path) -> Path:
351 # Add a run of ThinLTO, so any ThinLTO-specific lld bits get exercised.
352 # Also, since CrOS uses -Os often, exercise that.
353 runner.run(HOST_TRIPLE, extra_cflags="-flto=thin -Os")
357 def convert_profraw_to_pgo_profile(profraw_dir: Path) -> Path:
358 """Creates a PGO profile from the profraw profiles in profraw_dir."""
360 profile_files = list(profraw_dir.glob("profile-*profraw"))
365 "Creating a PGO profile from %d profraw files", len(profile_files)
368 "llvm-profdata",
370 "--instr",
371 f"--output={output}",
389 "--output",
392 help="Where to put the PGO profile",
395 "--use-old-binpkg",
399 restore that installation later in the build. Passing --use-old-binpkg
417 previous run, please pass --use-old-binpkg (so the old LLVM
424 logging.info("Ensuring `cross-` libraries are installed")
433 # (e.g., a PGO'ed one ;) ). Ensure we always start with that binpkg as
438 logging.info("Building PGO instrumented LLVM")
444 triple + "-clang", tempdir
455 # If our current LLVM's llvm-profdata is used to interpret the profraw
457 # 1. The profile generated will be for our new version of clang, and
471 logging.info("Removing now-obsolete tempdir")
473 logging.info("PGO profile is available at %s.", output)