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

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

Legend:

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

    r5106 r5111  
    5454    std::vector<Type *> doBlockParameters = {selfType};
    5555    std::vector<Type *> finalBlockParameters = {selfType, iBuilder->getSizeTy()};
    56     /*
    57     for (auto inputSet : mStreamSetInputs) {
    58         Type * inputSetParmType = PointerType::getUnqual(inputSet.ssType.getStreamSetBlockType(iBuilder));
    59         doBlockParameters.push_back(inputSetParmType);
    60         finalBlockParameters.push_back(inputSetParmType);
    61     }
    62     for (auto outputSet : mStreamSetOutputs) {
    63         Type * outputSetParmType = PointerType::getUnqual(outputSet.ssType.getStreamSetBlockType(iBuilder));
    64         doBlockParameters.push_back(outputSetParmType);
    65         finalBlockParameters.push_back(outputSetParmType);
    66     }
    67      */
    68     FunctionType * doBlockFunctionType = FunctionType::get(mDoBlockReturnType, doBlockParameters, false);
     56    FunctionType * doBlockFunctionType = FunctionType::get(iBuilder->getVoidTy(), doBlockParameters, false);
    6957    std::string doBlockName = mKernelName + doBlock_suffix;
    7058    Function * doBlockFn = Function::Create(doBlockFunctionType, GlobalValue::ExternalLinkage, doBlockName, client);
     
    7563    }
    7664   
    77     FunctionType * finalBlockType = FunctionType::get(mDoBlockReturnType, finalBlockParameters, false);
     65    FunctionType * finalBlockType = FunctionType::get(iBuilder->getVoidTy(), finalBlockParameters, false);
    7866    std::string finalBlockName = mKernelName + finalBlock_suffix;
    7967    Function * finalBlockFn = Function::Create(finalBlockType, GlobalValue::ExternalLinkage, finalBlockName, client);
     
    9583    finalBlockArg->setName("remainingBytes");
    9684
    97 /*    for (auto inputSet : mStreamSetInputs) {
    98         doBlockArg = &*(doBlockArgs++);
    99         finalBlockArg = &*(finalBlockArgs++);
    100         doBlockArg->setName(inputSet.ssName);
    101         finalBlockArg->setName(inputSet.ssName);
    102     }
    103     for (auto outputSet : mStreamSetOutputs) {
    104         doBlockArg = &*(doBlockArgs++);
    105         finalBlockArg = &*(finalBlockArgs++);
    106         doBlockArg->setName(outputSet.ssName);
    107         finalBlockArg->setName(outputSet.ssName);
    108     }
    109     */
    11085    // Create the doSegment function prototype.
    11186    std::vector<Type *> doSegmentParameters = {selfType, iBuilder->getSizeTy()};
    112     FunctionType * doSegmentFunctionType = FunctionType::get(mDoBlockReturnType, doSegmentParameters, false);
     87    FunctionType * doSegmentFunctionType = FunctionType::get(iBuilder->getVoidTy(), doSegmentParameters, false);
    11388    std::string doSegmentName = mKernelName + doSegment_suffix;
    11489    Function * doSegmentFn = Function::Create(doSegmentFunctionType, GlobalValue::ExternalLinkage, doSegmentName, client);
     
    137112    if (!initMethod) {
    138113        throw std::runtime_error("Cannot find " + initFnName);
    139         //Or just zero-initialize???
    140         //iBuilder->CreateStore(Constant::getNullValue(mKernelStateType), kernelInstance);
    141         //return kernelInstance;
    142114    }
    143115    iBuilder->CreateCall(initMethod, init_args);
  • icGREP/icgrep-devel/icgrep/kernels/interface.h

    r5102 r5111  
    4848    mScalarOutputs(scalar_outputs),
    4949    mInternalScalars(internal_scalars),
    50     mDoBlockReturnType(nullptr),
    5150    mKernelStateType(nullptr) {}
    5251   
     
    7170    std::vector<ScalarBinding> mScalarOutputs;
    7271    std::vector<ScalarBinding> mInternalScalars;
    73     llvm::Type * mDoBlockReturnType;
    7472    llvm::Type * mKernelStateType;
    7573};
  • 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}
  • icGREP/icgrep-devel/icgrep/kernels/kernel.h

    r5109 r5111  
    7474    void addScalar(llvm::Type * t, std::string scalarName);
    7575   
    76     // Set a specific _DoBlock return type;
    77    
    78     void setDoBlockReturnType(llvm::Type * t);
    79        
    8076    // Run-time access of Kernel State and parameters of methods for
    8177    // use in implementing kernels.
  • icGREP/icgrep-devel/icgrep/kernels/p2s_kernel.cpp

    r5109 r5111  
    6969   
    7070void p2sKernel_withCompressedOutput::prepareKernel() {
    71     setDoBlockReturnType(iBuilder->getInt32Ty());
    7271    KernelBuilder::prepareKernel();
    7372}
     
    107106        offset = iBuilder->CreateZExt(iBuilder->CreateExtractElement(unit_counts, iBuilder->getInt32(j)), i32);
    108107    }
    109     iBuilder->CreateRet(offset);
     108    iBuilder->CreateRetVoid();
    110109    iBuilder->restoreIP(savePoint);
    111110}
     
    153152}
    154153   
    155     static Function * create_write(Module * const mod) {
    156         Function * write = mod->getFunction("write");
    157         if (write == nullptr) {
    158             FunctionType *write_type =
    159             TypeBuilder<long(int, char *, long), false>::get(mod->getContext());
    160             write = cast<Function>(mod->getOrInsertFunction("write", write_type,
    161                                                             AttributeSet().addAttribute(mod->getContext(), 2U, Attribute::NoAlias)));
    162         }
    163         return write;
    164     }
     154static Function * create_write(Module * const mod) {
     155    Function * write = mod->getFunction("write");
     156    if (write == nullptr) {
     157        FunctionType *write_type =
     158        TypeBuilder<long(int, char *, long), false>::get(mod->getContext());
     159        write = cast<Function>(mod->getOrInsertFunction("write", write_type,
     160                                                        AttributeSet().addAttribute(mod->getContext(), 2U, Attribute::NoAlias)));
     161    }
     162    return write;
     163}
    165164   
    166165   
     
    244243    IDISA::IDISA_Builder::InsertPoint savePoint = iBuilder->saveIP();
    245244    Module * m = iBuilder->getModule();
    246     Type * i32 = iBuilder->getIntNTy(32);
    247245    Type * bitBlockPtrTy = llvm::PointerType::get(iBuilder->getBitBlockType(), 0);
    248246    Type * i8PtrTy = iBuilder->getInt8PtrTy();
  • icGREP/icgrep-devel/icgrep/kernels/pipeline.cpp

    r5106 r5111  
    5858        iBuilder->SetInsertPoint(segmentBodyBlock);
    5959        Value * segBlocks = ConstantInt::get(size_ty, segmentSize);
    60         Value * rslt = kernels[0]->createDoSegmentCall(instances[0], segBlocks);
    61         for (unsigned i = 1; i < kernels.size(); i++) {
    62             rslt = kernels[i]->createDoSegmentCall(instances[i], rslt->getType()->isVoidTy() ? segBlocks : rslt);
     60        for (unsigned i = 0; i < kernels.size(); i++) {
     61            kernels[i]->createDoSegmentCall(instances[i], segBlocks);
    6362        }
    6463        remainingBytes->addIncoming(iBuilder->CreateSub(remainingBytes, step), segmentBodyBlock);
     
    8887    // Full Block Pipeline loop
    8988    iBuilder->SetInsertPoint(fullBodyBlock);
    90     rslt = kernels[0]->createDoSegmentCall(instances[0], ConstantInt::get(size_ty, 1));
    91     for (unsigned i = 1; i < kernels.size(); i++) {
    92         rslt = kernels[i]->createDoSegmentCall(instances[i], rslt->getType()->isVoidTy() ? ConstantInt::get(size_ty, 1) : rslt);
     89    for (unsigned i = 0; i < kernels.size(); i++) {
     90        kernels[i]->createDoSegmentCall(instances[i], ConstantInt::get(size_ty, 1));
    9391    }
    9492   
Note: See TracChangeset for help on using the changeset viewer.