[Frontend] Add a new -index-unit-ouput-path and filelist equivalent to the frontend

These new options mirror -o and -output-filelist and are used instead
of those options to supply the output file path(s) to record in the
index store. This is intended to allow sharing index data across
builds in separate directories that are otherwise equivalent as far
as the index data is concered (e.g. an ASAN build and a non-ASAN build)
by supplying the same -index-unit-output-path for both.

Resolves rdar://problem/74816412
This commit is contained in:
Nathan Hawes
2021-02-16 15:59:55 +10:00
parent 6e0267f6b8
commit 821345c834
14 changed files with 397 additions and 36 deletions

View File

@@ -322,7 +322,14 @@ bool FrontendInputsAndOutputs::forEachInputProducingAMainOutputFile(
void FrontendInputsAndOutputs::setMainAndSupplementaryOutputs(
ArrayRef<std::string> outputFiles,
ArrayRef<SupplementaryOutputPaths> supplementaryOutputs) {
ArrayRef<SupplementaryOutputPaths> supplementaryOutputs,
ArrayRef<std::string> outputFilesForIndexUnits) {
if (outputFilesForIndexUnits.empty())
outputFilesForIndexUnits = outputFiles;
assert(outputFiles.size() == outputFilesForIndexUnits.size() &&
"Must have one index unit output path per main output");
if (AllInputs.empty()) {
assert(outputFiles.empty() && "Cannot have outputs without inputs");
assert(supplementaryOutputs.empty() &&
@@ -340,7 +347,8 @@ void FrontendInputsAndOutputs::setMainAndSupplementaryOutputs(
for (auto &input : AllInputs) {
if (input.isPrimary()) {
input.setPrimarySpecificPaths(PrimarySpecificPaths(
outputFiles[i], input.getFileName(), supplementaryOutputs[i]));
outputFiles[i], outputFilesForIndexUnits[i], input.getFileName(),
supplementaryOutputs[i]));
++i;
}
}
@@ -350,7 +358,8 @@ void FrontendInputsAndOutputs::setMainAndSupplementaryOutputs(
"WMO only ever produces one set of supplementary outputs");
if (outputFiles.size() == 1) {
AllInputs.front().setPrimarySpecificPaths(PrimarySpecificPaths(
outputFiles.front(), firstInputProducingOutput().getFileName(),
outputFiles.front(), outputFilesForIndexUnits.front(),
firstInputProducingOutput().getFileName(),
supplementaryOutputs.front()));
return;
}
@@ -358,7 +367,7 @@ void FrontendInputsAndOutputs::setMainAndSupplementaryOutputs(
"Multi-threaded WMO requires one main output per input");
for (auto i : indices(AllInputs))
AllInputs[i].setPrimarySpecificPaths(PrimarySpecificPaths(
outputFiles[i], outputFiles[i],
outputFiles[i], outputFilesForIndexUnits[i], outputFiles[i],
i == 0 ? supplementaryOutputs.front() : SupplementaryOutputPaths()));
}
@@ -372,6 +381,17 @@ std::vector<std::string> FrontendInputsAndOutputs::copyOutputFilenames() const {
return outputs;
}
std::vector<std::string>
FrontendInputsAndOutputs::copyIndexUnitOutputFilenames() const {
std::vector<std::string> outputs;
(void)forEachInputProducingAMainOutputFile(
[&](const InputFile &input) -> bool {
outputs.push_back(input.indexUnitOutputFilename());
return false;
});
return outputs;
}
void FrontendInputsAndOutputs::forEachOutputFilename(
llvm::function_ref<void(StringRef)> fn) const {
(void)forEachInputProducingAMainOutputFile(
@@ -387,6 +407,12 @@ std::string FrontendInputsAndOutputs::getSingleOutputFilename() const {
: std::string();
}
std::string FrontendInputsAndOutputs::getSingleIndexUnitOutputFilename() const {
assertMustNotBeMoreThanOnePrimaryInputUnlessBatchModeChecksHaveBeenBypassed();
return hasInputs() ? lastInputProducingOutput().indexUnitOutputFilename()
: std::string();
}
bool FrontendInputsAndOutputs::isOutputFilenameStdout() const {
return getSingleOutputFilename() == "-";
}