Ignore:
Timestamp:
Mar 31, 2017, 3:40:54 PM (2 years ago)
Author:
nmedfort
Message:

Fix for 32-bit

File:
1 edited

Legend:

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

    r5386 r5387  
    180180        fMMap = Function::Create(fty, Function::ExternalLinkage, "mmap", mMod);
    181181    }
     182    size = CreateZExtOrTrunc(size, sizeTy);
    182183    ConstantInt * const prot =  ConstantInt::get(intTy, PROT_READ | PROT_WRITE);
    183184    ConstantInt * const flags =  ConstantInt::get(intTy, MAP_PRIVATE | MAP_ANONYMOUS);
     
    189190}
    190191
    191 Value * CBuilder::CreateFileSourceMMap(Value * const fd, Value * const size) {
     192Value * CBuilder::CreateFileSourceMMap(Value * const fd, Value * size) {
    192193    DataLayout DL(mMod);
    193194    PointerType * const voidPtrTy = getVoidPtrTy();
     
    200201        fMMap = Function::Create(fty, Function::ExternalLinkage, "mmap", mMod);
    201202    }
     203    size = CreateZExtOrTrunc(size, sizeTy);
    202204    ConstantInt * const prot =  ConstantInt::get(intTy, PROT_READ);
    203205    ConstantInt * const flags =  ConstantInt::get(intTy, MAP_PRIVATE);
     
    215217    Function * fMRemap = mMod->getFunction("mremap");
    216218    if (LLVM_UNLIKELY(fMRemap == nullptr)) {
    217         //    void * mremap (void *addr, size_t old_size,
    218         //                   size_t new_size, unsigned long flags);
    219 
    220219        FunctionType * fty = FunctionType::get(voidPtrTy, {voidPtrTy, sizeTy, sizeTy, intTy}, false);
    221220        fMRemap = Function::Create(fty, Function::ExternalLinkage, "mremap", mMod);
    222221    }   
    223222    addr = CreatePointerCast(addr, voidPtrTy);
    224     CreateAssert(addr, "CreateMRemap: initial addr is null");
    225     Value * ptr = CreateCall(fMRemap, {addr, oldSize, newSize, ConstantInt::get(intTy, mayMove ? MREMAP_MAYMOVE : 0)});
     223    CreateAssert(addr, "CreateMRemap: addr cannot be null");
     224    oldSize = CreateZExtOrTrunc(oldSize, sizeTy);
     225    newSize = CreateZExtOrTrunc(newSize, sizeTy);
     226    ConstantInt * const flags = ConstantInt::get(intTy, mayMove ? MREMAP_MAYMOVE : 0);
     227    Value * ptr = CreateCall(fMRemap, {addr, oldSize, newSize, flags});
    226228    CreateAssert(addr, "CreateMRemap: mremap failed to allocate memory");
    227229    return ptr;
     
    230232Value * CBuilder::CreateMUnmap(Value * addr, Value * size) {
    231233    DataLayout DL(mMod);
    232     IntegerType * const intTy = getIntPtrTy(DL);
    233234    IntegerType * const sizeTy = getSizeTy();
     235    PointerType * const voidPtrTy = getVoidPtrTy();
    234236    Function * fMUnmap = mMod->getFunction("munmap");
    235237    if (LLVM_UNLIKELY(fMUnmap == nullptr)) {
    236         // int munmap (void *addr, size_t len);
    237 
    238         PointerType * const voidPtrTy = getVoidPtrTy();
     238        IntegerType * const intTy = getIntPtrTy(DL);
    239239        FunctionType * fty = FunctionType::get(intTy, {voidPtrTy, sizeTy}, false);
    240240        fMUnmap = Function::Create(fty, Function::ExternalLinkage, "munmap", mMod);
    241241    }
     242    addr = CreatePointerCast(addr, voidPtrTy);
     243    CreateAssert(addr, "CreateMUnmap: addr cannot be null");
     244    size = CreateZExtOrTrunc(size, sizeTy);
    242245    return CreateCall(fMUnmap, {addr, size});
    243246}
Note: See TracChangeset for help on using the changeset viewer.