1//===- ObjCARCUtil.h - ObjC ARC Utility Functions ---------------*- 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/// \file
9/// This file defines ARC utility functions which are used by various parts of
10/// the compiler.
11///
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_IR_OBJCARCUTIL_H
15#define LLVM_IR_OBJCARCUTIL_H
16
17#include "llvm/IR/InstrTypes.h"
18#include "llvm/IR/LLVMContext.h"
19
20namespace llvm {
21namespace objcarc {
22
23inline const char *getRVMarkerModuleFlagStr() {
24  return "clang.arc.retainAutoreleasedReturnValueMarker";
25}
26
27enum AttachedCallOperandBundle : unsigned { RVOB_Retain, RVOB_Claim };
28
29inline AttachedCallOperandBundle
30getAttachedCallOperandBundleEnum(bool IsRetain) {
31  return IsRetain ? RVOB_Retain : RVOB_Claim;
32}
33
34inline bool hasAttachedCallOpBundle(const CallBase *CB, bool IsRetain) {
35  auto B = CB->getOperandBundle(LLVMContext::OB_clang_arc_attachedcall);
36  if (!B.hasValue())
37    return false;
38  return cast<ConstantInt>(B->Inputs[0])->getZExtValue() ==
39         getAttachedCallOperandBundleEnum(IsRetain);
40}
41
42inline bool hasAttachedCallOpBundle(const CallBase *CB) {
43  return CB->getOperandBundle(LLVMContext::OB_clang_arc_attachedcall)
44      .hasValue();
45}
46
47} // end namespace objcarc
48} // end namespace llvm
49
50#endif
51