Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 1 | //===-- IR/Statepoint.cpp -- gc.statepoint utilities --- -----------------===// |
| 2 | // |
Chih-Hung Hsieh | 43f0694 | 2019-12-19 15:01:08 -0800 | [diff] [blame^] | 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 |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 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 | |
Chih-Hung Hsieh | 43f0694 | 2019-12-19 15:01:08 -0800 | [diff] [blame^] | 20 | bool llvm::isStatepoint(const CallBase *Call) { |
| 21 | if (auto *F = Call->getCalledFunction()) |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 22 | return F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint; |
| 23 | return false; |
| 24 | } |
| 25 | |
| 26 | bool llvm::isStatepoint(const Value *V) { |
Chih-Hung Hsieh | 43f0694 | 2019-12-19 15:01:08 -0800 | [diff] [blame^] | 27 | if (auto *Call = dyn_cast<CallBase>(V)) |
| 28 | return isStatepoint(Call); |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 29 | return false; |
| 30 | } |
| 31 | |
| 32 | bool llvm::isStatepoint(const Value &V) { |
| 33 | return isStatepoint(&V); |
| 34 | } |
| 35 | |
Chih-Hung Hsieh | 43f0694 | 2019-12-19 15:01:08 -0800 | [diff] [blame^] | 36 | bool llvm::isGCRelocate(const CallBase *Call) { |
| 37 | return isa<GCRelocateInst>(Call); |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | bool llvm::isGCRelocate(const Value *V) { |
Chih-Hung Hsieh | 43f0694 | 2019-12-19 15:01:08 -0800 | [diff] [blame^] | 41 | if (auto *Call = dyn_cast<CallBase>(V)) |
| 42 | return isGCRelocate(Call); |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 43 | return false; |
| 44 | } |
| 45 | |
Chih-Hung Hsieh | 43f0694 | 2019-12-19 15:01:08 -0800 | [diff] [blame^] | 46 | bool llvm::isGCResult(const CallBase *Call) { return isa<GCResultInst>(Call); } |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 47 | |
| 48 | bool llvm::isGCResult(const Value *V) { |
Chih-Hung Hsieh | 43f0694 | 2019-12-19 15:01:08 -0800 | [diff] [blame^] | 49 | if (auto *Call = dyn_cast<CallBase>(V)) |
| 50 | return isGCResult(Call); |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 51 | return false; |
| 52 | } |
| 53 | |
| 54 | bool llvm::isStatepointDirectiveAttr(Attribute Attr) { |
| 55 | return Attr.hasAttribute("statepoint-id") || |
| 56 | Attr.hasAttribute("statepoint-num-patch-bytes"); |
| 57 | } |
| 58 | |
| 59 | StatepointDirectives |
| 60 | llvm::parseStatepointDirectivesFromAttrs(AttributeList AS) { |
| 61 | StatepointDirectives Result; |
| 62 | |
| 63 | Attribute AttrID = |
| 64 | AS.getAttribute(AttributeList::FunctionIndex, "statepoint-id"); |
| 65 | uint64_t StatepointID; |
| 66 | if (AttrID.isStringAttribute()) |
| 67 | if (!AttrID.getValueAsString().getAsInteger(10, StatepointID)) |
| 68 | Result.StatepointID = StatepointID; |
| 69 | |
| 70 | uint32_t NumPatchBytes; |
| 71 | Attribute AttrNumPatchBytes = AS.getAttribute(AttributeList::FunctionIndex, |
| 72 | "statepoint-num-patch-bytes"); |
| 73 | if (AttrNumPatchBytes.isStringAttribute()) |
| 74 | if (!AttrNumPatchBytes.getValueAsString().getAsInteger(10, NumPatchBytes)) |
| 75 | Result.NumPatchBytes = NumPatchBytes; |
| 76 | |
| 77 | return Result; |
| 78 | } |