LLVM  8.0.1
Statepoint.cpp
Go to the documentation of this file.
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 //
10 // This file contains some utility functions to help recognize gc.statepoint
11 // intrinsics.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "llvm/IR/Statepoint.h"
16 
17 #include "llvm/IR/Function.h"
18 
19 using namespace llvm;
20 
22  if (!CS.getInstruction())
23  return nullptr;
24  return CS.getCalledFunction();
25 }
26 
28  if (auto *F = getCalledFunction(CS))
29  return F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint;
30  return false;
31 }
32 
33 bool llvm::isStatepoint(const Value *V) {
34  if (auto CS = ImmutableCallSite(V))
35  return isStatepoint(CS);
36  return false;
37 }
38 
39 bool llvm::isStatepoint(const Value &V) {
40  return isStatepoint(&V);
41 }
42 
44  return CS.getInstruction() && isa<GCRelocateInst>(CS.getInstruction());
45 }
46 
47 bool llvm::isGCRelocate(const Value *V) {
48  if (auto CS = ImmutableCallSite(V))
49  return isGCRelocate(CS);
50  return false;
51 }
52 
54  return CS.getInstruction() && isa<GCResultInst>(CS.getInstruction());
55 }
56 
57 bool llvm::isGCResult(const Value *V) {
58  if (auto CS = ImmutableCallSite(V))
59  return isGCResult(CS);
60  return false;
61 }
62 
64  return Attr.hasAttribute("statepoint-id") ||
65  Attr.hasAttribute("statepoint-num-patch-bytes");
66 }
67 
70  StatepointDirectives Result;
71 
72  Attribute AttrID =
73  AS.getAttribute(AttributeList::FunctionIndex, "statepoint-id");
74  uint64_t StatepointID;
75  if (AttrID.isStringAttribute())
76  if (!AttrID.getValueAsString().getAsInteger(10, StatepointID))
77  Result.StatepointID = StatepointID;
78 
79  uint32_t NumPatchBytes;
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 }
This class represents lattice values for constants.
Definition: AllocatorList.h:24
StatepointDirectives parseStatepointDirectivesFromAttrs(AttributeList AS)
Parse out statepoint directives from the function attributes present in AS.
Definition: Statepoint.cpp:69
F(f)
bool isGCRelocate(ImmutableCallSite CS)
Definition: Statepoint.cpp:43
bool isStringAttribute() const
Return true if the attribute is a string (target-dependent) attribute.
Definition: Attributes.cpp:170
InstrTy * getInstruction() const
Definition: CallSite.h:92
bool hasAttribute(AttrKind Val) const
Return true if the attribute is present.
Definition: Attributes.cpp:202
Optional< uint32_t > NumPatchBytes
Definition: Statepoint.h:457
bool isGCResult(ImmutableCallSite CS)
Definition: Statepoint.cpp:53
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:497
static const Function * getCalledFunction(ImmutableCallSite CS)
Definition: Statepoint.cpp:21
bool isStatepointDirectiveAttr(Attribute Attr)
Return true if the Attr is an attribute that is a statepoint directive.
Definition: Statepoint.cpp:63
Optional< uint64_t > StatepointID
Definition: Statepoint.h:458
Call sites that get wrapped by a gc.statepoint (currently only in RewriteStatepointsForGC and potenti...
Definition: Statepoint.h:456
StringRef getValueAsString() const
Return the attribute&#39;s value as a string.
Definition: Attributes.cpp:195
Establish a view to a call site for examination.
Definition: CallSite.h:711
bool isStatepoint(ImmutableCallSite CS)
Definition: Statepoint.cpp:27
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:107
LLVM Value Representation.
Definition: Value.h:73