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

Last change on this file since 5045 was 5044, checked in by cameron, 3 years ago

Stream set declaraations and buffers

File size: 1.4 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::Value * StreamSetBuffer::allocateBuffer() {
24    if (mStreamSetBufferPtr == nullptr) {
25        llvm::Type * streamBufferType = getStreamSetBlockType();
26        if (mSegmentSize > 1) streamBufferType = ArrayType::get(getStreamSetBlockType(), mSegmentSize);
27        mStreamSetBufferPtr = iBuilder->CreateAlloca(streamBufferType);
28    }
29    return mStreamSetBufferPtr;
30}
31
32llvm::Value * StreamSetBuffer::getBlockPointer(llvm::Value * blockNo) {
33    if (mSegmentSize == 1) return mStreamSetBufferPtr;
34    if (mSegmentSize == 0) return
35        iBuilder->CreateGEP(getStreamSetBlockType(), mStreamSetBufferPtr, {blockNo});
36    Value * offset = iBuilder->CreateURem(blockNo, iBuilder->getInt32(mSegmentSize));
37    return iBuilder->CreateGEP(getStreamSetBlockType(), mStreamSetBufferPtr, {offset});
38}
39
Note: See TracBrowser for help on using the repository browser.