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

Last change on this file since 5630 was 5630, checked in by nmedfort, 18 months ago

Partial check-in for avoidance of compiling Pablo/LLVM code to determine the Kernel struct type when using a cached object. Inactive RE alternation minimization check in.

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