source: icGREP/icgrep-devel/icgrep/kernels/mmap_kernel.cpp @ 5248

Last change on this file since 5248 was 5248, checked in by cameron, 2 years ago

MMapKernel initial check-in

File size: 2.6 KB
Line 
1/*
2 *  Copyright (c) 2017 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 */
5#include <kernels/mmap_kernel.h>
6#include <IR_Gen/idisa_builder.h>
7
8namespace kernel {
9           
10void MMapSourceKernel::generateDoSegmentMethod() const {
11    auto savePoint = iBuilder->saveIP();
12    Module * m = iBuilder->getModule();
13    Function * doSegmentFunction = m->getFunction(mKernelName + doSegment_suffix);
14   
15    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), mKernelName + "_entry", doSegmentFunction, 0));
16    BasicBlock * setTermination = BasicBlock::Create(iBuilder->getContext(), "setTermination", doSegmentFunction, 0);
17    BasicBlock * mmapSourceExit = BasicBlock::Create(iBuilder->getContext(), "mmapSourceExit", doSegmentFunction, 0);
18    Constant * blockItems = iBuilder->getSize(iBuilder->getBitBlockWidth());
19   
20    Function::arg_iterator args = doSegmentFunction->arg_begin();
21    Value * self = &*(args++);
22    Value * blocksToDo = &*(args);
23   
24    Value * fileItems = getScalarField(self, "fileSize");
25    Value * produced = getProducedItemCount(self, "sourceBuffer");
26    Value * itemsAvail = iBuilder->CreateSub(fileItems, produced);
27    Value * itemsMax = iBuilder->CreateMul(blocksToDo, blockItems);
28    Value * lessThanFullSegment = iBuilder->CreateICmpULT(itemsAvail, itemsMax);
29    Value * itemsToDo = iBuilder->CreateSelect(lessThanFullSegment, itemsAvail, itemsMax);
30    setProducedItemCount(self, "sourceBuffer", iBuilder->CreateAdd(produced, itemsToDo));
31   
32    iBuilder->CreateCondBr(lessThanFullSegment, setTermination, mmapSourceExit);
33    iBuilder->SetInsertPoint(setTermination);
34    setTerminationSignal(self);
35    iBuilder->CreateBr(mmapSourceExit);
36    iBuilder->SetInsertPoint(mmapSourceExit);
37    iBuilder->CreateRetVoid();
38    iBuilder->restoreIP(savePoint);
39}
40
41// The doBlock method is deprecated.   But in case it is used, just call doSegment with
42// 1 as the number of blocks to do.
43void MMapSourceKernel::generateDoBlockMethod() const {
44    auto savePoint = iBuilder->saveIP();
45    Module * m = iBuilder->getModule();
46    Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
47    Function * doSegmentFunction = m->getFunction(mKernelName + doSegment_suffix);
48    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", doBlockFunction, 0));
49    Value * self = getParameter(doBlockFunction, "self");
50    iBuilder->CreateCall(doSegmentFunction, {self, iBuilder->getSize(1)});
51    iBuilder->CreateRetVoid();
52    iBuilder->restoreIP(savePoint);
53}
54   
55}
Note: See TracBrowser for help on using the repository browser.