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

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

Use dynamic size_t determination

File size: 3.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;
13using namespace parabix;
14
15PabloKernel::PabloKernel(IDISA::IDISA_Builder * builder,
16                         std::string kernelName,
17                         PabloFunction * function,
18                         StreamSetBuffer & inputBuffer,
19                         StreamSetBuffer & outputBuffer,
20                         std::vector<std::string> accumulators) :
21    KernelBuilder(builder, kernelName,
22                    {StreamSetBinding{inputBuffer, "inputs"}},
23                    {StreamSetBinding{outputBuffer, "outputs"}},
24                    {},
25                    {},
26                    {ScalarBinding{builder->getBitBlockType(), "EOFmark"}}),
27    mPabloFunction(function) {
28    unsigned output_streams = function->getNumOfResults();
29    assert (output_streams > 0);
30    mScalarOutputs = accumBindings(accumulators);
31    pablo_compiler = new PabloCompiler(builder, this, function);
32}
33
34PabloKernel::PabloKernel(IDISA::IDISA_Builder * builder,
35                         std::string kernelName,
36                         PabloFunction * function,
37                         StreamSetBuffer & inputBuffer,
38                         std::vector<std::string> accumulators) :
39    KernelBuilder(builder, kernelName,
40                    {StreamSetBinding{inputBuffer, "inputs"}},
41                    {},
42                    {},
43                    {},
44                    {ScalarBinding{builder->getBitBlockType(), "EOFmark"}}),
45    mPabloFunction(function) {
46    unsigned output_streams = function->getNumOfResults();
47    assert (output_streams == 0);
48    mScalarOutputs = accumBindings(accumulators);
49    pablo_compiler = new PabloCompiler(builder, this, function);
50}
51
52
53std::vector<ScalarBinding> PabloKernel::accumBindings(std::vector<std::string> accum_names) {
54    std::vector<ScalarBinding> vec;
55    Type * accum_t = iBuilder->getSizeTy();
56    for (auto a : accum_names) {
57        vec.push_back(ScalarBinding{accum_t, a});
58        addScalar(accum_t, a);
59    }
60    return vec;
61}
62
63void PabloKernel::prepareKernel() {
64    Type * carryDataType = pablo_compiler->initializeCarryData();
65    addScalar(carryDataType, "carries");
66    KernelBuilder::prepareKernel();
67}
68
69void PabloKernel::generateDoBlockMethod() {
70    IDISA::IDISA_Builder::InsertPoint savePoint = iBuilder->saveIP();
71    Module * m = iBuilder->getModule();
72    pablo_compiler->compile(m->getFunction(mKernelName + doBlock_suffix));
73    iBuilder->restoreIP(savePoint);
74}
75
76void PabloKernel::generateFinalBlockMethod() {
77    IDISA::IDISA_Builder::InsertPoint savePoint = iBuilder->saveIP();
78    Module * m = iBuilder->getModule();
79    Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
80    Function * finalBlockFunction = m->getFunction(mKernelName + finalBlock_suffix);
81    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "fb_entry", finalBlockFunction, 0));
82    // Final Block arguments: self, remaining, then the standard DoBlock args.
83    Function::arg_iterator args = finalBlockFunction->arg_begin();
84    Value * self = &*(args++);
85    Value * remaining = &*(args++);
86    std::vector<Value *> doBlockArgs = {self};
87    while (args != finalBlockFunction->arg_end()){
88        doBlockArgs.push_back(&*args++);
89    }
90    // Standard Pablo convention for final block processing: set a bit marking
91    // the position just past EOF.
92    Type * bitBlockInt = iBuilder->getIntNTy(iBuilder->getBitBlockWidth());
93    Value * EOFmark = iBuilder->CreateShl(ConstantInt::get(bitBlockInt, 1), iBuilder->CreateZExt(remaining, bitBlockInt));
94    setScalarField(self, "EOFmark", iBuilder->CreateBitCast(EOFmark, iBuilder->getBitBlockType()));
95    iBuilder->CreateCall(doBlockFunction, doBlockArgs);
96    iBuilder->CreateRetVoid();
97    iBuilder->restoreIP(savePoint);
98}
99
Note: See TracBrowser for help on using the repository browser.