1
//===- ARCRuntimeEntryPoints.h - ObjC ARC Optimization --*- C++ -*---------===//
3
// The LLVM Compiler Infrastructure
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
8
//===----------------------------------------------------------------------===//
10
/// This file contains a class ARCRuntimeEntryPoints for use in
11
/// creating/managing references to entry points to the arc objective c runtime.
13
/// WARNING: This file knows about certain library functions. It recognizes them
14
/// by name, and hardwires knowledge of their semantics.
16
/// WARNING: This file knows about how certain Objective-C library functions are
17
/// used. Naive LLVM IR transformations which would otherwise be
18
/// behavior-preserving may break these assumptions.
20
//===----------------------------------------------------------------------===//
22
#ifndef LLVM_LIB_TRANSFORMS_OBJCARC_ARCRUNTIMEENTRYPOINTS_H
23
#define LLVM_LIB_TRANSFORMS_OBJCARC_ARCRUNTIMEENTRYPOINTS_H
30
enum class ARCRuntimeEntryPointKind {
42
/// Declarations for ObjC runtime functions and constants. These are initialized
43
/// lazily to avoid cluttering up the Module with unused declarations.
44
class ARCRuntimeEntryPoints {
46
ARCRuntimeEntryPoints() : TheModule(nullptr),
47
AutoreleaseRV(nullptr),
54
RetainAutorelease(nullptr),
55
RetainAutoreleaseRV(nullptr) { }
57
void init(Module *M) {
59
AutoreleaseRV = nullptr;
62
RetainBlock = nullptr;
63
Autorelease = nullptr;
64
StoreStrong = nullptr;
66
RetainAutorelease = nullptr;
67
RetainAutoreleaseRV = nullptr;
70
Constant *get(ARCRuntimeEntryPointKind kind) {
71
assert(TheModule != nullptr && "Not initialized.");
74
case ARCRuntimeEntryPointKind::AutoreleaseRV:
75
return getI8XRetI8XEntryPoint(AutoreleaseRV,
76
"objc_autoreleaseReturnValue", true);
77
case ARCRuntimeEntryPointKind::Release:
78
return getVoidRetI8XEntryPoint(Release, "objc_release");
79
case ARCRuntimeEntryPointKind::Retain:
80
return getI8XRetI8XEntryPoint(Retain, "objc_retain", true);
81
case ARCRuntimeEntryPointKind::RetainBlock:
82
return getI8XRetI8XEntryPoint(RetainBlock, "objc_retainBlock", false);
83
case ARCRuntimeEntryPointKind::Autorelease:
84
return getI8XRetI8XEntryPoint(Autorelease, "objc_autorelease", true);
85
case ARCRuntimeEntryPointKind::StoreStrong:
86
return getI8XRetI8XXI8XEntryPoint(StoreStrong, "objc_storeStrong");
87
case ARCRuntimeEntryPointKind::RetainRV:
88
return getI8XRetI8XEntryPoint(RetainRV,
89
"objc_retainAutoreleasedReturnValue", true);
90
case ARCRuntimeEntryPointKind::RetainAutorelease:
91
return getI8XRetI8XEntryPoint(RetainAutorelease, "objc_retainAutorelease",
93
case ARCRuntimeEntryPointKind::RetainAutoreleaseRV:
94
return getI8XRetI8XEntryPoint(RetainAutoreleaseRV,
95
"objc_retainAutoreleaseReturnValue", true);
98
llvm_unreachable("Switch should be a covered switch.");
102
/// Cached reference to the module which we will insert declarations into.
105
/// Declaration for ObjC runtime function objc_autoreleaseReturnValue.
106
Constant *AutoreleaseRV;
107
/// Declaration for ObjC runtime function objc_release.
109
/// Declaration for ObjC runtime function objc_retain.
111
/// Declaration for ObjC runtime function objc_retainBlock.
112
Constant *RetainBlock;
113
/// Declaration for ObjC runtime function objc_autorelease.
114
Constant *Autorelease;
115
/// Declaration for objc_storeStrong().
116
Constant *StoreStrong;
117
/// Declaration for objc_retainAutoreleasedReturnValue().
119
/// Declaration for objc_retainAutorelease().
120
Constant *RetainAutorelease;
121
/// Declaration for objc_retainAutoreleaseReturnValue().
122
Constant *RetainAutoreleaseRV;
124
Constant *getVoidRetI8XEntryPoint(Constant *&Decl,
129
LLVMContext &C = TheModule->getContext();
130
Type *Params[] = { PointerType::getUnqual(Type::getInt8Ty(C)) };
132
AttributeSet().addAttribute(C, AttributeSet::FunctionIndex,
133
Attribute::NoUnwind);
134
FunctionType *Fty = FunctionType::get(Type::getVoidTy(C), Params,
136
return Decl = TheModule->getOrInsertFunction(Name, Fty, Attr);
139
Constant *getI8XRetI8XEntryPoint(Constant *& Decl,
141
bool NoUnwind = false) {
145
LLVMContext &C = TheModule->getContext();
146
Type *I8X = PointerType::getUnqual(Type::getInt8Ty(C));
147
Type *Params[] = { I8X };
148
FunctionType *Fty = FunctionType::get(I8X, Params, /*isVarArg=*/false);
149
AttributeSet Attr = AttributeSet();
152
Attr = Attr.addAttribute(C, AttributeSet::FunctionIndex,
153
Attribute::NoUnwind);
155
return Decl = TheModule->getOrInsertFunction(Name, Fty, Attr);
158
Constant *getI8XRetI8XXI8XEntryPoint(Constant *&Decl,
163
LLVMContext &C = TheModule->getContext();
164
Type *I8X = PointerType::getUnqual(Type::getInt8Ty(C));
165
Type *I8XX = PointerType::getUnqual(I8X);
166
Type *Params[] = { I8XX, I8X };
169
AttributeSet().addAttribute(C, AttributeSet::FunctionIndex,
170
Attribute::NoUnwind);
171
Attr = Attr.addAttribute(C, 1, Attribute::NoCapture);
173
FunctionType *Fty = FunctionType::get(Type::getVoidTy(C), Params,
176
return Decl = TheModule->getOrInsertFunction(Name, Fty, Attr);
179
}; // class ARCRuntimeEntryPoints
181
} // namespace objcarc