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

Last change on this file since 5544 was 5544, checked in by cameron, 22 months ago

Deallocating dynamic buffers

File size: 2.6 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 bool hasExternalFunction(const llvm::StringRef functionName) const = 0;
43
44    void deallocateBuffers();
45   
46    virtual void finalizeObject() = 0;
47   
48    virtual void * getMain() = 0; // "main" exists until the driver is deleted
49
50protected:
51
52    virtual llvm::Function * addLinkFunction(llvm::Module * mod, llvm::StringRef name, llvm::FunctionType * type, void * functionPtr) const = 0;
53
54protected:
55    std::unique_ptr<llvm::LLVMContext>                      mContext;
56    llvm::Module * const                                    mMainModule;
57    std::unique_ptr<kernel::KernelBuilder>                  iBuilder;
58    std::vector<std::unique_ptr<kernel::Kernel>>            mOwnedKernels;
59    std::vector<std::unique_ptr<parabix::StreamSetBuffer>>  mOwnedBuffers;
60    std::vector<kernel::Kernel *>                           mPipeline;
61};
62
63template <typename ExternalFunctionType>
64llvm::Function * Driver::LinkFunction(kernel::Kernel & kb, llvm::StringRef name, ExternalFunctionType * functionPtr) const {
65    llvm::FunctionType * const type = FunctionTypeBuilder<ExternalFunctionType>::get(*mContext.get());
66    assert ("FunctionTypeBuilder did not resolve a function type." && type);
67    return addLinkFunction(kb.getModule(), name, type, reinterpret_cast<void *>(functionPtr));
68}
69
70#endif // DRIVER_H
Note: See TracBrowser for help on using the repository browser.