Ignore:
Timestamp:
Apr 19, 2017, 1:41:55 PM (2 years ago)
Author:
cameron
Message:

Speed-up file output using new temporary files; unlinking old files

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

Legend:

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

    r5412 r5415  
    6868    return CreateCall(closeFn, {fildes});
    6969}
     70
     71
     72Value * CBuilder::CreateUnlinkCall(Value * path) {
     73    Function * unlinkFunc = mMod->getFunction("unlink");
     74    if (unlinkFunc == nullptr) {
     75        FunctionType * fty = FunctionType::get(getInt32Ty(), {getInt8PtrTy()}, false);
     76        unlinkFunc = Function::Create(fty, Function::ExternalLinkage, "unlink", mMod);
     77        unlinkFunc->setCallingConv(CallingConv::C);
     78    }
     79    return CreateCall(unlinkFunc, {path});
     80}
     81
     82Value * CBuilder::CreateMkstempCall(Value * ftemplate) {
     83    Function * mkstempFn = mMod->getFunction("mkstemp");
     84    if (mkstempFn == nullptr) {
     85        mkstempFn = cast<Function>(mMod->getOrInsertFunction("mkstemp", getInt32Ty(), getInt8PtrTy(), nullptr));
     86    }
     87    return CreateCall(mkstempFn, {ftemplate});
     88}
     89
     90
     91Value * CBuilder::CreateStrlenCall(Value * str) {
     92    Function * strlenFn = mMod->getFunction("strlen");
     93    if (strlenFn == nullptr) {
     94        strlenFn = cast<Function>(mMod->getOrInsertFunction("strlen", getSizeTy(), getInt8PtrTy(), nullptr));
     95    }
     96    return CreateCall(strlenFn, {str});
     97}
     98
    7099
    71100Function * CBuilder::GetPrintf() {
     
    472501    }
    473502    return CreateCall(fCloseFunc, {stream});
     503}
     504
     505Value * CBuilder::CreateRenameCall(Value * oldName, Value * newName) {
     506    Function * renameFunc = mMod->getFunction("rename");
     507    if (renameFunc == nullptr) {
     508        FunctionType * fty = FunctionType::get(getInt32Ty(), {getInt8PtrTy(), getInt8PtrTy()}, false);
     509        renameFunc = Function::Create(fty, Function::ExternalLinkage, "rename", mMod);
     510        renameFunc->setCallingConv(CallingConv::C);
     511    }
     512    return CreateCall(renameFunc, {oldName, newName});
     513}
     514
     515Value * CBuilder::CreateRemoveCall(Value * path) {
     516    Function * removeFunc = mMod->getFunction("remove");
     517    if (removeFunc == nullptr) {
     518        FunctionType * fty = FunctionType::get(getInt32Ty(), {getInt8PtrTy()}, false);
     519        removeFunc = Function::Create(fty, Function::ExternalLinkage, "remove", mMod);
     520        removeFunc->setCallingConv(CallingConv::C);
     521    }
     522    return CreateCall(removeFunc, {path});
    474523}
    475524
  • icGREP/icgrep-devel/icgrep/IR_Gen/CBuilder.h

    r5411 r5415  
    6262    //  Create a call to:  int fclose ( FILE * stream );
    6363    llvm::Value * CreateFCloseCall(llvm::Value * stream);
     64    //  Create a call to:  int remove(const char *path);
     65    llvm::Value * CreateRemoveCall(llvm::Value * path);
     66   
     67    //  Create a call to:  int rename(const char *old, const char *new);
     68    llvm::Value * CreateRenameCall(llvm::Value * oldName, llvm::Value * newName);
    6469   
    6570    llvm::Function * GetPrintf();
     
    7580    //  Create a call to:  int close(int filedes);
    7681    llvm::Value * CreateCloseCall(llvm::Value * fildes);
     82    //  Create a call to:  int unlink(const char *path);
     83    llvm::Value * CreateUnlinkCall(llvm::Value * path);
    7784
    78 
     85    //  Create calls to stdlib.h functions.
     86    //
     87    //  Create a call to:  int mkstemp (char *template);
     88    llvm::Value * CreateMkstempCall(llvm::Value * ftemplate);
     89   
     90    //  Create a call to:  size_t strlen(const char *str);
     91    llvm::Value * CreateStrlenCall(llvm::Value * str);
     92   
     93   
     94   
    7995    llvm::Value * CreateAnonymousMMap(llvm::Value * size);
    8096
Note: See TracChangeset for help on using the changeset viewer.