Ignore:
Timestamp:
Apr 25, 2017, 2:33:31 PM (2 years ago)
Author:
nmedfort
Message:

Changes towards separate compilation

Location:
icGREP/icgrep-devel/icgrep/toolchain
Files:
1 added
1 moved

Legend:

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

    r5424 r5425  
    99#include <string>
    1010#include <IR_Gen/idisa_builder.h>
    11 #include <llvm/IR/TypeBuilder.h>
     11#include <IR_Gen/FunctionTypeBuilder.h>
    1212#include <kernels/kernel.h>
    1313#include <kernels/streamset.h>
    14 #include <boost/container/flat_map.hpp>
    1514
    1615namespace llvm { class ExecutionEngine; }
     
    6261
    6362class ParabixDriver {
    64     using ModuleMap = boost::container::flat_map<kernel::KernelBuilder *, llvm::Module *>;
     63    friend class CBuilder;
    6564public:
    66     ParabixDriver(IDISA::IDISA_Builder * iBuilder);
     65    ParabixDriver(std::string && moduleName);
    6766
    6867    ~ParabixDriver();
    6968   
    70     IDISA::IDISA_Builder * getIDISA_Builder() {return iBuilder;}
     69    IDISA::IDISA_Builder * getIDISA_Builder() { return iBuilder.get(); }
    7170   
    7271    parabix::ExternalFileBuffer * addExternalBuffer(std::unique_ptr<parabix::ExternalFileBuffer> b, llvm::Value * externalBuf);
     
    7776   
    7877    void addKernelCall(kernel::KernelBuilder & kb, const std::vector<parabix::StreamSetBuffer *> & inputs, const std::vector<parabix::StreamSetBuffer *> & outputs);
     78
    7979    void makeKernelCall(kernel::KernelBuilder * kb, const std::vector<parabix::StreamSetBuffer *> & inputs, const std::vector<parabix::StreamSetBuffer *> & outputs);
    8080   
     
    8282   
    8383    template <typename ExternalFunctionType>
    84     void addExternalLink(kernel::KernelBuilder & kb, llvm::StringRef name, ExternalFunctionType * functionPtr) const;
     84    llvm::Function * LinkFunction(kernel::KernelBuilder & kb, llvm::StringRef name, ExternalFunctionType * functionPtr) const;
    8585
    8686    void linkAndFinalize();
     
    8888    void * getPointerToMain();
    8989
    90 private:
     90protected:
    9191
    92 
    93     void addExternalLink(kernel::KernelBuilder & kb, llvm::StringRef name, llvm::FunctionType * type, void * functionPtr) const;
    94 
     92    llvm::Function * LinkFunction(llvm::Module * mod, llvm::StringRef name, llvm::FunctionType * type, void * functionPtr) const;
    9593
    9694private:
    97     IDISA::IDISA_Builder * const            iBuilder;
     95    std::unique_ptr<llvm::LLVMContext>      mContext;
    9896    llvm::Module * const                    mMainModule;
     97    std::unique_ptr<IDISA::IDISA_Builder>   iBuilder;
    9998    llvm::TargetMachine *                   mTarget;
    10099    llvm::ExecutionEngine *                 mEngine;
    101100    ParabixObjectCache *                    mCache;
     101
    102102    std::vector<kernel::KernelBuilder *>    mPipeline;
    103103    // Owned kernels and buffers that will persist with this ParabixDriver instance.
     
    106106};
    107107
    108 namespace {
    109 
    110 // NOTE: Currently, LLVM TypeBuilder can deduce FuntionTypes for up to 5 arguments. The following
    111 // templates have no limit but should be deprecated if the TypeBuilder ever supports n-ary functions.
    112 
    113 template<unsigned i, typename... Args>
    114 struct ParameterTypeBuilder;
    115 
    116 template<unsigned i, typename A1, typename... An>
    117 struct ParameterTypeBuilder<i, A1, An...> {
    118     static void get(llvm::LLVMContext & C, llvm::Type ** params) {
    119         ParameterTypeBuilder<i, A1>::get(C, params);
    120         ParameterTypeBuilder<i + 1, An...>::get(C, params);
    121     }
    122 };
    123 
    124 template<unsigned i, typename A>
    125 struct ParameterTypeBuilder<i, A> {
    126     static void get(llvm::LLVMContext & C, llvm::Type ** params) {
    127         params[i] = llvm::TypeBuilder<A, false>::get(C);
    128     }
    129 };
    130 
    131 template<typename T>
    132 struct FunctionTypeBuilder;
    133 
    134 template<typename R, typename... Args>
    135 struct FunctionTypeBuilder<R(Args...)> {
    136     static llvm::FunctionType * get(llvm::LLVMContext & C) {
    137         llvm::Type * params[sizeof...(Args)];
    138         ParameterTypeBuilder<0, Args...>::get(C, params);
    139         return llvm::FunctionType::get(llvm::TypeBuilder<R, false>::get(C), params, false);
    140     }
    141 };
    142 
    143 template<typename R>
    144 struct FunctionTypeBuilder<R()> {
    145     static llvm::FunctionType * get(llvm::LLVMContext & C) {
    146         return llvm::FunctionType::get(llvm::TypeBuilder<R, false>::get(C), false);
    147     }
    148 };
    149 
    150 }
    151 
    152108template <typename ExternalFunctionType>
    153 void ParabixDriver::addExternalLink(kernel::KernelBuilder & kb, llvm::StringRef name, ExternalFunctionType * functionPtr) const {
     109llvm::Function * ParabixDriver::LinkFunction(kernel::KernelBuilder & kb, llvm::StringRef name, ExternalFunctionType * functionPtr) const {
    154110    llvm::FunctionType * const type = FunctionTypeBuilder<ExternalFunctionType>::get(iBuilder->getContext());
    155111    assert ("FunctionTypeBuilder did not resolve a function type." && type);
    156     addExternalLink(kb, name, type, reinterpret_cast<void *>(functionPtr));
     112    return LinkFunction(kb.getModule(), name, type, reinterpret_cast<void *>(functionPtr));
    157113}
    158114
Note: See TracChangeset for help on using the changeset viewer.