source: icGREP/icgrep-devel/icgrep/toolchain/driver.h @ 5474

Last change on this file since 5474 was 5474, checked in by nmedfort, 2 years ago

Eliminated ExecutionEngine? memory leak. Intentionally broke compatibility with prior versions to ensure unchecked in projects are restructured.

File size: 2.5 KB
Line 
1#ifndef DRIVER_H
2#define DRIVER_H
3
4#include <IR_Gen/FunctionTypeBuilder.h>
5#include <llvm/ExecutionEngine/GenericValue.h>
6#include <kernels/streamset.h>
7#include <kernels/kernel.h>
8#include <string>
9#include <vector>
10
11namespace llvm { class Function; }
12namespace kernel { class KernelBuilder; }
13
14class Driver {
15    friend class CBuilder;
16public:
17    Driver(std::string && moduleName);
18
19    virtual ~Driver() = default;
20
21    const std::unique_ptr<kernel::KernelBuilder> & getBuilder() {
22        return iBuilder;
23    }
24
25    parabix::ExternalBuffer * addExternalBuffer(std::unique_ptr<parabix::ExternalBuffer> b);
26
27    parabix::StreamSetBuffer * addBuffer(std::unique_ptr<parabix::StreamSetBuffer> b);
28
29    kernel::Kernel * addKernelInstance(std::unique_ptr<kernel::Kernel> kb);
30
31    void addKernelCall(kernel::Kernel & kb, const std::vector<parabix::StreamSetBuffer *> & inputs, const std::vector<parabix::StreamSetBuffer *> & outputs) {
32        return makeKernelCall(&kb, inputs, outputs);
33    }
34
35    virtual void makeKernelCall(kernel::Kernel * kb, const std::vector<parabix::StreamSetBuffer *> & inputs, const std::vector<parabix::StreamSetBuffer *> & outputs) = 0;
36
37    virtual void generatePipelineIR() = 0;
38
39    template <typename ExternalFunctionType>
40    llvm::Function * LinkFunction(kernel::Kernel & kb, llvm::StringRef name, ExternalFunctionType * functionPtr) const;
41
42    virtual void finalizeObject() = 0;
43
44    virtual void * getMain() = 0; // "main" exists until the driver is deleted
45
46protected:
47
48    virtual llvm::Function * addLinkFunction(llvm::Module * mod, llvm::StringRef name, llvm::FunctionType * type, void * functionPtr) const = 0;
49
50protected:
51    std::unique_ptr<llvm::LLVMContext>                      mContext;
52    llvm::Module * const                                    mMainModule;
53    std::unique_ptr<kernel::KernelBuilder>                  iBuilder;
54    std::vector<std::unique_ptr<kernel::Kernel>>            mOwnedKernels;
55    std::vector<std::unique_ptr<parabix::StreamSetBuffer>>  mOwnedBuffers;
56    std::vector<kernel::Kernel *>                           mPipeline;
57};
58
59template <typename ExternalFunctionType>
60llvm::Function * Driver::LinkFunction(kernel::Kernel & kb, llvm::StringRef name, ExternalFunctionType * functionPtr) const {
61    llvm::FunctionType * const type = FunctionTypeBuilder<ExternalFunctionType>::get(*mContext.get());
62    assert ("FunctionTypeBuilder did not resolve a function type." && type);
63    return addLinkFunction(kb.getModule(), name, type, reinterpret_cast<void *>(functionPtr));
64}
65
66#endif // DRIVER_H
Note: See TracBrowser for help on using the repository browser.