LLVM  12.0.0git
ARCRuntimeEntryPoints.h
Go to the documentation of this file.
1 //===- ARCRuntimeEntryPoints.h - ObjC ARC Optimization ----------*- 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 /// \file
10 /// This file contains a class ARCRuntimeEntryPoints for use in
11 /// creating/managing references to entry points to the arc objective c runtime.
12 ///
13 /// WARNING: This file knows about certain library functions. It recognizes them
14 /// by name, and hardwires knowledge of their semantics.
15 ///
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.
19 //
20 //===----------------------------------------------------------------------===//
21 
22 #ifndef LLVM_LIB_TRANSFORMS_OBJCARC_ARCRUNTIMEENTRYPOINTS_H
23 #define LLVM_LIB_TRANSFORMS_OBJCARC_ARCRUNTIMEENTRYPOINTS_H
24 
25 #include "llvm/IR/Attributes.h"
26 #include "llvm/IR/Intrinsics.h"
28 #include <cassert>
29 
30 namespace llvm {
31 
32 class Function;
33 class Module;
34 
35 namespace objcarc {
36 
39  Release,
40  Retain,
44  RetainRV,
47 };
48 
49 /// Declarations for ObjC runtime functions and constants. These are initialized
50 /// lazily to avoid cluttering up the Module with unused declarations.
52 public:
53  ARCRuntimeEntryPoints() = default;
54 
55  void init(Module *M) {
56  TheModule = M;
57  AutoreleaseRV = nullptr;
58  Release = nullptr;
59  Retain = nullptr;
60  RetainBlock = nullptr;
61  Autorelease = nullptr;
62  StoreStrong = nullptr;
63  RetainRV = nullptr;
64  RetainAutorelease = nullptr;
65  RetainAutoreleaseRV = nullptr;
66  }
67 
69  assert(TheModule != nullptr && "Not initialized.");
70 
71  switch (kind) {
73  return getIntrinsicEntryPoint(AutoreleaseRV,
74  Intrinsic::objc_autoreleaseReturnValue);
76  return getIntrinsicEntryPoint(Release, Intrinsic::objc_release);
78  return getIntrinsicEntryPoint(Retain, Intrinsic::objc_retain);
80  return getIntrinsicEntryPoint(RetainBlock, Intrinsic::objc_retainBlock);
82  return getIntrinsicEntryPoint(Autorelease, Intrinsic::objc_autorelease);
84  return getIntrinsicEntryPoint(StoreStrong, Intrinsic::objc_storeStrong);
86  return getIntrinsicEntryPoint(RetainRV,
87  Intrinsic::objc_retainAutoreleasedReturnValue);
89  return getIntrinsicEntryPoint(RetainAutorelease,
90  Intrinsic::objc_retainAutorelease);
92  return getIntrinsicEntryPoint(RetainAutoreleaseRV,
93  Intrinsic::objc_retainAutoreleaseReturnValue);
94  }
95 
96  llvm_unreachable("Switch should be a covered switch.");
97  }
98 
99 private:
100  /// Cached reference to the module which we will insert declarations into.
101  Module *TheModule = nullptr;
102 
103  /// Declaration for ObjC runtime function objc_autoreleaseReturnValue.
104  Function *AutoreleaseRV = nullptr;
105 
106  /// Declaration for ObjC runtime function objc_release.
107  Function *Release = nullptr;
108 
109  /// Declaration for ObjC runtime function objc_retain.
110  Function *Retain = nullptr;
111 
112  /// Declaration for ObjC runtime function objc_retainBlock.
113  Function *RetainBlock = nullptr;
114 
115  /// Declaration for ObjC runtime function objc_autorelease.
116  Function *Autorelease = nullptr;
117 
118  /// Declaration for objc_storeStrong().
119  Function *StoreStrong = nullptr;
120 
121  /// Declaration for objc_retainAutoreleasedReturnValue().
122  Function *RetainRV = nullptr;
123 
124  /// Declaration for objc_retainAutorelease().
125  Function *RetainAutorelease = nullptr;
126 
127  /// Declaration for objc_retainAutoreleaseReturnValue().
128  Function *RetainAutoreleaseRV = nullptr;
129 
130  Function *getIntrinsicEntryPoint(Function *&Decl, Intrinsic::ID IntID) {
131  if (Decl)
132  return Decl;
133 
134  return Decl = Intrinsic::getDeclaration(TheModule, IntID);
135  }
136 };
137 
138 } // end namespace objcarc
139 
140 } // end namespace llvm
141 
142 #endif // LLVM_LIB_TRANSFORMS_OBJCARC_ARCRUNTIMEENTRYPOINTS_H
This class represents lattice values for constants.
Definition: AllocatorList.h:23
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:67
Machine Debugify Module
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:1161
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Declarations for ObjC runtime functions and constants.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())