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

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

Initial check-in for Pablo Kernel - incomplete

File size: 2.4 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
7#include <pablo/pablo_kernel.h>
8
9
10using namespace pablo;
11
12PabloKernel::PabloKernel(IDISA::IDISA_Builder * builder,
13                    std::string kernelName,
14                    PabloFunction * pf,
15                    std::vector<string> accumulators);
16    KernelInterface(iBuilder, kernelName,
17                    {StreamSetBinding{StreamSetType(pf->NumOfParameters(), 1), "inputs"}},
18                    {StreamSetBinding{StreamSetType(pf->NumOfResults(), 1), "outputs"}},
19                    {},
20                    accumBindings(accumulators),
21                    {ScalarBinding(iBuilder->getBitBlockType(), "EOFmark"}) {}
22
23std::vector<ScalarBinding> accumBindings(std::vector<std::string> accum_names) {
24    std::vector<ScalarBinding> vec;
25    accum_t = iBuilder->getInt64Ty();
26    for (a in accum_names) {
27        vec.push_back(ScalarBinding{accum_t, a});
28    }
29    return vec;
30}
31
32std::unique_ptr<llvm::Module> PabloKernel::createKernelModule() {
33    std::unique_ptr<llvm::Module> theModule = KernelInterface::createKernelModule();
34    addFinalBlockMethod(theModule);
35    Function * doBlockFunction = theModule.get()->getFunction(mKernelName + "_DoBlock");
36    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", doBlockFunction, 0));
37   
38   
39   
40}
41
42void PabloKernel::addFinalBlockMethod(Module * m) {
43    Function * doBlockFunction = m->getFunction(mKernelName + "_DoBlock");
44    Function * finalBlockFunction = m->getFunction(mKernelName + "_FinalBlock");
45    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "fb_entry", finalBlockFunction, 0));
46    // Final Block arguments: self, remaining, then the standard DoBlock args.
47    Function::arg_iterator args = main->arg_begin();
48    Value * self = &*(args++);
49    Value * remaining = &*(args++);
50    std::vector<Value *> doBlockArgs = {self};
51    while (args != main->arg_end()){
52        doBlockArgs.push_back(&*args++);
53    }
54    // Standard Pablo convention for final block processing: set a bit marking
55    // the position just past EOF.
56    Value * EOFmark = iBuilder->CreateShl(ConstantInt::get(iBuilder->getIntNTy(mBlockSize), 1), remaining);
57    setScalarField(self, "EOFmark", EOFmark);
58    iBuilder->CreateCall(doBlockFunction, doBlockArgs);
59    iBuilder->CreateRetVoid();
60}
61
Note: See TracBrowser for help on using the repository browser.