xref: /freebsd/contrib/llvm-project/llvm/lib/Analysis/ObjCARCAnalysisUtils.cpp (revision e8d8bef961a50d4dc22501cde4fb9fb0be1b2532)
10b57cec5SDimitry Andric //===- ObjCARCAnalysisUtils.cpp -------------------------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file implements common infrastructure for libLLVMObjCARCOpts.a, which
100b57cec5SDimitry Andric // implements several scalar transformations over the LLVM intermediate
110b57cec5SDimitry Andric // representation, including the C bindings for that library.
120b57cec5SDimitry Andric //
130b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
140b57cec5SDimitry Andric 
150b57cec5SDimitry Andric #include "llvm/Analysis/ObjCARCAnalysisUtils.h"
16*e8d8bef9SDimitry Andric #include "llvm/Analysis/AliasAnalysis.h"
170b57cec5SDimitry Andric #include "llvm/Support/CommandLine.h"
180b57cec5SDimitry Andric 
190b57cec5SDimitry Andric using namespace llvm;
200b57cec5SDimitry Andric using namespace llvm::objcarc;
210b57cec5SDimitry Andric 
220b57cec5SDimitry Andric /// A handy option to enable/disable all ARC Optimizations.
230b57cec5SDimitry Andric bool llvm::objcarc::EnableARCOpts;
240b57cec5SDimitry Andric static cl::opt<bool, true> EnableARCOptimizations(
250b57cec5SDimitry Andric     "enable-objc-arc-opts", cl::desc("enable/disable all ARC Optimizations"),
260b57cec5SDimitry Andric     cl::location(EnableARCOpts), cl::init(true), cl::Hidden);
27*e8d8bef9SDimitry Andric 
IsPotentialRetainableObjPtr(const Value * Op,AAResults & AA)28*e8d8bef9SDimitry Andric bool llvm::objcarc::IsPotentialRetainableObjPtr(const Value *Op,
29*e8d8bef9SDimitry Andric                                                 AAResults &AA) {
30*e8d8bef9SDimitry Andric   // First make the rudimentary check.
31*e8d8bef9SDimitry Andric   if (!IsPotentialRetainableObjPtr(Op))
32*e8d8bef9SDimitry Andric     return false;
33*e8d8bef9SDimitry Andric 
34*e8d8bef9SDimitry Andric   // Objects in constant memory are not reference-counted.
35*e8d8bef9SDimitry Andric   if (AA.pointsToConstantMemory(Op))
36*e8d8bef9SDimitry Andric     return false;
37*e8d8bef9SDimitry Andric 
38*e8d8bef9SDimitry Andric   // Pointers in constant memory are not pointing to reference-counted objects.
39*e8d8bef9SDimitry Andric   if (const LoadInst *LI = dyn_cast<LoadInst>(Op))
40*e8d8bef9SDimitry Andric     if (AA.pointsToConstantMemory(LI->getPointerOperand()))
41*e8d8bef9SDimitry Andric       return false;
42*e8d8bef9SDimitry Andric 
43*e8d8bef9SDimitry Andric   // Otherwise assume the worst.
44*e8d8bef9SDimitry Andric   return true;
45*e8d8bef9SDimitry Andric }
46