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

Last change on this file since 5413 was 5398, checked in by nmedfort, 3 years ago

Continued work on processing stdin input. Partial integration of ParabixDriver? methods into icgrep and editd. Object cache does not currently work for recursive REs.

File size: 2.1 KB
RevLine 
[5248]1/*
2 *  Copyright (c) 2017 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 */
[5260]5#include "mmap_kernel.h"
6#include <llvm/IR/Function.h>  // for Function, Function::arg_iterator
7#include <llvm/IR/Module.h>
[5248]8#include <IR_Gen/idisa_builder.h>
[5260]9#include <kernels/streamset.h>
10namespace llvm { class BasicBlock; }
11namespace llvm { class Constant; }
12namespace llvm { class Module; }
13namespace llvm { class Value; }
[5248]14
[5260]15using namespace llvm;
16
[5248]17namespace kernel {
[5377]18
[5292]19void MMapSourceKernel::generateDoSegmentMethod(Value *doFinal, const std::vector<Value *> &producerPos) {
[5377]20
21    BasicBlock * entryBlock = iBuilder->GetInsertBlock();
[5292]22    BasicBlock * setTermination = CreateBasicBlock("setTermination");
23    BasicBlock * mmapSourceExit = CreateBasicBlock("mmapSourceExit");
[5286]24    ConstantInt * segmentItems = iBuilder->getSize(mSegmentBlocks * iBuilder->getBitBlockWidth());
[5292]25    Value * fileItems = getScalarField("fileSize");
[5255]26    if (mCodeUnitWidth > 8) {
[5286]27        fileItems = iBuilder->CreateUDiv(fileItems, iBuilder->getSize(mCodeUnitWidth / 8));
[5255]28    }
[5292]29    Value * produced = getProducedItemCount("sourceBuffer");
[5377]30    produced = iBuilder->CreateAdd(produced, segmentItems);
31    Value * lessThanFullSegment = iBuilder->CreateICmpULT(fileItems, produced);
[5248]32    iBuilder->CreateCondBr(lessThanFullSegment, setTermination, mmapSourceExit);
33    iBuilder->SetInsertPoint(setTermination);
[5292]34    setTerminationSignal();
[5377]35    iBuilder->CreateBr(mmapSourceExit);
[5286]36
[5248]37    iBuilder->SetInsertPoint(mmapSourceExit);
[5377]38
39    PHINode * itemsRead = iBuilder->CreatePHI(produced->getType(), 2);
40    itemsRead->addIncoming(produced, entryBlock);
41    itemsRead->addIncoming(fileItems, setTermination);
42    setProducedItemCount("sourceBuffer", itemsRead);
[5248]43}
44
[5267]45MMapSourceKernel::MMapSourceKernel(IDISA::IDISA_Builder * iBuilder, unsigned blocksPerSegment, unsigned codeUnitWidth)
[5391]46: SegmentOrientedKernel(iBuilder, "Parabix:mmap_source",
[5307]47    {},
[5325]48    {Binding{iBuilder->getStreamSetTy(1, codeUnitWidth), "sourceBuffer"}},
[5307]49    {Binding{iBuilder->getSizeTy(), "fileSize"}}, {}, {})
[5260]50, mSegmentBlocks(blocksPerSegment)
51, mCodeUnitWidth(codeUnitWidth) {
52
[5248]53}
[5260]54
55}
Note: See TracBrowser for help on using the repository browser.