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

Last change on this file was 6288, checked in by cameron, 8 months ago

Repeat of prior check in

File size: 2.4 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; }
8namespace llvm { class ModulePass; }
9namespace kernel { class KernelBuilder; }
10
11#include <llvm/IR/LegacyPassManager.h>
12#if LLVM_VERSION_INTEGER >= LLVM_VERSION_CODE(4, 0, 0)
13#define ORCJIT
14#endif
15
16#ifdef ORCJIT
17#include <llvm/ExecutionEngine/Orc/CompileUtils.h>
18
19#if LLVM_VERSION_INTEGER < LLVM_VERSION_CODE(5, 0, 0)
20#include <llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h>
21#else
22#include <llvm/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.h>
23#endif
24#include <llvm/ExecutionEngine/Orc/IRCompileLayer.h>
25#include <llvm/ExecutionEngine/Orc/IRTransformLayer.h>
26
27#if LLVM_VERSION_INTEGER < LLVM_VERSION_CODE(5, 0, 0)
28typedef llvm::orc::ObjectLinkingLayer<> ObjectLayerT;
29typedef llvm::orc::IRCompileLayer<ObjectLayerT> CompileLayerT;
30#else
31typedef llvm::orc::RTDyldObjectLinkingLayer ObjectLayerT;
32typedef llvm::orc::IRCompileLayer<ObjectLayerT, llvm::orc::SimpleCompiler> CompileLayerT;
33#endif
34
35#endif
36
37class CPUDriver final : public BaseDriver {
38public:
39
40    CPUDriver(std::string && moduleName);
41
42    ~CPUDriver();
43
44    void generateUncachedKernels() override;
45
46    void * finalizeObject(kernel::PipelineKernel * const pipeline) override;
47
48    bool hasExternalFunction(const llvm::StringRef functionName) const override;
49
50    llvm::ModulePass * createTracePass(kernel::KernelBuilder * kb, llvm::StringRef to_trace);
51
52
53private:
54
55    std::string getMangledName(std::string s);
56
57    void preparePassManager();
58
59    llvm::Function * addLinkFunction(llvm::Module * mod, llvm::StringRef name, llvm::FunctionType * type, void * functionPtr) const override;
60
61private:
62    llvm::TargetMachine *                                   mTarget;
63    #ifdef ORCJIT
64    ObjectLayerT                                            mObjectLayer;
65    std::unique_ptr<CompileLayerT>                          mCompileLayer;
66    #else
67    llvm::ExecutionEngine *                                 mEngine;
68    #endif
69    std::unique_ptr<llvm::legacy::PassManager>              mPassManager;
70    std::unique_ptr<llvm::raw_fd_ostream>                   mUnoptimizedIROutputStream;
71    std::unique_ptr<llvm::raw_fd_ostream>                   mIROutputStream;
72    std::unique_ptr<llvm::raw_fd_ostream>                   mASMOutputStream;
73};
74
75#endif // CPUDRIVER_H
Note: See TracBrowser for help on using the repository browser.