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

Last change on this file since 5915 was 5915, checked in by cameron, 14 months ago

ORCJIT for LLVM 3.9/4.0 initial check-in

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