1//===-- IR/Statepoint.cpp -- gc.statepoint utilities ---  -----------------===//
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// This file contains some utility functions to help recognize gc.statepoint
10// intrinsics.
11//
12//===----------------------------------------------------------------------===//
13
14#include "llvm/IR/Statepoint.h"
15
16#include "llvm/IR/Function.h"
17
18using namespace llvm;
19
20bool llvm::isStatepointDirectiveAttr(Attribute Attr) {
21  return Attr.hasAttribute("statepoint-id") ||
22         Attr.hasAttribute("statepoint-num-patch-bytes");
23}
24
25StatepointDirectives
26llvm::parseStatepointDirectivesFromAttrs(AttributeList AS) {
27  StatepointDirectives Result;
28
29  Attribute AttrID =
30      AS.getAttribute(AttributeList::FunctionIndex, "statepoint-id");
31  uint64_t StatepointID;
32  if (AttrID.isStringAttribute())
33    if (!AttrID.getValueAsString().getAsInteger(10, StatepointID))
34      Result.StatepointID = StatepointID;
35
36  uint32_t NumPatchBytes;
37  Attribute AttrNumPatchBytes = AS.getAttribute(AttributeList::FunctionIndex,
38                                                "statepoint-num-patch-bytes");
39  if (AttrNumPatchBytes.isStringAttribute())
40    if (!AttrNumPatchBytes.getValueAsString().getAsInteger(10, NumPatchBytes))
41      Result.NumPatchBytes = NumPatchBytes;
42
43  return Result;
44}
45