Path: blob/main/contrib/llvm-project/llvm/lib/Transforms/ObjCARC/ARCRuntimeEntryPoints.h
35269 views
//===- ARCRuntimeEntryPoints.h - ObjC ARC Optimization ----------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8/// \file9/// This file contains a class ARCRuntimeEntryPoints for use in10/// creating/managing references to entry points to the arc objective c runtime.11///12/// WARNING: This file knows about certain library functions. It recognizes them13/// by name, and hardwires knowledge of their semantics.14///15/// WARNING: This file knows about how certain Objective-C library functions are16/// used. Naive LLVM IR transformations which would otherwise be17/// behavior-preserving may break these assumptions.18//19//===----------------------------------------------------------------------===//2021#ifndef LLVM_LIB_TRANSFORMS_OBJCARC_ARCRUNTIMEENTRYPOINTS_H22#define LLVM_LIB_TRANSFORMS_OBJCARC_ARCRUNTIMEENTRYPOINTS_H2324#include "llvm/IR/Attributes.h"25#include "llvm/IR/Intrinsics.h"26#include "llvm/Support/ErrorHandling.h"27#include <cassert>2829namespace llvm {3031class Function;32class Module;3334namespace objcarc {3536enum class ARCRuntimeEntryPointKind {37AutoreleaseRV,38Release,39Retain,40RetainBlock,41Autorelease,42StoreStrong,43RetainRV,44UnsafeClaimRV,45RetainAutorelease,46RetainAutoreleaseRV,47};4849/// Declarations for ObjC runtime functions and constants. These are initialized50/// lazily to avoid cluttering up the Module with unused declarations.51class ARCRuntimeEntryPoints {52public:53ARCRuntimeEntryPoints() = default;5455void init(Module *M) {56TheModule = M;57AutoreleaseRV = nullptr;58Release = nullptr;59Retain = nullptr;60RetainBlock = nullptr;61Autorelease = nullptr;62StoreStrong = nullptr;63RetainRV = nullptr;64UnsafeClaimRV = nullptr;65RetainAutorelease = nullptr;66RetainAutoreleaseRV = nullptr;67}6869Function *get(ARCRuntimeEntryPointKind kind) {70assert(TheModule != nullptr && "Not initialized.");7172switch (kind) {73case ARCRuntimeEntryPointKind::AutoreleaseRV:74return getIntrinsicEntryPoint(AutoreleaseRV,75Intrinsic::objc_autoreleaseReturnValue);76case ARCRuntimeEntryPointKind::Release:77return getIntrinsicEntryPoint(Release, Intrinsic::objc_release);78case ARCRuntimeEntryPointKind::Retain:79return getIntrinsicEntryPoint(Retain, Intrinsic::objc_retain);80case ARCRuntimeEntryPointKind::RetainBlock:81return getIntrinsicEntryPoint(RetainBlock, Intrinsic::objc_retainBlock);82case ARCRuntimeEntryPointKind::Autorelease:83return getIntrinsicEntryPoint(Autorelease, Intrinsic::objc_autorelease);84case ARCRuntimeEntryPointKind::StoreStrong:85return getIntrinsicEntryPoint(StoreStrong, Intrinsic::objc_storeStrong);86case ARCRuntimeEntryPointKind::RetainRV:87return getIntrinsicEntryPoint(RetainRV,88Intrinsic::objc_retainAutoreleasedReturnValue);89case ARCRuntimeEntryPointKind::UnsafeClaimRV:90return getIntrinsicEntryPoint(91UnsafeClaimRV, Intrinsic::objc_unsafeClaimAutoreleasedReturnValue);92case ARCRuntimeEntryPointKind::RetainAutorelease:93return getIntrinsicEntryPoint(RetainAutorelease,94Intrinsic::objc_retainAutorelease);95case ARCRuntimeEntryPointKind::RetainAutoreleaseRV:96return getIntrinsicEntryPoint(RetainAutoreleaseRV,97Intrinsic::objc_retainAutoreleaseReturnValue);98}99100llvm_unreachable("Switch should be a covered switch.");101}102103private:104/// Cached reference to the module which we will insert declarations into.105Module *TheModule = nullptr;106107/// Declaration for ObjC runtime function objc_autoreleaseReturnValue.108Function *AutoreleaseRV = nullptr;109110/// Declaration for ObjC runtime function objc_release.111Function *Release = nullptr;112113/// Declaration for ObjC runtime function objc_retain.114Function *Retain = nullptr;115116/// Declaration for ObjC runtime function objc_retainBlock.117Function *RetainBlock = nullptr;118119/// Declaration for ObjC runtime function objc_autorelease.120Function *Autorelease = nullptr;121122/// Declaration for objc_storeStrong().123Function *StoreStrong = nullptr;124125/// Declaration for objc_retainAutoreleasedReturnValue().126Function *RetainRV = nullptr;127128/// Declaration for objc_unsafeClaimAutoreleasedReturnValue().129Function *UnsafeClaimRV = nullptr;130131/// Declaration for objc_retainAutorelease().132Function *RetainAutorelease = nullptr;133134/// Declaration for objc_retainAutoreleaseReturnValue().135Function *RetainAutoreleaseRV = nullptr;136137Function *getIntrinsicEntryPoint(Function *&Decl, Intrinsic::ID IntID) {138if (Decl)139return Decl;140141return Decl = Intrinsic::getDeclaration(TheModule, IntID);142}143};144145} // end namespace objcarc146147} // end namespace llvm148149#endif // LLVM_LIB_TRANSFORMS_OBJCARC_ARCRUNTIMEENTRYPOINTS_H150151152