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

Last change on this file since 5391 was 5391, checked in by cameron, 3 years ago

ParabixDriver/ObjectCache? separate compilation and linking: initial check-in with wc

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