source: icGREP/icgrep-devel/icgrep/kernels/streamset.cpp @ 5098

Last change on this file since 5098 was 5077, checked in by cameron, 3 years ago

Correction for segment processing

File size: 1.5 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
6   
7#include <kernels/streamset.h>
8#include <vector>
9#include <IDISA/idisa_builder.h>
10#include <llvm/IR/Type.h>
11   
12using namespace kernel;
13
14llvm::Type * StreamSetType::getStreamSetBlockType(IDISA::IDISA_Builder * iBuilder) {
15    llvm::Type * streamType = mFieldWidth == 1 ? iBuilder->getBitBlockType() : ArrayType::get(iBuilder->getBitBlockType(), mFieldWidth);
16    return ArrayType::get(streamType, mStreamCount);
17}
18
19llvm::Type * StreamSetBuffer::getStreamSetBlockType() {
20    return mStreamSetType.getStreamSetBlockType(iBuilder);
21}
22
23llvm::Type * StreamSetBuffer::getStreamSetBufferType() {
24    if (mSegmentSize == 1) return getStreamSetBlockType();
25    return ArrayType::get(getStreamSetBlockType(), mSegmentSize);
26}
27
28llvm::Value * StreamSetBuffer::allocateBuffer() {
29    if (mStreamSetBufferPtr == nullptr) {
30        mStreamSetBufferPtr = iBuilder->CreateAlloca(getStreamSetBlockType(), iBuilder->getInt32(mSegmentSize));
31    }
32    return mStreamSetBufferPtr;
33}
34
35llvm::Value * StreamSetBuffer::getBlockPointer(llvm::Value * blockNo) {
36    if (mSegmentSize == 1) return mStreamSetBufferPtr;
37    if (mSegmentSize == 0) return
38        iBuilder->CreateGEP(getStreamSetBlockType(), mStreamSetBufferPtr, {blockNo});
39    Value * offset = iBuilder->CreateURem(blockNo, iBuilder->getInt64(mSegmentSize));
40    return iBuilder->CreateGEP(getStreamSetBlockType(), mStreamSetBufferPtr, {offset});
41}
42
Note: See TracBrowser for help on using the repository browser.