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

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

Processing rate attributes on stream set inputs and outputs; initial check-in

File size: 2.0 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(Value *doFinal, const std::vector<Value *> &producerPos) {
20    BasicBlock * setTermination = CreateBasicBlock("setTermination");
21    BasicBlock * mmapSourceExit = CreateBasicBlock("mmapSourceExit");
22    ConstantInt * segmentItems = iBuilder->getSize(mSegmentBlocks * iBuilder->getBitBlockWidth());
23    Value * fileItems = getScalarField("fileSize");
24    if (mCodeUnitWidth > 8) {
25        fileItems = iBuilder->CreateUDiv(fileItems, iBuilder->getSize(mCodeUnitWidth / 8));
26    }
27    Value * produced = getProducedItemCount("sourceBuffer");
28    Value * nextProduced = iBuilder->CreateAdd(produced, segmentItems);
29    Value * lessThanFullSegment = iBuilder->CreateICmpULT(fileItems, nextProduced);
30    produced = iBuilder->CreateSelect(lessThanFullSegment, fileItems, nextProduced);
31    setProducedItemCount("sourceBuffer", produced);
32
33    iBuilder->CreateCondBr(lessThanFullSegment, setTermination, mmapSourceExit);
34    iBuilder->SetInsertPoint(setTermination);
35    setTerminationSignal();
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",
44    {},
45    {Binding{iBuilder->getStreamSetTy(1, codeUnitWidth), "sourceBuffer"}},
46    {Binding{iBuilder->getSizeTy(), "fileSize"}}, {}, {})
47, mSegmentBlocks(blocksPerSegment)
48, mCodeUnitWidth(codeUnitWidth) {
49
50}
51
52}
Note: See TracBrowser for help on using the repository browser.