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

Last change on this file since 5385 was 5377, checked in by nmedfort, 3 years ago

Support for stdin. Needs more testing.

File size: 2.3 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
21    BasicBlock * entryBlock = iBuilder->GetInsertBlock();
22    BasicBlock * setTermination = CreateBasicBlock("setTermination");
23    BasicBlock * mmapSourceExit = CreateBasicBlock("mmapSourceExit");
24    ConstantInt * segmentItems = iBuilder->getSize(mSegmentBlocks * iBuilder->getBitBlockWidth());
25    Value * fileItems = getScalarField("fileSize");
26    if (mCodeUnitWidth > 8) {
27        fileItems = iBuilder->CreateUDiv(fileItems, iBuilder->getSize(mCodeUnitWidth / 8));
28    }
29    Value * produced = getProducedItemCount("sourceBuffer");
30    produced = iBuilder->CreateAdd(produced, segmentItems);
31    Value * lessThanFullSegment = iBuilder->CreateICmpULT(fileItems, produced);
32    iBuilder->CreateCondBr(lessThanFullSegment, setTermination, mmapSourceExit);
33    iBuilder->SetInsertPoint(setTermination);
34    setTerminationSignal();
35    iBuilder->CreateBr(mmapSourceExit);
36
37    iBuilder->SetInsertPoint(mmapSourceExit);
38
39    PHINode * itemsRead = iBuilder->CreatePHI(produced->getType(), 2);
40    itemsRead->addIncoming(produced, entryBlock);
41    itemsRead->addIncoming(fileItems, setTermination);
42    setProducedItemCount("sourceBuffer", itemsRead);
43}
44
45void MMapSourceKernel::generateInitMethod() {
46//    Value * fileSize = getScalarField("fileSize");
47//    fileSize = iBuilder->CreateUDiv(fileSize, iBuilder->getSize(mCodeUnitWidth / 8));
48//    setProducedItemCount("sourceBuffer", fileSize);
49}
50
51MMapSourceKernel::MMapSourceKernel(IDISA::IDISA_Builder * iBuilder, unsigned blocksPerSegment, unsigned codeUnitWidth)
52: SegmentOrientedKernel(iBuilder, "mmap_source",
53    {},
54    {Binding{iBuilder->getStreamSetTy(1, codeUnitWidth), "sourceBuffer"}},
55    {Binding{iBuilder->getSizeTy(), "fileSize"}}, {}, {})
56, mSegmentBlocks(blocksPerSegment)
57, mCodeUnitWidth(codeUnitWidth) {
58
59}
60
61}
Note: See TracBrowser for help on using the repository browser.