2
0

StatepointExampleGC.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //===-- StatepointDefaultGC.cpp - The default statepoint GC strategy ------===//
  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. // This file contains a GCStrategy which serves as an example for the usage
  11. // of a statepoint based lowering strategy. This GCStrategy is intended to
  12. // suitable as a default implementation usable with any collector which can
  13. // consume the standard stackmap format generated by statepoints, uses the
  14. // default addrespace to distinguish between gc managed and non-gc managed
  15. // pointers, and has reasonable relocation semantics.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #include "llvm/CodeGen/GCStrategy.h"
  19. #include "llvm/IR/DerivedTypes.h"
  20. #include "llvm/IR/Value.h"
  21. using namespace llvm;
  22. namespace {
  23. class StatepointGC : public GCStrategy {
  24. public:
  25. StatepointGC() {
  26. UseStatepoints = true;
  27. // These options are all gc.root specific, we specify them so that the
  28. // gc.root lowering code doesn't run.
  29. InitRoots = false;
  30. NeededSafePoints = 0;
  31. UsesMetadata = false;
  32. CustomRoots = false;
  33. }
  34. Optional<bool> isGCManagedPointer(const Value *V) const override {
  35. // Method is only valid on pointer typed values.
  36. PointerType *PT = cast<PointerType>(V->getType());
  37. // For the sake of this example GC, we arbitrarily pick addrspace(1) as our
  38. // GC managed heap. We know that a pointer into this heap needs to be
  39. // updated and that no other pointer does. Note that addrspace(1) is used
  40. // only as an example, it has no special meaning, and is not reserved for
  41. // GC usage.
  42. return (1 == PT->getAddressSpace());
  43. }
  44. };
  45. }
  46. static GCRegistry::Add<StatepointGC> X("statepoint-example",
  47. "an example strategy for statepoint");
  48. namespace llvm {
  49. void linkStatepointExampleGC() {}
  50. }