Changeset 4687 for icGREP/icgrep-devel


Ignore:
Timestamp:
Jul 22, 2015, 8:39:29 AM (4 years ago)
Author:
cameron
Message:

Carry Manager restructuring and bug fixes

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

Legend:

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

    r4682 r4687  
    2626}
    2727
    28 unsigned PabloBlockCarryData::enumerate(PabloBlock & blk) {
    29     for (Statement * stmt : blk) {
     28void PabloBlockCarryData::enumerateLocal() {
     29    for (Statement * stmt : *theScope) {
    3030        if (Advance * adv = dyn_cast<Advance>(stmt)) {
    3131            unsigned shift_amount = adv->getAdvanceAmount();
     
    7373    nested.frameOffsetinBits = advance1.frameOffsetinBits + advance1.entries * BLOCK_SIZE;
    7474#endif
    75     unsigned nestedframePosition = nested.frameOffsetinBits;
     75}
     76       
     77void PabloBlockCarryData::dumpCarryData(llvm::raw_ostream & strm) {
     78    unsigned totalDepth = ifDepth + whileDepth;
     79    for (int i = 0; i < totalDepth; i++) strm << "  ";
     80    strm << "scope index = " << theScope->getScopeIndex();
     81    strm << " framePosition: " << framePosition << ", ifDepth: " << ifDepth << ", whileDepth:" << whileDepth << ", maxNestingDepth: " << maxNestingDepth << "\n";
     82    for (int i = 0; i < totalDepth; i++) strm << "  ";
     83    strm << "longAdvance: offset = " << longAdvance.frameOffsetinBits << ", entries = " << longAdvance.entries << "\n";
     84    for (int i = 0; i < totalDepth; i++) strm << "  ";
     85    strm << "shortAdvance: offset = " << shortAdvance.frameOffsetinBits << ", entries = " << shortAdvance.entries << "\n";
     86    for (int i = 0; i < totalDepth; i++) strm << "  ";
     87    strm << "advance1: offset = " << advance1.frameOffsetinBits << ", entries = " << advance1.entries << "\n";
     88    for (int i = 0; i < totalDepth; i++) strm << "  ";
     89    strm << "addWithCarry: offset = " << addWithCarry.frameOffsetinBits << ", entries = " << addWithCarry.entries << "\n";
     90    for (int i = 0; i < totalDepth; i++) strm << "  ";
     91    strm << "nested: offset = " << nested.frameOffsetinBits << ", allocatedBits = " << nested.allocatedBits << "\n";
     92    for (int i = 0; i < totalDepth; i++) strm << "  ";
     93    strm << "summary: offset = " << summary.frameOffsetinBits << ", allocatedBits = " << summary.allocatedBits << "\n";
     94    for (int i = 0; i < totalDepth; i++) strm << "  ";
     95    strm << "scopeCarryDataBits = " << scopeCarryDataBits  << "\n";
     96    strm.flush();
    7697   
    77     for (Statement * stmt : blk) {
    78         if (If * ifStatement = dyn_cast<If>(stmt)) {
    79             PabloBlockCarryData & nestedBlockData = ifStatement->getBody().carryData;
    80             nestedBlockData.ifDepth = ifDepth + 1;
    81             nestedBlockData.whileDepth = whileDepth;
    82             const unsigned ifCarryDataBits = nestedBlockData.enumerate(ifStatement->getBody());
    83 #ifdef PACKING
    84             EnsurePackHasSpace(nestedframePosition, ifCarryDataBits);
    85 #endif
    86             nestedBlockData.framePosition = nestedframePosition;
    87             nestedframePosition += ifCarryDataBits;
    88             if (maxNestingDepth <= nestedBlockData.maxNestingDepth) maxNestingDepth = nestedBlockData.maxNestingDepth + 1;
    89             nested.entries++;
    90         }
    91         else if (While * whileStatement = dyn_cast<While>(stmt)) {
    92             PabloBlockCarryData & nestedBlockData = whileStatement->getBody().carryData;
    93             nestedBlockData.ifDepth = ifDepth;
    94             nestedBlockData.whileDepth = whileDepth + 1;
    95             unsigned whileCarryDataBits = nestedBlockData.enumerate(whileStatement->getBody());
    96             //if (whileStatement->isMultiCarry()) whileCarryDataBits *= whileStatement->getMaxIterations();
    97 #ifdef PACKING
    98             EnsurePackHasSpace(nestedframePosition, whileCarryDataBits);
    99 #endif
    100             nestedBlockData.framePosition = nestedframePosition;
    101             nestedframePosition += whileCarryDataBits;
    102             if (maxNestingDepth <= nestedBlockData.maxNestingDepth) maxNestingDepth = nestedBlockData.maxNestingDepth + 1;
    103             nested.entries++;
    104         }
    105     }
    106    
    107    
    108     scopeCarryDataBits = nestedframePosition;
    109    
    110     if (explicitSummaryRequired()) {
    111         // Need extra space for the summary variable, always the last
    112         // entry within an if block.
    113         scopeCarryDataBits = alignCeiling(scopeCarryDataBits, PACK_SIZE);
    114         summary.frameOffsetinBits = scopeCarryDataBits;
    115         summary.allocatedBits = PACK_SIZE;
    116         scopeCarryDataBits += PACK_SIZE;
    117     }
    118     else {
    119         summary.frameOffsetinBits = 0;
    120         summary.allocatedBits = scopeCarryDataBits;
    121     }
    122     return scopeCarryDataBits;
    12398}
    12499
  • icGREP/icgrep-devel/icgrep/pablo/carry_data.h

    r4682 r4687  
    99#include <include/simd-lib/bitblock.hpp>
    1010#include <stdexcept>
     11#include <iostream>
     12#include <ostream>
     13#include <llvm/Support/raw_os_ostream.h>
    1114/*
    1215 * Carry Data system.
     
    4851class PabloBlockCarryData {
    4952public:
    50     PabloBlockCarryData(): framePosition(0),
     53    PabloBlockCarryData(PabloBlock * b):
     54                           theScope(b), framePosition(0),
    5155                           ifDepth(0), whileDepth (0), maxNestingDepth(0),
    5256                           longAdvance({0, 0, 0}),
     
    5761                           summary({0, 0}),
    5862                           scopeCarryDataBits(0)
    59                            {}
     63    {enumerateLocal();}
    6064       
    61     unsigned enumerate(PabloBlock & p);
     65    friend class CarryManager;
     66   
     67    void enumerateLocal();
     68    void dumpCarryData(llvm::raw_ostream & strm);
    6269   
    6370    unsigned getBlockCarryDataIndex()  const {
    6471        return framePosition/BLOCK_SIZE;
     72    }
     73   
     74    void setFramePosition(unsigned p) {
     75        framePosition = p;
    6576    }
    6677   
     
    6980    }
    7081   
     82    void setIfDepth(unsigned d) {
     83        ifDepth = d;
     84    }
     85   
    7186    unsigned getWhileDepth()  const {
    7287        return whileDepth;
    7388    }
    7489       
     90    void setWhileDepth(unsigned d) {
     91        whileDepth = d;
     92    }
     93   
    7594    unsigned longAdvanceCarryDataOffset(unsigned advanceIndex)  const {
    7695        return fullOrPartialBlocks(longAdvance.frameOffsetinBits, BLOCK_SIZE) + advanceIndex;
     
    113132    bool explicitSummaryRequired() const { return (ifDepth > 0) && (scopeCarryDataBits > PACK_SIZE);}
    114133   
    115 private:
     134protected:
     135   
     136    PabloBlock * theScope;
    116137   
    117138    unsigned framePosition;
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.cpp

    r4684 r4687  
    77
    88#include <include/simd-lib/bitblock.hpp>
    9 #include <pablo/carry_data.h>
    10 #include <pablo/codegenstate.h>
    11 #include <pablo/carry_manager.h>
    12 #include <pablo/pabloAST.h>
    139#include <stdexcept>
    1410#include <pablo/carry_data.h>
     
    1915
    2016namespace pablo {
     17 
     18    unsigned doScopeCount(PabloBlock * pb) {
     19        unsigned count = 1;
     20       
     21        for (Statement * stmt : *pb) {
     22            if (If * ifStatement = dyn_cast<If>(stmt)) {
     23                count += doScopeCount(&ifStatement->getBody());
     24            }
     25            else if (While * whileStatement = dyn_cast<While>(stmt)) {
     26                count += doScopeCount(&whileStatement->getBody());
     27            }
     28        }
     29        return count;
     30       
     31    }
    2132
    2233unsigned CarryManager::initialize(PabloBlock * pb, Value * carryPtr) {
    23  
    2434    mPabloRoot = pb;
    2535    mCurrentScope = pb;
     
    2737   
    2838    mCarryDataPtr = carryPtr;
    29     mCarryInfo = &(pb->carryData);
    30     unsigned totalCarryDataBits = mCarryInfo->enumerate(*pb);
     39    unsigned scopeCount = doScopeCount(pb);
     40    mCarryInfoVector.resize(scopeCount);
     41   
     42    unsigned totalCarryDataBits = enumerate(pb, 0, 0, 0);
     43   
    3144    mTotalCarryDataBitBlocks = (totalCarryDataBits + BLOCK_SIZE - 1)/BLOCK_SIZE + 1; // One extra element for the block no.
    3245    mBlockNoPtr = mBuilder->CreateBitCast(mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(mTotalCarryDataBitBlocks - 1)), Type::getInt64PtrTy(mBuilder->getContext()));
     
    4861}
    4962
     63unsigned CarryManager::enumerate(PabloBlock * blk, unsigned ifDepth, unsigned whileDepth, unsigned nestedframePosition) {
     64    llvm::raw_os_ostream cerr(std::cerr);
     65    unsigned idx = blk->getScopeIndex();
     66    PabloBlockCarryData * cd = new PabloBlockCarryData(blk);
     67    mCarryInfoVector[idx] = cd;
     68
     69    cd->setIfDepth(ifDepth);
     70    cd->setWhileDepth(whileDepth);
     71    cd->setFramePosition(nestedframePosition);
     72    unsigned nestedOffset = cd->nested.frameOffsetinBits;
     73 
     74    for (Statement * stmt : *blk) {
     75        if (If * ifStatement = dyn_cast<If>(stmt)) {
     76            const unsigned ifCarryDataBits = enumerate(&ifStatement->getBody(), ifDepth+1, whileDepth, nestedOffset);
     77            PabloBlockCarryData * nestedBlockData = mCarryInfoVector[ifStatement->getBody().getScopeIndex()];
     78#ifdef PACKING
     79            EnsurePackHasSpace(nestedOffset, ifCarryDataBits);
     80#endif
     81            nestedOffset += ifCarryDataBits;
     82            if (cd->maxNestingDepth <= nestedBlockData->maxNestingDepth) cd->maxNestingDepth = nestedBlockData->maxNestingDepth + 1;
     83            cd->nested.entries++;
     84        }
     85        else if (While * whileStatement = dyn_cast<While>(stmt)) {
     86            const unsigned whileCarryDataBits = enumerate(&whileStatement->getBody(), ifDepth, whileDepth+1, nestedOffset);
     87            PabloBlockCarryData * nestedBlockData = mCarryInfoVector[whileStatement->getBody().getScopeIndex()];
     88            //if (whileStatement->isMultiCarry()) whileCarryDataBits *= whileStatement->getMaxIterations();
     89#ifdef PACKING
     90            EnsurePackHasSpace(nestedOffset, whileCarryDataBits);
     91#endif
     92            nestedOffset += whileCarryDataBits;
     93            if (cd->maxNestingDepth <= nestedBlockData->maxNestingDepth) cd->maxNestingDepth = nestedBlockData->maxNestingDepth + 1;
     94            cd->nested.entries++;
     95        }
     96    }
     97   
     98    cd->scopeCarryDataBits = nestedOffset;
     99   
     100    if (cd->explicitSummaryRequired()) {
     101        // Need extra space for the summary variable, always the last
     102        // entry within an if block.
     103        cd->scopeCarryDataBits = alignCeiling(cd->scopeCarryDataBits, PACK_SIZE);
     104        cd->summary.frameOffsetinBits = cd->scopeCarryDataBits;
     105        cd->summary.allocatedBits = PACK_SIZE;
     106        cd->scopeCarryDataBits += PACK_SIZE;
     107    }
     108    else {
     109        cd->summary.frameOffsetinBits = 0;
     110        cd->summary.allocatedBits = cd->scopeCarryDataBits;
     111    }
     112#ifndef NDEBUG
     113    cd->dumpCarryData(cerr);
     114#endif
     115    return cd->scopeCarryDataBits;
     116}
     117
     118
    50119/* Entering and leaving blocks. */
    51120
     
    53122   
    54123    mCurrentScope = blk;
    55     mCarryInfo = & (blk->carryData);
     124    mCarryInfo = mCarryInfoVector[blk->getScopeIndex()];
    56125    mCurrentScopeIndex += mCarryInfo->getBlockCarryDataIndex();
    57126    //std::cerr << "enterScope:  mCurrentScopeIndex = " << mCurrentScopeIndex << std::endl;
     
    61130    mCurrentScopeIndex -= mCarryInfo->getBlockCarryDataIndex();
    62131    mCurrentScope = mCurrentScope->getParent();
    63     mCarryInfo = & (mCurrentScope->carryData);
     132    mCarryInfo = mCarryInfoVector[mCurrentScope->getScopeIndex()];
    64133    //std::cerr << "leaveScope:  mCurrentScopeIndex = " << mCurrentScopeIndex << std::endl;
    65134}
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.h

    r4683 r4687  
    1111#include <IDISA/idisa_builder.h>
    1212#include <pablo/codegenstate.h>
     13#include <pablo/carry_data.h>
    1314
    1415/*
     
    2829
    2930class PabloBlock;
     31
     32
    3033
    3134class CarryManager {
     
    5154   
    5255    unsigned initialize(PabloBlock * blk, Value * carryDataPtr); 
     56   
     57    unsigned enumerate(PabloBlock * blk, unsigned ifDepth, unsigned whileDepth, unsigned nestedframePosition);
    5358   
    5459    void generateBlockNoIncrement();
     
    111116    Value * mBlockNo;
    112117    unsigned mTotalCarryDataBitBlocks;
     118   
     119    std::vector<PabloBlockCarryData *> mCarryInfoVector;
     120
    113121
    114122    std::vector<Value *> mCarryInVector;
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.cpp

    r4681 r4687  
    434434}
    435435
     436// Assign sequential scope indexes, returning the next unassigned index   
     437
     438unsigned PabloBlock::enumerateScopes(unsigned baseScopeIndex) {
     439    mScopeIndex = baseScopeIndex;
     440    unsigned nextScopeIndex = baseScopeIndex + 1;
     441    for (Statement * stmt : *this) {
     442        if (If * ifStatement = dyn_cast<If>(stmt)) {
     443            nextScopeIndex = ifStatement->getBody().enumerateScopes(nextScopeIndex);
     444        }
     445        else if (While * whileStatement = dyn_cast<While>(stmt)) {
     446            nextScopeIndex = whileStatement->getBody().enumerateScopes(nextScopeIndex);
     447        }
     448    }
     449    return nextScopeIndex;
     450}   
     451           
     452   
     453       
     454   
    436455/// CONSTRUCTOR
    437456
     
    442461, mSymbolGenerator(symbolGenerator)
    443462, mParent(nullptr)
     463, mScopeIndex(0)
    444464{
    445465
     
    451471, mOnes(predecessor->mOnes) // inherit the original "Ones" variable for simplicity
    452472, mSymbolGenerator(predecessor->mSymbolGenerator)
    453 , mParent(predecessor) {
     473, mParent(predecessor)
     474, mScopeIndex(0)
     475{
    454476
    455477}
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.h

    r4681 r4687  
    88#define PS_PABLOS_H
    99
    10 #include <pablo/carry_data.h>
    1110#include <pablo/pabloAST.h>
    1211#include <pablo/symbol_generator.h>
     
    160159    void insert(Statement * const statement);
    161160
    162     PabloBlockCarryData carryData;
     161    unsigned enumerateScopes(unsigned baseScopeIndex);
     162   
     163    inline unsigned getScopeIndex() const {
     164        return mScopeIndex;
     165    }
    163166   
    164167    virtual ~PabloBlock();
    165168
    166    
    167169protected:
    168170
     
    196198    SymbolGenerator &                                   mSymbolGenerator;
    197199    PabloBlock *                                        mParent;
     200    unsigned                                            mScopeIndex;
    198201};
    199202
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r4686 r4687  
    151151std::pair<llvm::Function *, size_t> PabloCompiler::compile(PabloFunction & function, Module * module) {
    152152
     153 
     154    function.getEntryBlock().enumerateScopes(0);
     155   
    153156    Examine(function);
    154157
Note: See TracChangeset for help on using the changeset viewer.