Ignore:
Timestamp:
Jul 30, 2016, 1:12:45 PM (3 years ago)
Author:
cameron
Message:

DoBlock/FinalBlock/DoSegment? Kernel functions always return void; clean-up

File:
1 edited

Legend:

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

    r5109 r5111  
    3131}
    3232
    33 void KernelBuilder::setDoBlockReturnType(llvm::Type * t) {
    34     mDoBlockReturnType = t;
    35 }
    36 
    3733void KernelBuilder::prepareKernel() {
    38     if (!mDoBlockReturnType) mDoBlockReturnType = iBuilder->getVoidTy();
    3934    addScalar(iBuilder->getSizeTy(), blockNoScalar);
    4035    int streamSetNo = 0;
     
    125120    }
    126121    Value * rslt = iBuilder->CreateCall(doBlockFunction, doBlockArgs);
    127     if (mDoBlockReturnType->isVoidTy()) {
    128         iBuilder->CreateRetVoid();
    129     }
    130     else {
    131         iBuilder->CreateRet(rslt);
    132     }
     122    iBuilder->CreateRetVoid();
    133123    iBuilder->restoreIP(savePoint);
    134124}
     
    153143   
    154144    iBuilder->SetInsertPoint(blockLoop);
    155     if (mDoBlockReturnType->isVoidTy()) {
    156         PHINode * blocksRemaining = iBuilder->CreatePHI(iBuilder->getSizeTy(), 2, "blocksRemaining");
    157         blocksRemaining->addIncoming(blocksToDo, entryBlock);
    158        
    159         Value * blockNo = getScalarField(self, blockNoScalar);
    160        
    161         iBuilder->CreateCall(doBlockFunction, {self});
    162         setScalarField(self, blockNoScalar, iBuilder->CreateAdd(blockNo, ConstantInt::get(iBuilder->getSizeTy(), 1)));
    163         blocksToDo = iBuilder->CreateSub(blocksRemaining, ConstantInt::get(iBuilder->getSizeTy(), 1));
    164         blocksRemaining->addIncoming(blocksToDo, blockLoop);
    165         Value * notDone = iBuilder->CreateICmpUGT(blocksToDo, ConstantInt::get(iBuilder->getSizeTy(), 0));
    166         iBuilder->CreateCondBr(notDone, blockLoop, blocksDone);
    167        
    168         iBuilder->SetInsertPoint(blocksDone);
    169         iBuilder->CreateRetVoid();
    170     }
    171     else {
    172         PHINode * blocksRemaining = iBuilder->CreatePHI(iBuilder->getSizeTy(), 2, "blocksRemaining");
    173         blocksRemaining->addIncoming(blocksToDo, entryBlock);
    174         PHINode * total = iBuilder->CreatePHI(mDoBlockReturnType, 2, "resultTotal");
    175         total->addIncoming(ConstantInt::getNullValue(mDoBlockReturnType), entryBlock);
    176 
    177         Value * blockNo = getScalarField(self, blockNoScalar);
    178         std::vector<Value *> doBlockArgs = {self};
    179        
    180         Value * rslt = iBuilder->CreateCall(doBlockFunction, {self});
    181         setScalarField(self, blockNoScalar, iBuilder->CreateAdd(blockNo, ConstantInt::get(iBuilder->getSizeTy(), 1)));
    182         blocksToDo = iBuilder->CreateSub(blocksRemaining, ConstantInt::get(iBuilder->getSizeTy(), 1));
    183         blocksRemaining->addIncoming(blocksToDo, blockLoop);
    184         Value * notDone = iBuilder->CreateICmpUGT(blocksToDo, ConstantInt::get(iBuilder->getSizeTy(), 0));
    185         Value * totalSoFar = iBuilder->CreateAdd(total, rslt);
    186         total->addIncoming(totalSoFar, blockLoop);
    187         iBuilder->CreateCondBr(notDone, blockLoop, blocksDone);
    188        
    189         iBuilder->SetInsertPoint(blocksDone);
    190         iBuilder->CreateRet(rslt);
    191     }
     145    PHINode * blocksRemaining = iBuilder->CreatePHI(iBuilder->getSizeTy(), 2, "blocksRemaining");
     146    blocksRemaining->addIncoming(blocksToDo, entryBlock);
     147   
     148    Value * blockNo = getScalarField(self, blockNoScalar);
     149   
     150    iBuilder->CreateCall(doBlockFunction, {self});
     151    setScalarField(self, blockNoScalar, iBuilder->CreateAdd(blockNo, ConstantInt::get(iBuilder->getSizeTy(), 1)));
     152    blocksToDo = iBuilder->CreateSub(blocksRemaining, ConstantInt::get(iBuilder->getSizeTy(), 1));
     153    blocksRemaining->addIncoming(blocksToDo, blockLoop);
     154    Value * notDone = iBuilder->CreateICmpUGT(blocksToDo, ConstantInt::get(iBuilder->getSizeTy(), 0));
     155    iBuilder->CreateCondBr(notDone, blockLoop, blocksDone);
     156   
     157    iBuilder->SetInsertPoint(blocksDone);
     158    iBuilder->CreateRetVoid();
    192159    iBuilder->restoreIP(savePoint);
    193160}
Note: See TracChangeset for help on using the changeset viewer.