• 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/toolchain/toolchain.gni")
10
11# Configuration that enables PGO instrumentation.
12config("pgo_instrumentation_flags") {
13  visibility = [ ":default_pgo_flags" ]
14
15  # Only add flags when chrome_pgo_phase == 1, so that variables we would use
16  # are not required to be defined when we're not actually using PGO.
17  if (chrome_pgo_phase == 1 && is_clang && !is_nacl && is_a_target_toolchain) {
18    cflags = [ "-fprofile-generate" ]
19    if (!is_win) {
20      # Windows directly calls link.exe instead of the compiler driver when
21      # linking, and embeds the path to the profile runtime library as
22      # dependent library into each object file.
23      ldflags = [ "-fprofile-generate" ]
24    }
25  }
26}
27
28# Configuration that enables optimization using profile data.
29config("pgo_optimization_flags") {
30  visibility = [ ":default_pgo_flags" ]
31
32  # Only add flags when chrome_pgo_phase == 2, so that variables we would use
33  # are not required to be defined when we're not actually using PGO.
34  if (chrome_pgo_phase == 2 && is_clang && !is_nacl && is_a_target_toolchain) {
35    _pgo_target = ""
36
37    # There are txt files used by //tools/update_pgo_profiles.py to decide which
38    # profiles to use, adding them as inputs so that analyzer recognizes the
39    # dependencies.
40    inputs = []
41
42    if (is_win) {
43      if (target_cpu == "x64") {
44        _pgo_target = "win64"
45      } else {
46        _pgo_target = "win32"
47      }
48    } else if (is_mac) {
49      if (target_cpu == "arm64") {
50        _pgo_target = "mac-arm"
51      } else {
52        _pgo_target = "mac"
53      }
54    } else if (is_linux) {
55      _pgo_target = "linux"
56    } else if (is_chromeos_lacros) {
57      if (target_cpu == "arm") {
58        _pgo_target = "lacros-arm"
59      } else if (target_cpu == "arm64") {
60        _pgo_target = "lacros-arm64"
61      } else {
62        _pgo_target = "lacros64"
63      }
64    } else if (is_android) {
65      # Temporarily use mac-arm profile until Android native PGO support works.
66      # TODO(crbug.com/1308749): fix this.
67      _pgo_target = "mac-arm"
68    } else if (is_fuchsia) {
69      if (target_cpu == "arm64") {
70        _pgo_target = "mac-arm"
71      } else {
72        _pgo_target = "mac"
73      }
74    }
75
76    if (_pgo_target == "win64") {
77      inputs = [ "//chrome/build/win64.pgo.txt" ]
78    } else if (_pgo_target == "win32") {
79      inputs = [ "//chrome/build/win32.pgo.txt" ]
80    } else if (_pgo_target == "mac-arm") {
81      inputs = [ "//chrome/build/mac-arm.pgo.txt" ]
82    } else if (_pgo_target == "mac") {
83      inputs = [ "//chrome/build/mac.pgo.txt" ]
84    } else if (_pgo_target == "linux") {
85      inputs = [ "//chrome/build/linux.pgo.txt" ]
86    } else if (_pgo_target == "lacros64") {
87      inputs = [ "//chrome/build/lacros64.pgo.txt" ]
88    } else if (_pgo_target == "lacros-arm") {
89      inputs = [ "//chrome/build/lacros-arm.pgo.txt" ]
90    } else if (_pgo_target == "lacros-arm64") {
91      inputs = [ "//chrome/build/lacros-arm64.pgo.txt" ]
92    }
93
94    if (_pgo_target != "" && pgo_data_path == "") {
95      pgo_data_path = exec_script("//tools/update_pgo_profiles.py",
96                                  [
97                                    "--target",
98                                    _pgo_target,
99                                    "get_profile_path",
100                                  ],
101                                  "value")
102    }
103    assert(pgo_data_path != "",
104           "Please set pgo_data_path to point at the profile data")
105    cflags = [
106      "-fprofile-use=" + rebase_path(pgo_data_path, root_build_dir),
107
108      # It's possible to have some profile data legitimately missing,
109      # and at least some profile data always ends up being considered
110      # out of date, so make sure we don't error for those cases.
111      "-Wno-profile-instr-unprofiled",
112      "-Wno-profile-instr-out-of-date",
113
114      # Some hashing conflict results in a lot of warning like this when doing
115      # a PGO build:
116      #   warning: foo.cc: Function control flow change detected (hash mismatch)
117      #   [-Wbackend-plugin]
118      # See https://crbug.com/978401
119      "-Wno-backend-plugin",
120    ]
121  }
122}
123
124# Applies flags necessary when profile-guided optimization is used.
125# Flags are only added if PGO is enabled, so that this config is safe to
126# include by default.
127config("default_pgo_flags") {
128  if (chrome_pgo_phase == 0) {
129    # Nothing. This config should be a no-op when chrome_pgo_phase == 0.
130  } else if (chrome_pgo_phase == 1) {
131    configs = [ ":pgo_instrumentation_flags" ]
132  } else if (chrome_pgo_phase == 2) {
133    configs = [ ":pgo_optimization_flags" ]
134  }
135}
136