source: icGREP/icgrep-devel/icgrep/object_cache.h @ 5400

Last change on this file since 5400 was 5394, checked in by cameron, 2 years ago

Object cache system with signature checking complete

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