Ignore:
Timestamp:
Jan 29, 2017, 4:40:32 PM (2 years ago)
Author:
nmedfort
Message:

More changes towards simplifying the KernelBuilder?

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/kernels/interface.cpp

    r5285 r5287  
    1414namespace llvm { class Type; }
    1515
     16static const auto INIT_SUFFIX = "_Init";
     17
     18static const auto DO_SEGMENT_SUFFIX = "_DoSegment";
     19
     20static const auto ACCUMULATOR_INFIX = "_get_";
     21
    1622using namespace llvm;
    1723
     
    2834    for (auto binding : mScalarOutputs) {
    2935        FunctionType * accumFnType = FunctionType::get(binding.type, {selfType}, false);
    30         std::string fnName = mKernelName + accumulator_infix + binding.name;
     36        std::string fnName = mKernelName + ACCUMULATOR_INFIX + binding.name;
    3137        Function * accumFn = Function::Create(accumFnType, GlobalValue::ExternalLinkage, fnName, client);
    3238        accumFn->setCallingConv(CallingConv::C);
     
    4248    }
    4349    FunctionType * initFunctionType = FunctionType::get(iBuilder->getVoidTy(), initParameters, false);
    44     std::string initFnName = mKernelName + init_suffix;
     50    std::string initFnName = mKernelName + INIT_SUFFIX;
    4551    Function * initFn = Function::Create(initFunctionType, GlobalValue::ExternalLinkage, initFnName, client);
    4652    initFn->setCallingConv(CallingConv::C);
     
    5460    }
    5561
    56     // Create the doBlock and finalBlock function prototypes
    57    
    58     std::vector<Type *> doBlockParameters = {selfType};
    59     std::vector<Type *> finalBlockParameters = {selfType, iBuilder->getSizeTy()};
    60     FunctionType * doBlockFunctionType = FunctionType::get(iBuilder->getVoidTy(), doBlockParameters, false);
    61     std::string doBlockName = mKernelName + doBlock_suffix;
    62     Function * doBlockFn = Function::Create(doBlockFunctionType, GlobalValue::ExternalLinkage, doBlockName, client);
    63     doBlockFn->setCallingConv(CallingConv::C);
    64     doBlockFn->setDoesNotThrow();
    65     doBlockFn->setDoesNotCapture(1);
    66    
    67     FunctionType * finalBlockType = FunctionType::get(iBuilder->getVoidTy(), finalBlockParameters, false);
    68     std::string finalBlockName = mKernelName + finalBlock_suffix;
    69     Function * finalBlockFn = Function::Create(finalBlockType, GlobalValue::ExternalLinkage, finalBlockName, client);
    70     finalBlockFn->setCallingConv(CallingConv::C);
    71     finalBlockFn->setDoesNotThrow();
    72     finalBlockFn->setDoesNotCapture(1);
    73    
    74     Function::arg_iterator doBlockArgs = doBlockFn->arg_begin();
    75     Function::arg_iterator finalBlockArgs = finalBlockFn->arg_begin();
    76     Value * doBlockArg = &*(doBlockArgs++);
    77     doBlockArg->setName("self");
    78     Value * finalBlockArg = &*(finalBlockArgs++);
    79     finalBlockArg->setName("self");
    80     finalBlockArg = &*(finalBlockArgs++);
    81     finalBlockArg->setName("remainingBytes");
    82 
    8362    // Create the doSegment function prototype.
    8463    std::vector<Type *> doSegmentParameters = {selfType, iBuilder->getInt1Ty()};
     
    8766    }
    8867    FunctionType * doSegmentFunctionType = FunctionType::get(iBuilder->getVoidTy(), doSegmentParameters, false);
    89     std::string doSegmentName = mKernelName + doSegment_suffix;
     68    std::string doSegmentName = mKernelName + DO_SEGMENT_SUFFIX;
    9069    Function * doSegmentFn = Function::Create(doSegmentFunctionType, GlobalValue::ExternalLinkage, doSegmentName, client);
    9170    doSegmentFn->setCallingConv(CallingConv::C);
     
    10180    }
    10281    doSegmentFn->setDoesNotCapture(1); // for self parameter only.
     82
     83    // Add any additional kernel declarations
     84    addAdditionalKernelDeclarations(client, selfType);
     85
    10386    iBuilder->setModule(saveModule);
    10487    iBuilder->restoreIP(savePoint);
     88}
     89
     90void KernelInterface::addAdditionalKernelDeclarations(llvm::Module * module, llvm::PointerType * selfType) const {
     91
    10592}
    10693
     
    10996}
    11097
    111 Value * KernelInterface::createDoSegmentCall(std::vector<Value *> args) const {
    112     Module * m = iBuilder->getModule();
    113     std::string fnName = mKernelName + doSegment_suffix;
    114     Function * method = m->getFunction(fnName);
    115     if (!method) {
    116         throw std::runtime_error("Cannot find " + fnName);
     98llvm::Function * KernelInterface::getAccumulatorFunction(const std::string & accumName) const {
     99    const auto name = mKernelName + ACCUMULATOR_INFIX + accumName;
     100    Function * f = iBuilder->getModule()->getFunction(name);
     101    if (LLVM_UNLIKELY(f == nullptr)) {
     102        llvm::report_fatal_error("Cannot find " + name);
    117103    }
    118     return iBuilder->CreateCall(method, args);
     104    return f;
    119105}
    120106
    121 Value * KernelInterface::createGetAccumulatorCall(Value * self, std::string accumName) const {
    122     Module * m = iBuilder->getModule();
    123     std::string fnName = mKernelName + accumulator_infix + accumName;
    124     Function * accumMethod = m->getFunction(fnName);
    125     if (!accumMethod) {
    126         throw std::runtime_error("Cannot find " + fnName);
     107Function * KernelInterface::getInitFunction() const {
     108    const auto name = mKernelName + INIT_SUFFIX;
     109    Function * f = iBuilder->getModule()->getFunction(name);
     110    if (LLVM_UNLIKELY(f == nullptr)) {
     111        llvm::report_fatal_error("Cannot find " + name);
    127112    }
    128     return iBuilder->CreateCall(accumMethod, {self});
     113    return f;
    129114}
    130115
    131116Function * KernelInterface::getDoSegmentFunction() const {
    132     return iBuilder->getModule()->getFunction(mKernelName + doSegment_suffix);
     117    const auto name = mKernelName + DO_SEGMENT_SUFFIX;
     118    Function * f = iBuilder->getModule()->getFunction(name);
     119    if (LLVM_UNLIKELY(f == nullptr)) {
     120        llvm::report_fatal_error("Cannot find " + name);
     121    }
     122    return f;
    133123}
Note: See TracChangeset for help on using the changeset viewer.