Add opt-in option to turn on ThinLTO caching
Allow developers to enable ThinLTO caching on their local build by setting USE_THINLTO_CACHE environment variable. This significantly speeds up incremental ThinLTO builds by caching intermediate results. An incremental ART build (by `touch compiler/compiler.cc`) reduced from 01:32 to 00:45. We put the cache under out/soong/thinlto-cache as the cache can be valid across different targets, and allows us to set a global cache pruning policy. The current cache policy is sufficient for current list of ThinLTO-enabled projects, we can tune it up/down in the future. Test: USE_THINLTO_CACHE=true m Bug: 62839002 Change-Id: I4838fe833a1d8fbc73d743da6d19e3698dc89600
This commit is contained in:
parent
a052599bb6
commit
8aeaa7158a
15
cc/lto.go
15
cc/lto.go
|
@ -74,12 +74,27 @@ func (lto *lto) flags(ctx BaseModuleContext, flags Flags) Flags {
|
||||||
var ltoFlag string
|
var ltoFlag string
|
||||||
if Bool(lto.Properties.Lto.Thin) {
|
if Bool(lto.Properties.Lto.Thin) {
|
||||||
ltoFlag = "-flto=thin"
|
ltoFlag = "-flto=thin"
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ltoFlag = "-flto"
|
ltoFlag = "-flto"
|
||||||
}
|
}
|
||||||
|
|
||||||
flags.CFlags = append(flags.CFlags, ltoFlag)
|
flags.CFlags = append(flags.CFlags, ltoFlag)
|
||||||
flags.LdFlags = append(flags.LdFlags, ltoFlag)
|
flags.LdFlags = append(flags.LdFlags, ltoFlag)
|
||||||
|
|
||||||
|
if ctx.Config().IsEnvTrue("USE_THINLTO_CACHE") && Bool(lto.Properties.Lto.Thin) {
|
||||||
|
// Set appropriate ThinLTO cache policy
|
||||||
|
cacheDirFormat := "-Wl,-plugin-opt,cache-dir="
|
||||||
|
cacheDir := android.PathForOutput(ctx, "thinlto-cache").String()
|
||||||
|
flags.LdFlags = append(flags.LdFlags, cacheDirFormat+cacheDir)
|
||||||
|
|
||||||
|
// Limit the size of the ThinLTO cache to the lesser of 10% of available
|
||||||
|
// disk space and 10GB.
|
||||||
|
cachePolicyFormat := "-Wl,-plugin-opt,cache-policy="
|
||||||
|
policy := "cache_size=10%:cache_size_bytes=10g"
|
||||||
|
flags.LdFlags = append(flags.LdFlags, cachePolicyFormat+policy)
|
||||||
|
}
|
||||||
|
|
||||||
if ctx.Device() {
|
if ctx.Device() {
|
||||||
// Work around bug in Clang that doesn't pass correct emulated
|
// Work around bug in Clang that doesn't pass correct emulated
|
||||||
// TLS option to target. See b/72706604 or
|
// TLS option to target. See b/72706604 or
|
||||||
|
|
Loading…
Reference in New Issue