From 9723e338ee143a4daff826a521ecd3672adf1b32 Mon Sep 17 00:00:00 2001 From: Yi Kong Date: Mon, 4 Dec 2023 14:52:53 +0900 Subject: [PATCH] Do not perform AFDO or optimizing LTO for eng builds Afdo creates more variants to build, and optimizing LTO is costly to perform. Turn off these two optimizations for eng builds for a faster build speed. This reduces total C/C++ invocation time for aosp_arm64-eng by 6.28%. Test: presubmit Bug: 307753064 Change-Id: Ibac4269c66a64e896dba2074b607d71a2da37546 --- cc/afdo.go | 7 +++++++ cc/cc.go | 3 +++ cc/lto.go | 3 ++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/cc/afdo.go b/cc/afdo.go index 91cf0b8a2..e7dea0e0d 100644 --- a/cc/afdo.go +++ b/cc/afdo.go @@ -64,6 +64,13 @@ func (afdo *afdo) props() []interface{} { return []interface{}{&afdo.Properties} } +func (afdo *afdo) begin(ctx BaseModuleContext) { + // Disable on eng builds for faster build. + if ctx.Config().Eng() { + afdo.Properties.Afdo = false + } +} + // afdoEnabled returns true for binaries and shared libraries // that set afdo prop to True and there is a profile available func (afdo *afdo) afdoEnabled() bool { diff --git a/cc/cc.go b/cc/cc.go index 867a59c03..2e42761c4 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -2401,6 +2401,9 @@ func (c *Module) begin(ctx BaseModuleContext) { if c.coverage != nil { c.coverage.begin(ctx) } + if c.afdo != nil { + c.afdo.begin(ctx) + } if c.lto != nil { c.lto.begin(ctx) } diff --git a/cc/lto.go b/cc/lto.go index d2a43d27b..8b0880cf0 100644 --- a/cc/lto.go +++ b/cc/lto.go @@ -116,7 +116,8 @@ func (lto *lto) flags(ctx BaseModuleContext, flags Flags) Flags { // better dead code elimination and CFG simplification, but do // not perform costly optimizations for a balance between compile // time, binary size and performance. - if !lto.ThinLTO() { + // Apply the same for Eng builds as well. + if !lto.ThinLTO() || ctx.Config().Eng() { ltoLdFlags = append(ltoLdFlags, "-Wl,--lto-O0") }