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

UnicodeSet? bug fix and compile warning clean-up.

Location:
icGREP/icgrep-devel/icgrep/kernels
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/kernels/instance.h

    r5010 r5037  
    4949    }
    5050
    51     llvm::Value * getInputStream(llvm::Value * const index, const unsigned streamOffset = 0) {
     51    llvm::Value * getInputStream(disable_implicit_conversion<llvm::Value *> index, const unsigned streamOffset = 0) {
    5252        return mDefinition->getInputStreamInternal(getInputStreamSet(streamOffset), index);
    5353    }
     
    6161    }
    6262
    63     llvm::Value * getInputScalar(llvm::Value * const index) {
     63    llvm::Value * getInputScalar(disable_implicit_conversion<llvm::Value *> index) {
    6464        return mDefinition->getInputScalarInternal(mInputScalarSet, index);
    6565    }
     
    7979    }
    8080
    81     llvm::Value * getOutputStream(llvm::Value * const index, const unsigned streamOffset = 0) {
     81    llvm::Value * getOutputStream(disable_implicit_conversion<llvm::Value *> index, const unsigned streamOffset = 0) {
    8282        return mDefinition->getOutputStreamInternal(getOutputStreamSet(streamOffset), index);
    8383    }
     
    8989    }
    9090
    91     llvm::Value * getOutputScalar(llvm::Value * const index) {
     91    llvm::Value * getOutputScalar(disable_implicit_conversion<llvm::Value *> index) {
    9292        return mDefinition->getOutputScalarInternal(mOutputScalarSet, index);
    9393    }
  • icGREP/icgrep-devel/icgrep/kernels/kernel.cpp

    r5014 r5037  
    100100
    101101void KernelBuilder::addInputStream(const unsigned fields) {
    102     addInputStream(fields, std::move(mKernelName + "_InputStream_" + std::to_string(mInputStream.size())));
     102    addInputStream(fields, mKernelName + "_InputStream_" + std::to_string(mInputStream.size()));
    103103}
    104104
     
    126126
    127127void KernelBuilder::addInputScalar(Type * const type) {
    128     addInputScalar(type, std::move(mKernelName + "_InputScalar_" + std::to_string(mInputScalar.size())));
     128    addInputScalar(type, mKernelName + "_InputScalar_" + std::to_string(mInputScalar.size()));
    129129}
    130130
  • icGREP/icgrep-devel/icgrep/kernels/kernel.h

    r5008 r5037  
    2929}
    3030
     31template<typename T>
     32struct disable_implicit_conversion {
     33    inline disable_implicit_conversion(T const value) : _value(value) { assert(_value); }
     34    inline disable_implicit_conversion(std::nullptr_t) = delete;
     35    inline disable_implicit_conversion(unsigned) = delete;
     36    operator T() const { return _value; }
     37    T operator-> () const { return _value; }
     38    T get() const { return _value; }
     39private:
     40    T const  _value;
     41};
     42
    3143namespace kernel {
    3244
     
    4153
    4254    KernelBuilder(IDISA::IDISA_Builder * builder, std::string && name, const unsigned defaultBufferSize);
    43 
    44     template<typename T>
    45     struct disable_implicit_conversion {
    46         inline disable_implicit_conversion(T const value) : _value(value) { assert(_value); }
    47         inline disable_implicit_conversion(std::nullptr_t) = delete;
    48         inline disable_implicit_conversion(unsigned) = delete;
    49         operator T() const { return _value; }
    50         T operator-> () const { return _value; }
    51         T get() const { return _value; }
    52     private:
    53         T const  _value;
    54     };
    5555
    5656    unsigned addInternalState(llvm::Type * const type);
  • 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}
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.cpp

    r5017 r5037  
    237237        Value * matchWord = iBuilder->CreateExtractElement(matchWordVector, ConstantInt::get(T, i));
    238238        Value * recordBreaksWord = iBuilder->CreateExtractElement(breakWordVector, ConstantInt::get(T, i));
    239         Value * wordResult = wordResult = iBuilder->CreateCall(scanWordFunction, std::vector<Value *>({kernelStuctParam, matchWord, recordBreaksWord, scanwordPos, recordStart, recordNum}));
     239        Value * wordResult = iBuilder->CreateCall(scanWordFunction, {kernelStuctParam, matchWord, recordBreaksWord, scanwordPos, recordStart, recordNum});
    240240        scanwordPos = iBuilder->CreateAdd(scanwordPos, ConstantInt::get(T, scanWordBitWidth));
    241241        recordStart = iBuilder->CreateExtractValue(wordResult, std::vector<unsigned>({0}));
  • icGREP/icgrep-devel/icgrep/kernels/symboltablepipeline.cpp

    r5014 r5037  
    444444
    445445        AllocaInst * const buffer = iBuilder->CreateAlloca(gatherVectorType, iBuilder->getInt32(maxCount * 4), "buffer");
    446         Value * end = iBuilder->CreateGEP(buffer, {iBuilder->getInt32(maxCount * 4)});
     446        Value * end = iBuilder->CreateGEP(buffer, iBuilder->getInt32(maxCount * 4));
    447447        Value * size = iBuilder->CreateSub(iBuilder->CreatePtrToInt(end, iBuilder->getInt64Ty()), iBuilder->CreatePtrToInt(buffer, iBuilder->getInt64Ty()));
    448448        iBuilder->CreateMemSet(buffer, iBuilder->getInt8(0), size, 4);
Note: See TracChangeset for help on using the changeset viewer.