Commit b822aab9 authored by George Burgess IV's avatar George Burgess IV Committed by Commit Bot

Add basic clang-based AFDO support.

This patch adds support for clang-based AFDO to Chromium.

AFDO stands for Automatic Feedback Directed Optimization. In short, it
allows you to use the postprocessed output of a special `perf` command
to inform the compiler of hot/cold code, among other things.

This allows users to easily specify a profile to use, and allows for
platforms to specify default profiles. It turns none of this on on its
own.

At the moment, this is very sharp and pointy, since the sample profile
isn't a dependency for anything. Ideally, anything built with AFDO
should depend on the profile. I have a CL to make this easily possible
(CL:827560), but think this is useful enough (given care) to get in now.

(and with clang_use_default_sample_profile set to true). We built
with profiles and failed to `gn gen`, respectively. Patch seemed to be
a nop running on an otherwise "regular" build.

Bug: 794750
Test: Ran the build with and without clang_default_afdo_profile defined
Change-Id: I7b2730d52875f108681232f4d8ce7e82e7570a74
Reviewed-on: https://chromium-review.googlesource.com/828277Reviewed-by: default avataragrieve <agrieve@chromium.org>
Commit-Queue: George Burgess <gbiv@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524620}
parent dc171dd3
...@@ -101,6 +101,24 @@ declare_args() { ...@@ -101,6 +101,24 @@ declare_args() {
# Strip the debug info of symbols file in lib.unstripped to reduce size. # Strip the debug info of symbols file in lib.unstripped to reduce size.
strip_debug_info = false strip_debug_info = false
# Path to an AFDO profile to use while building with clang, if any. Empty
# implies none.
#
# Please note that you need to be very careful about changing your profile at
# the moment. See the `BUG(gbiv)` comment later in this file.
clang_sample_profile_path = ""
# Some configurations have default sample profiles. If this is true and
# clang_sample_profile_path is empty, we'll fall back to the default.
clang_use_default_sample_profile =
is_official_build && defined(clang_default_afdo_profile)
# Whether to assert to the compiler that the AFDO profiles are accurate.
# True will cause the compiler to optimize uncovered functions for size
# (despite passing -O2 or -O3), which reduces binary size by quite a bit,
# potentially at the cost of some performance.
clang_sample_profile_is_accurate = true
} }
declare_args() { declare_args() {
...@@ -197,6 +215,34 @@ config("compiler") { ...@@ -197,6 +215,34 @@ config("compiler") {
# -------------------------------- # --------------------------------
cflags += [ "-fno-strict-aliasing" ] # See http://crbug.com/32204 cflags += [ "-fno-strict-aliasing" ] # See http://crbug.com/32204
# AFDO on clang. Clang doesn't seem to suffer from the bug that caused GCC's
# AFDO to be split into its own config, so this isn't part of that config.
#
# Since we only profile the browser, skip it if we're building host tools.
#
# XXX(gbiv): There is currently *no* dependency between the profile we use
# and the compilations/links that we do. So, if the profile gets updated,
# the user has to manually clean build artifacts. CL:827560 should fix this
# by allowing us to specify `inputs` here, but until then, the only "good"
# workaround is changing your profile name each time you update the profile.
if (is_clang && current_toolchain == default_toolchain) {
_sample_path = ""
if (clang_sample_profile_path != "") {
_sample_path = clang_sample_profile_path
} else if (clang_use_default_sample_profile) {
assert(defined(clang_default_afdo_profile),
"This platform has no default sample profiles")
_sample_path = clang_default_afdo_profile
}
if (_sample_path != "") {
cflags += [ "-fprofile-sample-use=${_sample_path}" ]
if (clang_sample_profile_is_accurate) {
cflags += [ "-fprofile-sample-accurate" ]
}
}
}
# Stack protection. # Stack protection.
if (is_mac) { if (is_mac) {
# The strong variant of the stack protector significantly increases # The strong variant of the stack protector significantly increases
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment