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