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