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

Last change on this file since 5257 was 5257, checked in by cameron, 3 years ago

finalSegment kernel methods initial check-in

File size: 3.2 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 * segmentItems = iBuilder->getSize(mSegmentBlocks * iBuilder->getBitBlockWidth());
19   
20   
21    Function::arg_iterator args = doSegmentFunction->arg_begin();
22    Value * self = &*(args);
23   
24    Value * fileItems = getScalarField(self, "fileSize");
25    if (mCodeUnitWidth > 8) {
26        fileItems = iBuilder->CreateUDiv(fileItems, iBuilder->getSize(mCodeUnitWidth/8));
27    }
28    Value * produced = getProducedItemCount(self, "sourceBuffer");
29    Value * itemsAvail = iBuilder->CreateSub(fileItems, produced);
30    Value * lessThanFullSegment = iBuilder->CreateICmpULT(itemsAvail, segmentItems);
31    Value * itemsToDo = iBuilder->CreateSelect(lessThanFullSegment, itemsAvail, segmentItems);
32    setProducedItemCount(self, "sourceBuffer", iBuilder->CreateAdd(produced, itemsToDo));
33   
34    iBuilder->CreateCondBr(lessThanFullSegment, setTermination, mmapSourceExit);
35    iBuilder->SetInsertPoint(setTermination);
36    setTerminationSignal(self);
37    iBuilder->CreateBr(mmapSourceExit);
38    iBuilder->SetInsertPoint(mmapSourceExit);
39    iBuilder->CreateRetVoid();
40    iBuilder->restoreIP(savePoint);
41}
42
43void MMapSourceKernel::generateFinalSegmentMethod() const {
44    auto savePoint = iBuilder->saveIP();
45    Module * m = iBuilder->getModule();
46    Function * finalSegmentFunction = m->getFunction(mKernelName + finalSegment_suffix);
47    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", finalSegmentFunction, 0));
48       
49    Function::arg_iterator args = finalSegmentFunction->arg_begin();
50    Value * self = &*(args++);
51    Value * blocksToDo = &*(args);
52   
53    createDoSegmentCall(self, blocksToDo);
54
55    iBuilder->CreateRetVoid();
56    iBuilder->restoreIP(savePoint);
57}
58
59
60// The doBlock method is deprecated.   But in case it is used, just call doSegment with
61// 1 as the number of blocks to do.
62void MMapSourceKernel::generateDoBlockMethod() const {
63    auto savePoint = iBuilder->saveIP();
64    Module * m = iBuilder->getModule();
65    Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
66    Function * doSegmentFunction = m->getFunction(mKernelName + doSegment_suffix);
67    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", doBlockFunction, 0));
68    Value * self = getParameter(doBlockFunction, "self");
69    iBuilder->CreateCall(doSegmentFunction, {self, iBuilder->getSize(1)});
70    iBuilder->CreateRetVoid();
71    iBuilder->restoreIP(savePoint);
72}
73   
74}
Note: See TracBrowser for help on using the repository browser.