diff options
Diffstat (limited to 'src/main/java/com')
4 files changed, 51 insertions, 11 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java index 3af52e31c2..dfbf191f82 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppConfiguration.java @@ -841,7 +841,8 @@ public class CppConfiguration extends BuildConfiguration.Fragment { + " action: 'c++-compile'" + " action: 'c++-link'" + " flag_group {" - + " flag: '-fprofile-generate=%{fdo_instrument_path}'" + + " flag: '-Xgcc-only=-fprofile-generate=%{fdo_instrument_path}'" + + " flag: '-Xclang-only=-fprofile-instr-generate=%{fdo_instrument_path}'" + " }" + " flag_group {" + " flag: '-fno-data-sections'" @@ -858,7 +859,10 @@ public class CppConfiguration extends BuildConfiguration.Fragment { + " action: 'c-compile'" + " action: 'c++-compile'" + " flag_group {" - + " flag: '-fprofile-use=%{fdo_profile_path}'" + + " flag: '-Xgcc-only=-fprofile-use=%{fdo_profile_path}'" + + " flag: '-Xclang-only=-fprofile-instr-use=%{fdo_profile_path}'" + + " flag: '-Xclang-only=-Wno-profile-instr-unprofiled'" + + " flag: '-Xclang-only=-Wno-profile-instr-out-of-date'" + " flag: '-fprofile-correction'" + " }" + " }" diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java index 0d19b9ab42..a1a371b8de 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppFileTypes.java @@ -132,6 +132,7 @@ public final class CppFileTypes { public static final FileType COVERAGE_DATA = FileType.of(".gcda"); public static final FileType COVERAGE_DATA_IMPORTS = FileType.of(".gcda.imports"); public static final FileType GCC_AUTO_PROFILE = FileType.of(".afdo"); + public static final FileType LLVM_PROFILE = FileType.of(".profdata"); public static final FileType CPP_MODULE_MAP = FileType.of(".cppmap"); public static final FileType CPP_MODULE = FileType.of(".pcm"); diff --git a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java index 02a6eb91a1..7915bb2916 100644 --- a/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java +++ b/src/main/java/com/google/devtools/build/lib/rules/cpp/CppOptions.java @@ -192,8 +192,8 @@ public class CppOptions extends FragmentOptions { @Option(name = "thin_archives", defaultValue = "false", category = "strategy", // but also adds edges to the action graph - help = "Pass the 'T' flag to ar if supported by the toolchain. " + - "All supported toolchains support this setting.") + help = "Pass the 'T' flag to ar if supported by the toolchain. " + + "All supported toolchains support this setting.") public boolean useThinArchives; // O intrepid reaper of unused options: Be warned that the [no]start_end_lib @@ -353,7 +353,8 @@ public class CppOptions extends FragmentOptions { category = "flags", implicitRequirements = {"--copt=-Wno-error"}, help = "Generate binaries with FDO instrumentation. Specify the relative " + - "directory name for the .gcda files at runtime.") + "directory name for the .gcda files at runtime. It also accepts " + + "an LLVM profile output file path.") public PathFragment fdoInstrument; @Option(name = "fdo_optimize", @@ -364,7 +365,7 @@ public class CppOptions extends FragmentOptions { "an auto profile. This flag also accepts files specified as labels, for " + "example //foo/bar:file.afdo. Such labels must refer to input files; you may " + "need to add an exports_files directive to the corresponding package to make " + - "the file visible to Blaze.") + "the file visible to Blaze. It also accepts an indexed LLVM profile file.") public String fdoOptimize; @Option(name = "autofdo_lipo_data", 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 c425820565..c960ef8912 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 { FileSystemUtils.removeExtension(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. */ |