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>2015-07-22 15:01:42 +0000
committerGravatar Laszlo Csomor <laszlocsomor@google.com>2015-07-23 11:00:16 +0000
commit53f5f3327c329cd036bb7cb63932e4bfcc248d9a (patch)
treea9781d6cfde676e07c7cdccfc10cc32d02610520 /src/main/java/com/google/devtools/build/lib/rules/cpp/FdoSupport.java
parentcbfda111b20a779d65b6598de64971d3384c41f9 (diff)
Rollforward of []: Blaze changes to support LLVM profile feedback
Rollback of commit b961bb931400044ed91e6b0b596f94fe983f9f17. -- MOS_MIGRATED_REVID=98833728
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.java44
1 files changed, 39 insertions, 5 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 592fe2c295..a2339c2b2a 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
@@ -121,13 +121,20 @@ public class FdoSupport {
private static final PathFragment ZIP_ROOT = new PathFragment("/");
/**
- * Returns true if the give fdoFile represents an AutoFdo profile.
+ * Returns true if the given fdoFile represents an AutoFdo profile.
*/
public static final boolean isAutoFdo(String fdoFile) {
return CppFileTypes.GCC_AUTO_PROFILE.matches(fdoFile);
}
/**
+ * Returns true if the given fdoFile represents an LLVM profile.
+ */
+ public static final boolean isLLVMFdo(String fdoFile) {
+ return CppFileTypes.LLVM_PROFILE.matches(fdoFile);
+ }
+
+ /**
* Coverage information output directory passed to {@code --fdo_instrument},
* or {@code null} if FDO instrumentation is disabled.
*/
@@ -173,6 +180,12 @@ public class FdoSupport {
private final boolean useAutoFdo;
/**
+ * Flag indicating whether to use LLVM instrumentation-based FDO (as
+ * opposed to GCC instrumentation-based FDO).
+ */
+ private final boolean useLLVMFdo;
+
+ /**
* The {@code .gcda} files that have been extracted from the ZIP file,
* relative to the root of the ZIP file.
*
@@ -217,6 +230,7 @@ public class FdoSupport {
fdoProfile.getBaseName()));
this.lipoMode = lipoMode;
this.useAutoFdo = fdoProfile != null && isAutoFdo(fdoProfile.getBaseName());
+ this.useLLVMFdo = fdoProfile != null && isLLVMFdo(fdoProfile.getBaseName());
}
public Root getFdoRoot() {
@@ -276,6 +290,9 @@ public class FdoSupport {
}
FileSystemUtils.ensureSymbolicLink(
execRoot.getRelative(getAutoProfilePath()), fdoProfile);
+ } else if (useLLVMFdo) {
+ FileSystemUtils.ensureSymbolicLink(
+ execRoot.getRelative(getLLVMProfilePath()), fdoProfile);
} else {
Path zipFilePath = new ZipFileSystem(fdoProfile).getRootDirectory();
if (!zipFilePath.getRelative("blaze-out").isDirectory()) {
@@ -477,8 +494,13 @@ public class FdoSupport {
getAutoProfilePath().getPathString());
}
if (featureConfiguration.isEnabled(CppRuleClasses.FDO_OPTIMIZE)) {
- buildVariables.addVariable("fdo_profile_path",
- fdoRootExecPath.getPathString());
+ if (useLLVMFdo) {
+ buildVariables.addVariable("fdo_profile_path",
+ getLLVMProfilePath().getPathString());
+ } else {
+ buildVariables.addVariable("fdo_profile_path",
+ fdoRootExecPath.getPathString());
+ }
}
} else {
// TODO(bazel-team): Remove this workaround once the feature configuration
@@ -516,11 +538,14 @@ public class FdoSupport {
// If --fdo_optimize was not specified, we don't have any additional inputs.
if (fdoProfile == null) {
return ImmutableSet.of();
- } else if (useAutoFdo) {
+ } else if (useAutoFdo || useLLVMFdo) {
ImmutableSet.Builder<Artifact> auxiliaryInputs = ImmutableSet.builder();
+ PathFragment profileRootRelativePath = (useLLVMFdo)
+ ? getLLVMProfileRootRelativePath()
+ : getAutoProfileRootRelativePath();
Artifact artifact = env.getDerivedArtifact(
- fdoPath.getRelative(getAutoProfileRootRelativePath()), fdoRoot);
+ fdoPath.getRelative(profileRootRelativePath), fdoRoot);
env.registerAction(new FdoStubAction(ruleContext.getActionOwner(), artifact));
auxiliaryInputs.add(artifact);
if (lipoContextProvider != null) {
@@ -624,6 +649,15 @@ public class FdoSupport {
return new PathFragment(fdoProfile.getBaseName());
}
+
+ private PathFragment getLLVMProfilePath() {
+ return fdoRootExecPath.getRelative(getLLVMProfileRootRelativePath());
+ }
+
+ private PathFragment getLLVMProfileRootRelativePath() {
+ return new PathFragment(fdoProfile.getBaseName());
+ }
+
/**
* Returns whether LIPO is enabled.
*/