Ignore:
Timestamp:
Apr 1, 2017, 1:14:57 PM (2 years ago)
Author:
nmedfort
Message:

Investigating jenkins issue.

Location:
icGREP/icgrep-devel/icgrep/IR_Gen
Files:
2 edited

Legend:

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

    r5388 r5389  
    1515#include <sys/mman.h>
    1616#include <toolchain.h>
    17 
     17#include <errno.h>
    1818#include <llvm/Support/raw_ostream.h>
    1919
     
    170170
    171171Value * CBuilder::CreateAnonymousMMap(Value * size) {
    172     DataLayout DL(mMod);
    173     PointerType * const voidPtrTy = getVoidPtrTy();
    174     IntegerType * const intTy = getIntPtrTy(DL);
     172    PointerType * const voidPtrTy = getVoidPtrTy();
     173    IntegerType * const intTy = getInt32Ty();
    175174    IntegerType * const sizeTy = getSizeTy();
    176     Type * const offTy = TypeBuilder<off_t, false>::get(getContext());
    177     Function * fMMap = mMod->getFunction("mmap");
    178     if (LLVM_UNLIKELY(fMMap == nullptr)) {
    179         FunctionType * fty = FunctionType::get(voidPtrTy, {voidPtrTy, sizeTy, intTy, intTy, intTy, offTy}, false);
    180         fMMap = Function::Create(fty, Function::ExternalLinkage, "mmap", mMod);
    181     }
    182175    size = CreateZExtOrTrunc(size, sizeTy);
    183176    ConstantInt * const prot =  ConstantInt::get(intTy, PROT_READ | PROT_WRITE);
    184177    ConstantInt * const flags =  ConstantInt::get(intTy, MAP_PRIVATE | MAP_ANONYMOUS);
    185178    ConstantInt * const fd =  ConstantInt::get(intTy, -1);
    186     Constant * const offset = ConstantInt::get(offTy, 0); // getCacheAlignment()
    187     Value * const ptr = CreateCall(fMMap, {Constant::getNullValue(voidPtrTy), size, prot, flags, fd, offset});
    188     CreateAssert(CreateICmpNE(CreatePtrToInt(ptr, getSizeTy()), getSize((size_t)MAP_FAILED)), "CreateAnonymousMMap: mmap failed to allocate memory");
    189     return ptr;
     179    Constant * const offset = ConstantInt::get(sizeTy, 0);
     180    return CreateMMap(Constant::getNullValue(voidPtrTy), size, prot, flags, fd, offset);
    190181}
    191182
    192183Value * CBuilder::CreateFileSourceMMap(Value * const fd, Value * size) {
    193     DataLayout DL(mMod);
    194     PointerType * const voidPtrTy = getVoidPtrTy();
    195     IntegerType * const intTy = getIntPtrTy(DL);
     184    PointerType * const voidPtrTy = getVoidPtrTy();
     185    IntegerType * const intTy = getInt32Ty();
    196186    IntegerType * const sizeTy = getSizeTy();
    197     Type * const offTy = TypeBuilder<off_t, false>::get(getContext());
    198     Function * fMMap = mMod->getFunction("mmap");
    199     if (LLVM_UNLIKELY(fMMap == nullptr)) {
    200         FunctionType * fty = FunctionType::get(voidPtrTy, {voidPtrTy, sizeTy, intTy, intTy, intTy, offTy}, false);
    201         fMMap = Function::Create(fty, Function::ExternalLinkage, "mmap", mMod);
    202     }
    203187    size = CreateZExtOrTrunc(size, sizeTy);
    204188    ConstantInt * const prot =  ConstantInt::get(intTy, PROT_READ);
    205189    ConstantInt * const flags =  ConstantInt::get(intTy, MAP_PRIVATE);
    206     Constant * const offset = ConstantInt::get(offTy, 0); // getCacheAlignment()
    207     Value * const ptr = CreateCall(fMMap, {Constant::getNullValue(voidPtrTy), size, prot, flags, fd, offset});
    208     CreateAssert(CreateICmpNE(CreatePtrToInt(ptr, getSizeTy()), getSize((size_t)MAP_FAILED)), "CreateFileSourceMMap: mmap failed to allocate memory");
     190    Constant * const offset = ConstantInt::get(sizeTy, 0);
     191    return CreateMMap(Constant::getNullValue(voidPtrTy), size, prot, flags, fd, offset);
     192}
     193
     194Value * CBuilder::CreateMMap(Value * const addr, Value * size, Value * const prot, Value * const flags, Value * const fd, Value * const offset) {
     195    Function * fMMap = mMod->getFunction("mmap");
     196    if (LLVM_UNLIKELY(fMMap == nullptr)) {
     197        PointerType * const voidPtrTy = getVoidPtrTy();
     198        IntegerType * const intTy = getInt32Ty();
     199        IntegerType * const sizeTy = getSizeTy();
     200        FunctionType * fty = FunctionType::get(voidPtrTy, {voidPtrTy, sizeTy, intTy, intTy, intTy, sizeTy}, false);
     201        fMMap = Function::Create(fty, Function::ExternalLinkage, "mmap", mMod);
     202    }
     203    Value * ptr = CreateCall(fMMap, {addr, size, prot, flags, fd, offset});
     204    CreateAssert(CheckMMapSuccess(ptr), "CreateMMap: mmap failed to allocate memory");
    209205    return ptr;
     206}
     207
     208Value * CBuilder::CheckMMapSuccess(Value * const addr) {
     209    DataLayout DL(mMod);
     210    IntegerType * const ty = getIntPtrTy(DL);
     211    return CreateICmpNE(CreatePtrToInt(addr, ty), ConstantInt::getAllOnesValue(ty)); // MAP_FAILED = -1
    210212}
    211213
     
    221223    }   
    222224    addr = CreatePointerCast(addr, voidPtrTy);
    223     CreateAssert(addr, "CreateMRemap: addr cannot be null");
    224225    oldSize = CreateZExtOrTrunc(oldSize, sizeTy);
    225226    newSize = CreateZExtOrTrunc(newSize, sizeTy);
    226227    ConstantInt * const flags = ConstantInt::get(intTy, mayMove ? MREMAP_MAYMOVE : 0);
    227     Value * ptr = CreateCall(fMRemap, {addr, oldSize, newSize, flags});
    228     CreateAssert(addr, "CreateMRemap: mremap failed to allocate memory");
     228    Value * ptr = CreateCall(fMRemap, {addr, oldSize, newSize, flags});   
     229    CreateAssert(CheckMMapSuccess(ptr), "CreateMRemap: mremap failed to allocate memory");
    229230    return ptr;
    230231}
  • icGREP/icgrep-devel/icgrep/IR_Gen/CBuilder.h

    r5386 r5389  
    8181    llvm::Value * CreateFileSourceMMap(llvm::Value * fd, llvm::Value * size);
    8282
     83    llvm::Value * CreateMMap(llvm::Value * const addr, llvm::Value * size, llvm::Value * const prot, llvm::Value * const flags, llvm::Value * const fd, llvm::Value * const offset);
     84
     85    llvm::Value * CheckMMapSuccess(llvm::Value * const addr);
     86
    8387    llvm::Value * CreateMRemap(llvm::Value * addr, llvm::Value * oldSize, llvm::Value * newSize, const bool mayMove = true);
    8488
Note: See TracChangeset for help on using the changeset viewer.