Changeset 5286


Ignore:
Timestamp:
Jan 29, 2017, 12:05:00 PM (8 months ago)
Author:
nmedfort
Message:

Continuation of work to simplify Kernel writing

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

Legend:

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

    r5285 r5286  
    115115    mStreamSetInputBuffers.assign(inputs.begin(), inputs.end());
    116116    mStreamSetOutputBuffers.assign(outputs.begin(), outputs.end());
    117     prepareKernel();            // possibly overridden by the KernelBuilder subtype
     117    prepareKernel(); // possibly overridden by the KernelBuilder subtype
    118118    addKernelDeclarations(m);
    119     generateInitMethod();       // possibly overridden by the KernelBuilder subtype
    120     generateDoSegmentMethod();
     119    callGenerateInitMethod();
     120    callGenerateDoSegmentMethod();
    121121
    122122    // Implement the accumulator get functions
     
    133133}
    134134
    135 // Default init method, possibly overridden if special init actions required.
    136 void KernelBuilder::generateInitMethod() const {
    137     auto savePoint = iBuilder->saveIP();
     135void KernelBuilder::callGenerateDoSegmentMethod() const {
     136    Function * doSegmentFunction = getDoSegmentFunction();
     137    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), mKernelName + "_entry", doSegmentFunction, 0));
     138    auto args = doSegmentFunction->arg_begin();
     139    Value * self = &*(args++);
     140    Value * doFinal = &*(args++);
     141    std::vector<Value *> producerPos;
     142    for (unsigned i = 0; i < mStreamSetInputs.size(); i++) {
     143        producerPos.push_back(&*(args++));
     144    }
     145    assert (args == doSegmentFunction->arg_end());
     146    generateDoSegmentMethod(doSegmentFunction, self, doFinal, producerPos); // must be overridden by the KernelBuilder subtype
     147    iBuilder->CreateRetVoid();
     148}
     149
     150void KernelBuilder::callGenerateInitMethod() const {
    138151    Module * const m = iBuilder->getModule();
    139152    Function * initFunction = m->getFunction(mKernelName + init_suffix);
    140     iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "Init_entry", initFunction, 0));   
     153    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "Init_entry", initFunction, 0));
    141154    Function::arg_iterator args = initFunction->arg_begin();
    142155    Value * self = &*(args++);
     
    147160        iBuilder->CreateStore(param, ptr);
    148161    }
     162    generateInitMethod(initFunction, self);
    149163    iBuilder->CreateRetVoid();
    150     iBuilder->restoreIP(savePoint);
    151 }
     164}
     165
     166// Default init method, possibly overridden if special init actions required.
     167void KernelBuilder::generateInitMethod(Function * /* initFunction */, Value * /* self */) const { }
     168
    152169
    153170ConstantInt * KernelBuilder::getScalarIndex(const std::string & name) const {
     
    321338//  The default doSegment method dispatches to the doBlock routine for
    322339//  each block of the given number of blocksToDo, and then updates counts.
    323 void BlockOrientedKernel::generateDoSegmentMethod() const {
     340void BlockOrientedKernel::generateDoSegmentMethod(Function * doSegmentFunction, Value * self, Value * doFinal, const std::vector<Value *> &producerPos) const {
     341
    324342    auto savePoint = iBuilder->saveIP();
    325 
    326343    callGenerateDoBlockMethod();
    327 
    328344    callGenerateDoFinalBlockMethod();
    329 
    330     Module * m = iBuilder->getModule();
    331     Function * doSegmentFunction = m->getFunction(mKernelName + doSegment_suffix);
    332     iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), mKernelName + "_entry", doSegmentFunction, 0));
     345    iBuilder->restoreIP(savePoint);
     346
    333347    BasicBlock * entryBlock = iBuilder->GetInsertBlock();
    334348    BasicBlock * strideLoopCond = BasicBlock::Create(iBuilder->getContext(), mKernelName + "_strideLoopCond", doSegmentFunction, 0);
     
    342356    ConstantInt * strideBlocks = iBuilder->getSize(iBuilder->getStride() / iBuilder->getBitBlockWidth());
    343357
    344     Function::arg_iterator args = doSegmentFunction->arg_begin();
    345     Value * self = &*(args++);
    346     Value * doFinal = &*(args++);
    347 
    348     std::vector<Value *> producerPos;
    349     producerPos.push_back(&*(args++));
    350358    Value * availablePos = producerPos[0];
    351359    for (unsigned i = 1; i < mStreamSetInputs.size(); i++) {
    352         Value * p = &*(args++);
    353         producerPos.push_back(p);
     360        Value * p = producerPos[i];
    354361        availablePos = iBuilder->CreateSelect(iBuilder->CreateICmpULT(availablePos, p), availablePos, p);
    355362    }
     
    362369    PHINode * stridesRemaining = iBuilder->CreatePHI(size_ty, 2, "stridesRemaining");
    363370    stridesRemaining->addIncoming(stridesToDo, entryBlock);
    364     Value * notDone = iBuilder->CreateICmpUGT(stridesRemaining, ConstantInt::get(size_ty, 0));
     371    Value * notDone = iBuilder->CreateICmpUGT(stridesRemaining, iBuilder->getSize(0));
    365372    iBuilder->CreateCondBr(notDone, strideLoopBody, stridesDone);
    366373
     
    371378
    372379    setBlockNo(self, iBuilder->CreateAdd(blockNo, strideBlocks));
    373     stridesRemaining->addIncoming(iBuilder->CreateSub(stridesRemaining, ConstantInt::get(size_ty, 1)), strideLoopBody);
     380    stridesRemaining->addIncoming(iBuilder->CreateSub(stridesRemaining, iBuilder->getSize(1)), strideLoopBody);
    374381    iBuilder->CreateBr(strideLoopCond);
    375382
     
    412419    iBuilder->SetInsertPoint(segmentDone);
    413420
    414     iBuilder->CreateRetVoid();
    415     iBuilder->restoreIP(savePoint);
    416421}
    417422
    418423void BlockOrientedKernel::callGenerateDoBlockMethod() const {
    419424    Function * f = getDoBlockFunction();
    420     Value * const self = getParameter(f, "self"); assert (self);
     425    auto args = f->arg_begin();
     426    Value * const self = &(*args);
    421427    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", f));
    422428    generateDoBlockMethod(f, self, getBlockNo(self)); // must be implemented by the KernelBuilder subtype
    423429    iBuilder->CreateRetVoid();
    424 //    #ifndef NDEBUG
    425 //    llvm::verifyFunction(*f, &errs());
    426 //    #endif
    427430}
    428431
    429432void BlockOrientedKernel::callGenerateDoFinalBlockMethod() const {
    430433    Function * f = getDoFinalBlockFunction();
    431     Value * const self = getParameter(f, "self"); assert (self);
    432     Value * remainingBytes = getParameter(f, "remainingBytes"); assert (remainingBytes);
     434    auto args = f->arg_begin();
     435    Value * const self = &(*args++);
     436    Value * const remainingBytes = &(*args);
    433437    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", f));
    434438    generateFinalBlockMethod(f, self, remainingBytes, getBlockNo(self)); // possibly overridden by the KernelBuilder subtype
    435439    iBuilder->CreateRetVoid();
    436 //    #ifndef NDEBUG
    437 //    llvm::verifyFunction(*f, &errs());
    438 //    #endif
    439440}
    440441
  • icGREP/icgrep-devel/icgrep/kernels/kernel.h

    r5285 r5286  
    118118    virtual void prepareKernel();
    119119       
    120     virtual void generateInitMethod() const;
    121    
    122     virtual void generateDoSegmentMethod() const = 0;
     120    virtual void generateInitMethod(llvm::Function * initFunction, llvm::Value * self) const;
     121   
     122    virtual void generateDoSegmentMethod(llvm::Function * function, llvm::Value * self, llvm::Value * doFinal, const std::vector<llvm::Value *> & producerPos) const = 0;
    123123   
    124124    // Add an additional scalar field to the KernelState struct.
     
    176176    virtual void setProducedItemCount(llvm::Value * self, const std::string & name, llvm::Value * value) const;
    177177
    178 protected:
    179 
    180178    const parabix::StreamSetBuffer * getStreamSetBuffer(const std::string & name) const;
     179
     180private:
     181
     182    void callGenerateInitMethod() const;
     183
     184    void callGenerateDoSegmentMethod() const;
    181185
    182186protected:
     
    208212    virtual void generateFinalBlockMethod(llvm::Function * function, llvm::Value * self, llvm::Value * remainingBytes, llvm::Value * blockNo) const;
    209213
    210     virtual void generateDoSegmentMethod() const final;
     214    virtual void generateDoSegmentMethod(llvm::Function * function, llvm::Value * self, llvm::Value * doFinal, const std::vector<llvm::Value *> & producerPos) const final;
    211215
    212216    BlockOrientedKernel(IDISA::IDISA_Builder * builder,
  • icGREP/icgrep-devel/icgrep/kernels/mmap_kernel.cpp

    r5283 r5286  
    1717namespace kernel {
    1818           
    19 void MMapSourceKernel::generateDoSegmentMethod() const {
    20     auto savePoint = iBuilder->saveIP();
    21     Module * m = iBuilder->getModule();
    22     Function * doSegmentFunction = m->getFunction(mKernelName + doSegment_suffix);
    23    
    24     iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), mKernelName + "_entry", doSegmentFunction, 0));
     19void MMapSourceKernel::generateDoSegmentMethod(Function * doSegmentFunction, Value *self, Value *doFinal, const std::vector<Value *> &producerPos) const {
    2520    BasicBlock * setTermination = BasicBlock::Create(iBuilder->getContext(), "setTermination", doSegmentFunction, 0);
    2621    BasicBlock * mmapSourceExit = BasicBlock::Create(iBuilder->getContext(), "mmapSourceExit", doSegmentFunction, 0);
    27     Constant * segmentItems = iBuilder->getSize(mSegmentBlocks * iBuilder->getBitBlockWidth());
    28    
    29    
    30     auto args = doSegmentFunction->arg_begin();
    31     Value * self = &*(args++);
    32    
     22    ConstantInt * segmentItems = iBuilder->getSize(mSegmentBlocks * iBuilder->getBitBlockWidth());
    3323    Value * fileItems = getScalarField(self, "fileSize");
    3424    if (mCodeUnitWidth > 8) {
    35         fileItems = iBuilder->CreateUDiv(fileItems, iBuilder->getSize(mCodeUnitWidth/8));
     25        fileItems = iBuilder->CreateUDiv(fileItems, iBuilder->getSize(mCodeUnitWidth / 8));
    3626    }
    3727    Value * produced = getProducedItemCount(self, "sourceBuffer");   
     
    4030    produced = iBuilder->CreateSelect(lessThanFullSegment, fileItems, nextProduced);
    4131    setProducedItemCount(self, "sourceBuffer", produced);
    42    
     32
    4333    iBuilder->CreateCondBr(lessThanFullSegment, setTermination, mmapSourceExit);
    4434    iBuilder->SetInsertPoint(setTermination);
    4535    setTerminationSignal(self);
    46     iBuilder->CreateBr(mmapSourceExit);
    47    
     36    iBuilder->CreateBr(mmapSourceExit);   
     37
    4838    iBuilder->SetInsertPoint(mmapSourceExit);
    49     iBuilder->CreateRetVoid();
    50     iBuilder->restoreIP(savePoint);
    5139}
    5240
  • icGREP/icgrep-devel/icgrep/kernels/mmap_kernel.h

    r5285 r5286  
    1919    MMapSourceKernel(IDISA::IDISA_Builder * iBuilder, unsigned blocksPerSegment = 1, unsigned codeUnitWidth = 8); 
    2020private:
    21     void generateDoSegmentMethod() const override;
     21    void generateDoSegmentMethod(llvm::Function * function, llvm::Value * self, llvm::Value * doFinal, const std::vector<llvm::Value *> & producerPos) const override final;
    2222private:
    2323    const unsigned mSegmentBlocks;
  • icGREP/icgrep-devel/icgrep/kernels/radix64.cpp

    r5285 r5286  
    4141// a continous buffer for the full segment (number of blocks).
    4242
    43 void expand3_4Kernel::generateDoSegmentMethod() const {
    44     IDISA::IDISA_Builder::InsertPoint savePoint = iBuilder->saveIP();
    45     Module * m = iBuilder->getModule();
    46     Function * doSegmentFunction = m->getFunction(mKernelName + doSegment_suffix);
    47     BasicBlock * expand2_3entry = BasicBlock::Create(iBuilder->getContext(), "expand2_3entry", doSegmentFunction, 0);
    48     iBuilder->SetInsertPoint(expand2_3entry);
     43void expand3_4Kernel::generateDoSegmentMethod(Function * doSegmentFunction, Value *self, Value *doFinal, const std::vector<Value *> &producerPos) const {
     44
     45    BasicBlock * expand2_3entry = iBuilder->GetInsertBlock();
    4946    BasicBlock * expand_3_4_loop = BasicBlock::Create(iBuilder->getContext(), "expand_3_4_loop", doSegmentFunction, 0);
    5047    BasicBlock * expand3_4_loop_exit = BasicBlock::Create(iBuilder->getContext(), "expand3_4_loop_exit", doSegmentFunction, 0);
     
    9188    const unsigned packAlign = iBuilder->getBitBlockWidth()/8;
    9289
    93     Function::arg_iterator args = doSegmentFunction->arg_begin();
    94     Value * self = &*(args++);
    95     Value * doFinal = &*(args++);
    96     Value * producerPos = &*(args++);
    9790    Value * processed = getProcessedItemCount(self, "sourceStream");
    98     Value * itemsAvail = iBuilder->CreateSub(producerPos, processed);
     91    Value * itemsAvail = iBuilder->CreateSub(producerPos[0], processed);
    9992   
    10093    //
     
    256249    iBuilder->CreateBr(expand3_4_exit);
    257250    iBuilder->SetInsertPoint(expand3_4_exit);
    258     iBuilder->CreateRetVoid();
    259     iBuilder->restoreIP(savePoint);
    260251}
    261252
  • icGREP/icgrep-devel/icgrep/kernels/radix64.h

    r5285 r5286  
    2323    expand3_4Kernel(IDISA::IDISA_Builder * iBuilder);
    2424private:
    25     void generateDoSegmentMethod() const override;
     25    void generateDoSegmentMethod(llvm::Function * doSegmentFunction, llvm::Value *self, llvm::Value *doFinal, const std::vector<llvm::Value *> &producerPos) const override;
    2626};
    2727
  • icGREP/icgrep-devel/icgrep/kernels/stdin_kernel.cpp

    r5283 r5286  
    1212namespace kernel {
    1313   
    14 void StdInKernel::generateDoSegmentMethod() const {
    15     auto savePoint = iBuilder->saveIP();
    16     Module * m = iBuilder->getModule();
    17     Function * doSegmentFunction = m->getFunction(mKernelName + doSegment_suffix);
     14void StdInKernel::generateDoSegmentMethod(Function *doSegmentFunction, Value *self, Value *doFinal, const std::vector<Value *> &producerPos) const {
     15
    1816    Type * i8PtrTy = iBuilder->getInt8PtrTy();
    1917   
     
    2119    BasicBlock * setTermination = BasicBlock::Create(iBuilder->getContext(), "setTermination", doSegmentFunction, 0);
    2220    BasicBlock * stdInExit = BasicBlock::Create(iBuilder->getContext(), "stdInExit", doSegmentFunction, 0);
    23     Constant * blockItems = ConstantInt::get(iBuilder->getSizeTy(), iBuilder->getBitBlockWidth());
    24     Constant * itemBytes = ConstantInt::get(iBuilder->getSizeTy(), mCodeUnitWidth/8);
    25     Constant * segmentBytes = ConstantInt::get(iBuilder->getSizeTy(),
    26                                                mSegmentBlocks * iBuilder->getBitBlockWidth() * mCodeUnitWidth/8);
    27     Constant * stdin_fileno = iBuilder->getInt32(STDIN_FILENO);
    28     Function::arg_iterator args = doSegmentFunction->arg_begin();
    29     Value * self = &*(args++);
    30    
     21    ConstantInt * blockItems = iBuilder->getSize(iBuilder->getBitBlockWidth());
     22    ConstantInt * itemBytes = iBuilder->getSize(mCodeUnitWidth/8);
     23    ConstantInt * segmentBytes = iBuilder->getSize(mSegmentBlocks * iBuilder->getBitBlockWidth() * mCodeUnitWidth/8);
     24    ConstantInt * stdin_fileno = iBuilder->getInt32(STDIN_FILENO);
    3125    Value * produced = getProducedItemCount(self, "codeUnitBuffer");
    3226    Value * blockNo = iBuilder->CreateUDiv(produced, blockItems);
     
    4539   
    4640    iBuilder->SetInsertPoint(stdInExit);
    47     iBuilder->CreateRetVoid();
    48     iBuilder->restoreIP(savePoint);
     41
    4942   
    5043}
     
    5750}
    5851
    59 void FileSource::generateInitMethod() const {
    60     auto savePoint = iBuilder->saveIP();
    61     Module * const m = iBuilder->getModule();
    62     Function * initFunction = m->getFunction(mKernelName + init_suffix);
    63     iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "Init_entry", initFunction, 0));
     52void FileSource::generateInitMethod(Function * initFunction, Value * self) const {
    6453    BasicBlock * setTerminationOnFailure = BasicBlock::Create(iBuilder->getContext(), "setTerminationOnFailure", initFunction, 0);
    6554    BasicBlock * fileSourceInitExit = BasicBlock::Create(iBuilder->getContext(), "fileSourceInitExit", initFunction, 0);
    66     Function::arg_iterator args = initFunction->arg_begin();
    67     Value * self = &*(args++);
    68     iBuilder->CreateStore(ConstantAggregateZero::get(mKernelStateType), self);
    69     for (auto binding : mScalarInputs) {
    70         Value * param = &*(args++);
    71         Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), getScalarIndex(binding.name)});
    72         iBuilder->CreateStore(param, ptr);
    73     }
    7455    Value * handle = iBuilder->CreateFOpenCall(getScalarField(self, "fileName"), iBuilder->CreateGlobalStringPtr("r"));
    7556    setScalarField(self, "IOstreamPtr", handle);
     
    8061    iBuilder->CreateBr(fileSourceInitExit);
    8162    iBuilder->SetInsertPoint(fileSourceInitExit);
    82     iBuilder->CreateRetVoid();
    83     iBuilder->restoreIP(savePoint);
    8463}
    8564   
    86 void FileSource::generateDoSegmentMethod() const {
    87     auto savePoint = iBuilder->saveIP();
    88     Module * m = iBuilder->getModule();
    89     Function * doSegmentFunction = m->getFunction(mKernelName + doSegment_suffix);
    90     Type * i8PtrTy = iBuilder->getInt8PtrTy();
     65void FileSource::generateDoSegmentMethod(Function * doSegmentFunction, Value *self, Value * doFinal, const std::vector<Value *> & producerPos) const {
     66
     67    PointerType * i8PtrTy = iBuilder->getInt8PtrTy();
    9168   
    9269    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", doSegmentFunction, 0));
     
    9673    Constant * itemBytes = iBuilder->getSize(mCodeUnitWidth/8);
    9774   
    98     Function::arg_iterator args = doSegmentFunction->arg_begin();
    99     Value * self = &*(args++);
    100     // ignore: Value * doFinal = &*(args++);
    10175    Value * produced = getProducedItemCount(self, "codeUnitBuffer");
    10276    Value * blockNo = iBuilder->CreateUDiv(produced, blockItems);
     
    11791   
    11892    iBuilder->SetInsertPoint(fileSourceExit);
    119     iBuilder->CreateRetVoid();
    120     iBuilder->restoreIP(savePoint);
    12193   
    12294}
  • icGREP/icgrep-devel/icgrep/kernels/stdin_kernel.h

    r5285 r5286  
    1818    StdInKernel(IDISA::IDISA_Builder * iBuilder, unsigned blocksPerSegment = 1, unsigned codeUnitWidth = 8);
    1919protected:
    20     void generateDoSegmentMethod() const override final;
     20    void generateDoSegmentMethod(llvm::Function * function, llvm::Value * self, llvm::Value * doFinal, const std::vector<llvm::Value *> & producerPos) const override final;
    2121private:
    2222    unsigned mSegmentBlocks;
     
    2929    FileSource(IDISA::IDISA_Builder * iBuilder, unsigned blocksPerSegment = 1, unsigned codeUnitWidth = 8);
    3030protected:
    31     void generateInitMethod() const override final;
    32     void generateDoSegmentMethod() const override final;
     31    void generateInitMethod(llvm::Function * initFunction, llvm::Value * self) const override final;
     32    void generateDoSegmentMethod(llvm::Function * function, llvm::Value * self, llvm::Value * doFinal, const std::vector<llvm::Value *> & producerPos) const override final;
    3333private:
    3434    unsigned mSegmentBlocks;
  • icGREP/icgrep-devel/icgrep/kernels/stdout_kernel.cpp

    r5285 r5286  
    1717// Rather than using doBlock logic to write one block at a time, this custom
    1818// doSegment method, writes the entire segment with a single write call.
    19 void StdOutKernel::generateDoSegmentMethod() const {
    20     auto savePoint = iBuilder->saveIP();
    21     Module * m = iBuilder->getModule();
    22     Function * doSegmentFunction = m->getFunction(mKernelName + doSegment_suffix);
    23     Type * i8PtrTy = iBuilder->getInt8PtrTy();
    24    
    25     iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", doSegmentFunction, 0));
     19void StdOutKernel::generateDoSegmentMethod(Function *doSegmentFunction, Value *self, Value *doFinal, const std::vector<Value *> &producerPos) const {
     20
     21    PointerType * i8PtrTy = iBuilder->getInt8PtrTy();
     22
    2623    Constant * blockItems = iBuilder->getSize(iBuilder->getBitBlockWidth());
    2724    Constant * itemBytes = iBuilder->getSize(mCodeUnitWidth/8);
    2825   
    29     Function::arg_iterator args = doSegmentFunction->arg_begin();
    30     Value * self = &*(args++);
    31     /* unused Value * doFinal = &*(args++);*/ args++;
    32     Value * producerPos = &*(args++);
    3326    Value * processed = getProcessedItemCount(self, "codeUnitBuffer");
    34     Value * itemsToDo = iBuilder->CreateSub(producerPos, processed);
     27    Value * itemsToDo = iBuilder->CreateSub(producerPos[0], processed);
    3528   
    3629    Value * blockNo = getBlockNo(self);
     
    4336    setBlockNo(self, iBuilder->CreateUDiv(processed, blockItems));
    4437
    45     iBuilder->CreateRetVoid();
    46     iBuilder->restoreIP(savePoint);
    4738}
    4839
     
    5344}
    5445
    55 void FileSink::generateInitMethod() const {
    56     auto savePoint = iBuilder->saveIP();
    57     Module * const m = iBuilder->getModule();
    58     Function * initFunction = m->getFunction(mKernelName + init_suffix);
    59     iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "Init_entry", initFunction, 0));   
     46void FileSink::generateInitMethod(Function *initFunction, Value *self) const {
    6047    BasicBlock * setTerminationOnFailure = BasicBlock::Create(iBuilder->getContext(), "setTerminationOnFailure", initFunction, 0);
    6148    BasicBlock * fileSinkInitExit = BasicBlock::Create(iBuilder->getContext(), "fileSinkInitExit", initFunction, 0);
    62     Function::arg_iterator args = initFunction->arg_begin();
    63     Value * self = &*(args++);
    64     iBuilder->CreateStore(ConstantAggregateZero::get(mKernelStateType), self);
    65     for (auto binding : mScalarInputs) {
    66         Value * param = &*(args++);
    67         Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), getScalarIndex(binding.name)});
    68         iBuilder->CreateStore(param, ptr);
    69     }
    7049    Value * handle = iBuilder->CreateFOpenCall(getScalarField(self, "fileName"), iBuilder->CreateGlobalStringPtr("w"));
    7150    setScalarField(self, "IOstreamPtr", handle);
     
    7655    iBuilder->CreateBr(fileSinkInitExit);
    7756    iBuilder->SetInsertPoint(fileSinkInitExit);
    78     iBuilder->CreateRetVoid();
    79     iBuilder->restoreIP(savePoint);
    8057}
     58
     59void FileSink::generateDoSegmentMethod(Function *doSegmentFunction, Value *self, Value *doFinal, const std::vector<Value *> &producerPos) const {
     60    PointerType * i8PtrTy = iBuilder->getInt8PtrTy();
    8161   
    82    
    83 
    84 void FileSink::generateDoSegmentMethod() const {
    85     auto savePoint = iBuilder->saveIP();
    86     Module * m = iBuilder->getModule();
    87     Function * doSegmentFunction = m->getFunction(mKernelName + doSegment_suffix);
    88     Type * i8PtrTy = iBuilder->getInt8PtrTy();
    89    
    90     iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", doSegmentFunction, 0));
    9162    BasicBlock * closeFile = BasicBlock::Create(iBuilder->getContext(), "closeFile", doSegmentFunction, 0);
    9263    BasicBlock * fileOutExit = BasicBlock::Create(iBuilder->getContext(), "fileOutExit", doSegmentFunction, 0);
     
    9465    Constant * itemBytes = iBuilder->getSize(mCodeUnitWidth/8);
    9566   
    96     Function::arg_iterator args = doSegmentFunction->arg_begin();
    97     Value * self = &*(args++);
    98     Value * doFinal = &*(args++);
    99     Value * producerPos = &*(args++);
    10067    Value * processed = getProcessedItemCount(self, "codeUnitBuffer");
    101     Value * itemsToDo = iBuilder->CreateSub(producerPos, processed);
     68    Value * itemsToDo = iBuilder->CreateSub(producerPos[0], processed);
    10269    Value * IOstreamPtr = getScalarField(self, "IOstreamPtr");
    10370   
     
    11784   
    11885    iBuilder->SetInsertPoint(fileOutExit);
    119     iBuilder->CreateRetVoid();
    120     iBuilder->restoreIP(savePoint);
    121 
    12286}
    12387
  • icGREP/icgrep-devel/icgrep/kernels/stdout_kernel.h

    r5285 r5286  
    1616    StdOutKernel(IDISA::IDISA_Builder * iBuilder, unsigned codeUnitWidth);
    1717private:
    18     void generateDoSegmentMethod() const override final;
     18    void generateDoSegmentMethod(llvm::Function * doSegmentFunction, llvm::Value * self, llvm::Value * doFinal, const std::vector<llvm::Value *> & producerPos) const override final;
    1919private:
    2020    const unsigned mCodeUnitWidth;
     
    2727    FileSink(IDISA::IDISA_Builder * iBuilder, unsigned codeUnitWidth);
    2828protected:
    29     void generateInitMethod() const override final;
    30     void generateDoSegmentMethod() const override final;
     29    void generateInitMethod(llvm::Function * initFunction, llvm::Value * self) const override final;
     30    void generateDoSegmentMethod(llvm::Function * doSegmentFunction, llvm::Value * self, llvm::Value * doFinal, const std::vector<llvm::Value *> & producerPos) const override final;
    3131private:
    3232    const unsigned mCodeUnitWidth;
Note: See TracChangeset for help on using the changeset viewer.