Changes in directory llvm/lib/Transforms/IPO:
SimplifyLibCalls.cpp updated: 1.64 -> 1.65 --- Log message: Simplify fprintf(file, "%s", str) to fputs(str, file). --- Diffs of the changes: (+36 -16) SimplifyLibCalls.cpp | 52 +++++++++++++++++++++++++++++++++++---------------- 1 files changed, 36 insertions(+), 16 deletions(-) Index: llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp diff -u llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp:1.64 llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp:1.65 --- llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp:1.64 Fri May 12 18:35:26 2006 +++ llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp Thu Jun 15 23:52:30 2006 @@ -229,6 +229,15 @@ return fputc_func; } + /// @brief Return a Function* for the fputs libcall + Function* get_fputs(const Type* FILEptr_type) { + if (!fputs_func) + fputs_func = M->getOrInsertFunction("fputs", Type::IntTy, + PointerType::get(Type::SByteTy), + FILEptr_type, NULL); + return fputs_func; + } + /// @brief Return a Function* for the fwrite libcall Function* get_fwrite(const Type* FILEptr_type) { if (!fwrite_func) @@ -310,6 +319,7 @@ M = &mod; TD = &getAnalysis<TargetData>(); fputc_func = 0; + fputs_func = 0; fwrite_func = 0; memcpy_func = 0; memchr_func = 0; @@ -325,7 +335,7 @@ private: /// Caches for function pointers. - Function *fputc_func, *fwrite_func; + Function *fputc_func, *fputs_func, *fwrite_func; Function *memcpy_func, *memchr_func; Function* sqrt_func; Function *strcpy_func, *strlen_func; @@ -1340,21 +1350,31 @@ { uint64_t len = 0; ConstantArray* CA = 0; - if (!getConstantStringLength(ci->getOperand(3), len, &CA)) - return false; - - // fprintf(file,"%s",str) -> fwrite(fmt,strlen(fmt),1,file) - const Type* FILEptr_type = ci->getOperand(1)->getType(); - Function* fwrite_func = SLC.get_fwrite(FILEptr_type); - if (!fwrite_func) - return false; - std::vector<Value*> args; - args.push_back(CastToCStr(ci->getOperand(3), *ci)); - args.push_back(ConstantUInt::get(SLC.getIntPtrType(),len)); - args.push_back(ConstantUInt::get(SLC.getIntPtrType(),1)); - args.push_back(ci->getOperand(1)); - new CallInst(fwrite_func,args,ci->getName(),ci); - ci->replaceAllUsesWith(ConstantSInt::get(Type::IntTy,len)); + if (getConstantStringLength(ci->getOperand(3), len, &CA)) { + // fprintf(file,"%s",str) -> fwrite(str,strlen(str),1,file) + const Type* FILEptr_type = ci->getOperand(1)->getType(); + Function* fwrite_func = SLC.get_fwrite(FILEptr_type); + if (!fwrite_func) + return false; + std::vector<Value*> args; + args.push_back(CastToCStr(ci->getOperand(3), *ci)); + args.push_back(ConstantUInt::get(SLC.getIntPtrType(),len)); + args.push_back(ConstantUInt::get(SLC.getIntPtrType(),1)); + args.push_back(ci->getOperand(1)); + new CallInst(fwrite_func,args,ci->getName(),ci); + ci->replaceAllUsesWith(ConstantSInt::get(Type::IntTy,len)); + } else { + // fprintf(file,"%s",str) -> fputs(str,file) + const Type* FILEptr_type = ci->getOperand(1)->getType(); + Function* fputs_func = SLC.get_fputs(FILEptr_type); + if (!fputs_func) + return false; + std::vector<Value*> args; + args.push_back(ci->getOperand(3)); + args.push_back(ci->getOperand(1)); + new CallInst(fputs_func,args,ci->getName(),ci); + ci->replaceAllUsesWith(ConstantSInt::get(Type::IntTy,len)); + } break; } case 'c': _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits