| 1 | //===- ObjCARCAnalysisUtils.cpp -------------------------------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file implements common infrastructure for libLLVMObjCARCOpts.a, which |
| 10 | // implements several scalar transformations over the LLVM intermediate |
| 11 | // representation, including the C bindings for that library. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "llvm/Analysis/ObjCARCAnalysisUtils.h" |
| 16 | #include "llvm/Analysis/AliasAnalysis.h" |
| 17 | #include "llvm/Support/CommandLine.h" |
| 18 | |
| 19 | using namespace llvm; |
| 20 | using namespace llvm::objcarc; |
| 21 | |
| 22 | /// A handy option to enable/disable all ARC Optimizations. |
| 23 | bool llvm::objcarc::EnableARCOpts; |
| 24 | static cl::opt<bool, true> EnableARCOptimizations( |
| 25 | "enable-objc-arc-opts" , cl::desc("enable/disable all ARC Optimizations" ), |
| 26 | cl::location(L&: EnableARCOpts), cl::init(Val: true), cl::Hidden); |
| 27 | |
| 28 | bool llvm::objcarc::IsPotentialRetainableObjPtr(const Value *Op, |
| 29 | AAResults &AA) { |
| 30 | // First make the rudimentary check. |
| 31 | if (!IsPotentialRetainableObjPtr(Op)) |
| 32 | return false; |
| 33 | |
| 34 | // Objects in constant memory are not reference-counted. |
| 35 | if (AA.pointsToConstantMemory(P: Op)) |
| 36 | return false; |
| 37 | |
| 38 | // Pointers in constant memory are not pointing to reference-counted objects. |
| 39 | if (const LoadInst *LI = dyn_cast<LoadInst>(Val: Op)) |
| 40 | if (AA.pointsToConstantMemory(P: LI->getPointerOperand())) |
| 41 | return false; |
| 42 | |
| 43 | // Otherwise assume the worst. |
| 44 | return true; |
| 45 | } |
| 46 | |