Ignore:
Timestamp:
Mar 28, 2016, 3:44:17 PM (3 years ago)
Author:
nmedfort
Message:

Continued work on symbol table.

File:
1 edited

Legend:

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

    r4991 r4992  
    6565 ** ------------------------------------------------------------------------------------------------------------- */
    6666Value * KernelBuilder::getInternalState(Value * const instance, const unsigned index) {
    67     Value* indices[] = {iBuilder->getInt64(0),
    68                         iBuilder->getInt32(INTERNAL_STATE),
    69                         iBuilder->getInt32(index)};
    70     return iBuilder->CreateGEP(instance, indices);
     67    assert (index < mInternalState.size());
     68    return getInternalState(instance, iBuilder->getInt32(index));
     69}
     70
     71Value * KernelBuilder::getInternalState(Value * const instance, disable_implicit_conversion<Value *> index) {
     72    assert (index->getType() == iBuilder->getInt32Ty());
     73    return iBuilder->CreateGEP(instance, {iBuilder->getInt64(0), iBuilder->getInt32(INTERNAL_STATE), index});
    7174}
    7275
     
    9396
    9497void KernelBuilder::setInternalState(Value * const instance, const unsigned index, Value * const value) {
     98    assert (index < mInternalState.size());
     99    return setInternalState(instance, iBuilder->getInt32(index), value);
     100}
     101
     102void KernelBuilder::setInternalState(Value * const instance, disable_implicit_conversion<Value *> index, Value * const value) {
    95103    Value * ptr = getInternalState(instance, index);
    96104    assert (ptr->getType()->getPointerElementType() == value->getType());
     
    123131 ** ------------------------------------------------------------------------------------------------------------- */
    124132Value * KernelBuilder::getInputStream(Value * const instance, const unsigned index, const unsigned streamOffset) {
    125     assert (instance);
    126133    assert (index < mInputStream.size());
     134    return getInputStream(instance, iBuilder->getInt32(index), streamOffset);
     135}
     136
     137Value * KernelBuilder::getInputStream(Value * const instance, disable_implicit_conversion<Value *> index, const unsigned streamOffset) {
     138    assert (instance && index);
    127139    Value * inputStream = iBuilder->CreateLoad(iBuilder->CreateGEP(instance,
    128140        {iBuilder->getInt32(0), iBuilder->getInt32(INPUT_STREAM_SET), iBuilder->getInt32(0)}));
     
    132144    if (streamOffset) {
    133145        offset = iBuilder->CreateAdd(offset, ConstantInt::get(offset->getType(), streamOffset));
    134     }   
    135     return iBuilder->CreateGEP(inputStream, { iBuilder->CreateCall(modFunction, offset), iBuilder->getInt32(index) });
     146    }
     147    assert (index->getType() == iBuilder->getInt32Ty());
     148    return iBuilder->CreateGEP(inputStream, { iBuilder->CreateCall(modFunction, offset), index });
    136149}
    137150
     
    153166 ** ------------------------------------------------------------------------------------------------------------- */
    154167Value * KernelBuilder::getInputScalar(Value * const instance, const unsigned) {
     168    assert (instance);
     169    throw std::runtime_error("currently not supported!");
     170}
     171
     172Value * KernelBuilder::getInputScalar(Value * const instance, disable_implicit_conversion<Value *>) {
     173    assert (instance);
    155174    throw std::runtime_error("currently not supported!");
    156175}
     
    180199 ** ------------------------------------------------------------------------------------------------------------- */
    181200Value * KernelBuilder::getOutputStream(Value * const instance, const unsigned index, const unsigned streamOffset) {
    182     assert (instance);
    183     Value * const offset = getOffset(instance, streamOffset);
    184     Value * const indices[] = {iBuilder->getInt32(0), iBuilder->getInt32(OUTPUT_STREAM_SET), offset, iBuilder->getInt32(index)};
    185     return iBuilder->CreateGEP(instance, indices);
     201    assert (index < mOutputStream.size());
     202    return getOutputStream(instance, iBuilder->getInt32(index), streamOffset);
     203}
     204
     205Value * KernelBuilder::getOutputStream(Value * const instance, disable_implicit_conversion<Value *> index, const unsigned streamOffset) {
     206    assert (instance && index);
     207    assert (index->getType() == iBuilder->getInt32Ty());
     208    return iBuilder->CreateGEP(instance, {iBuilder->getInt32(0), iBuilder->getInt32(OUTPUT_STREAM_SET), getStreamOffset(instance, streamOffset), index});
    186209}
    187210
     
    190213 ** ------------------------------------------------------------------------------------------------------------- */
    191214Value * KernelBuilder::getOutputScalar(Value * const instance, const unsigned) {
     215    throw std::runtime_error("currently not supported!");
     216}
     217
     218Value * KernelBuilder::getOutputScalar(Value * const instance, disable_implicit_conversion<Value *> ) {
    192219    throw std::runtime_error("currently not supported!");
    193220}
     
    369396 ** ------------------------------------------------------------------------------------------------------------- */
    370397void KernelBuilder::clearOutputStreamSet(Value * const instance, const unsigned streamOffset) {
    371     Value * const indices[] = {iBuilder->getInt32(0), iBuilder->getInt32(OUTPUT_STREAM_SET), getOffset(instance, streamOffset)};
     398    Value * const indices[] = {iBuilder->getInt32(0), iBuilder->getInt32(OUTPUT_STREAM_SET), getStreamOffset(instance, streamOffset)};
    372399    Value * ptr = iBuilder->CreateGEP(instance, indices);
    373400    unsigned size = 0;
     
    383410 * Compute the stream index of the given offset value.
    384411 ** ------------------------------------------------------------------------------------------------------------- */
    385 Value * KernelBuilder::getOffset(Value * const instance, const unsigned value) {
     412Value * KernelBuilder::getStreamOffset(Value * const instance, const unsigned index) {
    386413    Value * offset = nullptr;
    387414    if (mBufferSize > 1) {
    388415        offset = iBuilder->CreateLoad(getBlockNo(instance));
    389         if (value) {
    390             offset = iBuilder->CreateAdd(offset, iBuilder->getInt64(value));
     416        if (index) {
     417            offset = iBuilder->CreateAdd(offset, iBuilder->getInt64(index));
    391418        }
    392419        if (isPowerOfTwo(mBufferSize)) {
     
    396423        }
    397424    } else {
    398         offset = iBuilder->getInt64(value);
     425        offset = iBuilder->getInt64(index);
    399426    }
    400427    return offset;
Note: See TracChangeset for help on using the changeset viewer.