Changeset 4931 for icGREP/icgrep-devel


Ignore:
Timestamp:
Feb 18, 2016, 3:57:20 PM (4 years ago)
Author:
lindanl
Message:

Add final block processing.

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

Legend:

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

    r4929 r4931  
    2626}
    2727
    28 void PipelineBuilder::CreateKernels(re::RE * re_ast){
     28void PipelineBuilder::CreateKernels(pablo::PabloFunction * function){
    2929    mS2PKernel = new KernelBuilder("s2p", mMod, iBuilder);
    3030    mICgrepKernel = new KernelBuilder("icgrep", mMod, iBuilder);
     
    3434    generateS2PKernel(mMod, iBuilder, mS2PKernel);
    3535    generateScanMatch(mMod, iBuilder, 64, mScanMatchKernel);
    36 
    37     Encoding encoding(Encoding::Type::UTF_8, 8);
    38     re_ast = regular_expression_passes(encoding, re_ast);
    39    
    40     pablo::PabloFunction * function = re2pablo_compiler(encoding, re_ast);
    4136
    4237    pablo_function_passes(function);
     
    6257    Type * inputType = PointerType::get(ArrayType::get(StructType::get(mMod->getContext(), std::vector<Type *>({ArrayType::get(mBitBlockType, 8)})), 1), 0);
    6358 
    64     Constant* c = mMod->getOrInsertFunction("Main", Type::getVoidTy(mMod->getContext()), inputType, T, S, NULL);
     59    Constant* c = mMod->getOrInsertFunction("Main", Type::getVoidTy(mMod->getContext()), inputType, T, S, T, NULL);
    6560    Function* mMainFunction = cast<Function>(c);
    6661    mMainFunction->setCallingConv(CallingConv::C);
     
    7368    buffersize_param->setName("buffersize");   
    7469    Value* filename_param = args++;
    75     filename_param->setName("filename");
     70    filename_param->setName("filename");     
     71    Value* finalLineUnterminated_param = args++;
     72    finalLineUnterminated_param->setName("finalLineUnterminated");
    7673
    7774    iBuilder->SetInsertPoint(BasicBlock::Create(mMod->getContext(), "entry", mMainFunction,0));
     
    8178    BasicBlock * pipeline_test_block = BasicBlock::Create(mMod->getContext(), "pipeline_test_block", mMainFunction, 0);
    8279    BasicBlock * pipeline_do_block = BasicBlock::Create(mMod->getContext(), "pipeline_do_block", mMainFunction, 0);
     80    BasicBlock * pipeline_final_block = BasicBlock::Create(mMod->getContext(), "pipeline_final_block", mMainFunction, 0);
    8381    BasicBlock * pipeline_partial_block = BasicBlock::Create(mMod->getContext(), "pipeline_partial_block", mMainFunction, 0);
     82    BasicBlock * pipeline_empty_block = BasicBlock::Create(mMod->getContext(), "pipeline_empty_block", mMainFunction, 0);
     83    BasicBlock * pipeline_end_block = BasicBlock::Create(mMod->getContext(), "pipeline_end_block", mMainFunction, 0);   
     84    BasicBlock * pipeline_Unterminated_block = BasicBlock::Create(mMod->getContext(), "pipeline_Unterminated_block", mMainFunction, 0);
     85    BasicBlock * pipeline_return_block = BasicBlock::Create(mMod->getContext(), "pipeline_return_block", mMainFunction, 0);
    8486
    8587    Value * s2pKernelStruct = mS2PKernel->generateKernelInstance();
    8688    Value * icGrepKernelStruct = mICgrepKernel->generateKernelInstance();
    8789    Value * scanMatchKernelStruct = mScanMatchKernel->generateKernelInstance();
     90
     91    Value * gep = iBuilder->CreateGEP(scanMatchKernelStruct, {iBuilder->getInt32(0), iBuilder->getInt32(0), iBuilder->getInt32(7)});
     92    Value* filebuf = iBuilder->CreateBitCast(input_param, S);
     93    iBuilder->CreateStore(filebuf, gep);
     94    gep = iBuilder->CreateGEP(scanMatchKernelStruct, {iBuilder->getInt32(0), iBuilder->getInt32(0), iBuilder->getInt32(8)});
     95    iBuilder->CreateStore(buffersize_param, gep);
     96    gep = iBuilder->CreateGEP(scanMatchKernelStruct, {iBuilder->getInt32(0), iBuilder->getInt32(0), iBuilder->getInt32(9)});
     97    iBuilder->CreateStore(filename_param, gep);
     98
     99    Value * basis_bits = iBuilder->CreateGEP(s2pKernelStruct, {iBuilder->getInt32(0), iBuilder->getInt32(1)});
     100    Value * results = iBuilder->CreateGEP(icGrepKernelStruct, {iBuilder->getInt32(0), iBuilder->getInt32(1)});
     101 
    88102    iBuilder->CreateBr(pipeline_test_block);
    89103
     
    93107    remaining_phi->addIncoming(buffersize_param, entry_block);
    94108    blkNo_phi->addIncoming(iBuilder->getInt64(0), entry_block);
    95     Value * cond = iBuilder->CreateICmpSLT(remaining_phi, ConstantInt::get(T, mBlockSize));
    96     iBuilder->CreateCondBr(cond, pipeline_partial_block, pipeline_do_block);
    97109
     110    Value * final_block_cond = iBuilder->CreateICmpSLT(remaining_phi, ConstantInt::get(T, mBlockSize));
     111    iBuilder->CreateCondBr(final_block_cond, pipeline_final_block, pipeline_do_block);
    98112
    99113    iBuilder->SetInsertPoint(pipeline_do_block);
    100114
    101     Value * gep = iBuilder->CreateGEP(input_param, {blkNo_phi});
    102     mS2PKernel->generateDoBlockCall(gep);
     115    gep = iBuilder->CreateGEP(input_param, {blkNo_phi});
    103116    Value * update_blkNo = iBuilder->CreateAdd(blkNo_phi, iBuilder->getInt64(1));
    104117    blkNo_phi->addIncoming(update_blkNo, pipeline_do_block);
    105118
    106     Value * basis_bits = iBuilder->CreateGEP(s2pKernelStruct, {iBuilder->getInt32(0), iBuilder->getInt32(1)});
     119    mS2PKernel->generateDoBlockCall(gep);
    107120    mICgrepKernel->generateDoBlockCall(basis_bits);
    108 
    109     gep = iBuilder->CreateGEP(scanMatchKernelStruct, {iBuilder->getInt64(0), iBuilder->getInt32(0), iBuilder->getInt32(7)});
    110     Value* filebuf = iBuilder->CreateBitCast(input_param, S);
    111     iBuilder->CreateStore(filebuf, gep);
    112     gep = iBuilder->CreateGEP(scanMatchKernelStruct, {iBuilder->getInt64(0), iBuilder->getInt32(0), iBuilder->getInt32(8)});
    113     iBuilder->CreateStore(buffersize_param, gep);
    114     gep = iBuilder->CreateGEP(scanMatchKernelStruct, {iBuilder->getInt64(0), iBuilder->getInt32(0), iBuilder->getInt32(9)});
    115     iBuilder->CreateStore(filename_param, gep);
    116 
    117     Value * results = iBuilder->CreateGEP(icGrepKernelStruct, {iBuilder->getInt32(0), iBuilder->getInt32(1)});
    118121    mScanMatchKernel->generateDoBlockCall(results);
    119122
    120     Value * update_remaining = iBuilder->CreateSub(remaining_phi, iBuilder->getInt64(iBuilder->getBitBlockWidth()));
     123    Value * update_remaining = iBuilder->CreateSub(remaining_phi, iBuilder->getInt64(mBlockSize));
    121124    remaining_phi->addIncoming(update_remaining, pipeline_do_block);
    122125    iBuilder->CreateBr(pipeline_test_block);
    123126
     127    iBuilder->SetInsertPoint(pipeline_final_block);
     128
     129    Value * empty_block_cond = iBuilder->CreateICmpEQ(remaining_phi, ConstantInt::get(T, 0));
     130    iBuilder->CreateCondBr(empty_block_cond, pipeline_empty_block, pipeline_partial_block);
     131
    124132    iBuilder->SetInsertPoint(pipeline_partial_block);
     133
     134    gep = iBuilder->CreateGEP(input_param, {blkNo_phi});
     135    mS2PKernel->generateDoBlockCall(gep);
     136    iBuilder->CreateBr(pipeline_end_block);
     137
     138    iBuilder->SetInsertPoint(pipeline_empty_block);
     139
     140    iBuilder->CreateMemSet(basis_bits, iBuilder->getInt8(0), mBlockSize, 4);
     141    iBuilder->CreateBr(pipeline_end_block);
     142
     143    iBuilder->SetInsertPoint(pipeline_end_block);
     144
     145    Value * return_block_cond = iBuilder->CreateICmpNE(finalLineUnterminated_param, ConstantInt::get(T, 0));
     146    iBuilder->CreateCondBr(return_block_cond, pipeline_return_block, pipeline_Unterminated_block);
     147   
     148    iBuilder->SetInsertPoint(pipeline_Unterminated_block);
     149
     150    Value * remaining = iBuilder->CreateBitCast(remaining_phi, iBuilder->getIntNTy(128));
     151    Value * EOF_mask = iBuilder->CreateShl(ConstantInt::get(iBuilder->getIntNTy(128), 1), remaining);
     152    EOF_mask = iBuilder->CreateSub(EOF_mask, ConstantInt::get(iBuilder->getIntNTy(128), 1));
     153
     154    Value * EOF_pos = iBuilder->CreateNeg(iBuilder->CreateOr(iBuilder->CreateShl(iBuilder->CreateNeg(EOF_mask), 1), EOF_mask));
     155    EOF_pos = iBuilder->CreateBitCast(EOF_pos, mBitBlockType);
     156
     157    Value * gep_bits4 = iBuilder->CreateGEP(basis_bits, {iBuilder->getInt32(0), iBuilder->getInt32(0), iBuilder->getInt32(4)});
     158    Value * bits4 = iBuilder->CreateAlignedLoad(gep_bits4, mBlockSize/8, false, "bits4");
     159    bits4 = iBuilder->CreateOr(bits4, EOF_pos);
     160    iBuilder->CreateAlignedStore(bits4, gep_bits4, mBlockSize/8, false);
     161
     162    Value * gep_bits6 = iBuilder->CreateGEP(basis_bits, {iBuilder->getInt32(0), iBuilder->getInt32(0), iBuilder->getInt32(6)});
     163    Value * bits6 = iBuilder->CreateAlignedLoad(gep_bits6, mBlockSize/8, false, "bits6");
     164    bits6 = iBuilder->CreateOr(bits6, EOF_pos);
     165    iBuilder->CreateAlignedStore(bits6, gep_bits6, mBlockSize/8, false);
     166    iBuilder->CreateBr(pipeline_return_block);
     167
     168    iBuilder->SetInsertPoint(pipeline_return_block);
     169
     170    mICgrepKernel->generateDoBlockCall(basis_bits);
     171    mScanMatchKernel->generateDoBlockCall(results);
    125172    iBuilder->CreateRetVoid();
    126173
  • icGREP/icgrep-devel/icgrep/kernels/pipeline.h

    r4929 r4931  
    2525}
    2626
    27 namespace re { class RE; }
     27namespace pablo { class PabloFunction; }
    2828
    2929using namespace llvm;
     
    3434        ~PipelineBuilder();
    3535
    36         void CreateKernels(re::RE * re_ast);
     36        void CreateKernels(pablo::PabloFunction * function);
    3737    void ExecuteKernels();
    3838
Note: See TracChangeset for help on using the changeset viewer.