Skip to content

Commit

Permalink
Support of using the absolute path profile for LLVM's Context Sensiti…
Browse files Browse the repository at this point in the history
…ve FDO

This CL adds the support of using the absolute path profile in LLVM's Context
Sensitive FDO. The newly added option is
    --cs_fdo_absolute_path=<csfdo_profile>
The profile can be of the zip file containing the profile file, a raw or an
indexed LLVM profile file. Unlike --fdo_optimize, it will not accept a profile label.
Profile label should should use option --cs_fdo_profile.

RELNOTES: Add new options --cs_fdo_absolute_path= to support the absolute path
profile for LLVM's context-sensitive FDO.
PiperOrigin-RevId: 251252510
  • Loading branch information
Googler authored and Copybara-Service committed Jun 3, 2019
1 parent 5935259 commit fe81b49
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ public String toString() {
private final PathFragment fdoPath;
private final Label fdoOptimizeLabel;

private final PathFragment csFdoAbsolutePath;

private final ImmutableList<String> conlyopts;

private final ImmutableList<String> copts;
Expand Down Expand Up @@ -197,13 +199,30 @@ static CppConfiguration create(CpuTransformer cpuTransformer, BuildOptions optio
}
}

PathFragment csFdoAbsolutePath = null;
if (cppOptions.csFdoAbsolutePathForBuild != null) {
csFdoAbsolutePath = PathFragment.create(cppOptions.csFdoAbsolutePathForBuild);
if (!csFdoAbsolutePath.isAbsolute()) {
throw new InvalidConfigurationException(
"Path of '"
+ csFdoAbsolutePath.getPathString()
+ "' in --cs_fdo_absolute_path is not an absolute path.");
}
try {
FileSystemUtils.checkBaseName(csFdoAbsolutePath.getBaseName());
} catch (IllegalArgumentException e) {
throw new InvalidConfigurationException(e);
}
}

return new CppConfiguration(
cppOptions.doNotUseCpuTransformer
? commonOptions.cpu
: cpuTransformer.getTransformer().apply(commonOptions.cpu),
Preconditions.checkNotNull(commonOptions.cpu),
fdoPath,
fdoProfileLabel,
csFdoAbsolutePath,
ImmutableList.copyOf(cppOptions.conlyoptList),
ImmutableList.copyOf(cppOptions.coptList),
ImmutableList.copyOf(cppOptions.cxxoptList),
Expand All @@ -224,6 +243,7 @@ private CppConfiguration(
String desiredCpu,
PathFragment fdoPath,
Label fdoOptimizeLabel,
PathFragment csFdoAbsolutePath,
ImmutableList<String> conlyopts,
ImmutableList<String> copts,
ImmutableList<String> cxxopts,
Expand All @@ -239,6 +259,7 @@ private CppConfiguration(
this.desiredCpu = desiredCpu;
this.fdoPath = fdoPath;
this.fdoOptimizeLabel = fdoOptimizeLabel;
this.csFdoAbsolutePath = csFdoAbsolutePath;
this.conlyopts = conlyopts;
this.copts = copts;
this.cxxopts = cxxopts;
Expand Down Expand Up @@ -548,6 +569,10 @@ public String getCSFdoInstrument() {
return cppOptions.csFdoInstrumentForBuild;
}

public PathFragment getCSFdoAbsolutePath() {
return csFdoAbsolutePath;
}

Label getFdoPrefetchHintsLabel() {
if (isThisHostConfigurationDoNotUseWillBeRemovedFor129045294()) {
// We don't want FDO in the host configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,17 @@ public String getFdoOptimize() {
+ "dumped at runtime.")
public String csFdoInstrumentForBuild;

@Option(
name = "cs_fdo_absolute_path",
defaultValue = "null",
documentationCategory = OptionDocumentationCategory.OUTPUT_PARAMETERS,
effectTags = {OptionEffectTag.AFFECTS_OUTPUTS},
help =
"Use CSFDO profile information to optimize compilation. Specify the absolute path name "
+ "of the zip file containing the profile file, a raw or an indexed "
+ "LLVM profile file.")
public String csFdoAbsolutePathForBuild;

@Option(
name = "xbinary_fdo",
defaultValue = "null",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ public static FdoContext getFdoContext(
}

Pair<FdoInputFile, Artifact> csFdoInputs = null;
if (cppConfiguration.getCSFdoProfileLabel() != null) {
PathFragment csFdoZip = cppConfiguration.getCSFdoAbsolutePath();
if (csFdoZip != null) {
csFdoInputFile = FdoInputFile.fromAbsolutePath(csFdoZip);
} else if (cppConfiguration.getCSFdoProfileLabel() != null) {
csFdoInputs = getFdoInputs(ruleContext, attributes.getCSFdoProfileProvider());
}
if (csFdoInputs != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,24 @@ public void testFdoOptimizeNotCompatibleWithCoverage() throws Exception {
assertContainsEvent("coverage mode is not compatible with FDO optimization");
}

@Test
public void testCSFdoRejectRelativePath() throws Exception {
reporter.removeHandler(failFastHandler);
scratch.file("a/BUILD", "cc_toolchain_alias(name = 'b')");
scratch.file("a/profile.profdata", "");
scratch.file("a/csprofile.profdata", "");
Exception e =
assertThrows(
Exception.class,
() ->
useConfiguration(
"-c",
"opt",
"--fdo_optimize=a/profile.profdata",
"--cs_fdo_absolute_path=a/csprofile.profdata"));
assertThat(e).hasMessageThat().contains("in --cs_fdo_absolute_path is not an absolute path");
}

@Test
public void testXFdoOptimizeNotProvider() throws Exception {
reporter.removeHandler(failFastHandler);
Expand Down

0 comments on commit fe81b49

Please sign in to comment.