1 //===- ARCRuntimeEntryPoints.h - ObjC ARC Optimization --*- mode: 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) {
63 Constant *get(const EntryPointType entry) {
64 assert(TheModule != 0 && "Not initialized.");
67 case EPT_AutoreleaseRV:
68 return getI8XRetI8XEntryPoint(AutoreleaseRV,
69 "objc_autoreleaseReturnValue", true);
71 return getVoidRetI8XEntryPoint(Release, "objc_release");
73 return getI8XRetI8XEntryPoint(Retain, "objc_retain", true);
75 return getI8XRetI8XEntryPoint(RetainBlock, "objc_retainBlock", false);
77 return getI8XRetI8XEntryPoint(Autorelease, "objc_autorelease", true);
79 return getI8XRetI8XXI8XEntryPoint(StoreStrong, "objc_storeStrong");
81 return getI8XRetI8XEntryPoint(RetainRV,
82 "objc_retainAutoreleasedReturnValue", true);
83 case EPT_RetainAutorelease:
84 return getI8XRetI8XEntryPoint(RetainAutorelease, "objc_retainAutorelease",
86 case EPT_RetainAutoreleaseRV:
87 return getI8XRetI8XEntryPoint(RetainAutoreleaseRV,
88 "objc_retainAutoreleaseReturnValue", true);
91 llvm_unreachable("Switch should be a covered switch.");
95 /// Cached reference to the module which we will insert declarations into.
98 /// Declaration for ObjC runtime function objc_autoreleaseReturnValue.
99 Constant *AutoreleaseRV;
100 /// Declaration for ObjC runtime function objc_release.
102 /// Declaration for ObjC runtime function objc_retain.
104 /// Declaration for ObjC runtime function objc_retainBlock.
105 Constant *RetainBlock;
106 /// Declaration for ObjC runtime function objc_autorelease.
107 Constant *Autorelease;
108 /// Declaration for objc_storeStrong().
109 Constant *StoreStrong;
110 /// Declaration for objc_retainAutoreleasedReturnValue().
112 /// Declaration for objc_retainAutorelease().
113 Constant *RetainAutorelease;
114 /// Declaration for objc_retainAutoreleaseReturnValue().
115 Constant *RetainAutoreleaseRV;
117 Constant *getVoidRetI8XEntryPoint(Constant *&Decl,
122 LLVMContext &C = TheModule->getContext();
123 Type *Params[] = { PointerType::getUnqual(Type::getInt8Ty(C)) };
125 AttributeSet().addAttribute(C, AttributeSet::FunctionIndex,
126 Attribute::NoUnwind);
127 FunctionType *Fty = FunctionType::get(Type::getVoidTy(C), Params,
129 return Decl = TheModule->getOrInsertFunction(Name, Fty, Attr);
132 Constant *getI8XRetI8XEntryPoint(Constant *& Decl,
134 bool NoUnwind = false) {
138 LLVMContext &C = TheModule->getContext();
139 Type *I8X = PointerType::getUnqual(Type::getInt8Ty(C));
140 Type *Params[] = { I8X };
141 FunctionType *Fty = FunctionType::get(I8X, Params, /*isVarArg=*/false);
142 AttributeSet Attr = AttributeSet();
145 Attr = Attr.addAttribute(C, AttributeSet::FunctionIndex,
146 Attribute::NoUnwind);
148 return Decl = TheModule->getOrInsertFunction(Name, Fty, Attr);
151 Constant *getI8XRetI8XXI8XEntryPoint(Constant *&Decl,
156 LLVMContext &C = TheModule->getContext();
157 Type *I8X = PointerType::getUnqual(Type::getInt8Ty(C));
158 Type *I8XX = PointerType::getUnqual(I8X);
159 Type *Params[] = { I8XX, I8X };
162 AttributeSet().addAttribute(C, AttributeSet::FunctionIndex,
163 Attribute::NoUnwind);
164 Attr = Attr.addAttribute(C, 1, Attribute::NoCapture);
166 FunctionType *Fty = FunctionType::get(Type::getVoidTy(C), Params,
169 return Decl = TheModule->getOrInsertFunction(Name, Fty, Attr);
172 }; // class ARCRuntimeEntryPoints
174 } // namespace objcarc
177 #endif // LLVM_TRANSFORMS_SCALAR_ARCRUNTIMEENTRYPOINTS_H