[llvm-commits] [llvm] r89479 - /llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp
Eric Christopher
echristo at apple.com
Fri Nov 20 12:21:52 PST 2009
Um oops. Can you please revert? Apparently I forgot to save the file
when building and testing the last time.
Sorry again.
-eric
On Nov 20, 2009, at 12:06 PM, Evan Cheng <evan.cheng at apple.com> wrote:
> This breaks the build?
>
> /tmp/llvmCore_Embedded.roots/llvmCore_Embedded~obj/src/lib/
> Transforms/Scalar/SimplifyLibCalls.cpp: In member function
> 'llvm::Value*<unnamed>::LibCallOptimization::EmitMemMove
> (llvm::Value*,\
> llvm::Value*, llvm::Value*, unsigned int, llvm::IRBuilder<true,
> llvm::ConstantFolder, llvm::IRBuilderDefaultInserter<true> >&)':
> /tmp/llvmCore_Embedded.roots/llvmCore_Embedded~obj/src/lib/
> Transforms/Scalar/SimplifyLibCalls.cpp:175: error: declaration of
> 'llvm::Value* Dst' shadows a parameter
> /tmp/llvmCore_Embedded.roots/llvmCore_Embedded~obj/src/lib/
> Transforms/Scalar/SimplifyLibCalls.cpp:175: error: 'CI' was not
> declared in this scope
> /tmp/llvmCore_Embedded.roots/llvmCore_Embedded~obj/src/lib/
> Transforms/Scalar/SimplifyLibCalls.cpp:176: error: declaration of
> 'llvm::Value* Src' shadows a parameter
> /tmp/llvmCore_Embedded.roots/llvmCore_Embedded~obj/src/lib/
> Transforms/Scalar/SimplifyLibCalls.cpp:178: error: declaration of
> 'llvm::Value* Align' shadows a parameter
>
> Evan
> On Nov 20, 2009, at 11:57 AM, Eric Christopher wrote:
>
>> Author: echristo
>> Date: Fri Nov 20 13:57:37 2009
>> New Revision: 89479
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=89479&view=rev
>> Log:
>> Add some rough optimizations for checking routines.
>>
>> Modified:
>> llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp
>>
>> Modified: llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp?rev=89479&r1=89478&r2=89479&view=diff
>>
>> ===
>> ===
>> ===
>> =====================================================================
>> --- llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp (original)
>> +++ llvm/trunk/lib/Transforms/Scalar/SimplifyLibCalls.cpp Fri Nov
>> 20 13:57:37 2009
>> @@ -81,6 +81,9 @@
>> Value *EmitMemCpy(Value *Dst, Value *Src, Value *Len,
>> unsigned Align, IRBuilder<> &B);
>>
>> + Value *EmitMemMove(Value *Dst, Value *Src, Value *Len,
>> + unsigned Align, IRBuilder<> &B);
>> +
>> /// EmitMemChr - Emit a call to the memchr function. This assumes
>> that Ptr is
>> /// a pointer, Val is an i32 value, and Len is an 'intptr_t' value.
>> Value *EmitMemChr(Value *Ptr, Value *Val, Value *Len, IRBuilder<>
>> &B);
>> @@ -160,6 +163,22 @@
>> ConstantInt::get(Type::getInt32Ty(*Context),
>> Align));
>> }
>>
>> +/// EmitMemMOve - Emit a call to the memmove function to the
>> builder. This
>> +/// always expects that the size has type 'intptr_t' and Dst/Src
>> are pointers.
>> +Value *LibCallOptimization::EmitMemMove(Value *Dst, Value *Src,
>> Value *Len,
>> + unsigned Align, IRBuilder<> &B) {
>> + Module *M = Caller->getParent();
>> + Intrinsic::ID IID = Intrinsic::memmove;
>> + const Type *Tys[1];
>> + Tys[0] = TD->getIntPtrType(*Context);
>> + Value *MemMove = Intrinsic::getDeclaration(M, IID, Tys, 1);
>> + Value *Dst = CastToCStr(CI->getOperand(1), B);
>> + Value *Src = CastToCStr(CI->getOperand(2), B);
>> + Value *Size = CI->getOperand(3);
>> + Value *Align = ConstantInt::get(Type::getInt32Ty(*Context), 1);
>> + return B.CreateCall4(MemMove, Dst, Src, Size, Align);
>> +}
>> +
>> /// EmitMemChr - Emit a call to the memchr function. This assumes
>> that Ptr is
>> /// a pointer, Val is an i32 value, and Len is an 'intptr_t' value.
>> Value *LibCallOptimization::EmitMemChr(Value *Ptr, Value *Val,
>> @@ -1010,16 +1029,7 @@
>> return 0;
>>
>> // memmove(x, y, n) -> llvm.memmove(x, y, n, 1)
>> - Module *M = Caller->getParent();
>> - Intrinsic::ID IID = Intrinsic::memmove;
>> - const Type *Tys[1];
>> - Tys[0] = TD->getIntPtrType(*Context);
>> - Value *MemMove = Intrinsic::getDeclaration(M, IID, Tys, 1);
>> - Value *Dst = CastToCStr(CI->getOperand(1), B);
>> - Value *Src = CastToCStr(CI->getOperand(2), B);
>> - Value *Size = CI->getOperand(3);
>> - Value *Align = ConstantInt::get(Type::getInt32Ty(*Context), 1);
>> - B.CreateCall4(MemMove, Dst, Src, Size, Align);
>> + EmitMemMove(CI->getOperand(1), CI->getOperand(2), CI-
>> >getOperand(3), 1, B);
>> return CI->getOperand(1);
>> }
>> };
>> @@ -1048,6 +1058,96 @@
>> };
>>
>> //
>> ===
>> ---
>> -------------------------------------------------------------------
>> ===//
>> +// Object Size Checking Optimizations
>> +//
>> ===
>> ---
>> -------------------------------------------------------------------
>> ===//
>> +//===---------------------------------------===//
>> +// 'memcpy_chk' Optimizations
>> +
>> +struct MemCpyChkOpt : public LibCallOptimization {
>> + virtual Value *CallOptimizer(Function *Callee, CallInst *CI,
>> IRBuilder<> &B) {
>> + // These optimizations require TargetData.
>> + if (!TD) return 0;
>> +
>> + const FunctionType *FT = Callee->getFunctionType();
>> + if (FT->getNumParams() != 4 || FT->getReturnType() != FT-
>> >getParamType(0) ||
>> + !isa<PointerType>(FT->getParamType(0)) ||
>> + !isa<PointerType>(FT->getParamType(1)) ||
>> + !isa<IntegerType>(FT->getParamType(3)) ||
>> + FT->getParamType(2) != TD->getIntPtrType(*Context))
>> + return 0;
>> +
>> + ConstantInt *SizeCI = dyn_cast<ConstantInt>(CI->getOperand(4));
>> + if (!SizeCI)
>> + return 0;
>> + if (SizeCI->isAllOnesValue()) {
>> + EmitMemCpy(CI->getOperand(1), CI->getOperand(2), CI-
>> >getOperand(3), 1, B);
>> + return CI->getOperand(1);
>> + }
>> +
>> + return 0;
>> + }
>> +};
>> +
>> +//===---------------------------------------===//
>> +// 'memset_chk' Optimizations
>> +
>> +struct MemSetChkOpt : public LibCallOptimization {
>> + virtual Value *CallOptimizer(Function *Callee, CallInst *CI,
>> IRBuilder<> &B) {
>> + // These optimizations require TargetData.
>> + if (!TD) return 0;
>> +
>> + const FunctionType *FT = Callee->getFunctionType();
>> + if (FT->getNumParams() != 4 || FT->getReturnType() != FT-
>> >getParamType(0) ||
>> + !isa<PointerType>(FT->getParamType(0)) ||
>> + !isa<IntegerType>(FT->getParamType(1)) ||
>> + !isa<IntegerType>(FT->getParamType(3)) ||
>> + FT->getParamType(2) != TD->getIntPtrType(*Context))
>> + return 0;
>> +
>> + ConstantInt *SizeCI = dyn_cast<ConstantInt>(CI->getOperand(4));
>> + if (!SizeCI)
>> + return 0;
>> + if (SizeCI->isAllOnesValue()) {
>> + Value *Val = B.CreateIntCast(CI->getOperand(2),
>> Type::getInt8Ty(*Context),
>> + false);
>> + EmitMemSet(CI->getOperand(1), Val, CI->getOperand(3), B);
>> + return CI->getOperand(1);
>> + }
>> +
>> + return 0;
>> + }
>> +};
>> +
>> +//===---------------------------------------===//
>> +// 'memmove_chk' Optimizations
>> +
>> +struct MemMoveChkOpt : public LibCallOptimization {
>> + virtual Value *CallOptimizer(Function *Callee, CallInst *CI,
>> IRBuilder<> &B) {
>> + // These optimizations require TargetData.
>> + if (!TD) return 0;
>> +
>> + const FunctionType *FT = Callee->getFunctionType();
>> + if (FT->getNumParams() != 4 || FT->getReturnType() != FT-
>> >getParamType(0) ||
>> + !isa<PointerType>(FT->getParamType(0)) ||
>> + !isa<PointerType>(FT->getParamType(1)) ||
>> + !isa<IntegerType>(FT->getParamType(3)) ||
>> + FT->getParamType(2) != TD->getIntPtrType(*Context))
>> + return 0;
>> +
>> + ConstantInt *SizeCI = dyn_cast<ConstantInt>(CI->getOperand(4));
>> + if (!SizeCI)
>> + return 0;
>> + if (SizeCI->isAllOnesValue()) {
>> + EmitMemMove(CI->getOperand(1), CI->getOperand(2), CI-
>> >getOperand(3),
>> + 1, B);
>> + return CI->getOperand(1);
>> + }
>> +
>> + return 0;
>> + }
>> +};
>> +
>> +//
>> ===
>> ---
>> -------------------------------------------------------------------
>> ===//
>> // Math Library Optimizations
>> //
>> ===
>> ---
>> -------------------------------------------------------------------
>> ===//
>>
>> @@ -1586,7 +1686,10 @@
>> // Formatting and IO Optimizations
>> SPrintFOpt SPrintF; PrintFOpt PrintF;
>> FWriteOpt FWrite; FPutsOpt FPuts; FPrintFOpt FPrintF;
>> +
>> + // Object Size Checking
>> SizeOpt ObjectSize;
>> + MemCpyChkOpt MemCpyChk; MemSetChkOpt MemSetChk; MemMoveChkOpt
>> MemMoveChk;
>>
>> bool Modified; // This is only used by doInitialization.
>> public:
>> @@ -1693,8 +1796,12 @@
>> Optimizations["fputs"] = &FPuts;
>> Optimizations["fprintf"] = &FPrintF;
>>
>> - // Miscellaneous
>> - Optimizations["llvm.objectsize"] = &ObjectSize;
>> + // Object Size Checking
>> + Optimizations["llvm.objectsize.i32"] = &ObjectSize;
>> + Optimizations["llvm.objectsize.i64"] = &ObjectSize;
>> + Optimizations["__memcpy_chk"] = &MemCpyChk;
>> + Optimizations["__memset_chk"] = &MemSetChk;
>> + Optimizations["__memmove_chk"] = &MemMoveChk;
>> }
>>
>>
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
More information about the llvm-commits
mailing list