[llvm] r198852 - Add an "-object-cache-dir=<string>" option to LLI. This option specifies the
NAKAMURA Takumi
geek4civic at gmail.com
Thu Jan 9 21:54:13 PST 2014
Path handling would be incompatible to Win32...
See also; http://bb.pgr.jp/builders/clang-i686-msys/builds/1627
2014/1/9 Lang Hames <lhames at gmail.com>:
> Author: lhames
> Date: Wed Jan 8 23:24:05 2014
> New Revision: 198852
>
> URL: http://llvm.org/viewvc/llvm-project?rev=198852&view=rev
> Log:
> Add an "-object-cache-dir=<string>" option to LLI. This option specifies the
> root path to which object files managed by the LLIObjectCache instance should be
> written. This option defaults to "", in which case objects are cached in the
> same directory as the bitcode they are derived from.
>
> The load-object-a.ll test has been rewritten to use this option to support
> testing in environments where the test directory is not writable.
>
>
> Modified:
> llvm/trunk/test/ExecutionEngine/MCJIT/load-object-a.ll
> llvm/trunk/tools/lli/lli.cpp
>
> Modified: llvm/trunk/test/ExecutionEngine/MCJIT/load-object-a.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/MCJIT/load-object-a.ll?rev=198852&r1=198851&r2=198852&view=diff
> ==============================================================================
> --- llvm/trunk/test/ExecutionEngine/MCJIT/load-object-a.ll (original)
> +++ llvm/trunk/test/ExecutionEngine/MCJIT/load-object-a.ll Wed Jan 8 23:24:05 2014
> @@ -1,23 +1,18 @@
> ; REQUIRES: shell
>
> ; This first line will generate the .o files for the next run line
> -; RUN: %lli_mcjit -extra-module=%p/Inputs/multi-module-b.ll -extra-module=%p/Inputs/multi-module-c.ll -enable-cache-manager %s
> +; RUN: mkdir -p %t.cachedir
> +; RUN: %lli_mcjit -extra-module=%p/Inputs/multi-module-b.ll -extra-module=%p/Inputs/multi-module-c.ll -enable-cache-manager -object-cache-dir=%t.cachedir %s
>
> ; This line tests MCJIT object loading
> -; RUN: %lli_mcjit -extra-object=%p/Inputs/multi-module-b.o -extra-object=%p/Inputs/multi-module-c.o %s
> +; RUN: %lli_mcjit -extra-object=%t.cachedir/%p/Inputs/multi-module-b.o -extra-object=%t.cachedir/%p/Inputs/multi-module-c.o %s
>
> ; These lines put the object files into an archive
> -; RUN: llvm-ar r %p/Inputs/load-object.a %p/Inputs/multi-module-b.o
> -; RUN: llvm-ar r %p/Inputs/load-object.a %p/Inputs/multi-module-c.o
> +; RUN: llvm-ar r %t.cachedir/%p/Inputs/load-object.a %t.cachedir/%p/Inputs/multi-module-b.o
> +; RUN: llvm-ar r %t.cachedir/%p/Inputs/load-object.a %t.cachedir/%p/Inputs/multi-module-c.o
>
> ; This line test MCJIT archive loading
> -; RUN: %lli_mcjit -extra-archive=%p/Inputs/load-object.a %s
> -
> -; These lines clean up our temporary files
> -; RUN: rm -f %p/Inputs/load-object-a.o
> -; RUN: rm -f %p/Inputs/multi-module-b.o
> -; RUN: rm -f %p/Inputs/multi-module-c.o
> -; RUN: rm -f %p/Inputs/load-object.a
> +; RUN: %lli_mcjit -extra-archive=%t.cachedir/%p/Inputs/load-object.a %s
>
> declare i32 @FB()
>
>
> Modified: llvm/trunk/tools/lli/lli.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lli/lli.cpp?rev=198852&r1=198851&r2=198852&view=diff
> ==============================================================================
> --- llvm/trunk/tools/lli/lli.cpp (original)
> +++ llvm/trunk/tools/lli/lli.cpp Wed Jan 8 23:24:05 2014
> @@ -153,10 +153,16 @@ namespace {
>
> cl::opt<bool>
> EnableCacheManager("enable-cache-manager",
> - cl::desc("Use cache manager to save/load mdoules."),
> + cl::desc("Use cache manager to save/load mdoules"),
> cl::init(false));
>
> cl::opt<std::string>
> + ObjectCacheDir("object-cache-dir",
> + cl::desc("Directory to store cached object files "
> + "(must be user writable)"),
> + cl::init(""));
> +
> + cl::opt<std::string>
> FakeArgv0("fake-argv0",
> cl::desc("Override the 'argv[0]' value passed into the executing"
> " program"), cl::value_desc("executable"));
> @@ -240,13 +246,19 @@ namespace {
> //===----------------------------------------------------------------------===//
> // Object cache
> //
> -// This object cache implementation writes cached objects to disk using a
> -// filename provided in the module descriptor and tries to load a saved object
> -// using that filename if the file exists.
> +// This object cache implementation writes cached objects to disk to the
> +// directory specified by CacheDir, using a filename provided in the module
> +// descriptor. The cache tries to load a saved object using that path if the
> +// file exists. CacheDir defaults to "", in which case objects are cached
> +// alongside their originating bitcodes.
> //
> class LLIObjectCache : public ObjectCache {
> public:
> - LLIObjectCache() { }
> + LLIObjectCache(const std::string& CacheDir) : CacheDir(CacheDir) {
> + // Add trailing '/' to cache dir if necessary.
> + if (!this->CacheDir.empty() && this->CacheDir.back() != '/')
> + this->CacheDir += '/';
> + }
> virtual ~LLIObjectCache() {}
>
> virtual void notifyObjectCompiled(const Module *M, const MemoryBuffer *Obj) {
> @@ -255,6 +267,8 @@ public:
> if (!getCacheFilename(ModuleID, CacheName))
> return;
> std::string errStr;
> + if (!CacheDir.empty()) // Create user-defined cache dir.
> + sys::fs::create_directories(CacheName.substr(0, CacheName.rfind('/')));
> raw_fd_ostream outfile(CacheName.c_str(), errStr, sys::fs::F_Binary);
> outfile.write(Obj->getBufferStart(), Obj->getBufferSize());
> outfile.close();
> @@ -279,12 +293,14 @@ public:
> }
>
> private:
> + std::string CacheDir;
> +
> bool getCacheFilename(const std::string &ModID, std::string &CacheName) {
> std::string Prefix("file:");
> size_t PrefixLength = Prefix.length();
> if (ModID.substr(0, PrefixLength) != Prefix)
> return false;
> - CacheName = ModID.substr(PrefixLength);
> + CacheName = CacheDir + ModID.substr(PrefixLength);
> size_t pos = CacheName.rfind('.');
> CacheName.replace(pos, CacheName.length() - pos, ".o");
> return true;
> @@ -476,7 +492,7 @@ int main(int argc, char **argv, char * c
> }
>
> if (EnableCacheManager) {
> - CacheManager = new LLIObjectCache;
> + CacheManager = new LLIObjectCache(ObjectCacheDir);
> EE->setObjectCache(CacheManager);
> }
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list