1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
build / config / compiler / pgo / BUILD.gn [blame]
# Copyright 2016 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//build/config/clang/clang.gni")
import("//build/config/compiler/compiler.gni")
import("//build/config/compiler/pgo/pgo.gni")
import("//build/config/features.gni")
import("//build/toolchain/toolchain.gni")
# Configuration that enables PGO instrumentation.
config("pgo_instrumentation_flags") {
visibility = [ ":default_pgo_flags" ]
# Only add flags when chrome_pgo_phase == 1, so that variables we would use
# are not required to be defined when we're not actually using PGO.
if (chrome_pgo_phase == 1 && is_clang && !is_nacl && is_a_target_toolchain) {
cflags = [ "-fprofile-generate" ]
if (temporal_pgo_profile) {
cflags += [
"-mllvm",
"-pgo-temporal-instrumentation",
]
}
if (!is_win) {
# Windows directly calls link.exe instead of the compiler driver when
# linking, and embeds the path to the profile runtime library as
# dependent library into each object file.
ldflags = [ "-fprofile-generate" ]
}
}
}
# Configuration that enables optimization using profile data.
config("pgo_optimization_flags") {
visibility = [ ":default_pgo_flags" ]
# Only add flags when chrome_pgo_phase == 2, so that variables we would use
# are not required to be defined when we're not actually using PGO.
if (chrome_pgo_phase == 2 && is_clang && !is_nacl && is_a_target_toolchain) {
_pgo_target = ""
# There are txt files used by //tools/update_pgo_profiles.py to decide which
# profiles to use, adding them as inputs so that analyzer recognizes the
# dependencies.
inputs = []
if (is_win) {
if (target_cpu == "arm64") {
_pgo_target = "win-arm64"
} else if (target_cpu == "x64") {
_pgo_target = "win64"
} else {
_pgo_target = "win32"
}
} else if (is_mac) {
if (target_cpu == "arm64") {
_pgo_target = "mac-arm"
} else {
_pgo_target = "mac"
}
} else if (is_linux) {
_pgo_target = "linux"
} else if (is_android) {
# Use |current_cpu| and not |target_cpu|; for Android we may built both.
if (current_cpu == "arm64") {
_pgo_target = "android-arm64"
} else {
_pgo_target = "android-arm32"
}
} else if (is_fuchsia) {
if (target_cpu == "arm64") {
_pgo_target = "mac-arm"
} else {
_pgo_target = "mac"
}
} else if (is_ios && use_blink) {
if (target_cpu == "arm64") {
_pgo_target = "mac-arm"
} else {
_pgo_target = "mac"
}
}
if (_pgo_target == "win-arm64") {
inputs = [ "//chrome/build/win-arm64.pgo.txt" ]
} else if (_pgo_target == "win64") {
inputs = [ "//chrome/build/win64.pgo.txt" ]
} else if (_pgo_target == "win32") {
inputs = [ "//chrome/build/win32.pgo.txt" ]
} else if (_pgo_target == "mac-arm") {
inputs = [ "//chrome/build/mac-arm.pgo.txt" ]
} else if (_pgo_target == "mac") {
inputs = [ "//chrome/build/mac.pgo.txt" ]
} else if (_pgo_target == "linux") {
inputs = [ "//chrome/build/linux.pgo.txt" ]
} else if (_pgo_target == "android-arm32") {
inputs = [ "//chrome/build/android-arm32.pgo.txt" ]
} else if (_pgo_target == "android-arm64") {
inputs = [ "//chrome/build/android-arm64.pgo.txt" ]
}
if (_pgo_target != "" && pgo_data_path == "") {
pgo_data_path = exec_script("//tools/update_pgo_profiles.py",
[
"--target",
_pgo_target,
"get_profile_path",
],
"value")
}
assert(pgo_data_path != "",
"Please set pgo_data_path to point at the profile data")
cflags = [
"-fprofile-use=" + rebase_path(pgo_data_path, root_build_dir),
# It's possible to have some profile data legitimately missing,
# and at least some profile data always ends up being considered
# out of date, so make sure we don't error for those cases.
"-Wno-profile-instr-unprofiled",
"-Wno-profile-instr-out-of-date",
# Some hashing conflict results in a lot of warning like this when doing
# a PGO build:
# warning: foo.cc: Function control flow change detected (hash mismatch)
# [-Wbackend-plugin]
# See https://crbug.com/978401
"-Wno-backend-plugin",
]
# TODO(crbug.com/383537825): Try enabling on all platforms.
if (is_android) {
cflags += [
"-mllvm",
"-pgo-cold-func-opt=minsize",
]
}
# Enable basic block layout based on the extended TSP problem. This aims to
# improve icache utilization and reduce the binary size.
if (use_thin_lto) {
if (is_win) {
ldflags = [ "-mllvm:-enable-ext-tsp-block-placement=1" ]
} else {
ldflags = [ "-Wl,-mllvm,-enable-ext-tsp-block-placement=1" ]
}
} else {
cflags += [
"-mllvm",
"-enable-ext-tsp-block-placement=1",
]
}
}
}
# Applies flags necessary when profile-guided optimization is used.
# Flags are only added if PGO is enabled, so that this config is safe to
# include by default.
config("default_pgo_flags") {
if (chrome_pgo_phase == 0) {
# Nothing. This config should be a no-op when chrome_pgo_phase == 0.
} else if (chrome_pgo_phase == 1) {
configs = [ ":pgo_instrumentation_flags" ]
} else if (chrome_pgo_phase == 2) {
configs = [ ":pgo_optimization_flags" ]
}
}