LLVM  14.0.0git
ObjCARCUtil.h
Go to the documentation of this file.
1 //===- ObjCARCUtil.h - ObjC ARC Utility Functions ---------------*- C++ -*-===//
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 /// \file
9 /// This file defines ARC utility functions which are used by various parts of
10 /// the compiler.
11 ///
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_ANALYSIS_OBJCARCUTIL_H
15 #define LLVM_ANALYSIS_OBJCARCUTIL_H
16 
18 #include "llvm/IR/Function.h"
19 #include "llvm/IR/InstrTypes.h"
20 #include "llvm/IR/LLVMContext.h"
21 
22 namespace llvm {
23 namespace objcarc {
24 
25 inline const char *getRVMarkerModuleFlagStr() {
26  return "clang.arc.retainAutoreleasedReturnValueMarker";
27 }
28 
29 inline bool hasAttachedCallOpBundle(const CallBase *CB) {
30  // Ignore the bundle if the return type is void. Global optimization passes
31  // can turn the called function's return type to void. That should happen only
32  // if the call doesn't return and the call to @llvm.objc.clang.arc.noop.use
33  // no longer consumes the function return or is deleted. In that case, it's
34  // not necessary to emit the marker instruction or calls to the ARC runtime
35  // functions.
36  return !CB->getFunctionType()->getReturnType()->isVoidTy() &&
38  .hasValue();
39 }
40 
41 /// This function returns operand bundle clang_arc_attachedcall's argument,
42 /// which is the address of the ARC runtime function.
45  if (!B.hasValue() || B->Inputs.size() == 0)
46  return None;
47 
48  return cast<Function>(B->Inputs[0]);
49 }
50 
51 /// Check whether the function is retainRV/claimRV.
54 }
55 
56 /// This function returns the ARCInstKind of the function attached to operand
57 /// bundle clang_arc_attachedcall. It returns None if the call doesn't have the
58 /// operand bundle or the operand is null. Otherwise it returns either RetainRV
59 /// or ClaimRV.
62  if (!Fn.hasValue())
63  return ARCInstKind::None;
64  auto FnClass = GetFunctionClass(*Fn);
65  assert(isRetainOrClaimRV(FnClass) && "unexpected ARC runtime function");
66  return FnClass;
67 }
68 
69 } // end namespace objcarc
70 } // end namespace llvm
71 
72 #endif
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::objcarc::hasAttachedCallOpBundle
bool hasAttachedCallOpBundle(const CallBase *CB)
Definition: ObjCARCUtil.h:29
llvm::objcarc::getAttachedARCFunction
Optional< Function * > getAttachedARCFunction(const CallBase *CB)
This function returns operand bundle clang_arc_attachedcall's argument, which is the address of the A...
Definition: ObjCARCUtil.h:43
llvm::CallBase::getOperandBundle
Optional< OperandBundleUse > getOperandBundle(StringRef Name) const
Return an operand bundle by name, if present.
Definition: InstrTypes.h:1987
llvm::objcarc::GetFunctionClass
ARCInstKind GetFunctionClass(const Function *F)
Determine if F is one of the special known Functions.
Definition: ObjCARCInstKind.cpp:85
llvm::CallBase::getFunctionType
FunctionType * getFunctionType() const
Definition: InstrTypes.h:1241
llvm::objcarc::isRetainOrClaimRV
bool isRetainOrClaimRV(ARCInstKind Kind)
Check whether the function is retainRV/claimRV.
Definition: ObjCARCUtil.h:52
llvm::Optional
Definition: APInt.h:33
llvm::LLVMContext::OB_clang_arc_attachedcall
@ OB_clang_arc_attachedcall
Definition: LLVMContext.h:96
llvm::Optional::hasValue
constexpr bool hasValue() const
Definition: Optional.h:288
InstrTypes.h
llvm::objcarc::ARCInstKind::RetainRV
@ RetainRV
objc_retainAutoreleasedReturnValue
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::None
const NoneType None
Definition: None.h:23
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
llvm::objcarc::ARCInstKind
ARCInstKind
Definition: ObjCARCInstKind.h:28
ObjCARCInstKind.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::Type::isVoidTy
bool isVoidTy() const
Return true if this is 'void'.
Definition: Type.h:138
llvm::objcarc::getRVMarkerModuleFlagStr
const char * getRVMarkerModuleFlagStr()
Definition: ObjCARCUtil.h:25
llvm::objcarc::getAttachedARCFunctionKind
ARCInstKind getAttachedARCFunctionKind(const CallBase *CB)
This function returns the ARCInstKind of the function attached to operand bundle clang_arc_attachedca...
Definition: ObjCARCUtil.h:60
Function.h
llvm::objcarc::ARCInstKind::ClaimRV
@ ClaimRV
objc_unsafeClaimAutoreleasedReturnValue
llvm::objcarc::ARCInstKind::None
@ None
anything that is inert from an ARC perspective.
llvm::CallBase
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1161
LLVMContext.h
llvm::FunctionType::getReturnType
Type * getReturnType() const
Definition: DerivedTypes.h:124