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

getScalarIndex, getParameter

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.