2424#include " llvm/LTO/legacy/LTOCodeGenerator.h"
2525#include " llvm/LTO/legacy/LTOModule.h"
2626#include " llvm/LTO/legacy/ThinLTOCodeGenerator.h"
27+ #include " llvm/Support/FileSystem.h"
2728#include " llvm/Support/MemoryBuffer.h"
2829#include " llvm/Support/Signals.h"
2930#include " llvm/Support/TargetSelect.h"
@@ -44,6 +45,29 @@ static cl::opt<bool> EnableFreestanding(
4445 " lto-freestanding" , cl::init(false ),
4546 cl::desc(" Enable Freestanding (disable builtins / TLI) during LTO" ));
4647
48+ static cl::opt<std::string> ThinLTOCacheDir (
49+ " legacy-thinlto-cache-dir" ,
50+ cl::desc (" Experimental option, enable ThinLTO caching. Note: the cache "
51+ " currently does not take the mcmodel setting into account, so you "
52+ " might get false hits if different mcmodels are used in different "
53+ " builds using the same cache directory." ));
54+
55+ static cl::opt<int > ThinLTOCachePruningInterval (
56+ " legacy-thinlto-cache-pruning-interval" , cl::init(1200 ),
57+ cl::desc(" Set ThinLTO cache pruning interval (seconds)." ));
58+
59+ static cl::opt<uint64_t > ThinLTOCacheMaxSizeBytes (
60+ " legacy-thinlto-cache-max-size-bytes" ,
61+ cl::desc (" Set ThinLTO cache pruning directory maximum size in bytes." ));
62+
63+ static cl::opt<int > ThinLTOCacheMaxSizeFiles (
64+ " legacy-thinlto-cache-max-size-files" , cl::init(1000000 ),
65+ cl::desc(" Set ThinLTO cache pruning directory maximum number of files." ));
66+
67+ static cl::opt<unsigned > ThinLTOCacheEntryExpiration (
68+ " legacy-thinlto-cache-entry-expiration" , cl::init(604800 ) /* 1w */ ,
69+ cl::desc(" Set ThinLTO cache entry expiration time (seconds)." ));
70+
4771#ifdef NDEBUG
4872static bool VerifyByDefault = false ;
4973#else
@@ -543,6 +567,25 @@ thinlto_code_gen_t thinlto_create_codegen(void) {
543567 assert (CGOptLevelOrNone);
544568 CodeGen->setCodeGenOptLevel (*CGOptLevelOrNone);
545569 }
570+ if (!ThinLTOCacheDir.empty ()) {
571+ auto Err = llvm::sys::fs::create_directories (ThinLTOCacheDir);
572+ if (Err)
573+ report_fatal_error (Twine (" Unable to create thinLTO cache directory: " ) +
574+ Err.message ());
575+ bool result;
576+ Err = llvm::sys::fs::is_directory (ThinLTOCacheDir, result);
577+ if (Err || !result)
578+ report_fatal_error (Twine (" Unable to get status of thinLTO cache path or "
579+ " path is not a directory: " ) +
580+ Err.message ());
581+ CodeGen->setCacheDir (ThinLTOCacheDir);
582+
583+ CodeGen->setCachePruningInterval (ThinLTOCachePruningInterval);
584+ CodeGen->setCacheEntryExpiration (ThinLTOCacheEntryExpiration);
585+ CodeGen->setCacheMaxSizeFiles (ThinLTOCacheMaxSizeFiles);
586+ CodeGen->setCacheMaxSizeBytes (ThinLTOCacheMaxSizeBytes);
587+ }
588+
546589 return wrap (CodeGen);
547590}
548591
0 commit comments