Ignore:
Timestamp:
Jul 18, 2016, 11:11:02 AM (3 years ago)
Author:
cameron
Message:

Pipeline generation for kernels with non-void DoBlock? return

File:
1 edited

Legend:

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

    r5098 r5099  
    152152   
    153153    iBuilder->SetInsertPoint(blockLoop);
    154     PHINode * blocksRemaining = iBuilder->CreatePHI(iBuilder->getInt64Ty(), 2, "blocksRemaining");
    155     blocksRemaining->addIncoming(blocksToDo, entryBlock);
    156    
    157     Value * blockNo = getScalarField(self, blockNoScalar);
    158     std::vector<Value *> doBlockArgs = {self};
    159 
    160     Value * rslt = iBuilder->CreateCall(doBlockFunction, doBlockArgs);
    161     setScalarField(self, blockNoScalar, iBuilder->CreateAdd(blockNo, iBuilder->getInt64(1)));
    162     blocksToDo = iBuilder->CreateSub(blocksRemaining, iBuilder->getInt64(1));
    163     blocksRemaining->addIncoming(blocksToDo, blockLoop);
    164     Value * notDone = iBuilder->CreateICmpUGT(blocksToDo, iBuilder->getInt64(0));
    165     iBuilder->CreateCondBr(notDone, blockLoop, blocksDone);
    166    
    167     iBuilder->SetInsertPoint(blocksDone);
    168154    if (mDoBlockReturnType->isVoidTy()) {
     155        PHINode * blocksRemaining = iBuilder->CreatePHI(iBuilder->getInt64Ty(), 2, "blocksRemaining");
     156        blocksRemaining->addIncoming(blocksToDo, entryBlock);
     157       
     158        Value * blockNo = getScalarField(self, blockNoScalar);
     159       
     160        iBuilder->CreateCall(doBlockFunction, {self});
     161        setScalarField(self, blockNoScalar, iBuilder->CreateAdd(blockNo, iBuilder->getInt64(1)));
     162        blocksToDo = iBuilder->CreateSub(blocksRemaining, iBuilder->getInt64(1));
     163        blocksRemaining->addIncoming(blocksToDo, blockLoop);
     164        Value * notDone = iBuilder->CreateICmpUGT(blocksToDo, iBuilder->getInt64(0));
     165        iBuilder->CreateCondBr(notDone, blockLoop, blocksDone);
     166       
     167        iBuilder->SetInsertPoint(blocksDone);
    169168        iBuilder->CreateRetVoid();
    170169    }
    171170    else {
     171        PHINode * blocksRemaining = iBuilder->CreatePHI(iBuilder->getInt64Ty(), 2, "blocksRemaining");
     172        blocksRemaining->addIncoming(blocksToDo, entryBlock);
     173        PHINode * total = iBuilder->CreatePHI(mDoBlockReturnType, 2, "resultTotal");
     174        total->addIncoming(ConstantInt::getNullValue(mDoBlockReturnType), entryBlock);
     175
     176        Value * blockNo = getScalarField(self, blockNoScalar);
     177        std::vector<Value *> doBlockArgs = {self};
     178       
     179        Value * rslt = iBuilder->CreateCall(doBlockFunction, {self});
     180        setScalarField(self, blockNoScalar, iBuilder->CreateAdd(blockNo, iBuilder->getInt64(1)));
     181        blocksToDo = iBuilder->CreateSub(blocksRemaining, iBuilder->getInt64(1));
     182        blocksRemaining->addIncoming(blocksToDo, blockLoop);
     183        Value * notDone = iBuilder->CreateICmpUGT(blocksToDo, iBuilder->getInt64(0));
     184        Value * totalSoFar = iBuilder->CreateAdd(total, rslt);
     185        total->addIncoming(totalSoFar, blockLoop);
     186        iBuilder->CreateCondBr(notDone, blockLoop, blocksDone);
     187       
     188        iBuilder->SetInsertPoint(blocksDone);
    172189        iBuilder->CreateRet(rslt);
    173190    }
    174191    iBuilder->restoreIP(savePoint);
     192    doSegmentFunction->dump();
    175193}
    176194
Note: See TracChangeset for help on using the changeset viewer.