• 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 == "arm64") {
45        _pgo_target = "win-arm64"
46      } else if (target_cpu == "x64") {
47        _pgo_target = "win64"
48      } else {
49        _pgo_target = "win32"
50      }
51    } else if (is_mac) {
52      if (target_cpu == "arm64") {
53        _pgo_target = "mac-arm"
54      } else {
55        _pgo_target = "mac"
56      }
57    } else if (is_linux) {
58      _pgo_target = "linux"
59    } else if (is_chromeos_lacros) {
60      if (target_cpu == "arm") {
61        _pgo_target = "lacros-arm"
62      } else if (target_cpu == "arm64") {
63        _pgo_target = "lacros-arm64"
64      } else {
65        _pgo_target = "lacros64"
66      }
67    } else if (is_android) {
68      # Use |current_cpu| and not |target_cpu|; for Android we may built both.
69      if (current_cpu == "arm64") {
70        _pgo_target = "android-arm64"
71      } else {
72        _pgo_target = "android-arm32"
73      }
74    } else if (is_fuchsia) {
75      if (target_cpu == "arm64") {
76        _pgo_target = "mac-arm"
77      } else {
78        _pgo_target = "mac"
79      }
80    } else if (is_ios && use_blink) {
81      if (target_cpu == "arm64") {
82        _pgo_target = "mac-arm"
83      } else {
84        _pgo_target = "mac"
85      }
86    }
87
88    if (_pgo_target == "win-arm64") {
89      inputs = [ "//chrome/build/win-arm64.pgo.txt" ]
90    } else if (_pgo_target == "win64") {
91      inputs = [ "//chrome/build/win64.pgo.txt" ]
92    } else if (_pgo_target == "win32") {
93      inputs = [ "//chrome/build/win32.pgo.txt" ]
94    } else if (_pgo_target == "mac-arm") {
95      inputs = [ "//chrome/build/mac-arm.pgo.txt" ]
96    } else if (_pgo_target == "mac") {
97      inputs = [ "//chrome/build/mac.pgo.txt" ]
98    } else if (_pgo_target == "linux") {
99      inputs = [ "//chrome/build/linux.pgo.txt" ]
100    } else if (_pgo_target == "lacros64") {
101      inputs = [ "//chrome/build/lacros64.pgo.txt" ]
102    } else if (_pgo_target == "lacros-arm") {
103      inputs = [ "//chrome/build/lacros-arm.pgo.txt" ]
104    } else if (_pgo_target == "lacros-arm64") {
105      inputs = [ "//chrome/build/lacros-arm64.pgo.txt" ]
106    } else if (_pgo_target == "android-arm32") {
107      inputs = [ "//chrome/build/android-arm32.pgo.txt" ]
108    } else if (_pgo_target == "android-arm64") {
109      inputs = [ "//chrome/build/android-arm64.pgo.txt" ]
110    }
111
112    if (_pgo_target != "" && pgo_data_path == "") {
113      pgo_data_path = exec_script("//tools/update_pgo_profiles.py",
114                                  [
115                                    "--target",
116                                    _pgo_target,
117                                    "get_profile_path",
118                                  ],
119                                  "value")
120    }
121    assert(pgo_data_path != "",
122           "Please set pgo_data_path to point at the profile data")
123    cflags = [
124      "-fprofile-use=" + rebase_path(pgo_data_path, root_build_dir),
125
126      # It's possible to have some profile data legitimately missing,
127      # and at least some profile data always ends up being considered
128      # out of date, so make sure we don't error for those cases.
129      "-Wno-profile-instr-unprofiled",
130      "-Wno-profile-instr-out-of-date",
131
132      # Some hashing conflict results in a lot of warning like this when doing
133      # a PGO build:
134      #   warning: foo.cc: Function control flow change detected (hash mismatch)
135      #   [-Wbackend-plugin]
136      # See https://crbug.com/978401
137      "-Wno-backend-plugin",
138    ]
139
140    # Enable basic block layout based on the extended TSP problem. This aims to
141    # improve icache utilization and reduce the binary size.
142    if (use_thin_lto) {
143      if (is_win) {
144        ldflags = [ "-mllvm:-enable-ext-tsp-block-placement=1" ]
145      } else {
146        ldflags = [ "-Wl,-mllvm,-enable-ext-tsp-block-placement=1" ]
147      }
148    } else {
149      cflags += [
150        "-mllvm",
151        "-enable-ext-tsp-block-placement=1",
152      ]
153    }
154  }
155}
156
157# Applies flags necessary when profile-guided optimization is used.
158# Flags are only added if PGO is enabled, so that this config is safe to
159# include by default.
160config("default_pgo_flags") {
161  if (chrome_pgo_phase == 0) {
162    # Nothing. This config should be a no-op when chrome_pgo_phase == 0.
163  } else if (chrome_pgo_phase == 1) {
164    configs = [ ":pgo_instrumentation_flags" ]
165  } else if (chrome_pgo_phase == 2) {
166    configs = [ ":pgo_optimization_flags" ]
167  }
168}
169