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

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

Use dynamic size_t determination

File size: 2.2 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 parabix;
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
23// Single Block Buffer
24
25size_t SingleBlockBuffer::getBufferSize() {
26    return 1; //iBuilder->getBitBlockWidth();
27}
28
29llvm::Value * SingleBlockBuffer::allocateBuffer() {
30    mStreamSetBufferPtr = iBuilder->CreateAlloca(getStreamSetBlockType());
31    return mStreamSetBufferPtr;
32}
33
34// For a single block buffer, the block pointer is always the buffer base pointer.
35llvm::Value * SingleBlockBuffer::getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) {
36    return bufferBasePtr;
37}
38
39
40// External Unbounded Buffer
41
42size_t ExternalUnboundedBuffer::getBufferSize() {
43    return 0;
44}
45
46llvm::Value * ExternalUnboundedBuffer::allocateBuffer() {
47    throw std::runtime_error("External buffers cannot be allocated.");
48}
49
50llvm::Value * ExternalUnboundedBuffer::getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) {
51    return iBuilder->CreateGEP(getStreamSetBlockType(), bufferBasePtr, {blockNo});
52}
53
54
55// Circular Stack Allocated Buffer
56
57size_t CircularBuffer::getBufferSize() {
58    return mBufferBlocks; // * iBuilder->getBitBlockWidth();
59}
60
61llvm::Value * CircularBuffer::allocateBuffer() {
62    mStreamSetBufferPtr = iBuilder->CreateAlloca(getStreamSetBlockType(), ConstantInt::get(iBuilder->getSizeTy(), mBufferBlocks));
63    return mStreamSetBufferPtr;
64}
65
66llvm::Value * CircularBuffer::getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) {
67    return iBuilder->CreateGEP(getStreamSetBlockType(), bufferBasePtr, {iBuilder->CreateAnd(blockNo, ConstantInt::get(iBuilder->getSizeTy(), mBufferBlocks-1))});
68}
69
Note: See TracBrowser for help on using the repository browser.