2015-01-18 16:17:27 +00:00
|
|
|
//===-- IR/Statepoint.cpp -- gc.statepoint utilities --- -----------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2016-07-23 20:41:05 +00:00
|
|
|
// This file contains some utility functions to help recognize gc.statepoint
|
|
|
|
// intrinsics.
|
|
|
|
//
|
2015-01-18 16:17:27 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "llvm/IR/Statepoint.h"
|
|
|
|
|
2016-07-23 20:41:05 +00:00
|
|
|
#include "llvm/IR/Function.h"
|
|
|
|
|
2015-01-18 16:17:27 +00:00
|
|
|
using namespace llvm;
|
|
|
|
|
2016-07-23 20:41:05 +00:00
|
|
|
static const Function *getCalledFunction(ImmutableCallSite CS) {
|
|
|
|
if (!CS.getInstruction())
|
|
|
|
return nullptr;
|
|
|
|
return CS.getCalledFunction();
|
|
|
|
}
|
2015-05-27 18:44:32 +00:00
|
|
|
|
2016-07-23 20:41:05 +00:00
|
|
|
bool llvm::isStatepoint(ImmutableCallSite CS) {
|
|
|
|
if (auto *F = getCalledFunction(CS))
|
|
|
|
return F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint;
|
|
|
|
return false;
|
2015-01-18 16:17:27 +00:00
|
|
|
}
|
2016-07-23 20:41:05 +00:00
|
|
|
|
|
|
|
bool llvm::isStatepoint(const Value *V) {
|
|
|
|
if (auto CS = ImmutableCallSite(V))
|
2015-01-18 16:17:27 +00:00
|
|
|
return isStatepoint(CS);
|
|
|
|
return false;
|
|
|
|
}
|
2016-07-23 20:41:05 +00:00
|
|
|
|
|
|
|
bool llvm::isStatepoint(const Value &V) {
|
|
|
|
return isStatepoint(&V);
|
2015-01-18 16:17:27 +00:00
|
|
|
}
|
|
|
|
|
2016-07-23 20:41:05 +00:00
|
|
|
bool llvm::isGCRelocate(ImmutableCallSite CS) {
|
2016-01-06 20:01:02 +00:00
|
|
|
return CS.getInstruction() && isa<GCRelocateInst>(CS.getInstruction());
|
2015-01-18 16:17:27 +00:00
|
|
|
}
|
|
|
|
|
2016-07-23 20:41:05 +00:00
|
|
|
bool llvm::isGCResult(ImmutableCallSite CS) {
|
|
|
|
return CS.getInstruction() && isa<GCResultInst>(CS.getInstruction());
|
|
|
|
}
|
2015-05-27 18:44:32 +00:00
|
|
|
|
2016-07-23 20:41:05 +00:00
|
|
|
bool llvm::isStatepointDirectiveAttr(Attribute Attr) {
|
|
|
|
return Attr.hasAttribute("statepoint-id") ||
|
|
|
|
Attr.hasAttribute("statepoint-num-patch-bytes");
|
2015-01-18 16:17:27 +00:00
|
|
|
}
|
2016-07-23 20:41:05 +00:00
|
|
|
|
2017-04-16 16:01:22 +00:00
|
|
|
StatepointDirectives
|
|
|
|
llvm::parseStatepointDirectivesFromAttrs(AttributeList AS) {
|
2016-07-23 20:41:05 +00:00
|
|
|
StatepointDirectives Result;
|
|
|
|
|
|
|
|
Attribute AttrID =
|
2017-04-16 16:01:22 +00:00
|
|
|
AS.getAttribute(AttributeList::FunctionIndex, "statepoint-id");
|
2016-07-23 20:41:05 +00:00
|
|
|
uint64_t StatepointID;
|
|
|
|
if (AttrID.isStringAttribute())
|
|
|
|
if (!AttrID.getValueAsString().getAsInteger(10, StatepointID))
|
|
|
|
Result.StatepointID = StatepointID;
|
|
|
|
|
|
|
|
uint32_t NumPatchBytes;
|
2017-04-16 16:01:22 +00:00
|
|
|
Attribute AttrNumPatchBytes = AS.getAttribute(AttributeList::FunctionIndex,
|
2016-07-23 20:41:05 +00:00
|
|
|
"statepoint-num-patch-bytes");
|
|
|
|
if (AttrNumPatchBytes.isStringAttribute())
|
|
|
|
if (!AttrNumPatchBytes.getValueAsString().getAsInteger(10, NumPatchBytes))
|
|
|
|
Result.NumPatchBytes = NumPatchBytes;
|
|
|
|
|
|
|
|
return Result;
|
2015-01-18 16:17:27 +00:00
|
|
|
}
|