blob: 63be1e780d8144a82c74361559cabcd0cd0cb8d0 [file] [log] [blame]
Philip Reames1a1bdb22014-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 Dasd6fc46e2016-03-17 00:47:18 +000010// This file contains some utility functions to help recognize gc.statepoint
11// intrinsics.
12//
Philip Reames1a1bdb22014-12-02 18:50:36 +000013//===----------------------------------------------------------------------===//
14
Philip Reames1a1bdb22014-12-02 18:50:36 +000015#include "llvm/IR/Statepoint.h"
16
Sanjoy Dasd6fc46e2016-03-17 00:47:18 +000017#include "llvm/IR/Function.h"
18
Philip Reames1a1bdb22014-12-02 18:50:36 +000019using namespace llvm;
20
Sanjoy Dasd6fc46e2016-03-17 00:47:18 +000021static const Function *getCalledFunction(ImmutableCallSite CS) {
22 if (!CS.getInstruction())
23 return nullptr;
24 return CS.getCalledFunction();
Philip Reames1a1bdb22014-12-02 18:50:36 +000025}
Sanjoy Dasd6fc46e2016-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 Reames1a1bdb22014-12-02 18:50:36 +000030 return false;
31}
Sanjoy Dasd6fc46e2016-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 Reames1a1bdb22014-12-02 18:50:36 +000037}
38
Sanjoy Dasd6fc46e2016-03-17 00:47:18 +000039bool llvm::isStatepoint(const Value &V) {
40 return isStatepoint(&V);
41}
42
43bool llvm::isGCRelocate(ImmutableCallSite CS) {
Manuel Jacob83eefa62016-01-05 04:03:00 +000044 return CS.getInstruction() && isa<GCRelocateInst>(CS.getInstruction());
Philip Reames1a1bdb22014-12-02 18:50:36 +000045}
46
Sanjoy Dasd6fc46e2016-03-17 00:47:18 +000047bool llvm::isGCResult(ImmutableCallSite CS) {
Philip Reames92d1f0c2016-04-12 18:05:10 +000048 return CS.getInstruction() && isa<GCResultInst>(CS.getInstruction());
Sanjoy Dasd6fc46e2016-03-17 00:47:18 +000049}
Sanjoy Das31203882016-03-17 01:56:10 +000050
51bool llvm::isStatepointDirectiveAttr(Attribute Attr) {
52 return Attr.hasAttribute("statepoint-id") ||
53 Attr.hasAttribute("statepoint-num-patch-bytes");
54}
55
56StatepointDirectives llvm::parseStatepointDirectivesFromAttrs(AttributeSet AS) {
57 StatepointDirectives Result;
58
59 Attribute AttrID =
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;
65
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;
72
73 return Result;
74}