Changeset 4898


Ignore:
Timestamp:
Dec 23, 2015, 11:47:47 AM (3 years ago)
Author:
cameron
Message:

Add IRBuilder functionality to IDISA_Builder; eliminate separate mBuilder

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

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/IDISA/idisa_avx_builder.cpp

    r4892 r4898  
    1616    if (fw == 64) {
    1717        Value * signmask_f64func = Intrinsic::getDeclaration(mMod, Intrinsic::x86_avx_movmsk_pd_256);
    18         Type * bitBlock_f64type = VectorType::get(mLLVMBuilder->getDoubleTy(), mBitBlockWidth/64);
    19         Value * a_as_pd = mLLVMBuilder->CreateBitCast(a, bitBlock_f64type);
    20         Value * mask = mLLVMBuilder->CreateCall(signmask_f64func, std::vector<Value *>({a_as_pd}));
     18        Type * bitBlock_f64type = VectorType::get(getDoubleTy(), mBitBlockWidth/64);
     19        Value * a_as_pd = CreateBitCast(a, bitBlock_f64type);
     20        Value * mask = CreateCall(signmask_f64func, std::vector<Value *>({a_as_pd}));
    2121        return mask;
    2222    }
    2323    else if (fw == 32) {
    2424        Value * signmask_f32func = Intrinsic::getDeclaration(mMod, Intrinsic::x86_avx_movmsk_ps_256);
    25         Type * bitBlock_f32type = VectorType::get(mLLVMBuilder->getFloatTy(), mBitBlockWidth/32);
    26         Value * a_as_ps = mLLVMBuilder->CreateBitCast(a, bitBlock_f32type);
    27         Value * mask = mLLVMBuilder->CreateCall(signmask_f32func, std::vector<Value *>({a_as_ps}));
     25        Type * bitBlock_f32type = VectorType::get(getFloatTy(), mBitBlockWidth/32);
     26        Value * a_as_ps = CreateBitCast(a, bitBlock_f32type);
     27        Value * mask = CreateCall(signmask_f32func, std::vector<Value *>({a_as_ps}));
    2828        return mask;
    2929    }
    30     Value * mask = mLLVMBuilder->CreateICmpSLT(fwCast(fw, a), ConstantAggregateZero::get(fwVectorType(fw)));
    31     return mLLVMBuilder->CreateBitCast(mask, mLLVMBuilder->getIntNTy(mBitBlockWidth/fw));
     30    Value * mask = CreateICmpSLT(fwCast(fw, a), ConstantAggregateZero::get(fwVectorType(fw)));
     31    return CreateBitCast(mask, getIntNTy(mBitBlockWidth/fw));
    3232}
    3333   
  • icGREP/icgrep-devel/icgrep/IDISA/idisa_avx_builder.h

    r4892 r4898  
    1616public:
    1717   
    18     IDISA_AVX_Builder(Type * bitBlockType) : IDISA_Builder(bitBlockType) {
     18    IDISA_AVX_Builder(Module * m, Type * bitBlockType) : IDISA_Builder(m, bitBlockType) {
    1919    }
    2020    ~IDISA_AVX_Builder() {};
     
    2525public:
    2626   
    27     IDISA_AVX2_Builder(Type * bitBlockType) : IDISA_AVX_Builder(bitBlockType) {
     27    IDISA_AVX2_Builder(Module * m, Type * bitBlockType) : IDISA_AVX_Builder(m, bitBlockType) {
    2828    }
    2929    Value * hsimd_signmask(unsigned fw, Value * a) override;
  • icGREP/icgrep-devel/icgrep/IDISA/idisa_builder.cpp

    r4895 r4898  
    1515VectorType * IDISA_Builder::fwVectorType(unsigned fw) {
    1616    int fieldCount = mBitBlockWidth/fw;
    17     return VectorType::get(mLLVMBuilder->getIntNTy(fw), fieldCount);
     17    return VectorType::get(getIntNTy(fw), fieldCount);
    1818}
    1919
    2020Value * IDISA_Builder::fwCast(unsigned fw, Value * a) {
    21     return a->getType() == fwVectorType(fw) ? a : mLLVMBuilder->CreateBitCast(a, fwVectorType(fw));
     21    return a->getType() == fwVectorType(fw) ? a : CreateBitCast(a, fwVectorType(fw));
    2222}
    2323
     
    3232                                                   /*Linkage=*/ GlobalValue::PrivateLinkage,
    3333                                                   /*Initializer=*/ regNameData);
    34     Value * regStrPtr = mLLVMBuilder->CreateGEP(regStrVar, std::vector<Value *>({mLLVMBuilder->getInt64(0), mLLVMBuilder->getInt32(0)}));
    35     mLLVMBuilder->CreateCall(mPrintRegisterFunction, std::vector<Value *>({regStrPtr, bitCast(bitblockValue)}));
     34    Value * regStrPtr = CreateGEP(regStrVar, std::vector<Value *>({getInt64(0), getInt32(0)}));
     35    CreateCall(mPrintRegisterFunction, std::vector<Value *>({regStrPtr, bitCast(bitblockValue)}));
    3636}
    3737
    3838    Constant * IDISA_Builder::simd_himask(unsigned fw) {
    39         return Constant::getIntegerValue(mLLVMBuilder->getIntNTy(mBitBlockWidth), APInt::getSplat(mBitBlockWidth, APInt::getHighBitsSet(fw, fw/2)));
     39        return Constant::getIntegerValue(getIntNTy(mBitBlockWidth), APInt::getSplat(mBitBlockWidth, APInt::getHighBitsSet(fw, fw/2)));
    4040    }
    4141   
    4242    Constant * IDISA_Builder::simd_lomask(unsigned fw) {
    43         return Constant::getIntegerValue(mLLVMBuilder->getIntNTy(mBitBlockWidth), APInt::getSplat(mBitBlockWidth, APInt::getLowBitsSet(fw, fw/2)));
     43        return Constant::getIntegerValue(getIntNTy(mBitBlockWidth), APInt::getSplat(mBitBlockWidth, APInt::getLowBitsSet(fw, fw/2)));
    4444    }
    4545   
    4646    Value * IDISA_Builder::simd_add(unsigned fw, Value * a, Value * b) {
    47     return mLLVMBuilder->CreateAdd(fwCast(fw, a), fwCast(fw, b));
     47    return CreateAdd(fwCast(fw, a), fwCast(fw, b));
    4848}
    4949
    5050Value * IDISA_Builder::simd_sub(unsigned fw, Value * a, Value * b) {
    51     return mLLVMBuilder->CreateSub(fwCast(fw, a), fwCast(fw, b));
     51    return CreateSub(fwCast(fw, a), fwCast(fw, b));
    5252}
    5353
    5454Value * IDISA_Builder::simd_mult(unsigned fw, Value * a, Value * b) {
    55     return mLLVMBuilder->CreateMul(fwCast(fw, a), fwCast(fw, b));
     55    return CreateMul(fwCast(fw, a), fwCast(fw, b));
    5656}
    5757
    5858Value * IDISA_Builder::simd_eq(unsigned fw, Value * a, Value * b) {
    59     return mLLVMBuilder->CreateSExt(mLLVMBuilder->CreateICmpEQ(fwCast(fw, a), fwCast(fw, b)), fwVectorType(fw));
     59    return CreateSExt(CreateICmpEQ(fwCast(fw, a), fwCast(fw, b)), fwVectorType(fw));
    6060}
    6161
    6262Value * IDISA_Builder::simd_gt(unsigned fw, Value * a, Value * b) {
    63     return mLLVMBuilder->CreateSExt(mLLVMBuilder->CreateICmpSGT(fwCast(fw, a), fwCast(fw, b)), fwVectorType(fw));
     63    return CreateSExt(CreateICmpSGT(fwCast(fw, a), fwCast(fw, b)), fwVectorType(fw));
    6464}
    6565
    6666Value * IDISA_Builder::simd_ugt(unsigned fw, Value * a, Value * b) {
    67     return mLLVMBuilder->CreateSExt(mLLVMBuilder->CreateICmpUGT(fwCast(fw, a), fwCast(fw, b)), fwVectorType(fw));
     67    return CreateSExt(CreateICmpUGT(fwCast(fw, a), fwCast(fw, b)), fwVectorType(fw));
    6868}
    6969
    7070Value * IDISA_Builder::simd_lt(unsigned fw, Value * a, Value * b) {
    71     return mLLVMBuilder->CreateSExt(mLLVMBuilder->CreateICmpSLT(fwCast(fw, a), fwCast(fw, b)), fwVectorType(fw));
     71    return CreateSExt(CreateICmpSLT(fwCast(fw, a), fwCast(fw, b)), fwVectorType(fw));
    7272}
    7373
    7474Value * IDISA_Builder::simd_ult(unsigned fw, Value * a, Value * b) {
    75     return mLLVMBuilder->CreateSExt(mLLVMBuilder->CreateICmpULT(fwCast(fw, a), fwCast(fw, b)), fwVectorType(fw));
     75    return CreateSExt(CreateICmpULT(fwCast(fw, a), fwCast(fw, b)), fwVectorType(fw));
    7676}
    7777
     
    7979    Value * aVec = fwCast(fw, a);
    8080    Value * bVec = fwCast(fw, b);
    81     return mLLVMBuilder->CreateSelect(mLLVMBuilder->CreateICmpSGT(aVec, bVec), aVec, bVec);
     81    return CreateSelect(CreateICmpSGT(aVec, bVec), aVec, bVec);
    8282}
    8383
     
    8585    Value * aVec = fwCast(fw, a);
    8686    Value * bVec = fwCast(fw, b);
    87     return mLLVMBuilder->CreateSelect(mLLVMBuilder->CreateICmpUGT(aVec, bVec), aVec, bVec);
     87    return CreateSelect(CreateICmpUGT(aVec, bVec), aVec, bVec);
    8888}
    8989
     
    9191    Value * aVec = fwCast(fw, a);
    9292    Value * bVec = fwCast(fw, b);
    93     return mLLVMBuilder->CreateSelect(mLLVMBuilder->CreateICmpSLT(aVec, bVec), aVec, bVec);
     93    return CreateSelect(CreateICmpSLT(aVec, bVec), aVec, bVec);
    9494}
    9595
     
    9797    Value * aVec = fwCast(fw, a);
    9898    Value * bVec = fwCast(fw, b);
    99     return mLLVMBuilder->CreateSelect(mLLVMBuilder->CreateICmpULT(aVec, bVec), aVec, bVec);
     99    return CreateSelect(CreateICmpULT(aVec, bVec), aVec, bVec);
    100100}
    101101
    102102Value * IDISA_Builder::simd_slli(unsigned fw, Value * a, unsigned shift) {
    103     return mLLVMBuilder->CreateShl(fwCast(fw, a), shift);
     103    return CreateShl(fwCast(fw, a), shift);
    104104}
    105105
    106106Value * IDISA_Builder::simd_srli(unsigned fw, Value * a, unsigned shift) {
    107     return mLLVMBuilder->CreateLShr(fwCast(fw, a), shift);
     107    return CreateLShr(fwCast(fw, a), shift);
    108108}
    109109
    110110Value * IDISA_Builder::simd_srai(unsigned fw, Value * a, unsigned shift) {
    111     return mLLVMBuilder->CreateAShr(fwCast(fw, a), shift);
     111    return CreateAShr(fwCast(fw, a), shift);
    112112}
    113113
    114114Value * IDISA_Builder::simd_cttz(unsigned fw, Value * a) {
    115115    Value * cttzFunc = Intrinsic::getDeclaration(mMod, Intrinsic::cttz, fwVectorType(fw));
    116     Value * rslt = mLLVMBuilder->CreateCall(cttzFunc, std::vector<Value *>({fwCast(fw, a), ConstantInt::get(mLLVMBuilder->getInt1Ty(), 0)}));
     116    Value * rslt = CreateCall(cttzFunc, std::vector<Value *>({fwCast(fw, a), ConstantInt::get(getInt1Ty(), 0)}));
    117117    return rslt;
    118118}
     
    120120Value * IDISA_Builder::simd_popcount(unsigned fw, Value * a) {
    121121    Value * ctpopFunc = Intrinsic::getDeclaration(mMod, Intrinsic::ctpop, fwVectorType(fw));
    122     Value * rslt = mLLVMBuilder->CreateCall(ctpopFunc, std::vector<Value *>({fwCast(fw, a)}));
     122    Value * rslt = CreateCall(ctpopFunc, std::vector<Value *>({fwCast(fw, a)}));
    123123    return rslt;
    124124}
     
    127127    Value * aVec = fwCast(fw, a);
    128128    Value * bVec = fwCast(fw, b);
    129     return mLLVMBuilder->CreateSelect(mLLVMBuilder->CreateICmpSLT(cond, mZeroInitializer), aVec, bVec);
     129    return CreateSelect(CreateICmpSLT(cond, mZeroInitializer), aVec, bVec);
    130130}
    131131
     
    137137    std::vector<Constant*> Idxs;
    138138    for (unsigned i = field_count/2; i < field_count; i++) {
    139         Idxs.push_back(mLLVMBuilder->getInt32(i));    // selects elements from first reg.
    140         Idxs.push_back(mLLVMBuilder->getInt32(i + field_count)); // selects elements from second reg.
    141     }
    142     return mLLVMBuilder->CreateShuffleVector(aVec, bVec, ConstantVector::get(Idxs));
     139        Idxs.push_back(getInt32(i));    // selects elements from first reg.
     140        Idxs.push_back(getInt32(i + field_count)); // selects elements from second reg.
     141    }
     142    return CreateShuffleVector(aVec, bVec, ConstantVector::get(Idxs));
    143143}
    144144
     
    149149    std::vector<Constant*> Idxs;
    150150    for (unsigned i = 0; i < field_count/2; i++) {
    151         Idxs.push_back(mLLVMBuilder->getInt32(i));    // selects elements from first reg.
    152         Idxs.push_back(mLLVMBuilder->getInt32(i + field_count)); // selects elements from second reg.
    153     }
    154     return mLLVMBuilder->CreateShuffleVector(aVec, bVec, ConstantVector::get(Idxs));
     151        Idxs.push_back(getInt32(i));    // selects elements from first reg.
     152        Idxs.push_back(getInt32(i + field_count)); // selects elements from second reg.
     153    }
     154    return CreateShuffleVector(aVec, bVec, ConstantVector::get(Idxs));
    155155}
    156156
    157157Value * IDISA_Builder::esimd_bitspread(unsigned fw, Value * bitmask) {
    158158    unsigned field_count = mBitBlockWidth/fw;
    159     Type * field_type = mLLVMBuilder->getIntNTy(fw);
     159    Type * field_type = getIntNTy(fw);
    160160    if (bitmask->getType()->getIntegerBitWidth() < fw) {
    161         bitmask = mLLVMBuilder->CreateZExt(bitmask, field_type);
     161        bitmask = CreateZExt(bitmask, field_type);
    162162    }
    163163    else if (bitmask->getType()->getIntegerBitWidth() > fw) {
    164         bitmask = mLLVMBuilder->CreateTrunc(bitmask, field_type);
    165     }
    166     Value * spread_field = mLLVMBuilder->CreateBitCast(bitmask, VectorType::get(mLLVMBuilder->getIntNTy(fw), 1));
    167     Value * undefVec = UndefValue::get(VectorType::get(mLLVMBuilder->getIntNTy(fw), 1));
    168     Value * broadcast = mLLVMBuilder->CreateShuffleVector(spread_field, undefVec, Constant::getNullValue(VectorType::get(mLLVMBuilder->getInt32Ty(), field_count)));
     164        bitmask = CreateTrunc(bitmask, field_type);
     165    }
     166    Value * spread_field = CreateBitCast(bitmask, VectorType::get(getIntNTy(fw), 1));
     167    Value * undefVec = UndefValue::get(VectorType::get(getIntNTy(fw), 1));
     168    Value * broadcast = CreateShuffleVector(spread_field, undefVec, Constant::getNullValue(VectorType::get(getInt32Ty(), field_count)));
    169169    std::vector<Constant*> bitSel;
    170170    std::vector<Constant*> bitShift;
     
    175175    Value * bitSelVec = ConstantVector::get(bitSel);
    176176    Value * bitShiftVec = ConstantVector::get(bitShift);
    177     return mLLVMBuilder->CreateLShr(mLLVMBuilder->CreateAnd(bitSelVec, broadcast), bitShiftVec);
     177    return CreateLShr(CreateAnd(bitSelVec, broadcast), bitShiftVec);
    178178}
    179179
     
    184184    std::vector<Constant*> Idxs;
    185185    for (unsigned i = 0; i < field_count; i++) {
    186         Idxs.push_back(mLLVMBuilder->getInt32(2*i));
    187     }
    188     return mLLVMBuilder->CreateShuffleVector(aVec, bVec, ConstantVector::get(Idxs));
     186        Idxs.push_back(getInt32(2*i));
     187    }
     188    return CreateShuffleVector(aVec, bVec, ConstantVector::get(Idxs));
    189189}
    190190
     
    195195    std::vector<Constant*> Idxs;
    196196    for (unsigned i = 0; i < field_count; i++) {
    197         Idxs.push_back(mLLVMBuilder->getInt32(2*i+1));
    198     }
    199     return mLLVMBuilder->CreateShuffleVector(aVec, bVec, ConstantVector::get(Idxs));
     197        Idxs.push_back(getInt32(2*i+1));
     198    }
     199    return CreateShuffleVector(aVec, bVec, ConstantVector::get(Idxs));
    200200}
    201201
    202202Value * IDISA_Builder::hsimd_signmask(unsigned fw, Value * a) {
    203     Value * mask = mLLVMBuilder->CreateICmpSLT(fwCast(fw, a), ConstantAggregateZero::get(fwVectorType(fw)));
    204     return mLLVMBuilder->CreateZExt(mLLVMBuilder->CreateBitCast(mask, mLLVMBuilder->getIntNTy(mBitBlockWidth/fw)), mLLVMBuilder->getInt32Ty());
     203    Value * mask = CreateICmpSLT(fwCast(fw, a), ConstantAggregateZero::get(fwVectorType(fw)));
     204    return CreateZExt(CreateBitCast(mask, getIntNTy(mBitBlockWidth/fw)), getInt32Ty());
    205205}
    206206
    207207Value * IDISA_Builder::mvmd_extract(unsigned fw, Value * a, unsigned fieldIndex) {
    208208    Value * aVec = fwCast(fw, a);
    209     return mLLVMBuilder->CreateExtractElement(aVec, mLLVMBuilder->getInt32(fieldIndex));
     209    return CreateExtractElement(aVec, getInt32(fieldIndex));
    210210}
    211211
    212212Value * IDISA_Builder::mvmd_insert(unsigned fw, Value * blk, Value * elt, unsigned fieldIndex) {
    213213    Value * vec = fwCast(fw, blk);
    214     return mLLVMBuilder->CreateInsertElement(vec, elt, mLLVMBuilder->getInt32(fieldIndex));
     214    return CreateInsertElement(vec, elt, getInt32(fieldIndex));
    215215}
    216216
     
    221221    std::vector<Constant*> Idxs;
    222222    for (unsigned i = 0; i < field_count; i++) {
    223         Idxs.push_back(mLLVMBuilder->getInt32(i + shift));
    224     }
    225     return mLLVMBuilder->CreateShuffleVector(bVec, aVec, ConstantVector::get(Idxs));
     223        Idxs.push_back(getInt32(i + shift));
     224    }
     225    return CreateShuffleVector(bVec, aVec, ConstantVector::get(Idxs));
    226226}
    227227
    228228Value * IDISA_Builder::bitblock_any(Value * a) {
    229     Type * iBitBlock = mLLVMBuilder->getIntNTy(mBitBlockWidth);
    230     return mLLVMBuilder->CreateICmpNE(mLLVMBuilder->CreateBitCast(a, iBitBlock),  ConstantInt::get(iBitBlock, 0));
     229    Type * iBitBlock = getIntNTy(mBitBlockWidth);
     230    return CreateICmpNE(CreateBitCast(a, iBitBlock),  ConstantInt::get(iBitBlock, 0));
    231231}
    232232
    233233Value * IDISA_Builder::simd_and(Value * a, Value * b) {
    234     return a->getType() == b->getType() ? mLLVMBuilder->CreateAnd(a, b) : mLLVMBuilder->CreateAnd(bitCast(a), bitCast(b));
     234    return a->getType() == b->getType() ? CreateAnd(a, b) : CreateAnd(bitCast(a), bitCast(b));
    235235}
    236236
    237237Value * IDISA_Builder::simd_or(Value * a, Value * b) {
    238     return a->getType() == b->getType() ? mLLVMBuilder->CreateOr(a, b) : mLLVMBuilder->CreateOr(bitCast(a), bitCast(b));
     238    return a->getType() == b->getType() ? CreateOr(a, b) : CreateOr(bitCast(a), bitCast(b));
    239239}
    240240   
    241241Value * IDISA_Builder::simd_xor(Value * a, Value * b) {
    242     return a->getType() == b->getType() ? mLLVMBuilder->CreateXor(a, b) : mLLVMBuilder->CreateXor(bitCast(a), bitCast(b));
     242    return a->getType() == b->getType() ? CreateXor(a, b) : CreateXor(bitCast(a), bitCast(b));
    243243}
    244244
  • icGREP/icgrep-devel/icgrep/IDISA/idisa_builder.h

    r4895 r4898  
    1717namespace IDISA {
    1818
    19 class IDISA_Builder {
     19    class IDISA_Builder : public IRBuilder<> {
    2020public:
    2121
    22     IDISA_Builder(Type * bitBlockType)
    23     : mMod(nullptr)
    24     , mLLVMBuilder(nullptr)
     22        IDISA_Builder(Module * m, Type * bitBlockType) : IRBuilder<>(m->getContext())
     23    , mMod(m)
    2524    , mBitBlockType(bitBlockType)
    2625    , mBitBlockWidth(bitBlockType->isIntegerTy() ? cast<IntegerType>(bitBlockType)->getIntegerBitWidth() : cast<VectorType>(bitBlockType)->getBitWidth())
     
    3130    }
    3231    virtual ~IDISA_Builder() {};
    33 
    34     void initialize(Module * m, IRBuilder <> * b) {
    35         mMod = m;
    36         mLLVMBuilder = b;
    37     }
    3832   
    3933    Type * getBitBlockType() { return mBitBlockType;}
    40     Value * bitCast(Value * a) {return a->getType() == mBitBlockType ? a : mLLVMBuilder->CreateBitCast(a, mBitBlockType);}
     34    Value * bitCast(Value * a) {return a->getType() == mBitBlockType ? a : CreateBitCast(a, mBitBlockType);}
    4135    int getBitBlockWidth() { return mBitBlockWidth;}
    4236    Module * getModule() {return mMod;}
     
    9286protected:
    9387    Module * mMod;
    94     IRBuilder <> * mLLVMBuilder;
    9588    Type * mBitBlockType;
    9689    unsigned mBitBlockWidth;
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.cpp

    r4897 r4898  
    5252    f->setCallingConv(CallingConv::C);
    5353    f->setAttributes(AttrSet);
    54     llvm::IRBuilderBase::InsertPoint ip = mBuilder->saveIP();
    55     mBuilder->SetInsertPoint(BasicBlock::Create(m->getContext(), "entry1", f,0));
    56     mBuilder->CreateMemSet(mCarryBitBlockPtr, mBuilder->getInt8(0), mTotalCarryDataBitBlocks * mBITBLOCK_WIDTH/8, 4);
    57     ReturnInst::Create(m->getContext(), mBuilder->GetInsertBlock());
    58     mBuilder->restoreIP(ip);
     54    llvm::IRBuilderBase::InsertPoint ip = iBuilder->saveIP();
     55    iBuilder->SetInsertPoint(BasicBlock::Create(m->getContext(), "entry1", f,0));
     56    iBuilder->CreateMemSet(mCarryBitBlockPtr, iBuilder->getInt8(0), mTotalCarryDataBitBlocks * mBITBLOCK_WIDTH/8, 4);
     57    ReturnInst::Create(m->getContext(), iBuilder->GetInsertBlock());
     58    iBuilder->restoreIP(ip);
    5959}
    6060   
     
    6868        mPACK_SIZE = 64;
    6969        mITEMS_PER_PACK = 64;
    70         mCarryPackType = mBuilder->getIntNTy(mPACK_SIZE);
     70        mCarryPackType = iBuilder->getIntNTy(mPACK_SIZE);
    7171    }
    7272    else {
     
    9797    cdArray->setInitializer(cdInitData);
    9898   
    99     mCarryPackBasePtr = mBuilder->CreateBitCast(cdArray, PointerType::get(mCarryPackType, 0));
    100     mCarryBitBlockPtr = mBuilder->CreateBitCast(cdArray, PointerType::get(mBitBlockType, 0));
     99    mCarryPackBasePtr = iBuilder->CreateBitCast(cdArray, PointerType::get(mCarryPackType, 0));
     100    mCarryBitBlockPtr = iBuilder->CreateBitCast(cdArray, PointerType::get(mBitBlockType, 0));
    101101   
    102102    generateCarryDataInitializer(m);
     
    104104    // Popcount data is stored after all the carry data.
    105105    if (mPabloCountCount > 0) {
    106         ArrayType* pcArrayTy = ArrayType::get(mBuilder->getIntNTy(64), mPabloCountCount);
     106        ArrayType* pcArrayTy = ArrayType::get(iBuilder->getIntNTy(64), mPabloCountCount);
    107107        GlobalVariable* pcArray = new GlobalVariable(*m, pcArrayTy, /*isConstant=*/false, GlobalValue::CommonLinkage, 0, "popcount_data");
    108108        cdArray->setAlignment(mBITBLOCK_WIDTH/8);
    109109        ConstantAggregateZero* pcInitData = ConstantAggregateZero::get(pcArrayTy);
    110110        pcArray->setInitializer(pcInitData);
    111         mPopcountBasePtr = mBuilder->CreateBitCast(pcArray, Type::getInt64PtrTy(mBuilder->getContext()));
     111        mPopcountBasePtr = iBuilder->CreateBitCast(pcArray, Type::getInt64PtrTy(iBuilder->getContext()));
    112112    }
    113113    // Carry Data area will have one extra bit block to store the block number.
    114     GlobalVariable* blkNo = new GlobalVariable(*m, mBuilder->getIntNTy(64), /*isConstant=*/false, GlobalValue::CommonLinkage, 0, "blockNo");
     114    GlobalVariable* blkNo = new GlobalVariable(*m, iBuilder->getIntNTy(64), /*isConstant=*/false, GlobalValue::CommonLinkage, 0, "blockNo");
    115115    blkNo->setAlignment(16);
    116     blkNo->setInitializer(mBuilder->getInt64(0));
     116    blkNo->setInitializer(iBuilder->getInt64(0));
    117117    mBlockNoPtr = blkNo;
    118     mBlockNo = mBuilder->CreateLoad(mBlockNoPtr);
     118    mBlockNo = iBuilder->CreateLoad(mBlockNoPtr);
    119119    /*  Set the current scope to PabloRoot */
    120120    mCurrentScope = mPabloRoot;
     
    124124   
    125125void CarryManager::generateBlockNoIncrement() {
    126     mBuilder->CreateStore(mBuilder->CreateAdd(mBlockNo, mBuilder->getInt64(1)), mBlockNoPtr);
     126    iBuilder->CreateStore(iBuilder->CreateAdd(mBlockNo, iBuilder->getInt64(1)), mBlockNoPtr);
    127127}
    128128
     
    277277Value * CarryManager::getCarryPack(unsigned packIndex) {
    278278    if (mCarryInPack[packIndex] == nullptr) {
    279         Value * packPtr = mBuilder->CreateGEP(mCarryPackBasePtr, mBuilder->getInt64(packIndex));
     279        Value * packPtr = iBuilder->CreateGEP(mCarryPackBasePtr, iBuilder->getInt64(packIndex));
    280280        // Save the computed pointer - so that it can be used in storeCarryPack.
    281281        mCarryPackPtr[packIndex] = packPtr;
    282         mCarryInPack[packIndex] = mBuilder->CreateAlignedLoad(packPtr, mPACK_SIZE/8);
     282        mCarryInPack[packIndex] = iBuilder->CreateAlignedLoad(packPtr, mPACK_SIZE/8);
    283283    }
    284284    return mCarryInPack[packIndex];
     
    286286   
    287287void CarryManager::storeCarryPack(unsigned packIndex) {
    288     mBuilder->CreateAlignedStore(mCarryOutPack[packIndex], mCarryPackPtr[packIndex], mPACK_SIZE/8);
     288    iBuilder->CreateAlignedStore(mCarryOutPack[packIndex], mCarryPackPtr[packIndex], mPACK_SIZE/8);
    289289}
    290290
     
    299299    }
    300300    uint64_t mask = ((((uint64_t) 1) << bitCount) - 1) << lo_bit;
    301     return mBuilder->CreateAnd(pack, ConstantInt::get(mCarryPackType, mask));
     301    return iBuilder->CreateAnd(pack, ConstantInt::get(mCarryPackType, mask));
    302302}
    303303   
     
    307307    Value * selected = maskSelectBitRange(getCarryPack(packIndex), packOffset, carryBitCount);
    308308    if (packOffset == 0) return selected;
    309     return mBuilder->CreateLShr(selected, packOffset);
     309    return iBuilder->CreateLShr(selected, packOffset);
    310310}
    311311
     
    319319    //Value * field = maskSelectBitRange(field, PACK_SIZE - carryBitCount, carryBitCount);
    320320    if (rshift != 0) {
    321         field = mBuilder->CreateLShr(field, mBuilder->getInt64(rshift));
     321        field = iBuilder->CreateLShr(field, iBuilder->getInt64(rshift));
    322322    }
    323323    if (packOffset != 0) {
    324         field = mBuilder->CreateAnd(field, mBuilder->getInt64(mask));
     324        field = iBuilder->CreateAnd(field, iBuilder->getInt64(mask));
    325325    }
    326326    if (mCarryOutPack[packIndex] == nullptr) {
     
    328328    }
    329329    else {
    330         mCarryOutPack[packIndex] = mBuilder->CreateOr(mCarryOutPack[packIndex], field);
     330        mCarryOutPack[packIndex] = iBuilder->CreateOr(mCarryOutPack[packIndex], field);
    331331    }
    332332}
    333333
    334334Value * CarryManager::pack2bitblock(Value * pack) {
    335     return iBuilder->bitCast(mBuilder->CreateZExt(pack, mBuilder->getIntNTy(mBITBLOCK_WIDTH)));
     335    return iBuilder->bitCast(iBuilder->CreateZExt(pack, iBuilder->getIntNTy(mBITBLOCK_WIDTH)));
    336336}
    337337   
     
    361361    else {
    362362#ifndef LONGADD
    363         Value * carry_bit = mBuilder->CreateLShr(mBuilder->CreateBitCast(carry_out_strm, mBuilder->getIntNTy(mBITBLOCK_WIDTH)), mBITBLOCK_WIDTH-1);
    364         mCarryOutPack[posn] = mBuilder->CreateBitCast(carry_bit, mBitBlockType);
     363        Value * carry_bit = iBuilder->CreateLShr(iBuilder->CreateBitCast(carry_out_strm, iBuilder->getIntNTy(mBITBLOCK_WIDTH)), mBITBLOCK_WIDTH-1);
     364        mCarryOutPack[posn] = iBuilder->CreateBitCast(carry_bit, mBitBlockType);
    365365#else
    366366        mCarryOutPack[posn] = carry_out_strm;
     
    380380        Value* digitsum = iBuilder->simd_add(64, e1, e2);
    381381        Value* partial = iBuilder->simd_add(64, digitsum, carryq_value);
    382         Value* digitcarry = iBuilder->simd_or(carrygen, iBuilder->simd_and(carryprop, mBuilder->CreateNot(partial)));
    383         Value* mid_carry_in = iBuilder->simd_slli(128, mBuilder->CreateLShr(digitcarry, 63), 64);
    384         Value* sum = iBuilder->simd_add(64, partial, mBuilder->CreateBitCast(mid_carry_in, mBitBlockType));
    385         Value* carry_out_strm = iBuilder->simd_or(carrygen, iBuilder->simd_and(carryprop, mBuilder->CreateNot(sum)));
     382        Value* digitcarry = iBuilder->simd_or(carrygen, iBuilder->simd_and(carryprop, iBuilder->CreateNot(partial)));
     383        Value* mid_carry_in = iBuilder->simd_slli(128, iBuilder->CreateLShr(digitcarry, 63), 64);
     384        Value* sum = iBuilder->simd_add(64, partial, iBuilder->CreateBitCast(mid_carry_in, mBitBlockType));
     385        Value* carry_out_strm = iBuilder->simd_or(carrygen, iBuilder->simd_and(carryprop, iBuilder->CreateNot(sum)));
    386386        setCarryOpCarryOut(localIndex, carry_out_strm);
    387387        return sum;
     
    393393        Value* carryprop = iBuilder->simd_or(e1, e2);
    394394        Value * sum = iBuilder->simd_add(mBITBLOCK_WIDTH, iBuilder->simd_add(mBITBLOCK_WIDTH, e1, e2), carryq_value);
    395         Value* carry_out_strm = iBuilder->simd_or(carrygen, iBuilder->simd_and(carryprop, mBuilder->CreateNot(sum)));
     395        Value* carry_out_strm = iBuilder->simd_or(carrygen, iBuilder->simd_and(carryprop, iBuilder->CreateNot(sum)));
    396396        setCarryOpCarryOut(localIndex, carry_out_strm);
    397397        return sum;
     
    402402        Value * carryprop = iBuilder->simd_or(e1, e2);
    403403        Value * digitsum = iBuilder->simd_add(64, e1, e2);
    404         Value * digitcarry = iBuilder->simd_or(carrygen, iBuilder->simd_and(carryprop, mBuilder->CreateNot(digitsum)));
     404        Value * digitcarry = iBuilder->simd_or(carrygen, iBuilder->simd_and(carryprop, iBuilder->CreateNot(digitsum)));
    405405        Value * carryMask = iBuilder->hsimd_signmask(64, digitcarry);
    406         Value * carryMask2 = mBuilder->CreateOr(mBuilder->CreateAdd(carryMask, carryMask), carryin);
     406        Value * carryMask2 = iBuilder->CreateOr(iBuilder->CreateAdd(carryMask, carryMask), carryin);
    407407        Value * bubble = iBuilder->simd_eq(64, digitsum, iBuilder->allOnes());
    408408        Value * bubbleMask = iBuilder->hsimd_signmask(64, bubble);
    409         Value * incrementMask = mBuilder->CreateXor(mBuilder->CreateAdd(bubbleMask, carryMask2), bubbleMask);
     409        Value * incrementMask = iBuilder->CreateXor(iBuilder->CreateAdd(bubbleMask, carryMask2), bubbleMask);
    410410        Value * increments = iBuilder->esimd_bitspread(64,incrementMask);
    411411        Value * sum = iBuilder->simd_add(64, digitsum, increments);
    412         Value * carry_out_strm = iBuilder->mvmd_insert(32, iBuilder->allZeroes(), mBuilder->CreateLShr(incrementMask, iBuilder->getBitBlockWidth()/64), 0);
     412        Value * carry_out_strm = iBuilder->mvmd_insert(32, iBuilder->allZeroes(), iBuilder->CreateLShr(incrementMask, iBuilder->getBitBlockWidth()/64), 0);
    413413        setCarryOpCarryOut(localIndex, carry_out_strm);
    414414        return sum;
     
    436436    if (mITEMS_PER_PACK > 1) {// #ifdef PACKING
    437437        extractAndSaveCarryOutBits(strm, posn, 1);
    438         Value* carry_longint = mBuilder->CreateZExt(getCarryInBits(posn, 1), mBuilder->getIntNTy(mBITBLOCK_WIDTH));
    439         Value* strm_longint = mBuilder->CreateBitCast(strm, mBuilder->getIntNTy(mBITBLOCK_WIDTH));
    440         Value* adv_longint = mBuilder->CreateOr(mBuilder->CreateShl(strm_longint, 1), carry_longint);
    441         Value* result_value = mBuilder->CreateBitCast(adv_longint, mBitBlockType);
     438        Value* carry_longint = iBuilder->CreateZExt(getCarryInBits(posn, 1), iBuilder->getIntNTy(mBITBLOCK_WIDTH));
     439        Value* strm_longint = iBuilder->CreateBitCast(strm, iBuilder->getIntNTy(mBITBLOCK_WIDTH));
     440        Value* adv_longint = iBuilder->CreateOr(iBuilder->CreateShl(strm_longint, 1), carry_longint);
     441        Value* result_value = iBuilder->CreateBitCast(adv_longint, mBitBlockType);
    442442        return result_value;
    443443    }
     
    456456        extractAndSaveCarryOutBits(strm, posn, shift_amount);
    457457        //std::cerr << "shortAdvanceCarryInCarryOut: posn = " << posn << ", shift_amount = " << shift_amount << std::endl;
    458         Value* carry_longint = mBuilder->CreateZExt(getCarryInBits(posn, shift_amount), mBuilder->getIntNTy(mBITBLOCK_WIDTH));
    459         Value* strm_longint = mBuilder->CreateBitCast(strm, mBuilder->getIntNTy(mBITBLOCK_WIDTH));
    460         Value* adv_longint = mBuilder->CreateOr(mBuilder->CreateShl(strm_longint, shift_amount), carry_longint);
    461         Value* result_value = mBuilder->CreateBitCast(adv_longint, mBitBlockType);
     458        Value* carry_longint = iBuilder->CreateZExt(getCarryInBits(posn, shift_amount), iBuilder->getIntNTy(mBITBLOCK_WIDTH));
     459        Value* strm_longint = iBuilder->CreateBitCast(strm, iBuilder->getIntNTy(mBITBLOCK_WIDTH));
     460        Value* adv_longint = iBuilder->CreateOr(iBuilder->CreateShl(strm_longint, shift_amount), carry_longint);
     461        Value* result_value = iBuilder->CreateBitCast(adv_longint, mBitBlockType);
    462462        return result_value;
    463463    }
     
    475475        return iBuilder->simd_or(iBuilder->simd_srli(DSSLI_FIELDWIDTH, ahead, DSSLI_FIELDWIDTH-shift_amount), iBuilder->simd_slli(DSSLI_FIELDWIDTH, strm, shift_amount));
    476476    }
    477     Value* advanceq_longint = mBuilder->CreateBitCast(carry_in, mBuilder->getIntNTy(mBITBLOCK_WIDTH));
    478     Value* strm_longint = mBuilder->CreateBitCast(strm, mBuilder->getIntNTy(mBITBLOCK_WIDTH));
    479     Value* adv_longint = mBuilder->CreateOr(mBuilder->CreateShl(strm_longint, shift_amount), mBuilder->CreateLShr(advanceq_longint, mBITBLOCK_WIDTH - shift_amount), "advance");
    480     return mBuilder->CreateBitCast(adv_longint, mBitBlockType);
     477    Value* advanceq_longint = iBuilder->CreateBitCast(carry_in, iBuilder->getIntNTy(mBITBLOCK_WIDTH));
     478    Value* strm_longint = iBuilder->CreateBitCast(strm, iBuilder->getIntNTy(mBITBLOCK_WIDTH));
     479    Value* adv_longint = iBuilder->CreateOr(iBuilder->CreateShl(strm_longint, shift_amount), iBuilder->CreateLShr(advanceq_longint, mBITBLOCK_WIDTH - shift_amount), "advance");
     480    return iBuilder->CreateBitCast(adv_longint, mBitBlockType);
    481481}
    482482   
     
    502502Value * CarryManager::longAdvanceCarryInCarryOut(int localIndex, unsigned shift_amount, Value * carry_out) {
    503503    unsigned carryDataIndex = longAdvanceBitBlockPosition(localIndex);
    504     Value * advBaseIndex = mBuilder->getInt64(carryDataIndex);
     504    Value * advBaseIndex = iBuilder->getInt64(carryDataIndex);
    505505    if (shift_amount <= mBITBLOCK_WIDTH) {
    506506        // special case using a single buffer entry and the carry_out value.
    507         Value * advanceDataPtr = mBuilder->CreateGEP(mCarryBitBlockPtr, advBaseIndex);
    508         Value * carry_block0 = mBuilder->CreateAlignedLoad(advanceDataPtr, mBITBLOCK_WIDTH/8);
    509         mBuilder->CreateAlignedStore(carry_out, advanceDataPtr, mBITBLOCK_WIDTH/8);
     507        Value * advanceDataPtr = iBuilder->CreateGEP(mCarryBitBlockPtr, advBaseIndex);
     508        Value * carry_block0 = iBuilder->CreateAlignedLoad(advanceDataPtr, mBITBLOCK_WIDTH/8);
     509        iBuilder->CreateAlignedStore(carry_out, advanceDataPtr, mBITBLOCK_WIDTH/8);
    510510        /* Very special case - no combine */
    511511        if (shift_amount == mBITBLOCK_WIDTH) return carry_block0;
    512         Value* block0_shr = mBuilder->CreateLShr(mBuilder->CreateBitCast(carry_block0, mBuilder->getIntNTy(mBITBLOCK_WIDTH)), mBITBLOCK_WIDTH - shift_amount);
    513         Value* block1_shl = mBuilder->CreateShl(mBuilder->CreateBitCast(carry_out, mBuilder->getIntNTy(mBITBLOCK_WIDTH)), shift_amount);
    514         return mBuilder->CreateBitCast(mBuilder->CreateOr(block1_shl, block0_shr), mBitBlockType);
     512        Value* block0_shr = iBuilder->CreateLShr(iBuilder->CreateBitCast(carry_block0, iBuilder->getIntNTy(mBITBLOCK_WIDTH)), mBITBLOCK_WIDTH - shift_amount);
     513        Value* block1_shl = iBuilder->CreateShl(iBuilder->CreateBitCast(carry_out, iBuilder->getIntNTy(mBITBLOCK_WIDTH)), shift_amount);
     514        return iBuilder->CreateBitCast(iBuilder->CreateOr(block1_shl, block0_shr), mBitBlockType);
    515515    }
    516516    // We need a buffer of at least two elements for storing the advance data.
     
    518518    const unsigned advanceEntries = mCarryInfo->longAdvanceEntries(shift_amount);
    519519    const unsigned bufsize = mCarryInfo->longAdvanceBufferSize(shift_amount);
    520     Value * indexMask = mBuilder->getInt64(bufsize - 1);  // A mask to implement circular buffer indexing
    521     Value * loadIndex0 = mBuilder->CreateAdd(mBuilder->CreateAnd(mBuilder->CreateSub(mBlockNo, mBuilder->getInt64(advanceEntries)), indexMask), advBaseIndex);
    522     Value * storeIndex = mBuilder->CreateAdd(mBuilder->CreateAnd(mBlockNo, indexMask), advBaseIndex);
    523     Value * carry_block0 = mBuilder->CreateAlignedLoad(mBuilder->CreateGEP(mCarryBitBlockPtr, loadIndex0), mBITBLOCK_WIDTH/8);
     520    Value * indexMask = iBuilder->getInt64(bufsize - 1);  // A mask to implement circular buffer indexing
     521    Value * loadIndex0 = iBuilder->CreateAdd(iBuilder->CreateAnd(iBuilder->CreateSub(mBlockNo, iBuilder->getInt64(advanceEntries)), indexMask), advBaseIndex);
     522    Value * storeIndex = iBuilder->CreateAdd(iBuilder->CreateAnd(mBlockNo, indexMask), advBaseIndex);
     523    Value * carry_block0 = iBuilder->CreateAlignedLoad(iBuilder->CreateGEP(mCarryBitBlockPtr, loadIndex0), mBITBLOCK_WIDTH/8);
    524524    // If the long advance is an exact multiple of mBITBLOCK_WIDTH, we simply return the oldest
    525525    // block in the long advance carry data area. 
    526526    if (block_shift == 0) {
    527         mBuilder->CreateAlignedStore(carry_out, mBuilder->CreateGEP(mCarryBitBlockPtr, storeIndex), mBITBLOCK_WIDTH/8);
     527        iBuilder->CreateAlignedStore(carry_out, iBuilder->CreateGEP(mCarryBitBlockPtr, storeIndex), mBITBLOCK_WIDTH/8);
    528528        return carry_block0;
    529529    }
    530530    // Otherwise we need to combine data from the two oldest blocks.
    531     Value * loadIndex1 = mBuilder->CreateAdd(mBuilder->CreateAnd(mBuilder->CreateSub(mBlockNo, mBuilder->getInt64(advanceEntries-1)), indexMask), advBaseIndex);
    532     Value * carry_block1 = mBuilder->CreateAlignedLoad(mBuilder->CreateGEP(mCarryBitBlockPtr, loadIndex1), mBITBLOCK_WIDTH/8);
    533     Value* block0_shr = mBuilder->CreateLShr(mBuilder->CreateBitCast(carry_block0, mBuilder->getIntNTy(mBITBLOCK_WIDTH)), mBITBLOCK_WIDTH - block_shift);
    534     Value* block1_shl = mBuilder->CreateShl(mBuilder->CreateBitCast(carry_block1, mBuilder->getIntNTy(mBITBLOCK_WIDTH)), block_shift);
    535     mBuilder->CreateAlignedStore(carry_out, mBuilder->CreateGEP(mCarryBitBlockPtr, storeIndex), mBITBLOCK_WIDTH/8);
    536     return mBuilder->CreateBitCast(mBuilder->CreateOr(block1_shl, block0_shr), mBitBlockType);
     531    Value * loadIndex1 = iBuilder->CreateAdd(iBuilder->CreateAnd(iBuilder->CreateSub(mBlockNo, iBuilder->getInt64(advanceEntries-1)), indexMask), advBaseIndex);
     532    Value * carry_block1 = iBuilder->CreateAlignedLoad(iBuilder->CreateGEP(mCarryBitBlockPtr, loadIndex1), mBITBLOCK_WIDTH/8);
     533    Value* block0_shr = iBuilder->CreateLShr(iBuilder->CreateBitCast(carry_block0, iBuilder->getIntNTy(mBITBLOCK_WIDTH)), mBITBLOCK_WIDTH - block_shift);
     534    Value* block1_shl = iBuilder->CreateShl(iBuilder->CreateBitCast(carry_block1, iBuilder->getIntNTy(mBITBLOCK_WIDTH)), block_shift);
     535    iBuilder->CreateAlignedStore(carry_out, iBuilder->CreateGEP(mCarryBitBlockPtr, storeIndex), mBITBLOCK_WIDTH/8);
     536    return iBuilder->CreateBitCast(iBuilder->CreateOr(block1_shl, block0_shr), mBitBlockType);
    537537}
    538538   
     
    551551        if (mITEMS_PER_PACK > 1) {// #ifdef PACKING
    552552            Value * summary_bits = maskSelectBitRange(summary_pack, summaryPosition() % mPACK_SIZE, summaryBits());
    553             test_expr = iBuilder->simd_or(test_expr, mBuilder->CreateZExt(summary_bits, mBuilder->getIntNTy(mBITBLOCK_WIDTH)));
     553            test_expr = iBuilder->simd_or(test_expr, iBuilder->CreateZExt(summary_bits, iBuilder->getIntNTy(mBITBLOCK_WIDTH)));
    554554        }
    555555        else {
     
    577577        const unsigned currentScopeBase = scopeBasePack();
    578578        for (unsigned index = currentScopeBase; index < currentScopeBase + scopeCarryPacks; ++index) {
    579             PHINode * phi_out = mBuilder->CreatePHI(mCarryPackType, 2);
     579            PHINode * phi_out = iBuilder->CreatePHI(mCarryPackType, 2);
    580580            phi_out->addIncoming(Constant::getNullValue(mCarryPackType),ifEntryBlock);
    581581            phi_out->addIncoming(mCarryOutPack[index], ifBodyFinalBlock);
     
    592592        if (ifScopeCarrySize <= mPACK_SIZE) {
    593593            unsigned const ifPackIndex = scopeBasePack();
    594             PHINode * ifPack_phi = mBuilder->CreatePHI(mCarryPackType, 2, "ifPack");
     594            PHINode * ifPack_phi = iBuilder->CreatePHI(mCarryPackType, 2, "ifPack");
    595595            ifPack_phi->addIncoming(mCarryInfo->ifEntryPack, ifEntryBlock);
    596596            ifPack_phi->addIncoming(mCarryOutPack[ifPackIndex], ifBodyFinalBlock);
     
    603603        // its own summary.
    604604        const unsigned summaryIndex = summaryPackIndex();
    605         PHINode * summary_phi = mBuilder->CreatePHI(mCarryPackType, 2, "summary");
     605        PHINode * summary_phi = iBuilder->CreatePHI(mCarryPackType, 2, "summary");
    606606        summary_phi->addIncoming(Constant::getNullValue(mCarryPackType), ifEntryBlock);
    607607        summary_phi->addIncoming(mCarryOutPack[summaryIndex], ifBodyFinalBlock);
     
    617617    }
    618618    const unsigned carrySummaryIndex = summaryPackIndex();
    619     PHINode * summary_phi = mBuilder->CreatePHI(mCarryPackType, 2, "summary");
     619    PHINode * summary_phi = iBuilder->CreatePHI(mCarryPackType, 2, "summary");
    620620    summary_phi->addIncoming(Constant::getNullValue(mCarryPackType), ifEntryBlock);
    621621    summary_phi->addIncoming(mCarryOutPack[carrySummaryIndex], ifBodyFinalBlock);
     
    644644            carry_summary = mCarryOutPack[localCarryIndex];
    645645            for (unsigned i = 1; i < localCarryPacks; i++) {
    646                 carry_summary = mBuilder->CreateOr(carry_summary, mCarryOutPack[localCarryIndex+i]);
     646                carry_summary = iBuilder->CreateOr(carry_summary, mCarryOutPack[localCarryIndex+i]);
    647647            }
    648648        }
     
    652652                enterScope(inner_blk);
    653653                if (blockHasCarries()) {
    654                   carry_summary = mBuilder->CreateOr(carry_summary, mCarryOutPack[summaryPackIndex()]);
     654                  carry_summary = iBuilder->CreateOr(carry_summary, mCarryOutPack[summaryPackIndex()]);
    655655                }
    656656                leaveScope();
     
    660660                enterScope(inner_blk);
    661661                if (blockHasCarries()) {
    662                     carry_summary = mBuilder->CreateOr(carry_summary, mCarryOutPack[summaryPackIndex()]);
     662                    carry_summary = iBuilder->CreateOr(carry_summary, mCarryOutPack[summaryPackIndex()]);
    663663                }
    664664                leaveScope();
     
    692692    for (unsigned index = 0; index < scopeCarryPacks; ++index) {
    693693#ifdef SET_WHILE_CARRY_IN_TO_ZERO_AFTER_FIRST_ITERATION
    694         PHINode * phi_in = mBuilder->CreatePHI(mCarryPackType, 2);
     694        PHINode * phi_in = iBuilder->CreatePHI(mCarryPackType, 2);
    695695        phi_in->addIncoming(mCarryInPack[currentScopeBase+index], whileEntryBlock);
    696696        mCarryInPhis[index] = phi_in;
    697697#endif
    698         PHINode * phi_out = mBuilder->CreatePHI(mCarryPackType, 2);
     698        PHINode * phi_out = iBuilder->CreatePHI(mCarryPackType, 2);
    699699        phi_out->addIncoming(Constant::getNullValue(mCarryPackType), whileEntryBlock);
    700700        mCarryOutAccumPhis[index] = phi_out;
     
    711711#endif
    712712        PHINode * phi = mCarryOutAccumPhis[index];
    713         Value * carryOut = mBuilder->CreateOr(phi, mCarryOutPack[currentScopeBase+index]);
     713        Value * carryOut = iBuilder->CreateOr(phi, mCarryOutPack[currentScopeBase+index]);
    714714        phi->addIncoming(carryOut, whileBodyFinalBlock);
    715715        mCarryOutPack[currentScopeBase+index] = carryOut;
     
    748748
    749749Value * CarryManager::popCount(Value * to_count, unsigned globalIdx) {
    750     Value * countPtr = mBuilder->CreateGEP(mPopcountBasePtr, mBuilder->getInt64(globalIdx));
    751     Value * countSoFar = mBuilder->CreateAlignedLoad(countPtr, 8);
     750    Value * countPtr = iBuilder->CreateGEP(mPopcountBasePtr, iBuilder->getInt64(globalIdx));
     751    Value * countSoFar = iBuilder->CreateAlignedLoad(countPtr, 8);
    752752    Value * fieldCounts = iBuilder->simd_popcount(64, to_count);
    753753    for (int i = 0; i < mBITBLOCK_WIDTH/64; i++) {
    754         countSoFar = mBuilder->CreateAdd(countSoFar, iBuilder->mvmd_extract(64, fieldCounts, i));
    755     }
    756     mBuilder->CreateAlignedStore(countSoFar, countPtr, 8);
    757     return iBuilder->bitCast(mBuilder->CreateZExt(countSoFar, mBuilder->getIntNTy(mBITBLOCK_WIDTH)));
     754        countSoFar = iBuilder->CreateAdd(countSoFar, iBuilder->mvmd_extract(64, fieldCounts, i));
     755    }
     756    iBuilder->CreateAlignedStore(countSoFar, countPtr, 8);
     757    return iBuilder->bitCast(iBuilder->CreateZExt(countSoFar, iBuilder->getIntNTy(mBITBLOCK_WIDTH)));
    758758}
    759759
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.h

    r4897 r4898  
    4040public:
    4141 
    42     CarryManager(IRBuilder <> * b, IDISA::IDISA_Builder * idb)
    43     : mBuilder(b)
    44     , iBuilder(idb)
     42    CarryManager(IDISA::IDISA_Builder * idb)
     43    : iBuilder(idb)
    4544    , mBitBlockType(idb->getBitBlockType())
    4645    , mBITBLOCK_WIDTH(idb->getBitBlockWidth())
     
    120119   
    121120private:
    122     IRBuilder <> * mBuilder;
    123121    IDISA::IDISA_Builder * iBuilder;
    124122    Type * mBitBlockType;
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r4892 r4898  
    5858PabloCompiler::PabloCompiler(Type * bitBlockType)
    5959: mMod(nullptr)
    60 , mBuilder(nullptr)
    6160, mCarryManager(nullptr)
    6261, mBitBlockType(bitBlockType)
     
    110109    mMod = module;
    111110
    112     mBuilder = new IRBuilder<>(mMod->getContext());
    113 
    114111#if (BLOCK_SIZE == 256)
    115112    if ((strncmp(lGetSystemISA(), "avx2", 4) == 0)) {
    116         iBuilder = new IDISA::IDISA_AVX2_Builder(mBitBlockType);
     113        iBuilder = new IDISA::IDISA_AVX2_Builder(mMod, mBitBlockType);
    117114        //std::cerr << "IDISA_AVX2_Builder selected\n";
    118115    }
    119116    else{
    120         iBuilder = new IDISA::IDISA_Builder(mBitBlockType);
     117        iBuilder = new IDISA::IDISA_Builder(mMod, mBitBlockType);
    121118        //std::cerr << "Generic IDISA_Builder selected\n";
    122119    }
    123120#else   
    124     iBuilder = new IDISA::IDISA_Builder(mBitBlockType);
     121    iBuilder = new IDISA::IDISA_Builder(mMod, mBitBlockType);
    125122#endif
    126     iBuilder->initialize(mMod, mBuilder);
    127 
    128     mCarryManager = new CarryManager(mBuilder, iBuilder);
     123
     124    mCarryManager = new CarryManager(iBuilder);
    129125   
    130126    GenerateFunction(*function);
    131127   
    132     mBuilder->SetInsertPoint(BasicBlock::Create(mMod->getContext(), "entry", mFunction,0));
     128    iBuilder->SetInsertPoint(BasicBlock::Create(mMod->getContext(), "entry", mFunction,0));
    133129
    134130    //The basis bits structure
    135131    for (unsigned i = 0; i != function->getNumOfParameters(); ++i) {
    136         Value* indices[] = {mBuilder->getInt64(0), mBuilder->getInt32(i)};
    137         Value * gep = mBuilder->CreateGEP(mInputAddressPtr, indices);
    138         LoadInst * basisBit = mBuilder->CreateAlignedLoad(gep, iBuilder->getBitBlockWidth()/8, false, function->getParameter(i)->getName()->to_string());
     132        Value* indices[] = {iBuilder->getInt64(0), iBuilder->getInt32(i)};
     133        Value * gep = iBuilder->CreateGEP(mInputAddressPtr, indices);
     134        LoadInst * basisBit = iBuilder->CreateAlignedLoad(gep, iBuilder->getBitBlockWidth()/8, false, function->getParameter(i)->getName()->to_string());
    139135        mMarkerMap[function->getParameter(i)] = basisBit;
    140136        if (DumpTrace) {
     
    156152
    157153    if (DumpTrace) {
    158         iBuilder->genPrintRegister("mBlockNo", mBuilder->CreateAlignedLoad(mBuilder->CreateBitCast(mCarryManager->getBlockNoPtr(), PointerType::get(mBitBlockType, 0)), iBuilder->getBitBlockWidth()/8, false));
     154        iBuilder->genPrintRegister("mBlockNo", iBuilder->CreateAlignedLoad(iBuilder->CreateBitCast(mCarryManager->getBlockNoPtr(), PointerType::get(mBitBlockType, 0)), iBuilder->getBitBlockWidth()/8, false));
    159155    }
    160156   
     
    166162
    167163    //Terminate the block
    168     ReturnInst::Create(mMod->getContext(), mBuilder->GetInsertBlock());
     164    ReturnInst::Create(mMod->getContext(), iBuilder->GetInsertBlock());
    169165   
    170166    // Clean up
    171167    delete mCarryManager; mCarryManager = nullptr;
    172168    delete iBuilder; iBuilder = nullptr;
    173     delete mBuilder; mBuilder = nullptr;
     169    delete iBuilder; iBuilder = nullptr;
    174170    mMod = nullptr; // don't delete this. It's either owned by the ExecutionEngine or the calling function.
    175171
     
    253249    //
    254250
    255     BasicBlock * ifEntryBlock = mBuilder->GetInsertBlock();
     251    BasicBlock * ifEntryBlock = iBuilder->GetInsertBlock();
    256252    BasicBlock * ifBodyBlock = BasicBlock::Create(mMod->getContext(), "if.body", mFunction, 0);
    257253    BasicBlock * ifEndBlock = BasicBlock::Create(mMod->getContext(), "if.end", mFunction, 0);
     
    262258   
    263259    mCarryManager->enterScope(ifBody);
    264     mBuilder->CreateCondBr(mCarryManager->generateBitBlockOrSummaryTest(if_test_value), ifBodyBlock, ifEndBlock);
     260    iBuilder->CreateCondBr(mCarryManager->generateBitBlockOrSummaryTest(if_test_value), ifBodyBlock, ifEndBlock);
    265261   
    266262    // Entry processing is complete, now handle the body of the if.
    267     mBuilder->SetInsertPoint(ifBodyBlock);
     263    iBuilder->SetInsertPoint(ifBodyBlock);
    268264   
    269265    mCarryManager->initializeCarryDataAtIfEntry();
     
    272268        mCarryManager->generateCarryOutSummaryCodeIfNeeded();
    273269    }
    274     BasicBlock * ifBodyFinalBlock = mBuilder->GetInsertBlock();
     270    BasicBlock * ifBodyFinalBlock = iBuilder->GetInsertBlock();
    275271    mCarryManager->ensureCarriesStoredLocal();
    276     mBuilder->CreateBr(ifEndBlock);
     272    iBuilder->CreateBr(ifEndBlock);
    277273    //End Block
    278     mBuilder->SetInsertPoint(ifEndBlock);
     274    iBuilder->SetInsertPoint(ifEndBlock);
    279275    for (const PabloAST * node : ifStatement->getDefined()) {
    280276        const Assign * assign = cast<Assign>(node);
    281         PHINode * phi = mBuilder->CreatePHI(mBitBlockType, 2, assign->getName()->value());
     277        PHINode * phi = iBuilder->CreatePHI(mBitBlockType, 2, assign->getName()->value());
    282278        auto f = mMarkerMap.find(assign);
    283279        assert (f != mMarkerMap.end());
     
    295291    PabloBlock * const whileBody = whileStatement->getBody();
    296292   
    297     BasicBlock * whileEntryBlock = mBuilder->GetInsertBlock();
     293    BasicBlock * whileEntryBlock = iBuilder->GetInsertBlock();
    298294    BasicBlock * whileBodyBlock = BasicBlock::Create(mMod->getContext(), "while.body", mFunction, 0);
    299295    BasicBlock * whileEndBlock = BasicBlock::Create(mMod->getContext(), "while.end", mFunction, 0);
     
    310306    // the loop.
    311307
    312     mBuilder->CreateBr(whileBodyBlock);
    313     mBuilder->SetInsertPoint(whileBodyBlock);
     308    iBuilder->CreateBr(whileBodyBlock);
     309    iBuilder->SetInsertPoint(whileBodyBlock);
    314310
    315311    //
     
    323319    // for any Next nodes in the loop body, initialize to (a) pre-loop value.
    324320    for (const Next * n : nextNodes) {
    325         PHINode * phi = mBuilder->CreatePHI(mBitBlockType, 2, n->getName()->value());
     321        PHINode * phi = iBuilder->CreatePHI(mBitBlockType, 2, n->getName()->value());
    326322        auto f = mMarkerMap.find(n->getInitial());
    327323        assert (f != mMarkerMap.end());
     
    337333    compileBlock(whileBody);
    338334
    339     BasicBlock * whileBodyFinalBlock = mBuilder->GetInsertBlock();
     335    BasicBlock * whileBodyFinalBlock = iBuilder->GetInsertBlock();
    340336
    341337    if (mCarryManager->blockHasCarries()) {
     
    345341
    346342    // Terminate the while loop body with a conditional branch back.
    347     mBuilder->CreateCondBr(iBuilder->bitblock_any(compileExpression(whileStatement->getCondition())), whileBodyBlock, whileEndBlock);
     343    iBuilder->CreateCondBr(iBuilder->bitblock_any(compileExpression(whileStatement->getCondition())), whileBodyBlock, whileEndBlock);
    348344
    349345    // and for any Next nodes in the loop body
     
    357353    }
    358354
    359     mBuilder->SetInsertPoint(whileEndBlock);
     355    iBuilder->SetInsertPoint(whileEndBlock);
    360356    --mWhileDepth;
    361357
     
    407403
    408404
    409         AllocaInst * outputStruct = mBuilder->CreateAlloca(outputType);
    410         mBuilder->CreateCall2(externalFunction, mInputAddressPtr, outputStruct);
    411         Value * outputPtr = mBuilder->CreateGEP(outputStruct, std::vector<Value *>({ mBuilder->getInt32(0), mBuilder->getInt32(0) }));
    412         expr = mBuilder->CreateAlignedLoad(outputPtr, iBuilder->getBitBlockWidth() / 8, false);
     405        AllocaInst * outputStruct = iBuilder->CreateAlloca(outputType);
     406        iBuilder->CreateCall2(externalFunction, mInputAddressPtr, outputStruct);
     407        Value * outputPtr = iBuilder->CreateGEP(outputStruct, std::vector<Value *>({ iBuilder->getInt32(0), iBuilder->getInt32(0) }));
     408        expr = iBuilder->CreateAlignedLoad(outputPtr, iBuilder->getBitBlockWidth() / 8, false);
    413409    }
    414410    else if (const And * pablo_and = dyn_cast<And>(stmt)) {
     
    510506    }
    511507    if (LLVM_UNLIKELY(marker->getType()->isPointerTy())) {
    512         marker = mBuilder->CreateAlignedLoad(marker, iBuilder->getBitBlockWidth()/8, false);
    513     }
    514     Value* indices[] = {mBuilder->getInt64(0), mBuilder->getInt32(index)};
    515     Value* gep = mBuilder->CreateGEP(mOutputAddressPtr, indices);
     508        marker = iBuilder->CreateAlignedLoad(marker, iBuilder->getBitBlockWidth()/8, false);
     509    }
     510    Value* indices[] = {iBuilder->getInt64(0), iBuilder->getInt32(index)};
     511    Value* gep = iBuilder->CreateGEP(mOutputAddressPtr, indices);
    516512    if (marker->getType() != mBitBlockType) {
    517         marker = mBuilder->CreateBitCast(marker, mBitBlockType);
    518     }
    519     mBuilder->CreateAlignedStore(marker, gep, iBuilder->getBitBlockWidth()/8, false);
    520 }
    521 
    522 }
     513        marker = iBuilder->CreateBitCast(marker, mBitBlockType);
     514    }
     515    iBuilder->CreateAlignedStore(marker, gep, iBuilder->getBitBlockWidth()/8, false);
     516}
     517
     518}
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.h

    r4892 r4898  
    9898
    9999    Module *                            mMod;
    100     IRBuilder <> *                      mBuilder;
    101100
    102101    CarryManager *                      mCarryManager;
Note: See TracChangeset for help on using the changeset viewer.