Statepoint.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #include "llvm/IR/Function.h"
  13. #include "llvm/IR/Constant.h"
  14. #include "llvm/IR/Constants.h"
  15. #include "llvm/IR/Statepoint.h"
  16. #include "llvm/Support/CommandLine.h"
  17. using namespace std;
  18. using namespace llvm;
  19. bool llvm::isStatepoint(const ImmutableCallSite &CS) {
  20. if (!CS.getInstruction()) {
  21. // This is not a call site
  22. return false;
  23. }
  24. const Function *F = CS.getCalledFunction();
  25. return (F && F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint);
  26. }
  27. bool llvm::isStatepoint(const Value *inst) {
  28. if (isa<InvokeInst>(inst) || isa<CallInst>(inst)) {
  29. ImmutableCallSite CS(inst);
  30. return isStatepoint(CS);
  31. }
  32. return false;
  33. }
  34. bool llvm::isStatepoint(const Value &inst) {
  35. return isStatepoint(&inst);
  36. }
  37. bool llvm::isGCRelocate(const ImmutableCallSite &CS) {
  38. if (!CS.getInstruction()) {
  39. // This is not a call site
  40. return false;
  41. }
  42. return isGCRelocate(CS.getInstruction());
  43. }
  44. bool llvm::isGCRelocate(const Value *inst) {
  45. if (const CallInst *call = dyn_cast<CallInst>(inst)) {
  46. if (const Function *F = call->getCalledFunction()) {
  47. return F->getIntrinsicID() == Intrinsic::experimental_gc_relocate;
  48. }
  49. }
  50. return false;
  51. }
  52. bool llvm::isGCResult(const ImmutableCallSite &CS) {
  53. if (!CS.getInstruction()) {
  54. // This is not a call site
  55. return false;
  56. }
  57. return isGCResult(CS.getInstruction());
  58. }
  59. bool llvm::isGCResult(const Value *inst) {
  60. if (const CallInst *call = dyn_cast<CallInst>(inst)) {
  61. if (Function *F = call->getCalledFunction()) {
  62. return (F->getIntrinsicID() == Intrinsic::experimental_gc_result_int ||
  63. F->getIntrinsicID() == Intrinsic::experimental_gc_result_float ||
  64. F->getIntrinsicID() == Intrinsic::experimental_gc_result_ptr ||
  65. F->getIntrinsicID() == Intrinsic::experimental_gc_result);
  66. }
  67. }
  68. return false;
  69. }