Ignore:
Timestamp:
Feb 15, 2017, 4:08:37 PM (2 years ago)
Author:
nmedfort
Message:

memcpy/memset support for 32-bit systems; more error messages/handling; bug fix for ParabixCharacterClassKernelBuilder?. continued work on parenthesis matching + expandable buffers.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/IR_Gen/CBuilder.cpp

    r5309 r5320  
    112112Value * CBuilder::CreateMalloc(Type * type, Value * size) {
    113113    DataLayout DL(getModule());
    114     Type * const intTy = getIntPtrTy(DL);
    115     Constant * const width = ConstantExpr::getSizeOf(type);
     114    IntegerType * const intTy = getIntPtrTy(DL);
    116115    if (size->getType() != intTy) {
    117116        if (isa<Constant>(size)) {
    118117            size = ConstantExpr::getIntegerCast(cast<Constant>(size), intTy, false);
    119118        } else {
    120             size = CreateTruncOrBitCast(size, intTy);
    121         }
     119            size = CreateZExtOrTrunc(size, intTy);
     120        }
     121    }   
     122    Constant * width = ConstantExpr::getSizeOf(type);
     123    if (LLVM_UNLIKELY(width->getType() != intTy)) {
     124        width = ConstantExpr::getIntegerCast(width, intTy, false);
    122125    }
    123126    if (!width->isOneValue()) {
     
    136139        malloc->setDoesNotAlias(0);
    137140    }
     141    assert (size->getType() == intTy);
    138142    CallInst * ci = CreateCall(malloc, size);
    139143    ci->setTailCall();
     
    146150    DataLayout DL(getModule());
    147151    IntegerType * const intTy = getIntPtrTy(DL);
     152    if (size->getType() != intTy) {
     153        if (isa<Constant>(size)) {
     154            size = ConstantExpr::getIntegerCast(cast<Constant>(size), intTy, false);
     155        } else {
     156            size = CreateZExtOrTrunc(size, intTy);
     157        }
     158    }
    148159    const auto byteWidth = (intTy->getBitWidth() / 8);
    149160    Constant * const offset = ConstantInt::get(intTy, alignment + byteWidth - 1);
    150     Constant * const width = ConstantExpr::getSizeOf(type);
     161    Constant * width = ConstantExpr::getSizeOf(type);
     162    if (LLVM_UNLIKELY(width->getType() != intTy)) {
     163        width = ConstantExpr::getIntegerCast(width, intTy, false);
     164    }
    151165    if (!width->isOneValue()) {
    152166        if (isa<Constant>(size)) {
     
    154168        } else {
    155169            size = CreateMul(size, width);
    156         }
    157     }
    158     if (size->getType() != intTy) {
    159         if (isa<Constant>(size)) {
    160             size = ConstantExpr::getIntegerCast(cast<Constant>(size), intTy, false);
    161         } else {
    162             size = CreateTruncOrBitCast(size, intTy);
    163170        }
    164171    }
     
    168175        size = CreateAdd(size, offset);
    169176    }
     177    assert (size->getType() == intTy);
    170178    Value * unaligned = CreatePtrToInt(CreateMalloc(getInt8Ty(), size), intTy);
    171179    Value * aligned = CreateAnd(CreateAdd(unaligned, offset), ConstantExpr::getNot(ConstantInt::get(intTy, alignment - 1)));
     
    220228Value * CBuilder::CreateRealloc(Value * ptr, Value * size) {
    221229    DataLayout DL(getModule());
    222     Type * const intTy = getIntPtrTy(DL);
     230    IntegerType * const intTy = getIntPtrTy(DL);
    223231    PointerType * type = cast<PointerType>(ptr->getType());
    224     Constant * const width = ConstantExpr::getSizeOf(type->getPointerElementType());
     232    Constant * width = ConstantExpr::getSizeOf(type->getPointerElementType());
     233    if (LLVM_UNLIKELY(width->getType() != intTy)) {
     234        width = ConstantExpr::getIntegerCast(width, intTy, false);
     235    }
    225236    if (size->getType() != intTy) {
    226237        if (isa<Constant>(size)) {
    227238            size = ConstantExpr::getIntegerCast(cast<Constant>(size), intTy, false);
    228239        } else {
    229             size = CreateTruncOrBitCast(size, intTy);
     240            size = CreateZExtOrTrunc(size, intTy);
    230241        }
    231242    }
     
    245256        realloc->setDoesNotAlias(1);
    246257    }
     258    assert (size->getType() == intTy);
    247259    CallInst * ci = CreateCall(realloc, {ptr, size});
    248260    ci->setTailCall();
     
    252264
    253265void CBuilder::CreateMemZero(Value * ptr, Value * size, const unsigned alignment) {
    254     assert (ptr->getType()->isPointerTy() && size->getType()->isIntegerTy());
    255     Type * const type = ptr->getType();
    256     Constant * const width = ConstantExpr::getSizeOf(type->getPointerElementType());
     266    DataLayout DL(getModule());
     267    IntegerType * const intTy = getIntPtrTy(DL);
     268    Constant * width = ConstantExpr::getSizeOf(ptr->getType()->getPointerElementType());
     269    if (LLVM_UNLIKELY(width->getType() != intTy)) {
     270        width = ConstantExpr::getIntegerCast(width, intTy, false);
     271    }
     272    if (size->getType() != intTy) {
     273        if (isa<Constant>(size)) {
     274            size = ConstantExpr::getIntegerCast(cast<Constant>(size), intTy, false);
     275        } else {
     276            size = CreateZExtOrTrunc(size, intTy);
     277        }
     278    }
    257279    if (isa<Constant>(size)) {
    258280        size = ConstantExpr::getMul(cast<Constant>(size), width);
     
    260282        size = CreateMul(size, width);
    261283    }
     284    assert (size->getType() == intTy);
    262285    CreateMemSet(CreatePointerCast(ptr, getInt8PtrTy()), getInt8(0), size, alignment);
    263286}
     
    268291
    269292LoadInst * CBuilder::CreateAtomicLoadAcquire(Value * ptr) {
    270     unsigned alignment = cast<PointerType>(ptr->getType())->getElementType()->getPrimitiveSizeInBits() / 8;
     293    const auto alignment = ptr->getType()->getPointerElementType()->getPrimitiveSizeInBits() / 8;
    271294    LoadInst * inst = CreateAlignedLoad(ptr, alignment);
    272295    inst->setOrdering(AtomicOrdering::Acquire);
     
    275298}
    276299StoreInst * CBuilder::CreateAtomicStoreRelease(Value * val, Value * ptr) {
    277     unsigned alignment = cast<PointerType>(ptr->getType())->getElementType()->getPrimitiveSizeInBits() / 8;
     300    const auto alignment = ptr->getType()->getPointerElementType()->getPrimitiveSizeInBits() / 8;
    278301    StoreInst * inst = CreateAlignedStore(val, ptr, alignment);
    279302    inst->setOrdering(AtomicOrdering::Release);
Note: See TracChangeset for help on using the changeset viewer.