blob: 18efee2177c343591e578f6ebca6371c7a8a7f13 [file] [log] [blame]
Philip Reamesd021bb82014-12-02 18:50:36 +00001//===-- 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 Das62221332016-03-17 00:47:18 +000010// This file contains some utility functions to help recognize gc.statepoint
11// intrinsics.
12//
Philip Reamesd021bb82014-12-02 18:50:36 +000013//===----------------------------------------------------------------------===//
14
Philip Reamesd021bb82014-12-02 18:50:36 +000015#include "llvm/IR/Statepoint.h"
16
Sanjoy Das62221332016-03-17 00:47:18 +000017#include "llvm/IR/Function.h"
18
Philip Reamesd021bb82014-12-02 18:50:36 +000019using namespace llvm;
20
Sanjoy Das62221332016-03-17 00:47:18 +000021static const Function *getCalledFunction(ImmutableCallSite CS) {
22 if (!CS.getInstruction())
23 return nullptr;
24 return CS.getCalledFunction();
Philip Reamesd021bb82014-12-02 18:50:36 +000025}
Sanjoy Das62221332016-03-17 00:47:18 +000026
27bool llvm::isStatepoint(ImmutableCallSite CS) {
28 if (auto *F = getCalledFunction(CS))
29 return F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint;
Philip Reamesd021bb82014-12-02 18:50:36 +000030 return false;
31}
Sanjoy Das62221332016-03-17 00:47:18 +000032
33bool llvm::isStatepoint(const Value *V) {
34 if (auto CS = ImmutableCallSite(V))
35 return isStatepoint(CS);
36 return false;
Philip Reamesd021bb82014-12-02 18:50:36 +000037}
38
Sanjoy Das62221332016-03-17 00:47:18 +000039bool llvm::isStatepoint(const Value &V) {
40 return isStatepoint(&V);
41}
42
43bool llvm::isGCRelocate(ImmutableCallSite CS) {
Manuel Jacob397864c2016-01-05 04:03:00 +000044 return CS.getInstruction() && isa<GCRelocateInst>(CS.getInstruction());
Philip Reamesd021bb82014-12-02 18:50:36 +000045}
46
Anna Thomas076f8192017-06-20 20:54:57 +000047bool llvm::isGCRelocate(const Value *V) {
48 if (auto CS = ImmutableCallSite(V))
49 return isGCRelocate(CS);
50 return false;
51}
52
Sanjoy Das62221332016-03-17 00:47:18 +000053bool llvm::isGCResult(ImmutableCallSite CS) {
Philip Reames0802f712016-04-12 18:05:10 +000054 return CS.getInstruction() && isa<GCResultInst>(CS.getInstruction());
Sanjoy Das62221332016-03-17 00:47:18 +000055}
Sanjoy Dasd3bfdec2016-03-17 01:56:10 +000056
Anna Thomas076f8192017-06-20 20:54:57 +000057bool llvm::isGCResult(const Value *V) {
58 if (auto CS = ImmutableCallSite(V))
59 return isGCResult(CS);
60 return false;
61}
62
Sanjoy Dasd3bfdec2016-03-17 01:56:10 +000063bool llvm::isStatepointDirectiveAttr(Attribute Attr) {
64 return Attr.hasAttribute("statepoint-id") ||
65 Attr.hasAttribute("statepoint-num-patch-bytes");
66}
67
Reid Kleckner67077702017-03-21 16:57:19 +000068StatepointDirectives
69llvm::parseStatepointDirectivesFromAttrs(AttributeList AS) {
Sanjoy Dasd3bfdec2016-03-17 01:56:10 +000070 StatepointDirectives Result;
71
72 Attribute AttrID =
Reid Kleckner67077702017-03-21 16:57:19 +000073 AS.getAttribute(AttributeList::FunctionIndex, "statepoint-id");
Sanjoy Dasd3bfdec2016-03-17 01:56:10 +000074 uint64_t StatepointID;
75 if (AttrID.isStringAttribute())
76 if (!AttrID.getValueAsString().getAsInteger(10, StatepointID))
77 Result.StatepointID = StatepointID;
78
79 uint32_t NumPatchBytes;
Reid Kleckner67077702017-03-21 16:57:19 +000080 Attribute AttrNumPatchBytes = AS.getAttribute(AttributeList::FunctionIndex,
Sanjoy Dasd3bfdec2016-03-17 01:56:10 +000081 "statepoint-num-patch-bytes");
82 if (AttrNumPatchBytes.isStringAttribute())
83 if (!AttrNumPatchBytes.getValueAsString().getAsInteger(10, NumPatchBytes))
84 Result.NumPatchBytes = NumPatchBytes;
85
86 return Result;
87}