Add PGO support to soong
Bug: http://b/63768402
Bug: http://b/65598278
Add support for the 'pgo' property to specify how a module is processed
under PGO. A sample property is below:
pgo: {
instrumentation: true, // could be "sampling: true" when supported
profile_file: "pgo_simple.profdata",
benchmarks: ["pgo_simple"],
}
1. Runtime profiles can be gathered using "sampling" or
"instrumentation". Sampling is not supported initially.
2. If 'toolchain/pgo-profiles' project is found,
'toolchain/pgo-profiles/${profile_file}' is passed to the compiler and
linker when building this module.
3. If ANDROID_PGO_INSTRUMENT environment variable is set, and includes a
benchmark in the 'benchmarks' list, appropriate flags (for e.g.
-fprofile-generate for instrumentation) are passed to the compiler and
linker when building this module.
Test: Add example modules that specify the pgo property and verify
appropriate flags and dependencies in the Ninja file. Some
tests/examples are in https://android-review.googlesource.com/474805
Change-Id: I6242e0c904497a115e367dea6927ba1c4b906355
diff --git a/cc/cc.go b/cc/cc.go
index af58f9d..b4b70ed 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -134,7 +134,8 @@
RequiredInstructionSet string
DynamicLinker string
- CFlagsDeps android.Paths // Files depended on by compiler flags
+ CFlagsDeps android.Paths // Files depended on by compiler flags
+ LdFlagsDeps android.Paths // Files depended on by linker flags
GroupStaticLibs bool
}
@@ -308,6 +309,7 @@
sabi *sabi
vndkdep *vndkdep
lto *lto
+ pgo *pgo
androidMkSharedLibDeps []string
@@ -350,6 +352,9 @@
if c.lto != nil {
c.AddProperties(c.lto.props()...)
}
+ if c.pgo != nil {
+ c.AddProperties(c.pgo.props()...)
+ }
for _, feature := range c.features {
c.AddProperties(feature.props()...)
}
@@ -506,6 +511,7 @@
module.sabi = &sabi{}
module.vndkdep = &vndkdep{}
module.lto = <o{}
+ module.pgo = &pgo{}
return module
}
@@ -557,6 +563,9 @@
if c.lto != nil {
flags = c.lto.flags(ctx, flags)
}
+ if c.pgo != nil {
+ flags = c.pgo.flags(ctx, flags)
+ }
for _, feature := range c.features {
flags = feature.flags(ctx, flags)
}
@@ -643,6 +652,9 @@
if c.lto != nil {
c.lto.begin(ctx)
}
+ if c.pgo != nil {
+ c.pgo.begin(ctx)
+ }
for _, feature := range c.features {
feature.begin(ctx)
}
@@ -1250,6 +1262,7 @@
&SAbiProperties{},
&VndkProperties{},
<OProperties{},
+ &PgoProperties{},
)
android.InitDefaultsModule(module)