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

Last change on this file since 6184 was 6184, checked in by nmedfort, 9 months ago

Initial version of PipelineKernel? + revised StreamSet? model.

File size: 3.1 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/kernel.h>
7#include <kernels/streamset.h>
8#include <kernels/relationship.h>
9#include <toolchain/object_cache_manager.h>
10#include <util/slab_allocator.h>
11#include <string>
12#include <vector>
13#include <memory>
14
15namespace llvm { class Function; }
16namespace kernel { class KernelBuilder; }
17namespace kernel { class PipelineBuilder; }
18class CBuilder;
19
20class ObjectCacheManager;
21
22class BaseDriver {
23    friend class CBuilder;
24    friend class kernel::PipelineBuilder;
25    using Kernel = kernel::Kernel;
26    using Relationship = kernel::Relationship;
27    using Bindings = kernel::Bindings;
28    using OwnedKernels = std::vector<std::unique_ptr<Kernel>>;
29
30public:
31
32    std::unique_ptr<kernel::PipelineBuilder> makePipelineWithIO(Bindings stream_inputs = {}, Bindings stream_outputs = {}, Bindings scalar_inputs = {}, Bindings scalar_outputs = {});
33
34    std::unique_ptr<kernel::PipelineBuilder> makePipeline(Bindings scalar_inputs = {}, Bindings scalar_outputs = {});
35
36    const std::unique_ptr<kernel::KernelBuilder> & getBuilder() {
37        return iBuilder;
38    }
39
40    kernel::StreamSet * CreateStreamSet(const unsigned NumElements = 1, const unsigned FieldWidth = 1);
41
42    kernel::Scalar * CreateScalar(llvm::Type * scalarType);
43
44    kernel::Scalar * CreateConstant(llvm::Constant * value);
45
46    void addKernel(Kernel * const kernel);
47
48    template <typename ExternalFunctionType>
49    llvm::Function * LinkFunction(not_null<Kernel *> kb, llvm::StringRef name, ExternalFunctionType & functionPtr) const;
50
51    virtual bool hasExternalFunction(const llvm::StringRef functionName) const = 0;
52
53    virtual void generateUncachedKernels() = 0;
54
55    virtual void * finalizeObject(llvm::Function * mainMethod) = 0;
56   
57    virtual ~BaseDriver();
58
59    llvm::LLVMContext & getContext() const {
60        return *mContext.get();
61    }
62
63    llvm::Module * getMainModule() const {
64        return mMainModule;
65    }
66
67protected:
68
69    BaseDriver(std::string && moduleName);
70
71    virtual llvm::Function * addLinkFunction(llvm::Module * mod, llvm::StringRef name, llvm::FunctionType * type, void * functionPtr) const = 0;
72
73protected:
74
75    std::unique_ptr<llvm::LLVMContext>                      mContext;
76    llvm::Module * const                                    mMainModule;
77    std::unique_ptr<kernel::KernelBuilder>                  iBuilder;
78    OwnedKernels                                            mUncachedKernel;
79    OwnedKernels                                            mCachedKernel;
80    SlabAllocator<>                                         mAllocator;
81};
82
83template <typename ExternalFunctionType>
84llvm::Function * BaseDriver::LinkFunction(not_null<Kernel *> kb, llvm::StringRef name, ExternalFunctionType & functionPtr) const {
85    llvm::FunctionType * const type = FunctionTypeBuilder<ExternalFunctionType>::get(getContext());
86    assert ("FunctionTypeBuilder did not resolve a function type." && type);
87    return addLinkFunction(kb->getModule(), name, type, reinterpret_cast<void *>(functionPtr));
88}
89
90#endif // DRIVER_H
Note: See TracBrowser for help on using the repository browser.