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

Last change on this file since 6253 was 6253, checked in by nmedfort, 7 months ago

Moved consumed item counts for all buffers into pipeline state. Initial work on conditional kernel logic.

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