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 | // |
Sanjoy Das | d6fc46e | 2016-03-17 00:47:18 +0000 | [diff] [blame^] | 10 | // This file contains some utility functions to help recognize gc.statepoint |
| 11 | // intrinsics. |
| 12 | // |
Philip Reames | 1a1bdb2 | 2014-12-02 18:50:36 +0000 | [diff] [blame] | 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Philip Reames | 1a1bdb2 | 2014-12-02 18:50:36 +0000 | [diff] [blame] | 15 | #include "llvm/IR/Statepoint.h" |
| 16 | |
Sanjoy Das | d6fc46e | 2016-03-17 00:47:18 +0000 | [diff] [blame^] | 17 | #include "llvm/IR/Function.h" |
| 18 | |
Philip Reames | 1a1bdb2 | 2014-12-02 18:50:36 +0000 | [diff] [blame] | 19 | using namespace llvm; |
| 20 | |
Sanjoy Das | d6fc46e | 2016-03-17 00:47:18 +0000 | [diff] [blame^] | 21 | static const Function *getCalledFunction(ImmutableCallSite CS) { |
| 22 | if (!CS.getInstruction()) |
| 23 | return nullptr; |
| 24 | return CS.getCalledFunction(); |
Philip Reames | 1a1bdb2 | 2014-12-02 18:50:36 +0000 | [diff] [blame] | 25 | } |
Sanjoy Das | d6fc46e | 2016-03-17 00:47:18 +0000 | [diff] [blame^] | 26 | |
| 27 | bool llvm::isStatepoint(ImmutableCallSite CS) { |
| 28 | if (auto *F = getCalledFunction(CS)) |
| 29 | return F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint; |
Philip Reames | 1a1bdb2 | 2014-12-02 18:50:36 +0000 | [diff] [blame] | 30 | return false; |
| 31 | } |
Sanjoy Das | d6fc46e | 2016-03-17 00:47:18 +0000 | [diff] [blame^] | 32 | |
| 33 | bool llvm::isStatepoint(const Value *V) { |
| 34 | if (auto CS = ImmutableCallSite(V)) |
| 35 | return isStatepoint(CS); |
| 36 | return false; |
Philip Reames | 1a1bdb2 | 2014-12-02 18:50:36 +0000 | [diff] [blame] | 37 | } |
| 38 | |
Sanjoy Das | d6fc46e | 2016-03-17 00:47:18 +0000 | [diff] [blame^] | 39 | bool llvm::isStatepoint(const Value &V) { |
| 40 | return isStatepoint(&V); |
| 41 | } |
| 42 | |
| 43 | bool llvm::isGCRelocate(ImmutableCallSite CS) { |
Manuel Jacob | 83eefa6 | 2016-01-05 04:03:00 +0000 | [diff] [blame] | 44 | return CS.getInstruction() && isa<GCRelocateInst>(CS.getInstruction()); |
Philip Reames | 1a1bdb2 | 2014-12-02 18:50:36 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Sanjoy Das | d6fc46e | 2016-03-17 00:47:18 +0000 | [diff] [blame^] | 47 | bool llvm::isGCResult(ImmutableCallSite CS) { |
| 48 | if (auto *F = getCalledFunction(CS)) |
| 49 | return F->getIntrinsicID() == Intrinsic::experimental_gc_result; |
Philip Reames | 1a1bdb2 | 2014-12-02 18:50:36 +0000 | [diff] [blame] | 50 | return false; |
| 51 | } |
Sanjoy Das | d6fc46e | 2016-03-17 00:47:18 +0000 | [diff] [blame^] | 52 | |
| 53 | bool llvm::isGCResult(const Value *V) { |
| 54 | return isGCResult(ImmutableCallSite(V)); |
| 55 | } |