source: icGREP/icgrep-devel/icgrep/pablo/pablo_kernel.cpp @ 5297

Last change on this file since 5297 was 5297, checked in by nmedfort, 2 years ago

Partial removal of BlockNo?

File size: 3.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#include "pablo_kernel.h"
7#include <pablo/codegenstate.h>
8#include <pablo/pablo_compiler.h>
9#include <pablo/pe_var.h>
10#include <pablo/pe_zeroes.h>
11#include <pablo/pe_ones.h>
12//#include <llvm/IR/Module.h>
13//#include <llvm/IR/Verifier.h>
14//#include <IR_Gen/idisa_builder.h>
15
16using namespace pablo;
17using namespace kernel;
18using namespace parabix;
19using namespace IDISA;
20using namespace llvm;
21
22Var * PabloKernel::addInput(const std::string & name, Type * const type) {
23    Var * param = new (mAllocator) Var(mSymbolTable->makeString(name, iBuilder), type, mAllocator, Var::ReadOnly);
24    param->addUser(this);
25    mInputs.push_back(param);
26    mVariables.push_back(param);
27    if (isa<ArrayType>(type) || isa<StreamType>(type)) {
28        mStreamSetInputs.emplace_back(type, name);
29    } else {
30        mScalarInputs.emplace_back(type, name);
31    }
32    assert (mStreamSetInputs.size() + mScalarInputs.size() == mInputs.size());
33    return param;
34}
35
36Var * PabloKernel::addOutput(const std::string & name, Type * const type) {
37    Var * result = new (mAllocator) Var(mSymbolTable->makeString(name, iBuilder), type, mAllocator, Var::ReadNone);
38    result->addUser(this);
39    mOutputs.push_back(result);
40    mVariables.push_back(result);
41    if (isa<ArrayType>(type) || isa<StreamType>(type)) {
42        mStreamSetOutputs.emplace_back(type, name);
43    } else {
44        mScalarOutputs.emplace_back(type, name);
45    }
46    assert (mStreamSetOutputs.size() + mScalarOutputs.size() == mOutputs.size());
47    return result;
48}
49
50Var * PabloKernel::makeVariable(String * name, Type * const type) {
51    Var * const var = new (mAllocator) Var(name, type, mAllocator);
52    mVariables.push_back(var);
53    return var;
54}
55
56Zeroes * PabloKernel::getNullValue(Type * type) {
57    if (type == nullptr) {
58        type = getStreamTy();
59    }
60    for (PabloAST * constant : mConstants) {
61        if (isa<Zeroes>(constant) && constant->getType() == type) {
62            return cast<Zeroes>(constant);
63        }
64    }
65    Zeroes * value = new (mAllocator) Zeroes(type, mAllocator);
66    mConstants.push_back(value);
67    return value;
68}
69
70Ones * PabloKernel::getAllOnesValue(Type * type) {
71    if (type == nullptr) {
72        type = getStreamTy();
73    }
74    for (PabloAST * constant : mConstants) {
75        if (isa<Ones>(constant) && constant->getType() == type) {
76            return cast<Ones>(constant);
77        }
78    }
79    Ones * value = new (mAllocator) Ones(type, mAllocator);
80    mConstants.push_back(value);
81    return value;
82}
83
84void PabloKernel::prepareKernel() {
85    mPabloCompiler->initializeKernelData();
86    BlockOrientedKernel::prepareKernel();
87}
88
89void PabloKernel::generateDoBlockMethod() {
90    mPabloCompiler->compile();
91}
92
93void PabloKernel::generateFinalBlockMethod(Value * remainingBytes) {
94    // Standard Pablo convention for final block processing: set a bit marking
95    // the position just past EOF, as well as a mask marking all positions past EOF.
96    setScalarField("EOFbit", iBuilder->bitblock_set_bit(remainingBytes));
97    setScalarField("EOFmask", iBuilder->bitblock_mask_from(remainingBytes));
98    CreateDoBlockMethodCall();
99}
100
101PabloKernel::PabloKernel(IDISA::IDISA_Builder * builder, std::string kernelName)
102: BlockOrientedKernel(builder, std::move(kernelName), {}, {}, {}, {}, {Binding{builder->getBitBlockType(), "EOFbit"}, Binding{builder->getBitBlockType(), "EOFmask"}})
103, PabloAST(PabloAST::ClassTypeId::Kernel, nullptr, mAllocator)
104, mPabloCompiler(new PabloCompiler(this))
105, mSymbolTable(new SymbolGenerator(mAllocator))
106, mEntryBlock(PabloBlock::Create(this)) {
107    setDoBlockUpdatesProducedItemCountsAttribute(false);
108}
109
110PabloKernel::~PabloKernel() {
111    delete mPabloCompiler;
112    delete mSymbolTable; 
113}
114
Note: See TracBrowser for help on using the repository browser.