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

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

Large refactoring step. Removed IR generation code from Kernel (formally KernelBuilder?) and moved it into the new KernelBuilder? class.

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