aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Googler <noreply@google.com>2017-01-18 17:13:15 +0000
committerGravatar Vladimir Moskva <vladmos@google.com>2017-01-18 18:34:05 +0000
commit227a06872dd5e1a2ca32655ad699848b3651db36 (patch)
tree557360c82a54948e6dc18f39809c6c3acd237738
parent0a08c0bef9ac5509a7b144328a828acd505d0a38 (diff)
Pass AutoFDO profiles to LTO backend.
-- PiperOrigin-RevId: 144841772 MOS_MIGRATED_REVID=144841772
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java19
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/cpp/LTOBackendArtifacts.java5
-rw-r--r--src/test/java/com/google/devtools/build/lib/packages/util/MockCcSupport.java17
3 files changed, 41 insertions, 0 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 1e37bda60c..6a0b231914 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
@@ -702,6 +702,25 @@ public class FdoSupport {
}
/**
+ * Adds the AutoFDO profile path to the variable builder and returns the profile artifact.
+ * If AutoFDO is disabled, no build variable is added and returns null.
+ */
+ @ThreadSafe
+ public Artifact buildProfileForLtoBackend(FeatureConfiguration featureConfiguration,
+ CcToolchainFeatures.Variables.Builder buildVariables, RuleContext ruleContext) {
+ if (!featureConfiguration.isEnabled(CppRuleClasses.AUTOFDO)) {
+ return null;
+ }
+ buildVariables.addStringVariable("fdo_profile_path", getAutoProfilePath(
+ fdoProfile, fdoRootExecPath).getPathString());
+ Artifact artifact = ruleContext.getAnalysisEnvironment().getDerivedArtifact(
+ fdoPath.getRelative(getAutoProfileRootRelativePath(fdoProfile)), fdoRoot);
+ ruleContext.getAnalysisEnvironment().registerAction(
+ new FdoStubAction(ruleContext.getActionOwner(), artifact));
+ return artifact;
+ }
+
+ /**
* Returns the path of the FDO output tree (relative to the execution root)
* containing the .gcda profile files, or null if FDO is not enabled.
*/
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/LTOBackendArtifacts.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/LTOBackendArtifacts.java
index 05907badd8..1d2a25c9af 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/cpp/LTOBackendArtifacts.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/LTOBackendArtifacts.java
@@ -134,6 +134,11 @@ public final class LTOBackendArtifacts {
// The input to the LTO backend step is the bitcode file.
buildVariablesBuilder.addStringVariable(
"thinlto_input_bitcode_file", bitcodeFile.getExecPath().toString());
+ Artifact autoFdoProfile = CppHelper.getFdoSupport(ruleContext).buildProfileForLtoBackend(
+ featureConfiguration, buildVariablesBuilder, ruleContext);
+ if (autoFdoProfile != null) {
+ builder.addInput(autoFdoProfile);
+ }
Variables buildVariables = buildVariablesBuilder.build();
List<String> execArgs = new ArrayList<>();
execArgs.addAll(featureConfiguration.getCommandLine("lto-backend", buildVariables));
diff --git a/src/test/java/com/google/devtools/build/lib/packages/util/MockCcSupport.java b/src/test/java/com/google/devtools/build/lib/packages/util/MockCcSupport.java
index 5c4bb7622f..f9969d1db0 100644
--- a/src/test/java/com/google/devtools/build/lib/packages/util/MockCcSupport.java
+++ b/src/test/java/com/google/devtools/build/lib/packages/util/MockCcSupport.java
@@ -234,6 +234,23 @@ public abstract class MockCcSupport {
+ " }"
+ "}";
+ public static final String AUTO_FDO_CONFIGURATION =
+ ""
+ + "feature {"
+ + " name: 'autofdo'"
+ + " provides: 'profile'"
+ + " flag_set {"
+ + " action: 'c-compile'"
+ + " action: 'c++-compile'"
+ + " action: 'lto-backend'"
+ + " expand_if_all_available: 'fdo_profile_path'"
+ + " flag_group {"
+ + " flag: '-fauto-profile=%{fdo_profile_path}'"
+ + " flag: '-fprofile-correction'"
+ + " }"
+ + " }"
+ + "}";
+
public static final String FDO_INSTRUMENT_CONFIGURATION =
""
+ "feature { "