Statepoint.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //===-- IR/Statepoint.cpp -- gc.statepoint utilities --- -----------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file contains some utility functions to help recognize gc.statepoint
  10. // intrinsics.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "llvm/IR/Statepoint.h"
  14. #include "llvm/IR/Function.h"
  15. using namespace llvm;
  16. bool llvm::isStatepoint(const CallBase *Call) {
  17. if (auto *F = Call->getCalledFunction())
  18. return F->getIntrinsicID() == Intrinsic::experimental_gc_statepoint;
  19. return false;
  20. }
  21. bool llvm::isStatepoint(const Value *V) {
  22. if (auto *Call = dyn_cast<CallBase>(V))
  23. return isStatepoint(Call);
  24. return false;
  25. }
  26. bool llvm::isStatepoint(const Value &V) {
  27. return isStatepoint(&V);
  28. }
  29. bool llvm::isGCRelocate(const CallBase *Call) {
  30. return isa<GCRelocateInst>(Call);
  31. }
  32. bool llvm::isGCRelocate(const Value *V) {
  33. if (auto *Call = dyn_cast<CallBase>(V))
  34. return isGCRelocate(Call);
  35. return false;
  36. }
  37. bool llvm::isGCResult(const CallBase *Call) { return isa<GCResultInst>(Call); }
  38. bool llvm::isGCResult(const Value *V) {
  39. if (auto *Call = dyn_cast<CallBase>(V))
  40. return isGCResult(Call);
  41. return false;
  42. }
  43. bool llvm::isStatepointDirectiveAttr(Attribute Attr) {
  44. return Attr.hasAttribute("statepoint-id") ||
  45. Attr.hasAttribute("statepoint-num-patch-bytes");
  46. }
  47. StatepointDirectives
  48. llvm::parseStatepointDirectivesFromAttrs(AttributeList AS) {
  49. StatepointDirectives Result;
  50. Attribute AttrID =
  51. AS.getAttribute(AttributeList::FunctionIndex, "statepoint-id");
  52. uint64_t StatepointID;
  53. if (AttrID.isStringAttribute())
  54. if (!AttrID.getValueAsString().getAsInteger(10, StatepointID))
  55. Result.StatepointID = StatepointID;
  56. uint32_t NumPatchBytes;
  57. Attribute AttrNumPatchBytes = AS.getAttribute(AttributeList::FunctionIndex,
  58. "statepoint-num-patch-bytes");
  59. if (AttrNumPatchBytes.isStringAttribute())
  60. if (!AttrNumPatchBytes.getValueAsString().getAsInteger(10, NumPatchBytes))
  61. Result.NumPatchBytes = NumPatchBytes;
  62. return Result;
  63. }