2726180be402c967d24854c9efde44a12de0d91a
[oota-llvm.git] / lib / CodeGen / CoreCLRGC.cpp
1 //===-- CoreCLRGC.cpp - CoreCLR Runtime GC Strategy -----------------------===//\r
2 //\r
3 //                     The LLVM Compiler Infrastructure\r
4 //\r
5 // This file is distributed under the University of Illinois Open Source\r
6 // License. See LICENSE.TXT for details.\r
7 //\r
8 //===----------------------------------------------------------------------===//\r
9 //\r
10 // This file contains a GCStrategy for the CoreCLR Runtime.\r
11 // The strategy is similar to Statepoint-example GC, but differs from it in\r
12 // certain aspects, such as:\r
13 // 1) Base-pointers need not be explicitly tracked and reported for\r
14 //    interior pointers\r
15 // 2) Uses a different format for encoding stack-maps\r
16 // 3) Location of Safe-point polls: polls are only needed before loop-back edges\r
17 //    and before tail-calls (not needed at function-entry)\r
18 //\r
19 // The above differences in behavior are to be implemented in upcoming checkins.\r
20 //\r
21 //===----------------------------------------------------------------------===//\r
22 \r
23 #include "llvm/CodeGen/GCStrategy.h"\r
24 #include "llvm/IR/DerivedTypes.h"\r
25 #include "llvm/IR/Value.h"\r
26 \r
27 using namespace llvm;\r
28 \r
29 namespace {\r
30 class CoreCLRGC : public GCStrategy {\r
31 public:\r
32   CoreCLRGC() {\r
33     UseStatepoints = true;\r
34     // These options are all gc.root specific, we specify them so that the\r
35     // gc.root lowering code doesn't run.\r
36     InitRoots = false;\r
37     NeededSafePoints = 0;\r
38     UsesMetadata = false;\r
39     CustomRoots = false;\r
40   }\r
41   Optional<bool> isGCManagedPointer(const Value *V) const override {\r
42     // Method is only valid on pointer typed values.\r
43     PointerType *PT = cast<PointerType>(V->getType());\r
44     // We pick addrspace(1) as our GC managed heap. \r
45     return (1 == PT->getAddressSpace());\r
46   }\r
47 };\r
48 }\r
49 \r
50 static GCRegistry::Add<CoreCLRGC> X("coreclr",\r
51                                     "CoreCLR-compatible GC");\r
52 \r
53 namespace llvm {\r
54 void linkCoreCLRGC() {}\r
55 }\r