LLVM  8.0.1
ARCRuntimeEntryPoints.h
Go to the documentation of this file.
1 //===- ARCRuntimeEntryPoints.h - ObjC ARC Optimization ----------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 /// \file
11 /// This file contains a class ARCRuntimeEntryPoints for use in
12 /// creating/managing references to entry points to the arc objective c runtime.
13 ///
14 /// WARNING: This file knows about certain library functions. It recognizes them
15 /// by name, and hardwires knowledge of their semantics.
16 ///
17 /// WARNING: This file knows about how certain Objective-C library functions are
18 /// used. Naive LLVM IR transformations which would otherwise be
19 /// behavior-preserving may break these assumptions.
20 //
21 //===----------------------------------------------------------------------===//
22 
23 #ifndef LLVM_LIB_TRANSFORMS_OBJCARC_ARCRUNTIMEENTRYPOINTS_H
24 #define LLVM_LIB_TRANSFORMS_OBJCARC_ARCRUNTIMEENTRYPOINTS_H
25 
26 #include "llvm/ADT/StringRef.h"
27 #include "llvm/IR/Attributes.h"
28 #include "llvm/IR/DerivedTypes.h"
29 #include "llvm/IR/Intrinsics.h"
30 #include "llvm/IR/Module.h"
31 #include "llvm/IR/Type.h"
33 #include <cassert>
34 
35 namespace llvm {
36 
37 class Constant;
38 class LLVMContext;
39 
40 namespace objcarc {
41 
44  Release,
45  Retain,
49  RetainRV,
52 };
53 
54 /// Declarations for ObjC runtime functions and constants. These are initialized
55 /// lazily to avoid cluttering up the Module with unused declarations.
57 public:
58  ARCRuntimeEntryPoints() = default;
59 
60  void init(Module *M) {
61  TheModule = M;
62  AutoreleaseRV = nullptr;
63  Release = nullptr;
64  Retain = nullptr;
65  RetainBlock = nullptr;
66  Autorelease = nullptr;
67  StoreStrong = nullptr;
68  RetainRV = nullptr;
69  RetainAutorelease = nullptr;
70  RetainAutoreleaseRV = nullptr;
71  }
72 
74  assert(TheModule != nullptr && "Not initialized.");
75 
76  switch (kind) {
78  return getIntrinsicEntryPoint(AutoreleaseRV,
81  return getIntrinsicEntryPoint(Release, Intrinsic::objc_release);
83  return getIntrinsicEntryPoint(Retain, Intrinsic::objc_retain);
85  return getIntrinsicEntryPoint(RetainBlock, Intrinsic::objc_retainBlock);
87  return getIntrinsicEntryPoint(Autorelease, Intrinsic::objc_autorelease);
89  return getIntrinsicEntryPoint(StoreStrong, Intrinsic::objc_storeStrong);
91  return getIntrinsicEntryPoint(RetainRV,
94  return getIntrinsicEntryPoint(RetainAutorelease,
97  return getIntrinsicEntryPoint(RetainAutoreleaseRV,
99  }
100 
101  llvm_unreachable("Switch should be a covered switch.");
102  }
103 
104 private:
105  /// Cached reference to the module which we will insert declarations into.
106  Module *TheModule = nullptr;
107 
108  /// Declaration for ObjC runtime function objc_autoreleaseReturnValue.
109  Constant *AutoreleaseRV = nullptr;
110 
111  /// Declaration for ObjC runtime function objc_release.
112  Constant *Release = nullptr;
113 
114  /// Declaration for ObjC runtime function objc_retain.
115  Constant *Retain = nullptr;
116 
117  /// Declaration for ObjC runtime function objc_retainBlock.
118  Constant *RetainBlock = nullptr;
119 
120  /// Declaration for ObjC runtime function objc_autorelease.
121  Constant *Autorelease = nullptr;
122 
123  /// Declaration for objc_storeStrong().
124  Constant *StoreStrong = nullptr;
125 
126  /// Declaration for objc_retainAutoreleasedReturnValue().
127  Constant *RetainRV = nullptr;
128 
129  /// Declaration for objc_retainAutorelease().
130  Constant *RetainAutorelease = nullptr;
131 
132  /// Declaration for objc_retainAutoreleaseReturnValue().
133  Constant *RetainAutoreleaseRV = nullptr;
134 
135  Constant *getIntrinsicEntryPoint(Constant *&Decl, Intrinsic::ID IntID) {
136  if (Decl)
137  return Decl;
138 
139  return Decl = Intrinsic::getDeclaration(TheModule, IntID);
140  }
141 };
142 
143 } // end namespace objcarc
144 
145 } // end namespace llvm
146 
147 #endif // LLVM_LIB_TRANSFORMS_OBJCARC_ARCRUNTIMEENTRYPOINTS_H
This class represents lattice values for constants.
Definition: AllocatorList.h:24
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
This file contains the simple types necessary to represent the attributes associated with functions a...
Function * getDeclaration(Module *M, ID id, ArrayRef< Type *> Tys=None)
Create or insert an LLVM Function declaration for an intrinsic, and return it.
Definition: Function.cpp:1020
This is an important base class in LLVM.
Definition: Constant.h:42
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Module.h This file contains the declarations for the Module class.
Declarations for ObjC runtime functions and constants.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())