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

Last change on this file since 5286 was 5286, checked in by nmedfort, 2 years ago

Continuation of work to simplify Kernel writing

File size: 2.1 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 "mmap_kernel.h"
6#include <llvm/IR/Function.h>  // for Function, Function::arg_iterator
7#include <llvm/IR/Module.h>
8#include <IR_Gen/idisa_builder.h>
9#include <kernels/streamset.h>
10namespace llvm { class BasicBlock; }
11namespace llvm { class Constant; }
12namespace llvm { class Module; }
13namespace llvm { class Value; }
14
15using namespace llvm;
16
17namespace kernel {
18           
19void MMapSourceKernel::generateDoSegmentMethod(Function * doSegmentFunction, Value *self, Value *doFinal, const std::vector<Value *> &producerPos) const {
20    BasicBlock * setTermination = BasicBlock::Create(iBuilder->getContext(), "setTermination", doSegmentFunction, 0);
21    BasicBlock * mmapSourceExit = BasicBlock::Create(iBuilder->getContext(), "mmapSourceExit", doSegmentFunction, 0);
22    ConstantInt * segmentItems = iBuilder->getSize(mSegmentBlocks * iBuilder->getBitBlockWidth());
23    Value * fileItems = getScalarField(self, "fileSize");
24    if (mCodeUnitWidth > 8) {
25        fileItems = iBuilder->CreateUDiv(fileItems, iBuilder->getSize(mCodeUnitWidth / 8));
26    }
27    Value * produced = getProducedItemCount(self, "sourceBuffer");   
28    Value * nextProduced = iBuilder->CreateAdd(produced, segmentItems);
29    Value * lessThanFullSegment = iBuilder->CreateICmpULT(fileItems, nextProduced);
30    produced = iBuilder->CreateSelect(lessThanFullSegment, fileItems, nextProduced);
31    setProducedItemCount(self, "sourceBuffer", produced);
32
33    iBuilder->CreateCondBr(lessThanFullSegment, setTermination, mmapSourceExit);
34    iBuilder->SetInsertPoint(setTermination);
35    setTerminationSignal(self);
36    iBuilder->CreateBr(mmapSourceExit);   
37
38    iBuilder->SetInsertPoint(mmapSourceExit);
39}
40
41
42MMapSourceKernel::MMapSourceKernel(IDISA::IDISA_Builder * iBuilder, unsigned blocksPerSegment, unsigned codeUnitWidth)
43: SegmentOrientedKernel(iBuilder, "mmap_source", {}, {Binding{iBuilder->getStreamSetTy(1, codeUnitWidth), "sourceBuffer"}}, {Binding{iBuilder->getSizeTy(), "fileSize"}}, {}, {})
44, mSegmentBlocks(blocksPerSegment)
45, mCodeUnitWidth(codeUnitWidth) {
46
47}
48
49}
Note: See TracBrowser for help on using the repository browser.