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

Last change on this file since 5998 was 5998, checked in by nmedfort, 12 months ago

Added temporary buffer functionality to the pipeline for single stream source buffers. Fixed memory leak from UCD::UnicodeBreakRE()

File size: 2.9 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#include <memory>
11
12namespace llvm { class Function; }
13namespace kernel { class KernelBuilder; }
14
15class Driver {
16    friend class CBuilder;
17public:
18    Driver(std::string && moduleName);
19
20    const std::unique_ptr<kernel::KernelBuilder> & getBuilder() {
21        return iBuilder;
22    }
23
24    template<typename BufferType, typename... Args>
25    parabix::StreamSetBuffer * addBuffer(Args &&... args) {
26        BufferType * const b = new BufferType(std::forward<Args>(args) ...);
27        mOwnedBuffers.emplace_back(b);
28        if (!std::is_same<BufferType, parabix::ExternalBuffer>::value) {
29            mOwnedBuffers.back()->allocateBuffer(iBuilder);
30        }
31        return b;
32    }
33
34    template<typename KernelType, typename... Args>
35    kernel::Kernel * addKernelInstance(Args &&... args) {
36        KernelType * const k = new KernelType(std::forward<Args>(args) ...);
37        mOwnedKernels.emplace_back(k);
38        return k;
39    }
40
41    virtual void makeKernelCall(kernel::Kernel * kb, const std::vector<parabix::StreamSetBuffer *> & inputs, const std::vector<parabix::StreamSetBuffer *> & outputs) = 0;
42
43    virtual void generatePipelineIR() = 0;
44
45    template <typename ExternalFunctionType>
46    llvm::Function * LinkFunction(kernel::Kernel & kb, llvm::StringRef name, ExternalFunctionType * functionPtr) const;
47
48    virtual bool hasExternalFunction(const llvm::StringRef functionName) const = 0;
49
50    void deallocateBuffers();
51   
52    virtual void finalizeObject() = 0;
53   
54    virtual void * getMain() = 0; // "main" exists until the driver is deleted
55   
56    virtual void performIncrementalCacheCleanupStep() = 0;
57
58    virtual ~Driver() = 0;
59
60protected:
61
62    virtual llvm::Function * addLinkFunction(llvm::Module * mod, llvm::StringRef name, llvm::FunctionType * type, void * functionPtr) const = 0;
63
64protected:
65    std::unique_ptr<llvm::LLVMContext>                      mContext;
66    llvm::Module * const                                    mMainModule;
67    std::unique_ptr<kernel::KernelBuilder>                  iBuilder;
68    std::vector<std::unique_ptr<kernel::Kernel>>            mOwnedKernels;
69    std::vector<std::unique_ptr<parabix::StreamSetBuffer>>  mOwnedBuffers;
70    std::vector<kernel::Kernel *>                           mPipeline;
71};
72
73template <typename ExternalFunctionType>
74llvm::Function * Driver::LinkFunction(kernel::Kernel & kb, llvm::StringRef name, ExternalFunctionType * functionPtr) const {
75    llvm::FunctionType * const type = FunctionTypeBuilder<ExternalFunctionType>::get(*mContext.get());
76    assert ("FunctionTypeBuilder did not resolve a function type." && type);
77    return addLinkFunction(kb.getModule(), name, type, reinterpret_cast<void *>(functionPtr));
78}
79
80#endif // DRIVER_H
Note: See TracBrowser for help on using the repository browser.