LLVM  9.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 
21  if (!CS.getInstruction())
22  return nullptr;
23  return CS.getCalledFunction();
24 }
25 
27  if (auto *F = getCalledFunction(CS))
28  return F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint;
29  return false;
30 }
31 
32 bool llvm::isStatepoint(const Value *V) {
33  if (auto CS = ImmutableCallSite(V))
34  return isStatepoint(CS);
35  return false;
36 }
37 
38 bool llvm::isStatepoint(const Value &V) {
39  return isStatepoint(&V);
40 }
41 
43  return CS.getInstruction() && isa<GCRelocateInst>(CS.getInstruction());
44 }
45 
46 bool llvm::isGCRelocate(const Value *V) {
47  if (auto CS = ImmutableCallSite(V))
48  return isGCRelocate(CS);
49  return false;
50 }
51 
53  return CS.getInstruction() && isa<GCResultInst>(CS.getInstruction());
54 }
55 
56 bool llvm::isGCResult(const Value *V) {
57  if (auto CS = ImmutableCallSite(V))
58  return isGCResult(CS);
59  return false;
60 }
61 
63  return Attr.hasAttribute("statepoint-id") ||
64  Attr.hasAttribute("statepoint-num-patch-bytes");
65 }
66 
69  StatepointDirectives Result;
70 
71  Attribute AttrID =
72  AS.getAttribute(AttributeList::FunctionIndex, "statepoint-id");
73  uint64_t StatepointID;
74  if (AttrID.isStringAttribute())
75  if (!AttrID.getValueAsString().getAsInteger(10, StatepointID))
76  Result.StatepointID = StatepointID;
77 
78  uint32_t NumPatchBytes;
80  "statepoint-num-patch-bytes");
81  if (AttrNumPatchBytes.isStringAttribute())
82  if (!AttrNumPatchBytes.getValueAsString().getAsInteger(10, NumPatchBytes))
83  Result.NumPatchBytes = NumPatchBytes;
84 
85  return Result;
86 }
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:68
F(f)
bool isGCRelocate(ImmutableCallSite CS)
Definition: Statepoint.cpp:42
bool isStringAttribute() const
Return true if the attribute is a string (target-dependent) attribute.
Definition: Attributes.cpp:169
InstrTy * getInstruction() const
Definition: CallSite.h:91
bool hasAttribute(AttrKind Val) const
Return true if the attribute is present.
Definition: Attributes.cpp:201
Optional< uint32_t > NumPatchBytes
Definition: Statepoint.h:456
bool isGCResult(ImmutableCallSite CS)
Definition: Statepoint.cpp:52
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:496
static const Function * getCalledFunction(ImmutableCallSite CS)
Definition: Statepoint.cpp:20
bool isStatepointDirectiveAttr(Attribute Attr)
Return true if the Attr is an attribute that is a statepoint directive.
Definition: Statepoint.cpp:62
Optional< uint64_t > StatepointID
Definition: Statepoint.h:457
Call sites that get wrapped by a gc.statepoint (currently only in RewriteStatepointsForGC and potenti...
Definition: Statepoint.h:455
StringRef getValueAsString() const
Return the attribute&#39;s value as a string.
Definition: Attributes.cpp:194
Establish a view to a call site for examination.
Definition: CallSite.h:886
bool isStatepoint(ImmutableCallSite CS)
Definition: Statepoint.cpp:26
FunTy * getCalledFunction() const
Return the function being called if this is a direct call, otherwise return null (if it&#39;s an indirect...
Definition: CallSite.h:106
LLVM Value Representation.
Definition: Value.h:72