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

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

Optimized Symbol Generation (and fixed potential bug that could allow duplicate names being constructed); made PabloKernel? extend PabloAST (temporarily removed PabloAST::getName() to avoid diamond problem); added an internal scalar to PabloKernel? struct for each Count to avoid InOut? output scalar variable problem; allowed CodeMotionPass? to move code within the same scope but across a branch statement. Began work on separating Kernels into either Block-Oriented or Segment-Oriented kernels.

File size: 2.5 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() const {
20    auto savePoint = iBuilder->saveIP();
21    Module * m = iBuilder->getModule();
22    Function * doSegmentFunction = m->getFunction(mKernelName + doSegment_suffix);
23   
24    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), mKernelName + "_entry", doSegmentFunction, 0));
25    BasicBlock * setTermination = BasicBlock::Create(iBuilder->getContext(), "setTermination", doSegmentFunction, 0);
26    BasicBlock * mmapSourceExit = BasicBlock::Create(iBuilder->getContext(), "mmapSourceExit", doSegmentFunction, 0);
27    Constant * segmentItems = iBuilder->getSize(mSegmentBlocks * iBuilder->getBitBlockWidth());
28   
29   
30    auto args = doSegmentFunction->arg_begin();
31    Value * self = &*(args++);
32   
33    Value * fileItems = getScalarField(self, "fileSize");
34    if (mCodeUnitWidth > 8) {
35        fileItems = iBuilder->CreateUDiv(fileItems, iBuilder->getSize(mCodeUnitWidth/8));
36    }
37    Value * produced = getProducedItemCount(self, "sourceBuffer");   
38    Value * nextProduced = iBuilder->CreateAdd(produced, segmentItems);
39    Value * lessThanFullSegment = iBuilder->CreateICmpULT(fileItems, nextProduced);
40    produced = iBuilder->CreateSelect(lessThanFullSegment, fileItems, nextProduced);
41    setProducedItemCount(self, "sourceBuffer", produced);
42   
43    iBuilder->CreateCondBr(lessThanFullSegment, setTermination, mmapSourceExit);
44    iBuilder->SetInsertPoint(setTermination);
45    setTerminationSignal(self);
46    iBuilder->CreateBr(mmapSourceExit);
47   
48    iBuilder->SetInsertPoint(mmapSourceExit);
49    iBuilder->CreateRetVoid();
50    iBuilder->restoreIP(savePoint);
51}
52
53
54MMapSourceKernel::MMapSourceKernel(IDISA::IDISA_Builder * iBuilder, unsigned blocksPerSegment, unsigned codeUnitWidth)
55: SegmentOrientedKernel(iBuilder, "mmap_source", {}, {Binding{iBuilder->getStreamSetTy(1, codeUnitWidth), "sourceBuffer"}}, {Binding{iBuilder->getSizeTy(), "fileSize"}}, {}, {})
56, mSegmentBlocks(blocksPerSegment)
57, mCodeUnitWidth(codeUnitWidth) {
58
59}
60
61}
Note: See TracBrowser for help on using the repository browser.