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

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

AddrSpace? parameter for external buffers

File size: 2.6 KB
RevLine 
[5044]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>
[5122]11#include <iostream>
[5044]12   
[5100]13using namespace parabix;
[5044]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}
[5076]19
[5044]20llvm::Type * StreamSetBuffer::getStreamSetBlockType() {
21    return mStreamSetType.getStreamSetBlockType(iBuilder);
22}
23
[5100]24// Single Block Buffer
25
[5106]26size_t SingleBlockBuffer::getBufferSize() {
[5100]27    return 1; //iBuilder->getBitBlockWidth();
[5076]28}
29
[5100]30llvm::Value * SingleBlockBuffer::allocateBuffer() {
31    mStreamSetBufferPtr = iBuilder->CreateAlloca(getStreamSetBlockType());
[5044]32    return mStreamSetBufferPtr;
33}
34
[5100]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;
[5044]38}
39
[5100]40
41// External Unbounded Buffer
42
[5106]43size_t ExternalUnboundedBuffer::getBufferSize() {
[5100]44    return 0;
45}
46
[5122]47void ExternalUnboundedBuffer::setStreamSetBuffer(llvm::Value * ptr) {
48    PointerType * t = PointerType::get(getStreamSetBlockType(), mAddrSpace);
49   
50    mStreamSetBufferPtr = iBuilder->CreatePointerBitCastOrAddrSpaceCast(ptr, t);
51    std::cerr << "mStreamSetBufferPtr\n";
52}
53
[5100]54llvm::Value * ExternalUnboundedBuffer::allocateBuffer() {
55    throw std::runtime_error("External buffers cannot be allocated.");
56}
57
58llvm::Value * ExternalUnboundedBuffer::getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) {
[5122]59    PointerType * t = PointerType::get(getStreamSetBlockType(), mAddrSpace);
60    return iBuilder->CreateGEP(iBuilder->CreatePointerBitCastOrAddrSpaceCast(bufferBasePtr, t), {blockNo});
[5100]61}
62
63
64// Circular Stack Allocated Buffer
65
[5106]66size_t CircularBuffer::getBufferSize() {
[5100]67    return mBufferBlocks; // * iBuilder->getBitBlockWidth();
68}
69
70llvm::Value * CircularBuffer::allocateBuffer() {
[5106]71    mStreamSetBufferPtr = iBuilder->CreateAlloca(getStreamSetBlockType(), ConstantInt::get(iBuilder->getSizeTy(), mBufferBlocks));
[5100]72    return mStreamSetBufferPtr;
73}
74
75llvm::Value * CircularBuffer::getStreamSetBlockPointer(llvm::Value * bufferBasePtr, llvm::Value * blockNo) {
[5106]76    return iBuilder->CreateGEP(getStreamSetBlockType(), bufferBasePtr, {iBuilder->CreateAnd(blockNo, ConstantInt::get(iBuilder->getSizeTy(), mBufferBlocks-1))});
[5100]77}
78
Note: See TracBrowser for help on using the repository browser.