diff options
author | Eric Christopher <echristo@apple.com> | 2009-10-27 00:52:25 +0000 |
---|---|---|
committer | Eric Christopher <echristo@apple.com> | 2009-10-27 00:52:25 +0000 |
commit | 7a50b280c18e93e005fb3206ce16df2c70e83a97 (patch) | |
tree | d1df75c633beb885b27fdeb10574e20a39e4c1c9 /llvm/lib/Transforms/Scalar | |
parent | bb85c2644a99d3593d0279eb8841539e18e40270 (diff) | |
download | bcm5719-llvm-7a50b280c18e93e005fb3206ce16df2c70e83a97.tar.gz bcm5719-llvm-7a50b280c18e93e005fb3206ce16df2c70e83a97.zip |
Add objectsize intrinsic and hook it up through codegen. Doesn't
do anything than return "I don't know" at the moment.
llvm-svn: 85189
Diffstat (limited to 'llvm/lib/Transforms/Scalar')
-rw-r--r-- | llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp index e186601505c..575c93b9dd3 100644 --- a/llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp +++ b/llvm/lib/Transforms/Scalar/SimplifyLibCalls.cpp @@ -509,6 +509,27 @@ static bool IsOnlyUsedInZeroEqualityComparison(Value *V) { } //===----------------------------------------------------------------------===// +// Miscellaneous LibCall/Intrinsic Optimizations +//===----------------------------------------------------------------------===// + +namespace { +struct SizeOpt : public LibCallOptimization { + virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B) { + // TODO: We can do more with this, but delaying to here should be no change + // in behavior. + ConstantInt *Const = dyn_cast<ConstantInt>(CI->getOperand(2)); + + if (!Const) return 0; + + if (Const->getZExtValue() < 2) + return Constant::getAllOnesValue(Const->getType()); + else + return ConstantInt::get(Const->getType(), 0); + } +}; +} + +//===----------------------------------------------------------------------===// // String and Memory LibCall Optimizations //===----------------------------------------------------------------------===// @@ -1548,6 +1569,7 @@ namespace { // Formatting and IO Optimizations SPrintFOpt SPrintF; PrintFOpt PrintF; FWriteOpt FWrite; FPutsOpt FPuts; FPrintFOpt FPrintF; + SizeOpt ObjectSize; bool Modified; // This is only used by doInitialization. public: @@ -1653,6 +1675,9 @@ void SimplifyLibCalls::InitOptimizations() { Optimizations["fwrite"] = &FWrite; Optimizations["fputs"] = &FPuts; Optimizations["fprintf"] = &FPrintF; + + // Miscellaneous + Optimizations["llvm.objectsize"] = &ObjectSize; } |