1 //===-- IR/Statepoint.cpp -- gc.statepoint utilities --- -----------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains some utility functions to help recognize gc.statepoint
13 //===----------------------------------------------------------------------===//
15 #include "llvm/IR/Statepoint.h"
17 #include "llvm/IR/Function.h"
21 static const Function *getCalledFunction(ImmutableCallSite CS) {
22 if (!CS.getInstruction())
24 return CS.getCalledFunction();
27 bool llvm::isStatepoint(ImmutableCallSite CS) {
28 if (auto *F = getCalledFunction(CS))
29 return F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint;
33 bool llvm::isStatepoint(const Value *V) {
34 if (auto CS = ImmutableCallSite(V))
35 return isStatepoint(CS);
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::isGCResult(ImmutableCallSite CS) {
48 return CS.getInstruction() && isa<GCResultInst>(CS.getInstruction());
51 bool llvm::isStatepointDirectiveAttr(Attribute Attr) {
52 return Attr.hasAttribute("statepoint-id") ||
53 Attr.hasAttribute("statepoint-num-patch-bytes");
56 StatepointDirectives llvm::parseStatepointDirectivesFromAttrs(AttributeSet AS) {
57 StatepointDirectives Result;
60 AS.getAttribute(AttributeSet::FunctionIndex, "statepoint-id");
61 uint64_t StatepointID;
62 if (AttrID.isStringAttribute())
63 if (!AttrID.getValueAsString().getAsInteger(10, StatepointID))
64 Result.StatepointID = StatepointID;
66 uint32_t NumPatchBytes;
67 Attribute AttrNumPatchBytes = AS.getAttribute(AttributeSet::FunctionIndex,
68 "statepoint-num-patch-bytes");
69 if (AttrNumPatchBytes.isStringAttribute())
70 if (!AttrNumPatchBytes.getValueAsString().getAsInteger(10, NumPatchBytes))
71 Result.NumPatchBytes = NumPatchBytes;