Skip to content

Commit

Permalink
Introduce FdoHelper
Browse files Browse the repository at this point in the history
    Fdo related logic is complicated enough to have it in a separate class.

    bazelbuild/bazel#6516

    RELNOTES: None
    PiperOrigin-RevId: 240376113
  • Loading branch information
Luca Di Grazia committed Sep 4, 2022
1 parent 72412d5 commit c580bf3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public static CcToolchainProvider getCcToolchainProvider(
CppToolchainInfo toolchainInfo =
getCppToolchainInfo(
ruleContext,
cppConfiguration.disableLegacyCrosstoolFields(),
cppConfiguration.disableGenruleCcToolchainDependency(),
cppConfiguration.getTransformedCpuFromOptions(),
cppConfiguration.getCompilerFromOptions(),
Expand Down Expand Up @@ -370,6 +371,7 @@ private static PathFragment calculateSysroot(
/** Finds an appropriate {@link CppToolchainInfo} for this target. */
private static CppToolchainInfo getCppToolchainInfo(
RuleContext ruleContext,
boolean disableLegacyCrosstoolFields,
boolean disableGenruleCcToolchainDependency,
String cpuFromOptions,
String compilerFromOptions,
Expand All @@ -386,6 +388,7 @@ private static CppToolchainInfo getCppToolchainInfo(
return CppToolchainInfo.create(
ruleContext.getLabel(),
configInfo,
disableLegacyCrosstoolFields,
disableGenruleCcToolchainDependency);
} catch (EvalException e) {
throw ruleContext.throwWithRuleError(e.getMessage());
Expand Down Expand Up @@ -415,10 +418,12 @@ private static CppToolchainInfo getCppToolchainInfo(
.getSkylarkSemantics()
.incompatibleDoNotSplitLinkingCmdline(),
CppToolchainInfo.getToolsDirectory(attributes.getCcToolchainLabel()));
CcToolchainConfigInfo ccToolchainConfigInfo = CcToolchainConfigInfo.fromToolchain(toolchain);
CcToolchainConfigInfo ccToolchainConfigInfo =
CcToolchainConfigInfo.fromToolchain(ruleContext, toolchain);
return CppToolchainInfo.create(
attributes.getCcToolchainLabel(),
ccToolchainConfigInfo,
disableLegacyCrosstoolFields,
disableGenruleCcToolchainDependency);
} catch (EvalException e) {
throw ruleContext.throwWithRuleError(e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,12 @@ public static FdoContext getFdoContext(
Artifact protoProfileArtifact = null;
Pair<FdoInputFile, Artifact> fdoInputs = null;
if (configuration.getCompilationMode() == CompilationMode.OPT) {
if (cppConfiguration
.getFdoPrefetchHintsLabelUnsafeSinceItCanReturnValueFromWrongConfiguration()
!= null) {
if (cppConfiguration.getFdoPrefetchHintsLabel() != null) {
FdoPrefetchHintsProvider provider = attributes.getFdoPrefetch();
prefetchHints = provider.getInputFile();
}
if (cppConfiguration.getFdoPathUnsafeSinceItCanReturnValueFromWrongConfiguration() != null) {
PathFragment fdoZip =
cppConfiguration.getFdoPathUnsafeSinceItCanReturnValueFromWrongConfiguration();
if (cppConfiguration.getFdoPath() != null) {
PathFragment fdoZip = cppConfiguration.getFdoPath();
SkyKey fdoKey = CcSkyframeFdoSupportValue.key(fdoZip);
SkyFunction.Environment skyframeEnv = ruleContext.getAnalysisEnvironment().getSkyframeEnv();
CcSkyframeFdoSupportValue ccSkyframeFdoSupportValue =
Expand All @@ -69,22 +66,16 @@ public static FdoContext getFdoContext(
Preconditions.checkState(fdoInputFile == null);
fdoInputFile =
FdoInputFile.fromAbsolutePath(ccSkyframeFdoSupportValue.getFdoZipPath().asFragment());
} else if (cppConfiguration
.getFdoOptimizeLabelUnsafeSinceItCanReturnValueFromWrongConfiguration()
!= null) {
} else if (cppConfiguration.getFdoOptimizeLabel() != null) {
FdoProfileProvider fdoProfileProvider = attributes.getFdoOptimizeProvider();
if (fdoProfileProvider != null) {
fdoInputs = getFdoInputs(ruleContext, fdoProfileProvider);
} else {
fdoInputFile = fdoInputFileFromArtifacts(ruleContext, attributes);
}
} else if (cppConfiguration
.getFdoProfileLabelUnsafeSinceItCanReturnValueFromWrongConfiguration()
!= null) {
} else if (cppConfiguration.getFdoProfileLabel() != null) {
fdoInputs = getFdoInputs(ruleContext, attributes.getFdoProfileProvider());
} else if (cppConfiguration
.getXFdoProfileLabelUnsafeSinceItCanReturnValueFromWrongConfiguration()
!= null) {
} else if (cppConfiguration.getXFdoProfileLabel() != null) {
fdoInputs = getFdoInputs(ruleContext, attributes.getXFdoProfileProvider());
}
}
Expand Down Expand Up @@ -116,8 +107,7 @@ public static FdoContext getFdoContext(
return null;
}
if (branchFdoMode != BranchFdoMode.XBINARY_FDO
&& cppConfiguration.getXFdoProfileLabelUnsafeSinceItCanReturnValueFromWrongConfiguration()
!= null) {
&& cppConfiguration.getXFdoProfileLabel() != null) {
ruleContext.throwWithRuleError(
"--xbinary_fdo cannot accept profile input other than *.xfdo");
}
Expand Down Expand Up @@ -240,13 +230,7 @@ private static Artifact convertLLVMRawProfileToIndexed(
// Get the zipper binary for unzipping the profile.
Artifact zipperBinaryArtifact = attributes.getZipper();
if (zipperBinaryArtifact == null) {
if (CppHelper.useToolchainResolution(ruleContext)) {
ruleContext.ruleError(
"Zipped profiles are not supported with platforms/toolchains before "
+ "toolchain-transitions are implemented.");
} else {
ruleContext.ruleError("Cannot find zipper binary to unzip the profile");
}
ruleContext.ruleError("Cannot find zipper binary to unzip the profile");
return null;
}

Expand Down

0 comments on commit c580bf3

Please sign in to comment.