Ignore:
Timestamp:
Mar 15, 2016, 10:20:07 PM (4 years ago)
Author:
nmedfort
Message:

Added the kernel instance class; removed original mmap file access in favour of the boost mmap system. corrected PrintRegister? routine.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r4970 r4974  
    6666namespace pablo {
    6767
     68#define DSSLI_FIELDWIDTH 64
     69
    6870PabloCompiler::PabloCompiler(Module * m, IDISA::IDISA_Builder * b)
    6971: mMod(m)
     
    8183}
    8284
    83 void PabloCompiler::setKernel(KernelBuilder * kBuilder){
     85void PabloCompiler::setKernel(kernel::KernelBuilder * kBuilder){
    8486    mKernelBuilder = kBuilder;
    8587}
     
    131133    mCarryManager->initialize(function, mKernelBuilder);
    132134
    133     mKernelBuilder->prepareFunction();
    134 
    135     mFunction = mKernelBuilder->getDoBlockFunction();
    136 
    137     for(unsigned i = 0; i < mKernelBuilder->getSegmentBlocks(); ++i){
    138 
    139         mCarryManager->reset();
    140 
    141         for (unsigned j = 0; j < function->getNumOfParameters(); ++j) {
    142             mMarkerMap.insert(std::make_pair(function->getParameter(j), mKernelBuilder->getInputStream(j)));
    143         }
    144 
    145         compileBlock(function->getEntryBlock());
    146 
    147         for (unsigned j = 0; j < function->getNumOfResults(); ++j) {
    148             const auto f = mMarkerMap.find(function->getResult(j));
    149             Value * result = nullptr;
    150             if (LLVM_UNLIKELY(f == mMarkerMap.end())) {
    151                 result = iBuilder->allZeroes();
    152             } else {
    153                 result = f->second;
    154             }
    155             iBuilder->CreateBlockAlignedStore(result, mKernelBuilder->getOutputStream(j));
    156         }
    157 
    158         mMarkerMap.clear();
    159 
    160         mKernelBuilder->increment();
    161     }   
     135    mFunction = mKernelBuilder->prepareFunction();
     136
     137    mCarryManager->reset();
     138
     139    for (unsigned j = 0; j < function->getNumOfParameters(); ++j) {
     140        mMarkerMap.insert(std::make_pair(function->getParameter(j), mKernelBuilder->getInputStream(j)));
     141    }
     142
     143    compileBlock(function->getEntryBlock());
     144
     145    for (unsigned j = 0; j < function->getNumOfResults(); ++j) {
     146        const auto f = mMarkerMap.find(function->getResult(j));
     147        Value * result = nullptr;
     148        if (LLVM_UNLIKELY(f == mMarkerMap.end())) {
     149            result = iBuilder->allZeroes();
     150        } else {
     151            result = f->second;
     152        }
     153        iBuilder->CreateBlockAlignedStore(result, mKernelBuilder->getOutputStream(j));
     154    }
    162155
    163156    mKernelBuilder->finalize();
     
    414407            throw std::runtime_error("Lookahead input type must be a Var object");
    415408        }
    416         Value * index = nullptr;
    417         for (unsigned i = 0; i < mPabloFunction->getNumOfParameters(); ++i) {
    418             if (mPabloFunction->getParameter(i) == var) {
    419                 index = iBuilder->getInt32(i);
     409        unsigned index = 0;
     410        for (; index < mPabloFunction->getNumOfParameters(); ++index) {
     411            if (mPabloFunction->getParameter(index) == var) {
    420412                break;
    421413            }
    422414        }
    423         if (LLVM_UNLIKELY(index == nullptr)) {
     415        if (LLVM_UNLIKELY(index >= mPabloFunction->getNumOfParameters())) {
    424416            throw std::runtime_error("Lookahead has an illegal Var operand");
    425417        }
    426         Type * const streamType = iBuilder->getIntNTy(iBuilder->getBitBlockWidth());
    427418        const unsigned offset = l->getAmount() / iBuilder->getBitBlockWidth();
    428419        const unsigned shift = (l->getAmount() % iBuilder->getBitBlockWidth());
    429         Value * const b0 = iBuilder->CreateBitCast(iBuilder->CreateBlockAlignedLoad(mKernelBuilder->getInputStream(offset), index), streamType);
    430         Value * const b1 = iBuilder->CreateBitCast(iBuilder->CreateBlockAlignedLoad(mKernelBuilder->getInputStream(offset + 1), index), streamType);
    431         Value * result = iBuilder->CreateOr(iBuilder->CreateLShr(b0, shift), iBuilder->CreateShl(b1, iBuilder->getBitBlockWidth() - shift), "lookahead");
    432         expr = iBuilder->CreateBitCast(result, iBuilder->getBitBlockType());
     420        Value * const v0 = iBuilder->CreateBlockAlignedLoad(mKernelBuilder->getInputStream(index, offset));
     421        Value * const v1 = iBuilder->CreateBlockAlignedLoad(mKernelBuilder->getInputStream(index, offset + 1));
     422        if (LLVM_UNLIKELY((shift % 8) == 0)) { // Use a single whole-byte shift, if possible.
     423            expr = iBuilder->mvmd_dslli(8, v1, v0, (shift / 8));
     424        } else if (LLVM_LIKELY(shift < DSSLI_FIELDWIDTH)) {
     425            Value * ahead = iBuilder->mvmd_dslli(DSSLI_FIELDWIDTH, v1, v0, 1);
     426            ahead = iBuilder->simd_slli(DSSLI_FIELDWIDTH, ahead, DSSLI_FIELDWIDTH - shift);
     427            Value * value = iBuilder->simd_srli(DSSLI_FIELDWIDTH, v0, shift);
     428            expr = iBuilder->simd_or(value, ahead);
     429        } else {
     430            Type  * const streamType = iBuilder->getIntNTy(iBuilder->getBitBlockWidth());
     431            Value * b0 = iBuilder->CreateBitCast(v0, streamType);
     432            Value * b1 = iBuilder->CreateBitCast(v1, streamType);
     433            Value * result = iBuilder->CreateOr(iBuilder->CreateShl(b1, iBuilder->getBitBlockWidth() - shift), iBuilder->CreateLShr(b0, shift));
     434            expr = iBuilder->CreateBitCast(result, mBitBlockType);
     435        }
    433436    } else {
    434437        std::string tmp;
     
    441444    mMarkerMap[stmt] = expr;
    442445    if (DumpTrace) {
    443         iBuilder->genPrintRegister(stmt->getName()->to_string(), expr);
     446        iBuilder->CallPrintRegister(stmt->getName()->to_string(), expr);
    444447    }
    445448   
Note: See TracChangeset for help on using the changeset viewer.