Ignore:
Timestamp:
Feb 22, 2017, 4:23:51 PM (2 years ago)
Author:
nmedfort
Message:

Added a simple CreateAssert? function in CBuilder and ReadOnly? flag for getStreamSetBufferPtr method to prevent expanding input stream sets. Begun work on CarryManager? to preallocate variable-length carry data slots.

Location:
icGREP/icgrep-devel/icgrep
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/IR_Gen/CBuilder.cpp

    r5337 r5340  
    99#include <llvm/IR/Constants.h>
    1010#include <llvm/IR/Intrinsics.h>
    11 //#include <llvm/IR/Function.h>
    1211#include <llvm/IR/TypeBuilder.h>
    13 #include <fcntl.h>  // for
     12#include <fcntl.h>
    1413
    1514using namespace llvm;
     
    364363}
    365364
     365void CBuilder::CreateAssert(llvm::Value * const toCheck, llvm::StringRef failureMessage) {
     366    #ifndef NDEBUG
     367    Module * m = getModule();
     368    Function * assertion = m->getFunction("__assert");
     369    if (LLVM_UNLIKELY(assertion == nullptr)) {
     370        auto ip = saveIP();
     371        assertion = cast<Function>(m->getOrInsertFunction("__assert", getVoidTy(), getInt1Ty(), getInt8PtrTy(), getSizeTy(), nullptr));
     372        BasicBlock * entry = BasicBlock::Create(getContext(), "", assertion);
     373        BasicBlock * failure = BasicBlock::Create(getContext(), "", assertion);
     374        BasicBlock * success = BasicBlock::Create(getContext(), "", assertion);
     375        auto arg = assertion->arg_begin();
     376        arg->setName("e");
     377        Value * e = &*arg++;
     378        arg->setName("msg");
     379        Value * msg = &*arg++;
     380        arg->setName("sz");
     381        Value * sz = &*arg;
     382        SetInsertPoint(entry);
     383        CreateCondBr(e, failure, success);
     384        SetInsertPoint(failure);
     385        CreateWriteCall(getInt32(2), msg, sz);
     386        Function * exit = m->getFunction("exit");
     387        if (LLVM_UNLIKELY(exit == nullptr)) {
     388            exit = cast<Function>(m->getOrInsertFunction("exit", getVoidTy(), getInt32Ty(), nullptr));
     389            exit->setDoesNotReturn();
     390            exit->setDoesNotThrow();
     391        }
     392        CreateCall(exit, getInt32(-1));
     393        CreateBr(success); // we're forced to have this to satisfy the LLVM verifier. this is not actually executed.
     394        SetInsertPoint(success);
     395        CreateRetVoid();
     396        restoreIP(ip);
     397    }
     398    CreateCall(assertion, {CreateICmpEQ(toCheck, Constant::getNullValue(toCheck->getType())), CreateGlobalStringPtr(failureMessage), getSize(failureMessage.size())});
     399    #endif
     400}
     401
    366402CBuilder::CBuilder(llvm::Module * m, unsigned GeneralRegisterWidthInBits, unsigned CacheLineAlignmentInBytes)
    367403: IRBuilder<>(m->getContext())
  • icGREP/icgrep-devel/icgrep/IR_Gen/CBuilder.h

    r5337 r5340  
    3333   
    3434    llvm::Value * CreateMalloc(llvm::Type * type, llvm::Value * size);
    35    
     35
    3636    llvm::Value * CreateAlignedMalloc(llvm::Type * type, llvm::Value * size, const unsigned alignment);
    3737   
     
    109109    virtual llvm::StoreInst *  CreateAtomicStoreRelease(llvm::Value * val, llvm::Value * ptr);
    110110   
     111    // Warning! this class must be compiled in debug mode or the check will be ignored.
     112    void CreateAssert(llvm::Value * toCheck, llvm::StringRef failureMessage);
     113
    111114protected:
    112115    llvm::Module *      mMod;
  • icGREP/icgrep-devel/icgrep/kernels/alignedprint.cpp

    r5337 r5340  
    268268: BlockOrientedKernel(builder, "PrintableStreamSet", {}, {}, {}, {}, {})
    269269, mNames(names)
    270 , mNameWidth() {
     270, mNameWidth(0) {
    271271    auto width = minWidth;
    272272    for (const std::string & name : mNames) {
  • icGREP/icgrep-devel/icgrep/kernels/kernel.cpp

    r5337 r5340  
    307307    Value * const blockIndex = computeBlockIndex(mStreamSetInputs, name, getProcessedItemCount(name));
    308308    const StreamSetBuffer * const buf = getInputStreamSetBuffer(name);
    309     return buf->getStreamBlockPtr(getStreamSetBufferPtr(name), streamIndex, blockIndex);
     309    return buf->getStreamBlockPtr(getStreamSetBufferPtr(name), streamIndex, blockIndex, true);
    310310}
    311311
     
    317317    Value * const blockIndex = computeBlockIndex(mStreamSetInputs, name, getProcessedItemCount(name));
    318318    const StreamSetBuffer * const buf = getInputStreamSetBuffer(name);
    319     return buf->getStreamPackPtr(getStreamSetBufferPtr(name), streamIndex, blockIndex, packIndex);
     319    return buf->getStreamPackPtr(getStreamSetBufferPtr(name), streamIndex, blockIndex, packIndex, true);
    320320}
    321321
     
    332332    blockIndex = iBuilder->CreateAdd(blockIndex, blockAdjustment);
    333333    const StreamSetBuffer * const buf = getInputStreamSetBuffer(name);
    334     return buf->getStreamBlockPtr(getStreamSetBufferPtr(name), streamIndex, blockIndex);
     334    return buf->getStreamBlockPtr(getStreamSetBufferPtr(name), streamIndex, blockIndex, true);
    335335}
    336336
     
    338338    Value * const blockIndex = computeBlockIndex(mStreamSetOutputs, name, getProducedItemCount(name));
    339339    const StreamSetBuffer * const buf = getOutputStreamSetBuffer(name);
    340     return buf->getStreamBlockPtr(getStreamSetBufferPtr(name), streamIndex, blockIndex);
     340    return buf->getStreamBlockPtr(getStreamSetBufferPtr(name), streamIndex, blockIndex, false);
    341341}
    342342
     
    348348    Value * const blockIndex = computeBlockIndex(mStreamSetOutputs, name, getProducedItemCount(name));
    349349    const StreamSetBuffer * const buf = getOutputStreamSetBuffer(name);
    350     return buf->getStreamPackPtr(getStreamSetBufferPtr(name), streamIndex, blockIndex, packIndex);
     350    return buf->getStreamPackPtr(getStreamSetBufferPtr(name), streamIndex, blockIndex, packIndex, false);
    351351}
    352352
     
    448448    CreateDoBlockMethodCall();
    449449}
    450 
    451 //Value * BlockOrientedKernel::loadBlock(const std::string & inputName, Value * const streamIndex) const {
    452 
    453 //}
    454 
    455 //Value * BlockOrientedKernel::loadPack(const std::string & inputName, Value * const streamIndex, Value * const packIndex) const {
    456 
    457 //}
    458 
    459450
    460451//  The default doSegment method dispatches to the doBlock routine for
  • icGREP/icgrep-devel/icgrep/kernels/streamset.cpp

    r5337 r5340  
    1313#include <llvm/IR/Value.h>         // for Value
    1414#include <llvm/Support/raw_ostream.h>
     15#include <llvm/IR/CFG.h>
    1516
    1617namespace llvm { class Constant; }
     
    2930}
    3031
    31 Value * StreamSetBuffer::getStreamBlockPtr(Value * self, Value * streamIndex, Value * blockIndex) const {
     32Value * StreamSetBuffer::getStreamBlockPtr(Value * self, Value * streamIndex, Value * blockIndex, const bool /* readOnly */) const {
    3233    return iBuilder->CreateGEP(getStreamSetBlockPtr(self, blockIndex), {iBuilder->getInt32(0), streamIndex});
    3334}
    3435
    35 Value * StreamSetBuffer::getStreamPackPtr(Value * self, Value * streamIndex, Value * blockIndex, Value * packIndex) const {
     36Value * StreamSetBuffer::getStreamPackPtr(Value * self, Value * streamIndex, Value * blockIndex, Value * packIndex, const bool /* readOnly */) const {
    3637    return iBuilder->CreateGEP(getStreamSetBlockPtr(self, blockIndex), {iBuilder->getInt32(0), streamIndex, packIndex});
    3738}
     
    199200}
    200201
    201 std::pair<Value *, Value *> ExpandableBuffer::getExpandedStreamOffset(llvm::Value * self, llvm::Value * streamIndex, Value * blockIndex) const {
     202bool dominates(const Instruction * const x, const Instruction * const y) {
     203    // Are they in the same basic block?
     204    if (x->getParent() == y->getParent()) {
     205        if (y->getNextNode() == nullptr) {
     206            return true;
     207        }
     208        for (const Instruction * z = x; z; z = z->getNextNode()) {
     209            if (z == y) {
     210                return true;
     211            }
     212        }
     213        return false;
     214    } else {
     215        const BasicBlock * yp = y->getParent();
     216        for (auto pi = pred_begin(yp), pi_end = pred_end(yp); pi != pi_end; ++pi) {
     217            if (!dominates(x, (*pi)->getTerminator())) {
     218                return false;
     219            }
     220        }
     221        return true;
     222    }
     223}
     224
     225inline bool ExpandableBuffer::isGuaranteedCapacity(const llvm::Value * const index) const {
     226    if (LLVM_UNLIKELY(isa<ConstantInt>(index))) {
     227        if (LLVM_LIKELY(cast<ConstantInt>(index)->getLimitedValue() < mInitialCapacity)) {
     228            return true;
     229        }
     230    }
     231    return false;
     232}
     233
     234std::pair<Value *, Value *> ExpandableBuffer::getInternalStreamBuffer(llvm::Value * self, llvm::Value * streamIndex, Value * blockIndex, const bool readOnly) const {
    202235
    203236    // MDNode *Weights = MDBuilder(Ctx).createBranchWeights(42, 13);
    204 
    205     /// TODO: Check whether a dominating test with the same streamIndex exists or whether streamIndex is guaranteed to be < capacity
    206237
    207238    // ENTRY
     
    212243
    213244    // Are we guaranteed that we can access this stream?
    214     if (LLVM_UNLIKELY(isa<ConstantInt>(streamIndex))) {
    215         if (LLVM_LIKELY(cast<ConstantInt>(streamIndex)->getLimitedValue() < mInitialCapacity)) {
    216             return {streamSet, capacity};
    217         }
     245    if (isGuaranteedCapacity(streamIndex)) {
     246        return {streamSet, capacity};
     247    } else if (readOnly) {
     248        iBuilder->CreateAssert(iBuilder->CreateICmpULT(streamIndex, capacity), "ExpandableBuffer: out-of-bounds readonly stream access!");
     249        return {streamSet, capacity};
    218250    }
    219251
     
    267299}
    268300
    269 llvm::Value * ExpandableBuffer::getStreamBlockPtr(llvm::Value * self, Value * streamIndex, Value * blockIndex) const {
     301llvm::Value * ExpandableBuffer::getStreamBlockPtr(llvm::Value * self, Value * streamIndex, Value * blockIndex, const bool readOnly) const {
    270302    Value * ptr, * offset;
    271     std::tie(ptr, offset) = getExpandedStreamOffset(self, streamIndex, blockIndex);
     303    std::tie(ptr, offset) = getInternalStreamBuffer(self, streamIndex, blockIndex, readOnly);
    272304    return iBuilder->CreateGEP(ptr, offset);
    273305}
    274306
    275 llvm::Value * ExpandableBuffer::getStreamPackPtr(llvm::Value * self, llvm::Value * streamIndex, Value * blockIndex, Value * packIndex) const {
     307llvm::Value * ExpandableBuffer::getStreamPackPtr(llvm::Value * self, llvm::Value * streamIndex, Value * blockIndex, Value * packIndex, const bool readOnly) const {
    276308    Value * ptr, * offset;
    277     std::tie(ptr, offset) = getExpandedStreamOffset(self, streamIndex, blockIndex);
     309    std::tie(ptr, offset) = getInternalStreamBuffer(self, streamIndex, blockIndex, readOnly);
    278310    return iBuilder->CreateGEP(ptr, {offset, packIndex});
    279311}
  • icGREP/icgrep-devel/icgrep/kernels/streamset.h

    r5329 r5340  
    4747    virtual void allocateBuffer();
    4848
    49     virtual llvm::Value * getStreamBlockPtr(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex) const;
     49    virtual llvm::Value * getStreamBlockPtr(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex, const bool readOnly) const;
    5050
    51     virtual llvm::Value * getStreamPackPtr(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex, llvm::Value * packIndex) const;
     51    virtual llvm::Value * getStreamPackPtr(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex, llvm::Value * packIndex, const bool readOnly) const;
    5252   
    5353    virtual llvm::Value * getStreamSetCount(llvm::Value * self) const;
     
    159159    ExpandableBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, unsigned AddressSpace = 0);
    160160
    161     llvm::Value * getStreamBlockPtr(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex) const override;
     161    llvm::Value * getStreamBlockPtr(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex, const bool readOnly) const override;
    162162
    163     llvm::Value * getStreamPackPtr(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex, llvm::Value * packIndex) const override;
     163    llvm::Value * getStreamPackPtr(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex, llvm::Value * packIndex, const bool readOnly) const override;
    164164
    165165    llvm::Value * getLinearlyAccessibleItems(llvm::Value * fromPosition) const override;
     
    175175private:
    176176
    177     std::pair<llvm::Value *, llvm::Value *> getExpandedStreamOffset(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex) const;
     177    bool isGuaranteedCapacity(const llvm::Value * const index) const;
     178
     179    std::pair<llvm::Value *, llvm::Value *> getInternalStreamBuffer(llvm::Value * self, llvm::Value * streamIndex, llvm::Value * blockIndex, const bool readOnly) const;
    178180
    179181private:
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.cpp

    r5337 r5340  
    7070    mCurrentScope = kernel->getEntryBlock();
    7171
    72     mCarryMetadata.resize(enumerate(kernel->getEntryBlock()));
     72    mCarryScopes = 0;
     73
     74    mCarryMetadata.resize(getScopeCount(kernel->getEntryBlock()));
    7375
    7476    mKernel->addScalar(analyse(kernel->getEntryBlock()), "carries");
     
    8385
    8486/** ------------------------------------------------------------------------------------------------------------- *
     87 * @brief allocateCarryData
     88 ** ------------------------------------------------------------------------------------------------------------- */
     89void CarryManager::allocateCarryData(PabloKernel * const kernel) {
     90//    mKernel = kernel;
     91//    mCarryScopes = 0;
     92//    mCarryScopeIndex.push_back(0);
     93//    mCurrentFrame = kernel->getScalarFieldPtr("carries");
     94//    allocateCarryData (mCurrentFrame->getType());
     95}
     96
     97///** ------------------------------------------------------------------------------------------------------------- *
     98// * @brief allocateCarryData
     99// ** ------------------------------------------------------------------------------------------------------------- */
     100//void CarryManager::allocateCarryData(Type * const type) {
     101//    assert (type->isStructTy());
     102
     103//    const auto scopeIndex = mCarryScopes++;
     104
     105//    const unsigned vl = mCarryMetadata[scopeIndex].variableLength ? 4 : 0;
     106
     107//    if (LLVM_UNLIKELY(vl != 0)) {
     108
     109
     110//        ConstantInt * const capacity = iBuilder->getSize(vl);
     111//        Value * capacityPtr = iBuilder->CreateGEP(mCurrentFrame, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
     112//        iBuilder->CreateStore(capacity, capacityPtr, false);
     113//        Value * arrayPtr = iBuilder->CreateGEP(mCurrentFrame, {iBuilder->getInt32(0), iBuilder->getInt32(1)});
     114//        Value * carryStateType = arrayPtr->getType()->getPointerElementType();
     115//        Value * array = iBuilder->CreateAlignedMalloc(carryStateType, capacity, iBuilder->getCacheAlignment());
     116//        Constant * typeWidth = ConstantExpr::getIntegerCast(ConstantExpr::getSizeOf(carryStateType), iBuilder->getSizeTy(), false);
     117//        iBuilder->CreateMemZero(array, iBuilder->CreateMul(capacity, typeWidth), iBuilder->getCacheAlignment());
     118//        iBuilder->CreateStore(array, arrayPtr, false);
     119
     120
     121
     122
     123//    } else {
     124
     125
     126//        for (unsigned i = 0; i < type->getStructNumElements(); ++i) {
     127
     128
     129
     130//        }
     131
     132
     133
     134//    }
     135
     136
     137
     138
     139
     140
     141//}
     142
     143
     144/** ------------------------------------------------------------------------------------------------------------- *
    85145 * @brief initializeCodeGen
    86146 ** ------------------------------------------------------------------------------------------------------------- */
    87147void CarryManager::initializeCodeGen() {
    88     // TODO: need to look into abstracting the Initialize creation function in KernelBuilder::generateKernel
    89     // so that we can allocate the variable length buffers if needed.
    90148
    91149    assert(!mCarryMetadata.empty());
     
    95153    mCurrentFrame = mKernel->getScalarFieldPtr("carries");
    96154    mCurrentFrameIndex = 0;
    97 
     155    mCarryScopes = 0;
     156    mCarryScopeIndex.push_back(0);
    98157    assert (mCarryFrame.empty());
    99158    assert (mCarrySummary.empty());
     
    116175        mKernel->setScalarField("CarryBlockIndex", idx);
    117176    }
     177    assert (mCarryFrame.empty());
     178    assert (mCarrySummary.empty());
     179    assert (mCarryScopeIndex.size() == 1);
     180    mCarryScopeIndex.clear();
    118181}
    119182
     
    154217        Value * array = iBuilder->CreateLoad(arrayPtr, false, "array");
    155218
     219        BasicBlock * entry = iBuilder->GetInsertBlock();
    156220        BasicBlock * resizeBlock = mKernel->CreateBasicBlock("");
    157221        BasicBlock * cleanUpBlock = mKernel->CreateBasicBlock("");
     
    193257        iBuilder->SetInsertPoint(codeBlock);
    194258
    195         mCurrentFrame = iBuilder->CreateGEP(iBuilder->CreateLoad(arrayPtr), index);
     259        PHINode * phiArray = iBuilder->CreatePHI(array->getType(), 2);
     260        phiArray->addIncoming(array, entry);
     261        phiArray->addIncoming(newArray, zeroBlock);
     262
     263        mCurrentFrame = iBuilder->CreateGEP(phiArray, index);
    196264
    197265    }
     
    321389    mCarryFrame.emplace_back(mCurrentFrame, mCurrentFrameIndex + 1);
    322390    mCurrentScope = scope;
    323     mCarryInfo = &mCarryMetadata[scope->getScopeIndex()];
     391    mCarryScopeIndex.push_back(++mCarryScopes);
     392    mCarryInfo = &mCarryMetadata[mCarryScopes];
    324393    // Check whether we're still within our struct bounds; if this fails, either the Pablo program changed within
    325394    // compilation or a memory corruption has occured.
     
    347416
    348417    mCarryFrame.pop_back();
    349 
     418    mCarryScopeIndex.pop_back();
     419    assert (!mCarryScopeIndex.empty());
    350420    mCurrentScope = mCurrentScope->getPredecessor();
    351421    assert (mCurrentScope);
    352     mCarryInfo = &mCarryMetadata[mCurrentScope->getScopeIndex()];   
     422    mCarryInfo = &mCarryMetadata[mCarryScopeIndex.back()];
    353423}
    354424
     
    528598 * @brief enumerate
    529599 ** ------------------------------------------------------------------------------------------------------------- */
    530 unsigned CarryManager::enumerate(PabloBlock * const scope, unsigned index) {
    531     scope->setScopeIndex(index++);
     600unsigned CarryManager::getScopeCount(PabloBlock * const scope, unsigned index) {
    532601    for (Statement * stmt : *scope) {
    533602        if (LLVM_UNLIKELY(isa<Branch>(stmt))) {
    534             index = enumerate(cast<Branch>(stmt)->getBody(), index);
    535         }
    536     }
    537     return index;
     603            index = getScopeCount(cast<Branch>(stmt)->getBody(), index);
     604        }
     605    }
     606    return index + 1;
    538607}
    539608
     
    577646
    578647    Type * const carryPackType = (loopDepth == 0) ? mCarryPackType : ArrayType::get(mCarryPackType, 2);
     648
     649    const auto scopeIndex = mCarryScopes++;
     650
     651    assert (scopeIndex < mCarryMetadata.size());
    579652
    580653    bool hasLongAdvances = false;
     
    605678    }
    606679
    607     assert (scope->getScopeIndex() < mCarryMetadata.size());
    608 
    609     CarryData & cd = mCarryMetadata[scope->getScopeIndex()];
     680    CarryData & cd = mCarryMetadata[scopeIndex];
    610681
    611682    StructType * carryState = nullptr;
     
    638709        }
    639710    }
     711
    640712    return carryState;
    641713}
     
    660732, mHasLoop(false)
    661733, mLoopDepth(0)
    662 , mLoopSelector(nullptr) {
    663 
    664 }
    665 
    666 }
    667 
     734, mLoopSelector(nullptr)
     735, mCarryScopes(0) {
     736
     737}
     738
     739}
     740
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.h

    r5311 r5340  
    4242public:
    4343 
    44     explicit CarryManager(IDISA::IDISA_Builder * idb) noexcept;
     44    CarryManager(IDISA::IDISA_Builder * idb) noexcept;
    4545
    4646    void initializeCarryData(PabloKernel * const kernel);
     47
     48    void allocateCarryData(PabloKernel * const kernels);
    4749
    4850    void initializeCodeGen();
     
    8284protected:
    8385
    84     static unsigned enumerate(PabloBlock * const scope, unsigned index = 0);
     86    static unsigned getScopeCount(PabloBlock * const scope, unsigned index = 0);
    8587    static bool requiresVariableLengthMode(const PabloBlock * const scope);
    8688    llvm::StructType * analyse(PabloBlock * const scope, const unsigned ifDepth = 0, const unsigned whileDepth = 0);
     
    127129
    128130    std::vector<CarryData>                          mCarryMetadata;
     131
    129132    std::vector<std::pair<llvm::Value *, unsigned>> mCarryFrame;
     133
     134    unsigned                                        mCarryScopes;
     135    std::vector<unsigned>                           mCarryScopeIndex;
    130136
    131137    std::vector<llvm::Value *>                      mCarrySummary;
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.h

    r5329 r5340  
    287287    void insert(Statement * const statement);
    288288
    289     inline void setScopeIndex(const unsigned index) {
    290         mScopeIndex = index;
    291     }
    292 
    293     inline unsigned getScopeIndex() const {
    294         return mScopeIndex;
    295     }
    296    
    297289    void eraseFromParent(const bool recursively = false);
    298290
     
    319311protected:
    320312
    321     explicit PabloBlock(PabloKernel * const parent, Allocator & allocator) noexcept
     313    PabloBlock(PabloKernel * const parent, Allocator & allocator) noexcept
    322314    : PabloAST(PabloAST::ClassTypeId::Block, nullptr, allocator)
    323315    , mParent(parent)
    324316    , mBranch(nullptr)
    325     , mScopeIndex(0)
    326317    , mAllocator(allocator) {
    327318
     
    341332    PabloKernel * const         mParent;
    342333    Branch *                    mBranch;
    343     unsigned                    mScopeIndex;
    344334    Allocator &                 mAllocator;
    345335};
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r5329 r5340  
    4444}
    4545
    46 void PabloCompiler::initializeKernelData() {
    47     Examine();
    48     mCarryManager->initializeCarryData(mKernel);
    49 }
    50    
    5146void PabloCompiler::compile() {
    5247
     
    6358}
    6459
    65 inline void PabloCompiler::Examine() {
    66     Examine(mKernel->getEntryBlock());
    67 }
    68 
    69 void PabloCompiler::Examine(const PabloBlock * const block) {
     60void PabloCompiler::initializeKernelData() {
     61    examineBlock(mKernel->getEntryBlock());
     62    mCarryManager->initializeCarryData(mKernel);
     63}
     64
     65void PabloCompiler::allocateKernelData() {
     66    mCarryManager->allocateCarryData(mKernel);
     67}
     68
     69void PabloCompiler::examineBlock(const PabloBlock * const block) {
    7070    for (const Statement * stmt : *block) {
    7171        if (LLVM_UNLIKELY(isa<Lookahead>(stmt))) {
     
    7676            }
    7777        } else if (LLVM_UNLIKELY(isa<Branch>(stmt))) {
    78             Examine(cast<Branch>(stmt)->getBody());
     78            examineBlock(cast<Branch>(stmt)->getBody());
    7979        } else if (LLVM_UNLIKELY(isa<Count>(stmt))) {
    8080            mAccumulator.insert(std::make_pair(stmt, iBuilder->getInt32(mKernel->addUnnamedScalar(stmt->getType()))));
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.h

    r5310 r5340  
    2323
    2424class PabloCompiler {
    25 //    friend class CarryManager;
     25
     26    friend class PabloKernel;
    2627
    2728    using TranslationMap = std::unordered_map<const PabloAST *, llvm::Value *>;
    2829
    2930public:
     31
    3032    PabloCompiler(PabloKernel * kernel);
     33
    3134    ~PabloCompiler();
     35
     36protected:
     37
    3238    void initializeKernelData();
     39
     40    void allocateKernelData();
     41
    3342    void compile();
    3443
    3544private:
    3645
    37     void Examine();
    38 
    39     void Examine(const PabloBlock * const block);
     46    void examineBlock(const PabloBlock * const block);
    4047
    4148    void compileBlock(const PabloBlock * const block);
  • icGREP/icgrep-devel/icgrep/pablo/pablo_kernel.cpp

    r5319 r5340  
    116116}
    117117
     118void PabloKernel::generateInitMethod() {
     119    mPabloCompiler->allocateKernelData();
     120}
     121
    118122void PabloKernel::generateDoBlockMethod() {
    119123    mPabloCompiler->compile();
  • icGREP/icgrep-devel/icgrep/pablo/pablo_kernel.h

    r5310 r5340  
    131131    void prepareKernel()  override final;
    132132
     133    void generateInitMethod() override final;
     134
    133135    void generateDoBlockMethod() override final;
    134136
Note: See TracChangeset for help on using the changeset viewer.