Philip Reames | d021bb8 | 2014-12-02 18:50:36 +0000 | [diff] [blame] | 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 | // |
Sanjoy Das | 6222133 | 2016-03-17 00:47:18 +0000 | [diff] [blame] | 10 | // This file contains some utility functions to help recognize gc.statepoint |
| 11 | // intrinsics. |
| 12 | // |
Philip Reames | d021bb8 | 2014-12-02 18:50:36 +0000 | [diff] [blame] | 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Philip Reames | d021bb8 | 2014-12-02 18:50:36 +0000 | [diff] [blame] | 15 | #include "llvm/IR/Statepoint.h" |
| 16 | |
Sanjoy Das | 6222133 | 2016-03-17 00:47:18 +0000 | [diff] [blame] | 17 | #include "llvm/IR/Function.h" |
| 18 | |
Philip Reames | d021bb8 | 2014-12-02 18:50:36 +0000 | [diff] [blame] | 19 | using namespace llvm; |
| 20 | |
Sanjoy Das | 6222133 | 2016-03-17 00:47:18 +0000 | [diff] [blame] | 21 | static const Function *getCalledFunction(ImmutableCallSite CS) { |
| 22 | if (!CS.getInstruction()) |
| 23 | return nullptr; |
| 24 | return CS.getCalledFunction(); |
Philip Reames | d021bb8 | 2014-12-02 18:50:36 +0000 | [diff] [blame] | 25 | } |
Sanjoy Das | 6222133 | 2016-03-17 00:47:18 +0000 | [diff] [blame] | 26 | |
| 27 | bool llvm::isStatepoint(ImmutableCallSite CS) { |
| 28 | if (auto *F = getCalledFunction(CS)) |
| 29 | return F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint; |
Philip Reames | d021bb8 | 2014-12-02 18:50:36 +0000 | [diff] [blame] | 30 | return false; |
| 31 | } |
Sanjoy Das | 6222133 | 2016-03-17 00:47:18 +0000 | [diff] [blame] | 32 | |
| 33 | bool llvm::isStatepoint(const Value *V) { |
| 34 | if (auto CS = ImmutableCallSite(V)) |
| 35 | return isStatepoint(CS); |
| 36 | return false; |
Philip Reames | d021bb8 | 2014-12-02 18:50:36 +0000 | [diff] [blame] | 37 | } |
| 38 | |
Sanjoy Das | 6222133 | 2016-03-17 00:47:18 +0000 | [diff] [blame] | 39 | bool llvm::isStatepoint(const Value &V) { |
| 40 | return isStatepoint(&V); |
| 41 | } |
| 42 | |
| 43 | bool llvm::isGCRelocate(ImmutableCallSite CS) { |
Manuel Jacob | 397864c | 2016-01-05 04:03:00 +0000 | [diff] [blame] | 44 | return CS.getInstruction() && isa<GCRelocateInst>(CS.getInstruction()); |
Philip Reames | d021bb8 | 2014-12-02 18:50:36 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Anna Thomas | 076f819 | 2017-06-20 20:54:57 +0000 | [diff] [blame] | 47 | bool llvm::isGCRelocate(const Value *V) { |
| 48 | if (auto CS = ImmutableCallSite(V)) |
| 49 | return isGCRelocate(CS); |
| 50 | return false; |
| 51 | } |
| 52 | |
Sanjoy Das | 6222133 | 2016-03-17 00:47:18 +0000 | [diff] [blame] | 53 | bool llvm::isGCResult(ImmutableCallSite CS) { |
Philip Reames | 0802f71 | 2016-04-12 18:05:10 +0000 | [diff] [blame] | 54 | return CS.getInstruction() && isa<GCResultInst>(CS.getInstruction()); |
Sanjoy Das | 6222133 | 2016-03-17 00:47:18 +0000 | [diff] [blame] | 55 | } |
Sanjoy Das | d3bfdec | 2016-03-17 01:56:10 +0000 | [diff] [blame] | 56 | |
Anna Thomas | 076f819 | 2017-06-20 20:54:57 +0000 | [diff] [blame] | 57 | bool llvm::isGCResult(const Value *V) { |
| 58 | if (auto CS = ImmutableCallSite(V)) |
| 59 | return isGCResult(CS); |
| 60 | return false; |
| 61 | } |
| 62 | |
Sanjoy Das | d3bfdec | 2016-03-17 01:56:10 +0000 | [diff] [blame] | 63 | bool llvm::isStatepointDirectiveAttr(Attribute Attr) { |
| 64 | return Attr.hasAttribute("statepoint-id") || |
| 65 | Attr.hasAttribute("statepoint-num-patch-bytes"); |
| 66 | } |
| 67 | |
Reid Kleckner | 6707770 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 68 | StatepointDirectives |
| 69 | llvm::parseStatepointDirectivesFromAttrs(AttributeList AS) { |
Sanjoy Das | d3bfdec | 2016-03-17 01:56:10 +0000 | [diff] [blame] | 70 | StatepointDirectives Result; |
| 71 | |
| 72 | Attribute AttrID = |
Reid Kleckner | 6707770 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 73 | AS.getAttribute(AttributeList::FunctionIndex, "statepoint-id"); |
Sanjoy Das | d3bfdec | 2016-03-17 01:56:10 +0000 | [diff] [blame] | 74 | uint64_t StatepointID; |
| 75 | if (AttrID.isStringAttribute()) |
| 76 | if (!AttrID.getValueAsString().getAsInteger(10, StatepointID)) |
| 77 | Result.StatepointID = StatepointID; |
| 78 | |
| 79 | uint32_t NumPatchBytes; |
Reid Kleckner | 6707770 | 2017-03-21 16:57:19 +0000 | [diff] [blame] | 80 | Attribute AttrNumPatchBytes = AS.getAttribute(AttributeList::FunctionIndex, |
Sanjoy Das | d3bfdec | 2016-03-17 01:56:10 +0000 | [diff] [blame] | 81 | "statepoint-num-patch-bytes"); |
| 82 | if (AttrNumPatchBytes.isStringAttribute()) |
| 83 | if (!AttrNumPatchBytes.getValueAsString().getAsInteger(10, NumPatchBytes)) |
| 84 | Result.NumPatchBytes = NumPatchBytes; |
| 85 | |
| 86 | return Result; |
| 87 | } |