Ignore:
Timestamp:
Nov 18, 2016, 1:46:55 PM (2 years ago)
Author:
nmedfort
Message:

Merged PabloFunction? and PabloKernel? classes. Updated projects where necessary.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/pablo/pablo_kernel.cpp

    r5204 r5217  
    88#include <llvm/Support/Debug.h>
    99#include <pablo/pe_var.h>
    10 #include <pablo/type/streamtype.h>
    1110#include <llvm/IR/Verifier.h>
     11#include <IDISA/idisa_builder.h>
     12#include <pablo/prototype.h>
    1213
    1314using namespace pablo;
    1415using namespace kernel;
    1516using namespace parabix;
     17using namespace IDISA;
    1618
    17 PabloKernel::PabloKernel(IDISA::IDISA_Builder * builder,
    18                          std::string kernelName,
    19                          PabloFunction * function)
    20 : KernelBuilder(builder, kernelName, {}, {}, {}, {}, {Binding{builder->getBitBlockType(), "EOFbit"}, Binding{builder->getBitBlockType(), "EOFmask"}})
    21 , mPabloFunction(function)
    22 , mPabloCompiler(new PabloCompiler(this, function))
     19Var * PabloKernel::addInput(const std::string name, Type * const type) {
     20    Var * param = new Var(mSymbolTable->make(name), type);
     21    mInputs.push_back(param);
     22    if (isa<StreamType>(type)) {
     23        Type * const resolvedType = cast<StreamType>(type)->resolveType(iBuilder);
     24        mStreamSetInputs.emplace_back(resolvedType, name);
     25    } else {
     26        mScalarInputs.emplace_back(type, name);
     27    }
     28    assert (mStreamSetInputs.size() + mScalarInputs.size() == mInputs.size());
     29    return param;
     30}
    2331
    24 {
    25     for (unsigned i = 0; i < function->getNumOfParameters(); ++i) {
    26         const auto var = function->getParameter(i);
    27         Type * type = var->getType();
    28         bool scalar = false;
    29         if (isa<StreamType>(type)) {
    30             type = cast<StreamType>(type)->resolveType(builder);
    31         } else if (type->isSingleValueType()) {
    32             if (isa<IntegerType>(type) && cast<IntegerType>(type)->getBitWidth() == 0) {
    33                 type = builder->getSizeTy();
    34             }
    35             scalar = true;
    36         }
     32Var * PabloKernel::addOutput(const std::string name, Type * const type) {
     33    Var * result = new Var(mSymbolTable->make(name), type);
     34    mOutputs.push_back(result);
     35    if (isa<StreamType>(type)) {
     36        Type * const resolvedType = cast<StreamType>(type)->resolveType(iBuilder);
     37        mStreamSetOutputs.emplace_back(resolvedType, name);
     38    } else {
     39        mScalarOutputs.emplace_back(type, name);
     40    }
     41    assert (mStreamSetOutputs.size() + mScalarOutputs.size() == mOutputs.size());
     42    return result;
     43}
    3744
    38         std::string name = var->getName()->to_string();
    39         if (scalar) {
    40             mScalarInputs.emplace_back(type, std::move(name));
    41         } else {
    42             mStreamSetInputs.emplace_back(type, std::move(name));
     45Var * PabloKernel::makeVariable(PabloAST * name, Type * const type) {
     46    Var * const var = new Var(name, type);
     47    mVariables.push_back(var);
     48    return var;
     49}
     50
     51Zeroes * PabloKernel::getNullValue(Type * type) {
     52    if (type == nullptr) {
     53        type = getStreamSetTy();
     54    }
     55    for (PabloAST * constant : mConstants) {
     56        if (isa<Zeroes>(constant) && constant->getType() == type) {
     57            return cast<Zeroes>(constant);
    4358        }
    4459    }
     60    Zeroes * value = new Zeroes(type);
     61    mConstants.push_back(value);
     62    return value;
     63}
    4564
    46     for (unsigned i = 0; i < function->getNumOfResults(); ++i) {
    47         const auto var = function->getResult(i);
    48         Type * type = var->getType();
    49         bool scalar = false;
    50         if (isa<StreamType>(type)) {
    51             type = cast<StreamType>(type)->resolveType(builder);
    52         } else if (type->isSingleValueType()) {
    53             if (isa<IntegerType>(type) && cast<IntegerType>(type)->getBitWidth() == 0) {
    54                 type = builder->getSizeTy();
    55             }
    56             scalar = true;
    57         }
    58 
    59         std::string name = var->getName()->to_string();
    60         if (scalar) {
    61             mScalarOutputs.emplace_back(type, std::move(name));
    62         } else {
    63             mStreamSetOutputs.emplace_back(type, std::move(name));
     65Ones * PabloKernel::getAllOnesValue(Type * type) {
     66    if (type == nullptr) {
     67        type = getStreamSetTy();
     68    }
     69    for (PabloAST * constant : mConstants) {
     70        if (isa<Ones>(constant) && constant->getType() == type) {
     71            return cast<Ones>(constant);
    6472        }
    6573    }
    66 
    67 
    68 }
    69 
    70 PabloKernel::~PabloKernel() {
    71     delete mPabloCompiler;
     74    Ones * value = new Ones(type);
     75    mConstants.push_back(value);
     76    return value;
    7277}
    7378
     
    8287    Module * m = iBuilder->getModule();
    8388    Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
    84     mPabloCompiler->compile(doBlockFunction);
    85     Function::arg_iterator args = doBlockFunction->arg_begin();
    86     Value * self = &*(args);
     89    auto args = doBlockFunction->arg_begin();
     90    Value * const self = &*(args);
     91    mPabloCompiler->compile(self, doBlockFunction);
    8792    Value * produced = getProducedItemCount(self);
    8893    produced = iBuilder->CreateAdd(produced, ConstantInt::get(iBuilder->getSizeTy(), iBuilder->getStride()));
     
    124129    iBuilder->restoreIP(savePoint);
    125130}
     131
     132PabloKernel::PabloKernel(IDISA::IDISA_Builder * builder, const std::string & kernelName)
     133: KernelBuilder(builder, kernelName, {}, {}, {}, {}, {Binding{builder->getBitBlockType(), "EOFbit"}, Binding{builder->getBitBlockType(), "EOFmask"}})
     134, mPabloCompiler(new PabloCompiler(this))
     135, mSymbolTable(new SymbolGenerator())
     136, mEntryBlock(PabloBlock::Create(this))
     137{
     138
     139}
     140
     141PabloKernel::~PabloKernel() {
     142    delete mPabloCompiler;
     143    delete mSymbolTable;
     144}
     145
Note: See TracChangeset for help on using the changeset viewer.