Ignore:
Timestamp:
Jun 13, 2016, 9:26:31 AM (3 years ago)
Author:
cameron
Message:

getScalarIndex, getParameter

Location:
icGREP/icgrep-devel/icgrep/kernels
Files:
2 edited

Legend:

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

    r5049 r5050  
    142142        iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "get_" + binding.scalarName, accumFn, 0));
    143143        Value * self = &*(accumFn->arg_begin());
    144         const auto f = mInternalStateNameMap.find(binding.scalarName);
    145         if (LLVM_UNLIKELY(f == mInternalStateNameMap.end())) {
    146             throw std::runtime_error("Kernel does not contain internal state " + binding.scalarName);
    147         }
    148         Value * idx = f->second;
    149         Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), idx});
     144        Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), getScalarIndex(binding.scalarName)});
    150145        Value * retVal = iBuilder->CreateLoad(ptr);
    151146        iBuilder->CreateRet(retVal);
     
    161156    for (auto binding : mScalarInputs) {
    162157        Value * parm = &*(args++);
    163         const auto f = mInternalStateNameMap.find(binding.scalarName);
    164         if (LLVM_UNLIKELY(f == mInternalStateNameMap.end())) {
    165             throw std::runtime_error("Kernel does not contain internal state " + binding.scalarName);
    166         }
    167         Value * idx = f->second;
    168         Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), idx});
     158        Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), getScalarIndex(binding.scalarName)});
    169159        iBuilder->CreateStore(ptr, parm);
    170160    }
     
    172162    return theModule;
    173163}
     164
     165llvm::Value * KernelInterface::getScalarIndex(std::string fieldName) {
     166    const auto f = mInternalStateNameMap.find(fieldName);
     167    if (LLVM_UNLIKELY(f == mInternalStateNameMap.end())) {
     168        throw std::runtime_error("Kernel does not contain internal state: " + fieldName);
     169    }
     170    return f->second;
     171}
     172
     173
     174llvm::Value * KernelInterface::getParameter(Function * f, std::string paramName) {
     175    for (Function::arg_iterator argIter = f->arg_begin(), end = f->arg_end(); argIter != end; argIter++) {
     176        Value * arg = &*argIter;
     177        if (arg->getName() == paramName) return arg;
     178    }
     179    throw std::runtime_error("Method does not have parameter: " + paramName);
     180}
     181
  • icGREP/icgrep-devel/icgrep/kernels/interface.h

    r5047 r5050  
    4343    // all required methods.  The init and accumulator output methods will be
    4444    // defined, while the doBlock and finalBlock methods will initially be empty.
    45     std::unique_ptr<llvm::Module> createKernelModule();
     45    virtual std::unique_ptr<llvm::Module> createKernelModule();
    4646   
    4747protected:
    4848    // Get the index of a named scalar within the kernel state struct.
    49     llvm::Value * getInputStreamSetIndex(std::string);
    50     llvm::Value * getOutputStreamSetIndex(std::string);
    5149    llvm::Value * getScalarIndex(std::string);
    52    
    53    
    54 private:
     50    // Get a parameter by name.
     51    llvm::Value * getParameter(Function * f, std::string paramName);
     52
    5553    IDISA::IDISA_Builder * iBuilder;
    5654    std::string mKernelName;
     
    6361    llvm::Type *               mKernelStateType;
    6462    NameMap                    mInternalStateNameMap;
    65 
     63    NameMap                    mStreamSetNameMap;
    6664};
    6765
Note: See TracChangeset for help on using the changeset viewer.