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

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

CPU driver progress

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