Merge changes from topic "optimize_for_size" into main
* changes: Enable MLGO inliner optimization for optimize_for_size cases Add "Optimize_for_size" build property
This commit is contained in:
commit
cdb8501c1e
3 changed files with 21 additions and 1 deletions
15
cc/cc.go
15
cc/cc.go
|
@ -286,6 +286,11 @@ type BaseProperties struct {
|
||||||
// Deprecated. true is the default, false is invalid.
|
// Deprecated. true is the default, false is invalid.
|
||||||
Clang *bool `android:"arch_variant"`
|
Clang *bool `android:"arch_variant"`
|
||||||
|
|
||||||
|
// Aggresively trade performance for smaller binary size.
|
||||||
|
// This should only be used for on-device binaries that are rarely executed and not
|
||||||
|
// performance critical.
|
||||||
|
Optimize_for_size *bool `android:"arch_variant"`
|
||||||
|
|
||||||
// The API level that this module is built against. The APIs of this API level will be
|
// The API level that this module is built against. The APIs of this API level will be
|
||||||
// visible at build time, but use of any APIs newer than min_sdk_version will render the
|
// visible at build time, but use of any APIs newer than min_sdk_version will render the
|
||||||
// module unloadable on older devices. In the future it will be possible to weakly-link new
|
// module unloadable on older devices. In the future it will be possible to weakly-link new
|
||||||
|
@ -546,6 +551,7 @@ type ModuleContextIntf interface {
|
||||||
isCfiAssemblySupportEnabled() bool
|
isCfiAssemblySupportEnabled() bool
|
||||||
getSharedFlags() *SharedFlags
|
getSharedFlags() *SharedFlags
|
||||||
notInPlatform() bool
|
notInPlatform() bool
|
||||||
|
optimizeForSize() bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type SharedFlags struct {
|
type SharedFlags struct {
|
||||||
|
@ -985,6 +991,7 @@ func (c *Module) AddJSONData(d *map[string]interface{}) {
|
||||||
"WinMsgSrcs": hasWinMsg,
|
"WinMsgSrcs": hasWinMsg,
|
||||||
"YaccSrsc": hasYacc,
|
"YaccSrsc": hasYacc,
|
||||||
"OnlyCSrcs": !(hasAidl || hasLex || hasProto || hasRenderscript || hasSysprop || hasWinMsg || hasYacc),
|
"OnlyCSrcs": !(hasAidl || hasLex || hasProto || hasRenderscript || hasSysprop || hasWinMsg || hasYacc),
|
||||||
|
"OptimizeForSize": c.OptimizeForSize(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1070,6 +1077,10 @@ func (c *Module) StubDecorator() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Module) OptimizeForSize() bool {
|
||||||
|
return Bool(c.Properties.Optimize_for_size)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Module) SdkVersion() string {
|
func (c *Module) SdkVersion() string {
|
||||||
return String(c.Properties.Sdk_version)
|
return String(c.Properties.Sdk_version)
|
||||||
}
|
}
|
||||||
|
@ -1613,6 +1624,10 @@ func (ctx *moduleContextImpl) object() bool {
|
||||||
return ctx.mod.Object()
|
return ctx.mod.Object()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ctx *moduleContextImpl) optimizeForSize() bool {
|
||||||
|
return ctx.mod.OptimizeForSize()
|
||||||
|
}
|
||||||
|
|
||||||
func (ctx *moduleContextImpl) canUseSdk() bool {
|
func (ctx *moduleContextImpl) canUseSdk() bool {
|
||||||
return ctx.mod.canUseSdk()
|
return ctx.mod.canUseSdk()
|
||||||
}
|
}
|
||||||
|
|
|
@ -693,6 +693,11 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags, deps
|
||||||
flags.Local.CFlags = append(flags.Local.CFlags, "-fopenmp")
|
flags.Local.CFlags = append(flags.Local.CFlags, "-fopenmp")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ctx.optimizeForSize() {
|
||||||
|
flags.Local.CFlags = append(flags.Local.CFlags, "-Oz")
|
||||||
|
flags.Local.LdFlags = append(flags.Local.LdFlags, "-Wl,-mllvm,-enable-ml-inliner=release")
|
||||||
|
}
|
||||||
|
|
||||||
// Exclude directories from manual binder interface allowed list.
|
// Exclude directories from manual binder interface allowed list.
|
||||||
//TODO(b/145621474): Move this check into IInterface.h when clang-tidy no longer uses absolute paths.
|
//TODO(b/145621474): Move this check into IInterface.h when clang-tidy no longer uses absolute paths.
|
||||||
if android.HasAnyPrefix(ctx.ModuleDir(), allowedManualInterfacePaths) {
|
if android.HasAnyPrefix(ctx.ModuleDir(), allowedManualInterfacePaths) {
|
||||||
|
|
|
@ -144,7 +144,7 @@ func (lto *lto) flags(ctx ModuleContext, flags Flags) Flags {
|
||||||
|
|
||||||
if !ctx.Config().IsEnvFalse("THINLTO_USE_MLGO") {
|
if !ctx.Config().IsEnvFalse("THINLTO_USE_MLGO") {
|
||||||
// Register allocation MLGO flags for ARM64.
|
// Register allocation MLGO flags for ARM64.
|
||||||
if ctx.Arch().ArchType == android.Arm64 {
|
if ctx.Arch().ArchType == android.Arm64 && !ctx.optimizeForSize() {
|
||||||
ltoLdFlags = append(ltoLdFlags, "-Wl,-mllvm,-regalloc-enable-advisor=release")
|
ltoLdFlags = append(ltoLdFlags, "-Wl,-mllvm,-regalloc-enable-advisor=release")
|
||||||
}
|
}
|
||||||
// Flags for training MLGO model.
|
// Flags for training MLGO model.
|
||||||
|
|
Loading…
Reference in a new issue