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

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

Start of work to simplify kernel writing. Removed generateDoBlockLogic method.

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