Ignore:
Timestamp:
Jun 25, 2016, 9:07:07 AM (3 years ago)
Author:
cameron
Message:

Kernel infrastructure: move common logic into KernelBuilder? base class; demo linking in wc

File:
1 edited

Legend:

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

    r5073 r5074  
    4242}
    4343
    44 void KernelBuilder::finalizeKernelStateType() {
     44void KernelBuilder::prepareKernelStateType() {
    4545    mKernelStateType = StructType::create(getGlobalContext(), mKernelFields, mKernelName);
    4646}
     
    4949    Module * saveModule = iBuilder->getModule();
    5050    IDISA::IDISA_Builder::InsertPoint savePoint = iBuilder->saveIP();
    51     if (mKernelStateType == nullptr) finalizeKernelStateType();
    5251    std::unique_ptr<Module> theModule = make_unique<Module>(mKernelName + "_" + iBuilder->getBitBlockTypeName(), getGlobalContext());
    5352    Module * m = theModule.get();
    5453    iBuilder->setModule(m);
    55     KernelBuilder::generateKernel();
     54    generateKernel();
    5655    iBuilder->setModule(saveModule);
    5756    iBuilder->restoreIP(savePoint);
     
    6059
    6160void KernelBuilder::generateKernel() {
     61    IDISA::IDISA_Builder::InsertPoint savePoint = iBuilder->saveIP();
    6262    Module * m = iBuilder->getModule();
    63     IDISA::IDISA_Builder::InsertPoint savePoint = iBuilder->saveIP();
    64     addKernelDeclarations(m);
     63
     64    prepareKernelStateType();  // possibly overriden by the KernelBuilder subtype
     65    KernelInterface::addKernelDeclarations(m);
     66    generateDoBlockMethod();     // must be implemented by the KernelBuilder subtype
     67    generateFinalBlockMethod();  // possibly overriden by the KernelBuilder subtype
     68
    6569    // Implement the accumulator get functions
    6670    for (auto binding : mScalarOutputs) {
     
    8993}
    9094
    91 void KernelBuilder::addTrivialFinalBlockMethod(Module * m) {
     95//  The default finalBlock method simply dispatches to the doBlock routine.
     96void KernelBuilder::generateFinalBlockMethod() {
    9297    IDISA::IDISA_Builder::InsertPoint savePoint = iBuilder->saveIP();
    93     Module * saveModule = iBuilder->getModule();
    94     iBuilder->setModule(m);
     98    Module * m = iBuilder->getModule();
    9599    Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
    96100    Function * finalBlockFunction = m->getFunction(mKernelName + finalBlock_suffix);
     
    106110    iBuilder->CreateCall(doBlockFunction, doBlockArgs);
    107111    iBuilder->CreateRetVoid();
    108     iBuilder->setModule(saveModule);
    109112    iBuilder->restoreIP(savePoint);
    110113}
Note: See TracChangeset for help on using the changeset viewer.