source: icGREP/icgrep-devel/icgrep/toolchain/cpudriver.h @ 5924

Last change on this file since 5924 was 5924, checked in by cameron, 11 months ago

Various cleanups

File size: 2.8 KB
Line 
1#ifndef CPUDRIVER_H
2#define CPUDRIVER_H
3#include "driver.h"
4#include <toolchain/toolchain.h>
5namespace llvm { class ExecutionEngine; }
6namespace llvm { class TargetMachine; }
7namespace llvm { class raw_fd_ostream; }
8
9#include <llvm/IR/LegacyPassManager.h>
10#if LLVM_VERSION_INTEGER >= LLVM_VERSION_CODE(4, 0, 0)
11#define ORCJIT
12#endif
13
14#ifdef ORCJIT
15#include <llvm/ExecutionEngine/Orc/CompileUtils.h>
16
17#if LLVM_VERSION_INTEGER < LLVM_VERSION_CODE(5, 0, 0)
18#include <llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h>
19#else
20#include <llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h>
21#endif
22#include <llvm/ExecutionEngine/Orc/IRCompileLayer.h>
23#include <llvm/ExecutionEngine/Orc/IRTransformLayer.h>
24
25#if LLVM_VERSION_INTEGER < LLVM_VERSION_CODE(5, 0, 0)
26typedef llvm::orc::ObjectLinkingLayer<> ObjectLayerT;
27typedef llvm::orc::IRCompileLayer<ObjectLayerT> CompileLayerT;
28#else
29typedef llvm::orc::RTDyldObjectLinkingLayer ObjectLayerT;
30typedef llvm::orc::IRCompileLayer<ObjectLayerT, llvm::orc::SimpleCompiler> CompileLayerT;
31#endif
32
33#endif
34
35class ParabixObjectCache;
36
37class ParabixDriver final : public Driver {
38    friend class CBuilder;
39public:
40    ParabixDriver(std::string && moduleName);
41
42    ~ParabixDriver();
43
44    void generatePipelineIR() override;
45
46    void makeKernelCall(kernel::Kernel * kb, const std::vector<parabix::StreamSetBuffer *> & inputs, const std::vector<parabix::StreamSetBuffer *> & outputs) override;
47
48    void finalizeObject() override;
49
50    bool hasExternalFunction(const llvm::StringRef functionName) const override;
51
52    void * getMain() override; // "main" exists until the driver is deleted
53   
54    void performIncrementalCacheCleanupStep() override;
55
56private:
57    std::string getMangledName(std::string s);
58   
59    void preparePassManager();
60
61    llvm::Function * addLinkFunction(llvm::Module * mod, llvm::StringRef name, llvm::FunctionType * type, void * functionPtr) const override;
62
63    llvm::TargetMachine *                                   mTarget;
64    llvm::legacy::PassManager                               mPassManager;
65
66#ifdef ORCJIT
67    ObjectLayerT mObjectLayer;
68    std::unique_ptr<CompileLayerT> mCompileLayer;
69
70#else
71    llvm::ExecutionEngine *                                 mEngine;
72#endif
73    ParabixObjectCache *                                    mCache;
74    std::vector<kernel::Kernel *>                           mUncachedKernel;
75    // NOTE: when printing the IR/ASM, we cannot assume they're completely finished after finalizeObject is executed. Instead we store a
76    // pointer and delete them once the driver (and any processing) is complete. This prevents us from reclaiming the memory early but
77    // also avoids a potential segmentation fault when writing large files.
78    llvm::raw_fd_ostream *                                  mIROutputStream;
79    llvm::raw_fd_ostream *                                  mASMOutputStream;
80};
81
82#endif // CPUDRIVER_H
Note: See TracBrowser for help on using the repository browser.