OLD | NEW |
(Empty) | |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import("//build/config/clang/clang.gni") |
| 6 import("//build/config/compiler/compiler.gni") |
| 7 import("//build/config/compiler/pgo/pgo.gni") |
| 8 |
| 9 # Configuration that enables PGO instrumentation. |
| 10 config("pgo_instrumentation_flags") { |
| 11 visibility = [ ":default_pgo_flags" ] |
| 12 cflags = [] |
| 13 ldflags = [] |
| 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) { |
| 18 if (is_clang) { |
| 19 cflags = [ "-fprofile-instr-generate" ] |
| 20 if (is_win) { |
| 21 # Normally, we pass -fprofile-instr-generate to the compiler and it |
| 22 # automatically passes the right flags to the linker. |
| 23 # However, on Windows, we call the linker directly, without going |
| 24 # through the compiler driver. This means we need to pass the right |
| 25 # flags ourselves. |
| 26 _clang_rt_base_path = |
| 27 "$clang_base_path/lib/clang/$clang_version/lib/windows" |
| 28 if (target_cpu == "x86") { |
| 29 _clang_rt_suffix = "-i386.lib" |
| 30 } else if (target_cpu == "x64") { |
| 31 _clang_rt_suffix = "-x86_64.lib" |
| 32 } |
| 33 assert(_clang_rt_suffix != "", "target CPU $target_cpu not supported") |
| 34 ldflags += [ "$_clang_rt_base_path/clang_rt.profile$_clang_rt_suffix" ] |
| 35 } else { |
| 36 ldflags += [ "-fprofile-instr-generate" ] |
| 37 } |
| 38 } else if (is_win) { |
| 39 ldflags = [ |
| 40 # In MSVC, we must use /LTCG when using PGO. |
| 41 "/LTCG", |
| 42 |
| 43 # Make sure that enough memory gets allocated for the PGO profiling |
| 44 # buffers and also cap this memory. Usually a PGI instrumented build |
| 45 # of chrome_child.dll requires ~55MB of memory for storing its counter |
| 46 # etc, normally the linker should automatically choose an appropriate |
| 47 # amount of memory but it doesn't always do a good estimate and |
| 48 # sometime allocates too little or too much (and so the instrumented |
| 49 # image fails to start). Making sure that the buffer has a size in the |
| 50 # [128 MB, 512 MB] range should prevent this from happening. |
| 51 "/GENPROFILE:MEMMIN=134217728", |
| 52 "/GENPROFILE:MEMMAX=536870912", |
| 53 "/PogoSafeMode", |
| 54 ] |
| 55 } |
| 56 } |
| 57 } |
| 58 |
| 59 # Configuration that enables optimization using profile data. |
| 60 config("pgo_optimization_flags") { |
| 61 visibility = [ ":default_pgo_flags" ] |
| 62 cflags = [] |
| 63 ldflags = [] |
| 64 |
| 65 # Only add flags when chrome_pgo_phase == 2, so that variables we would use |
| 66 # are not required to be defined when we're not actually using PGO. |
| 67 if (chrome_pgo_phase == 2) { |
| 68 if (is_clang) { |
| 69 assert(pgo_data_path != "", |
| 70 "Please set pgo_data_path to point at the profile data") |
| 71 cflags += [ |
| 72 "-fprofile-instr-use=$pgo_data_path", |
| 73 |
| 74 # It's possible to have some profile data legitimately missing, |
| 75 # and at least some profile data always ends up being considered |
| 76 # out of date, so make sure we don't error for those cases. |
| 77 "-Wno-profile-instr-unprofiled", |
| 78 "-Wno-error=profile-instr-out-of-date", |
| 79 ] |
| 80 } else if (is_win) { |
| 81 ldflags += [ |
| 82 # In MSVC, we must use /LTCG when using PGO. |
| 83 "/LTCG", |
| 84 "/USEPROFILE", |
| 85 ] |
| 86 } |
| 87 } |
| 88 } |
| 89 |
| 90 # Applies flags necessary when profile-guided optimization is used. |
| 91 # Flags are only added if PGO is enabled, so that this config is safe to |
| 92 # include by default. |
| 93 config("default_pgo_flags") { |
| 94 if (chrome_pgo_phase == 0) { |
| 95 # Nothing. This config should be a no-op when chrome_pgo_phase == 0. |
| 96 } else if (chrome_pgo_phase == 1) { |
| 97 configs = [ ":pgo_instrumentation_flags" ] |
| 98 } else if (chrome_pgo_phase == 2) { |
| 99 configs = [ ":pgo_optimization_flags" ] |
| 100 } |
| 101 } |
OLD | NEW |