Philip Reames | 1a1bdb2 | 2014-12-02 18:50:36 +0000 | [diff] [blame] | 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 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "llvm/IR/Function.h" |
| 14 | #include "llvm/IR/Constant.h" |
| 15 | #include "llvm/IR/Constants.h" |
Philip Reames | 1a1bdb2 | 2014-12-02 18:50:36 +0000 | [diff] [blame] | 16 | #include "llvm/IR/Statepoint.h" |
Chandler Carruth | d990388 | 2015-01-14 11:23:27 +0000 | [diff] [blame] | 17 | #include "llvm/Support/CommandLine.h" |
Philip Reames | 1a1bdb2 | 2014-12-02 18:50:36 +0000 | [diff] [blame] | 18 | |
| 19 | using namespace std; |
| 20 | using namespace llvm; |
| 21 | |
| 22 | bool llvm::isStatepoint(const ImmutableCallSite &CS) { |
Igor Laevsky | 77f118f8 | 2015-02-19 11:02:11 +0000 | [diff] [blame] | 23 | if (!CS.getInstruction()) { |
| 24 | // This is not a call site |
| 25 | return false; |
| 26 | } |
| 27 | |
Philip Reames | 1a1bdb2 | 2014-12-02 18:50:36 +0000 | [diff] [blame] | 28 | const Function *F = CS.getCalledFunction(); |
| 29 | return (F && F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint); |
| 30 | } |
Igor Laevsky | 77f118f8 | 2015-02-19 11:02:11 +0000 | [diff] [blame] | 31 | bool llvm::isStatepoint(const Value *inst) { |
Philip Reames | 1a1bdb2 | 2014-12-02 18:50:36 +0000 | [diff] [blame] | 32 | if (isa<InvokeInst>(inst) || isa<CallInst>(inst)) { |
| 33 | ImmutableCallSite CS(inst); |
| 34 | return isStatepoint(CS); |
| 35 | } |
| 36 | return false; |
| 37 | } |
Igor Laevsky | 77f118f8 | 2015-02-19 11:02:11 +0000 | [diff] [blame] | 38 | bool llvm::isStatepoint(const Value &inst) { |
Philip Reames | 1a1bdb2 | 2014-12-02 18:50:36 +0000 | [diff] [blame] | 39 | return isStatepoint(&inst); |
| 40 | } |
| 41 | |
| 42 | bool llvm::isGCRelocate(const ImmutableCallSite &CS) { |
Manuel Jacob | 83eefa6 | 2016-01-05 04:03:00 +0000 | [diff] [blame] | 43 | return CS.getInstruction() && isa<GCRelocateInst>(CS.getInstruction()); |
Philip Reames | 1a1bdb2 | 2014-12-02 18:50:36 +0000 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | bool llvm::isGCResult(const ImmutableCallSite &CS) { |
Igor Laevsky | 77f118f8 | 2015-02-19 11:02:11 +0000 | [diff] [blame] | 47 | if (!CS.getInstruction()) { |
| 48 | // This is not a call site |
| 49 | return false; |
| 50 | } |
| 51 | |
Philip Reames | 1a1bdb2 | 2014-12-02 18:50:36 +0000 | [diff] [blame] | 52 | return isGCResult(CS.getInstruction()); |
| 53 | } |
Igor Laevsky | 77f118f8 | 2015-02-19 11:02:11 +0000 | [diff] [blame] | 54 | bool llvm::isGCResult(const Value *inst) { |
Philip Reames | eafafa3 | 2014-12-04 17:27:58 +0000 | [diff] [blame] | 55 | if (const CallInst *call = dyn_cast<CallInst>(inst)) { |
Philip Reames | 1a1bdb2 | 2014-12-02 18:50:36 +0000 | [diff] [blame] | 56 | if (Function *F = call->getCalledFunction()) { |
Manuel Jacob | 4e4f60d | 2015-12-22 18:44:45 +0000 | [diff] [blame] | 57 | return F->getIntrinsicID() == Intrinsic::experimental_gc_result; |
Philip Reames | 1a1bdb2 | 2014-12-02 18:50:36 +0000 | [diff] [blame] | 58 | } |
| 59 | } |
| 60 | return false; |
| 61 | } |