Ignore:
Timestamp:
May 10, 2016, 12:12:41 AM (3 years ago)
Author:
nmedfort
Message:

UnicodeSet? bug fix and compile warning clean-up.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/kernels/pipeline.cpp

    r5035 r5037  
    5757}
    5858
    59 Value * generatePopcount(IDISA::IDISA_Builder * iBuilder, Value * bits) {
     59inline Value * generatePopcount(IDISA::IDISA_Builder * iBuilder, Value * bits) {
    6060    Value * ctpopFunc = Intrinsic::getDeclaration(iBuilder->getModule(), Intrinsic::ctpop, bits->getType());
    61     return iBuilder->CreateCall(ctpopFunc, std::vector<Value *>({bits}));
    62 }
    63 
    64 Value * Cal_Count(Instance * icGrepInstance, IDISA::IDISA_Builder * iBuilder, int mBlockSize) {
    65     const unsigned index = 0;
    66     const unsigned streamOffset = 0;
    67     Value * match = (icGrepInstance->getOutputStream(index, streamOffset));
    68     Value * temp = iBuilder->CreateLoad(match);
    69     Value * matches = iBuilder->CreateBitCast(temp, iBuilder->getIntNTy(mBlockSize));
    70     Value * popcount = generatePopcount(iBuilder, matches);
    71     return popcount;
     61    return iBuilder->CreateCall(ctpopFunc, {bits});
     62}
     63
     64inline Value * Cal_Count(Instance * icGrepInstance, IDISA::IDISA_Builder * iBuilder) {
     65    Value * match = icGrepInstance->getOutputStream(0, 0);
     66    Value * matches = iBuilder->CreateLoad(match, false, "match");
     67    return generatePopcount(iBuilder, matches);
    7268}
    7369
     
    7672    Type * const int8PtrTy = iBuilder->getInt8PtrTy();
    7773    Type * const inputType = PointerType::get(ArrayType::get(StructType::get(mMod->getContext(), std::vector<Type *>({ArrayType::get(mBitBlockType, 8)})), 1), 0);
    78 
    79     Function * const main = cast<Function>(mMod->getOrInsertFunction("Main", Type::getVoidTy(mMod->getContext()), inputType, int64ty, int64ty, iBuilder->getInt1Ty(), nullptr));
     74    Type * const resultTy = CountOnly ? int64ty : iBuilder->getVoidTy();
     75    Function * const main = cast<Function>(mMod->getOrInsertFunction("Main", resultTy, inputType, int64ty, int64ty, iBuilder->getInt1Ty(), nullptr));
    8076    main->setCallingConv(CallingConv::C);
    8177    Function::arg_iterator args = main->arg_begin();
     
    110106    BasicBlock * exitBlock = BasicBlock::Create(mMod->getContext(), "exit", main, 0);
    111107
    112     Value * count = iBuilder->CreateAlloca (Type::getIntNTy(mMod->getContext(), mBlockSize), nullptr, "count");
    113     Value * num = ConstantInt::get(iBuilder->getIntNTy(mBlockSize), 0);
    114     iBuilder->CreateStore(num, count, false);
     108    Value * count = nullptr;
     109    if (CountOnly) {
     110        count = iBuilder->CreateAlloca(mBitBlockType, nullptr, "count");
     111        iBuilder->CreateStore(ConstantInt::getNullValue(mBitBlockType), count);
     112    }
    115113
    116114    Instance * s2pInstance = mS2PKernel->instantiate(inputStream);
    117115    Instance * icGrepInstance = mICgrepKernel->instantiate(s2pInstance->getOutputStreamBuffer());
    118     Instance * scanMatchInstance = mScanMatchKernel->instantiate(icGrepInstance->getOutputStreamBuffer());
     116    Instance * scanMatchInstance = nullptr;
    119117   
    120     if(!CountOnly) {
    121         scanMatchInstance->setInternalState("FileBuf", iBuilder->CreateBitCast(inputStream, int8PtrTy));
    122         scanMatchInstance->setInternalState("FileSize", bufferSize);
    123         scanMatchInstance->setInternalState("FileIdx", fileIdx);
     118    if (!CountOnly) {
     119        scanMatchInstance = mScanMatchKernel->instantiate(icGrepInstance->getOutputStreamBuffer());
     120        scanMatchInstance->setInternalState("FileBuf", iBuilder->CreateBitCast(inputStream, int8PtrTy));
     121        scanMatchInstance->setInternalState("FileSize", bufferSize);
     122        scanMatchInstance->setInternalState("FileIdx", fileIdx);
    124123    }
    125124    Value * initialBufferSize = nullptr;
     
    140139        for (unsigned i = 0; i < segmentSize; ++i) {
    141140            icGrepInstance->CreateDoBlockCall();
    142             if(CountOnly){
    143                 Value * popcount_for = Cal_Count(icGrepInstance, iBuilder, mBlockSize);
    144                 Value * temp_countfor = iBuilder->CreateLoad(count);
    145                 Value * add_for = iBuilder->CreateAdd(temp_countfor, popcount_for);
    146                 iBuilder->CreateStore(add_for, count);
    147             }
    148         }
    149         if(!CountOnly) {
    150             for (unsigned i = 0; i < segmentSize; ++i) {
    151                 scanMatchInstance->CreateDoBlockCall();
    152             }
    153         }
     141            if (CountOnly) {
     142                Value * popcount_for = Cal_Count(icGrepInstance, iBuilder);
     143                Value * temp_countfor = iBuilder->CreateLoad(count);
     144                Value * add_for = iBuilder->CreateAdd(temp_countfor, popcount_for);
     145                iBuilder->CreateStore(add_for, count);
     146            }
     147        }
     148        if (!CountOnly) {
     149            for (unsigned i = 0; i < segmentSize; ++i) {
     150                scanMatchInstance->CreateDoBlockCall();
     151            }
     152        }
    154153        remainingBytes->addIncoming(iBuilder->CreateSub(remainingBytes, step), segmentBodyBlock);
    155154        iBuilder->CreateBr(segmentCondBlock);
     
    173172    s2pInstance->CreateDoBlockCall();
    174173    icGrepInstance->CreateDoBlockCall();
    175     if(CountOnly){
    176         Value * popcount = Cal_Count(icGrepInstance, iBuilder, mBlockSize);   
    177         Value * temp_count = iBuilder->CreateLoad(count);
    178         Value * add = iBuilder->CreateAdd(temp_count, popcount);
    179         iBuilder->CreateStore(add, count);
    180     }
    181 
    182     if(!CountOnly) {
    183         scanMatchInstance->CreateDoBlockCall();
     174    if (CountOnly) {
     175        Value * popcount = Cal_Count(icGrepInstance, iBuilder);
     176        Value * temp_count = iBuilder->CreateLoad(count);
     177        Value * add = iBuilder->CreateAdd(temp_count, popcount);
     178        iBuilder->CreateStore(add, count);
     179    } else {
     180        scanMatchInstance->CreateDoBlockCall();
    184181    }
    185182
     
    228225
    229226    icGrepInstance->CreateDoBlockCall();
    230     if(CountOnly){
    231         Value * popcount1 = Cal_Count(icGrepInstance, iBuilder, mBlockSize);   
    232         Value * temp_count1 = iBuilder->CreateLoad(count);
    233         Value * add1 = iBuilder->CreateAdd(temp_count1, popcount1);
    234         iBuilder->CreateStore(add1, count);
    235     }
    236     if(!CountOnly) {
    237         scanMatchInstance->CreateDoBlockCall();
    238     }
    239     if(CountOnly){
    240         Value * Ret = iBuilder->CreateLoad(count);
    241         iBuilder->CreateRet(Ret);
    242     }
    243     else{
    244         iBuilder->CreateRetVoid();
    245     }
    246 
    247 
     227    if (CountOnly) {
     228        Value * popcount1 = Cal_Count(icGrepInstance, iBuilder);
     229        Value * temp_count1 = iBuilder->CreateLoad(count);
     230        Value * result = iBuilder->CreateAdd(temp_count1, popcount1);
     231        for (unsigned width = (mBlockSize / 64); width > 1; width /= 2) {
     232            std::vector<Constant *> mask(width / 2);
     233            for (unsigned i = 0; i < (width / 2); ++i) {
     234                mask[i] = iBuilder->getInt32(i);
     235            }
     236            Value * const undef = UndefValue::get(VectorType::get(int64ty, width));
     237            Value * const lh = iBuilder->CreateShuffleVector(result, undef, ConstantVector::get(mask));
     238            for (unsigned i = 0; i < (width / 2); ++i) {
     239                mask[i] = iBuilder->getInt32(i + (width / 2));
     240            }
     241            Value * const rh = iBuilder->CreateShuffleVector(result, undef, ConstantVector::get(mask));
     242            result = iBuilder->CreateAdd(lh, rh);
     243        }
     244        iBuilder->CreateRet(iBuilder->CreateExtractElement(result, iBuilder->getInt32(0)));
     245    } else {
     246        scanMatchInstance->CreateDoBlockCall();
     247        iBuilder->CreateRetVoid();
     248    }
    248249    return main;
    249250}
Note: See TracChangeset for help on using the changeset viewer.