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

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

Pablo Kernels subclass KernelBuilder?, provide generateKernel overrride

File size: 2.9 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/pablo_kernel.h>
7#include <pablo/pablo_compiler.h>
8#include <llvm/Support/Debug.h>
9
10
11using namespace pablo;
12using namespace kernel;
13
14PabloKernel::PabloKernel(IDISA::IDISA_Builder * builder,
15                         std::string kernelName,
16                         PabloFunction * function,
17                         std::vector<std::string> accumulators) :
18    KernelBuilder(builder, kernelName,
19                    {StreamSetBinding{StreamSetType(function->getNumOfParameters(), 1), "inputs"}},
20                    {StreamSetBinding{StreamSetType(function->getNumOfResults(), 1), "outputs"}},
21                    {},
22                    {},
23                    {ScalarBinding{builder->getBitBlockType(), "EOFmark"}}),
24    mPabloFunction(function) {
25    mScalarOutputs = accumBindings(accumulators);
26    pablo_compiler = new PabloCompiler(builder, this, function);
27}
28
29std::vector<ScalarBinding> PabloKernel::accumBindings(std::vector<std::string> accum_names) {
30    std::vector<ScalarBinding> vec;
31    Type * accum_t = iBuilder->getInt64Ty();
32    for (auto a : accum_names) {
33        vec.push_back(ScalarBinding{accum_t, a});
34    }
35    return vec;
36}
37
38void PabloKernel::prepareKernel() {
39    errs() << "PabloKernel::prepareKernel\n";
40    Type * carryDataType = pablo_compiler->initializeCarryData();
41    addScalar(carryDataType, "carries");
42    finalizeKernelStateType();
43}
44
45void PabloKernel::generateKernel() {
46    KernelBuilder::generateKernel();
47    Module * m = iBuilder->getModule();
48    addFinalBlockMethod(m);
49    pablo_compiler->compile(m->getFunction(mKernelName + doBlock_suffix));
50}
51
52void PabloKernel::addFinalBlockMethod(Module * m) {
53    Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
54    Function * finalBlockFunction = m->getFunction(mKernelName + finalBlock_suffix);
55    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "fb_entry", finalBlockFunction, 0));
56    // Final Block arguments: self, remaining, then the standard DoBlock args.
57    Function::arg_iterator args = finalBlockFunction->arg_begin();
58    Value * self = &*(args++);
59    Value * remaining = &*(args++);
60    std::vector<Value *> doBlockArgs = {self};
61    while (args != finalBlockFunction->arg_end()){
62        doBlockArgs.push_back(&*args++);
63    }
64    // Standard Pablo convention for final block processing: set a bit marking
65    // the position just past EOF.
66    Type * bitBlockInt = iBuilder->getIntNTy(iBuilder->getBitBlockWidth());
67    Value * EOFmark = iBuilder->CreateShl(ConstantInt::get(bitBlockInt, 1), iBuilder->CreateZExt(remaining, bitBlockInt));
68    setScalarField(self, "EOFmark", iBuilder->CreateBitCast(EOFmark, iBuilder->getBitBlockType()));
69    iBuilder->CreateCall(doBlockFunction, doBlockArgs);
70    iBuilder->CreateRetVoid();
71}
72
Note: See TracBrowser for help on using the repository browser.