blob: 27a990eaff811a99f93bdce82cdb9ff7e45e1b9f [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//
10//
11//===----------------------------------------------------------------------===//
12
13#include "llvm/IR/Function.h"
14#include "llvm/IR/Constant.h"
15#include "llvm/IR/Constants.h"
Philip Reames1a1bdb22014-12-02 18:50:36 +000016#include "llvm/IR/Statepoint.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000017#include "llvm/Support/CommandLine.h"
Philip Reames1a1bdb22014-12-02 18:50:36 +000018
19using namespace std;
20using namespace llvm;
21
22bool llvm::isStatepoint(const ImmutableCallSite &CS) {
Igor Laevsky77f118f82015-02-19 11:02:11 +000023 if (!CS.getInstruction()) {
24 // This is not a call site
25 return false;
26 }
27
Philip Reames1a1bdb22014-12-02 18:50:36 +000028 const Function *F = CS.getCalledFunction();
29 return (F && F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint);
30}
Igor Laevsky77f118f82015-02-19 11:02:11 +000031bool llvm::isStatepoint(const Value *inst) {
Philip Reames1a1bdb22014-12-02 18:50:36 +000032 if (isa<InvokeInst>(inst) || isa<CallInst>(inst)) {
33 ImmutableCallSite CS(inst);
34 return isStatepoint(CS);
35 }
36 return false;
37}
Igor Laevsky77f118f82015-02-19 11:02:11 +000038bool llvm::isStatepoint(const Value &inst) {
Philip Reames1a1bdb22014-12-02 18:50:36 +000039 return isStatepoint(&inst);
40}
41
42bool llvm::isGCRelocate(const ImmutableCallSite &CS) {
Manuel Jacob83eefa62016-01-05 04:03:00 +000043 return CS.getInstruction() && isa<GCRelocateInst>(CS.getInstruction());
Philip Reames1a1bdb22014-12-02 18:50:36 +000044}
45
46bool llvm::isGCResult(const ImmutableCallSite &CS) {
Igor Laevsky77f118f82015-02-19 11:02:11 +000047 if (!CS.getInstruction()) {
48 // This is not a call site
49 return false;
50 }
51
Philip Reames1a1bdb22014-12-02 18:50:36 +000052 return isGCResult(CS.getInstruction());
53}
Igor Laevsky77f118f82015-02-19 11:02:11 +000054bool llvm::isGCResult(const Value *inst) {
Philip Reameseafafa32014-12-04 17:27:58 +000055 if (const CallInst *call = dyn_cast<CallInst>(inst)) {
Philip Reames1a1bdb22014-12-02 18:50:36 +000056 if (Function *F = call->getCalledFunction()) {
Manuel Jacob4e4f60d2015-12-22 18:44:45 +000057 return F->getIntrinsicID() == Intrinsic::experimental_gc_result;
Philip Reames1a1bdb22014-12-02 18:50:36 +000058 }
59 }
60 return false;
61}