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

Last change on this file since 6141 was 5771, checked in by nmedfort, 21 months ago

Minor changes and hopefully a fix for bug exposed by base64 test

File size: 2.3 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#include <mutex>
18
19namespace llvm { class Module; }
20namespace llvm { class MemoryBuffer; }
21namespace llvm { class MemoryBufferRef; }
22namespace llvm { class LLVMContext; }
23namespace kernel { class Kernel; }
24namespace kernel { class KernelBuilder; }
25
26// The ParabixObjectCache is a two-level cache compatible with the requirements
27// of the LLVM ExecutionEngine as well as the Parabix Kernel builder infrastructure.
28//
29// The ParabixObjectCache allows the ParabixDriver to look up cached modules based on a
30// module stub that contains only the necessary Module ID and signature (loadCachedObjectFile).
31// If found, the module object file is immediately loaded into the cachedObjectMap,
32// and later made available to the ExecutionEngine as needed.  Otherwise, false is
33// return to signal that a cached File is not found.  The ParabixDriver can then
34// apply the necessary kernel builder to build the full module IR before passing
35// it to the ExecutionEngine.
36//
37
38class ParabixObjectCache final : public llvm::ObjectCache {   
39    template <typename K, typename V>
40    using Map = boost::container::flat_map<K, V>;
41    using ModuleCache = Map<std::string, std::pair<llvm::Module *, std::unique_ptr<llvm::MemoryBuffer>>>;   
42public:
43    using Path = llvm::SmallString<128>;
44    ParabixObjectCache(const llvm::StringRef dir);
45    ParabixObjectCache();
46    bool loadCachedObjectFile(const std::unique_ptr<kernel::KernelBuilder> & idb, kernel::Kernel * const kernel);
47    void notifyObjectCompiled(const llvm::Module * M, llvm::MemoryBufferRef Obj) override;
48    std::unique_ptr<llvm::MemoryBuffer> getObject(const llvm::Module * M) override;
49    void performIncrementalCacheCleanupStep();
50private:
51    std::mutex mCleanupMutex;
52    boost::filesystem::directory_iterator mCleanupIterator;
53    ModuleCache mCachedObject;
54    const Path mCachePath;
55};
56
57#endif
Note: See TracBrowser for help on using the repository browser.