Changeset 4654


Ignore:
Timestamp:
Jul 10, 2015, 9:10:06 AM (4 years ago)
Author:
cameron
Message:

Move logic for advance operations entirely within carry manager.

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

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/CMakeLists.txt

    r4644 r4654  
    6060endif()
    6161
    62 SET(PABLO_SRC pablo/pabloAST.cpp pablo/ps_assign.cpp pablo/ps_if.cpp pablo/ps_while.cpp pablo/codegenstate.cpp pablo/builder.cpp pablo/symbol_generator.cpp pablo/printer_pablos.cpp pablo/pablo_compiler.cpp pablo/optimizers/pablo_simplifier.cpp pablo/optimizers/pablo_codesinking.cpp pablo/carry_data.cpp pablo/carry_manager.cpp)
     62SET(PABLO_SRC pablo/pabloAST.cpp pablo/ps_assign.cpp pablo/ps_if.cpp pablo/ps_while.cpp pablo/codegenstate.cpp pablo/builder.cpp pablo/symbol_generator.cpp pablo/printer_pablos.cpp pablo/pablo_compiler.cpp pablo/optimizers/pablo_simplifier.cpp pablo/optimizers/pablo_codesinking.cpp pablo/carry_data.cpp pablo/carry_manager.cpp IDISA/idisa_builder.cpp)
    6363IF (ENABLE_MULTIPLEXING)
    6464SET(PABLO_SRC ${PABLO_SRC} pablo/optimizers/pablo_automultiplexing.cpp)
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.cpp

    r4647 r4654  
    2121    mPabloRoot = pb;
    2222    mCarryDataPtr = carryPtr;
     23    iBuilder = new IDISA::IDISA_Builder(mMod, mBuilder, mBitBlockType);
    2324   
    2425    PabloBlockCarryData & cd = pb->carryData;
     
    5455}
    5556
    56 Value * CarryManager::getUnitAdvanceCarryIn(PabloBlock * blk, int localIndex) {
    57     PabloBlockCarryData & cd = blk->carryData;
    58     if (cd.getWhileDepth() == 0) {
    59        Value * packPtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(cd.unitAdvanceCarryDataOffset(localIndex)));
    60        mCarryInVector[cd.unitAdvanceCarryDataOffset(localIndex)] = mBuilder->CreateAlignedLoad(packPtr, BLOCK_SIZE/8);
    61     }
    62     return mCarryInVector[cd.unitAdvanceCarryDataOffset(localIndex)];
    63 }
    64 
    65 Value * CarryManager::getShortAdvanceCarryIn(PabloBlock * blk, int localIndex, int shift_amount) {
    66     PabloBlockCarryData & cd = blk->carryData;
    67     if (cd.getWhileDepth() == 0) {
    68        Value * packPtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(cd.shortAdvanceCarryDataOffset(localIndex)));
    69        mCarryInVector[cd.shortAdvanceCarryDataOffset(localIndex)] = mBuilder->CreateAlignedLoad(packPtr, BLOCK_SIZE/8);
    70     }
    71     return mCarryInVector[cd.shortAdvanceCarryDataOffset(localIndex)];
    72 }
    73 
    7457void CarryManager::setCarryOpCarryOut(PabloBlock * blk, unsigned idx, Value * carry_out) {
    7558    PabloBlockCarryData & cd = blk->carryData;
     
    8164}
    8265
    83 void CarryManager::setUnitAdvanceCarryOut(PabloBlock * blk, unsigned idx, Value * carry_out) {
    84     PabloBlockCarryData & cd = blk->carryData;
    85     mCarryOutVector[cd.unitAdvanceCarryDataOffset(idx)] = carry_out;
     66   
     67Value * CarryManager::advanceCarryInCarryOut(PabloBlock * blk, int localIndex, int shift_amount, Value * strm) {
     68    if (shift_amount == 1) {
     69        return unitAdvanceCarryInCarryOut(blk, localIndex, strm);
     70    }
     71    else if (shift_amount < LongAdvanceBase) {
     72        return shortAdvanceCarryInCarryOut(blk, localIndex, shift_amount, strm);
     73    }
     74    else {
     75        return longAdvanceCarryInCarryOut(blk, localIndex, shift_amount, strm);
     76    }
     77}
     78
     79Value * CarryManager::unitAdvanceCarryInCarryOut(PabloBlock * blk, int localIndex, Value * strm) {
     80    PabloBlockCarryData & cd = blk->carryData;
     81    unsigned carryDataIndex = cd.unitAdvanceCarryDataOffset(localIndex);
     82    mCarryOutVector[carryDataIndex] = strm;
    8683    if (cd.getWhileDepth() == 0) {
    87        Value * packPtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(cd.unitAdvanceCarryDataOffset(idx)));
    88        mBuilder->CreateAlignedStore(carry_out, packPtr, BLOCK_SIZE/8);
    89     }
    90 }
    91 
    92 void CarryManager::setShortAdvanceCarryOut(PabloBlock * blk, unsigned idx, int shift_amount, Value * carry_out) {
    93     PabloBlockCarryData & cd = blk->carryData;
    94     mCarryOutVector[cd.shortAdvanceCarryDataOffset(idx)] = carry_out;
     84        Value * packPtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(carryDataIndex));
     85        mCarryInVector[carryDataIndex] = mBuilder->CreateAlignedLoad(packPtr, BLOCK_SIZE/8);
     86        mBuilder->CreateAlignedStore(strm, packPtr, BLOCK_SIZE/8);
     87       
     88    }
     89    Value * carry_in = mCarryInVector[carryDataIndex];
     90    Value* result_value;
     91   
     92#if (BLOCK_SIZE == 128) && !defined(USE_LONG_INTEGER_SHIFT)
     93    Value* advanceq_longint = mBuilder->CreateBitCast(carry_in, mBuilder->getIntNTy(BLOCK_SIZE));
     94    Value* advanceq_value = mBuilder->CreateBitCast(mBuilder->CreateLShr(advanceq_longint, BLOCK_SIZE - 1), mBitBlockType);
     95    Value* srli_1_value = mBuilder->CreateLShr(strm, 63);
     96    Value* packed_shuffle;
     97    Constant* const_packed_1_elems [] = {mBuilder->getInt32(0), mBuilder->getInt32(2)};
     98    Constant* const_packed_1 = ConstantVector::get(const_packed_1_elems);
     99    packed_shuffle = mBuilder->CreateShuffleVector(advanceq_value, srli_1_value, const_packed_1);
     100   
     101    Constant* const_packed_2_elems[] = {mBuilder->getInt64(1), mBuilder->getInt64(1)};
     102    Constant* const_packed_2 = ConstantVector::get(const_packed_2_elems);
     103   
     104    Value* shl_value = mBuilder->CreateShl(strm, const_packed_2);
     105    result_value = mBuilder->CreateOr(shl_value, packed_shuffle, "advance");
     106#else
     107    Value* advanceq_longint = mBuilder->CreateBitCast(carry_in, mBuilder->getIntNTy(BLOCK_SIZE));
     108    Value* strm_longint = mBuilder->CreateBitCast(strm, mBuilder->getIntNTy(BLOCK_SIZE));
     109    Value* adv_longint = mBuilder->CreateOr(mBuilder->CreateShl(strm_longint, 1), mBuilder->CreateLShr(advanceq_longint, BLOCK_SIZE - 1), "advance");
     110    result_value = mBuilder->CreateBitCast(adv_longint, mBitBlockType);
     111   
     112#endif
     113    return result_value;
     114}
     115
     116Value * CarryManager::shortAdvanceCarryInCarryOut(PabloBlock * blk, int localIndex, int shift_amount, Value * strm) {
     117    PabloBlockCarryData & cd = blk->carryData;
     118    unsigned carryDataIndex = cd.shortAdvanceCarryDataOffset(localIndex);
     119    mCarryOutVector[carryDataIndex] = strm;
    95120    if (cd.getWhileDepth() == 0) {
    96        Value * packPtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(cd.shortAdvanceCarryDataOffset(idx)));
    97        mBuilder->CreateAlignedStore(carry_out, packPtr, BLOCK_SIZE/8);
    98     }
    99 }
    100    
    101 /*
     121        Value * packPtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(carryDataIndex));
     122        mCarryInVector[carryDataIndex] = mBuilder->CreateAlignedLoad(packPtr, BLOCK_SIZE/8);
     123        mBuilder->CreateAlignedStore(strm, packPtr, BLOCK_SIZE/8);
     124       
     125    }
     126    Value * carry_in = mCarryInVector[carryDataIndex];
     127    Value* advanceq_longint = mBuilder->CreateBitCast(carry_in, mBuilder->getIntNTy(BLOCK_SIZE));
     128    Value* strm_longint = mBuilder->CreateBitCast(strm, mBuilder->getIntNTy(BLOCK_SIZE));
     129    Value* adv_longint = mBuilder->CreateOr(mBuilder->CreateShl(strm_longint, shift_amount), mBuilder->CreateLShr(advanceq_longint, BLOCK_SIZE - shift_amount), "advance");
     130    return mBuilder->CreateBitCast(adv_longint, mBitBlockType);
     131}
     132   
     133
     134/*  currently defined in carry_data.h
     135 
    102136 static unsigned power2ceil (unsigned v) {
    103137 unsigned ceil = 1;
     
    115149 */
    116150
     151   
    117152Value * CarryManager::longAdvanceCarryInCarryOut(PabloBlock * blk, int localIndex, int shift_amount, Value * carry_out) {
    118153    PabloBlockCarryData & cd = blk->carryData;
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.h

    r4647 r4654  
    88#define CARRY_MANAGER_H
    99#include <llvm/IR/IRBuilder.h>
     10#include <llvm/IR/Module.h>
     11#include <IDISA/idisa_builder.h>
    1012
    1113/*
     
    2931public:
    3032 
    31     CarryManager(IRBuilder <> * b, VectorType * bitBlockType, ConstantAggregateZero * zero, Constant * one) :
    32         mBuilder(b), mBitBlockType(bitBlockType), mZeroInitializer(zero), mOneInitializer(one) {}
     33    CarryManager(Module * m, IRBuilder <> * b, VectorType * bitBlockType, ConstantAggregateZero * zero, Constant * one) :
     34        mMod(m), mBuilder(b), mBitBlockType(bitBlockType), mZeroInitializer(zero), mOneInitializer(one) {}
    3335   
    3436    unsigned initialize(PabloBlock * blk, Value * carryDataPtr); 
     
    3840    Value * getBlockNoPtr();
    3941   
    40     /* Methods for getting and setting individual carry values. */
     42    /* Methods for processing individual carry-generating operations. */
    4143   
    4244    Value * getCarryOpCarryIn(PabloBlock * blk, int localIndex);
    4345
    44     Value * getUnitAdvanceCarryIn(PabloBlock * blk, int localIndex);
    45 
    46     Value * getShortAdvanceCarryIn(PabloBlock * blk, int localIndex, int shift_amount);
    47      
    4846    void setCarryOpCarryOut(PabloBlock * blk, unsigned idx, Value * carry_out);
    4947
    50     void setUnitAdvanceCarryOut(PabloBlock * blk, unsigned idx, Value * carry_out);
    51 
    52     void setShortAdvanceCarryOut(PabloBlock * blk, unsigned idx, int shift_amount, Value * carry_out);
    53    
    54     Value * longAdvanceCarryInCarryOut(PabloBlock * blk, int localIndex, int shift_amount, Value * carry_out);
     48    Value * advanceCarryInCarryOut(PabloBlock * blk, int localIndex, int shift_amount, Value * strm);
    5549 
    5650    /* Methods for getting and setting carry summary values for If statements */
     
    8478   
    8579private:
    86   IRBuilder <> * mBuilder;
    87   VectorType * mBitBlockType;
    88   ConstantAggregateZero * mZeroInitializer;
    89   Constant * mOneInitializer;
    90   PabloBlock * mPabloRoot;
    91   Value * mCarryDataPtr;
    92   Value * mBlockNoPtr;
    93   Value * mBlockNo;
    94   unsigned mTotalCarryDataSize;
    95  
    96   std::vector<Value *> mCarryInVector;
    97   std::vector<PHINode *> mCarryInPhis; 
    98   std::vector<PHINode *> mCarryOutAccumPhis; 
    99   std::vector<Value *> mCarryOutVector;
     80    Module * mMod;
     81    IRBuilder <> * mBuilder;
     82    VectorType * mBitBlockType;
     83    ConstantAggregateZero * mZeroInitializer;
     84    Constant * mOneInitializer;
     85    IDISA::IDISA_Builder * iBuilder;
     86    PabloBlock * mPabloRoot;
     87    Value * mCarryDataPtr;
     88    Value * mBlockNoPtr;
     89    Value * mBlockNo;
     90    unsigned mTotalCarryDataSize;
     91
     92    std::vector<Value *> mCarryInVector;
     93    std::vector<PHINode *> mCarryInPhis; 
     94    std::vector<PHINode *> mCarryOutAccumPhis; 
     95    std::vector<Value *> mCarryOutVector;
     96
     97    Value * unitAdvanceCarryInCarryOut(PabloBlock * blk, int localIndex, Value * strm);
     98    Value * shortAdvanceCarryInCarryOut(PabloBlock * blk, int localIndex, int shift_amount, Value * strm);
     99    Value * longAdvanceCarryInCarryOut(PabloBlock * blk, int localIndex, int shift_amount, Value * strm);
     100   
    100101};
    101102
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r4647 r4654  
    121121    mIfDepth = 0;
    122122    mMaxWhileDepth = 0;
    123     mCarryManager = new CarryManager(mBuilder, mBitBlockType, mZeroInitializer, mOneInitializer);
     123    mCarryManager = new CarryManager(mMod, mBuilder, mBitBlockType, mZeroInitializer, mOneInitializer);
    124124   
    125125    std::string errMessage;
     
    607607        int shift = adv->getAdvanceAmount();
    608608        unsigned advance_index = adv->getLocalAdvanceIndex();
    609         if (shift == 1) {
    610             expr = genUnitAdvanceWithCarry(strm_value, advance_index);
    611         }
    612         else if (shift < LongAdvanceBase) {
    613             expr = genShortAdvanceWithCarry(strm_value, advance_index, shift);
    614         }
    615         else {
    616             expr = genLongAdvanceWithCarry(strm_value, advance_index, shift);
    617         }
     609        expr = mCarryManager->advanceCarryInCarryOut(mPabloBlock, advance_index, shift, strm_value);
    618610    }
    619611    else if (const MatchStar * mstar = dyn_cast<MatchStar>(stmt)) {
     
    797789}
    798790
    799 Value* PabloCompiler::genUnitAdvanceWithCarry(Value* strm_value, unsigned localIndex) {
    800     Value * carry_in = mCarryManager->getUnitAdvanceCarryIn(mPabloBlock, localIndex);
    801     Value* result_value;
    802    
    803 #if (BLOCK_SIZE == 128) && !defined(USE_LONG_INTEGER_SHIFT)
    804     Value* advanceq_value = genShiftHighbitToLow(BLOCK_SIZE, carry_in);
    805     Value* srli_1_value = mBuilder->CreateLShr(strm_value, 63);
    806     Value* packed_shuffle;
    807     Constant* const_packed_1_elems [] = {mBuilder->getInt32(0), mBuilder->getInt32(2)};
    808     Constant* const_packed_1 = ConstantVector::get(const_packed_1_elems);
    809     packed_shuffle = mBuilder->CreateShuffleVector(advanceq_value, srli_1_value, const_packed_1);
    810    
    811     Constant* const_packed_2_elems[] = {mBuilder->getInt64(1), mBuilder->getInt64(1)};
    812     Constant* const_packed_2 = ConstantVector::get(const_packed_2_elems);
    813    
    814     Value* shl_value = mBuilder->CreateShl(strm_value, const_packed_2);
    815     result_value = mBuilder->CreateOr(shl_value, packed_shuffle, "advance");
    816 #else
    817     Value* advanceq_longint = mBuilder->CreateBitCast(carry_in, mBuilder->getIntNTy(BLOCK_SIZE));
    818     Value* strm_longint = mBuilder->CreateBitCast(strm_value, mBuilder->getIntNTy(BLOCK_SIZE));
    819     Value* adv_longint = mBuilder->CreateOr(mBuilder->CreateShl(strm_longint, 1), mBuilder->CreateLShr(advanceq_longint, BLOCK_SIZE - 1), "advance");
    820     result_value = mBuilder->CreateBitCast(adv_longint, mBitBlockType);
    821    
    822 #endif
    823     mCarryManager->setUnitAdvanceCarryOut(mPabloBlock, localIndex, strm_value);
    824     return result_value;
    825 }
    826                    
    827 Value* PabloCompiler::genShortAdvanceWithCarry(Value* strm_value, unsigned localIndex, int shift_amount) {
    828     Value * carry_in = mCarryManager->getShortAdvanceCarryIn(mPabloBlock, localIndex, shift_amount);
    829     Value* advanceq_longint = mBuilder->CreateBitCast(carry_in, mBuilder->getIntNTy(BLOCK_SIZE));
    830     Value* strm_longint = mBuilder->CreateBitCast(strm_value, mBuilder->getIntNTy(BLOCK_SIZE));
    831     Value* adv_longint = mBuilder->CreateOr(mBuilder->CreateShl(strm_longint, shift_amount), mBuilder->CreateLShr(advanceq_longint, BLOCK_SIZE - shift_amount), "advance");
    832     Value* result_value = mBuilder->CreateBitCast(adv_longint, mBitBlockType);
    833     mCarryManager->setShortAdvanceCarryOut(mPabloBlock, localIndex, shift_amount, strm_value);
    834     return result_value;
    835 }
    836                    
    837 Value* PabloCompiler::genLongAdvanceWithCarry(Value* strm_value, unsigned localIndex, int shift_amount) {
    838     return mCarryManager->longAdvanceCarryInCarryOut(mPabloBlock, localIndex, shift_amount, strm_value);
    839 }
    840791   
    841792void PabloCompiler::SetOutputValue(Value * marker, const unsigned index) {
Note: See TracChangeset for help on using the changeset viewer.