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

Last change on this file since 6237 was 6209, checked in by nmedfort, 8 months ago

Initial cache janitor daemon test

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