aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2018-06-06 11:45:28 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-06-06 11:47:08 -0700
commit52fa20f5830c2500f5f0f6c9f4522bf75583ce36 (patch)
tree0fd94fcebe75987fdb048155bfa79b397e3df6f6 /src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java
parent4c72a82ada742bd369185cd07c57f96c497ce440 (diff)
Build support for enabling cross binary FDO optimization.
Crossbinary FDO optimization is a special form of AutoFDO which uses a synthetic profile to optimize targets without any profile. The synthetic profile will often be used as a default profile and will use .xfdo as suffix. It will be passed though option -fdo_optimize just like Autofdo profile. If .xfdo file is passed through -fdo_optimize in the same command line with other types of profiles, .xfdo file will be neglected. RELNOTES: Build support for enabling cross binary FDO optimization. PiperOrigin-RevId: 199501260
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java
index f657c0775b..ddbe96e913 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java
@@ -152,6 +152,9 @@ public class FdoSupport {
/** FDO based on automatically collected data. */
AUTO_FDO,
+ /** FDO based on cross binary collected data. */
+ XBINARY_FDO,
+
/** Instrumentation-based FDO implemented on LLVM. */
LLVM_FDO,
}
@@ -371,7 +374,7 @@ public class FdoSupport {
FileSystemUtils.deleteTreesBelow(fdoDirPath);
FileSystemUtils.createDirectoryAndParents(fdoDirPath);
- if (fdoMode == FdoMode.AUTO_FDO) {
+ if (fdoMode == FdoMode.AUTO_FDO || fdoMode == FdoMode.XBINARY_FDO) {
if (lipoMode != LipoMode.OFF) {
imports = readAutoFdoImports(getAutoFdoImportsPath(fdoProfile));
}
@@ -636,7 +639,8 @@ public class FdoSupport {
ruleContext, sourceName, sourceExecPath, outputName, usePic, fdoSupportProvider);
builder.addMandatoryInputs(auxiliaryInputs);
if (!Iterables.isEmpty(auxiliaryInputs)) {
- if (featureConfiguration.isEnabled(CppRuleClasses.AUTOFDO)) {
+ if (featureConfiguration.isEnabled(CppRuleClasses.AUTOFDO)
+ || featureConfiguration.isEnabled(CppRuleClasses.XBINARYFDO)) {
variablesBuilder.put(
CompileBuildVariables.FDO_PROFILE_PATH.getVariableName(),
getAutoProfilePath(fdoProfile, fdoRootExecPath).getPathString());
@@ -678,7 +682,9 @@ public class FdoSupport {
// If --fdo_optimize was not specified, we don't have any additional inputs.
if (fdoProfile == null) {
return auxiliaryInputs.build();
- } else if (fdoMode == FdoMode.LLVM_FDO || fdoMode == FdoMode.AUTO_FDO) {
+ } else if (fdoMode == FdoMode.LLVM_FDO
+ || fdoMode == FdoMode.AUTO_FDO
+ || fdoMode == FdoMode.XBINARY_FDO) {
auxiliaryInputs.add(fdoSupportProvider.getProfileArtifact());
if (lipoContextProvider != null) {
auxiliaryInputs.addAll(getAutoFdoImports(ruleContext, sourceExecPath, lipoContextProvider));
@@ -795,6 +801,12 @@ public class FdoSupport {
return fdoMode == FdoMode.AUTO_FDO;
}
+ /** Returns whether crossbinary FDO is enabled. */
+ @ThreadSafe
+ public boolean isXBinaryFdoEnabled() {
+ return fdoMode == FdoMode.XBINARY_FDO;
+ }
+
/**
* Adds the FDO profile output path to the variable builder. If FDO is disabled, no build variable
* is added.
@@ -821,7 +833,8 @@ public class FdoSupport {
if (prefetch != null) {
buildVariables.addStringVariable("fdo_prefetch_hints_path", prefetch.getExecPathString());
}
- if (!featureConfiguration.isEnabled(CppRuleClasses.AUTOFDO)) {
+ if (!featureConfiguration.isEnabled(CppRuleClasses.AUTOFDO)
+ && !featureConfiguration.isEnabled(CppRuleClasses.XBINARYFDO)) {
return new ProfileArtifacts(null, prefetch);
}