[llvm-exegesis] Fix missing std::move.
[llvm-complete.git] / lib / IR / Statepoint.cpp
blob18efee2177c343591e578f6ebca6371c7a8a7f13
1 //===-- IR/Statepoint.cpp -- gc.statepoint utilities --- -----------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains some utility functions to help recognize gc.statepoint
11 // intrinsics.
13 //===----------------------------------------------------------------------===//
15 #include "llvm/IR/Statepoint.h"
17 #include "llvm/IR/Function.h"
19 using namespace llvm;
21 static const Function *getCalledFunction(ImmutableCallSite CS) {
22 if (!CS.getInstruction())
23 return nullptr;
24 return CS.getCalledFunction();
27 bool llvm::isStatepoint(ImmutableCallSite CS) {
28 if (auto *F = getCalledFunction(CS))
29 return F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint;
30 return false;
33 bool llvm::isStatepoint(const Value *V) {
34 if (auto CS = ImmutableCallSite(V))
35 return isStatepoint(CS);
36 return false;
39 bool llvm::isStatepoint(const Value &V) {
40 return isStatepoint(&V);
43 bool llvm::isGCRelocate(ImmutableCallSite CS) {
44 return CS.getInstruction() && isa<GCRelocateInst>(CS.getInstruction());
47 bool llvm::isGCRelocate(const Value *V) {
48 if (auto CS = ImmutableCallSite(V))
49 return isGCRelocate(CS);
50 return false;
53 bool llvm::isGCResult(ImmutableCallSite CS) {
54 return CS.getInstruction() && isa<GCResultInst>(CS.getInstruction());
57 bool llvm::isGCResult(const Value *V) {
58 if (auto CS = ImmutableCallSite(V))
59 return isGCResult(CS);
60 return false;
63 bool llvm::isStatepointDirectiveAttr(Attribute Attr) {
64 return Attr.hasAttribute("statepoint-id") ||
65 Attr.hasAttribute("statepoint-num-patch-bytes");
68 StatepointDirectives
69 llvm::parseStatepointDirectivesFromAttrs(AttributeList AS) {
70 StatepointDirectives Result;
72 Attribute AttrID =
73 AS.getAttribute(AttributeList::FunctionIndex, "statepoint-id");
74 uint64_t StatepointID;
75 if (AttrID.isStringAttribute())
76 if (!AttrID.getValueAsString().getAsInteger(10, StatepointID))
77 Result.StatepointID = StatepointID;
79 uint32_t NumPatchBytes;
80 Attribute AttrNumPatchBytes = AS.getAttribute(AttributeList::FunctionIndex,
81 "statepoint-num-patch-bytes");
82 if (AttrNumPatchBytes.isStringAttribute())
83 if (!AttrNumPatchBytes.getValueAsString().getAsInteger(10, NumPatchBytes))
84 Result.NumPatchBytes = NumPatchBytes;
86 return Result;