Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:16

0001 //===- ObjCARCUtil.h - ObjC ARC Utility Functions ---------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 /// \file
0009 /// This file defines ARC utility functions which are used by various parts of
0010 /// the compiler.
0011 ///
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_ANALYSIS_OBJCARCUTIL_H
0015 #define LLVM_ANALYSIS_OBJCARCUTIL_H
0016 
0017 #include "llvm/Analysis/ObjCARCInstKind.h"
0018 #include "llvm/IR/Function.h"
0019 #include "llvm/IR/InstrTypes.h"
0020 #include "llvm/IR/LLVMContext.h"
0021 
0022 namespace llvm {
0023 namespace objcarc {
0024 
0025 inline const char *getRVMarkerModuleFlagStr() {
0026   return "clang.arc.retainAutoreleasedReturnValueMarker";
0027 }
0028 
0029 inline bool hasAttachedCallOpBundle(const CallBase *CB) {
0030   // Ignore the bundle if the return type is void. Global optimization passes
0031   // can turn the called function's return type to void. That should happen only
0032   // if the call doesn't return and the call to @llvm.objc.clang.arc.noop.use
0033   // no longer consumes the function return or is deleted. In that case, it's
0034   // not necessary to emit the marker instruction or calls to the ARC runtime
0035   // functions.
0036   return !CB->getFunctionType()->getReturnType()->isVoidTy() &&
0037          CB->getOperandBundle(LLVMContext::OB_clang_arc_attachedcall)
0038              .has_value();
0039 }
0040 
0041 /// This function returns operand bundle clang_arc_attachedcall's argument,
0042 /// which is the address of the ARC runtime function.
0043 inline std::optional<Function *> getAttachedARCFunction(const CallBase *CB) {
0044   auto B = CB->getOperandBundle(LLVMContext::OB_clang_arc_attachedcall);
0045   if (!B)
0046     return std::nullopt;
0047 
0048   return cast<Function>(B->Inputs[0]);
0049 }
0050 
0051 /// Check whether the function is retainRV/unsafeClaimRV.
0052 inline bool isRetainOrClaimRV(ARCInstKind Kind) {
0053   return Kind == ARCInstKind::RetainRV || Kind == ARCInstKind::UnsafeClaimRV;
0054 }
0055 
0056 /// This function returns the ARCInstKind of the function attached to operand
0057 /// bundle clang_arc_attachedcall. It returns std::nullopt if the call doesn't
0058 /// have the operand bundle or the operand is null. Otherwise it returns either
0059 /// RetainRV or UnsafeClaimRV.
0060 inline ARCInstKind getAttachedARCFunctionKind(const CallBase *CB) {
0061   std::optional<Function *> Fn = getAttachedARCFunction(CB);
0062   if (!Fn)
0063     return ARCInstKind::None;
0064   auto FnClass = GetFunctionClass(*Fn);
0065   assert(isRetainOrClaimRV(FnClass) && "unexpected ARC runtime function");
0066   return FnClass;
0067 }
0068 
0069 } // end namespace objcarc
0070 } // end namespace llvm
0071 
0072 #endif