summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Yi Kong <yikong@google.com> 2020-09-25 08:36:17 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2020-09-25 08:36:17 +0000
commit6a94390d2ec0265d1fb9e5836bc4168fd2bc6a3a (patch)
tree4e4a06d87c9d24f777f4fd9ba38ca4e3a845f627
parenta6906e2329a20f1d3e2d1d50ca47d4bd290d1ca0 (diff)
parent93718e0d41488165c317ae234ec2f408a36dcd7b (diff)
Merge "Global ThinLTO mode"
-rw-r--r--cc/lto.go42
1 files changed, 29 insertions, 13 deletions
diff --git a/cc/lto.go b/cc/lto.go
index d1903b893..3e1acdf6d 100644
--- a/cc/lto.go
+++ b/cc/lto.go
@@ -45,6 +45,8 @@ type LTOProperties struct {
Thin *bool `android:"arch_variant"`
} `android:"arch_variant"`
+ GlobalThin *bool `blueprint:"mutated"`
+
// Dep properties indicate that this module needs to be built with LTO
// since it is an object dependency of an LTO module.
FullDep bool `blueprint:"mutated"`
@@ -68,6 +70,8 @@ func (lto *lto) props() []interface{} {
func (lto *lto) begin(ctx BaseModuleContext) {
if ctx.Config().IsEnvTrue("DISABLE_LTO") {
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() {
var ltoFlag string
- if Bool(lto.Properties.Lto.Thin) {
+ if lto.ThinLTO() {
ltoFlag = "-flto=thin -fsplit-lto-unit"
} else {
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")
}
- 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
cacheDirFormat := "-Wl,--thinlto-cache-dir="
cacheDir := android.PathForOutput(ctx, "thinlto-cache").String()
@@ -133,9 +137,21 @@ func (lto *lto) LTO() bool {
return false
}
- full := Bool(lto.Properties.Lto.Full)
- thin := Bool(lto.Properties.Lto.Thin)
- return full || thin
+ return lto.FullLTO() || lto.ThinLTO()
+}
+
+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?
@@ -146,8 +162,8 @@ func (lto *lto) Disabled() bool {
// Propagate lto requirements down from binaries
func ltoDepsMutator(mctx android.TopDownMutatorContext) {
if m, ok := mctx.Module().(*Module); ok && m.lto.LTO() {
- full := Bool(m.lto.Properties.Lto.Full)
- thin := Bool(m.lto.Properties.Lto.Thin)
+ full := m.lto.FullLTO()
+ thin := m.lto.ThinLTO()
if full && thin {
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 &&
!dep.lto.Disabled() {
- if full && !Bool(dep.lto.Properties.Lto.Full) {
+ if full && !dep.lto.FullLTO() {
dep.lto.Properties.FullDep = true
}
- if thin && !Bool(dep.lto.Properties.Lto.Thin) {
+ if thin && !dep.lto.ThinLTO() {
dep.lto.Properties.ThinDep = true
}
}
@@ -189,19 +205,19 @@ func ltoMutator(mctx android.BottomUpMutatorContext) {
// Create variations for LTO types required as static
// dependencies
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")
}
- if m.lto.Properties.ThinDep && !Bool(m.lto.Properties.Lto.Thin) {
+ if m.lto.Properties.ThinDep && !m.lto.ThinLTO() {
variationNames = append(variationNames, "lto-thin")
}
// Use correct dependencies if LTO property is explicitly set
// (mutually exclusive)
- if Bool(m.lto.Properties.Lto.Full) {
+ if m.lto.FullLTO() {
mctx.SetDependencyVariation("lto-full")
}
- if Bool(m.lto.Properties.Lto.Thin) {
+ if m.lto.ThinLTO() {
mctx.SetDependencyVariation("lto-thin")
}