Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 1 | // Copyright 2017 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package cc |
| 16 | |
| 17 | import ( |
| 18 | "fmt" |
Pirama Arumuga Nainar | 8aed42c | 2018-03-08 22:56:37 -0800 | [diff] [blame] | 19 | "path/filepath" |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 20 | "strings" |
| 21 | |
Yi Kong | ca610d2 | 2018-04-24 10:42:02 -0700 | [diff] [blame] | 22 | "github.com/google/blueprint/proptools" |
| 23 | |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 24 | "android/soong/android" |
| 25 | ) |
| 26 | |
| 27 | var ( |
| 28 | // Add flags to ignore warnings that profiles are old or missing for |
Pirama Arumuga Nainar | 3a25405 | 2019-06-14 09:54:23 -0700 | [diff] [blame] | 29 | // some functions. |
Yi Kong | 69c1ed9 | 2019-03-21 14:28:13 -0700 | [diff] [blame] | 30 | profileUseOtherFlags = []string{ |
| 31 | "-Wno-backend-plugin", |
Yi Kong | 69c1ed9 | 2019-03-21 14:28:13 -0700 | [diff] [blame] | 32 | } |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 33 | |
Pirama Arumuga Nainar | 4954080 | 2018-01-29 23:11:42 -0800 | [diff] [blame] | 34 | globalPgoProfileProjects = []string{ |
Yi Kong | 88b94ea | 2022-04-07 23:54:28 +0800 | [diff] [blame] | 35 | "toolchain/pgo-profiles/pgo", |
| 36 | "vendor/google_data/pgo_profile/pgo", |
Pirama Arumuga Nainar | 64946fe | 2018-01-17 14:00:53 -0800 | [diff] [blame] | 37 | } |
| 38 | ) |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 39 | |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 40 | var pgoProfileProjectsConfigKey = android.NewOnceKey("PgoProfileProjects") |
| 41 | |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 42 | const profileInstrumentFlag = "-fprofile-generate=/data/local/tmp" |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 43 | const profileUseInstrumentFormat = "-fprofile-use=%s" |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 44 | |
Pirama Arumuga Nainar | 4954080 | 2018-01-29 23:11:42 -0800 | [diff] [blame] | 45 | func getPgoProfileProjects(config android.DeviceConfig) []string { |
| 46 | return config.OnceStringSlice(pgoProfileProjectsConfigKey, func() []string { |
| 47 | return append(globalPgoProfileProjects, config.PgoAdditionalProfileDirs()...) |
| 48 | }) |
| 49 | } |
| 50 | |
Yi Kong | 7e53c57 | 2018-02-14 18:16:12 +0800 | [diff] [blame] | 51 | func recordMissingProfileFile(ctx BaseModuleContext, missing string) { |
Colin Cross | 571cccf | 2019-02-04 11:22:08 -0800 | [diff] [blame] | 52 | getNamedMapForConfig(ctx.Config(), modulesMissingProfileFileKey).Store(missing, true) |
Pirama Arumuga Nainar | 28316d4 | 2018-01-29 09:18:45 -0800 | [diff] [blame] | 53 | } |
| 54 | |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 55 | type PgoProperties struct { |
| 56 | Pgo struct { |
Pirama Arumuga Nainar | 6aeed8b | 2017-10-16 13:31:40 -0700 | [diff] [blame] | 57 | Instrumentation *bool |
Pirama Arumuga Nainar | 6aeed8b | 2017-10-16 13:31:40 -0700 | [diff] [blame] | 58 | Profile_file *string `android:"arch_variant"` |
| 59 | Benchmarks []string |
| 60 | Enable_profile_use *bool `android:"arch_variant"` |
Pirama Arumuga Nainar | 690ed55 | 2017-12-13 16:48:20 -0800 | [diff] [blame] | 61 | // Additional compiler flags to use when building this module |
Yi Kong | fe84186 | 2022-06-07 15:23:08 +0800 | [diff] [blame] | 62 | // for profiling. |
Pirama Arumuga Nainar | 690ed55 | 2017-12-13 16:48:20 -0800 | [diff] [blame] | 63 | Cflags []string `android:"arch_variant"` |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 64 | } `android:"arch_variant"` |
| 65 | |
| 66 | PgoPresent bool `blueprint:"mutated"` |
| 67 | ShouldProfileModule bool `blueprint:"mutated"` |
Yi Kong | 7e53c57 | 2018-02-14 18:16:12 +0800 | [diff] [blame] | 68 | PgoCompile bool `blueprint:"mutated"` |
Pirama Arumuga Nainar | 1150fd7 | 2020-09-21 22:04:25 -0700 | [diff] [blame] | 69 | PgoInstrLink bool `blueprint:"mutated"` |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | type pgo struct { |
| 73 | Properties PgoProperties |
| 74 | } |
| 75 | |
Pirama Arumuga Nainar | 49b53d5 | 2017-10-04 16:47:29 -0700 | [diff] [blame] | 76 | func (props *PgoProperties) isInstrumentation() bool { |
| 77 | return props.Pgo.Instrumentation != nil && *props.Pgo.Instrumentation == true |
| 78 | } |
| 79 | |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 80 | func (pgo *pgo) props() []interface{} { |
| 81 | return []interface{}{&pgo.Properties} |
| 82 | } |
| 83 | |
Yi Kong | ceb5b76 | 2020-03-20 15:22:27 +0800 | [diff] [blame] | 84 | func (props *PgoProperties) addInstrumentationProfileGatherFlags(ctx ModuleContext, flags Flags) Flags { |
Pirama Arumuga Nainar | 1150fd7 | 2020-09-21 22:04:25 -0700 | [diff] [blame] | 85 | // Add to C flags iff PGO is explicitly enabled for this module. |
| 86 | if props.ShouldProfileModule { |
| 87 | flags.Local.CFlags = append(flags.Local.CFlags, props.Pgo.Cflags...) |
| 88 | flags.Local.CFlags = append(flags.Local.CFlags, profileInstrumentFlag) |
| 89 | } |
| 90 | flags.Local.LdFlags = append(flags.Local.LdFlags, profileInstrumentFlag) |
Yi Kong | ceb5b76 | 2020-03-20 15:22:27 +0800 | [diff] [blame] | 91 | return flags |
| 92 | } |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 93 | |
Yi Kong | 7e53c57 | 2018-02-14 18:16:12 +0800 | [diff] [blame] | 94 | func (props *PgoProperties) getPgoProfileFile(ctx BaseModuleContext) android.OptionalPath { |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 95 | profileFile := *props.Pgo.Profile_file |
Pirama Arumuga Nainar | 8aed42c | 2018-03-08 22:56:37 -0800 | [diff] [blame] | 96 | |
Pirama Arumuga Nainar | 4954080 | 2018-01-29 23:11:42 -0800 | [diff] [blame] | 97 | // Test if the profile_file is present in any of the PGO profile projects |
| 98 | for _, profileProject := range getPgoProfileProjects(ctx.DeviceConfig()) { |
Pirama Arumuga Nainar | 8aed42c | 2018-03-08 22:56:37 -0800 | [diff] [blame] | 99 | // Bug: http://b/74395273 If the profile_file is unavailable, |
| 100 | // use a versioned file named |
| 101 | // <profile_file>.<arbitrary-version> when available. This |
| 102 | // works around an issue where ccache serves stale cache |
| 103 | // entries when the profile file has changed. |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 104 | globPattern := filepath.Join(profileProject, profileFile+".*") |
| 105 | versionedProfiles, err := ctx.GlobWithDeps(globPattern, nil) |
Pirama Arumuga Nainar | 8aed42c | 2018-03-08 22:56:37 -0800 | [diff] [blame] | 106 | if err != nil { |
| 107 | ctx.ModuleErrorf("glob: %s", err.Error()) |
| 108 | } |
| 109 | |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 110 | path := android.ExistentPathForSource(ctx, profileProject, profileFile) |
Pirama Arumuga Nainar | 64946fe | 2018-01-17 14:00:53 -0800 | [diff] [blame] | 111 | if path.Valid() { |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 112 | if len(versionedProfiles) != 0 { |
| 113 | ctx.PropertyErrorf("pgo.profile_file", "Profile_file has multiple versions: "+filepath.Join(profileProject, profileFile)+", "+strings.Join(versionedProfiles, ", ")) |
Pirama Arumuga Nainar | 8aed42c | 2018-03-08 22:56:37 -0800 | [diff] [blame] | 114 | } |
Pirama Arumuga Nainar | 64946fe | 2018-01-17 14:00:53 -0800 | [diff] [blame] | 115 | return path |
| 116 | } |
Pirama Arumuga Nainar | 8aed42c | 2018-03-08 22:56:37 -0800 | [diff] [blame] | 117 | |
Jaewoong Jung | 18aefc1 | 2020-12-21 09:11:10 -0800 | [diff] [blame] | 118 | if len(versionedProfiles) > 1 { |
| 119 | ctx.PropertyErrorf("pgo.profile_file", "Profile_file has multiple versions: "+strings.Join(versionedProfiles, ", ")) |
| 120 | } else if len(versionedProfiles) == 1 { |
| 121 | return android.OptionalPathForPath(android.PathForSource(ctx, versionedProfiles[0])) |
Pirama Arumuga Nainar | 8aed42c | 2018-03-08 22:56:37 -0800 | [diff] [blame] | 122 | } |
Pirama Arumuga Nainar | 64946fe | 2018-01-17 14:00:53 -0800 | [diff] [blame] | 123 | } |
| 124 | |
Pirama Arumuga Nainar | 28316d4 | 2018-01-29 09:18:45 -0800 | [diff] [blame] | 125 | // Record that this module's profile file is absent |
| 126 | missing := *props.Pgo.Profile_file + ":" + ctx.ModuleDir() + "/Android.bp:" + ctx.ModuleName() |
| 127 | recordMissingProfileFile(ctx, missing) |
| 128 | |
Pirama Arumuga Nainar | 64946fe | 2018-01-17 14:00:53 -0800 | [diff] [blame] | 129 | return android.OptionalPathForPath(nil) |
| 130 | } |
| 131 | |
Pirama Arumuga Nainar | 3f5bb9c | 2017-10-10 10:47:41 -0700 | [diff] [blame] | 132 | func (props *PgoProperties) profileUseFlags(ctx ModuleContext, file string) []string { |
Yi Kong | fe84186 | 2022-06-07 15:23:08 +0800 | [diff] [blame] | 133 | flags := []string{fmt.Sprintf(profileUseInstrumentFormat, file)} |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 134 | flags = append(flags, profileUseOtherFlags...) |
| 135 | return flags |
| 136 | } |
| 137 | |
Pirama Arumuga Nainar | 0fdfc45 | 2017-10-10 11:00:18 -0700 | [diff] [blame] | 138 | func (props *PgoProperties) addProfileUseFlags(ctx ModuleContext, flags Flags) Flags { |
Pirama Arumuga Nainar | 64946fe | 2018-01-17 14:00:53 -0800 | [diff] [blame] | 139 | // Return if 'pgo' property is not present in this module. |
| 140 | if !props.PgoPresent { |
| 141 | return flags |
| 142 | } |
| 143 | |
Yi Kong | ca610d2 | 2018-04-24 10:42:02 -0700 | [diff] [blame] | 144 | if props.PgoCompile { |
| 145 | profileFile := props.getPgoProfileFile(ctx) |
Pirama Arumuga Nainar | 64946fe | 2018-01-17 14:00:53 -0800 | [diff] [blame] | 146 | profileFilePath := profileFile.Path() |
| 147 | profileUseFlags := props.profileUseFlags(ctx, profileFilePath.String()) |
Pirama Arumuga Nainar | 0fdfc45 | 2017-10-10 11:00:18 -0700 | [diff] [blame] | 148 | |
Colin Cross | 4af21ed | 2019-11-04 09:37:55 -0800 | [diff] [blame] | 149 | flags.Local.CFlags = append(flags.Local.CFlags, profileUseFlags...) |
| 150 | flags.Local.LdFlags = append(flags.Local.LdFlags, profileUseFlags...) |
Pirama Arumuga Nainar | 0fdfc45 | 2017-10-10 11:00:18 -0700 | [diff] [blame] | 151 | |
| 152 | // Update CFlagsDeps and LdFlagsDeps so the module is rebuilt |
| 153 | // if profileFile gets updated |
Pirama Arumuga Nainar | 64946fe | 2018-01-17 14:00:53 -0800 | [diff] [blame] | 154 | flags.CFlagsDeps = append(flags.CFlagsDeps, profileFilePath) |
| 155 | flags.LdFlagsDeps = append(flags.LdFlagsDeps, profileFilePath) |
Pirama Arumuga Nainar | 0fdfc45 | 2017-10-10 11:00:18 -0700 | [diff] [blame] | 156 | } |
| 157 | return flags |
| 158 | } |
| 159 | |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 160 | func (props *PgoProperties) isPGO(ctx BaseModuleContext) bool { |
Pirama Arumuga Nainar | 49b53d5 | 2017-10-04 16:47:29 -0700 | [diff] [blame] | 161 | isInstrumentation := props.isInstrumentation() |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 162 | |
Yi Kong | fe84186 | 2022-06-07 15:23:08 +0800 | [diff] [blame] | 163 | profileKindPresent := isInstrumentation |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 164 | filePresent := props.Pgo.Profile_file != nil |
| 165 | benchmarksPresent := len(props.Pgo.Benchmarks) > 0 |
| 166 | |
| 167 | // If all three properties are absent, PGO is OFF for this module |
| 168 | if !profileKindPresent && !filePresent && !benchmarksPresent { |
| 169 | return false |
| 170 | } |
| 171 | |
Yi Kong | 84803c5 | 2020-07-21 15:38:23 +0800 | [diff] [blame] | 172 | // profileKindPresent and filePresent are mandatory properties. |
| 173 | if !profileKindPresent || !filePresent { |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 174 | var missing []string |
| 175 | if !profileKindPresent { |
Yi Kong | fe84186 | 2022-06-07 15:23:08 +0800 | [diff] [blame] | 176 | missing = append(missing, "profile kind") |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 177 | } |
| 178 | if !filePresent { |
| 179 | missing = append(missing, "profile_file property") |
| 180 | } |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 181 | missingProps := strings.Join(missing, ", ") |
| 182 | ctx.ModuleErrorf("PGO specification is missing properties: " + missingProps) |
| 183 | } |
| 184 | |
Yi Kong | 84803c5 | 2020-07-21 15:38:23 +0800 | [diff] [blame] | 185 | // Benchmark property is mandatory for instrumentation PGO. |
| 186 | if isInstrumentation && !benchmarksPresent { |
| 187 | ctx.ModuleErrorf("Instrumentation PGO specification is missing benchmark property") |
| 188 | } |
| 189 | |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 190 | return true |
| 191 | } |
| 192 | |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 193 | func (pgo *pgo) begin(ctx BaseModuleContext) { |
| 194 | // TODO Evaluate if we need to support PGO for host modules |
| 195 | if ctx.Host() { |
| 196 | return |
| 197 | } |
| 198 | |
| 199 | // Check if PGO is needed for this module |
| 200 | pgo.Properties.PgoPresent = pgo.Properties.isPGO(ctx) |
| 201 | |
| 202 | if !pgo.Properties.PgoPresent { |
| 203 | return |
| 204 | } |
| 205 | |
| 206 | // This module should be instrumented if ANDROID_PGO_INSTRUMENT is set |
Pirama Arumuga Nainar | e236b5a | 2018-01-22 19:10:19 -0800 | [diff] [blame] | 207 | // and includes 'all', 'ALL' or a benchmark listed for this module. |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 208 | // |
| 209 | // TODO Validate that each benchmark instruments at least one module |
| 210 | pgo.Properties.ShouldProfileModule = false |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 211 | pgoBenchmarks := ctx.Config().Getenv("ANDROID_PGO_INSTRUMENT") |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 212 | pgoBenchmarksMap := make(map[string]bool) |
| 213 | for _, b := range strings.Split(pgoBenchmarks, ",") { |
| 214 | pgoBenchmarksMap[b] = true |
| 215 | } |
| 216 | |
Pirama Arumuga Nainar | e236b5a | 2018-01-22 19:10:19 -0800 | [diff] [blame] | 217 | if pgoBenchmarksMap["all"] == true || pgoBenchmarksMap["ALL"] == true { |
| 218 | pgo.Properties.ShouldProfileModule = true |
Pirama Arumuga Nainar | 1150fd7 | 2020-09-21 22:04:25 -0700 | [diff] [blame] | 219 | pgo.Properties.PgoInstrLink = pgo.Properties.isInstrumentation() |
Pirama Arumuga Nainar | e236b5a | 2018-01-22 19:10:19 -0800 | [diff] [blame] | 220 | } else { |
| 221 | for _, b := range pgo.Properties.Pgo.Benchmarks { |
| 222 | if pgoBenchmarksMap[b] == true { |
| 223 | pgo.Properties.ShouldProfileModule = true |
Pirama Arumuga Nainar | 1150fd7 | 2020-09-21 22:04:25 -0700 | [diff] [blame] | 224 | pgo.Properties.PgoInstrLink = pgo.Properties.isInstrumentation() |
Pirama Arumuga Nainar | e236b5a | 2018-01-22 19:10:19 -0800 | [diff] [blame] | 225 | break |
| 226 | } |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 227 | } |
| 228 | } |
Yi Kong | 7e53c57 | 2018-02-14 18:16:12 +0800 | [diff] [blame] | 229 | |
Pirama Arumuga Nainar | 807d49b | 2020-02-12 13:57:37 -0800 | [diff] [blame] | 230 | // PGO profile use is not feasible for a Clang coverage build because |
| 231 | // -fprofile-use and -fprofile-instr-generate are incompatible. |
| 232 | if ctx.DeviceConfig().ClangCoverageEnabled() { |
| 233 | return |
| 234 | } |
| 235 | |
Yi Kong | ca610d2 | 2018-04-24 10:42:02 -0700 | [diff] [blame] | 236 | if !ctx.Config().IsEnvTrue("ANDROID_PGO_NO_PROFILE_USE") && |
| 237 | proptools.BoolDefault(pgo.Properties.Pgo.Enable_profile_use, true) { |
Yi Kong | 7e53c57 | 2018-02-14 18:16:12 +0800 | [diff] [blame] | 238 | if profileFile := pgo.Properties.getPgoProfileFile(ctx); profileFile.Valid() { |
| 239 | pgo.Properties.PgoCompile = true |
| 240 | } |
| 241 | } |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | func (pgo *pgo) flags(ctx ModuleContext, flags Flags) Flags { |
| 245 | if ctx.Host() { |
| 246 | return flags |
| 247 | } |
| 248 | |
Pirama Arumuga Nainar | 1150fd7 | 2020-09-21 22:04:25 -0700 | [diff] [blame] | 249 | // Deduce PgoInstrLink property i.e. whether this module needs to be |
| 250 | // linked with profile-generation flags. Here, we're setting it if any |
| 251 | // dependency needs PGO instrumentation. It is initially set in |
| 252 | // begin() if PGO is directly enabled for this module. |
| 253 | if ctx.static() && !ctx.staticBinary() { |
| 254 | // For static libraries, check if any whole_static_libs are |
| 255 | // linked with profile generation |
| 256 | ctx.VisitDirectDeps(func(m android.Module) { |
| 257 | if depTag, ok := ctx.OtherModuleDependencyTag(m).(libraryDependencyTag); ok { |
| 258 | if depTag.static() && depTag.wholeStatic { |
| 259 | if cc, ok := m.(*Module); ok { |
| 260 | if cc.pgo.Properties.PgoInstrLink { |
| 261 | pgo.Properties.PgoInstrLink = true |
| 262 | } |
| 263 | } |
| 264 | } |
| 265 | } |
| 266 | }) |
| 267 | } else { |
| 268 | // For executables and shared libraries, check all static dependencies. |
| 269 | ctx.VisitDirectDeps(func(m android.Module) { |
| 270 | if depTag, ok := ctx.OtherModuleDependencyTag(m).(libraryDependencyTag); ok { |
| 271 | if depTag.static() { |
| 272 | if cc, ok := m.(*Module); ok { |
| 273 | if cc.pgo.Properties.PgoInstrLink { |
| 274 | pgo.Properties.PgoInstrLink = true |
| 275 | } |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | }) |
| 280 | } |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 281 | |
Pirama Arumuga Nainar | 1150fd7 | 2020-09-21 22:04:25 -0700 | [diff] [blame] | 282 | props := pgo.Properties |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 283 | // Add flags to profile this module based on its profile_kind |
Pirama Arumuga Nainar | 1150fd7 | 2020-09-21 22:04:25 -0700 | [diff] [blame] | 284 | if (props.ShouldProfileModule && props.isInstrumentation()) || props.PgoInstrLink { |
Yi Kong | a575ff3 | 2020-07-22 01:41:58 +0800 | [diff] [blame] | 285 | // Instrumentation PGO use and gather flags cannot coexist. |
Pirama Arumuga Nainar | fe1da75 | 2020-09-02 17:44:06 +0000 | [diff] [blame] | 286 | return props.addInstrumentationProfileGatherFlags(ctx, flags) |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 287 | } |
| 288 | |
Colin Cross | 6510f91 | 2017-11-29 00:27:14 -0800 | [diff] [blame] | 289 | if !ctx.Config().IsEnvTrue("ANDROID_PGO_NO_PROFILE_USE") { |
Pirama Arumuga Nainar | fe1da75 | 2020-09-02 17:44:06 +0000 | [diff] [blame] | 290 | flags = props.addProfileUseFlags(ctx, flags) |
Pirama Arumuga Nainar | ada83ec | 2017-08-31 23:38:27 -0700 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | return flags |
| 294 | } |