Changeset 4258


Ignore:
Timestamp:
Oct 22, 2014, 10:38:57 AM (5 years ago)
Author:
nmedfort
Message:

Couple changes in preperation for using phi nodes for test/accum variables.

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

Legend:

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

    r4257 r4258  
    2727}
    2828
    29 Var * PabloBlock::createVar(String * name) {
    30     return mUnary.findOrMake<Var>(PabloAST::ClassTypeId::Var, name);
     29Var * PabloBlock::createVar(String * name, const bool internal) {
     30    // Note: this is a unary function; internal is a hidden property passed into the constructor
     31    // when instantiating a new variable.
     32    return mUnary.findOrMake<Var>(PabloAST::ClassTypeId::Var, name, internal);
    3133}
    3234
  • icGREP/icgrep-devel/icgrep/pablo/codegenstate.h

    r4255 r4258  
    4040
    4141    PabloBlock(SymbolGenerator & symgen)
    42     : mSymbolGenerator(symgen)
    43     , mZeroes(new Zeroes())
     42    : mZeroes(new Zeroes())
    4443    , mOnes(new Ones())
     44    , mSymbolGenerator(symgen)
    4545    , mUnary(nullptr, this)
    4646    , mBinary(nullptr, this)
     
    5151
    5252    PabloBlock(PabloBlock & cg)
    53     : mSymbolGenerator(cg.mSymbolGenerator)
    54     , mZeroes(cg.mZeroes) // inherit the original "Zeroes" variable for simplicity
     53    : mZeroes(cg.mZeroes) // inherit the original "Zeroes" variable for simplicity
    5554    , mOnes(cg.mOnes) // inherit the original "Ones" variable for simplicity
     55    , mSymbolGenerator(cg.mSymbolGenerator)
    5656    , mUnary(&(cg.mUnary), this)
    5757    , mBinary(&(cg.mBinary), this)
     
    7474
    7575    inline Assign * createAssign(const std::string prefix, PabloAST * expr) {
     76        // TODO: should this test whether we've somehow created a var for this prior to
     77        // making the assignment?
    7678        Assign * assign = new Assign(mSymbolGenerator.get_ssa(prefix), expr);
    7779        mStatements.push_back(assign);
     
    7981    }
    8082
    81     Var * createVar(String * name);
    82 
    8383    inline Var * createVar(const std::string name) {
    84         return createVar(mSymbolGenerator.get(name));
     84        return createVar(mSymbolGenerator.get(name), false);
    8585    }
    8686
    8787    inline Var * createVar(Assign * assign) {
    88         return createVar(assign->mName);
     88        return createVar(assign->mName, true);
    8989    }
    9090
    9191    inline Var * createVar(Next * next) {
    92         return createVar(next->mInitial->mName);
     92        return createVar(next->mInitial->mName, true);
    9393    }
    9494
     
    134134    template<typename... Args>
    135135    struct ExpressionMap {
     136        enum {N = sizeof...(Args)};
    136137        typedef ExpressionMap<Args...> MapType;
    137138        typedef std::tuple<PabloAST::ClassTypeId, Args...> Key;
     
    144145        }
    145146
    146         template <class Type>
    147         inline Type * findOrMake(const PabloAST::ClassTypeId type, Args... args) {
     147        template <class Type, typename... Params>
     148        inline Type * findOrMake(const PabloAST::ClassTypeId type, Args... args, Params... params) {
    148149            Key key = std::make_tuple(type, args...);
    149             PabloAST * f = find(key);
     150            PabloAST * const f = find(key);
    150151            if (f) {
    151152                return cast<Type>(f);
    152153            }
    153             Type * expr = new Type(args...);
     154            Type * const expr = new Type(std::forward<Args>(args)..., std::forward<Params>(params)...);
    154155            insert(std::move(key), expr);
    155156            return expr;
    156157        }
    157158
    158         template <class Functor>
    159         inline PabloAST * findOrCall(const PabloAST::ClassTypeId type, Args... args) {
     159
     160        template <class Functor, typename... Params>
     161        inline PabloAST * findOrCall(const PabloAST::ClassTypeId type, Args... args, Params... params) {
    160162            Key key = std::make_tuple(type, args...);
    161             PabloAST * f = find(key);
     163            PabloAST * const f = find(key);
    162164            if (f) {
    163165                return f;
    164166            }
    165167            Functor mf(mCodeGenState);
    166             PabloAST * expr = mf(args...);
     168            PabloAST * const expr = mf(std::forward<Args>(args)..., std::forward<Params>(params)...);
    167169            insert(std::move(key), expr);
    168170            return expr;
     
    202204    }
    203205
    204 private:   
     206protected:
     207
     208    Var * createVar(String * name, const bool internal);
     209
     210private:       
     211    Zeroes * const                                      mZeroes;
     212    Ones * const                                        mOnes;
    205213    SymbolGenerator &                                   mSymbolGenerator;
    206     Zeroes *                                            mZeroes;
    207     Ones *                                              mOnes;
    208214    ExpressionMap<PabloAST *>                           mUnary;
    209215    ExpressionMap<PabloAST *, PabloAST *>               mBinary;
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r4257 r4258  
    516516    if (const Assign * assign = dyn_cast<const Assign>(stmt))
    517517    {
    518         Value * expr = compileExpression(assign->getExpr());
    519         Value * marker = GetMarker(assign->getName());
     518        Value* expr = compileExpression(assign->getExpr());
     519        Value* marker = GetMarker(assign->getName());
    520520        IRBuilder<> b(mBasicBlock);
    521521        b.CreateAlignedStore(expr, marker, BLOCK_SIZE/8, false);
     
    535535    {
    536536        BasicBlock * ifEntryBlock = mBasicBlock;
    537         BasicBlock * ifBodyBlock = BasicBlock::Create(mMod->getContext(), "if.body",mFunc_process_block, 0);
    538         BasicBlock * ifEndBlock = BasicBlock::Create(mMod->getContext(), "if.end",mFunc_process_block, 0);
     537        BasicBlock * ifBodyBlock = BasicBlock::Create(mMod->getContext(), "if.body", mFunc_process_block, 0);
     538        BasicBlock * ifEndBlock = BasicBlock::Create(mMod->getContext(), "if.end", mFunc_process_block, 0);
    539539
    540540        int if_start_idx = mCarryQueueIdx;
     
    545545           final carry index.  */
    546546
    547         IRBuilder<> b_ifbody(ifBodyBlock);
     547        IRBuilder<> bIfBody(ifBodyBlock);
    548548        mBasicBlock = ifBodyBlock;
    549549
     
    562562            {
    563563                Value* carryq_value = genCarryInLoad(c);
    564                 if_carry_accum_value = b_ifbody.CreateOr(carryq_value, if_carry_accum_value);
     564                if_carry_accum_value = bIfBody.CreateOr(carryq_value, if_carry_accum_value);
    565565            }
    566566            genCarryOutStore(if_carry_accum_value, if_accum_idx);
    567567
    568568        }
    569         b_ifbody.CreateBr(ifEndBlock);
     569        bIfBody.CreateBr(ifEndBlock);
    570570
    571571        IRBuilder<> b_entry(ifEntryBlock);
     
    584584        retVal = returnMarker;
    585585    }
    586     else if (const While* whl = dyn_cast<const While>(stmt))
    587     {
    588         BasicBlock* entryBlock = mBasicBlock;
    589 
     586    else if (const While * whl = dyn_cast<const While>(stmt))
     587    {
    590588        const auto baseCarryQueueIdx = mCarryQueueIdx;
    591589        if (mNestingDepth == 0) {
     
    596594
    597595        // First compile the initial iteration statements; the calls to genCarryOutStore will update the
    598         // mCarryQueueVector with the appropriate values.
     596        // mCarryQueueVector with the appropriate values. Although we're not actually entering a new basic
     597        // block yet, increment the nesting depth so that any calls to genCarryInLoad or genCarryOutStore
     598        // will refer to the previous value.
    599599        ++mNestingDepth;
    600         Value * returnMarker = compileStatements(whl->getBody());
    601 
     600        compileStatements(whl->getBody());
     601        // Reset the carry queue index. Note: this ought to be changed in the future. Currently this assumes
     602        // that compiling the while body twice will generate the equivalent IR. This is not necessarily true
     603        // but works for now.
    602604        mCarryQueueIdx = baseCarryQueueIdx;
    603605
     
    606608        BasicBlock* whileEndBlock = BasicBlock::Create(mMod->getContext(), "while.end", mFunc_process_block, 0);
    607609
    608         IRBuilder<> b(mBasicBlock);
    609         b.CreateBr(whileCondBlock);
     610        // Note: compileStatements may update the mBasicBlock pointer if the body contains nested loops. Do not
     611        // assume it is the same one in which we entered the function with.
     612        IRBuilder<> bEntry(mBasicBlock);
     613        bEntry.CreateBr(whileCondBlock);
    610614
    611615        // CONDITION BLOCK
     
    616620            PHINode * phi = bCond.CreatePHI(mXi64Vect, 2);
    617621            phi->addIncoming(mCarryQueueVector[baseCarryQueueIdx + i], mBasicBlock);
    618             mCarryQueueVector[baseCarryQueueIdx + i] = mZeroInitializer; // phi;
     622            mCarryQueueVector[baseCarryQueueIdx + i] = mZeroInitializer; // phi; // (use phi for multi-carry mode.)
    619623            carryQueuePhiNodes[i] = phi;
    620624        }
     
    625629        // BODY BLOCK
    626630        mBasicBlock = whileBodyBlock;
    627         returnMarker = compileStatements(whl->getBody());
     631        retVal = compileStatements(whl->getBody());
    628632        // update phi nodes for any carry propogating instruction
    629633        IRBuilder<> bWhileBody(mBasicBlock);
     
    643647            }
    644648        }
    645         retVal = returnMarker;
    646649    }
    647650    return retVal;
     
    783786}
    784787
    785 Value* PabloCompiler::genCarryInLoad(const unsigned index) {
    786     IRBuilder<> b(mBasicBlock);
     788Value* PabloCompiler::genCarryInLoad(const unsigned index) {   
     789    assert (index < mCarryQueueVector.size());
    787790    if (mNestingDepth == 0) {
    788         LoadInst * carryIn = b.CreateAlignedLoad(b.CreateGEP(mCarryQueuePtr, b.getInt64(index)), BLOCK_SIZE/8, false);
    789         mCarryQueueVector[index] = carryIn;
    790         return carryIn;
    791     }
    792     else { // we're in a potentially-nested while/if block
    793         assert (index < mCarryQueueVector.size());
    794         return mCarryQueueVector[index];
    795     }
     791        IRBuilder<> b(mBasicBlock);
     792        mCarryQueueVector[index] = b.CreateAlignedLoad(b.CreateGEP(mCarryQueuePtr, b.getInt64(index)), BLOCK_SIZE/8, false);
     793    }
     794    return mCarryQueueVector[index];
    796795}
    797796
    798797void PabloCompiler::genCarryOutStore(Value* carryOut, const unsigned index ) {
    799     IRBuilder<> b(mBasicBlock);
    800798    assert (carryOut);
    801799    assert (index < mCarryQueueVector.size());
    802     if (mNestingDepth == 0) {
     800    if (mNestingDepth == 0) {       
     801        IRBuilder<> b(mBasicBlock);
    803802        b.CreateAlignedStore(carryOut, b.CreateGEP(mCarryQueuePtr, b.getInt64(index)), BLOCK_SIZE/8, false);
    804803    }
     
    806805}
    807806
    808 inline Value* PabloCompiler::genBitBlockAny(Value* e) {
     807inline Value* PabloCompiler::genBitBlockAny(Value* test) {
    809808    IRBuilder<> b(mBasicBlock);
    810     Value* cast_marker_value_1 = b.CreateBitCast(e, IntegerType::get(mMod->getContext(), BLOCK_SIZE));
     809    Value* cast_marker_value_1 = b.CreateBitCast(test, IntegerType::get(mMod->getContext(), BLOCK_SIZE));
    811810    return b.CreateICmpEQ(cast_marker_value_1, ConstantInt::get(IntegerType::get(mMod->getContext(), BLOCK_SIZE), 0));
    812811}
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.h

    r4257 r4258  
    109109    Value* genAddWithCarry(Value* e1, Value* e2);
    110110    Value* genAdvanceWithCarry(Value* e1);
    111     Value* genBitBlockAny(Value* e);
     111    Value* genBitBlockAny(Value* test);
    112112    Value* genShiftHighbitToLow(Value* e, const Twine & namehint = "");
    113113    Value* genShiftLeft64(Value* e, const Twine & namehint = "") ;
  • icGREP/icgrep-devel/icgrep/pablo/pe_var.h

    r4257 r4258  
    2828        return mName;
    2929    }
     30    inline bool isInternal() const {
     31        return mInternal;
     32    }
     33    inline bool isExternal() const {
     34        return !mInternal;
     35    }
    3036protected:
    31     Var(const PabloAST * var)
     37    Var(const PabloAST * var, const bool internal)
    3238    : PabloAST(ClassTypeId::Var)
    33     , mName(cast<String>(var)) {
     39    , mName(cast<String>(var))
     40    , mInternal(internal) {
    3441
    3542    }
    3643private:
    3744    const String * const mName;
     45    const bool           mInternal;
    3846};
    3947
Note: See TracChangeset for help on using the changeset viewer.