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::isStatepoint(const CallBase *Call) { 21 return isa<GCStatepointInst>(Call); 22 } 23 24 bool llvm::isStatepoint(const Value *V) { 25 return isa<GCStatepointInst>(V); 26 } 27 28 bool llvm::isStatepoint(const Value &V) { 29 return isStatepoint(&V); 30 } 31 32 bool llvm::isGCRelocate(const CallBase *Call) { 33 return isa<GCRelocateInst>(Call); 34 } 35 36 bool llvm::isGCRelocate(const Value *V) { 37 if (auto *Call = dyn_cast<CallBase>(V)) 38 return isGCRelocate(Call); 39 return false; 40 } 41 42 bool llvm::isGCResult(const CallBase *Call) { return isa<GCResultInst>(Call); } 43 44 bool llvm::isGCResult(const Value *V) { 45 if (auto *Call = dyn_cast<CallBase>(V)) 46 return isGCResult(Call); 47 return false; 48 } 49 50 bool llvm::isStatepointDirectiveAttr(Attribute Attr) { 51 return Attr.hasAttribute("statepoint-id") || 52 Attr.hasAttribute("statepoint-num-patch-bytes"); 53 } 54 55 StatepointDirectives 56 llvm::parseStatepointDirectivesFromAttrs(AttributeList AS) { 57 StatepointDirectives Result; 58 59 Attribute AttrID = 60 AS.getAttribute(AttributeList::FunctionIndex, "statepoint-id"); 61 uint64_t StatepointID; 62 if (AttrID.isStringAttribute()) 63 if (!AttrID.getValueAsString().getAsInteger(10, StatepointID)) 64 Result.StatepointID = StatepointID; 65 66 uint32_t NumPatchBytes; 67 Attribute AttrNumPatchBytes = AS.getAttribute(AttributeList::FunctionIndex, 68 "statepoint-num-patch-bytes"); 69 if (AttrNumPatchBytes.isStringAttribute()) 70 if (!AttrNumPatchBytes.getValueAsString().getAsInteger(10, NumPatchBytes)) 71 Result.NumPatchBytes = NumPatchBytes; 72 73 return Result; 74 } 75