ObjCARCAnalysisUtils.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. #include "llvm/Analysis/ObjCARCAnalysisUtils.h"
  15. #include "llvm/Analysis/AliasAnalysis.h"
  16. #include "llvm/Support/CommandLine.h"
  17. using namespace llvm;
  18. using namespace llvm::objcarc;
  19. /// A handy option to enable/disable all ARC Optimizations.
  20. bool llvm::objcarc::EnableARCOpts;
  21. static cl::opt<bool, true> EnableARCOptimizations(
  22. "enable-objc-arc-opts", cl::desc("enable/disable all ARC Optimizations"),
  23. cl::location(EnableARCOpts), cl::init(true), cl::Hidden);
  24. bool llvm::objcarc::IsPotentialRetainableObjPtr(const Value *Op,
  25. AAResults &AA) {
  26. // First make the rudimentary check.
  27. if (!IsPotentialRetainableObjPtr(Op))
  28. return false;
  29. // Objects in constant memory are not reference-counted.
  30. if (AA.pointsToConstantMemory(Op))
  31. return false;
  32. // Pointers in constant memory are not pointing to reference-counted objects.
  33. if (const LoadInst *LI = dyn_cast<LoadInst>(Op))
  34. if (AA.pointsToConstantMemory(LI->getPointerOperand()))
  35. return false;
  36. // Otherwise assume the worst.
  37. return true;
  38. }