Update profile_file discovery rules
Bug: http://b/63768402 Profile files are searched in multiple directories in a pre-define list, instead of just one. PGO profile_file enforcement is also removed - profile_file dependency and -fprofile-use are added iff the profile_file is present. Test: Build https://android-review.googlesource.com/c/474805 with .profdata files in vendor/google_data/pgo-profiles and toolchain/pgo-profiles and verify expected behavior. Change-Id: I2604713a8a7a682bd5c6bde569dc32335be5eca9 Merged-In: I2604713a8a7a682bd5c6bde569dc32335be5eca9
This commit is contained in:
41
cc/pgo.go
41
cc/pgo.go
@@ -26,9 +26,12 @@ var (
|
|||||||
// Add flags to ignore warnings that profiles are old or missing for
|
// Add flags to ignore warnings that profiles are old or missing for
|
||||||
// some functions
|
// some functions
|
||||||
profileUseOtherFlags = []string{"-Wno-backend-plugin"}
|
profileUseOtherFlags = []string{"-Wno-backend-plugin"}
|
||||||
)
|
|
||||||
|
|
||||||
const pgoProfileProject = "toolchain/pgo-profiles"
|
pgoProfileProjects = []string{
|
||||||
|
"toolchain/pgo-profiles",
|
||||||
|
"vendor/google_data/pgo-profiles",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
const profileInstrumentFlag = "-fprofile-generate=/data/local/tmp"
|
const profileInstrumentFlag = "-fprofile-generate=/data/local/tmp"
|
||||||
const profileSamplingFlag = "-gline-tables-only"
|
const profileSamplingFlag = "-gline-tables-only"
|
||||||
@@ -84,6 +87,18 @@ func (props *PgoProperties) addProfileGatherFlags(ctx ModuleContext, flags Flags
|
|||||||
return flags
|
return flags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (props *PgoProperties) getPgoProfileFile(ctx ModuleContext) android.OptionalPath {
|
||||||
|
// Test if the profile_file is present in any of the pgoProfileProjects
|
||||||
|
for _, profileProject := range pgoProfileProjects {
|
||||||
|
path := android.ExistentPathForSource(ctx, "", profileProject, *props.Pgo.Profile_file)
|
||||||
|
if path.Valid() {
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return android.OptionalPathForPath(nil)
|
||||||
|
}
|
||||||
|
|
||||||
func (props *PgoProperties) profileUseFlag(ctx ModuleContext, file string) string {
|
func (props *PgoProperties) profileUseFlag(ctx ModuleContext, file string) string {
|
||||||
if props.isInstrumentation() {
|
if props.isInstrumentation() {
|
||||||
return fmt.Sprintf(profileUseInstrumentFormat, file)
|
return fmt.Sprintf(profileUseInstrumentFormat, file)
|
||||||
@@ -101,24 +116,28 @@ func (props *PgoProperties) profileUseFlags(ctx ModuleContext, file string) []st
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (props *PgoProperties) addProfileUseFlags(ctx ModuleContext, flags Flags) Flags {
|
func (props *PgoProperties) addProfileUseFlags(ctx ModuleContext, flags Flags) Flags {
|
||||||
|
// Return if 'pgo' property is not present in this module.
|
||||||
|
if !props.PgoPresent {
|
||||||
|
return flags
|
||||||
|
}
|
||||||
|
|
||||||
// Skip -fprofile-use if 'enable_profile_use' property is set
|
// Skip -fprofile-use if 'enable_profile_use' property is set
|
||||||
if props.Pgo.Enable_profile_use != nil && *props.Pgo.Enable_profile_use == false {
|
if props.Pgo.Enable_profile_use != nil && *props.Pgo.Enable_profile_use == false {
|
||||||
return flags
|
return flags
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the PGO profiles project is found, and this module has PGO
|
// If the profile file is found, add flags to use the profile
|
||||||
// enabled, add flags to use the profile
|
if profileFile := props.getPgoProfileFile(ctx); profileFile.Valid() {
|
||||||
if profilesDir := getPgoProfilesDir(ctx); props.PgoPresent && profilesDir.Valid() {
|
profileFilePath := profileFile.Path()
|
||||||
profileFile := android.PathForSource(ctx, profilesDir.String(), *props.Pgo.Profile_file)
|
profileUseFlags := props.profileUseFlags(ctx, profileFilePath.String())
|
||||||
profileUseFlags := props.profileUseFlags(ctx, profileFile.String())
|
|
||||||
|
|
||||||
flags.CFlags = append(flags.CFlags, profileUseFlags...)
|
flags.CFlags = append(flags.CFlags, profileUseFlags...)
|
||||||
flags.LdFlags = append(flags.LdFlags, profileUseFlags...)
|
flags.LdFlags = append(flags.LdFlags, profileUseFlags...)
|
||||||
|
|
||||||
// Update CFlagsDeps and LdFlagsDeps so the module is rebuilt
|
// Update CFlagsDeps and LdFlagsDeps so the module is rebuilt
|
||||||
// if profileFile gets updated
|
// if profileFile gets updated
|
||||||
flags.CFlagsDeps = append(flags.CFlagsDeps, profileFile)
|
flags.CFlagsDeps = append(flags.CFlagsDeps, profileFilePath)
|
||||||
flags.LdFlagsDeps = append(flags.LdFlagsDeps, profileFile)
|
flags.LdFlagsDeps = append(flags.LdFlagsDeps, profileFilePath)
|
||||||
}
|
}
|
||||||
return flags
|
return flags
|
||||||
}
|
}
|
||||||
@@ -164,10 +183,6 @@ func (props *PgoProperties) isPGO(ctx BaseModuleContext) bool {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPgoProfilesDir(ctx ModuleContext) android.OptionalPath {
|
|
||||||
return android.ExistentPathForSource(ctx, "", pgoProfileProject)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (pgo *pgo) begin(ctx BaseModuleContext) {
|
func (pgo *pgo) begin(ctx BaseModuleContext) {
|
||||||
// TODO Evaluate if we need to support PGO for host modules
|
// TODO Evaluate if we need to support PGO for host modules
|
||||||
if ctx.Host() {
|
if ctx.Host() {
|
||||||
|
Reference in New Issue
Block a user