Ignore:
Timestamp:
Jul 21, 2016, 6:55:10 AM (3 years ago)
Author:
cameron
Message:

getStreamSetBlockPtr

File:
1 edited

Legend:

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

    r5103 r5104  
    2828    unsigned index = mKernelFields.size();
    2929    mKernelFields.push_back(t);
    30     mInternalStateNameMap.emplace(scalarName, iBuilder->getInt32(index));
     30    mInternalStateNameMap.emplace(scalarName, index);
    3131}
    3232
     
    3838    if (!mDoBlockReturnType) mDoBlockReturnType = iBuilder->getVoidTy();
    3939    addScalar(iBuilder->getInt64Ty(), blockNoScalar);
     40    int streamSetNo = 0;
    4041    for (auto sSet : mStreamSetInputs) {
    4142        mScalarInputs.push_back(ScalarBinding{PointerType::get(sSet.ssType.getStreamSetBlockType(), 0), sSet.ssName + basePtrSuffix});
     43        mStreamSetNameMap.emplace(sSet.ssName, streamSetNo);
     44        streamSetNo++;
    4245    }
    4346    for (auto sSet : mStreamSetOutputs) {
    4447        mScalarInputs.push_back(ScalarBinding{PointerType::get(sSet.ssType.getStreamSetBlockType(), 0), sSet.ssName + basePtrSuffix});
     48        mStreamSetNameMap.emplace(sSet.ssName, streamSetNo);
     49        streamSetNo++;
    4550    }
    4651    for (auto binding : mScalarInputs) {
     
    193198        throw std::runtime_error("Kernel does not contain internal state: " + fieldName);
    194199    }
    195     return f->second;
     200    return iBuilder->getInt32(f->second);
    196201}
    197202
     
    215220}
    216221
    217 
     222unsigned KernelBuilder::getStreamSetIndex(std::string ssName) {
     223    const auto f = mStreamSetNameMap.find(ssName);
     224    if (LLVM_UNLIKELY(f == mStreamSetNameMap.end())) {
     225        throw std::runtime_error("Kernel does not contain stream set: " + ssName);
     226    }
     227    return f->second;
     228}
     229
     230Value * KernelBuilder::getStreamSetBasePtr(Value * self, std::string ssName) {
     231    return getScalarField(self, ssName + basePtrSuffix);
     232}
     233
     234Value * KernelBuilder::getStreamSetBlockPtr(Value * self, std::string ssName, Value * blockNo) {
     235    Value * basePtr = getStreamSetBasePtr(self, ssName);
     236    unsigned ssIndex = getStreamSetIndex(ssName);
     237    if (ssIndex < mStreamSetInputs.size()) {
     238        return mStreamSetInputs[ssIndex].ssType.getStreamSetBlockPointer(basePtr, blockNo);
     239    }
     240    else {
     241        return mStreamSetOutputs[ssIndex - mStreamSetInputs.size()].ssType.getStreamSetBlockPointer(basePtr, blockNo);
     242    }
     243}
     244
     245
     246
     247
Note: See TracChangeset for help on using the changeset viewer.