Index: build/config/compiler/pgo/BUILD.gn |
diff --git a/build/config/compiler/pgo/BUILD.gn b/build/config/compiler/pgo/BUILD.gn |
new file mode 100644 |
index 0000000000000000000000000000000000000000..edd68c7b7406ea28afd1b8f5ae5e22ff5f9fd4b6 |
--- /dev/null |
+++ b/build/config/compiler/pgo/BUILD.gn |
@@ -0,0 +1,96 @@ |
+# Copyright 2016 The Chromium Authors. All rights reserved. |
+# 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") |
+ |
+# Applies linker 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_ldflags") { |
Sébastien Marchand
2016/11/24 15:57:07
If we stick with this approach I'd prefer to keep
|
+ visibility = [ ":default_pgo_flags" ] |
+ ldflags = [] |
+ |
+ if (is_clang) { |
+ if (chrome_pgo_phase == 1) { |
+ if (is_win) { |
+ # Normally, we pass -fprofile-instr-generate to the compiler and it |
+ # automatically passes the right flags to the linker. |
+ # However, on Windows, we call the linker directly, without going |
+ # through the compiler driver. This means we need to pass the right |
+ # flags ourselves. |
+ _clang_rt_base_path = |
+ "$clang_base_path/lib/clang/$clang_version/lib/windows" |
+ if (target_cpu == "x86") { |
+ _clang_rt_suffix = "-i386.lib" |
+ } else if (target_cpu == "x64") { |
+ _clang_rt_suffix = "-x86_64.lib" |
+ } |
+ assert(_clang_rt_suffix != "", "target CPU $target_cpu not supported") |
+ ldflags += [ "$_clang_rt_base_path/clang_rt.profile$_clang_rt_suffix" ] |
+ } else { |
+ ldflags += [ "-fprofile-instr-generate" ] |
+ } |
+ } |
+ } else if (is_win) { |
+ if (chrome_pgo_phase == 1) { |
+ ldflags += [ |
+ # In MSVC, we must use /LTCG when using PGO. |
+ "/LTCG", |
+ |
+ # Make sure that enough memory gets allocated for the PGO profiling |
+ # buffers and also cap this memory. Usually a PGI instrumented build |
+ # of chrome_child.dll requires ~55MB of memory for storing its counter |
+ # etc, normally the linker should automatically choose an appropriate |
+ # amount of memory but it doesn't always do a good estimate and |
+ # sometime allocates too little or too much (and so the instrumented |
+ # image fails to start). Making sure that the buffer has a size in the |
+ # [128 MB, 512 MB] range should prevent this from happening. |
+ "/GENPROFILE:MEMMIN=134217728", |
+ "/GENPROFILE:MEMMAX=536870912", |
+ "/PogoSafeMode", |
+ ] |
+ } else if (chrome_pgo_phase == 2) { |
+ ldflags += [ |
+ # In MSVC, we must use /LTCG when using PGO. |
+ "/LTCG", |
+ "/USEPROFILE", |
+ ] |
+ } |
+ } |
+} |
+ |
+# Applies compiler 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("pgo_flags") { |
+ visibility = [ ":default_pgo_flags" ] |
+ cflags = [] |
+ |
+ if (is_clang && !is_nacl) { |
+ if (chrome_pgo_phase == 1) { |
+ cflags += [ "-fprofile-instr-generate" ] |
+ } else if (chrome_pgo_phase == 2) { |
+ assert(pgo_data_path != "", |
+ "Please set pgo_data_path to point at the profile data") |
+ cflags += [ |
+ "-fprofile-instr-use=$pgo_data_path", |
+ |
+ # It's possible to have some profile data legitimately missing, and at least some |
Sébastien Marchand
2016/11/24 15:57:07
> 80 characters.
|
+ # 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-error=profile-instr-out-of-date", |
+ ] |
+ } |
+ } |
+} |
+ |
+config("default_pgo_flags") { |
+ configs = [ |
+ ":default_pgo_ldflags", |
+ ":pgo_flags", |
+ ] |
+} |