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

Last change on this file since 6047 was 6047, checked in by nmedfort, 17 months ago

Major refactoring of buffer types. Static buffers replace Circular and CircularCopyback?. External buffers unify Source/External?.

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