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

Last change on this file since 5435 was 5435, checked in by nmedfort, 2 years ago

Continued refactoring work.

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