source: icGREP/icgrep-devel/icgrep/toolchain/object_cache.h @ 5735

Last change on this file since 5735 was 5735, checked in by cameron, 17 months ago

Incremental object caching; multithreaded print

File size: 2.4 KB
Line 
1/*
2 *  Copyright (c) 2017 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 *  icgrep is a trademark of International Characters.
5 */
6
7#ifndef OBJECT_CACHE_H
8#define OBJECT_CACHE_H
9
10#include <llvm/ADT/SmallString.h>
11#include <llvm/ExecutionEngine/ObjectCache.h>
12#include <llvm/ADT/StringRef.h>
13#include <boost/container/flat_map.hpp>
14#include <boost/filesystem.hpp>
15#include <vector>
16#include <string>
17
18namespace llvm { class Module; }
19namespace llvm { class MemoryBuffer; }
20namespace llvm { class MemoryBufferRef; }
21namespace llvm { class LLVMContext; }
22namespace kernel { class Kernel; }
23namespace kernel { class KernelBuilder; }
24
25// The ParabixObjectCache is a two-level cache compatible with the requirements
26// of the LLVM ExecutionEngine as well as the Parabix Kernel builder infrastructure.
27//
28// The ParabixObjectCache allows the ParabixDriver to look up cached modules based on a
29// module stub that contains only the necessary Module ID and signature (loadCachedObjectFile).
30// If found, the module object file is immediately loaded into the cachedObjectMap,
31// and later made available to the ExecutionEngine as needed.  Otherwise, false is
32// return to signal that a cached File is not found.  The ParabixDriver can then
33// apply the necessary kernel builder to build the full module IR before passing
34// it to the ExecutionEngine.
35//
36
37unsigned const CACHE_ENTRY_MAX_HOURS (24 * 15);
38
39class ParabixObjectCache final : public llvm::ObjectCache {
40    using Path = llvm::SmallString<128>;
41    template <typename K, typename V>
42    using Map = boost::container::flat_map<K, V>;
43    using ModuleCache = Map<std::string, std::pair<llvm::Module *, std::unique_ptr<llvm::MemoryBuffer>>>;
44public:
45    ParabixObjectCache(const std::string dir);
46    ParabixObjectCache();
47    bool loadCachedObjectFile(const std::unique_ptr<kernel::KernelBuilder> & idb, kernel::Kernel * const kernel);
48    void notifyObjectCompiled(const llvm::Module * M, llvm::MemoryBufferRef Obj) override;
49    std::unique_ptr<llvm::MemoryBuffer> getObject(const llvm::Module * M) override;
50    void performIncrementalCacheCleanupStep();
51protected:
52    static std::string getDefaultPath();
53private:
54    ModuleCache         mCachedObject;
55    const Path          mCachePath;
56    boost::filesystem::directory_iterator mCacheCleanupIterator;
57    unsigned            mCacheEntryMaxHours;
58};
59
60#endif
Note: See TracBrowser for help on using the repository browser.