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.

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.