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

Last change on this file since 5761 was 5761, checked in by nmedfort, 15 months ago

Cache signature is now written into .kernel bitcode file. Minor bug fix and revision of GrepEngine::DoGrepThreadMethod?

File size: 2.2 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
37class ParabixObjectCache final : public llvm::ObjectCache {   
38    template <typename K, typename V>
39    using Map = boost::container::flat_map<K, V>;
40    using ModuleCache = Map<std::string, std::pair<llvm::Module *, std::unique_ptr<llvm::MemoryBuffer>>>;   
41public:
42    using Path = llvm::SmallString<128>;
43    ParabixObjectCache(const llvm::StringRef dir);
44    ParabixObjectCache();
45    bool loadCachedObjectFile(const std::unique_ptr<kernel::KernelBuilder> & idb, kernel::Kernel * const kernel);
46    void notifyObjectCompiled(const llvm::Module * M, llvm::MemoryBufferRef Obj) override;
47    std::unique_ptr<llvm::MemoryBuffer> getObject(const llvm::Module * M) override;
48    void performIncrementalCacheCleanupStep();
49private:
50    ModuleCache mCachedObject;
51    const Path mCachePath;
52    boost::filesystem::directory_iterator mCacheCleanupIterator;
53};
54
55#endif
Note: See TracBrowser for help on using the repository browser.