xref: /freebsd/contrib/llvm-project/llvm/lib/IR/Statepoint.cpp (revision 5e801ac66d24704442eba426ed13c3effb8a34e7)
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 
18 using namespace llvm;
19 
20 bool llvm::isStatepointDirectiveAttr(Attribute Attr) {
21   return Attr.hasAttribute("statepoint-id") ||
22          Attr.hasAttribute("statepoint-num-patch-bytes");
23 }
24 
25 StatepointDirectives
26 llvm::parseStatepointDirectivesFromAttrs(AttributeList AS) {
27   StatepointDirectives Result;
28 
29   Attribute AttrID = AS.getFnAttr("statepoint-id");
30   uint64_t StatepointID;
31   if (AttrID.isStringAttribute())
32     if (!AttrID.getValueAsString().getAsInteger(10, StatepointID))
33       Result.StatepointID = StatepointID;
34 
35   uint32_t NumPatchBytes;
36   Attribute AttrNumPatchBytes = AS.getFnAttr("statepoint-num-patch-bytes");
37   if (AttrNumPatchBytes.isStringAttribute())
38     if (!AttrNumPatchBytes.getValueAsString().getAsInteger(10, NumPatchBytes))
39       Result.NumPatchBytes = NumPatchBytes;
40 
41   return Result;
42 }
43