Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions llvm/tools/lto/lto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "llvm/LTO/legacy/LTOCodeGenerator.h"
#include "llvm/LTO/legacy/LTOModule.h"
#include "llvm/LTO/legacy/ThinLTOCodeGenerator.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/TargetSelect.h"
Expand All @@ -44,6 +45,29 @@ static cl::opt<bool> EnableFreestanding(
"lto-freestanding", cl::init(false),
cl::desc("Enable Freestanding (disable builtins / TLI) during LTO"));

static cl::opt<std::string> ThinLTOCacheDir(
"legacy-thinlto-cache-dir",
cl::desc("Experimental option, enable ThinLTO caching. Note: the cache "
"currently does not take the mcmodel setting into account, so you "
"might get false hits if different mcmodels are used in different "
"builds using the same cache directory."));

static cl::opt<int> ThinLTOCachePruningInterval(
"legacy-thinlto-cache-pruning-interval", cl::init(1200),
cl::desc("Set ThinLTO cache pruning interval (seconds)."));

static cl::opt<uint64_t> ThinLTOCacheMaxSizeBytes(
"legacy-thinlto-cache-max-size-bytes",
cl::desc("Set ThinLTO cache pruning directory maximum size in bytes."));

static cl::opt<int> ThinLTOCacheMaxSizeFiles(
"legacy-thinlto-cache-max-size-files", cl::init(1000000),
cl::desc("Set ThinLTO cache pruning directory maximum number of files."));

static cl::opt<unsigned> ThinLTOCacheEntryExpiration(
"legacy-thinlto-cache-entry-expiration", cl::init(604800) /* 1w */,
cl::desc("Set ThinLTO cache entry expiration time (seconds)."));

#ifdef NDEBUG
static bool VerifyByDefault = false;
#else
Expand Down Expand Up @@ -543,6 +567,25 @@ thinlto_code_gen_t thinlto_create_codegen(void) {
assert(CGOptLevelOrNone);
CodeGen->setCodeGenOptLevel(*CGOptLevelOrNone);
}
if (!ThinLTOCacheDir.empty()) {
auto Err = llvm::sys::fs::create_directories(ThinLTOCacheDir);
if (Err)
report_fatal_error(Twine("Unable to create thinLTO cache directory: ") +
Err.message());
bool result;
Err = llvm::sys::fs::is_directory(ThinLTOCacheDir, result);
if (Err || !result)
report_fatal_error(Twine("Unable to get status of thinLTO cache path or "
"path is not a directory: ") +
Err.message());
CodeGen->setCacheDir(ThinLTOCacheDir);

CodeGen->setCachePruningInterval(ThinLTOCachePruningInterval);
CodeGen->setCacheEntryExpiration(ThinLTOCacheEntryExpiration);
CodeGen->setCacheMaxSizeFiles(ThinLTOCacheMaxSizeFiles);
CodeGen->setCacheMaxSizeBytes(ThinLTOCacheMaxSizeBytes);
}

return wrap(CodeGen);
}

Expand Down