Philip Reames | 352fb93 | 2015-01-07 19:13:28 +0000 | [diff] [blame] | 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 |
Philip Reames | 3631953 | 2015-01-16 23:16:12 +0000 | [diff] [blame] | 15 | // pointers, and has reasonable relocation semantics. |
Philip Reames | 352fb93 | 2015-01-07 19:13:28 +0000 | [diff] [blame] | 16 | // |
| 17 | //===----------------------------------------------------------------------===// |
| 18 | |
Philip Reames | 56a0393 | 2015-01-26 18:26:35 +0000 | [diff] [blame] | 19 | #include "llvm/CodeGen/GCStrategy.h" |
Philip Reames | 352fb93 | 2015-01-07 19:13:28 +0000 | [diff] [blame] | 20 | #include "llvm/IR/DerivedTypes.h" |
Chandler Carruth | d990388 | 2015-01-14 11:23:27 +0000 | [diff] [blame] | 21 | #include "llvm/IR/Value.h" |
Philip Reames | 352fb93 | 2015-01-07 19:13:28 +0000 | [diff] [blame] | 22 | |
| 23 | using namespace llvm; |
| 24 | |
| 25 | namespace { |
| 26 | class StatepointGC : public GCStrategy { |
| 27 | public: |
| 28 | StatepointGC() { |
| 29 | UseStatepoints = true; |
| 30 | // These options are all gc.root specific, we specify them so that the |
| 31 | // gc.root lowering code doesn't run. |
| 32 | InitRoots = false; |
| 33 | NeededSafePoints = 0; |
| 34 | UsesMetadata = false; |
| 35 | CustomRoots = false; |
Philip Reames | 352fb93 | 2015-01-07 19:13:28 +0000 | [diff] [blame] | 36 | } |
| 37 | Optional<bool> isGCManagedPointer(const Value *V) const override { |
| 38 | // Method is only valid on pointer typed values. |
| 39 | PointerType *PT = cast<PointerType>(V->getType()); |
| 40 | // For the sake of this example GC, we arbitrarily pick addrspace(1) as our |
| 41 | // GC managed heap. We know that a pointer into this heap needs to be |
Philip Reames | 287987c | 2015-01-16 23:21:07 +0000 | [diff] [blame] | 42 | // updated and that no other pointer does. Note that addrspace(1) is used |
| 43 | // only as an example, it has no special meaning, and is not reserved for |
| 44 | // GC usage. |
Philip Reames | 352fb93 | 2015-01-07 19:13:28 +0000 | [diff] [blame] | 45 | return (1 == PT->getAddressSpace()); |
| 46 | } |
| 47 | }; |
| 48 | } |
| 49 | |
Philip Reames | 3631953 | 2015-01-16 23:16:12 +0000 | [diff] [blame] | 50 | static GCRegistry::Add<StatepointGC> X("statepoint-example", |
| 51 | "an example strategy for statepoint"); |
Philip Reames | 352fb93 | 2015-01-07 19:13:28 +0000 | [diff] [blame] | 52 | |
| 53 | namespace llvm { |
| 54 | void linkStatepointExampleGC() {} |
| 55 | } |