Merge "Global ThinLTO mode" am: 6a94390d2e
am: 26fb8c32be
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1432912 Change-Id: I635b464ec16ac9bde38eeaa4e64d7a8d5e316651
This commit is contained in:
42
cc/lto.go
42
cc/lto.go
@@ -45,6 +45,8 @@ type LTOProperties struct {
|
|||||||
Thin *bool `android:"arch_variant"`
|
Thin *bool `android:"arch_variant"`
|
||||||
} `android:"arch_variant"`
|
} `android:"arch_variant"`
|
||||||
|
|
||||||
|
GlobalThin *bool `blueprint:"mutated"`
|
||||||
|
|
||||||
// Dep properties indicate that this module needs to be built with LTO
|
// Dep properties indicate that this module needs to be built with LTO
|
||||||
// since it is an object dependency of an LTO module.
|
// since it is an object dependency of an LTO module.
|
||||||
FullDep bool `blueprint:"mutated"`
|
FullDep bool `blueprint:"mutated"`
|
||||||
@@ -68,6 +70,8 @@ func (lto *lto) props() []interface{} {
|
|||||||
func (lto *lto) begin(ctx BaseModuleContext) {
|
func (lto *lto) begin(ctx BaseModuleContext) {
|
||||||
if ctx.Config().IsEnvTrue("DISABLE_LTO") {
|
if ctx.Config().IsEnvTrue("DISABLE_LTO") {
|
||||||
lto.Properties.Lto.Never = boolPtr(true)
|
lto.Properties.Lto.Never = boolPtr(true)
|
||||||
|
} else if ctx.Config().IsEnvTrue("GLOBAL_THINLTO") {
|
||||||
|
lto.Properties.GlobalThin = boolPtr(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,7 +95,7 @@ func (lto *lto) flags(ctx BaseModuleContext, flags Flags) Flags {
|
|||||||
|
|
||||||
if lto.LTO() {
|
if lto.LTO() {
|
||||||
var ltoFlag string
|
var ltoFlag string
|
||||||
if Bool(lto.Properties.Lto.Thin) {
|
if lto.ThinLTO() {
|
||||||
ltoFlag = "-flto=thin -fsplit-lto-unit"
|
ltoFlag = "-flto=thin -fsplit-lto-unit"
|
||||||
} else {
|
} else {
|
||||||
ltoFlag = "-flto"
|
ltoFlag = "-flto"
|
||||||
@@ -104,7 +108,7 @@ func (lto *lto) flags(ctx BaseModuleContext, flags Flags) Flags {
|
|||||||
flags.Local.CFlags = append(flags.Local.CFlags, "-fwhole-program-vtables")
|
flags.Local.CFlags = append(flags.Local.CFlags, "-fwhole-program-vtables")
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.Config().IsEnvTrue("USE_THINLTO_CACHE") && Bool(lto.Properties.Lto.Thin) && lto.useClangLld(ctx) {
|
if lto.ThinLTO() && ctx.Config().IsEnvTrue("USE_THINLTO_CACHE") && lto.useClangLld(ctx) {
|
||||||
// Set appropriate ThinLTO cache policy
|
// Set appropriate ThinLTO cache policy
|
||||||
cacheDirFormat := "-Wl,--thinlto-cache-dir="
|
cacheDirFormat := "-Wl,--thinlto-cache-dir="
|
||||||
cacheDir := android.PathForOutput(ctx, "thinlto-cache").String()
|
cacheDir := android.PathForOutput(ctx, "thinlto-cache").String()
|
||||||
@@ -133,9 +137,21 @@ func (lto *lto) LTO() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
full := Bool(lto.Properties.Lto.Full)
|
return lto.FullLTO() || lto.ThinLTO()
|
||||||
thin := Bool(lto.Properties.Lto.Thin)
|
}
|
||||||
return full || thin
|
|
||||||
|
func (lto *lto) FullLTO() bool {
|
||||||
|
return Bool(lto.Properties.Lto.Full)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (lto *lto) ThinLTO() bool {
|
||||||
|
if Bool(lto.Properties.GlobalThin) {
|
||||||
|
if !lto.Disabled() && !lto.FullLTO() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Bool(lto.Properties.Lto.Thin)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Is lto.never explicitly set to true?
|
// Is lto.never explicitly set to true?
|
||||||
@@ -146,8 +162,8 @@ func (lto *lto) Disabled() bool {
|
|||||||
// Propagate lto requirements down from binaries
|
// Propagate lto requirements down from binaries
|
||||||
func ltoDepsMutator(mctx android.TopDownMutatorContext) {
|
func ltoDepsMutator(mctx android.TopDownMutatorContext) {
|
||||||
if m, ok := mctx.Module().(*Module); ok && m.lto.LTO() {
|
if m, ok := mctx.Module().(*Module); ok && m.lto.LTO() {
|
||||||
full := Bool(m.lto.Properties.Lto.Full)
|
full := m.lto.FullLTO()
|
||||||
thin := Bool(m.lto.Properties.Lto.Thin)
|
thin := m.lto.ThinLTO()
|
||||||
if full && thin {
|
if full && thin {
|
||||||
mctx.PropertyErrorf("LTO", "FullLTO and ThinLTO are mutually exclusive")
|
mctx.PropertyErrorf("LTO", "FullLTO and ThinLTO are mutually exclusive")
|
||||||
}
|
}
|
||||||
@@ -169,10 +185,10 @@ func ltoDepsMutator(mctx android.TopDownMutatorContext) {
|
|||||||
|
|
||||||
if dep, ok := dep.(*Module); ok && dep.lto != nil &&
|
if dep, ok := dep.(*Module); ok && dep.lto != nil &&
|
||||||
!dep.lto.Disabled() {
|
!dep.lto.Disabled() {
|
||||||
if full && !Bool(dep.lto.Properties.Lto.Full) {
|
if full && !dep.lto.FullLTO() {
|
||||||
dep.lto.Properties.FullDep = true
|
dep.lto.Properties.FullDep = true
|
||||||
}
|
}
|
||||||
if thin && !Bool(dep.lto.Properties.Lto.Thin) {
|
if thin && !dep.lto.ThinLTO() {
|
||||||
dep.lto.Properties.ThinDep = true
|
dep.lto.Properties.ThinDep = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -189,19 +205,19 @@ func ltoMutator(mctx android.BottomUpMutatorContext) {
|
|||||||
// Create variations for LTO types required as static
|
// Create variations for LTO types required as static
|
||||||
// dependencies
|
// dependencies
|
||||||
variationNames := []string{""}
|
variationNames := []string{""}
|
||||||
if m.lto.Properties.FullDep && !Bool(m.lto.Properties.Lto.Full) {
|
if m.lto.Properties.FullDep && !m.lto.FullLTO() {
|
||||||
variationNames = append(variationNames, "lto-full")
|
variationNames = append(variationNames, "lto-full")
|
||||||
}
|
}
|
||||||
if m.lto.Properties.ThinDep && !Bool(m.lto.Properties.Lto.Thin) {
|
if m.lto.Properties.ThinDep && !m.lto.ThinLTO() {
|
||||||
variationNames = append(variationNames, "lto-thin")
|
variationNames = append(variationNames, "lto-thin")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use correct dependencies if LTO property is explicitly set
|
// Use correct dependencies if LTO property is explicitly set
|
||||||
// (mutually exclusive)
|
// (mutually exclusive)
|
||||||
if Bool(m.lto.Properties.Lto.Full) {
|
if m.lto.FullLTO() {
|
||||||
mctx.SetDependencyVariation("lto-full")
|
mctx.SetDependencyVariation("lto-full")
|
||||||
}
|
}
|
||||||
if Bool(m.lto.Properties.Lto.Thin) {
|
if m.lto.ThinLTO() {
|
||||||
mctx.SetDependencyVariation("lto-thin")
|
mctx.SetDependencyVariation("lto-thin")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user