Skip to content

Commit 2a94cd8

Browse files
[CAS][LTO] Move setCacheDir function into .cpp file
setCacheDir function calls into CAS/RemoteCachingService creating function that will add extra dependency for the tools that calls this method. Fold the call into libLLVMLTO since this function is not in critical path that inlining will help performance. rdar://104907472 (cherry picked from commit 832f52c)
1 parent 0791cb7 commit 2a94cd8

File tree

2 files changed

+36
-34
lines changed

2 files changed

+36
-34
lines changed

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

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -166,40 +166,7 @@ class ThinLTOCodeGenerator {
166166

167167
/// Provide a path to a directory where to store the cached files for
168168
/// incremental build.
169-
Error setCacheDir(std::string Path) {
170-
// CacheDir can only be set once.
171-
if (!CacheOptions.Path.empty())
172-
return Error::success();
173-
174-
StringRef PathStr = Path;
175-
// The environment overwrites the option parameter.
176-
if (PathStr.consume_front("cas:")) {
177-
CacheOptions.Type = CachingOptions::CacheType::CAS;
178-
// Create ObjectStore and ActionCache.
179-
auto MaybeCAS = cas::createOnDiskCAS(PathStr);
180-
if (!MaybeCAS)
181-
return MaybeCAS.takeError();
182-
CacheOptions.CAS = std::move(*MaybeCAS);
183-
auto MaybeCache = cas::createOnDiskActionCache(PathStr);
184-
if (!MaybeCache)
185-
return MaybeCache.takeError();
186-
CacheOptions.Cache = std::move(*MaybeCache);
187-
CacheOptions.Path = PathStr.str();
188-
} else if (PathStr.consume_front("grpc:")) {
189-
CacheOptions.Type = CachingOptions::CacheType::RemoteService;
190-
auto MaybeService =
191-
cas::remote::createCompilationCachingRemoteClient(PathStr);
192-
if (!MaybeService)
193-
return MaybeService.takeError();
194-
CacheOptions.Service = std::move(*MaybeService);
195-
CacheOptions.Path = PathStr.str();
196-
} else {
197-
CacheOptions.Type = CachingOptions::CacheType::CacheDirectory;
198-
CacheOptions.Path = std::move(Path);
199-
}
200-
201-
return Error::success();
202-
}
169+
Error setCacheDir(std::string Path);
203170

204171
/// Create a cache entry for the module
205172
std::unique_ptr<ModuleCacheEntry> createModuleCacheEntry(

llvm/lib/LTO/ThinLTOCodeGenerator.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,41 @@ Error ModuleCacheEntry::writeObject(const MemoryBuffer &OutputBuffer,
843843
return Error::success();
844844
}
845845

846+
Error ThinLTOCodeGenerator::setCacheDir(std::string Path) {
847+
// CacheDir can only be set once.
848+
if (!CacheOptions.Path.empty())
849+
return Error::success();
850+
851+
StringRef PathStr = Path;
852+
// The environment overwrites the option parameter.
853+
if (PathStr.consume_front("cas:")) {
854+
CacheOptions.Type = CachingOptions::CacheType::CAS;
855+
// Create ObjectStore and ActionCache.
856+
auto MaybeCAS = cas::createOnDiskCAS(PathStr);
857+
if (!MaybeCAS)
858+
return MaybeCAS.takeError();
859+
CacheOptions.CAS = std::move(*MaybeCAS);
860+
auto MaybeCache = cas::createOnDiskActionCache(PathStr);
861+
if (!MaybeCache)
862+
return MaybeCache.takeError();
863+
CacheOptions.Cache = std::move(*MaybeCache);
864+
CacheOptions.Path = PathStr.str();
865+
} else if (PathStr.consume_front("grpc:")) {
866+
CacheOptions.Type = CachingOptions::CacheType::RemoteService;
867+
auto MaybeService =
868+
cas::remote::createCompilationCachingRemoteClient(PathStr);
869+
if (!MaybeService)
870+
return MaybeService.takeError();
871+
CacheOptions.Service = std::move(*MaybeService);
872+
CacheOptions.Path = PathStr.str();
873+
} else {
874+
CacheOptions.Type = CachingOptions::CacheType::CacheDirectory;
875+
CacheOptions.Path = std::move(Path);
876+
}
877+
878+
return Error::success();
879+
}
880+
846881
std::unique_ptr<ModuleCacheEntry> ThinLTOCodeGenerator::createModuleCacheEntry(
847882
const ModuleSummaryIndex &Index, StringRef ModuleID, StringRef OutputPath,
848883
const FunctionImporter::ImportMapTy &ImportList,

0 commit comments

Comments
 (0)