Ignore:
Timestamp:
May 10, 2017, 4:26:11 PM (2 years ago)
Author:
nmedfort
Message:

Large refactoring step. Removed IR generation code from Kernel (formally KernelBuilder?) and moved it into the new KernelBuilder? class.

File:
1 edited

Legend:

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

    r5436 r5440  
    3939// a continous buffer for the full segment (number of blocks).
    4040
    41 void expand3_4Kernel::generateDoSegmentMethod() {
     41void expand3_4Kernel::generateDoSegmentMethod(const std::unique_ptr<KernelBuilder> & iBuilder) {
    4242
    4343    BasicBlock * expand2_3entry = iBuilder->GetInsertBlock();
    44     BasicBlock * expand_3_4_loop = CreateBasicBlock("expand_3_4_loop");
    45     BasicBlock * expand3_4_loop_exit = CreateBasicBlock("expand3_4_loop_exit");
    46     BasicBlock * finalStep1 = CreateBasicBlock("finalStep1");
    47     BasicBlock * finalStep2 = CreateBasicBlock("finalStep2");
    48     BasicBlock * step2load = CreateBasicBlock("step2load");
    49     BasicBlock * step2store = CreateBasicBlock("step2store");
    50     BasicBlock * finalStep3 = CreateBasicBlock("finalStep3");
    51     BasicBlock * step3load = CreateBasicBlock("step3load");
    52     BasicBlock * step3store = CreateBasicBlock("step3store");
    53     BasicBlock * step3store2 = CreateBasicBlock("step3store2");
    54     BasicBlock * itemsDone = CreateBasicBlock("itemsDone");
    55     BasicBlock * expand3_4_final = CreateBasicBlock("expand3_4_final");
    56     BasicBlock * expand3_4_exit = CreateBasicBlock("expand3_4_exit");
     44    BasicBlock * expand_3_4_loop = iBuilder->CreateBasicBlock("expand_3_4_loop");
     45    BasicBlock * expand3_4_loop_exit = iBuilder->CreateBasicBlock("expand3_4_loop_exit");
     46    BasicBlock * finalStep1 = iBuilder->CreateBasicBlock("finalStep1");
     47    BasicBlock * finalStep2 = iBuilder->CreateBasicBlock("finalStep2");
     48    BasicBlock * step2load = iBuilder->CreateBasicBlock("step2load");
     49    BasicBlock * step2store = iBuilder->CreateBasicBlock("step2store");
     50    BasicBlock * finalStep3 = iBuilder->CreateBasicBlock("finalStep3");
     51    BasicBlock * step3load = iBuilder->CreateBasicBlock("step3load");
     52    BasicBlock * step3store = iBuilder->CreateBasicBlock("step3store");
     53    BasicBlock * step3store2 = iBuilder->CreateBasicBlock("step3store2");
     54    BasicBlock * itemsDone = iBuilder->CreateBasicBlock("itemsDone");
     55    BasicBlock * expand3_4_final = iBuilder->CreateBasicBlock("expand3_4_final");
     56    BasicBlock * expand3_4_exit = iBuilder->CreateBasicBlock("expand3_4_exit");
    5757   
    5858    // Determine the require shufflevector constants.
     
    8484    const unsigned packAlign = iBuilder->getBitBlockWidth()/8;
    8585
    86     Value * processed = getProcessedItemCount("sourceStream");
    87     Value * available = getAvailableItemCount("sourceStream");
     86    Value * processed = iBuilder->getProcessedItemCount("sourceStream");
     87    Value * available = iBuilder->getAvailableItemCount("sourceStream");
    8888    Value * itemsAvail = iBuilder->CreateSub(available, processed);
    8989   
     
    9898
    9999    // A block is made up of 8 packs.  Get the pointer to the first pack (changes the type of the pointer only).
    100     Value * sourcePackPtr = getInputStreamPackPtr("sourceStream", iBuilder->getInt32(0), iBuilder->getInt32(0));
    101     Value * outputPackPtr = getOutputStreamPackPtr("expandedStream", iBuilder->getInt32(0), iBuilder->getInt32(0));
     100    Value * sourcePackPtr = iBuilder->getInputStreamPackPtr("sourceStream", iBuilder->getInt32(0), iBuilder->getInt32(0));
     101    Value * outputPackPtr = iBuilder->getOutputStreamPackPtr("expandedStream", iBuilder->getInt32(0), iBuilder->getInt32(0));
    102102
    103103    Value * hasFullLoop = iBuilder->CreateICmpUGE(loopItemsToDo, triplePackSize);
     
    156156    // Update the processed items count based on the loopItemsToDo value.
    157157    processed = iBuilder->CreateAdd(processed, loopItemsToDo);
    158     setProcessedItemCount("sourceStream", processed);
     158    iBuilder->setProcessedItemCount("sourceStream", processed);
    159159
    160160
     
    226226    iBuilder->SetInsertPoint(itemsDone);
    227227    processed = iBuilder->CreateAdd(processed, excessItems);
    228     setProcessedItemCount("sourceStream", processed);
     228    iBuilder->setProcessedItemCount("sourceStream", processed);
    229229
    230230   
     
    244244//                                   ba    bits to move 12 positions left
    245245//    xwvuts|  nlkjzy|  barqpm|  hgfedc    Target
    246 inline Value * radix64Kernel::processPackData(llvm::Value * bytepack) const {
     246inline Value * radix64Kernel::processPackData(const std::unique_ptr<KernelBuilder> & iBuilder, llvm::Value * bytepack) const {
    247247
    248248    Value * step_right_6 = iBuilder->simd_fill(32, ConstantInt::get(iBuilder->getInt32Ty(), 0x00C00000));
     
    272272}
    273273
    274 void radix64Kernel::generateDoBlockMethod() {
     274void radix64Kernel::generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) {
    275275    for (unsigned i = 0; i < 8; i++) {
    276         Value * bytepack = loadInputStreamPack("expandedStream", iBuilder->getInt32(0), iBuilder->getInt32(i));
    277         Value * radix64pack = processPackData(bytepack);
    278         storeOutputStreamPack("radix64stream", iBuilder->getInt32(0), iBuilder->getInt32(i), radix64pack);
     276        Value * bytepack = iBuilder->loadInputStreamPack("expandedStream", iBuilder->getInt32(0), iBuilder->getInt32(i));
     277        Value * radix64pack = processPackData(iBuilder, bytepack);
     278        iBuilder->storeOutputStreamPack("radix64stream", iBuilder->getInt32(0), iBuilder->getInt32(i), radix64pack);
    279279    }
    280280}
    281281
    282 void radix64Kernel::generateFinalBlockMethod(Value * remainingBytes) {
     282void radix64Kernel::generateFinalBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder, Value * remainingBytes) {
    283283
    284284    BasicBlock * entry = iBuilder->GetInsertBlock();
    285     BasicBlock * radix64_loop = CreateBasicBlock("radix64_loop");
    286     BasicBlock * fbExit = CreateBasicBlock("fbExit");
     285    BasicBlock * radix64_loop = iBuilder->CreateBasicBlock("radix64_loop");
     286    BasicBlock * fbExit = iBuilder->CreateBasicBlock("fbExit");
    287287   
    288288    const unsigned PACK_SIZE = iBuilder->getStride()/8;
     
    298298    loopRemain->addIncoming(remainingBytes, entry);
    299299
    300     Value * bytepack = loadInputStreamPack("expandedStream", iBuilder->getInt32(0), idx);
    301     Value * radix64pack = processPackData(bytepack);
    302     storeOutputStreamPack("radix64stream", iBuilder->getInt32(0), idx, radix64pack);
     300    Value * bytepack = iBuilder->loadInputStreamPack("expandedStream", iBuilder->getInt32(0), idx);
     301    Value * radix64pack = processPackData(iBuilder, bytepack);
     302    iBuilder->storeOutputStreamPack("radix64stream", iBuilder->getInt32(0), idx, radix64pack);
    303303
    304304    Value* nextIdx = iBuilder->CreateAdd(idx, ConstantInt::get(iBuilder->getInt32Ty(), 1));
     
    314314}
    315315
    316 inline llvm::Value* base64Kernel::processPackData(llvm::Value* bytepack) const {
     316inline llvm::Value* base64Kernel::processPackData(const std::unique_ptr<KernelBuilder> & iBuilder, llvm::Value* bytepack) const {
    317317    Value * mask_gt_25 = iBuilder->simd_ugt(8, bytepack, iBuilder->simd_fill(8, iBuilder->getInt8(25)));
    318318    Value * mask_gt_51 = iBuilder->simd_ugt(8, bytepack, iBuilder->simd_fill(8, iBuilder->getInt8(51)));
     
    332332}
    333333
    334 void base64Kernel::generateDoBlockMethod() {
     334void base64Kernel::generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) {
    335335    for (unsigned i = 0; i < 8; i++) {
    336         Value * bytepack = loadInputStreamPack("radix64stream", iBuilder->getInt32(0), iBuilder->getInt32(i));
    337         Value * base64pack = processPackData(bytepack);
    338         storeOutputStreamPack("base64stream", iBuilder->getInt32(0), iBuilder->getInt32(i), base64pack);
     336        Value * bytepack = iBuilder->loadInputStreamPack("radix64stream", iBuilder->getInt32(0), iBuilder->getInt32(i));
     337        Value * base64pack = processPackData(iBuilder, bytepack);
     338        iBuilder->storeOutputStreamPack("base64stream", iBuilder->getInt32(0), iBuilder->getInt32(i), base64pack);
    339339    }
    340340}
    341 
    342 //// Special processing for the base 64 format.   The output must always contain a multiple
    343 //// of 4 bytes.   When the number of radix 64 values is not a multiple of 4
    344 //// number of radix 64 values
    345 //void base64Kernel::generateFinalBlockMethod(Value * remainingBytes) {
    346 
    347 //    BasicBlock * entry = iBuilder->GetInsertBlock();
    348 //    BasicBlock * base64_loop = CreateBasicBlock("base64_loop");
    349 //    BasicBlock * loopExit = CreateBasicBlock("loopExit");
    350 //    BasicBlock * doPadding = CreateBasicBlock("doPadding");
    351 //    BasicBlock * doPadding2 = CreateBasicBlock("doPadding2");
    352 //    BasicBlock * fbExit = CreateBasicBlock("fbExit");
    353 
    354 //    Value * remainMod4 = iBuilder->CreateAnd(remainingBytes, iBuilder->getSize(3));
    355 //    Value * padBytes = iBuilder->CreateSub(iBuilder->getSize(4), remainMod4);
    356 //    padBytes = iBuilder->CreateAnd(padBytes, iBuilder->getSize(3));
    357 
    358 //    Constant * packSize = iBuilder->getSize(iBuilder->getStride() / 8);
    359 
    360 //    // Enter the loop only if there is at least one byte remaining to process.
    361 //    iBuilder->CreateCondBr(iBuilder->CreateICmpEQ(remainingBytes, iBuilder->getSize(0)), fbExit, base64_loop);
    362 
    363 //    iBuilder->SetInsertPoint(base64_loop);
    364 //    PHINode * idx = iBuilder->CreatePHI(iBuilder->getInt32Ty(), 2);
    365 //    PHINode * loopRemain = iBuilder->CreatePHI(iBuilder->getSizeTy(), 2);
    366 //    idx->addIncoming(ConstantInt::getNullValue(iBuilder->getInt32Ty()), entry);
    367 //    loopRemain->addIncoming(remainingBytes, entry);
    368 //    Value * radix64streamPtr = getInputStream("radix64stream", iBuilder->getInt32(0), idx);
    369 //    Value * bytepack = iBuilder->CreateBlockAlignedLoad(radix64streamPtr);
    370 //    Value * base64pack = processPackData(bytepack);
    371 //    Value * base64streamPtr = getOutputStream("base64stream", iBuilder->getInt32(0), idx);
    372 
    373 //    iBuilder->CreateBlockAlignedStore(iBuilder->bitCast(base64pack), base64streamPtr);
    374 //    idx->addIncoming(iBuilder->CreateAdd(idx, ConstantInt::get(iBuilder->getInt32Ty(), 1)), base64_loop);
    375 //    Value* remainAfterLoop = iBuilder->CreateSub(loopRemain, packSize);
    376 //    loopRemain->addIncoming(remainAfterLoop, base64_loop);
    377 
    378 //    Value* continueLoop = iBuilder->CreateICmpSGT(remainAfterLoop, iBuilder->getSize(0));
    379 //    iBuilder->CreateCondBr(continueLoop, base64_loop, loopExit);
    380 
    381 //    iBuilder->SetInsertPoint(loopExit);
    382 //    iBuilder->CreateCondBr(iBuilder->CreateICmpEQ(padBytes, iBuilder->getSize(0)), fbExit, doPadding);
    383 
    384 //    iBuilder->SetInsertPoint(doPadding);
    385 
    386 //    base64streamPtr = getOutputStream("base64stream", iBuilder->getInt32(0), idx);
    387 //    Value * i8streamPtr = iBuilder->CreatePointerCast(base64streamPtr, iBuilder->getInt8PtrTy());
    388 //    iBuilder->CreateStore(ConstantInt::get(iBuilder->getInt8Ty(), '='), iBuilder->CreateGEP(i8streamPtr, remainingBytes));
    389 //    iBuilder->CreateCondBr(iBuilder->CreateICmpEQ(remainMod4, iBuilder->getSize(3)), fbExit, doPadding2);
    390 //    iBuilder->SetInsertPoint(doPadding2);
    391 //    Value * finalPadPos = iBuilder->CreateAdd(remainingBytes, iBuilder->getSize(1));
    392 //    iBuilder->CreateStore(ConstantInt::get(iBuilder->getInt8Ty(), '='), iBuilder->CreateGEP(i8streamPtr, finalPadPos));
    393 //    iBuilder->CreateBr(fbExit);
    394 //    iBuilder->SetInsertPoint(fbExit);
    395 //    Value * produced = iBuilder->CreateAdd(getProducedItemCount("base64stream"), iBuilder->CreateAdd(remainingBytes, padBytes));
    396 //    setProducedItemCount("base64stream", produced);
    397 //}
    398341
    399342// Special processing for the base 64 format.   The output must always contain a multiple
    400343// of 4 bytes.   When the number of radix 64 values is not a multiple of 4
    401344// number of radix 64 values
    402 void base64Kernel::generateFinalBlockMethod(Value * remainingBytes) {
     345void base64Kernel::generateFinalBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder, Value * remainingBytes) {
    403346
    404347    BasicBlock * entry = iBuilder->GetInsertBlock();
    405     BasicBlock * base64_loop = CreateBasicBlock("base64_loop");
    406     BasicBlock * loopExit = CreateBasicBlock("loopExit");
    407     BasicBlock * doPadding = CreateBasicBlock("doPadding");
    408     BasicBlock * doPadding2 = CreateBasicBlock("doPadding2");
    409     BasicBlock * fbExit = CreateBasicBlock("fbExit");
     348    BasicBlock * base64_loop = iBuilder->CreateBasicBlock("base64_loop");
     349    BasicBlock * loopExit = iBuilder->CreateBasicBlock("loopExit");
     350    BasicBlock * doPadding = iBuilder->CreateBasicBlock("doPadding");
     351    BasicBlock * doPadding2 = iBuilder->CreateBasicBlock("doPadding2");
     352    BasicBlock * fbExit = iBuilder->CreateBasicBlock("fbExit");
    410353
    411354    Value * remainMod4 = iBuilder->CreateAnd(remainingBytes, iBuilder->getSize(3));
     
    423366    idx->addIncoming(ConstantInt::getNullValue(iBuilder->getInt32Ty()), entry);
    424367    loopRemain->addIncoming(remainingBytes, entry);
    425     Value * bytepack = loadInputStreamPack("radix64stream", iBuilder->getInt32(0), idx);
    426     Value * base64pack = processPackData(bytepack);
    427     storeOutputStreamPack("base64stream", iBuilder->getInt32(0), idx, base64pack);
     368    Value * bytepack = iBuilder->loadInputStreamPack("radix64stream", iBuilder->getInt32(0), idx);
     369    Value * base64pack = processPackData(iBuilder, bytepack);
     370    iBuilder->storeOutputStreamPack("base64stream", iBuilder->getInt32(0), idx, base64pack);
    428371    idx->addIncoming(iBuilder->CreateAdd(idx, ConstantInt::get(iBuilder->getInt32Ty(), 1)), base64_loop);
    429372    Value* remainAfterLoop = iBuilder->CreateSub(loopRemain, packSize);
     
    437380
    438381    iBuilder->SetInsertPoint(doPadding);
    439     Value * i8output_ptr = getOutputStreamBlockPtr("base64stream", iBuilder->getInt32(0));
     382    Value * i8output_ptr = iBuilder->getOutputStreamBlockPtr("base64stream", iBuilder->getInt32(0));
    440383    i8output_ptr = iBuilder->CreatePointerCast(i8output_ptr, iBuilder->getInt8PtrTy());
    441384    iBuilder->CreateStore(ConstantInt::get(iBuilder->getInt8Ty(), '='), iBuilder->CreateGEP(i8output_ptr, remainingBytes));
Note: See TracChangeset for help on using the changeset viewer.