From 56e1cef70546f6c8a30ad742dc7b6a9dd9e4acd2 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 22 Aug 2011 17:29:11 +0000 Subject: Constant pointers to objects don't need reference counting. llvm-svn: 138242 --- llvm/lib/Transforms/Scalar/ObjCARC.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'llvm/lib/Transforms/Scalar/ObjCARC.cpp') diff --git a/llvm/lib/Transforms/Scalar/ObjCARC.cpp b/llvm/lib/Transforms/Scalar/ObjCARC.cpp index fea03b5f5b5..9654b1ecd30 100644 --- a/llvm/lib/Transforms/Scalar/ObjCARC.cpp +++ b/llvm/lib/Transforms/Scalar/ObjCARC.cpp @@ -515,6 +515,10 @@ static bool IsObjCIdentifiedObject(const Value *V) { const Value *Pointer = StripPointerCastsAndObjCCalls(LI->getPointerOperand()); if (const GlobalVariable *GV = dyn_cast(Pointer)) { + // A constant pointer can't be pointing to an object on the heap. It may + // be reference-counted, but it won't be deleted. + if (GV->isConstant()) + return true; StringRef Name = GV->getName(); // These special variables are known to hold values which are not // reference-counted pointers. @@ -2744,6 +2748,15 @@ ObjCARCOpt::PerformCodePlacement(DenseMap // regardless of what possible decrements or uses lie between them. bool KnownSafe = isa(Arg) || isa(Arg); + // A constant pointer can't be pointing to an object on the heap. It may + // be reference-counted, but it won't be deleted. + if (const LoadInst *LI = dyn_cast(Arg)) + if (const GlobalVariable *GV = + dyn_cast( + StripPointerCastsAndObjCCalls(LI->getPointerOperand()))) + if (GV->isConstant()) + KnownSafe = true; + // If a pair happens in a region where it is known that the reference count // is already incremented, we can similarly ignore possible decrements. bool KnownSafeTD = true, KnownSafeBU = true; -- cgit v1.2.3