Ignore:
Timestamp:
May 24, 2017, 12:06:43 PM (2 years ago)
Author:
nmedfort
Message:

Eliminated ExecutionEngine? memory leak. Intentionally broke compatibility with prior versions to ensure unchecked in projects are restructured.

File:
1 edited

Legend:

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

    r5472 r5474  
    280280    CreateAssert(ptr, "CreateAlignedMalloc: returned null pointer.");
    281281    return ptr;
     282}
     283
     284
     285Value * CBuilder::CreateRealloc(Value * const ptr, Value * size) {
     286    Module * const m = getModule();
     287    IntegerType * const sizeTy = getSizeTy();
     288    PointerType * const voidPtrTy = getVoidPtrTy();
     289    Function * f = m->getFunction("realloc");
     290    if (f == nullptr) {
     291        FunctionType * fty = FunctionType::get(voidPtrTy, {voidPtrTy, sizeTy}, false);
     292        f = Function::Create(fty, Function::ExternalLinkage, "realloc", m);
     293        f->setCallingConv(CallingConv::C);
     294        f->setDoesNotAlias(0);
     295        f->setDoesNotAlias(1);
     296        // f = LinkFunction("realloc", &realloc);
     297    }
     298    Value * const addr = CreatePointerCast(ptr, voidPtrTy);
     299    size = CreateZExtOrTrunc(size, sizeTy);
     300    CallInst * const ci = CreateCall(f, {addr, size});
     301    ci->setTailCall();
     302    return CreatePointerCast(ci, ptr->getType());
     303}
     304
     305void CBuilder::CreateFree(Value * ptr) {
     306    assert (ptr->getType()->isPointerTy());
     307    Module * const m = getModule();
     308    Type * const voidPtrTy =  getVoidPtrTy();
     309    Function * f = m->getFunction("free");
     310    if (f == nullptr) {
     311        FunctionType * fty = FunctionType::get(getVoidTy(), {voidPtrTy}, false);
     312        f = Function::Create(fty, Function::ExternalLinkage, "free", m);
     313        f->setCallingConv(CallingConv::C);
     314        // f = LinkFunction("free", &std::free);
     315    }
     316    ptr = CreatePointerCast(ptr, voidPtrTy);
     317    CreateCall(f, ptr)->setTailCall();
    282318}
    283319
     
    446482}
    447483
    448 void CBuilder::CreateFree(Value * ptr) {
    449     assert (ptr->getType()->isPointerTy());
    450     Module * const m = getModule();
    451     Type * const voidPtrTy =  getVoidPtrTy();
    452     Function * f = m->getFunction("free");
    453     if (f == nullptr) {
    454         FunctionType * fty = FunctionType::get(getVoidTy(), {voidPtrTy}, false);
    455         f = Function::Create(fty, Function::ExternalLinkage, "free", m);
    456         f->setCallingConv(CallingConv::C);
    457         // f = LinkFunction("free", &std::free);
    458     }
    459     ptr = CreatePointerCast(ptr, voidPtrTy);
    460     CreateCall(f, ptr)->setTailCall();
    461 }
    462 
    463 Value * CBuilder::CreateRealloc(Value * const ptr, Value * size) {
    464     Module * const m = getModule();
    465     IntegerType * const sizeTy = getSizeTy();
    466     PointerType * const voidPtrTy = getVoidPtrTy();
    467     Function * f = m->getFunction("realloc");
    468     if (f == nullptr) {
    469         FunctionType * fty = FunctionType::get(voidPtrTy, {voidPtrTy, sizeTy}, false);
    470         f = Function::Create(fty, Function::ExternalLinkage, "realloc", m);
    471         f->setCallingConv(CallingConv::C);
    472         f->setDoesNotAlias(0);
    473         f->setDoesNotAlias(1);
    474         // f = LinkFunction("realloc", &realloc);
    475     }
    476     Value * const addr = CreatePointerCast(ptr, voidPtrTy);
    477     size = CreateZExtOrTrunc(size, sizeTy);
    478     CallInst * const ci = CreateCall(f, {addr, size});
    479     ci->setTailCall();
    480     return CreatePointerCast(ci, ptr->getType());
    481 }
    482 
    483484PointerType * CBuilder::getVoidPtrTy() const {
    484485    return TypeBuilder<void *, true>::get(getContext());
Note: See TracChangeset for help on using the changeset viewer.