Skip to content

Commit 31baf4f

Browse files
Store MCCAS ObjectRef as CASOutputBackend's main output.
This patch stores the MCCAS ObjectRef as the main output of the CASOutputBackend when MCCAS is enabled.
1 parent edae2e6 commit 31baf4f

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

include/swift/Frontend/CASOutputBackends.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ class SwiftCASOutputBackend : public llvm::vfs::OutputBackend {
4949
llvm::Error storeCachedDiagnostics(unsigned InputIndex,
5050
llvm::StringRef Bytes);
5151

52+
/// Store the MCCAS CASID \p ID as the object file output for the input
53+
/// that corresponds to the \p OutputFilename
54+
llvm::Error storeMCCASObjectID(StringRef OutputFilename, llvm::cas::CASID ID);
55+
5256
private:
5357
class Implementation;
5458
Implementation &Impl;

lib/Frontend/CASOutputBackends.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,21 @@ Error SwiftCASOutputBackend::storeCachedDiagnostics(unsigned InputIndex,
141141
file_types::ID::TY_CachedDiagnostics);
142142
}
143143

144+
Error SwiftCASOutputBackend::storeMCCASObjectID(StringRef OutputFilename,
145+
llvm::cas::CASID ID) {
146+
auto Input = Impl.OutputToInputMap.find(OutputFilename);
147+
if (Input == Impl.OutputToInputMap.end())
148+
return llvm::createStringError("InputIndex for output file not found!");
149+
auto InputIndex = Input->second.first;
150+
auto MCRef = Impl.CAS.getReference(ID);
151+
if (!MCRef)
152+
return createStringError("Invalid CASID: " + ID.toString() +
153+
". No associated ObjectRef found!");
154+
155+
Impl.OutputRefs[InputIndex].insert({file_types::TY_Object, *MCRef});
156+
return Impl.finalizeCacheKeysFor(InputIndex);
157+
}
158+
144159
void SwiftCASOutputBackend::Implementation::initBackend(
145160
const FrontendInputsAndOutputs &InputsAndOutputs) {
146161
// FIXME: The output to input map might not be enough for example all the

lib/FrontendTool/FrontendTool.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1735,6 +1735,18 @@ static bool generateCode(CompilerInstance &Instance, StringRef OutputFilename,
17351735
createTargetMachine(opts, Instance.getASTContext());
17361736

17371737
TargetMachine->Options.MCOptions.CAS = Instance.getSharedCASInstance();
1738+
1739+
if (Instance.getInvocation().getCASOptions().EnableCaching &&
1740+
opts.UseCASBackend)
1741+
TargetMachine->Options.MCOptions.ResultCallBack =
1742+
[&](const llvm::cas::CASID &ID) -> llvm::Error {
1743+
if (auto Err = Instance.getCASOutputBackend().storeMCCASObjectID(
1744+
OutputFilename, ID))
1745+
return Err;
1746+
1747+
return llvm::Error::success();
1748+
};
1749+
17381750
// Free up some compiler resources now that we have an IRModule.
17391751
freeASTContextIfPossible(Instance);
17401752

0 commit comments

Comments
 (0)