Merge changes Ib23bad52,I1923ebde
* changes:
Do not use profiles if ANDROID_PGO_NO_PROFILE_USE is set
Refactor methods to be on PgoProperties struct
diff --git a/cc/pgo.go b/cc/pgo.go
index a99cbad..c5e4e86 100644
--- a/cc/pgo.go
+++ b/cc/pgo.go
@@ -63,37 +63,55 @@
return []interface{}{&pgo.Properties}
}
-func (pgo *pgo) addProfileGatherFlags(ctx ModuleContext, flags Flags) Flags {
- if pgo.Properties.isInstrumentation() {
+func (props *PgoProperties) addProfileGatherFlags(ctx ModuleContext, flags Flags) Flags {
+ if props.isInstrumentation() {
flags.CFlags = append(flags.CFlags, profileInstrumentFlag)
// The profile runtime is added below in deps(). Add the below
// flag, which is the only other link-time action performed by
// the Clang driver during link.
flags.LdFlags = append(flags.LdFlags, "-u__llvm_profile_runtime")
}
- if pgo.Properties.isSampling() {
+ if props.isSampling() {
flags.CFlags = append(flags.CFlags, profileSamplingFlag)
flags.LdFlags = append(flags.LdFlags, profileSamplingFlag)
}
return flags
}
-func (pgo *pgo) profileUseFlag(ctx ModuleContext, file string) string {
- if pgo.Properties.isInstrumentation() {
+func (props *PgoProperties) profileUseFlag(ctx ModuleContext, file string) string {
+ if props.isInstrumentation() {
return fmt.Sprintf(profileUseInstrumentFormat, file)
}
- if pgo.Properties.isSampling() {
+ if props.isSampling() {
return fmt.Sprintf(profileUseSamplingFormat, file)
}
return ""
}
-func (pgo *pgo) profileUseFlags(ctx ModuleContext, file string) []string {
- flags := []string{pgo.profileUseFlag(ctx, file)}
+func (props *PgoProperties) profileUseFlags(ctx ModuleContext, file string) []string {
+ flags := []string{props.profileUseFlag(ctx, file)}
flags = append(flags, profileUseOtherFlags...)
return flags
}
+func (props *PgoProperties) addProfileUseFlags(ctx ModuleContext, flags Flags) Flags {
+ // If the PGO profiles project is found, and this module has PGO
+ // enabled, add flags to use the profile
+ if profilesDir := getPgoProfilesDir(ctx); props.PgoPresent && profilesDir.Valid() {
+ profileFile := android.PathForSource(ctx, profilesDir.String(), *props.Pgo.Profile_file)
+ profileUseFlags := props.profileUseFlags(ctx, profileFile.String())
+
+ flags.CFlags = append(flags.CFlags, profileUseFlags...)
+ flags.LdFlags = append(flags.LdFlags, profileUseFlags...)
+
+ // Update CFlagsDeps and LdFlagsDeps so the module is rebuilt
+ // if profileFile gets updated
+ flags.CFlagsDeps = append(flags.CFlagsDeps, profileFile)
+ flags.LdFlagsDeps = append(flags.LdFlagsDeps, profileFile)
+ }
+ return flags
+}
+
func (props *PgoProperties) isPGO(ctx BaseModuleContext) bool {
isInstrumentation := props.isInstrumentation()
isSampling := props.isSampling()
@@ -188,22 +206,11 @@
// Add flags to profile this module based on its profile_kind
if props.ShouldProfileModule {
- return pgo.addProfileGatherFlags(ctx, flags)
+ return props.addProfileGatherFlags(ctx, flags)
}
- // If the PGO profiles project is found, and this module has PGO
- // enabled, add flags to use the profile
- if profilesDir := getPgoProfilesDir(ctx); props.PgoPresent && profilesDir.Valid() {
- profileFile := android.PathForSource(ctx, profilesDir.String(), *(props.Pgo.Profile_file))
- profileUseFlags := pgo.profileUseFlags(ctx, profileFile.String())
-
- flags.CFlags = append(flags.CFlags, profileUseFlags...)
- flags.LdFlags = append(flags.LdFlags, profileUseFlags...)
-
- // Update CFlagsDeps and LdFlagsDeps so the module is rebuilt
- // if profileFile gets updated
- flags.CFlagsDeps = append(flags.CFlagsDeps, profileFile)
- flags.LdFlagsDeps = append(flags.LdFlagsDeps, profileFile)
+ if !ctx.AConfig().IsEnvTrue("ANDROID_PGO_NO_PROFILE_USE") {
+ return props.addProfileUseFlags(ctx, flags)
}
return flags