Skip to content

Commit d6e0562

Browse files
committed
[ThinLTO][Cache] When remote caching is enabled, use the passed-in thin-LTO cache as temp directory
This ensures that we can move cached artifacts from the remote service to the temp directory because they should be on the same disk volume. rdar://126211886
1 parent 6aecf56 commit d6e0562

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

llvm/include/llvm/LTO/legacy/ThinLTOCodeGenerator.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,12 @@ class ThinLTOCodeGenerator {
244244
/// the processing.
245245
void setSaveTempsDir(std::string Path) { SaveTempsDir = std::move(Path); }
246246

247+
/// Set the path to a directory where to save temporaries from the remote
248+
/// service.
249+
void setRemoteServiceTempsDir(std::string Path) {
250+
RemoteServiceTempsDir = std::move(Path);
251+
}
252+
247253
/// Set the path to a directory where to save generated object files. This
248254
/// path can be used by a linker to request on-disk files instead of in-memory
249255
/// buffers. When set, results are available through getProducedBinaryFiles()
@@ -385,6 +391,9 @@ class ThinLTOCodeGenerator {
385391
/// Path to a directory to save the temporary bitcode files.
386392
std::string SaveTempsDir;
387393

394+
/// Path to a directory to save the temporary remote service files.
395+
std::string RemoteServiceTempsDir;
396+
388397
/// Path to a directory to save the generated object files.
389398
std::string SavedObjectsDirectoryPath;
390399

llvm/lib/LTO/ThinLTOCodeGenerator.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,6 +1582,8 @@ void ThinLTOCodeGenerator::run() {
15821582
// First, we need to remember whether the caller requests buffer API or file
15831583
// API based on if the SavedObjectsDirectoryPath was set or not.
15841584
bool UseBufferAPI = SavedObjectsDirectoryPath.empty();
1585+
if (SavedObjectsDirectoryPath.empty())
1586+
SavedObjectsDirectoryPath = RemoteServiceTempsDir;
15851587
std::string TempDirectory;
15861588
if (CacheOptions.Type == CachingOptions::CacheType::RemoteService &&
15871589
SavedObjectsDirectoryPath.empty()) {

llvm/tools/lto/lto.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,10 @@ void thinlto_codegen_set_cpu(thinlto_code_gen_t cg, const char *cpu) {
619619

620620
void thinlto_codegen_set_cache_dir(thinlto_code_gen_t cg,
621621
const char *cache_dir) {
622+
if (sys::Process::GetEnv("LLVM_THINLTO_USE_REMOTE_CACHE")) {
623+
unwrap(cg)->setRemoteServiceTempsDir(cache_dir);
624+
return;
625+
}
622626
// FIXME: need to return error somehow.
623627
Error Err = unwrap(cg)->setCacheDir(cache_dir);
624628
if (Err)

0 commit comments

Comments
 (0)