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_TRANSFORMS_SCALAR_ARCRUNTIMEENTRYPOINTS_H
23 #define LLVM_TRANSFORMS_SCALAR_ARCRUNTIMEENTRYPOINTS_H
30 /// Declarations for ObjC runtime functions and constants. These are initialized
31 /// lazily to avoid cluttering up the Module with unused declarations.
32 class ARCRuntimeEntryPoints {
42 EPT_RetainAutorelease,
43 EPT_RetainAutoreleaseRV
46 ARCRuntimeEntryPoints() : TheModule(0),
55 RetainAutoreleaseRV(0) { }
57 ~ARCRuntimeEntryPoints() { }
59 void Initialize(Module *M) {
68 RetainAutorelease = 0;
69 RetainAutoreleaseRV = 0;
72 Constant *get(const EntryPointType entry) {
73 assert(TheModule != 0 && "Not initialized.");
76 case EPT_AutoreleaseRV:
77 return getI8XRetI8XEntryPoint(AutoreleaseRV,
78 "objc_autoreleaseReturnValue", true);
80 return getVoidRetI8XEntryPoint(Release, "objc_release");
82 return getI8XRetI8XEntryPoint(Retain, "objc_retain", true);
84 return getI8XRetI8XEntryPoint(RetainBlock, "objc_retainBlock", false);
86 return getI8XRetI8XEntryPoint(Autorelease, "objc_autorelease", true);
88 return getI8XRetI8XXI8XEntryPoint(StoreStrong, "objc_storeStrong");
90 return getI8XRetI8XEntryPoint(RetainRV,
91 "objc_retainAutoreleasedReturnValue", true);
92 case EPT_RetainAutorelease:
93 return getI8XRetI8XEntryPoint(RetainAutorelease, "objc_retainAutorelease",
95 case EPT_RetainAutoreleaseRV:
96 return getI8XRetI8XEntryPoint(RetainAutoreleaseRV,
97 "objc_retainAutoreleaseReturnValue", true);
100 llvm_unreachable("Switch should be a covered switch.");
104 /// Cached reference to the module which we will insert declarations into.
107 /// Declaration for ObjC runtime function objc_autoreleaseReturnValue.
108 Constant *AutoreleaseRV;
109 /// Declaration for ObjC runtime function objc_release.
111 /// Declaration for ObjC runtime function objc_retain.
113 /// Declaration for ObjC runtime function objc_retainBlock.
114 Constant *RetainBlock;
115 /// Declaration for ObjC runtime function objc_autorelease.
116 Constant *Autorelease;
117 /// Declaration for objc_storeStrong().
118 Constant *StoreStrong;
119 /// Declaration for objc_retainAutoreleasedReturnValue().
121 /// Declaration for objc_retainAutorelease().
122 Constant *RetainAutorelease;
123 /// Declaration for objc_retainAutoreleaseReturnValue().
124 Constant *RetainAutoreleaseRV;
126 Constant *getVoidRetI8XEntryPoint(Constant *&Decl,
131 LLVMContext &C = TheModule->getContext();
132 Type *Params[] = { PointerType::getUnqual(Type::getInt8Ty(C)) };
134 AttributeSet().addAttribute(C, AttributeSet::FunctionIndex,
135 Attribute::NoUnwind);
136 FunctionType *Fty = FunctionType::get(Type::getVoidTy(C), Params,
138 return Decl = TheModule->getOrInsertFunction(Name, Fty, Attr);
141 Constant *getI8XRetI8XEntryPoint(Constant *& Decl,
143 bool NoUnwind = false) {
147 LLVMContext &C = TheModule->getContext();
148 Type *I8X = PointerType::getUnqual(Type::getInt8Ty(C));
149 Type *Params[] = { I8X };
150 FunctionType *Fty = FunctionType::get(I8X, Params, /*isVarArg=*/false);
151 AttributeSet Attr = AttributeSet();
154 Attr = Attr.addAttribute(C, AttributeSet::FunctionIndex,
155 Attribute::NoUnwind);
157 return Decl = TheModule->getOrInsertFunction(Name, Fty, Attr);
160 Constant *getI8XRetI8XXI8XEntryPoint(Constant *&Decl,
165 LLVMContext &C = TheModule->getContext();
166 Type *I8X = PointerType::getUnqual(Type::getInt8Ty(C));
167 Type *I8XX = PointerType::getUnqual(I8X);
168 Type *Params[] = { I8XX, I8X };
171 AttributeSet().addAttribute(C, AttributeSet::FunctionIndex,
172 Attribute::NoUnwind);
173 Attr = Attr.addAttribute(C, 1, Attribute::NoCapture);
175 FunctionType *Fty = FunctionType::get(Type::getVoidTy(C), Params,
178 return Decl = TheModule->getOrInsertFunction(Name, Fty, Attr);
181 }; // class ARCRuntimeEntryPoints
183 } // namespace objcarc
186 #endif // LLVM_TRANSFORMS_SCALAR_ARCRUNTIMEENTRYPOINTS_H