From 244bf079f90b95f737772147ef222108f582c574 Mon Sep 17 00:00:00 2001 From: Yi Kong Date: Tue, 29 Aug 2017 11:10:09 +0800 Subject: [PATCH] Add support for thin LTO ThinLTO achieves comparable performance to full LTO while taking much less time for compilation. Test: Build hwui with "thin" and "full" LTO Change-Id: If3400b82af0d5e0226410c8b740999cdad746a59 --- cc/lto.go | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/cc/lto.go b/cc/lto.go index f49677244..6a5ecdee9 100644 --- a/cc/lto.go +++ b/cc/lto.go @@ -41,8 +41,11 @@ import ( type LTOProperties struct { // Lto must violate capitialization style for acronyms so that it can be // referred to in blueprint files as "lto" - Lto *bool `android:"arch_variant"` - LTODep bool `blueprint:"mutated"` + Lto struct { + Full *bool `android:"arch_variant"` + Thin *bool `android:"arch_variant"` + } `android:"arch_variant"` + LTODep bool `blueprint:"mutated"` } type lto struct { @@ -61,9 +64,16 @@ func (lto *lto) deps(ctx BaseModuleContext, deps Deps) Deps { } func (lto *lto) flags(ctx BaseModuleContext, flags Flags) Flags { - if Bool(lto.Properties.Lto) { - flags.CFlags = append(flags.CFlags, "-flto") - flags.LdFlags = append(flags.LdFlags, "-flto") + if lto.LTO() { + var ltoFlag string + if Bool(lto.Properties.Lto.Thin) { + ltoFlag = "-flto=thin" + } else { + ltoFlag = "-flto" + } + + flags.CFlags = append(flags.CFlags, ltoFlag) + flags.LdFlags = append(flags.LdFlags, ltoFlag) if ctx.Device() { // Work around bug in Clang that doesn't pass correct emulated // TLS option to target @@ -80,12 +90,20 @@ func (lto *lto) LTO() bool { return false } - return Bool(lto.Properties.Lto) + full := Bool(lto.Properties.Lto.Full) + thin := Bool(lto.Properties.Lto.Thin) + return full || thin } // Propagate lto requirements down from binaries func ltoDepsMutator(mctx android.TopDownMutatorContext) { if c, ok := mctx.Module().(*Module); ok && c.lto.LTO() { + full := Bool(c.lto.Properties.Lto.Full) + thin := Bool(c.lto.Properties.Lto.Thin) + if full && thin { + mctx.PropertyErrorf("LTO", "FullLTO and ThinLTO are mutually exclusive") + } + mctx.VisitDepsDepthFirst(func(m blueprint.Module) { tag := mctx.OtherModuleDependencyTag(m) switch tag { @@ -105,8 +123,8 @@ func ltoMutator(mctx android.BottomUpMutatorContext) { mctx.SetDependencyVariation("lto") } else if c.lto.Properties.LTODep { modules := mctx.CreateVariations("", "lto") - modules[0].(*Module).lto.Properties.Lto = boolPtr(false) - modules[1].(*Module).lto.Properties.Lto = boolPtr(true) + modules[0].(*Module).lto.Properties.Lto.Full = boolPtr(false) + modules[0].(*Module).lto.Properties.Lto.Thin = boolPtr(false) modules[0].(*Module).lto.Properties.LTODep = false modules[1].(*Module).lto.Properties.LTODep = false modules[1].(*Module).Properties.PreventInstall = true