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

Changes towards separate compilation

Location:
icGREP/icgrep-devel/icgrep
Files:
2 added
30 edited
6 moved

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/CMakeLists.txt

    r5423 r5425  
    5757link_directories(${Boost_LIBRARY_DIR})
    5858
    59 SET(OBJECT_CACHE_SRC kernels/object_cache.cpp)
    60 
    61 SET(KERNEL_SRC kernels/kernel.cpp kernels/pipeline.cpp kernels/streamset.cpp kernels/interface.cpp)
    62 SET(KERNEL_SRC ${KERNEL_SRC} kernels/toolchain.cpp)
     59SET(TOOLCHAIN_SRC toolchain/toolchain.cpp toolchain/pipeline.cpp toolchain/object_cache.cpp)
     60
     61SET(KERNEL_SRC kernels/kernel.cpp kernels/streamset.cpp kernels/interface.cpp)
    6362SET(KERNEL_SRC ${KERNEL_SRC} kernels/s2p_kernel.cpp kernels/mmap_kernel.cpp kernels/deletion.cpp kernels/swizzle.cpp kernels/p2s_kernel.cpp kernels/stdin_kernel.cpp kernels/stdout_kernel.cpp)
    6463
     
    7574ENDIF()
    7675
    77 add_library(CodeGen ${KERNEL_SRC} ${OBJECT_CACHE_SRC} ${IDISA_SRC})
     76add_library(CodeGen ${TOOLCHAIN_SRC} ${KERNEL_SRC} ${IDISA_SRC})
    7877add_library(PabloADT ${PABLO_SRC})
    7978add_library(RegExpADT re/re_re.cpp re/re_cc.cpp re/re_rep.cpp re/re_diff.cpp re/re_intersect.cpp re/printer_re.cpp)
  • icGREP/icgrep-devel/icgrep/IR_Gen/CBuilder.cpp

    r5424 r5425  
    1212#include <llvm/IR/MDBuilder.h>
    1313#include <llvm/Support/raw_ostream.h>
    14 #include <kernels/toolchain.h>
    15 #include <llvm/ADT/Triple.h>
    16 #include <fcntl.h>
    17 #include <unistd.h>
     14#include <toolchain/toolchain.h>
    1815#include <sys/mman.h>
    19 #include <sys/stat.h>
    20 #include <errno.h>
    2116
    2217using namespace llvm;
     
    4136        PointerType * int8PtrTy = getInt8PtrTy();
    4237        write = cast<Function>(mMod->getOrInsertFunction("write",
    43                                                         AttributeSet().addAttribute(mMod->getContext(), 2U, Attribute::NoAlias),
     38                                                        AttributeSet().addAttribute(getContext(), 2U, Attribute::NoAlias),
    4439                                                        sizeTy, int32Ty, int8PtrTy, sizeTy, nullptr));
    4540    }
     
    4742}
    4843
    49 Value * CBuilder::CreateReadCall(Value * fildes, Value * buf, Value * nbyte) {
     44Value * CBuilder::CreateReadCall(Value * fileDescriptor, Value * buf, Value * nbyte) {
    5045    Function * readFn = mMod->getFunction("read");
    5146    if (readFn == nullptr) {
     
    5449        PointerType * int8PtrTy = getInt8PtrTy();
    5550        readFn = cast<Function>(mMod->getOrInsertFunction("read",
    56                                                          AttributeSet().addAttribute(mMod->getContext(), 2U, Attribute::NoAlias),
     51                                                         AttributeSet().addAttribute(getContext(), 2U, Attribute::NoAlias),
    5752                                                         sizeTy, int32Ty, int8PtrTy, sizeTy, nullptr));
    5853    }
    59     return CreateCall(readFn, {fildes, buf, nbyte});
     54    return CreateCall(readFn, {fileDescriptor, buf, nbyte});
    6055}
    6156
     
    6762        closeFn = Function::Create(fty, Function::ExternalLinkage, "close", mMod);
    6863    }
    69     return CreateCall(closeFn, {fileDescriptor});
     64    return CreateCall(closeFn, fileDescriptor);
    7065}
    7166
     
    7873        unlinkFunc->setCallingConv(CallingConv::C);
    7974    }
    80     return CreateCall(unlinkFunc, {path});
    81 }
    82 
    83 Value * CBuilder::CreateFileSize(Value * fileDescriptor) {
    84     Function * fileSizeFunc = mMod->getFunction("file_size");
    85     if (fileSizeFunc == nullptr) {
    86         FunctionType * fty = FunctionType::get(getSizeTy(), {getInt32Ty()}, true);
    87         fileSizeFunc = Function::Create(fty, Function::ExternalLinkage, "file_size", mMod);
    88     }
    89     return CreateCall(fileSizeFunc, {fileDescriptor});
     75    return CreateCall(unlinkFunc, path);
    9076}
    9177
     
    9581        mkstempFn = cast<Function>(mMod->getOrInsertFunction("mkstemp", getInt32Ty(), getInt8PtrTy(), nullptr));
    9682    }
    97     return CreateCall(mkstempFn, {ftemplate});
     83    return CreateCall(mkstempFn, ftemplate);
    9884}
    9985
     
    10490        strlenFn = cast<Function>(mMod->getOrInsertFunction("strlen", getSizeTy(), getInt8PtrTy(), nullptr));
    10591    }
    106     return CreateCall(strlenFn, {str});
     92    return CreateCall(strlenFn, str);
    10793}
    10894
     
    135121        auto arg = function->arg_begin();
    136122        std::string out = "%-40s = %" PRIx64 "\n";
    137         BasicBlock * entry = BasicBlock::Create(mMod->getContext(), "entry", function);
     123        BasicBlock * entry = BasicBlock::Create(getContext(), "entry", function);
    138124        IRBuilder<> builder(entry);
    139125        std::vector<Value *> args;
     
    167153        auto arg = function->arg_begin();
    168154        std::string out = "%-40s = %" PRIx64 "\n";
    169         BasicBlock * entry = BasicBlock::Create(mMod->getContext(), "entry", function);
     155        BasicBlock * entry = BasicBlock::Create(getContext(), "entry", function);
    170156        IRBuilder<> builder(entry);
    171157        std::vector<Value *> args;
     
    200186        auto arg = function->arg_begin();
    201187        std::string out = "%s\n";
    202         BasicBlock * entry = BasicBlock::Create(mMod->getContext(), "entry", function);
     188        BasicBlock * entry = BasicBlock::Create(getContext(), "entry", function);
    203189        IRBuilder<> builder(entry);
    204190        std::vector<Value *> args;
     
    260246        aligned_malloc->addFnAttr(Attribute::AlwaysInline);
    261247        Value * size = &*aligned_malloc->arg_begin();
    262         SetInsertPoint(BasicBlock::Create(mMod->getContext(), "entry", aligned_malloc));
     248        SetInsertPoint(BasicBlock::Create(getContext(), "entry", aligned_malloc));
    263249        const auto byteWidth = (intTy->getBitWidth() / 8);
    264250        Constant * const offset = ConstantInt::get(intTy, alignment + byteWidth - 1);
     
    341327 */
    342328Value * CBuilder::CreateMAdvise(Value * addr, Value * length, Advice advice) {
    343     Triple T(mMod->getTargetTriple());
     329    Triple T(mTriple);
    344330    Value * result = nullptr;
    345331    if (T.isOSLinux() || T.isOSDarwin()) {
     
    383369
    384370Value * CBuilder::CreateMRemap(Value * addr, Value * oldSize, Value * newSize) {
    385     Triple T(mMod->getTargetTriple());
     371    Triple T(mTriple);
    386372    Value * ptr = nullptr;
    387373    if (T.isOSLinux()) {
     
    714700    IntegerType * ty = cast<IntegerType>(value->getType());
    715701    CreateAssert(value, "CreateCeilLog2: value cannot be zero");
    716     Value * m = CreateCountForwardZeroes(CreateSub(value, ConstantInt::get(ty, 1)));
     702    Value * m = CreateCountReverseZeroes(CreateSub(value, ConstantInt::get(ty, 1)));
    717703    return CreateSub(ConstantInt::get(m->getType(), ty->getBitWidth() - 1), m);
    718704}
     
    732718}
    733719
    734 
    735 CBuilder::CBuilder(Module * const m, const unsigned GeneralRegisterWidthInBits, const bool SupportsIndirectBr, const unsigned CacheLineAlignmentInBytes)
    736 : IRBuilder<>(m->getContext())
    737 , mMod(m)
     720Function * CBuilder::LinkFunction(llvm::StringRef name, FunctionType * type, void * functionPtr) const {
     721    assert (mDriver);
     722    return mDriver->LinkFunction(mMod, name, type, functionPtr);
     723}
     724
     725CBuilder::CBuilder(Module * const module, const unsigned GeneralRegisterWidthInBits, const bool SupportsIndirectBr, const unsigned CacheLineAlignmentInBytes)
     726: IRBuilder<>(module->getContext())
     727, mMod(module)
    738728, mCacheLineAlignment(CacheLineAlignmentInBytes)
    739729, mSizeType(getIntNTy(GeneralRegisterWidthInBits))
    740730, mFILEtype(nullptr)
    741 , mSupportsIndirectBr(SupportsIndirectBr) {
    742 }
     731, mSupportsIndirectBr(SupportsIndirectBr)
     732, mDriver(nullptr) {
     733
     734}
  • icGREP/icgrep-devel/icgrep/IR_Gen/CBuilder.h

    r5424 r5425  
    66#define CBUILDER_H
    77
    8 #include <string>
     8#include <IR_Gen/FunctionTypeBuilder.h>
    99#include <llvm/IR/IRBuilder.h>
    1010#include <llvm/IR/Constants.h>
     11#include <llvm/ADT/Triple.h>
     12
     13namespace kernels { class KernelBuilder; }
    1114namespace llvm { class Function; }
    1215namespace llvm { class IntegerType; }
     
    1619namespace llvm { class Value; }
    1720
     21class ParabixDriver;
     22
    1823class CBuilder : public llvm::IRBuilder<> {
    19    
     24    friend class ParabixDriver;
    2025public:
    2126
    22     CBuilder(llvm::Module * m, const unsigned GeneralRegisterWidthInBits, const bool SupportsIndirectBr, const unsigned CacheLineAlignmentInBytes = 64);
     27    CBuilder(llvm::Module * const module, const unsigned GeneralRegisterWidthInBits, const bool SupportsIndirectBr, const unsigned CacheLineAlignmentInBytes = 64);
    2328   
    2429    virtual ~CBuilder() {}
     
    2833    }
    2934   
    30     void setModule(llvm::Module * m)  {
     35    void setModule(llvm::Module * m) {
     36        assert (m);
    3137        mMod = m;
    3238    }
     39
    3340
    3441    llvm::Value * CreateMalloc(llvm::Value * size);
     
    138145
    139146    inline llvm::IntegerType * getSizeTy() const {
     147        assert (mSizeType);
    140148        return mSizeType;
    141149    }
     
    180188    llvm::Value * CreateReadCycleCounter();
    181189
     190    template <typename ExternalFunctionType>
     191    llvm::Function * LinkFunction(llvm::StringRef name, ExternalFunctionType * functionPtr) const;
     192
    182193protected:
    183     llvm::Module *                  mMod;
     194
     195    llvm::Function * LinkFunction(llvm::StringRef name, llvm::FunctionType * type, void * functionPtr) const;
     196
     197    void setDriver(ParabixDriver * driver) {
     198        mDriver = driver;
     199    }
     200
     201protected:
     202    llvm::Module *                  mMod;   
    184203    unsigned                        mCacheLineAlignment;
    185204    llvm::IntegerType *             mSizeType;
    186205    llvm::StructType *              mFILEtype;
    187206    const bool                      mSupportsIndirectBr;
     207    ParabixDriver *                 mDriver;
     208    llvm::LLVMContext               mContext;
     209    const std::string               mTriple;
    188210};
    189211
     212template <typename ExternalFunctionType>
     213llvm::Function *CBuilder::LinkFunction(llvm::StringRef name, ExternalFunctionType * functionPtr) const {
     214    llvm::FunctionType * const type = FunctionTypeBuilder<ExternalFunctionType>::get(getContext());
     215    assert ("FunctionTypeBuilder did not resolve a function type." && type);
     216    return LinkFunction(name, type, reinterpret_cast<void *>(functionPtr));
     217}
     218
    190219#endif
  • icGREP/icgrep-devel/icgrep/IR_Gen/CudaDriver.h

    r5402 r5425  
    66#include <unistd.h>
    77#include <cassert>
    8 #include <kernels/toolchain.h>
     8#include <toolchain/toolchain.h>
    99#include "cuda.h"
    1010
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_avx_builder.h

    r5374 r5425  
    1616public:
    1717   
    18     IDISA_AVX_Builder(Module * m, unsigned archBitWidth, unsigned bitBlockWidth)
    19     : IDISA_SSE2_Builder(m, archBitWidth, bitBlockWidth) {
     18    IDISA_AVX_Builder(llvm::Module * const module, unsigned archBitWidth, unsigned bitBlockWidth)
     19    : IDISA_SSE2_Builder(module, archBitWidth, bitBlockWidth) {
    2020    }
     21
    2122    virtual std::string getBuilderUniqueName() override;
    2223    Value * hsimd_signmask(unsigned fw, Value * a) override;
     
    2829public:
    2930   
    30     IDISA_AVX2_Builder(Module * m, unsigned archBitWidth, unsigned bitBlockWidth)
    31     : IDISA_AVX_Builder(m, archBitWidth, bitBlockWidth) {
     31    IDISA_AVX2_Builder(llvm::Module * const module, unsigned archBitWidth, unsigned bitBlockWidth)
     32    : IDISA_AVX_Builder(module, archBitWidth, bitBlockWidth) {
    3233    }
     34
    3335    virtual std::string getBuilderUniqueName() override;
    3436    Value * hsimd_packh(unsigned fw, Value * a, Value * b) override;
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_builder.cpp

    r5402 r5425  
    1313#include <llvm/Support/raw_ostream.h>
    1414#include <llvm/IR/TypeBuilder.h>
    15 #include <kernels/toolchain.h>
     15#include <toolchain/toolchain.h>
    1616
    1717using namespace llvm;
     
    376376}
    377377
    378 IDISA_Builder::IDISA_Builder(Module * m, unsigned archBitWidth, unsigned bitBlockWidth, unsigned stride, const bool SupportsIndirectBr, unsigned CacheAlignment)
    379 : CBuilder(m, archBitWidth, SupportsIndirectBr, CacheAlignment)
     378IDISA_Builder::IDISA_Builder(llvm::Module * const module, unsigned archBitWidth, unsigned bitBlockWidth, unsigned stride, const bool SupportsIndirectBr, unsigned CacheAlignment)
     379: CBuilder(module, archBitWidth, SupportsIndirectBr, CacheAlignment)
    380380, mBitBlockWidth(bitBlockWidth)
    381381, mStride(stride)
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_builder.h

    r5398 r5425  
    2020public:
    2121
    22     IDISA_Builder(llvm::Module * m, unsigned archBitWidth, unsigned bitBlockWidth, unsigned stride, const bool SupportsIndirectBr=true, unsigned CacheAlignment=64);
     22    IDISA_Builder(llvm::Module * const module, unsigned archBitWidth, unsigned bitBlockWidth, unsigned stride, const bool SupportsIndirectBr=true, unsigned CacheAlignment=64);
    2323
    2424    virtual ~IDISA_Builder();
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_i64_builder.h

    r5374 r5425  
    1616public:
    1717 
    18     IDISA_I64_Builder(Module * m, unsigned archBitWidth, unsigned bitBlockWidth = 64, unsigned stride = 64, const bool SupportsIndirectBr = true)
    19     : IDISA_Builder(m, archBitWidth, bitBlockWidth, stride, SupportsIndirectBr) {
     18    IDISA_I64_Builder(llvm::Module * const module, unsigned archBitWidth, unsigned bitBlockWidth = 64, unsigned stride = 64, const bool SupportsIndirectBr = true)
     19    : IDISA_Builder(module, archBitWidth, bitBlockWidth, stride, SupportsIndirectBr) {
     20
    2021    }
     22
    2123    virtual std::string getBuilderUniqueName() override;
    2224
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_nvptx_builder.h

    r5374 r5425  
    1616public:
    1717   
    18     IDISA_NVPTX20_Builder(Module * m, unsigned groupSize)
    19     : IDISA_I64_Builder(m, 64, 64, 64 * groupSize, false)
     18    IDISA_NVPTX20_Builder(llvm::Module * const module, unsigned groupSize)
     19    : IDISA_I64_Builder(module, 64, 64, 64 * groupSize, false)
    2020    , groupThreads(groupSize) {
    2121        CreateGlobals();
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_sse_builder.h

    r5374 r5425  
    1717public:
    1818 
    19     IDISA_SSE_Builder(Module * m, unsigned archBitWidth, unsigned bitBlockWidth)
    20     : IDISA_Builder(m, archBitWidth, bitBlockWidth, bitBlockWidth) {
     19    IDISA_SSE_Builder(llvm::Module * const module, unsigned archBitWidth, unsigned bitBlockWidth)
     20    : IDISA_Builder(module, archBitWidth, bitBlockWidth, bitBlockWidth) {
    2121    }
     22
    2223    virtual std::string getBuilderUniqueName() override;
    2324    Value * hsimd_signmask(unsigned fw, Value * a) override;
     
    2930public:
    3031 
    31     IDISA_SSE2_Builder(Module * m, unsigned archBitWidth, unsigned bitBlockWidth)
    32     : IDISA_SSE_Builder(m, archBitWidth, bitBlockWidth) {
     32    IDISA_SSE2_Builder(llvm::Module * const module, unsigned archBitWidth, unsigned bitBlockWidth)
     33    : IDISA_SSE_Builder(module, archBitWidth, bitBlockWidth) {
    3334    }
     35
    3436    virtual std::string getBuilderUniqueName() override;
    3537    Value * hsimd_signmask(unsigned fw, Value * a) override;
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_target.cpp

    r5402 r5425  
    55
    66#include "idisa_target.h"
    7 #include <kernels/toolchain.h>
     7#include <toolchain/toolchain.h>
    88#include <IR_Gen/idisa_avx_builder.h>
    99#include <IR_Gen/idisa_sse_builder.h>
     
    1515namespace IDISA {
    1616   
    17 IDISA_Builder * GetIDISA_Builder(llvm::Module * const mod) {
    18     if (LLVM_UNLIKELY(mod == nullptr)) {
    19         report_fatal_error("GetIDISA_Builder: module cannot be null");
    20     }
    21     if (LLVM_LIKELY(mod->getTargetTriple().empty())) {
    22         mod->setTargetTriple(llvm::sys::getProcessTriple());
    23     }
     17IDISA_Builder * GetIDISA_Builder(llvm::Module * const module) {
    2418    unsigned registerWidth = 0;
    25     Triple T(mod->getTargetTriple());
     19    Triple T(module->getTargetTriple());
    2620    if (T.isArch64Bit()) {
    2721        registerWidth = 64;
     
    3731    if (codegen::BlockSize >= 256) {
    3832        if (hasAVX2) {
    39             return new IDISA_AVX2_Builder(mod, registerWidth, codegen::BlockSize);
     33            return new IDISA_AVX2_Builder(module, registerWidth, codegen::BlockSize);
    4034        }
    4135    } else if (codegen::BlockSize == 64) {
    42         return new IDISA_I64_Builder(mod, registerWidth);
     36        return new IDISA_I64_Builder(module, registerWidth);
    4337    }
    44     return new IDISA_SSE2_Builder(mod, registerWidth, codegen::BlockSize);
     38    return new IDISA_SSE2_Builder(module, registerWidth, codegen::BlockSize);
    4539}
    4640
    47 IDISA_Builder * GetIDISA_GPU_Builder(llvm::Module * const mod) {
    48     return new IDISA_NVPTX20_Builder(mod, 64);
     41IDISA_Builder * GetIDISA_GPU_Builder(llvm::Module * const module) {
     42    return new IDISA_NVPTX20_Builder(module, 64);
    4943}
    5044
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_target.h

    r5361 r5425  
    77#define IDISA_TARGET_H
    88
     9#include <string>
    910namespace llvm { class Module; }
    1011namespace IDISA { class IDISA_Builder; }
     
    1213namespace IDISA {
    1314   
    14 IDISA::IDISA_Builder * GetIDISA_Builder(llvm::Module * const m);
     15IDISA::IDISA_Builder * GetIDISA_Builder(llvm::Module * const module);
    1516
    16 IDISA::IDISA_Builder * GetIDISA_GPU_Builder(llvm::Module * const m);
     17IDISA::IDISA_Builder * GetIDISA_GPU_Builder(llvm::Module * const module);
    1718
    1819}
  • icGREP/icgrep-devel/icgrep/array-test.cpp

    r5402 r5425  
    1111#include <kernels/alignedprint.h>
    1212#include <kernels/streamset.h>                     // for SingleBlockBuffer
    13 #include <kernels/pipeline.h>
    1413#include <llvm/ExecutionEngine/ExecutionEngine.h>  // for ExecutionEngine
    1514#include <llvm/IR/Function.h>                      // for Function, Function...
     
    2120#include <pablo/pe_zeroes.h>
    2221#include <pablo/pe_ones.h>
    23 #include <kernels/toolchain.h>
     22#include <toolchain/toolchain.h>
    2423#include <pablo/builder.hpp>                       // for PabloBuilder
    2524#include <boost/filesystem.hpp>
     
    185184
    186185MatchParens generateAlgorithm() {
    187     LLVMContext ctx;
    188     Module * M = new Module("mp", ctx);
    189     IDISA::IDISA_Builder * idb = IDISA::GetIDISA_Builder(M);
    190     ParabixDriver pxDriver(idb);
     186    ParabixDriver pxDriver("mp");
    191187    pipeline(pxDriver, 3);
    192     delete idb;
    193188    return reinterpret_cast<MatchParens>(pxDriver.getPointerToMain());
    194189}
  • icGREP/icgrep-devel/icgrep/base64.cpp

    r5418 r5425  
    1111#include <llvm/IR/Verifier.h>
    1212#include <llvm/Support/CommandLine.h>
    13 #include <kernels/toolchain.h>
     13#include <toolchain/toolchain.h>
    1414#include <IR_Gen/idisa_builder.h>
    1515#include <IR_Gen/idisa_target.h>
    16 #include <kernels/pipeline.h>
    1716#include <kernels/mmap_kernel.h>
    1817#include <kernels/streamset.h>
     
    4039void base64PipelineGen(ParabixDriver & pxDriver) {
    4140       
    42     IDISA::IDISA_Builder * iBuilder = pxDriver.getIDISA_Builder();
     41    auto iBuilder = pxDriver.getIDISA_Builder();
    4342    Module * mod = iBuilder->getModule();
    44     Type * mBitBlockType = iBuilder->getBitBlockType();
     43    Type * bitBlockType = iBuilder->getBitBlockType();
    4544
    46     Type * const voidTy = Type::getVoidTy(mod->getContext());
     45    Type * const voidTy = iBuilder->getVoidTy();
    4746    Type * const int32Ty = iBuilder->getInt32Ty();
    48     Type * const outputType = PointerType::get(ArrayType::get(ArrayType::get(mBitBlockType, 8), 1), 0);
     47    Type * const outputType = PointerType::get(ArrayType::get(ArrayType::get(bitBlockType, 8), 1), 0);
    4948   
    5049   
     
    103102
    104103base64FunctionType base64CodeGen(void) {
    105     LLVMContext TheContext;                           
    106     Module * M = new Module("base64", TheContext);
    107     IDISA::IDISA_Builder * idb = IDISA::GetIDISA_Builder(M);
    108     ParabixDriver pxDriver(idb);
    109    
     104    ParabixDriver pxDriver("base64");
    110105    base64PipelineGen(pxDriver);
    111     base64FunctionType main = reinterpret_cast<base64FunctionType>(pxDriver.getPointerToMain());
    112    
    113     delete idb;
    114     return main;
     106    return reinterpret_cast<base64FunctionType>(pxDriver.getPointerToMain());
    115107}
    116108
  • icGREP/icgrep-devel/icgrep/editd/editd.cpp

    r5418 r5425  
    88#include <iostream>
    99#include <fstream>
    10 #include <kernels/toolchain.h>
     10#include <toolchain/toolchain.h>
    1111#include <pablo/pablo_toolchain.h>
    1212#include <llvm/IR/Function.h>
     
    2525#include <kernels/s2p_kernel.h>
    2626#include <editd/editdscan_kernel.h>
    27 #include <kernels/pipeline.h>
    2827#include <editd/pattern_compiler.h>
    2928#include <sys/stat.h>
     
    324323
    325324preprocessFunctionType preprocessCodeGen() {                           
    326     LLVMContext TheContext;
    327     Module * M = new Module("preprocess", TheContext);
    328     IDISA::IDISA_Builder * idb = IDISA::GetIDISA_Builder(M);
    329     ParabixDriver pxDriver(idb);
     325    ParabixDriver pxDriver("preprocess");
    330326    preprocessPipeline(pxDriver);
    331     auto f = reinterpret_cast<preprocessFunctionType>(pxDriver.getPointerToMain());
    332     delete idb;
    333     return f;
     327    return reinterpret_cast<preprocessFunctionType>(pxDriver.getPointerToMain());
    334328}
    335329
     
    337331
    338332editdFunctionType editdCodeGen(const std::vector<std::string> & patterns) {                           
    339     LLVMContext TheContext;
    340     Module * M = new Module("editd", TheContext);
    341     IDISA::IDISA_Builder * const idb = IDISA::GetIDISA_Builder(M);
    342     ParabixDriver pxDriver(idb);
     333    ParabixDriver pxDriver("editd");
    343334    editdPipeline(pxDriver, patterns);
    344     auto f = reinterpret_cast<editdFunctionType>(pxDriver.getPointerToMain());
    345     delete idb;
    346     return f;
     335    return reinterpret_cast<editdFunctionType>(pxDriver.getPointerToMain());
    347336}
    348337
     
    357346    return st.st_size;
    358347}
    359 
    360348
    361349char * preprocess(preprocessFunctionType fn_ptr) {
  • icGREP/icgrep-devel/icgrep/grep_engine.cpp

    r5419 r5425  
    1212#include <boost/filesystem.hpp>
    1313#include <IR_Gen/idisa_builder.h>
    14 #include <IR_Gen/idisa_target.h>
    1514#include <UCD/UnicodeNameData.h>
    1615#include <UCD/resolve_properties.h>
     
    2827#include <re/re_cc.h>
    2928#include <re/re_toolchain.h>
    30 #include <kernels/toolchain.h>
     29#include <toolchain/toolchain.h>
    3130#include <iostream>
    3231#include <sstream>
     
    194193}
    195194
    196 inline void linkGrepFunction(ParabixDriver & pxDriver, const GrepType grepType, const bool UTF_16, kernel::KernelBuilder & kernel) {
    197     switch (grepType) {
    198         case GrepType::Normal:
    199             if (UTF_16) {
    200                 pxDriver.addExternalLink(kernel, "matcher", &wrapped_report_match<uint16_t>);
    201             } else {
    202                 pxDriver.addExternalLink(kernel, "matcher", &wrapped_report_match<uint8_t>);
    203             }
    204             break;
    205         case GrepType::NameExpression:
    206             pxDriver.addExternalLink(kernel, "matcher", &insert_codepoints);
    207             break;
    208         case GrepType::PropertyValue:
    209             pxDriver.addExternalLink(kernel, "matcher", &insert_property_values);
    210             break;
    211     }
    212 }
    213 
    214 void GrepEngine::grepCodeGen(std::string moduleName, std::vector<re::RE *> REs, const bool CountOnly, const bool UTF_16, GrepSource grepSource, const GrepType grepType) {
    215 
    216     Module * M = new Module(moduleName + ":icgrep", getGlobalContext());;
    217     IDISA::IDISA_Builder * iBuilder = IDISA::GetIDISA_Builder(M);;
    218     ParabixDriver pxDriver(iBuilder);
     195void GrepEngine::grepCodeGen(const std::string & moduleName, std::vector<re::RE *> REs, const bool CountOnly, const bool UTF_16, GrepSource grepSource, const GrepType grepType) {
     196
     197    ParabixDriver pxDriver(moduleName + ":icgrep");
     198    auto idb = pxDriver.getIDISA_Builder();
     199    Module * M = idb->getModule();
    219200
    220201    const unsigned segmentSize = codegen::SegmentSize;
     
    222203    const unsigned encodingBits = UTF_16 ? 16 : 8;
    223204
    224     Type * const int64Ty = iBuilder->getInt64Ty();
    225     Type * const int32Ty = iBuilder->getInt32Ty();
     205    Type * const int64Ty = idb->getInt64Ty();
     206    Type * const int32Ty = idb->getInt32Ty();
    226207
    227208    Function * mainFunc = nullptr;
     
    232213    if (grepSource == GrepSource::Internal) {
    233214
    234         mainFunc = cast<Function>(M->getOrInsertFunction("Main", int64Ty, iBuilder->getInt8PtrTy(), int64Ty, int32Ty, nullptr));
     215        mainFunc = cast<Function>(M->getOrInsertFunction("Main", int64Ty, idb->getInt8PtrTy(), int64Ty, int32Ty, nullptr));
    235216        mainFunc->setCallingConv(CallingConv::C);
    236         iBuilder->SetInsertPoint(BasicBlock::Create(M->getContext(), "entry", mainFunc, 0));
    237         Function::arg_iterator args = mainFunc->arg_begin();
     217        idb->SetInsertPoint(BasicBlock::Create(M->getContext(), "entry", mainFunc, 0));
     218        auto args = mainFunc->arg_begin();
    238219
    239220        Value * const buffer = &*(args++);
     
    242223        Value * length = &*(args++);
    243224        length->setName("length");
    244         length = iBuilder->CreateZExtOrTrunc(length, iBuilder->getSizeTy());
     225        length = idb->CreateZExtOrTrunc(length, idb->getSizeTy());
    245226
    246227        fileIdx = &*(args++);
    247228        fileIdx->setName("fileIdx");
    248229
    249         ByteStream = pxDriver.addBuffer(make_unique<SourceFileBuffer>(iBuilder, iBuilder->getStreamSetTy(1, 8)));
    250 
    251         sourceK = pxDriver.addKernelInstance(make_unique<kernel::FileSourceKernel>(iBuilder, iBuilder->getInt8PtrTy(), segmentSize));
     230        ByteStream = pxDriver.addBuffer(make_unique<SourceFileBuffer>(idb, idb->getStreamSetTy(1, 8)));
     231
     232        sourceK = pxDriver.addKernelInstance(make_unique<kernel::FileSourceKernel>(idb, idb->getInt8PtrTy(), segmentSize));
    252233        sourceK->setInitialArguments({buffer, length});
    253234
    254235    } else {
    255236
    256         mainFunc = cast<Function>(M->getOrInsertFunction("Main", int64Ty, iBuilder->getInt32Ty(), int32Ty, nullptr));
     237        mainFunc = cast<Function>(M->getOrInsertFunction("Main", int64Ty, idb->getInt32Ty(), int32Ty, nullptr));
    257238        mainFunc->setCallingConv(CallingConv::C);
    258         iBuilder->SetInsertPoint(BasicBlock::Create(M->getContext(), "entry", mainFunc, 0));
    259         Function::arg_iterator args = mainFunc->arg_begin();
     239        idb->SetInsertPoint(BasicBlock::Create(M->getContext(), "entry", mainFunc, 0));
     240        auto args = mainFunc->arg_begin();
    260241
    261242        Value * const fileDescriptor = &*(args++);
     
    265246
    266247        if (grepSource == GrepSource::File) {
    267             ByteStream = pxDriver.addBuffer(make_unique<SourceFileBuffer>(iBuilder, iBuilder->getStreamSetTy(1, 8)));
    268             sourceK = pxDriver.addKernelInstance(make_unique<kernel::MMapSourceKernel>(iBuilder, segmentSize));
     248            ByteStream = pxDriver.addBuffer(make_unique<SourceFileBuffer>(idb, idb->getStreamSetTy(1, 8)));
     249            sourceK = pxDriver.addKernelInstance(make_unique<kernel::MMapSourceKernel>(idb, segmentSize));
    269250            sourceK->setInitialArguments({fileDescriptor});
    270251        } else { // if (grepSource == GrepSource::StdIn) {
    271             ByteStream = pxDriver.addBuffer(make_unique<ExtensibleBuffer>(iBuilder, iBuilder->getStreamSetTy(1, 8), segmentSize));
    272             sourceK = pxDriver.addKernelInstance(make_unique<kernel::StdInKernel>(iBuilder, segmentSize));
     252            ByteStream = pxDriver.addBuffer(make_unique<ExtensibleBuffer>(idb, idb->getStreamSetTy(1, 8), segmentSize));
     253            sourceK = pxDriver.addKernelInstance(make_unique<kernel::StdInKernel>(idb, segmentSize));
    273254        }
    274255    }
    275256
    276257    pxDriver.makeKernelCall(sourceK, {}, {ByteStream});
    277     StreamSetBuffer * BasisBits = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(8, 1), segmentSize * bufferSegments));
     258    StreamSetBuffer * BasisBits = pxDriver.addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(8, 1), segmentSize * bufferSegments));
    278259   
    279     kernel::KernelBuilder * s2pk = pxDriver.addKernelInstance(make_unique<kernel::S2PKernel>(iBuilder));
     260    kernel::KernelBuilder * s2pk = pxDriver.addKernelInstance(make_unique<kernel::S2PKernel>(idb));
    280261    pxDriver.makeKernelCall(s2pk, {ByteStream}, {BasisBits});
    281262   
    282     kernel::KernelBuilder * linebreakK = pxDriver.addKernelInstance(make_unique<kernel::LineBreakKernelBuilder>(iBuilder, encodingBits));
    283     StreamSetBuffer * LineBreakStream = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(1, 1), segmentSize * bufferSegments));
     263    kernel::KernelBuilder * linebreakK = pxDriver.addKernelInstance(make_unique<kernel::LineBreakKernelBuilder>(idb, encodingBits));
     264    StreamSetBuffer * LineBreakStream = pxDriver.addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments));
    284265    pxDriver.makeKernelCall(linebreakK, {BasisBits}, {LineBreakStream});
    285266   
     
    289270
    290271    for(unsigned i = 0; i < n; ++i){
    291         StreamSetBuffer * MatchResults = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(1, 1), segmentSize * bufferSegments));
    292         kernel::KernelBuilder * icgrepK = pxDriver.addKernelInstance(make_unique<kernel::ICgrepKernelBuilder>(iBuilder, REs[i]));
     272        StreamSetBuffer * MatchResults = pxDriver.addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments));
     273        kernel::KernelBuilder * icgrepK = pxDriver.addKernelInstance(make_unique<kernel::ICgrepKernelBuilder>(idb, REs[i]));
    293274        pxDriver.makeKernelCall(icgrepK, {BasisBits, LineBreakStream}, {MatchResults});
    294275        MatchResultsBufs[i] = MatchResults;
     
    296277    StreamSetBuffer * MergedResults = MatchResultsBufs[0];
    297278    if (REs.size() > 1) {
    298         MergedResults = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(1, 1), segmentSize * bufferSegments));
    299         kernel::KernelBuilder * streamsMergeK = pxDriver.addKernelInstance(make_unique<kernel::StreamsMerge>(iBuilder, 1, REs.size()));
     279        MergedResults = pxDriver.addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments));
     280        kernel::KernelBuilder * streamsMergeK = pxDriver.addKernelInstance(make_unique<kernel::StreamsMerge>(idb, 1, REs.size()));
    300281        pxDriver.makeKernelCall(streamsMergeK, MatchResultsBufs, {MergedResults});
    301282    }
    302283   
    303284    if (AlgorithmOptionIsSet(re::InvertMatches)) {
    304         kernel::KernelBuilder * invertK = pxDriver.addKernelInstance(make_unique<kernel::InvertMatchesKernel>(iBuilder));
     285        kernel::KernelBuilder * invertK = pxDriver.addKernelInstance(make_unique<kernel::InvertMatchesKernel>(idb));
    305286        StreamSetBuffer * OriginalMatches = MergedResults;
    306         MergedResults = pxDriver.addBuffer(make_unique<CircularBuffer>(iBuilder, iBuilder->getStreamSetTy(1, 1), segmentSize * bufferSegments));
     287        MergedResults = pxDriver.addBuffer(make_unique<CircularBuffer>(idb, idb->getStreamSetTy(1, 1), segmentSize * bufferSegments));
    307288        pxDriver.makeKernelCall(invertK, {OriginalMatches, LineBreakStream}, {MergedResults});
    308289    }
    309290    if (CountOnly) {
    310         kernel::MatchCount matchCountK(iBuilder);
     291        kernel::MatchCount matchCountK(idb);
    311292        pxDriver.addKernelCall(matchCountK, {MergedResults}, {});
    312293        pxDriver.generatePipelineIR();
    313294        Value * matchedLineCount = matchCountK.getScalarField("matchedLineCount");
    314         matchedLineCount = iBuilder->CreateZExt(matchedLineCount, int64Ty);
    315         iBuilder->CreateRet(matchedLineCount);
     295        matchedLineCount = idb->CreateZExt(matchedLineCount, int64Ty);
     296        idb->CreateRet(matchedLineCount);
    316297        pxDriver.linkAndFinalize();
    317298    } else {
    318         kernel::ScanMatchKernel scanMatchK(iBuilder, grepType, encodingBits);
     299        kernel::ScanMatchKernel scanMatchK(idb, grepType, encodingBits);
    319300        scanMatchK.setInitialArguments({fileIdx});
    320301        pxDriver.addKernelCall(scanMatchK, {MergedResults, LineBreakStream, ByteStream}, {});
    321         linkGrepFunction(pxDriver, grepType, UTF_16, scanMatchK);
     302        switch (grepType) {
     303            case GrepType::Normal:
     304                if (UTF_16) {
     305                    pxDriver.LinkFunction(scanMatchK, "matcher", &wrapped_report_match<uint16_t>);
     306                } else {
     307                    pxDriver.LinkFunction(scanMatchK, "matcher", &wrapped_report_match<uint8_t>);
     308                }
     309                break;
     310            case GrepType::NameExpression:
     311                pxDriver.LinkFunction(scanMatchK, "matcher", &insert_codepoints);
     312                break;
     313            case GrepType::PropertyValue:
     314                pxDriver.LinkFunction(scanMatchK, "matcher", &insert_property_values);
     315                break;
     316        }
    322317        pxDriver.generatePipelineIR();
    323         iBuilder->CreateRet(iBuilder->getInt64(0));
     318        idb->CreateRet(idb->getInt64(0));
    324319        pxDriver.linkAndFinalize();
    325320    }
  • icGREP/icgrep-devel/icgrep/grep_engine.h

    r5419 r5425  
    1919    GrepEngine();
    2020
    21     void grepCodeGen(std::string moduleName, std::vector<re::RE *> REs, bool CountOnly, bool UTF_16, GrepSource grepSource, GrepType grepType = GrepType::Normal);
     21    void grepCodeGen(const std::string & moduleName, std::vector<re::RE *> REs, bool CountOnly, bool UTF_16, GrepSource grepSource, GrepType grepType = GrepType::Normal);
    2222
    2323    uint64_t doGrep(const std::string & fileName, const uint32_t fileIdx) const;
  • icGREP/icgrep-devel/icgrep/icgrep-devel.files

    r5418 r5425  
    1818IR_Gen/CBuilder.h
    1919IR_Gen/CudaDriver.h
     20IR_Gen/FunctionTypeBuilder.h
    2021IR_Gen/idisa_avx_builder.cpp
    2122IR_Gen/idisa_avx_builder.h
     
    5051kernels/linebreak_kernel.cpp
    5152kernels/linebreak_kernel.h
     53kernels/lz4_bytestream_decoder.cpp
     54kernels/lz4_bytestream_decoder.h
     55kernels/lz4_index_decoder.cpp
     56kernels/lz4_index_decoder.h
    5257kernels/match_count.cpp
    5358kernels/match_count.h
    5459kernels/mmap_kernel.cpp
    5560kernels/mmap_kernel.h
    56 kernels/object_cache.cpp
    57 kernels/object_cache.h
    5861kernels/p2s_kernel.cpp
    5962kernels/p2s_kernel.h
    60 kernels/pipeline.cpp
    61 kernels/pipeline.h
    6263kernels/radix64.cpp
    6364kernels/radix64.h
     
    7677kernels/swizzle.cpp
    7778kernels/swizzle.h
    78 kernels/toolchain.cpp
    79 kernels/toolchain.h
    8079pablo/analysis/pabloverifier.cpp
    8180pablo/analysis/pabloverifier.hpp
     
    187186re/re_utility.cpp
    188187re/re_utility.h
     188toolchain/object_cache.cpp
     189toolchain/object_cache.h
     190toolchain/pipeline.cpp
     191toolchain/pipeline.h
     192toolchain/toolchain.cpp
     193toolchain/toolchain.h
    189194UCD/Blocks.h
    190195UCD/CaseFolding_txt.cpp
     
    233238hrtime.h
    234239icgrep.cpp
     240lz4d.cpp
     241lz4FrameDecoder.cpp
     242lz4FrameDecoder.h
    235243u8u16.cpp
    236244utf16_encoder.cpp
  • icGREP/icgrep-devel/icgrep/icgrep-devel.includes

    r5240 r5425  
    2727IR_Gen
    2828IR_Gen/types
     29pipeline
     30toolchain
  • icGREP/icgrep-devel/icgrep/icgrep.cpp

    r5418 r5425  
    2121#include <string>
    2222#include <boost/uuid/sha1.hpp>
    23 #include <kernels/toolchain.h>
     23#include <toolchain/toolchain.h>
    2424#include <re/re_toolchain.h>
    2525#include <pablo/pablo_toolchain.h>
  • icGREP/icgrep-devel/icgrep/kernels/interface.cpp

    r5418 r5425  
    139139    args->setName("self");
    140140
     141    linkExternalMethods();
     142
    141143    iBuilder->setModule(saveModule);
    142144}
  • icGREP/icgrep-devel/icgrep/kernels/interface.h

    r5418 r5425  
    141141protected:
    142142
     143    virtual void linkExternalMethods() = 0;
     144
    143145    KernelInterface(IDISA::IDISA_Builder * builder,
    144146                    std::string kernelName,
  • icGREP/icgrep-devel/icgrep/kernels/kernel.cpp

    r5418 r5425  
    55
    66#include "kernel.h"
    7 #include <kernels/toolchain.h>
     7#include <toolchain/toolchain.h>
    88#include <kernels/streamset.h>
    99#include <llvm/IR/Constants.h>
  • icGREP/icgrep-devel/icgrep/kernels/kernel.h

    r5422 r5425  
    77#define KERNEL_BUILDER_H
    88
    9 #include "interface.h"      // for KernelInterface
     9#include "interface.h"
    1010#include <boost/container/flat_map.hpp>
    1111#include <IR_Gen/idisa_builder.h>
    12 #include <kernels/pipeline.h>
     12#include <toolchain/pipeline.h>
    1313#include <llvm/IR/Constants.h>
    14 
    15 //#include <string>           // for string
    16 //#include <memory>           // for unique_ptr
    1714
    1815namespace llvm { class Function; }
     
    3431    using Kernels = std::vector<KernelBuilder *>;
    3532
    36     friend void ::generateSegmentParallelPipeline(IDISA::IDISA_Builder *, const Kernels &);
    37     friend void ::generatePipelineLoop(IDISA::IDISA_Builder *, const Kernels &);
    38     friend void ::generateParallelPipeline(IDISA::IDISA_Builder *, const Kernels &);
     33    friend void ::generateSegmentParallelPipeline(std::unique_ptr<IDISA::IDISA_Builder> &, const Kernels &);
     34    friend void ::generatePipelineLoop(std::unique_ptr<IDISA::IDISA_Builder> &, const Kernels &);
     35    friend void ::generateParallelPipeline(std::unique_ptr<IDISA::IDISA_Builder> &, const Kernels &);
    3936public:
    4037   
     
    120117    }
    121118
    122 //    llvm::Value * getScalarField(llvm::Value * index) const {
    123 //        return iBuilder->CreateLoad(getScalarFieldPtr(index));
    124 //    }
    125 
    126119    // Set the value of a scalar field for the current instance.
    127120    void setScalarField(const std::string & fieldName, llvm::Value * value) const {
    128121        iBuilder->CreateStore(value, getScalarFieldPtr(fieldName));
    129122    }
    130 
    131 //    void setScalarField(llvm::Value * index, llvm::Value * value) const {
    132 //        iBuilder->CreateStore(value, getScalarFieldPtr(index));
    133 //    }
    134123
    135124    // Synchronization actions for executing a kernel for a particular logical segment.
     
    204193
    205194    void prepareStreamSetNameMap();
     195
     196    void linkExternalMethods() override { }
    206197
    207198    virtual void prepareKernel();
  • icGREP/icgrep-devel/icgrep/kernels/mmap_kernel.cpp

    r5421 r5425  
    77#include <IR_Gen/idisa_builder.h>
    88#include <kernels/streamset.h>
     9#include <sys/stat.h>
     10#include <fcntl.h>
    911
    1012using namespace llvm;
    1113
     14uint64_t file_size(const uint32_t fd) {
     15    struct stat st;
     16    if (LLVM_UNLIKELY(fstat(fd, &st) != 0)) {
     17        st.st_size = 0;
     18    }
     19    return st.st_size;
     20}
     21
    1222namespace kernel {
     23
     24void MMapSourceKernel::linkExternalMethods() {
     25    mFileSizeFunction = iBuilder->LinkFunction("file_size", &file_size);
     26}
    1327
    1428void MMapSourceKernel::generateInitializeMethod() {
     
    1731    BasicBlock * exit = CreateBasicBlock("Exit");
    1832
    19     Value * fd = getScalarField("fileDescriptor");
    20     Value * fileSize = iBuilder->CreateFileSize(fd);
     33    Value * const fd = getScalarField("fileDescriptor");
     34    Value * fileSize = iBuilder->CreateCall(mFileSizeFunction, fd);
    2135    if (mCodeUnitWidth > 8) {
    2236        fileSize = iBuilder->CreateUDiv(fileSize, iBuilder->getSize(mCodeUnitWidth / 8));
     
    120134    {Binding{iBuilder->getInt32Ty(), "fileDescriptor"}}, {Binding{iBuilder->getSizeTy(), "fileSize"}}, {Binding{iBuilder->getVoidPtrTy(), "readableBuffer"}})
    121135, mSegmentBlocks(blocksPerSegment)
    122 , mCodeUnitWidth(codeUnitWidth) {
     136, mCodeUnitWidth(codeUnitWidth)
     137, mFileSizeFunction(nullptr) {
    123138
    124139}
  • icGREP/icgrep-devel/icgrep/kernels/mmap_kernel.h

    r5418 r5425  
    1818public:
    1919    MMapSourceKernel(IDISA::IDISA_Builder * iBuilder, unsigned blocksPerSegment = 1, unsigned codeUnitWidth = 8); 
    20     bool moduleIDisSignature() override {return true;}
     20    bool moduleIDisSignature() override { return true; }
    2121private:
     22    void linkExternalMethods() override;
    2223    void generateInitializeMethod() override;
    2324    void generateDoSegmentMethod() override;
    2425    void generateFinalizeMethod() override;
    2526private:
    26     const unsigned mSegmentBlocks;
    27     const unsigned mCodeUnitWidth;
     27    const unsigned          mSegmentBlocks;
     28    const unsigned          mCodeUnitWidth;
     29    llvm::Function *        mFileSizeFunction;
    2830};
    2931
  • icGREP/icgrep-devel/icgrep/kernels/streamset.cpp

    r5418 r5425  
    1515#include <llvm/IR/CFG.h>
    1616#include <kernels/kernel.h>
    17 #include <kernels/toolchain.h>
     17#include <toolchain/toolchain.h>
    1818
    1919namespace llvm { class Constant; }
  • icGREP/icgrep-devel/icgrep/lz4d.cpp

    r5423 r5425  
    2020#include <lz4FrameDecoder.h>
    2121#include <cc/cc_compiler.h>
    22 #include <kernels/toolchain.h>
     22#include <toolchain/toolchain.h>
    2323#include <kernels/cc_kernel.h>
    2424#include <kernels/streamset.h>
     
    2929#include <kernels/lz4_index_decoder.h>
    3030#include <kernels/lz4_bytestream_decoder.h>
    31 #include <kernels/pipeline.h>
    3231
    3332#include <string>
     
    4645
    4746typedef void (*MainFunctionType)(char * byte_data, size_t filesize, bool hasBlockChecksum);
    48 
    49 ParabixDriver * pxDriver = nullptr;
    50 
    5147
    5248void generatePipeline(ParabixDriver & pxDriver) {
     
    116112
    117113MainFunctionType codeGen() {
    118     Module * M = new Module("lz4d", getGlobalContext());
    119     IDISA::IDISA_Builder * idb = IDISA::GetIDISA_Builder(M);
    120     pxDriver = new ParabixDriver(idb);
    121 
    122     generatePipeline(*pxDriver);
    123 
    124     delete idb;
    125     return reinterpret_cast<MainFunctionType>(pxDriver->getPointerToMain());
     114    ParabixDriver pxDriver("lz4d");
     115    generatePipeline(pxDriver);
     116    return reinterpret_cast<MainFunctionType>(pxDriver.getPointerToMain());
    126117}
    127118
  • icGREP/icgrep-devel/icgrep/toolchain/pipeline.cpp

    r5424 r5425  
    55
    66#include "pipeline.h"
    7 #include <kernels/toolchain.h>
     7#include <toolchain/toolchain.h>
    88#include <kernels/kernel.h>
    99#include <kernels/streamset.h>
     
    2222using FlatSet = boost::container::flat_set<Value>;
    2323
    24 Function * makeThreadFunction(IDISA::IDISA_Builder * const b, const std::string & name) {
     24Function * makeThreadFunction(std::unique_ptr<IDISA::IDISA_Builder> & b, const std::string & name) {
    2525    Function * const f = Function::Create(FunctionType::get(b->getVoidTy(), {b->getVoidPtrTy()}, false), Function::InternalLinkage, name, b->getModule());
    2626    f->setCallingConv(CallingConv::C);
     
    3838 * fashion such that processing of segment S_i by the full pipeline is carried out by thread i mod T.
    3939 ** ------------------------------------------------------------------------------------------------------------- */
    40 void generateSegmentParallelPipeline(IDISA::IDISA_Builder * iBuilder, const std::vector<KernelBuilder *> & kernels) {
     40void generateSegmentParallelPipeline(std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, const std::vector<KernelBuilder *> & kernels) {
    4141
    4242    const unsigned n = kernels.size();
     
    243243 * @brief generateParallelPipeline
    244244 ** ------------------------------------------------------------------------------------------------------------- */
    245 void generateParallelPipeline(IDISA::IDISA_Builder * iBuilder, const std::vector<KernelBuilder *> &kernels) {
     245void generateParallelPipeline(std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, const std::vector<KernelBuilder *> &kernels) {
    246246
    247247    Module * const m = iBuilder->getModule();
     
    435435 * @brief generatePipelineLoop
    436436 ** ------------------------------------------------------------------------------------------------------------- */
    437 void generatePipelineLoop(IDISA::IDISA_Builder * iBuilder, const std::vector<KernelBuilder *> & kernels) {
     437void generatePipelineLoop(std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, const std::vector<KernelBuilder *> & kernels) {
    438438
    439439    BasicBlock * entryBlock = iBuilder->GetInsertBlock();
  • icGREP/icgrep-devel/icgrep/toolchain/pipeline.h

    r5424 r5425  
    77
    88#include <vector>
     9#include <memory>
     10
    911namespace IDISA { class IDISA_Builder; }
    1012namespace kernel { class KernelBuilder; }
    1113
    12 void generateSegmentParallelPipeline(IDISA::IDISA_Builder * iBuilder, const std::vector<kernel::KernelBuilder *> & kernels);
    13 void generatePipelineLoop(IDISA::IDISA_Builder * iBuilder, const std::vector<kernel::KernelBuilder *> & kernels);
    14 void generateParallelPipeline(IDISA::IDISA_Builder * iBuilder, const std::vector<kernel::KernelBuilder *> & kernels);
     14void generateSegmentParallelPipeline(std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, const std::vector<kernel::KernelBuilder *> & kernels);
     15void generatePipelineLoop(std::unique_ptr<IDISA::IDISA_Builder> & iBuilder, const std::vector<kernel::KernelBuilder *> & kernels);
     16void generateParallelPipeline(std::unique_ptr<IDISA::IDISA_Builder> &iBuilder, const std::vector<kernel::KernelBuilder *> & kernels);
    1517
    1618#endif // PIPELINE_H
  • icGREP/icgrep-devel/icgrep/toolchain/toolchain.cpp

    r5424 r5425  
    66
    77#include "toolchain.h"
     8#include <IR_Gen/idisa_target.h>
    89#include <llvm/CodeGen/CommandFlags.h>             // for InitTargetOptionsF...
    910#include <llvm/ExecutionEngine/ExecutionEngine.h>  // for EngineBuilder
     
    2627#include <llvm/Transforms/Utils/Local.h>
    2728#include <llvm/IR/Module.h>
    28 #include <kernels/object_cache.h>
    29 #include <kernels/pipeline.h>
     29#include <toolchain/object_cache.h>
     30#include <toolchain/pipeline.h>
    3031#include <kernels/kernel.h>
    3132#include <sys/stat.h>
     
    7172bool EnableCycleCounter;
    7273#ifndef NDEBUG
    73 #define DEFAULT_TO_TRUE_IN_DEBUG_MODE true
     74#define IN_DEBUG_MODE true
    7475#else
    75 #define DEFAULT_TO_TRUE_IN_DEBUG_MODE false
     76#define IN_DEBUG_MODE false
    7677#endif
    7778
     
    8081static cl::opt<int, true> BufferSegmentsOption("buffer-segments", cl::location(BufferSegments), cl::desc("Buffer Segments"), cl::value_desc("positive integer"), cl::init(1));
    8182static cl::opt<int, true> ThreadNumOption("thread-num", cl::location(ThreadNum), cl::desc("Number of threads used for segment pipeline parallel"), cl::value_desc("positive integer"), cl::init(2));
    82 static cl::opt<bool, true> EnableAssertsOption("ea", cl::location(EnableAsserts), cl::desc("Enable Asserts"), cl::init(DEFAULT_TO_TRUE_IN_DEBUG_MODE));
     83static cl::opt<bool, true> EnableAssertsOption("ea", cl::location(EnableAsserts), cl::desc("Enable Asserts"), cl::init(IN_DEBUG_MODE));
    8384static cl::opt<bool, true> EnableCycleCountOption("ShowKernelCycles", cl::location(EnableCycleCounter), cl::desc("Count and report CPU cycles per kernel"), cl::init(false), cl::cat(CodeGenOptions));
    8485
     
    159160}
    160161
    161 ParabixDriver::ParabixDriver(IDISA::IDISA_Builder * iBuilder)
    162 : iBuilder(iBuilder)
    163 , mMainModule(iBuilder->getModule())
     162ParabixDriver::ParabixDriver(std::string && moduleName)
     163: mContext(new llvm::LLVMContext())
     164, mMainModule(new Module(moduleName, *mContext))
     165, iBuilder(nullptr)
    164166, mTarget(nullptr)
    165167, mEngine(nullptr)
    166 , mCache(nullptr)
    167 {
     168, mCache(nullptr) {
     169
    168170    InitializeNativeTarget();
    169171    InitializeNativeTargetAsmPrinter();
     
    182184
    183185    builder.setTargetOptions(opts);
    184     builder.setVerifyModules(true);
     186    builder.setVerifyModules(IN_DEBUG_MODE);
    185187    CodeGenOpt::Level optLevel = CodeGenOpt::Level::None;
    186188    switch (codegen::OptLevel) {
     
    194196
    195197    setAllFeatures(builder);
    196 
    197198    mEngine = builder.create();
    198199    if (mEngine == nullptr) {
     
    209210        mEngine->setObjectCache(mCache);
    210211    }
     212
     213    mMainModule->setTargetTriple(mTarget->getTargetTriple().getTriple());
     214
     215    iBuilder.reset(IDISA::GetIDISA_Builder(mMainModule));
     216    iBuilder->setDriver(this);
    211217}
    212218
    213219ExternalFileBuffer * ParabixDriver::addExternalBuffer(std::unique_ptr<ExternalFileBuffer> b, Value * externalBuf) {
    214     ExternalFileBuffer * rawBuf = b.get();
    215220    mOwnedBuffers.push_back(std::move(b));
     221    ExternalFileBuffer * rawBuf = cast<ExternalFileBuffer>(mOwnedBuffers.back().get());
    216222    rawBuf->setStreamSetBuffer(externalBuf);
    217223    return rawBuf;
     
    252258    }
    253259    #endif
     260
    254261    // note: instantiation of all kernels must occur prior to initialization
    255262    for (const auto & k : mPipeline) {
     
    275282}
    276283
    277 void ParabixDriver::addExternalLink(kernel::KernelBuilder & kb, llvm::StringRef name, FunctionType * type, void * functionPtr) const {
    278     assert ("addKernelCall or makeKernelCall must be called before addExternalLink" && (kb.getModule() != nullptr));
    279     mEngine->addGlobalMapping(cast<Function>(kb.getModule()->getOrInsertFunction(name, type)), functionPtr);
    280 }
    281 
    282 uint64_t file_size(const uint32_t fd) {
    283     struct stat st;
    284     if (LLVM_UNLIKELY(fstat(fd, &st) != 0)) {
    285         st.st_size = 0;
    286     }
    287     return st.st_size;
     284Function * ParabixDriver::LinkFunction(Module * mod, llvm::StringRef name, FunctionType * type, void * functionPtr) const {
     285    assert ("addKernelCall or makeKernelCall must be called before LinkFunction" && (mod != nullptr));
     286    Function * f = cast<Function>(mod->getOrInsertFunction(name, type));
     287    mEngine->addGlobalMapping(f, functionPtr);
     288    return f;
    288289}
    289290
     
    328329    }
    329330    #endif
    330 
    331     FunctionType * fileSizeType = FunctionType::get(iBuilder->getInt64Ty(), { iBuilder->getInt32Ty() });
    332     mEngine->addGlobalMapping(cast<Function>(mMainModule->getOrInsertFunction("file_size", fileSizeType)), (void *)&file_size);
    333331
    334332    PM.run(*m);
  • 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
  • icGREP/icgrep-devel/icgrep/u8u16.cpp

    r5418 r5425  
    2323#include <pablo/pablo_toolchain.h>                 // for pablo_function_passes
    2424#include <pablo/pe_zeroes.h>
    25 #include <kernels/toolchain.h>
     25#include <toolchain/toolchain.h>
    2626#include "kernels/streamset.h"                     // for CircularBuffer
    27 #include <kernels/pipeline.h>
    2827#include "llvm/ADT/StringRef.h"                    // for StringRef
    2928#include "llvm/IR/CallingConv.h"                   // for ::C
     
    358357void u8u16PipelineGen(ParabixDriver & pxDriver) {
    359358   
    360     IDISA::IDISA_Builder * iBuilder = pxDriver.getIDISA_Builder();
     359    auto iBuilder = pxDriver.getIDISA_Builder();
    361360    Module * mod = iBuilder->getModule();
    362361   
    363362    const unsigned segmentSize = codegen::SegmentSize;
    364363    const unsigned bufferSegments = codegen::ThreadNum+1;
    365    
    366     assert (iBuilder);
    367    
    368364    Type * const voidTy = iBuilder->getVoidTy();
    369365    Type * const bitBlockType = iBuilder->getBitBlockType();
     
    436432typedef void (*u8u16FunctionType)(uint32_t fd, char * output_data);
    437433
    438 u8u16FunctionType u8u16CodeGen(void) {
    439     LLVMContext TheContext;                           
    440     Module * M = new Module("u8u16", TheContext);
    441     IDISA::IDISA_Builder * idb = IDISA::GetIDISA_Builder(M);
    442     ParabixDriver pxDriver(idb);
    443    
     434u8u16FunctionType u8u16CodeGen() {
     435    ParabixDriver pxDriver("u8u16");
    444436    if (enableAVXdel && AVX2_available() && codegen::BlockSize==256) {
    445         //u8u16PipelineAVX2(M, idb)
    446437        u8u16PipelineAVX2Gen(pxDriver);
    447     }
    448     else{
    449         //u8u16Pipeline(M, idb);
     438    } else{
    450439        u8u16PipelineGen(pxDriver);
    451440    }
    452     u8u16FunctionType main = reinterpret_cast<u8u16FunctionType>(pxDriver.getPointerToMain());
    453 
    454     delete idb;
    455     return main;
     441    return reinterpret_cast<u8u16FunctionType>(pxDriver.getPointerToMain());
    456442}
    457443
  • icGREP/icgrep-devel/icgrep/wc.cpp

    r5418 r5425  
    88#include <iomanip>
    99#include <sstream>
    10 #include <kernels/toolchain.h>
     10#include <toolchain/toolchain.h>
    1111#include <llvm/IR/Function.h>
    1212#include <llvm/IR/Module.h>
     
    2222#include <kernels/mmap_kernel.h>
    2323#include <kernels/s2p_kernel.h>
    24 #include <kernels/pipeline.h>
    2524#include <pablo/pablo_compiler.h>
    2625#include <pablo/pablo_toolchain.h>
     
    137136void wcPipelineGen(ParabixDriver & pxDriver) {
    138137
    139     IDISA::IDISA_Builder * iBuilder = pxDriver.getIDISA_Builder();
     138    auto iBuilder = pxDriver.getIDISA_Builder();
    140139    Module * m = iBuilder->getModule();
    141140   
     
    189188
    190189WordCountFunctionType wcCodeGen() {
    191     Module * M = new Module("wc", getGlobalContext());
    192     IDISA::IDISA_Builder * idb = IDISA::GetIDISA_Builder(M);
    193     ParabixDriver pxDriver(idb);
    194    
     190    ParabixDriver pxDriver("wc");
    195191    wcPipelineGen(pxDriver);
    196 
    197     WordCountFunctionType main = reinterpret_cast<WordCountFunctionType>(pxDriver.getPointerToMain());
    198     delete idb;
    199     return main;
     192    return reinterpret_cast<WordCountFunctionType>(pxDriver.getPointerToMain());
    200193}
    201194
Note: See TracChangeset for help on using the changeset viewer.