Changeset 5389 for icGREP/icgrep-devel


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

Investigating jenkins issue.

Location:
icGREP/icgrep-devel/icgrep
Files:
6 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
  • icGREP/icgrep-devel/icgrep/kernels/kernel.cpp

    r5379 r5389  
    322322    Value * itemCount = getProducedItemCount(instance, name);
    323323    const StreamSetBuffer * const buf = getOutputStreamSetBuffer(name);
    324     buf->reserveBytes(getStreamSetBufferPtr(name), itemCount, value);
     324    buf->reserveBytes(getStreamSetBufferPtr(name), iBuilder->CreateAdd(itemCount, value));
    325325}
    326326
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.cpp

    r5379 r5389  
    3737    return iBuilder->CreateAnd(bits_minus1, bits);
    3838}
    39        
    40 
    4139
    4240void ScanMatchKernel::generateDoBlockMethod() {
  • icGREP/icgrep-devel/icgrep/kernels/streamset.cpp

    r5386 r5389  
    115115}
    116116
    117 void StreamSetBuffer::reserveBytes(Value * self, llvm::Value * position, llvm::Value *requested) const {
     117void StreamSetBuffer::reserveBytes(Value * self, llvm::Value *requested) const {
    118118    report_fatal_error("reserve() can only be used with ExtensibleBuffers");
    119119}
     
    177177}
    178178
    179 void ExtensibleBuffer::reserveBytes(Value * const self, llvm::Value * const position, llvm::Value * const requested) const {
     179void ExtensibleBuffer::reserveBytes(Value * const self, llvm::Value * const requiredSize) const {
    180180    Value * const capacityPtr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
    181181    Value * const currentSize = iBuilder->CreateLoad(capacityPtr);
    182     Type * const intTy = currentSize->getType();
    183     assert (position->getType() == requested->getType());
    184     Constant * const blockSize = ConstantExpr::getIntegerCast(ConstantExpr::getIntegerCast(ConstantExpr::getSizeOf(getType()->getStructElementType(1)), intTy, false), requested->getType(), false);
    185182    BasicBlock * const entry = iBuilder->GetInsertBlock();
    186183    BasicBlock * const expand = BasicBlock::Create(iBuilder->getContext(), "expand", entry->getParent());
    187184    BasicBlock * const resume = BasicBlock::Create(iBuilder->getContext(), "resume", entry->getParent());
    188     Value * const reserved = iBuilder->CreateAdd(iBuilder->CreateMul(position, blockSize), requested);
    189     iBuilder->CreateLikelyCondBr(iBuilder->CreateICmpULT(reserved, currentSize), resume, expand);
     185    iBuilder->CreateLikelyCondBr(iBuilder->CreateICmpULT(requiredSize, currentSize), resume, expand);
    190186    iBuilder->SetInsertPoint(expand);
    191     Value * const reservedSize = iBuilder->CreateShl(reserved, 1);
     187    Value * const reservedSize = iBuilder->CreateShl(requiredSize, 1);
    192188    Value * const baseAddrPtr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(1)});
    193189    Value * const baseAddr = iBuilder->CreateLoad(baseAddrPtr);
     
    197193    iBuilder->CreateStore(newAddr, baseAddrPtr);
    198194    iBuilder->CreateBr(resume);
    199 
    200195    iBuilder->SetInsertPoint(resume);
    201196}
  • icGREP/icgrep-devel/icgrep/kernels/streamset.h

    r5386 r5389  
    6161    virtual llvm::Value * getLinearlyAccessibleBlocks(llvm::Value * self, llvm::Value * fromBlock) const;
    6262
    63     virtual void reserveBytes(llvm::Value * self, llvm::Value * position, llvm::Value * requested) const;
     63    virtual void reserveBytes(llvm::Value * self, llvm::Value * requested) const;
    6464
    6565    virtual ~StreamSetBuffer() = 0;
     
    131131    void allocateBuffer() override;
    132132
    133     void reserveBytes(llvm::Value * self, llvm::Value * position, llvm::Value * requested) const override;
     133    void reserveBytes(llvm::Value * self, llvm::Value * required) const override;
    134134
    135135    void releaseBuffer(llvm::Value * self) override;
Note: See TracChangeset for help on using the changeset viewer.