Ignore:
Timestamp:
Feb 10, 2017, 3:55:14 PM (2 years ago)
Author:
nmedfort
Message:

Removed BlockNo? + updated LookAhead? to use getInputStream.

File:
1 edited

Legend:

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

    r5310 r5311  
    474474
    475475        } else if (const Lookahead * l = dyn_cast<Lookahead>(stmt)) {
    476             PabloAST * const var = l->getExpr();
    477             if (LLVM_UNLIKELY(!isa<Var>(var))) {
    478                 throw std::runtime_error("Lookahead operations may only be applied to input streams");
    479             }
    480             unsigned index = 0;
    481             for (; index < mKernel->getNumOfInputs(); ++index) {
    482                 if (mKernel->getInput(index) == var) {
    483                     break;
     476            Var * var = nullptr;
     477            PabloAST * stream = l->getExpr();
     478            Value * index = iBuilder->getInt32(0);
     479
     480            if (LLVM_UNLIKELY(isa<Extract>(stream))) {
     481                stream = cast<Extract>(stream)->getArray();
     482                index = compileExpression(cast<Extract>(stream)->getIndex());
     483            }
     484            if (LLVM_LIKELY(isa<Var>(stream))) {
     485                var = cast<Var>(stream);
     486                if (!var->isKernelParameter() || var->isReadNone()) {
     487                    std::string tmp;
     488                    raw_string_ostream out(tmp);
     489                    out << "Lookahead operation cannot be applied to ";
     490                    stmt->print(out);
     491                    out << ": ";
     492                    var->print(out);
     493                    out << " is not an input stream";
     494                    report_fatal_error(out.str());
    484495                }
    485496            }
    486             if (LLVM_UNLIKELY(index >= mKernel->getNumOfInputs())) {
    487                 throw std::runtime_error("Lookahead has an illegal Var operand");
    488             }
    489             const unsigned bit_shift = (l->getAmount() % iBuilder->getBitBlockWidth());
    490             const unsigned block_shift = (l->getAmount() / iBuilder->getBitBlockWidth());
    491             std::string inputName = cast<Var>(var)->getName().str();
    492             Value * blockNo = mKernel->getBlockNo();
    493             Value * lookAhead_blockPtr  = mKernel->getInputStreamSetPtr(inputName, iBuilder->CreateAdd(blockNo, iBuilder->getSize(block_shift)));
    494             Value * lookAhead_inputPtr = iBuilder->CreateGEP(lookAhead_blockPtr, {iBuilder->getInt32(0), iBuilder->getInt32(index)});
    495             Value * lookAhead = iBuilder->CreateBlockAlignedLoad(lookAhead_inputPtr);
     497
     498            const auto bit_shift = (l->getAmount() % iBuilder->getBitBlockWidth());
     499            const auto block_shift = (l->getAmount() / iBuilder->getBitBlockWidth());
     500
     501            Value * ptr = mKernel->getInputStream(iBuilder->getSize(block_shift), var->getName(), index);
     502            Value * lookAhead = iBuilder->CreateBlockAlignedLoad(ptr);
    496503            if (bit_shift == 0) {  // Simple case with no intra-block shifting.
    497504                value = lookAhead;
    498505            } else { // Need to form shift result from two adjacent blocks.
    499                 Value * lookAhead_blockPtr1  = mKernel->getInputStreamSetPtr(inputName, iBuilder->CreateAdd(blockNo, iBuilder->getSize(block_shift + 1)));
    500                 Value * lookAhead_inputPtr1 = iBuilder->CreateGEP(lookAhead_blockPtr1, {iBuilder->getInt32(0), iBuilder->getInt32(index)});
    501                 Value * lookAhead1 = iBuilder->CreateBlockAlignedLoad(lookAhead_inputPtr1);
     506                Value * ptr = mKernel->getInputStream(iBuilder->getSize(block_shift + 1), var->getName(), index);
     507                Value * lookAhead1 = iBuilder->CreateBlockAlignedLoad(ptr);
    502508                if (LLVM_UNLIKELY((bit_shift % 8) == 0)) { // Use a single whole-byte shift, if possible.
    503509                    value = iBuilder->mvmd_dslli(8, lookAhead1, lookAhead, (bit_shift / 8));
Note: See TracChangeset for help on using the changeset viewer.