Ignore:
Timestamp:
Apr 7, 2017, 4:59:04 PM (2 years ago)
Author:
nmedfort
Message:

Continued work on processing stdin input. Partial integration of ParabixDriver? methods into icgrep and editd. Object cache does not currently work for recursive REs.

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

Legend:

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

    r5397 r5398  
    8989        IRBuilder<> builder(entry);
    9090        std::vector<Value *> args;
    91         args.push_back(CreateGlobalStringPtr(out.c_str()));
     91        args.push_back(GetString(out.c_str()));
    9292        Value * const name = &*(arg++);
    9393        name->setName("name");
     
    108108    }
    109109    assert (num->getType()->isIntegerTy());
    110     CreateCall(printRegister, {CreateGlobalStringPtr(name.c_str()), num});
     110    CreateCall(printRegister, {GetString(name.c_str()), num});
    111111}
    112112
     
    207207    }
    208208    Value * ptr = CreateCall(fMMap, {addr, size, prot, flags, fd, offset});
    209     CreateAssert(CheckMMapSuccess(ptr), "CreateMMap: mmap failed to allocate memory");
     209    if (codegen::EnableAsserts) {
     210        CreateAssert(CheckMMapSuccess(ptr), "CreateMMap: mmap failed to allocate memory");
     211    }
    210212    return ptr;
    211213}
     
    232234    newSize = CreateZExtOrTrunc(newSize, sizeTy);
    233235    ConstantInt * const flags = ConstantInt::get(intTy, mayMove ? MREMAP_MAYMOVE : 0);
    234     Value * ptr = CreateCall(fMRemap, {addr, oldSize, newSize, flags});   
    235     CreateAssert(CheckMMapSuccess(ptr), "CreateMRemap: mremap failed to allocate memory");
     236    Value * ptr = CreateCall(fMRemap, {addr, oldSize, newSize, flags});
     237    if (codegen::EnableAsserts) {
     238        CreateAssert(CheckMMapSuccess(ptr), "CreateMRemap: mremap failed to allocate memory");
     239    }
    236240    return ptr;
    237241}
     
    249253    }
    250254    addr = CreatePointerCast(addr, voidPtrTy);
    251     CreateAssert(addr, "CreateMUnmap: addr cannot be null");
    252255    size = CreateZExtOrTrunc(size, sizeTy);
    253256    return CreateCall(fMUnmap, {addr, size});
     
    451454            ConstantInt * _11 = getSize(11);
    452455            Value * bytes = CreatePointerCast(CreateMalloc(len), getInt8PtrTy());
    453             CreateMemCpy(bytes, CreateGlobalStringPtr("Assertion `"), _11, 1);
     456            CreateMemCpy(bytes, GetString("Assertion `"), _11, 1);
    454457            CreateMemCpy(CreateGEP(bytes, _11), msg, sz, 1);
    455             CreateMemCpy(CreateGEP(bytes, CreateAdd(sz, _11)), CreateGlobalStringPtr("' failed.\n"), getSize(10), 1);
     458            CreateMemCpy(CreateGEP(bytes, CreateAdd(sz, _11)), GetString("' failed.\n"), getSize(10), 1);
    456459            CreateWriteCall(getInt32(2), bytes, len);
     460
     461
    457462            CreateExit(-1);
    458463            CreateBr(success); // necessary to satisfy the LLVM verifier. this is not actually executed.
     
    461466            restoreIP(ip);
    462467        }
    463         CreateCall(function, {CreateICmpEQ(assertion, Constant::getNullValue(assertion->getType())), CreateGlobalStringPtr(failureMessage), getSize(failureMessage.size())});
     468        CreateCall(function, {CreateICmpEQ(assertion, Constant::getNullValue(assertion->getType())), GetString(failureMessage), getSize(failureMessage.size())});
    464469    }
    465470}
     
    484489}
    485490
     491inline static unsigned ceil_log2(const unsigned v) {
     492    assert ("log2(0) is undefined!" && v != 0);
     493    return 32 - __builtin_clz(v - 1);
     494}
     495
     496Value * CBuilder::CreatePopcount(Value * bits) {
     497    Value * ctpopFunc = Intrinsic::getDeclaration(mMod, Intrinsic::ctpop, bits->getType());
     498    return CreateCall(ctpopFunc, bits);
     499}
     500
     501Value * CBuilder::CreateCountForwardZeroes(Value * value) {
     502    Value * cttzFunc = Intrinsic::getDeclaration(mMod, Intrinsic::cttz, value->getType());
     503    return CreateCall(cttzFunc, {value, ConstantInt::getFalse(getContext())});
     504}
     505
     506Value * CBuilder::CreateCountReverseZeroes(Value * value) {
     507    Value * ctlzFunc = Intrinsic::getDeclaration(mMod, Intrinsic::ctlz, value->getType());
     508    return CreateCall(ctlzFunc, {value, ConstantInt::getFalse(getContext())});
     509}
     510
    486511Value * CBuilder::CreateCeilLog2(Value * value) {
    487512    IntegerType * ty = cast<IntegerType>(value->getType());
    488513    CreateAssert(value, "CreateCeilLog2: value cannot be zero");
    489     Value * m = CreateCall(Intrinsic::getDeclaration(mMod, Intrinsic::ctlz, ty), {value, ConstantInt::getFalse(getContext())});
    490     Value * isPowOf2 = CreateICmpEQ(CreateAnd(value, CreateSub(value, ConstantInt::get(ty, 1))), ConstantInt::getNullValue(ty));
    491     m = CreateSub(ConstantInt::get(m->getType(), ty->getBitWidth() - 1), m);
    492     return CreateSelect(isPowOf2, m, CreateAdd(m, ConstantInt::get(m->getType(), 1)));
     514    Value * m = CreateCountForwardZeroes(CreateSub(value, ConstantInt::get(ty, 1)));
     515    return CreateSub(ConstantInt::get(m->getType(), ty->getBitWidth() - 1), m);
     516}
     517
     518Value * CBuilder::GetString(StringRef Str) {
     519    Value * ptr = mMod->getGlobalVariable(Str, true);
     520    if (ptr == nullptr) {
     521        ptr = CreateGlobalString(Str, Str);
     522    }
     523    Value * zero = getInt32(0);
     524    return CreateInBoundsGEP(ptr, { zero, zero });
    493525}
    494526
  • icGREP/icgrep-devel/icgrep/IR_Gen/CBuilder.h

    r5389 r5398  
    105105    void CallPrintInt(const std::string & name, llvm::Value * const value);
    106106   
     107    llvm::Value * GetString(llvm::StringRef Str);
     108
    107109    inline llvm::IntegerType * getSizeTy() const {
    108110        return mSizeType;
     
    123125
    124126    virtual llvm::StoreInst *  CreateAtomicStoreRelease(llvm::Value * val, llvm::Value * ptr);
    125    
     127
    126128    void CreateAssert(llvm::Value * assertion, llvm::StringRef failureMessage);
    127129
     
    138140    }
    139141
     142    llvm::Value * CreatePopcount(llvm::Value * bits);
     143
     144    llvm::Value * CreateCountForwardZeroes(llvm::Value * value);
     145
     146    llvm::Value * CreateCountReverseZeroes(llvm::Value * value);
     147
    140148    llvm::Value * CreateCeilLog2(llvm::Value * value);
    141149
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_builder.cpp

    r5379 r5398  
    1313#include <llvm/Support/raw_ostream.h>
    1414#include <llvm/IR/TypeBuilder.h>
     15#include <toolchain.h>
    1516
    1617using namespace llvm;
     
    5556        IRBuilder<> builder(entry);
    5657        std::vector<Value *> args;
    57         args.push_back(CreateGlobalStringPtr(out.str().c_str()));
     58        args.push_back(GetString(out.str().c_str()));
    5859        Value * const name = &*(arg++);
    5960        name->setName("name");
     
    7172        printRegister = function;
    7273    }
    73     CreateCall(printRegister, {CreateGlobalStringPtr(name.c_str()), CreateBitCast(value, mBitBlockType)});
     74    CreateCall(printRegister, {GetString(name.c_str()), CreateBitCast(value, mBitBlockType)});
    7475}
    7576
     
    355356}
    356357
     358LoadInst * IDISA_Builder::CreateBlockAlignedLoad(Value * const ptr) {
     359    const auto alignment = mBitBlockWidth / 8;
     360    if (codegen::EnableAsserts) {
     361        Value * alignmentOffset = CreateURem(CreatePtrToInt(ptr, getSizeTy()), getSize(alignment));
     362        Value * alignmentCheck = CreateICmpEQ(alignmentOffset, getSize(0));
     363        CreateAssert(alignmentCheck, "CreateBlockAlignedLoad: pointer is unaligned");
     364    }
     365    return CreateAlignedLoad(ptr, alignment);
     366}
     367
     368void IDISA_Builder::CreateBlockAlignedStore(Value * const value, Value * const ptr) {
     369    const auto alignment = mBitBlockWidth / 8;
     370    if (codegen::EnableAsserts) {
     371        Value * alignmentOffset = CreateURem(CreatePtrToInt(ptr, getSizeTy()), getSize(alignment));
     372        Value * alignmentCheck = CreateICmpEQ(alignmentOffset, getSize(0));
     373        CreateAssert(alignmentCheck, "CreateBlockAlignedStore: pointer is not aligned");
     374    }
     375    CreateAlignedStore(value, ptr, alignment);
     376}
     377
    357378IDISA_Builder::IDISA_Builder(Module * m, unsigned archBitWidth, unsigned bitBlockWidth, unsigned stride, const bool SupportsIndirectBr, unsigned CacheAlignment)
    358379: CBuilder(m, archBitWidth, SupportsIndirectBr, CacheAlignment)
  • icGREP/icgrep-devel/icgrep/IR_Gen/idisa_builder.h

    r5377 r5398  
    133133    unsigned            mBitBlockWidth;
    134134    unsigned            mStride;
     135
    135136    llvm::VectorType *  mBitBlockType;
    136137    llvm::Constant *    mZeroInitializer;
     
    138139    llvm::Constant *    mPrintRegisterFunction;
    139140};
    140 
    141 inline llvm::LoadInst * IDISA_Builder::CreateBlockAlignedLoad(llvm::Value * const ptr) {
    142     return CreateAlignedLoad(ptr, mBitBlockWidth / 8);
    143 }
    144141
    145142inline llvm::LoadInst * IDISA_Builder::CreateBlockAlignedLoad(llvm::Value * const ptr, llvm::Value * const index) {
     
    149146inline llvm::LoadInst * IDISA_Builder::CreateBlockAlignedLoad(llvm::Value * const ptr, std::initializer_list<llvm::Value *> indices) {
    150147    return CreateBlockAlignedLoad(CreateGEP(ptr, indices));
    151 }
    152 
    153 inline void IDISA_Builder::CreateBlockAlignedStore(llvm::Value * const value, llvm::Value * const ptr) {
    154     CreateAlignedStore(value, ptr, mBitBlockWidth / 8);
    155148}
    156149
     
    163156}
    164157   
    165 
    166    
    167158}
    168159#endif // IDISA_BUILDER_H
  • icGREP/icgrep-devel/icgrep/IR_Gen/tracegen.h

    r5272 r5398  
    5151unsigned TraceTool::newTraceVar(std::string traceName) {
    5252    std::string formatString = traceName + " = %" PRIx64 "\n";
    53     mTraceFormatString.push_back(iBuilder->CreateGlobalStringPtr(formatString.c_str()));
     53    mTraceFormatString.push_back(iBuilder->GetString(formatString.c_str()));
    5454    return mTraceVarCount++;
    5555}
Note: See TracChangeset for help on using the changeset viewer.