Ignore:
Timestamp:
Mar 30, 2016, 4:42:52 PM (3 years ago)
Author:
nmedfort
Message:

More work on symbol table; unexpected bug with 4KiB-one page tests observed.

File:
1 edited

Legend:

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

    r4992 r4995  
    7070
    7171Value * KernelBuilder::getInternalState(Value * const instance, disable_implicit_conversion<Value *> index) {
    72     assert (index->getType() == iBuilder->getInt32Ty());
     72    assert (index->getType()->isIntegerTy());
    7373    return iBuilder->CreateGEP(instance, {iBuilder->getInt64(0), iBuilder->getInt32(INTERNAL_STATE), index});
    7474}
     
    137137Value * KernelBuilder::getInputStream(Value * const instance, disable_implicit_conversion<Value *> index, const unsigned streamOffset) {
    138138    assert (instance && index);
    139     Value * inputStream = iBuilder->CreateLoad(iBuilder->CreateGEP(instance,
     139    assert (index->getType()->isIntegerTy());
     140    Value * const inputStreamSet = iBuilder->CreateLoad(iBuilder->CreateGEP(instance,
    140141        {iBuilder->getInt32(0), iBuilder->getInt32(INPUT_STREAM_SET), iBuilder->getInt32(0)}));
    141142    Value * modFunction = iBuilder->CreateLoad(iBuilder->CreateGEP(instance,
     
    145146        offset = iBuilder->CreateAdd(offset, ConstantInt::get(offset->getType(), streamOffset));
    146147    }
    147     assert (index->getType() == iBuilder->getInt32Ty());
    148     return iBuilder->CreateGEP(inputStream, { iBuilder->CreateCall(modFunction, offset), index });
     148    if (LLVM_LIKELY(isa<ConstantInt>(index.get()) || inputStreamSet->getType()->getPointerElementType()->isArrayTy())) {
     149        return iBuilder->CreateGEP(inputStreamSet, { iBuilder->CreateCall(modFunction, offset), index });
     150    } else {
     151        throw std::runtime_error("Cannot access the input stream with a non-constant value unless all input stream types are identical!");
     152    }
    149153}
    150154
     
    205209Value * KernelBuilder::getOutputStream(Value * const instance, disable_implicit_conversion<Value *> index, const unsigned streamOffset) {
    206210    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});
     211    assert (index->getType()->isIntegerTy());
     212    if (LLVM_LIKELY(isa<ConstantInt>(index.get()))) {
     213        return iBuilder->CreateGEP(instance, {iBuilder->getInt32(0), iBuilder->getInt32(OUTPUT_STREAM_SET), getStreamOffset(instance, streamOffset), index});
     214    } else {
     215        Value * const outputStreamSet = iBuilder->CreateGEP(instance, {iBuilder->getInt32(0), iBuilder->getInt32(OUTPUT_STREAM_SET)});
     216        if (LLVM_LIKELY(outputStreamSet->getType()->getPointerElementType()->isArrayTy())) {
     217            return iBuilder->CreateGEP(outputStreamSet, {getStreamOffset(instance, streamOffset), index});
     218        }
     219    }
     220    throw std::runtime_error("Cannot access the output stream with a non-constant value unless all output stream types are identical!");
    209221}
    210222
     
    221233
    222234/** ------------------------------------------------------------------------------------------------------------- *
     235 * @brief packDataTypes
     236 ** ------------------------------------------------------------------------------------------------------------- */
     237llvm::Type * KernelBuilder::packDataTypes(const std::vector<llvm::Type *> & types) {
     238    bool canPackIntoArray = !types.empty();
     239    for (Type * type : types) {
     240        if (type != types.front()) { // use canLosslesslyBitcastInto ?
     241            canPackIntoArray = false;
     242            break;
     243        }
     244    }
     245    if (canPackIntoArray) {
     246        return ArrayType::get(types.front(), types.size());
     247    } else {
     248        return StructType::get(mMod->getContext(), types);
     249    }
     250}
     251
     252/** ------------------------------------------------------------------------------------------------------------- *
    223253 * @brief prepareFunction
    224254 ** ------------------------------------------------------------------------------------------------------------- */
     
    226256
    227257    PointerType * modFunctionType = PointerType::get(FunctionType::get(iBuilder->getInt64Ty(), {iBuilder->getInt64Ty()}, false), 0);
    228     mInputStreamType = PointerType::get(StructType::get(mMod->getContext(), mInputStream), 0);
    229     mInputScalarType = PointerType::get(StructType::get(mMod->getContext(), mInputScalar), 0);
    230     mOutputStreamType = StructType::get(mMod->getContext(), mOutputStream);
    231     Type * outputScalarType = StructType::get(mMod->getContext(), mOutputScalar);
    232     Type * internalStateType = StructType::create(mMod->getContext(), mInternalState);
     258    mInputStreamType = PointerType::get(packDataTypes(mInputStream), 0);
     259    mInputScalarType = PointerType::get(packDataTypes(mInputScalar), 0);
     260    mOutputStreamType = packDataTypes(mOutputStream);
     261    Type * outputScalarType = packDataTypes(mOutputScalar);
     262    Type * internalStateType = packDataTypes(mInternalState);
    233263    Type * inputStateType = StructType::create(mMod->getContext(), { mInputStreamType, modFunctionType});
    234 
    235264    Type * outputBufferType = ArrayType::get(mOutputStreamType, mBufferSize);
    236265    mKernelStateType = StructType::create(mMod->getContext(), {internalStateType, inputStateType, outputBufferType, outputScalarType}, mKernelName);
     
    286315    for (unsigned i = 0; i < mInternalState.size(); ++i) {
    287316        Type * const type = mInternalState[i];
    288         if (type->isIntegerTy() || type->isArrayTy() || type->isVectorTy()) {
     317        if (type->isSized()) {
    289318            setInternalState(i, Constant::getNullValue(type));
    290319        } else {
    291320            Value * const ptr = getInternalState(i);
    292321            Value * const size = iBuilder->CreatePtrDiff(iBuilder->CreateGEP(ptr, iBuilder->getInt32(1)), ptr);
     322            iBuilder->CallPrintInt(mKernelName + "_zeroinit_" + std::to_string(i), size);
    293323            iBuilder->CreateMemSet(ptr, iBuilder->getInt8(0), size, 4);
    294324        }
Note: See TracChangeset for help on using the changeset viewer.