source: icGREP/icgrep-devel/icgrep/kernels/stdout_kernel.cpp @ 5266

Last change on this file since 5266 was 5265, checked in by cameron, 3 years ago

Eliminate unneeded doBlock functions

File size: 2.3 KB
Line 
1/*
2 *  Copyright (c) 2016 International Characters.
3 *  This software is licensed to the public under the Open Software License 3.0.
4 */
5#include "stdout_kernel.h"
6#include <llvm/IR/Module.h>
7#include <IR_Gen/idisa_builder.h>
8
9using namespace llvm;
10
11namespace kernel {
12           
13// Rather than using doBlock logic to write one block at a time, this custom
14// doSegment method, writes the entire segment with a single write call.
15void StdOutKernel::generateDoSegmentMethod() const {
16    auto savePoint = iBuilder->saveIP();
17    Module * m = iBuilder->getModule();
18    Function * doSegmentFunction = m->getFunction(mKernelName + doSegment_suffix);
19    Type * i8PtrTy = iBuilder->getInt8PtrTy();
20   
21    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", doSegmentFunction, 0));
22    Constant * blockItems = iBuilder->getSize(iBuilder->getBitBlockWidth());
23    Constant * itemBytes = iBuilder->getSize(mCodeUnitWidth/8);
24   
25    Function::arg_iterator args = doSegmentFunction->arg_begin();
26    Value * self = &*(args++);
27    /* unused Value * doFinal = &*(args++);*/ args++;
28    Value * producerPos = &*(args++);
29    ////iBuilder->CallPrintInt("blocksToDo", blocksToDo);
30    Value * streamStructPtr = getStreamSetStructPtr(self, "codeUnitBuffer");
31    //iBuilder->CallPrintInt("streamStructPtr", iBuilder->CreatePtrToInt(streamStructPtr, iBuilder->getInt64Ty()));
32
33    //iBuilder->CallPrintInt("producerPos", producerPos);
34    Value * processed = getProcessedItemCount(self, "codeUnitBuffer");
35    Value * itemsToDo = iBuilder->CreateSub(producerPos, processed);
36   
37    Value * blockNo = getScalarField(self, blockNoScalar);
38    Value * byteOffset = iBuilder->CreateMul(iBuilder->CreateURem(processed, blockItems), itemBytes);
39    Value * bytePtr = getStreamView(i8PtrTy, self, "codeUnitBuffer", blockNo, byteOffset);
40    iBuilder->CreateWriteCall(iBuilder->getInt32(1), bytePtr, iBuilder->CreateMul(itemsToDo, itemBytes));
41
42    processed = iBuilder->CreateAdd(processed, itemsToDo);
43    setProcessedItemCount(self, "codeUnitBuffer", processed);
44    setScalarField(self, blockNoScalar, iBuilder->CreateUDiv(processed, blockItems));
45    mStreamSetInputBuffers[0]->setConsumerPos(streamStructPtr, processed);
46
47    iBuilder->CreateRetVoid();
48    iBuilder->restoreIP(savePoint);
49}
50
51}
Note: See TracBrowser for help on using the repository browser.