LLVM  14.0.0git
ObjCARCInstKind.h
Go to the documentation of this file.
1 //===- ObjCARCInstKind.h - ARC instruction equivalence classes --*- 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 
9 #ifndef LLVM_ANALYSIS_OBJCARCINSTKIND_H
10 #define LLVM_ANALYSIS_OBJCARCINSTKIND_H
11 
12 #include "llvm/IR/Instructions.h"
13 
14 namespace llvm {
15 namespace objcarc {
16 
17 /// \enum ARCInstKind
18 ///
19 /// Equivalence classes of instructions in the ARC Model.
20 ///
21 /// Since we do not have "instructions" to represent ARC concepts in LLVM IR,
22 /// we instead operate on equivalence classes of instructions.
23 ///
24 /// TODO: This should be split into two enums: a runtime entry point enum
25 /// (possibly united with the ARCRuntimeEntrypoint class) and an enum that deals
26 /// with effects of instructions in the ARC model (which would handle the notion
27 /// of a User or CallOrUser).
28 enum class ARCInstKind {
29  Retain, ///< objc_retain
30  RetainRV, ///< objc_retainAutoreleasedReturnValue
31  ClaimRV, ///< objc_unsafeClaimAutoreleasedReturnValue
32  RetainBlock, ///< objc_retainBlock
33  Release, ///< objc_release
34  Autorelease, ///< objc_autorelease
35  AutoreleaseRV, ///< objc_autoreleaseReturnValue
36  AutoreleasepoolPush, ///< objc_autoreleasePoolPush
37  AutoreleasepoolPop, ///< objc_autoreleasePoolPop
38  NoopCast, ///< objc_retainedObject, etc.
39  FusedRetainAutorelease, ///< objc_retainAutorelease
40  FusedRetainAutoreleaseRV, ///< objc_retainAutoreleaseReturnValue
41  LoadWeakRetained, ///< objc_loadWeakRetained (primitive)
42  StoreWeak, ///< objc_storeWeak (primitive)
43  InitWeak, ///< objc_initWeak (derived)
44  LoadWeak, ///< objc_loadWeak (derived)
45  MoveWeak, ///< objc_moveWeak (derived)
46  CopyWeak, ///< objc_copyWeak (derived)
47  DestroyWeak, ///< objc_destroyWeak (derived)
48  StoreStrong, ///< objc_storeStrong (derived)
49  IntrinsicUser, ///< llvm.objc.clang.arc.use
50  CallOrUser, ///< could call objc_release and/or "use" pointers
51  Call, ///< could call objc_release
52  User, ///< could "use" a pointer
53  None ///< anything that is inert from an ARC perspective.
54 };
55 
57 
58 /// Test if the given class is a kind of user.
59 bool IsUser(ARCInstKind Class);
60 
61 /// Test if the given class is objc_retain or equivalent.
62 bool IsRetain(ARCInstKind Class);
63 
64 /// Test if the given class is objc_autorelease or equivalent.
65 bool IsAutorelease(ARCInstKind Class);
66 
67 /// Test if the given class represents instructions which return their
68 /// argument verbatim.
69 bool IsForwarding(ARCInstKind Class);
70 
71 /// Test if the given class represents instructions which do nothing if
72 /// passed a null pointer.
73 bool IsNoopOnNull(ARCInstKind Class);
74 
75 /// Test if the given class represents instructions which do nothing if
76 /// passed a global variable.
77 bool IsNoopOnGlobal(ARCInstKind Class);
78 
79 /// Test if the given class represents instructions which are always safe
80 /// to mark with the "tail" keyword.
81 bool IsAlwaysTail(ARCInstKind Class);
82 
83 /// Test if the given class represents instructions which are never safe
84 /// to mark with the "tail" keyword.
85 bool IsNeverTail(ARCInstKind Class);
86 
87 /// Test if the given class represents instructions which are always safe
88 /// to mark with the nounwind attribute.
89 bool IsNoThrow(ARCInstKind Class);
90 
91 /// Test whether the given instruction can autorelease any pointer or cause an
92 /// autoreleasepool pop.
93 bool CanInterruptRV(ARCInstKind Class);
94 
95 /// Determine if F is one of the special known Functions. If it isn't,
96 /// return ARCInstKind::CallOrUser.
98 
99 /// Determine which objc runtime call instruction class V belongs to.
100 ///
101 /// This is similar to GetARCInstKind except that it only detects objc
102 /// runtime calls. This allows it to be faster.
103 ///
105  if (const CallInst *CI = dyn_cast<CallInst>(V)) {
106  if (const Function *F = CI->getCalledFunction())
107  return GetFunctionClass(F);
108  // Otherwise, be conservative.
110  }
111 
112  // Otherwise, be conservative.
113  return isa<InvokeInst>(V) ? ARCInstKind::CallOrUser : ARCInstKind::User;
114 }
115 
116 /// Map V to its ARCInstKind equivalence class.
118 
119 /// Returns false if conservatively we can prove that any instruction mapped to
120 /// this kind can not decrement ref counts. Returns true otherwise.
122 
123 } // end namespace objcarc
124 } // end namespace llvm
125 
126 #endif
llvm::objcarc::GetBasicARCInstKind
ARCInstKind GetBasicARCInstKind(const Value *V)
Determine which objc runtime call instruction class V belongs to.
Definition: ObjCARCInstKind.h:104
llvm::objcarc::ARCInstKind::User
@ User
could "use" a pointer
llvm::objcarc::operator<<
raw_ostream & operator<<(raw_ostream &OS, const ARCInstKind Class)
Definition: ObjCARCInstKind.cpp:28
llvm
---------------------— PointerInfo ------------------------------------—
Definition: AllocatorList.h:23
llvm::Function
Definition: Function.h:61
llvm::objcarc::ARCInstKind::RetainBlock
@ RetainBlock
objc_retainBlock
llvm::objcarc::GetFunctionClass
ARCInstKind GetFunctionClass(const Function *F)
Determine if F is one of the special known Functions.
Definition: ObjCARCInstKind.cpp:85
llvm::objcarc::IsNeverTail
bool IsNeverTail(ARCInstKind Class)
Test if the given class represents instructions which are never safe to mark with the "tail" keyword.
Definition: ObjCARCInstKind.cpp:557
llvm::objcarc::ARCInstKind::LoadWeak
@ LoadWeak
objc_loadWeak (derived)
llvm::objcarc::ARCInstKind::Call
@ Call
could call objc_release
llvm::objcarc::ARCInstKind::MoveWeak
@ MoveWeak
objc_moveWeak (derived)
llvm::objcarc::GetARCInstKind
ARCInstKind GetARCInstKind(const Value *V)
Map V to its ARCInstKind equivalence class.
Definition: ObjCARCInstKind.cpp:213
llvm::objcarc::IsAutorelease
bool IsAutorelease(ARCInstKind Class)
Test if the given class is objc_autorelease or equivalent.
Definition: ObjCARCInstKind.cpp:381
llvm::objcarc::ARCInstKind::Autorelease
@ Autorelease
objc_autorelease
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::objcarc::CanInterruptRV
bool CanInterruptRV(ARCInstKind Class)
Test whether the given instruction can autorelease any pointer or cause an autoreleasepool pop.
Definition: ObjCARCInstKind.cpp:635
llvm::objcarc::ARCInstKind::InitWeak
@ InitWeak
objc_initWeak (derived)
llvm::objcarc::ARCInstKind::CallOrUser
@ CallOrUser
could call objc_release and/or "use" pointers
llvm::objcarc::IsNoopOnGlobal
bool IsNoopOnGlobal(ARCInstKind Class)
Test if the given class represents instructions which do nothing if passed a global variable.
Definition: ObjCARCInstKind.cpp:486
llvm::objcarc::ARCInstKind::Release
@ Release
objc_release
llvm::objcarc::ARCInstKind::RetainRV
@ RetainRV
objc_retainAutoreleasedReturnValue
llvm::objcarc::ARCInstKind::NoopCast
@ NoopCast
objc_retainedObject, etc.
llvm::objcarc::ARCInstKind::CopyWeak
@ CopyWeak
objc_copyWeak (derived)
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::objcarc::ARCInstKind::IntrinsicUser
@ IntrinsicUser
llvm.objc.clang.arc.use
llvm::lltok::Kind
Kind
Definition: LLToken.h:18
llvm::objcarc::ARCInstKind
ARCInstKind
Definition: ObjCARCInstKind.h:28
llvm::objcarc::IsAlwaysTail
bool IsAlwaysTail(ARCInstKind Class)
Test if the given class represents instructions which are always safe to mark with the "tail" keyword...
Definition: ObjCARCInstKind.cpp:521
llvm::objcarc::ARCInstKind::AutoreleasepoolPop
@ AutoreleasepoolPop
objc_autoreleasePoolPop
llvm::objcarc::IsNoThrow
bool IsNoThrow(ARCInstKind Class)
Test if the given class represents instructions which are always safe to mark with the nounwind attri...
Definition: ObjCARCInstKind.cpp:596
llvm::objcarc::ARCInstKind::FusedRetainAutorelease
@ FusedRetainAutorelease
objc_retainAutorelease
llvm::objcarc::IsRetain
bool IsRetain(ARCInstKind Class)
Test if the given class is objc_retain or equivalent.
Definition: ObjCARCInstKind.cpp:345
llvm::objcarc::ARCInstKind::AutoreleasepoolPush
@ AutoreleasepoolPush
objc_autoreleasePoolPush
llvm::objcarc::ARCInstKind::StoreWeak
@ StoreWeak
objc_storeWeak (primitive)
llvm::objcarc::ARCInstKind::FusedRetainAutoreleaseRV
@ FusedRetainAutoreleaseRV
objc_retainAutoreleaseReturnValue
llvm::objcarc::ARCInstKind::DestroyWeak
@ DestroyWeak
objc_destroyWeak (derived)
llvm::objcarc::ARCInstKind::StoreStrong
@ StoreStrong
objc_storeStrong (derived)
llvm::objcarc::CanDecrementRefCount
bool CanDecrementRefCount(ARCInstKind Kind)
Returns false if conservatively we can prove that any instruction mapped to this kind can not decreme...
Definition: ObjCARCInstKind.cpp:668
llvm::objcarc::ARCInstKind::ClaimRV
@ ClaimRV
objc_unsafeClaimAutoreleasedReturnValue
Instructions.h
llvm::objcarc::ARCInstKind::None
@ None
anything that is inert from an ARC perspective.
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition: Instructions.h:1475
llvm::Value
LLVM Value Representation.
Definition: Value.h:75
llvm::objcarc::ARCInstKind::Retain
@ Retain
objc_retain
llvm::objcarc::IsForwarding
bool IsForwarding(ARCInstKind Class)
Test if the given class represents instructions which return their argument verbatim.
Definition: ObjCARCInstKind.cpp:416
llvm::objcarc::IsNoopOnNull
bool IsNoopOnNull(ARCInstKind Class)
Test if the given class represents instructions which do nothing if passed a null pointer.
Definition: ObjCARCInstKind.cpp:451
llvm::objcarc::ARCInstKind::LoadWeakRetained
@ LoadWeakRetained
objc_loadWeakRetained (primitive)
llvm::objcarc::IsUser
bool IsUser(ARCInstKind Class)
Test if the given class is a kind of user.
Definition: ObjCARCInstKind.cpp:311
llvm::objcarc::ARCInstKind::AutoreleaseRV
@ AutoreleaseRV
objc_autoreleaseReturnValue