Ignore:
Timestamp:
Apr 3, 2016, 4:31:22 PM (3 years ago)
Author:
nmedfort
Message:

Redesigned buffer system to allow the pipeline to control selection of the current input and output streams; DoBlock? functions containing lookahead now take multiple input stream arguments. Selection and passing occurs automatically. Some work on Symbol Table.

Location:
icGREP/icgrep-devel/icgrep/pablo
Files:
2 edited

Legend:

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

    r4995 r5000  
    8484    #endif
    8585 
    86     Examine(*function);
     86    Examine(function);
    8787
    8888    mCarryManager = new CarryManager(iBuilder);
     
    114114    mCarryManager->initialize(function, mKernelBuilder);
    115115
    116     mFunction = mKernelBuilder->prepareFunction();
     116    mFunction = mKernelBuilder->prepareFunction({mInputStreamOffset.begin(), mInputStreamOffset.end()});
    117117
    118118    mCarryManager->reset();
     
    120120    for (unsigned j = 0; j < function->getNumOfParameters(); ++j) {
    121121        Value * inputVal = mKernelBuilder->getInputStream(j);
     122        const Var * const var = function->getParameter(j);
    122123        if (DumpTrace) {
    123             iBuilder->CallPrintRegister("param" + std::to_string(j + 1), iBuilder->CreateBlockAlignedLoad(inputVal));
    124         }
    125         mMarkerMap.insert(std::make_pair(function->getParameter(j), inputVal));
     124            iBuilder->CallPrintRegister(var->getName()->to_string(), iBuilder->CreateBlockAlignedLoad(inputVal));
     125        }
     126        mMarkerMap.insert(std::make_pair(var, inputVal));
    126127    }
    127128
     
    139140}
    140141
    141 inline void PabloCompiler::Examine(PabloFunction & function) {
     142inline void PabloCompiler::Examine(const PabloFunction * const function) {
    142143    mWhileDepth = 0;
    143144    mIfDepth = 0;
    144145    mMaxWhileDepth = 0;
    145     Examine(function.getEntryBlock());
    146 }
    147 
    148 void PabloCompiler::Examine(PabloBlock * block) {
    149     for (Statement * stmt : *block) {
    150         if (LLVM_UNLIKELY(isa<If>(stmt))) {
    151             Examine(cast<If>(stmt)->getBody());
    152         } else if (LLVM_UNLIKELY(isa<While>(stmt))) {
    153             mMaxWhileDepth = std::max(mMaxWhileDepth, ++mWhileDepth);
    154             Examine(cast<While>(stmt)->getBody());
    155             --mWhileDepth;
    156         }
     146    LookaheadOffsetMap offsetMap;
     147    Examine(function->getEntryBlock(), offsetMap);
     148    mInputStreamOffset.clear();
     149    for (const auto & oi : offsetMap) {
     150        for (const auto offset : oi.second) {
     151            mInputStreamOffset.insert(offset / iBuilder->getBitBlockWidth());
     152        }
     153    }
     154}
     155
     156void PabloCompiler::Examine(const PabloBlock * const block, LookaheadOffsetMap & offsetMap) {
     157    for (const Statement * stmt : *block) {
     158         boost::container::flat_set<unsigned> offsets;
     159        if (LLVM_UNLIKELY(isa<Lookahead>(stmt))) {
     160            const Lookahead * const la = cast<Lookahead>(stmt);
     161            assert (isa<Var>(la->getExpr()));
     162            offsets.insert(la->getAmount());
     163            offsets.insert(la->getAmount() + iBuilder->getBitBlockWidth() - 1);
     164        } else {
     165            for (unsigned i = 0; i < stmt->getNumOperands(); ++i) {
     166                const PabloAST * expr = stmt->getOperand(i);
     167                if (isa<Var>(expr)) {
     168                    offsets.insert(0);
     169                } else if (LLVM_LIKELY(isa<Statement>(expr) && !isa<Assign>(expr) && !isa<Next>(expr))) {
     170                    const auto f = offsetMap.find(expr);
     171                    assert (f != offsetMap.end());
     172                    const auto & o = f->second;
     173                    offsets.insert(o.begin(), o.end());
     174                }
     175            }
     176            if (LLVM_UNLIKELY(isa<If>(stmt))) {
     177                Examine(cast<If>(stmt)->getBody(), offsetMap);
     178            } else if (LLVM_UNLIKELY(isa<While>(stmt))) {
     179                mMaxWhileDepth = std::max(mMaxWhileDepth, ++mWhileDepth);
     180                Examine(cast<While>(stmt)->getBody(), offsetMap);
     181                --mWhileDepth;
     182            }
     183        }
     184        offsetMap.emplace(stmt, offsets);
    157185    }
    158186}
     
    384412            throw std::runtime_error("Lookahead has an illegal Var operand");
    385413        }
    386         const unsigned offset = l->getAmount() / iBuilder->getBitBlockWidth();
     414        const unsigned offset0 = (l->getAmount() / iBuilder->getBitBlockWidth());
     415        const unsigned offset1 = ((l->getAmount() + iBuilder->getBitBlockWidth() - 1) / iBuilder->getBitBlockWidth());
    387416        const unsigned shift = (l->getAmount() % iBuilder->getBitBlockWidth());
    388         Value * const v0 = iBuilder->CreateBlockAlignedLoad(mKernelBuilder->getInputStream(index, offset));
    389         Value * const v1 = iBuilder->CreateBlockAlignedLoad(mKernelBuilder->getInputStream(index, offset + 1));
     417        Value * const v0 = iBuilder->CreateBlockAlignedLoad(mKernelBuilder->getInputStream(index, offset0));
     418        Value * const v1 = iBuilder->CreateBlockAlignedLoad(mKernelBuilder->getInputStream(index, offset1));
    390419        if (LLVM_UNLIKELY((shift % 8) == 0)) { // Use a single whole-byte shift, if possible.
    391420            expr = iBuilder->mvmd_dslli(8, v1, v0, (shift / 8));
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.h

    r4974 r5000  
    1717#include <IDISA/idisa_builder.h>
    1818#include <kernels/kernel.h>
     19#include <boost/container/flat_set.hpp>
    1920
    2021namespace llvm {
     
    2425    class VectorType;
    2526    class PointerType;
    26     class ConstantAggregateZero;
    2727    class Constant;
    2828    class FunctionType;
     
    4444
    4545class PabloCompiler {
    46 
     46    using IntSet = boost::container::flat_set<unsigned>;
    4747    using MarkerMap = std::unordered_map<const PabloAST *, Value *>;
    48 
     48    using LookaheadOffsetMap = std::unordered_map<const PabloAST *, IntSet>;
    4949public:
    5050    PabloCompiler(Module * m, IDISA::IDISA_Builder * b);
     
    5555private:
    5656
    57     void Examine(PabloFunction & function);
    58     void Examine(PabloBlock * block);
     57    void Examine(const PabloFunction * const function);
     58    void Examine(const PabloBlock * const block, LookaheadOffsetMap & offsetMap);
    5959
    6060    void compileBlock(const PabloBlock * const block);
     
    6666
    6767    MarkerMap                           mMarkerMap;
    68 
     68    IntSet                              mInputStreamOffset;
    6969    Module *                            mMod;
    7070    IDISA::IDISA_Builder *              iBuilder;
Note: See TracChangeset for help on using the changeset viewer.