LLVM  10.0.0svn
Statepoint.cpp
Go to the documentation of this file.
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  if (auto *F = Call->getCalledFunction())
22  return F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint;
23  return false;
24 }
25 
26 bool llvm::isStatepoint(const Value *V) {
27  if (auto *Call = dyn_cast<CallBase>(V))
28  return isStatepoint(Call);
29  return false;
30 }
31 
32 bool llvm::isStatepoint(const Value &V) {
33  return isStatepoint(&V);
34 }
35 
36 bool llvm::isGCRelocate(const CallBase *Call) {
37  return isa<GCRelocateInst>(Call);
38 }
39 
40 bool llvm::isGCRelocate(const Value *V) {
41  if (auto *Call = dyn_cast<CallBase>(V))
42  return isGCRelocate(Call);
43  return false;
44 }
45 
46 bool llvm::isGCResult(const CallBase *Call) { return isa<GCResultInst>(Call); }
47 
48 bool llvm::isGCResult(const Value *V) {
49  if (auto *Call = dyn_cast<CallBase>(V))
50  return isGCResult(Call);
51  return false;
52 }
53 
55  return Attr.hasAttribute("statepoint-id") ||
56  Attr.hasAttribute("statepoint-num-patch-bytes");
57 }
58 
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;
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 }
This class represents lattice values for constants.
Definition: AllocatorList.h:23
StatepointDirectives parseStatepointDirectivesFromAttrs(AttributeList AS)
Parse out statepoint directives from the function attributes present in AS.
Definition: Statepoint.cpp:60
Base class for all callable instructions (InvokeInst and CallInst) Holds everything related to callin...
Definition: InstrTypes.h:1100
F(f)
bool isStringAttribute() const
Return true if the attribute is a string (target-dependent) attribute.
Definition: Attributes.cpp:191
bool isStatepoint(const CallBase *Call)
Definition: Statepoint.cpp:20
bool hasAttribute(AttrKind Val) const
Return true if the attribute is present.
Definition: Attributes.cpp:235
Optional< uint32_t > NumPatchBytes
Definition: Statepoint.h:438
Attribute getAttribute(unsigned Index, Attribute::AttrKind Kind) const
Return the attribute object that exists at the given index.
std::enable_if< std::numeric_limits< T >::is_signed, bool >::type getAsInteger(unsigned Radix, T &Result) const
Parse the current string as an integer of the specified radix.
Definition: StringRef.h:492
bool isGCRelocate(const CallBase *Call)
Definition: Statepoint.cpp:36
bool isStatepointDirectiveAttr(Attribute Attr)
Return true if the Attr is an attribute that is a statepoint directive.
Definition: Statepoint.cpp:54
Optional< uint64_t > StatepointID
Definition: Statepoint.h:439
Call sites that get wrapped by a gc.statepoint (currently only in RewriteStatepointsForGC and potenti...
Definition: Statepoint.h:437
StringRef getValueAsString() const
Return the attribute&#39;s value as a string.
Definition: Attributes.cpp:220
Function * getCalledFunction() const
Returns the function called, or null if this is an indirect function invocation.
Definition: InstrTypes.h:1287
LLVM Value Representation.
Definition: Value.h:74
bool isGCResult(const CallBase *Call)
Definition: Statepoint.cpp:46