Ignore:
Timestamp:
Oct 16, 2015, 10:49:26 AM (4 years ago)
Author:
cameron
Message:

Encapsulation of bitblock and carry pack construction

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

Legend:

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

    r4828 r4837  
    287287    return mCarryInPack[packIndex];
    288288}
    289 
     289   
    290290void CarryManager::storeCarryPack(unsigned packIndex) {
    291     mBuilder->CreateAlignedStore(mCarryOutPack[packIndex], mCarryPackPtr[packIndex], mPACK_SIZE/8);
     291    mBuilder->CreateAlignedStore(mPackBuilder->bitCast(mCarryOutPack[packIndex]), mCarryPackPtr[packIndex], mPACK_SIZE/8);
    292292}
    293293
     
    302302    }
    303303    uint64_t mask = ((((uint64_t) 1) << bitCount) - 1) << lo_bit;
    304     return mBuilder->CreateAnd(pack, mBuilder->getInt64(mask));
     304    return mPackBuilder->simd_and(pack, mBuilder->getInt64(mask));
    305305}
    306306   
     
    331331    }
    332332    else {
    333         mCarryOutPack[packIndex] = mBuilder->CreateOr(mCarryOutPack[packIndex], field);
     333        mCarryOutPack[packIndex] = mPackBuilder->simd_or(mCarryOutPack[packIndex], field);
    334334    }
    335335}
    336336
    337337Value * CarryManager::pack2bitblock(Value * pack) {
    338     return mBuilder->CreateBitCast(mBuilder->CreateZExt(pack, mBuilder->getIntNTy(mBITBLOCK_WIDTH)), mBitBlockType);
     338    return iBuilder->bitCast(mBuilder->CreateZExt(pack, mBuilder->getIntNTy(mBITBLOCK_WIDTH)));
    339339}
    340340   
     
    371371        Value * carryq_value = getCarryOpCarryIn(localIndex);
    372372        //calculate carry through logical ops
    373         Value* carrygen = mBuilder->CreateAnd(e1, e2, "carrygen");
    374         Value* carryprop = mBuilder->CreateOr(e1, e2, "carryprop");
     373        Value* carrygen = iBuilder->simd_and(e1, e2);
     374        Value* carryprop = iBuilder->simd_or(e1, e2);
    375375        Value* digitsum = iBuilder->simd_add(64, e1, e2);
    376376        Value* partial = iBuilder->simd_add(64, digitsum, carryq_value);
    377         Value* digitcarry = mBuilder->CreateOr(carrygen, mBuilder->CreateAnd(carryprop, mBuilder->CreateNot(partial)));
     377        Value* digitcarry = iBuilder->simd_or(carrygen, iBuilder->simd_and(carryprop, mBuilder->CreateNot(partial)));
    378378        Value* mid_carry_in = iBuilder->simd_slli(128, mBuilder->CreateLShr(digitcarry, 63), 64);
    379379        Value* sum = iBuilder->simd_add(64, partial, mBuilder->CreateBitCast(mid_carry_in, mBitBlockType));
    380         Value* carry_out_strm = mBuilder->CreateOr(carrygen, mBuilder->CreateAnd(carryprop, mBuilder->CreateNot(sum)));
     380        Value* carry_out_strm = iBuilder->simd_or(carrygen, iBuilder->simd_and(carryprop, mBuilder->CreateNot(sum)));
    381381        setCarryOpCarryOut(localIndex, carry_out_strm);
    382382        return sum;
     
    384384    else {
    385385        Value * carryq_value = getCarryOpCarryIn(localIndex);
    386         Value* carrygen = mBuilder->CreateAnd(e1, e2, "carrygen");
    387         Value* carryprop = mBuilder->CreateOr(e1, e2, "carryprop");
     386        Value* carrygen = iBuilder->simd_and(e1, e2);
     387        Value* carryprop = iBuilder->simd_or(e1, e2);
    388388        Value * sum = iBuilder->simd_add(mBITBLOCK_WIDTH, iBuilder->simd_add(mBITBLOCK_WIDTH, e1, e2), carryq_value);
    389         Value* carry_out_strm = mBuilder->CreateOr(carrygen, mBuilder->CreateAnd(carryprop, mBuilder->CreateNot(sum)));
     389        Value* carry_out_strm = iBuilder->simd_or(carrygen, iBuilder->simd_and(carryprop, mBuilder->CreateNot(sum)));
    390390        setCarryOpCarryOut(localIndex, carry_out_strm);
    391391        return sum;
     
    425425    if (mBITBLOCK_WIDTH == 128) {
    426426        Value * ahead64 = iBuilder->mvmd_dslli(64, carry_in, strm, 1);
    427         result_value = mBuilder->CreateOr(iBuilder->simd_srli(64, ahead64, 63), iBuilder->simd_slli(64, strm, 1));
     427        result_value = iBuilder->simd_or(iBuilder->simd_srli(64, ahead64, 63), iBuilder->simd_slli(64, strm, 1));
    428428    }
    429429    else {
     
    553553            PHINode * phi_out = mBuilder->CreatePHI(mCarryPackType, 2);
    554554            phi_out->addIncoming(mPackBuilder->allZeroes(),ifEntryBlock);
    555             phi_out->addIncoming(mCarryOutPack[index],ifBodyFinalBlock);
     555            phi_out->addIncoming(mPackBuilder->bitCast(mCarryOutPack[index]), ifBodyFinalBlock);
    556556            mCarryOutPack[index] = phi_out;
    557557        }
     
    568568            PHINode * ifPack_phi = mBuilder->CreatePHI(mCarryPackType, 2, "ifPack");
    569569            ifPack_phi->addIncoming(mCarryInfo->ifEntryPack, ifEntryBlock);
    570             ifPack_phi->addIncoming(mCarryOutPack[ifPackIndex], ifBodyFinalBlock);
     570            ifPack_phi->addIncoming(mPackBuilder->bitCast(mCarryOutPack[ifPackIndex]), ifBodyFinalBlock);
    571571            mCarryOutPack[ifPackIndex] = ifPack_phi;
    572572            return;
     
    579579        PHINode * summary_phi = mBuilder->CreatePHI(mCarryPackType, 2, "summary");
    580580        summary_phi->addIncoming(mPackBuilder->allZeroes(), ifEntryBlock);
    581         summary_phi->addIncoming(mCarryOutPack[summaryIndex], ifBodyFinalBlock);
     581        summary_phi->addIncoming(mPackBuilder->bitCast(mCarryOutPack[summaryIndex]), ifBodyFinalBlock);
    582582        mCarryOutPack[summaryIndex] = summary_phi;
    583583    }
     
    593593    PHINode * summary_phi = mBuilder->CreatePHI(mCarryPackType, 2, "summary");
    594594    summary_phi->addIncoming(mPackBuilder->allZeroes(), ifEntryBlock);
    595     summary_phi->addIncoming(mCarryOutPack[carrySummaryIndex], ifBodyFinalBlock);
     595    summary_phi->addIncoming(mPackBuilder->bitCast(mCarryOutPack[carrySummaryIndex]), ifBodyFinalBlock);
    596596    mCarryOutPack[carrySummaryIndex] = summary_phi;
    597597}
     
    618618            carry_summary = mCarryOutPack[localCarryIndex];
    619619            for (unsigned i = 1; i < localCarryPacks; i++) {
    620                 carry_summary = mBuilder->CreateOr(carry_summary, mCarryOutPack[localCarryIndex+i]);
     620                carry_summary = mPackBuilder->simd_or(carry_summary, mCarryOutPack[localCarryIndex+i]);
    621621            }
    622622        }
     
    626626                enterScope(inner_blk);
    627627                if (blockHasCarries()) {
    628                   carry_summary = mBuilder->CreateOr(carry_summary, mCarryOutPack[summaryPackIndex()]);
     628                  carry_summary = mPackBuilder->simd_or(carry_summary, mCarryOutPack[summaryPackIndex()]);
    629629                }
    630630                leaveScope();
     
    634634                enterScope(inner_blk);
    635635                if (blockHasCarries()) {
    636                     carry_summary = mBuilder->CreateOr(carry_summary, mCarryOutPack[summaryPackIndex()]);
     636                    carry_summary = mPackBuilder->simd_or(carry_summary, mCarryOutPack[summaryPackIndex()]);
    637637                }
    638638                leaveScope();
     
    685685#endif
    686686        PHINode * phi = mCarryOutAccumPhis[index];
    687         Value * carryOut = mBuilder->CreateOr(phi, mCarryOutPack[currentScopeBase+index]);
    688         phi->addIncoming(carryOut, whileBodyFinalBlock);
     687        Value * carryOut = mPackBuilder->simd_or(phi, mCarryOutPack[currentScopeBase+index]);
     688        phi->addIncoming(mPackBuilder->bitCast(carryOut), whileBodyFinalBlock);
    689689        mCarryOutPack[currentScopeBase+index] = carryOut;
    690690    }
     
    729729    }
    730730    mBuilder->CreateAlignedStore(countSoFar, countPtr, 8);
    731     return mBuilder->CreateBitCast(mBuilder->CreateZExt(countSoFar, mBuilder->getIntNTy(mBITBLOCK_WIDTH)), mBitBlockType);
     731    return iBuilder->bitCast(mBuilder->CreateZExt(countSoFar, mBuilder->getIntNTy(mBITBLOCK_WIDTH)));
    732732}
    733733
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r4827 r4837  
    5959, mBuilder(nullptr)
    6060, mCarryManager(nullptr)
    61 , mBitBlockType(VectorType::get(IntegerType::get(getGlobalContext(), 64), BLOCK_SIZE / 64))
     61    , mBitBlockType(VectorType::get(IntegerType::get(getGlobalContext(), 64), BLOCK_SIZE/64))
    6262, iBuilder(mBitBlockType)
    6363, mInputType(nullptr)
     
    236236        if (t1 == mBitBlockType) {
    237237            if (t2 == mBitBlockType) {
    238                 return iBuilder.bitblock_any(mBuilder->CreateOr(e1, e2));
     238                return iBuilder.bitblock_any(iBuilder.simd_or(e1, e2));
    239239            }
    240240            else {
     
    438438    }
    439439    else if (const And * pablo_and = dyn_cast<And>(stmt)) {
    440         expr = mBuilder->CreateAnd(compileExpression(pablo_and->getExpr1()), compileExpression(pablo_and->getExpr2()), "and");
     440        expr = iBuilder.simd_and(compileExpression(pablo_and->getExpr1()), compileExpression(pablo_and->getExpr2()));
    441441    }
    442442    else if (const Or * pablo_or = dyn_cast<Or>(stmt)) {
    443         expr = mBuilder->CreateOr(compileExpression(pablo_or->getExpr1()), compileExpression(pablo_or->getExpr2()), "or");
     443        expr = iBuilder.simd_or(compileExpression(pablo_or->getExpr1()), compileExpression(pablo_or->getExpr2()));
    444444    }
    445445    else if (const Xor * pablo_xor = dyn_cast<Xor>(stmt)) {
    446         expr = mBuilder->CreateXor(compileExpression(pablo_xor->getExpr1()), compileExpression(pablo_xor->getExpr2()), "xor");
     446        expr = iBuilder.simd_xor(compileExpression(pablo_xor->getExpr1()), compileExpression(pablo_xor->getExpr2()));
    447447    }
    448448    else if (const Sel * sel = dyn_cast<Sel>(stmt)) {
    449449        Value* ifMask = compileExpression(sel->getCondition());
    450         Value* ifTrue = mBuilder->CreateAnd(ifMask, compileExpression(sel->getTrueExpr()));
    451         Value* ifFalse = mBuilder->CreateAnd(mBuilder->CreateNot(ifMask), compileExpression(sel->getFalseExpr()));
    452         expr = mBuilder->CreateOr(ifTrue, ifFalse);
     450        Value* ifTrue = iBuilder.simd_and(ifMask, compileExpression(sel->getTrueExpr()));
     451        Value* ifFalse = iBuilder.simd_and(iBuilder.simd_not(ifMask), compileExpression(sel->getFalseExpr()));
     452        expr = iBuilder.simd_or(ifTrue, ifFalse);
    453453    }
    454454    else if (const Not * pablo_not = dyn_cast<Not>(stmt)) {
    455         expr = mBuilder->CreateNot(compileExpression(pablo_not->getExpr()));
     455        expr = iBuilder.simd_not(compileExpression(pablo_not->getExpr()));
    456456    }
    457457    else if (const Advance * adv = dyn_cast<Advance>(stmt)) {
     
    469469        Value * marker = compileExpression(mstar->getMarker());
    470470        Value * cc = compileExpression(mstar->getCharClass());
    471         Value * marker_and_cc = mBuilder->CreateAnd(marker, cc);
     471        Value * marker_and_cc = iBuilder.simd_and(marker, cc);
    472472        unsigned carry_index = mstar->getLocalCarryIndex();
    473473        Value * sum = mCarryManager->addCarryInCarryOut(carry_index, marker_and_cc, cc);
    474         expr = mBuilder->CreateOr(mBuilder->CreateXor(sum, cc), marker, "matchstar");
     474        expr = iBuilder.simd_or(iBuilder.simd_xor(sum, cc), marker);
    475475    }
    476476    else if (const Mod64MatchStar * mstar = dyn_cast<Mod64MatchStar>(stmt)) {
    477477        Value * marker = compileExpression(mstar->getMarker());
    478478        Value * cc = compileExpression(mstar->getCharClass());
    479         Value * marker_and_cc = mBuilder->CreateAnd(marker, cc);
     479        Value * marker_and_cc = iBuilder.simd_and(marker, cc);
    480480        Value * sum = iBuilder.simd_add(64, marker_and_cc, cc);
    481         expr = mBuilder->CreateOr(mBuilder->CreateXor(sum, cc), marker, "matchstar64");
     481        expr = iBuilder.simd_or(iBuilder.simd_xor(sum, cc), marker);
    482482    }
    483483    else if (const ScanThru * sthru = dyn_cast<ScanThru>(stmt)) {
     
    486486        unsigned carry_index = sthru->getLocalCarryIndex();
    487487        Value * sum = mCarryManager->addCarryInCarryOut(carry_index, marker_expr, cc_expr);
    488         expr = mBuilder->CreateAnd(sum, mBuilder->CreateNot(cc_expr), "scanthru");
     488        expr = iBuilder.simd_and(sum, iBuilder.simd_not(cc_expr));
    489489    }
    490490    else if (const Mod64ScanThru * sthru = dyn_cast<Mod64ScanThru>(stmt)) {
     
    492492        Value * cc_expr = compileExpression(sthru->getScanThru());
    493493        Value * sum = iBuilder.simd_add(64, marker_expr, cc_expr);
    494         expr = mBuilder->CreateAnd(sum, mBuilder->CreateNot(cc_expr), "scanthru64");
     494        expr = iBuilder.simd_and(sum, iBuilder.simd_not(cc_expr));
    495495    }
    496496    else if (const Count * c = dyn_cast<Count>(stmt)) {
     
    539539    Value* indices[] = {mBuilder->getInt64(0), mBuilder->getInt32(index)};
    540540    Value* gep = mBuilder->CreateGEP(mOutputAddressPtr, indices);
     541    if (marker->getType() != mBitBlockType) {
     542        marker = mBuilder->CreateBitCast(marker, mBitBlockType);
     543    }
    541544    mBuilder->CreateAlignedStore(marker, gep, iBuilder.getBitBlockWidth()/8, false);
    542545}
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.h

    r4821 r4837  
    115115    CarryManager *                      mCarryManager;
    116116
    117     VectorType* const                   mBitBlockType;
     117    Type* const                   mBitBlockType;
    118118    IDISA::IDISA_Builder                iBuilder;
    119119    PointerType*                        mInputType;
Note: See TracChangeset for help on using the changeset viewer.