aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
authorEric Christopher <echristo@apple.com>2009-10-27 00:52:25 +0000
committerEric Christopher <echristo@apple.com>2009-10-27 00:52:25 +0000
commit7b5e61707a128a222e5e7ab20eb8154ca81001cb (patch)
tree97b92c485a5974efe8f986bc8d97daae634ff793 /lib/Transforms
parentdd22a45acc24ff1e4954fda753c555a6365d1dec (diff)
Add objectsize intrinsic and hook it up through codegen. Doesn't
do anything than return "I don't know" at the moment. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@85189 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/Scalar/SimplifyLibCalls.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/Transforms/Scalar/SimplifyLibCalls.cpp b/lib/Transforms/Scalar/SimplifyLibCalls.cpp
index e186601505..575c93b9dd 100644
--- a/lib/Transforms/Scalar/SimplifyLibCalls.cpp
+++ b/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;
}