Ignore:
Timestamp:
Apr 7, 2017, 4:59:04 PM (2 years ago)
Author:
nmedfort
Message:

Continued work on processing stdin input. Partial integration of ParabixDriver? methods into icgrep and editd. Object cache does not currently work for recursive REs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/toolchain.h

    r5391 r5398  
    99#include <string>
    1010#include <IR_Gen/idisa_builder.h>
     11#include <llvm/IR/TypeBuilder.h>
     12#include <boost/container/flat_map.hpp>
    1113#include <object_cache.h>
    1214
    1315namespace llvm { class ExecutionEngine; }
    1416namespace llvm { class Module; }
     17namespace llvm { class TargetMachine; }
    1518namespace llvm { namespace cl { class OptionCategory; } }
    1619namespace IDISA { class IDISA_Builder; }
     
    6265
    6366class ParabixDriver {
     67
     68    using ModuleMap = boost::container::flat_map<kernel::KernelBuilder *, std::unique_ptr<llvm::Module>>;
     69
    6470public:
    6571    ParabixDriver(IDISA::IDISA_Builder * iBuilder);
     
    6874   
    6975    void JITcompileMain ();
    70    
     76
    7177    void addKernelCall(kernel::KernelBuilder & kb, const std::vector<parabix::StreamSetBuffer *> & inputs, const std::vector<parabix::StreamSetBuffer *> & outputs);
    7278   
    7379    void generatePipelineIR();
    7480   
     81    template <typename ExternalFunctionType>
     82    void addExternalLink(kernel::KernelBuilder & kb, llvm::StringRef name, ExternalFunctionType * functionPtr) const;
     83
     84    void addExternalLink(kernel::KernelBuilder & kb, llvm::StringRef name, llvm::FunctionType * type, void * functionPtr) const;
     85
    7586    void linkAndFinalize();
    7687   
    7788    void * getPointerToMain();
    7889
    79    
    8090private:
    81     llvm::Module * mMainModule;
    82     IDISA::IDISA_Builder * iBuilder;
    83     std::unique_ptr<ParabixObjectCache> mCache;
    84     //std::unique_ptr<llvm::ExecutionEngine> mEngine;
    85     llvm::ExecutionEngine * mEngine;
    86     std::vector<kernel::KernelBuilder *> mKernelList;
     91    IDISA::IDISA_Builder * const            iBuilder;
     92    llvm::Module * const                    mMainModule;
     93    llvm::TargetMachine *                   mTarget;
     94    llvm::ExecutionEngine *                 mEngine;
     95    std::unique_ptr<ParabixObjectCache>     mCache;
     96    std::vector<kernel::KernelBuilder *>    mKernelList;
     97    ModuleMap                               mModuleMap;
    8798};
     99
     100namespace {
     101
     102// NOTE: Currently, LLVM TypeBuilder only work for up to 5 arguments. The following templates
     103// avoid that limit but should be deprecated if the TypeBuilder ever supports n-ary functions.
     104
     105template <typename... Args>
     106class ParameterTypeBuilder;
     107
     108template<typename A1, typename... An>
     109struct ParameterTypeBuilder<A1, An...> {
     110    static void get(llvm::LLVMContext & C, std::vector<llvm::Type *> & params) {
     111        ParameterTypeBuilder<A1>::get(C, params);
     112        ParameterTypeBuilder<An...>::get(C, params);
     113    }
     114};
     115
     116template<typename A>
     117struct ParameterTypeBuilder<A> {
     118    static void get(llvm::LLVMContext & C, std::vector<llvm::Type *> & params) {
     119        params.push_back(llvm::TypeBuilder<A, false>::get(C));
     120    }
     121};
     122
     123template<typename T>
     124struct FunctionTypeBuilder;
     125
     126template<typename R, typename... Args>
     127struct FunctionTypeBuilder<R(Args...)> {
     128    static llvm::FunctionType * get(llvm::LLVMContext & C) {
     129        auto result = llvm::TypeBuilder<R, false>::get(C);
     130        std::vector<llvm::Type *> params(0);
     131        params.reserve(sizeof...(Args));
     132        ParameterTypeBuilder<Args...>::get(C, params);
     133        return llvm::FunctionType::get(result, params, false);
     134    }
     135};
     136
     137template<typename R>
     138struct FunctionTypeBuilder<R()> {
     139    static llvm::FunctionType * get(llvm::LLVMContext & C) {
     140        auto result = llvm::TypeBuilder<R, false>::get(C);
     141        return llvm::FunctionType::get(result, false);
     142    }
     143};
     144
     145}
     146
     147template <typename ExternalFunctionType>
     148void ParabixDriver::addExternalLink(kernel::KernelBuilder & kb, llvm::StringRef name, ExternalFunctionType * functionPtr) const {
     149    llvm::FunctionType * const type = FunctionTypeBuilder<ExternalFunctionType>::get(iBuilder->getContext());
     150    assert ("FunctionTypeBuilder did not correctly resolve the current function type." && type);
     151    addExternalLink(kb, name, type, reinterpret_cast<void *>(functionPtr));
     152}
     153
    88154#endif
Note: See TracChangeset for help on using the changeset viewer.