Skip to content

Commit 20f6afd

Browse files
Add MCCAS support to SwiftCaching.cpp
To materialize the object file correctly on a cache hit when MCCAS is enabled, if lib_InternalSwiftScan.dylib is used to detect the cache hit, we need to add MCCAS support to the replay code in SwiftCaching.cpp
1 parent 2ec23ae commit 20f6afd

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

lib/Frontend/CachingUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ bool replayCachedCompilerOutputs(
286286
toString(File.takeError()));
287287
continue;
288288
}
289-
289+
290290
if (UseCASBackend && Output.Path == ObjFile) {
291291
auto Schema = std::make_unique<llvm::mccasformats::v1::MCSchema>(CAS);
292292
if (auto E = Schema->serializeObjectFile(Output.Proxy, *File))

tools/libSwiftScan/SwiftCaching.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "llvm/CAS/BuiltinUnifiedCASDatabases.h"
4040
#include "llvm/CAS/CASReference.h"
4141
#include "llvm/CAS/ObjectStore.h"
42+
#include "llvm/MCCAS/MCCASObjectV1.h"
4243
#include "llvm/Support/Allocator.h"
4344
#include "llvm/Support/Endian.h"
4445
#include "llvm/Support/Error.h"
@@ -940,6 +941,8 @@ static llvm::Error replayCompilation(SwiftScanReplayInstance &Instance,
940941
};
941942
SmallVector<OutputEntry> OutputProxies;
942943
std::optional<llvm::cas::ObjectProxy> DiagnosticsOutput;
944+
bool UseCASBackend = Invocation.getIRGenOptions().UseCASBackend;
945+
std::string ObjFile;
943946

944947
swift::cas::CachedResultLoader Loader(CAS, Comp.Output);
945948
if (auto Err = Loader.replay(
@@ -953,6 +956,9 @@ static llvm::Error replayCompilation(SwiftScanReplayInstance &Instance,
953956
if (!Proxy)
954957
return Proxy.takeError();
955958

959+
if (Kind == file_types::ID::TY_Object && UseCASBackend)
960+
ObjFile = OutputPath->second;
961+
956962
if (Kind == file_types::ID::TY_CachedDiagnostics) {
957963
assert(!DiagnosticsOutput && "more than 1 diagnostics found");
958964
DiagnosticsOutput = std::move(*Proxy);
@@ -1000,8 +1006,13 @@ static llvm::Error replayCompilation(SwiftScanReplayInstance &Instance,
10001006
auto File = Backend.createFile(Output.Path);
10011007
if (!File)
10021008
return File.takeError();
1003-
1004-
*File << Output.Proxy.getData();
1009+
if (UseCASBackend && Output.Path == ObjFile) {
1010+
auto Schema = std::make_unique<llvm::mccasformats::v1::MCSchema>(CAS);
1011+
if (auto E = Schema->serializeObjectFile(Output.Proxy, *File))
1012+
Inst.getDiags().diagnose(SourceLoc(), diag::error_mccas,
1013+
toString(std::move(E)));
1014+
} else
1015+
*File << Output.Proxy.getData();
10051016
if (auto E = File->keep())
10061017
return E;
10071018

0 commit comments

Comments
 (0)