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

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

Remove debug message

File size: 2.8 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#include <iostream>
12   
13using namespace parabix;
14
15llvm::Type * StreamSetType::getStreamSetBlockType(IDISA::IDISA_Builder * iBuilder) {
16    llvm::Type * streamType = mFieldWidth == 1 ? iBuilder->getBitBlockType() : ArrayType::get(iBuilder->getBitBlockType(), mFieldWidth);
17    return ArrayType::get(streamType, mStreamCount);
18}
19
20llvm::PointerType * StreamSetBuffer::getStreamBufferPointerType() {
21    return PointerType::get(mStreamSetType.getStreamSetBlockType(iBuilder), 0);
22}
23
24// Single Block Buffer
25
26size_t SingleBlockBuffer::getBufferSize() {
27    return 1; //iBuilder->getBitBlockWidth();
28}
29
30llvm::Value * SingleBlockBuffer::allocateBuffer() {
31    mStreamSetBufferPtr = iBuilder->CreateAlloca(mStreamSetType.getStreamSetBlockType(iBuilder));
32    return mStreamSetBufferPtr;
33}
34
35// For a single block buffer, the block pointer is always the buffer base pointer.
36llvm::Value * SingleBlockBuffer::getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) {
37    return bufferBasePtr;
38}
39
40
41// External Unbounded Buffer
42
43size_t ExternalUnboundedBuffer::getBufferSize() {
44    return 0;
45}
46
47void ExternalUnboundedBuffer::setStreamSetBuffer(llvm::Value * ptr) {
48    PointerType * t = PointerType::get(mStreamSetType.getStreamSetBlockType(iBuilder), mAddrSpace);
49   
50    mStreamSetBufferPtr = iBuilder->CreatePointerBitCastOrAddrSpaceCast(ptr, t);
51}
52
53llvm::PointerType * ExternalUnboundedBuffer::getStreamBufferPointerType() {
54    return PointerType::get(mStreamSetType.getStreamSetBlockType(iBuilder), mAddrSpace);
55}
56
57llvm::Value * ExternalUnboundedBuffer::allocateBuffer() {
58    throw std::runtime_error("External buffers cannot be allocated.");
59}
60
61llvm::Value * ExternalUnboundedBuffer::getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) {
62    PointerType * t = getStreamBufferPointerType();
63    return iBuilder->CreateGEP(iBuilder->CreatePointerBitCastOrAddrSpaceCast(bufferBasePtr, t), {blockNo});
64}
65
66
67// Circular Stack Allocated Buffer
68
69size_t CircularBuffer::getBufferSize() {
70    return mBufferBlocks; // * iBuilder->getBitBlockWidth();
71}
72
73llvm::Value * CircularBuffer::allocateBuffer() {
74    mStreamSetBufferPtr = iBuilder->CreateAlloca(mStreamSetType.getStreamSetBlockType(iBuilder), ConstantInt::get(iBuilder->getSizeTy(), mBufferBlocks));
75    return mStreamSetBufferPtr;
76}
77
78llvm::Value * CircularBuffer::getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) {
79    return iBuilder->CreateGEP(mStreamSetType.getStreamSetBlockType(iBuilder), bufferBasePtr, {iBuilder->CreateAnd(blockNo, ConstantInt::get(iBuilder->getSizeTy(), mBufferBlocks-1))});
80}
81
Note: See TracBrowser for help on using the repository browser.